diff --git a/README.md b/README.md
index b1b358f..4374ec4 100644
--- a/README.md
+++ b/README.md
@@ -97,6 +97,10 @@ For example, you may prefer that the `check` goal is performed in an earlier pha
`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`.
`forkMode` lets you specify whether to run google-java-format in a fork or in-process. Also adds JVM arguments to expose JDK internal javac APIs. Value `default` (which is the default) will fork (to avoid warnings for JDK9+ and to be able to run at all for JDK16+), `never` runs in-process, regardless of JDK version and `always` will always fork.
@@ -119,6 +123,8 @@ example:
some/other/dir
false
+ false
+ false
false
diff --git a/src/main/java/com/spotify/fmt/AbstractFMT.java b/src/main/java/com/spotify/fmt/AbstractFMT.java
index 8ccdf95..f0c6797 100644
--- a/src/main/java/com/spotify/fmt/AbstractFMT.java
+++ b/src/main/java/com/spotify/fmt/AbstractFMT.java
@@ -47,6 +47,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;
@@ -90,12 +96,12 @@ public void execute() throws 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/spotify/fmt/FMTTest.java b/src/test/java/com/spotify/fmt/FMTTest.java
index 26488d5..a31cf08 100644
--- a/src/test/java/com/spotify/fmt/FMTTest.java
+++ b/src/test/java/com/spotify/fmt/FMTTest.java
@@ -30,6 +30,14 @@ public void noSource() throws Exception {
assertThat(fmt.getResult().processedFiles()).isEmpty();
}
+ @Test
+ public void skipSource() throws Exception {
+ FMT fmt = loadMojo("skipsourcedirectory", FORMAT);
+ fmt.execute();
+
+ assertThat(fmt.getResult().processedFiles()).hasSize(1);
+ }
+
@Test
public void withoutTestSources() throws Exception {
FMT fmt = loadMojo("notestsource", FORMAT);
@@ -38,6 +46,14 @@ public void withoutTestSources() throws Exception {
assertThat(fmt.getResult().processedFiles()).hasSize(2);
}
+ @Test
+ public void skipTestSources() throws Exception {
+ FMT fmt = loadMojo("skiptestsourcedirectory", FORMAT);
+ fmt.execute();
+
+ assertThat(fmt.getResult().processedFiles()).hasSize(2);
+ }
+
@Test
public void withOnlyTestSources() throws Exception {
FMT fmt = loadMojo("onlytestsources", FORMAT);
@@ -199,6 +215,18 @@ public void checkFailsWhenNotFormatted() throws Exception {
check.execute();
}
+ @Test
+ public void checkSucceedsWhenSkipSourceDirectory() throws Exception {
+ Check check = loadMojo("check_skipsourcedirectory", CHECK);
+ check.execute();
+ }
+
+ @Test
+ public void checkSucceedsWhenSkipTestSourceDirectory() throws Exception {
+ Check check = loadMojo("check_skiptestsourcedirectory", CHECK);
+ check.execute();
+ }
+
@Test
public void checkSucceedsWhenFormatted() throws Exception {
Check check = loadMojo("check_formatted", CHECK);
diff --git a/src/test/resources/check_skipsourcedirectory/invoker.properties b/src/test/resources/check_skipsourcedirectory/invoker.properties
new file mode 100644
index 0000000..b577428
--- /dev/null
+++ b/src/test/resources/check_skipsourcedirectory/invoker.properties
@@ -0,0 +1 @@
+invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}: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..a62db40
--- /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.spotify.fmt
+ 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/invoker.properties b/src/test/resources/check_skiptestsourcedirectory/invoker.properties
new file mode 100644
index 0000000..b577428
--- /dev/null
+++ b/src/test/resources/check_skiptestsourcedirectory/invoker.properties
@@ -0,0 +1 @@
+invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:check
diff --git a/src/test/resources/check_skiptestsourcedirectory/pom.xml b/src/test/resources/check_skiptestsourcedirectory/pom.xml
new file mode 100644
index 0000000..45741bb
--- /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.spotify.fmt
+ 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/invoker.properties b/src/test/resources/skipsourcedirectory/invoker.properties
new file mode 100644
index 0000000..908e5e3
--- /dev/null
+++ b/src/test/resources/skipsourcedirectory/invoker.properties
@@ -0,0 +1 @@
+invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:format
diff --git a/src/test/resources/skipsourcedirectory/pom.xml b/src/test/resources/skipsourcedirectory/pom.xml
new file mode 100644
index 0000000..a62db40
--- /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.spotify.fmt
+ 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/invoker.properties b/src/test/resources/skiptestsourcedirectory/invoker.properties
new file mode 100644
index 0000000..908e5e3
--- /dev/null
+++ b/src/test/resources/skiptestsourcedirectory/invoker.properties
@@ -0,0 +1 @@
+invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:format
diff --git a/src/test/resources/skiptestsourcedirectory/pom.xml b/src/test/resources/skiptestsourcedirectory/pom.xml
new file mode 100644
index 0000000..45741bb
--- /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.spotify.fmt
+ 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!");
+ }
+}