diff --git a/README.md b/README.md
index 1ddb56c..fdc00fb 100644
--- a/README.md
+++ b/README.md
@@ -74,6 +74,10 @@ If you prefer, you can only check formatting at build time using the `check` goa
`skipSortingImports` is whether the plugin should skip sorting imports.
+`skipSourceDirectory` is whether the plugin should skip formatting/checking the `sourceDirectory`. It defaults to `false`.
+
+`skipTestSourceDirectory` is whether the plugin should skip formatting/checking the `testSourceDirectory`. It defaults to `false`.
+
`style` sets the formatter style to be _google_ or _aosp_. By default this is 'google'. Projects using Android conventions may prefer `aosp`.
example:
@@ -94,6 +98,8 @@ example:
some/other/dir
false
+ false
+ false
false
diff --git a/src/main/java/com/coveo/AbstractFMT.java b/src/main/java/com/coveo/AbstractFMT.java
index 444c010..5a6b6db 100644
--- a/src/main/java/com/coveo/AbstractFMT.java
+++ b/src/main/java/com/coveo/AbstractFMT.java
@@ -54,6 +54,12 @@ public abstract class AbstractFMT extends AbstractMojo {
@Parameter(defaultValue = "false", property = "fmt.skip")
private boolean skip = false;
+ @Parameter(defaultValue = "false", property = "skipSourceDirectory")
+ private boolean skipSourceDirectory = false;
+
+ @Parameter(defaultValue = "false", property = "skipTestSourceDirectory")
+ private boolean skipTestSourceDirectory = false;
+
@Parameter(defaultValue = "false", property = "skipSortingImports")
private boolean skipSortingImports = false;
@@ -82,12 +88,12 @@ public void execute() throws MojoExecutionException, MojoFailureException {
getLog().info("Skipping sorting imports");
}
List directoriesToFormat = new ArrayList<>();
- if (sourceDirectory.exists()) {
+ if (sourceDirectory.exists() && !skipSourceDirectory) {
directoriesToFormat.add(sourceDirectory);
} else {
handleMissingDirectory("Source", sourceDirectory);
}
- if (testSourceDirectory.exists()) {
+ if (testSourceDirectory.exists() && !skipTestSourceDirectory) {
directoriesToFormat.add(testSourceDirectory);
} else {
handleMissingDirectory("Test source", testSourceDirectory);
diff --git a/src/test/java/com/coveo/FMTTest.java b/src/test/java/com/coveo/FMTTest.java
index 6c6cc2b..68bff50 100644
--- a/src/test/java/com/coveo/FMTTest.java
+++ b/src/test/java/com/coveo/FMTTest.java
@@ -24,6 +24,14 @@ public void noSource() throws Exception {
assertThat(fmt.getFilesProcessed()).isEmpty();
}
+ @Test
+ public void skipSource() throws Exception {
+ FMT fmt = (FMT) mojoRule.lookupConfiguredMojo(loadPom("skipsourcedirectory"), FORMAT);
+ fmt.execute();
+
+ assertThat(fmt.getFilesProcessed()).hasSize(1);
+ }
+
@Test
public void withoutTestSources() throws Exception {
FMT fmt = (FMT) mojoRule.lookupConfiguredMojo(loadPom("notestsource"), FORMAT);
@@ -32,6 +40,14 @@ public void withoutTestSources() throws Exception {
assertThat(fmt.getFilesProcessed()).hasSize(2);
}
+ @Test
+ public void skipTestSources() throws Exception {
+ FMT fmt = (FMT) mojoRule.lookupConfiguredMojo(loadPom("skiptestsourcedirectory"), FORMAT);
+ fmt.execute();
+
+ assertThat(fmt.getFilesProcessed()).hasSize(2);
+ }
+
@Test
public void withOnlyTestSources() throws Exception {
FMT fmt = (FMT) mojoRule.lookupConfiguredMojo(loadPom("onlytestsources"), FORMAT);
@@ -149,6 +165,20 @@ public void checkFailsWhenNotFormatted() throws Exception {
check.execute();
}
+ @Test
+ public void checkSucceedsWhenSkipSourceDirectory() throws Exception {
+ Check check =
+ (Check) mojoRule.lookupConfiguredMojo(loadPom("check_skipsourcedirectory"), CHECK);
+ check.execute();
+ }
+
+ @Test
+ public void checkSucceedsWhenSkipTestSourceDirectory() throws Exception {
+ Check check =
+ (Check) mojoRule.lookupConfiguredMojo(loadPom("check_skiptestsourcedirectory"), CHECK);
+ check.execute();
+ }
+
@Test
public void checkSucceedsWhenFormatted() throws Exception {
Check check = (Check) mojoRule.lookupConfiguredMojo(loadPom("check_formatted"), CHECK);
diff --git a/src/test/resources/check_skipsourcedirectory/pom.xml b/src/test/resources/check_skipsourcedirectory/pom.xml
new file mode 100644
index 0000000..9b40520
--- /dev/null
+++ b/src/test/resources/check_skipsourcedirectory/pom.xml
@@ -0,0 +1,50 @@
+
+ 4.0.0
+
+ org.apache.maven.plugin.my.unit
+ project-to-test
+ 1.0.0
+ jar
+ Test MyMojo
+
+
+
+ junit
+ junit
+ 4.13.1
+ test
+
+
+
+
+
+
+ com.coveo
+ fmt-maven-plugin
+ 2.12
+
+ true
+
+
+
+
+ format
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/test/resources/check_skipsourcedirectory/src/main/java/HelloWorld1.java b/src/test/resources/check_skipsourcedirectory/src/main/java/HelloWorld1.java
new file mode 100644
index 0000000..b9cba7e
--- /dev/null
+++ b/src/test/resources/check_skipsourcedirectory/src/main/java/HelloWorld1.java
@@ -0,0 +1,7 @@
+package notestsource.src.main.java;
+
+public class HelloWorld1 {
+public static void main(String[] args) {
+ System.out.println("Hello World!");
+ }
+}
diff --git a/src/test/resources/check_skipsourcedirectory/src/main/java/HelloWorld2.java b/src/test/resources/check_skipsourcedirectory/src/main/java/HelloWorld2.java
new file mode 100644
index 0000000..b9cba7e
--- /dev/null
+++ b/src/test/resources/check_skipsourcedirectory/src/main/java/HelloWorld2.java
@@ -0,0 +1,7 @@
+package notestsource.src.main.java;
+
+public class HelloWorld1 {
+public static void main(String[] args) {
+ System.out.println("Hello World!");
+ }
+}
diff --git a/src/test/resources/check_skipsourcedirectory/src/test/java/HelloWorldTest.java b/src/test/resources/check_skipsourcedirectory/src/test/java/HelloWorldTest.java
new file mode 100644
index 0000000..3b2afb4
--- /dev/null
+++ b/src/test/resources/check_skipsourcedirectory/src/test/java/HelloWorldTest.java
@@ -0,0 +1,7 @@
+package notestsource.src.main.java;
+
+public class HelloWorldTest {
+ public static void main(String[] args) {
+ System.out.println("Hello World!");
+ }
+}
diff --git a/src/test/resources/check_skiptestsourcedirectory/pom.xml b/src/test/resources/check_skiptestsourcedirectory/pom.xml
new file mode 100644
index 0000000..3f56547
--- /dev/null
+++ b/src/test/resources/check_skiptestsourcedirectory/pom.xml
@@ -0,0 +1,50 @@
+
+ 4.0.0
+
+ org.apache.maven.plugin.my.unit
+ project-to-test
+ 1.0.0
+ jar
+ Test MyMojo
+
+
+
+ junit
+ junit
+ 4.13.1
+ test
+
+
+
+
+
+
+ com.coveo
+ fmt-maven-plugin
+ 2.12
+
+ true
+
+
+
+
+ format
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/test/resources/check_skiptestsourcedirectory/src/main/java/HelloWorld1.java b/src/test/resources/check_skiptestsourcedirectory/src/main/java/HelloWorld1.java
new file mode 100644
index 0000000..b2d5ee8
--- /dev/null
+++ b/src/test/resources/check_skiptestsourcedirectory/src/main/java/HelloWorld1.java
@@ -0,0 +1,7 @@
+package notestsource.src.main.java;
+
+public class HelloWorld1 {
+ public static void main(String[] args) {
+ System.out.println("Hello World!");
+ }
+}
diff --git a/src/test/resources/check_skiptestsourcedirectory/src/main/java/HelloWorld2.java b/src/test/resources/check_skiptestsourcedirectory/src/main/java/HelloWorld2.java
new file mode 100644
index 0000000..b2d5ee8
--- /dev/null
+++ b/src/test/resources/check_skiptestsourcedirectory/src/main/java/HelloWorld2.java
@@ -0,0 +1,7 @@
+package notestsource.src.main.java;
+
+public class HelloWorld1 {
+ public static void main(String[] args) {
+ System.out.println("Hello World!");
+ }
+}
diff --git a/src/test/resources/check_skiptestsourcedirectory/src/test/java/HelloWorldTest.java b/src/test/resources/check_skiptestsourcedirectory/src/test/java/HelloWorldTest.java
new file mode 100644
index 0000000..3be6792
--- /dev/null
+++ b/src/test/resources/check_skiptestsourcedirectory/src/test/java/HelloWorldTest.java
@@ -0,0 +1,7 @@
+package notestsource.src.main.java;
+
+public class HelloWorldTest {
+public static void main(String[] args) {
+ System.out.println("Hello World!");
+ }
+}
diff --git a/src/test/resources/skipsourcedirectory/pom.xml b/src/test/resources/skipsourcedirectory/pom.xml
new file mode 100644
index 0000000..9b40520
--- /dev/null
+++ b/src/test/resources/skipsourcedirectory/pom.xml
@@ -0,0 +1,50 @@
+
+ 4.0.0
+
+ org.apache.maven.plugin.my.unit
+ project-to-test
+ 1.0.0
+ jar
+ Test MyMojo
+
+
+
+ junit
+ junit
+ 4.13.1
+ test
+
+
+
+
+
+
+ com.coveo
+ fmt-maven-plugin
+ 2.12
+
+ true
+
+
+
+
+ format
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/test/resources/skipsourcedirectory/src/main/java/HelloWorld1.java b/src/test/resources/skipsourcedirectory/src/main/java/HelloWorld1.java
new file mode 100644
index 0000000..b2d5ee8
--- /dev/null
+++ b/src/test/resources/skipsourcedirectory/src/main/java/HelloWorld1.java
@@ -0,0 +1,7 @@
+package notestsource.src.main.java;
+
+public class HelloWorld1 {
+ public static void main(String[] args) {
+ System.out.println("Hello World!");
+ }
+}
diff --git a/src/test/resources/skipsourcedirectory/src/main/java/HelloWorld2.java b/src/test/resources/skipsourcedirectory/src/main/java/HelloWorld2.java
new file mode 100644
index 0000000..b2d5ee8
--- /dev/null
+++ b/src/test/resources/skipsourcedirectory/src/main/java/HelloWorld2.java
@@ -0,0 +1,7 @@
+package notestsource.src.main.java;
+
+public class HelloWorld1 {
+ public static void main(String[] args) {
+ System.out.println("Hello World!");
+ }
+}
diff --git a/src/test/resources/skipsourcedirectory/src/test/java/HelloWorldTest.java b/src/test/resources/skipsourcedirectory/src/test/java/HelloWorldTest.java
new file mode 100644
index 0000000..3b2afb4
--- /dev/null
+++ b/src/test/resources/skipsourcedirectory/src/test/java/HelloWorldTest.java
@@ -0,0 +1,7 @@
+package notestsource.src.main.java;
+
+public class HelloWorldTest {
+ public static void main(String[] args) {
+ System.out.println("Hello World!");
+ }
+}
diff --git a/src/test/resources/skiptestsourcedirectory/pom.xml b/src/test/resources/skiptestsourcedirectory/pom.xml
new file mode 100644
index 0000000..3f56547
--- /dev/null
+++ b/src/test/resources/skiptestsourcedirectory/pom.xml
@@ -0,0 +1,50 @@
+
+ 4.0.0
+
+ org.apache.maven.plugin.my.unit
+ project-to-test
+ 1.0.0
+ jar
+ Test MyMojo
+
+
+
+ junit
+ junit
+ 4.13.1
+ test
+
+
+
+
+
+
+ com.coveo
+ fmt-maven-plugin
+ 2.12
+
+ true
+
+
+
+
+ format
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/test/resources/skiptestsourcedirectory/src/main/java/HelloWorld1.java b/src/test/resources/skiptestsourcedirectory/src/main/java/HelloWorld1.java
new file mode 100644
index 0000000..b2d5ee8
--- /dev/null
+++ b/src/test/resources/skiptestsourcedirectory/src/main/java/HelloWorld1.java
@@ -0,0 +1,7 @@
+package notestsource.src.main.java;
+
+public class HelloWorld1 {
+ public static void main(String[] args) {
+ System.out.println("Hello World!");
+ }
+}
diff --git a/src/test/resources/skiptestsourcedirectory/src/main/java/HelloWorld2.java b/src/test/resources/skiptestsourcedirectory/src/main/java/HelloWorld2.java
new file mode 100644
index 0000000..b2d5ee8
--- /dev/null
+++ b/src/test/resources/skiptestsourcedirectory/src/main/java/HelloWorld2.java
@@ -0,0 +1,7 @@
+package notestsource.src.main.java;
+
+public class HelloWorld1 {
+ public static void main(String[] args) {
+ System.out.println("Hello World!");
+ }
+}
diff --git a/src/test/resources/skiptestsourcedirectory/src/test/java/HelloWorldTest.java b/src/test/resources/skiptestsourcedirectory/src/test/java/HelloWorldTest.java
new file mode 100644
index 0000000..3b2afb4
--- /dev/null
+++ b/src/test/resources/skiptestsourcedirectory/src/test/java/HelloWorldTest.java
@@ -0,0 +1,7 @@
+package notestsource.src.main.java;
+
+public class HelloWorldTest {
+ public static void main(String[] args) {
+ System.out.println("Hello World!");
+ }
+}