[MCOMPILER-500] add some parameter to pattern from stale source calculation (#141)

Signed-off-by: Olivier Lamy <olamy@apache.org>
diff --git a/src/it/MCOMPILER-500-package-info-incr/invoker.properties b/src/it/MCOMPILER-500-package-info-incr/invoker.properties
new file mode 100644
index 0000000..367af02
--- /dev/null
+++ b/src/it/MCOMPILER-500-package-info-incr/invoker.properties
@@ -0,0 +1,21 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+invoker.goals = clean compile
+invoker.buildResult = success
+invoker.goals.2 =  compile
+invoker.buildResult.2 = success
\ No newline at end of file
diff --git a/src/it/MCOMPILER-500-package-info-incr/pom.xml b/src/it/MCOMPILER-500-package-info-incr/pom.xml
new file mode 100644
index 0000000..c79c3f9
--- /dev/null
+++ b/src/it/MCOMPILER-500-package-info-incr/pom.xml
@@ -0,0 +1,50 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<project
+  xmlns="http://maven.apache.org/POM/4.0.0"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.plugins</groupId>
+  <artifactId>maven-compiler-plugin-it-package-info-incr</artifactId>
+  <version>1.0.0-SNAPSHOT</version>
+  <packaging>jar</packaging>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>@pom.version@</version>
+        <configuration>
+          <createMissingPackageInfoClass>false</createMissingPackageInfoClass>
+          <incrementalExcludes>
+            <incrementalExclude>**/package-info.java</incrementalExclude>
+          </incrementalExcludes>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git a/src/it/MCOMPILER-500-package-info-incr/src/main/java/dummy/Person.java b/src/it/MCOMPILER-500-package-info-incr/src/main/java/dummy/Person.java
new file mode 100644
index 0000000..e5fbf58
--- /dev/null
+++ b/src/it/MCOMPILER-500-package-info-incr/src/main/java/dummy/Person.java
@@ -0,0 +1,38 @@
+package dummy;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+public class Person {
+    private long id;
+    private String name;
+
+    public long getId() {
+        return id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+}
diff --git a/src/it/MCOMPILER-500-package-info-incr/src/main/java/dummy/foo/Person.java b/src/it/MCOMPILER-500-package-info-incr/src/main/java/dummy/foo/Person.java
new file mode 100644
index 0000000..9b56c1d
--- /dev/null
+++ b/src/it/MCOMPILER-500-package-info-incr/src/main/java/dummy/foo/Person.java
@@ -0,0 +1,38 @@
+package dummy.foo;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+public class Person {
+    private long id;
+    private String name;
+
+    public long getId() {
+        return id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+}
diff --git a/src/it/MCOMPILER-500-package-info-incr/src/main/java/dummy/package-info.java b/src/it/MCOMPILER-500-package-info-incr/src/main/java/dummy/package-info.java
new file mode 100644
index 0000000..ed72542
--- /dev/null
+++ b/src/it/MCOMPILER-500-package-info-incr/src/main/java/dummy/package-info.java
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * This is the package javadoc
+ */
+package dummy;
\ No newline at end of file
diff --git a/src/it/MCOMPILER-500-package-info-incr/verify.groovy b/src/it/MCOMPILER-500-package-info-incr/verify.groovy
new file mode 100644
index 0000000..ecba9c2
--- /dev/null
+++ b/src/it/MCOMPILER-500-package-info-incr/verify.groovy
@@ -0,0 +1,27 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+def logFile = new File( basedir, 'build.log' )
+assert logFile.exists()
+content = logFile.text
+
+assert 1 == content.count( 'Changes detected - recompiling the module!' )
+assert 1 == content.count( 'Nothing to compile - all classes are up to date' )
+
+
diff --git a/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java b/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java
index ea41300..305d1e3 100644
--- a/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java
+++ b/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java
@@ -95,6 +95,13 @@
     private Set<String> excludes = new HashSet<>();
 
     /**
+     * A list of exclusion filters for the incremental calculation.
+     * @since 3.11
+     */
+    @Parameter
+    private Set<String> incrementalExcludes = new HashSet<>();
+
+    /**
      * <p>
      * Specify where to place generated source files created by annotation processing. Only applies to JDK 1.6+
      * </p>
@@ -387,7 +394,7 @@
     
     protected SourceInclusionScanner getSourceInclusionScanner( int staleMillis )
     {
-        if ( includes.isEmpty() && excludes.isEmpty() )
+        if ( includes.isEmpty() && excludes.isEmpty() && incrementalExcludes.isEmpty() )
         {
             return new StaleSourceScanner( staleMillis );
         }
@@ -397,7 +404,9 @@
             includes.add( "**/*.java" );
         }
 
-        return new StaleSourceScanner( staleMillis, includes, excludes );
+        Set<String> excludesIncr = new HashSet<>( excludes );
+        excludesIncr.addAll( this.incrementalExcludes );
+        return new StaleSourceScanner( staleMillis, includes, excludesIncr );
     }
 
     protected SourceInclusionScanner getSourceInclusionScanner( String inputFileEnding )
@@ -409,8 +418,9 @@
         {
             includes.add( defaultIncludePattern );
         }
-
-        return new SimpleSourceInclusionScanner( includes, excludes );
+        Set<String> excludesIncr = new HashSet<>( excludes );
+        excludesIncr.addAll( excludesIncr );
+        return new SimpleSourceInclusionScanner( includes, excludesIncr );
     }
 
     protected String getSource()
diff --git a/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java b/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java
index 4368304..ed855ab 100644
--- a/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java
+++ b/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java
@@ -91,6 +91,13 @@
     private Set<String> testExcludes = new HashSet<>();
 
     /**
+     * A list of exclusion filters for the incremental calculation.
+     * @since 3.11
+     */
+    @Parameter
+    private Set<String> testIncrementalExcludes = new HashSet<>();
+
+    /**
      * The -source argument for the test Java compiler.
      *
      * @since 2.1
@@ -414,7 +421,7 @@
     {
         SourceInclusionScanner scanner;
 
-        if ( testIncludes.isEmpty() && testExcludes.isEmpty() )
+        if ( testIncludes.isEmpty() && testExcludes.isEmpty() && testIncrementalExcludes.isEmpty() )
         {
             scanner = new StaleSourceScanner( staleMillis );
         }
@@ -424,7 +431,9 @@
             {
                 testIncludes.add( "**/*.java" );
             }
-            scanner = new StaleSourceScanner( staleMillis, testIncludes, testExcludes );
+            Set<String> excludesIncr = new HashSet<>( testExcludes );
+            excludesIncr.addAll( this.testIncrementalExcludes );
+            scanner = new StaleSourceScanner( staleMillis, testIncludes, excludesIncr );
         }
 
         return scanner;
@@ -437,7 +446,7 @@
         // it's not defined if we get the ending with or without the dot '.'
         String defaultIncludePattern = "**/*" + ( inputFileEnding.startsWith( "." ) ? "" : "." ) + inputFileEnding;
 
-        if ( testIncludes.isEmpty() && testExcludes.isEmpty() )
+        if ( testIncludes.isEmpty() && testExcludes.isEmpty() && testIncrementalExcludes.isEmpty() )
         {
             testIncludes = Collections.singleton( defaultIncludePattern );
             scanner = new SimpleSourceInclusionScanner( testIncludes, Collections.emptySet() );
@@ -448,7 +457,9 @@
             {
                 testIncludes.add( defaultIncludePattern );
             }
-            scanner = new SimpleSourceInclusionScanner( testIncludes, testExcludes );
+            Set<String> excludesIncr = new HashSet<>( testExcludes );
+            excludesIncr.addAll( this.testIncrementalExcludes );
+            scanner = new SimpleSourceInclusionScanner( testIncludes, excludesIncr );
         }
 
         return scanner;