From 4014c0ba3f1f7ea6d60844007a2205e445c48871 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 22 Jul 2022 18:37:40 +1000 Subject: [PATCH] [MCOMPILER-500] add some parameter to pattern from stale source calculation Signed-off-by: Olivier Lamy --- .../invoker.properties | 21 ++++++++ .../MCOMPILER-500-package-info-incr/pom.xml | 50 +++++++++++++++++++ .../src/main/java/dummy/Person.java | 38 ++++++++++++++ .../src/main/java/dummy/foo/Person.java | 38 ++++++++++++++ .../src/main/java/dummy/package-info.java | 23 +++++++++ .../verify.groovy | 27 ++++++++++ .../maven/plugin/compiler/CompilerMojo.java | 18 +++++-- .../plugin/compiler/TestCompilerMojo.java | 19 +++++-- 8 files changed, 226 insertions(+), 8 deletions(-) create mode 100644 src/it/MCOMPILER-500-package-info-incr/invoker.properties create mode 100644 src/it/MCOMPILER-500-package-info-incr/pom.xml create mode 100644 src/it/MCOMPILER-500-package-info-incr/src/main/java/dummy/Person.java create mode 100644 src/it/MCOMPILER-500-package-info-incr/src/main/java/dummy/foo/Person.java create mode 100644 src/it/MCOMPILER-500-package-info-incr/src/main/java/dummy/package-info.java create mode 100644 src/it/MCOMPILER-500-package-info-incr/verify.groovy 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 00000000..367af02d --- /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 00000000..c79c3f9a --- /dev/null +++ b/src/it/MCOMPILER-500-package-info-incr/pom.xml @@ -0,0 +1,50 @@ + + + + + 4.0.0 + + org.apache.maven.plugins + maven-compiler-plugin-it-package-info-incr + 1.0.0-SNAPSHOT + jar + + + UTF-8 + + + + + org.apache.maven.plugins + maven-compiler-plugin + @pom.version@ + + false + + **/package-info.java + + + + + + 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 00000000..e5fbf583 --- /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 00000000..9b56c1d6 --- /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 00000000..ed72542b --- /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 00000000..ecba9c29 --- /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 ea41300a..305d1e3f 100644 --- a/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java +++ b/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java @@ -94,6 +94,13 @@ public class CompilerMojo @Parameter private Set excludes = new HashSet<>(); + /** + * A list of exclusion filters for the incremental calculation. + * @since 3.11 + */ + @Parameter + private Set incrementalExcludes = new HashSet<>(); + /** *

* Specify where to place generated source files created by annotation processing. Only applies to JDK 1.6+ @@ -387,7 +394,7 @@ private List getCompileClasspathElements( MavenProject project ) 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 @@ protected SourceInclusionScanner getSourceInclusionScanner( int staleMillis ) includes.add( "**/*.java" ); } - return new StaleSourceScanner( staleMillis, includes, excludes ); + Set excludesIncr = new HashSet<>( excludes ); + excludesIncr.addAll( this.incrementalExcludes ); + return new StaleSourceScanner( staleMillis, includes, excludesIncr ); } protected SourceInclusionScanner getSourceInclusionScanner( String inputFileEnding ) @@ -409,8 +418,9 @@ protected SourceInclusionScanner getSourceInclusionScanner( String inputFileEndi { includes.add( defaultIncludePattern ); } - - return new SimpleSourceInclusionScanner( includes, excludes ); + Set 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 43683040..ed855ab5 100644 --- a/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java +++ b/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java @@ -90,6 +90,13 @@ public class TestCompilerMojo @Parameter private Set testExcludes = new HashSet<>(); + /** + * A list of exclusion filters for the incremental calculation. + * @since 3.11 + */ + @Parameter + private Set testIncrementalExcludes = new HashSet<>(); + /** * The -source argument for the test Java compiler. * @@ -414,7 +421,7 @@ protected SourceInclusionScanner getSourceInclusionScanner( int staleMillis ) { SourceInclusionScanner scanner; - if ( testIncludes.isEmpty() && testExcludes.isEmpty() ) + if ( testIncludes.isEmpty() && testExcludes.isEmpty() && testIncrementalExcludes.isEmpty() ) { scanner = new StaleSourceScanner( staleMillis ); } @@ -424,7 +431,9 @@ protected SourceInclusionScanner getSourceInclusionScanner( int staleMillis ) { testIncludes.add( "**/*.java" ); } - scanner = new StaleSourceScanner( staleMillis, testIncludes, testExcludes ); + Set excludesIncr = new HashSet<>( testExcludes ); + excludesIncr.addAll( this.testIncrementalExcludes ); + scanner = new StaleSourceScanner( staleMillis, testIncludes, excludesIncr ); } return scanner; @@ -437,7 +446,7 @@ protected SourceInclusionScanner getSourceInclusionScanner( String inputFileEndi // 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 @@ protected SourceInclusionScanner getSourceInclusionScanner( String inputFileEndi { testIncludes.add( defaultIncludePattern ); } - scanner = new SimpleSourceInclusionScanner( testIncludes, testExcludes ); + Set excludesIncr = new HashSet<>( testExcludes ); + excludesIncr.addAll( this.testIncrementalExcludes ); + scanner = new SimpleSourceInclusionScanner( testIncludes, excludesIncr ); } return scanner;