diff --git a/pom.xml b/pom.xml index 467a251d..48fde2eb 100644 --- a/pom.xml +++ b/pom.xml @@ -105,7 +105,12 @@ under the License. com.thoughtworks.qdox qdox - 2.0.2 + 2.0.3 + + + org.codehaus.plexus + plexus-utils + 3.5.0 @@ -134,29 +139,22 @@ under the License. ${mavenVersion} provided + + org.apache.maven + maven-model + ${mavenVersion} + provided + org.apache.maven.shared maven-shared-utils 3.3.4 + - org.apache.maven.shared - maven-shared-incremental - 1.1 - - - maven-core - org.apache.maven - - - maven-plugin-api - org.apache.maven - - - maven-shared-utils - org.apache.maven.shared - - + org.ow2.asm + asm + 9.4 @@ -197,7 +195,7 @@ under the License. org.mockito mockito-core - 4.8.0 + 4.8.1 test diff --git a/src/it/MCOMPILER-500-package-info-incr/invoker.properties b/src/it/MCOMPILER-500-package-info-incr/invoker.properties deleted file mode 100644 index 367af02d..00000000 --- a/src/it/MCOMPILER-500-package-info-incr/invoker.properties +++ /dev/null @@ -1,21 +0,0 @@ -# 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 deleted file mode 100644 index c79c3f9a..00000000 --- a/src/it/MCOMPILER-500-package-info-incr/pom.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - - 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 deleted file mode 100644 index e5fbf583..00000000 --- a/src/it/MCOMPILER-500-package-info-incr/src/main/java/dummy/Person.java +++ /dev/null @@ -1,38 +0,0 @@ -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 deleted file mode 100644 index 9b56c1d6..00000000 --- a/src/it/MCOMPILER-500-package-info-incr/src/main/java/dummy/foo/Person.java +++ /dev/null @@ -1,38 +0,0 @@ -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 deleted file mode 100644 index ed72542b..00000000 --- a/src/it/MCOMPILER-500-package-info-incr/src/main/java/dummy/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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 deleted file mode 100644 index ecba9c29..00000000 --- a/src/it/MCOMPILER-500-package-info-incr/verify.groovy +++ /dev/null @@ -1,27 +0,0 @@ - -/* - * 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/it/default-incremental-disable/invoker.properties b/src/it/default-incremental-disable/invoker.properties deleted file mode 100644 index 5f1421e8..00000000 --- a/src/it/default-incremental-disable/invoker.properties +++ /dev/null @@ -1,19 +0,0 @@ -# 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 test-compile -invoker.goals.2 = test-compile diff --git a/src/it/default-incremental-disable/pom.xml b/src/it/default-incremental-disable/pom.xml deleted file mode 100644 index 5eb59dfe..00000000 --- a/src/it/default-incremental-disable/pom.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - - - 4.0.0 - - org.apache.maven.plugins.compiler.it - default-incremental-disable - 1.0-SNAPSHOT - - Test for default configuration - - - UTF-8 - - - - - junit - junit - 3.8.2 - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - @pom.version@ - - false - - -Xlint:-path - - - - - - - diff --git a/src/it/default-incremental-disable/src/main/java/MyClass.java b/src/it/default-incremental-disable/src/main/java/MyClass.java deleted file mode 100644 index 4945381a..00000000 --- a/src/it/default-incremental-disable/src/main/java/MyClass.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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 MyClass -{ - -} diff --git a/src/it/default-incremental-disable/src/test/java/MyTest.java b/src/it/default-incremental-disable/src/test/java/MyTest.java deleted file mode 100644 index 46ba41d4..00000000 --- a/src/it/default-incremental-disable/src/test/java/MyTest.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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. - */ - -import junit.framework.TestCase; - -public class MyTest - extends TestCase -{ - -} diff --git a/src/it/default-incremental-disable/verify.groovy b/src/it/default-incremental-disable/verify.groovy deleted file mode 100644 index 2f72f1c9..00000000 --- a/src/it/default-incremental-disable/verify.groovy +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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. - */ - -assert new File( basedir, "target/classes/MyClass.class" ).exists(); -assert new File( basedir, "target/test-classes/MyTest.class" ).exists(); - -content = new File( basedir, 'build.log' ).text; - -assert content.contains("Nothing to compile - all classes are up to date"); diff --git a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java index ea37a4d5..52afb3be 100644 --- a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java +++ b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java @@ -22,6 +22,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.io.UncheckedIOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.nio.charset.Charset; @@ -30,7 +31,6 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.Date; import java.util.HashSet; import java.util.Iterator; @@ -39,6 +39,7 @@ import java.util.Map; import java.util.Properties; import java.util.Set; +import java.util.stream.Stream; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DefaultArtifact; @@ -51,19 +52,13 @@ import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.MojoExecution; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.apache.maven.repository.RepositorySystem; -import org.apache.maven.shared.incremental.IncrementalBuildHelper; -import org.apache.maven.shared.incremental.IncrementalBuildHelperRequest; import org.apache.maven.shared.utils.ReaderFactory; import org.apache.maven.shared.utils.StringUtils; -import org.apache.maven.shared.utils.io.DirectoryScanResult; -import org.apache.maven.shared.utils.io.DirectoryScanner; -import org.apache.maven.shared.utils.io.FileUtils; import org.apache.maven.shared.utils.logging.MessageBuilder; import org.apache.maven.shared.utils.logging.MessageUtils; import org.apache.maven.toolchain.Toolchain; @@ -85,6 +80,7 @@ import org.codehaus.plexus.compiler.util.scan.mapping.SuffixMapping; import org.codehaus.plexus.languages.java.jpms.JavaModuleDescriptor; import org.codehaus.plexus.languages.java.version.JavaVersion; +import org.codehaus.plexus.util.FileUtils; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.Opcodes; @@ -523,40 +519,6 @@ public abstract class AbstractCompilerMojo @Parameter( defaultValue = "false", property = "maven.compiler.forceJavacCompilerUse" ) private boolean forceJavacCompilerUse; - /** - * @since 3.0 needed for storing the status for the incremental build support. - */ - @Parameter( defaultValue = "${mojoExecution}", readonly = true, required = true ) - private MojoExecution mojoExecution; - - /** - * File extensions to check timestamp for incremental build. - * Default contains only class and jar. - * - * @since 3.1 - */ - @Parameter - private List fileExtensions; - - /** - *

to enable/disable incremental compilation feature.

- *

This leads to two different modes depending on the underlying compiler. The default javac compiler does the - * following:

- *
    - *
  • true (default) in this mode the compiler plugin determines whether any JAR files the - * current module depends on have changed in the current build run; or any source file was added, removed or - * changed since the last compilation. If this is the case, the compiler plugin recompiles all sources.
  • - *
  • false (not recommended) this only compiles source files which are newer than their - * corresponding class files, namely which have changed since the last compilation. This does not - * recompile other classes which use the changed class, potentially leaving them with references to methods that no - * longer exist, leading to errors at runtime.
  • - *
- * - * @since 3.1 - */ - @Parameter( defaultValue = "true", property = "maven.compiler.useIncrementalCompilation" ) - private boolean useIncrementalCompilation = true; - /** * Package info source files that only contain javadoc and no annotation on the package * can lead to no class file being generated by the compiler. This causes a file miss @@ -871,130 +833,31 @@ else if ( CompilerConfiguration.CompilerReuseStrategy.ReuseSame.getStrategy().eq compilerConfiguration.setForceJavacCompilerUse( forceJavacCompilerUse ); - boolean canUpdateTarget; - - IncrementalBuildHelper incrementalBuildHelper = new IncrementalBuildHelper( mojoExecution, session ); - final Set sources; - IncrementalBuildHelperRequest incrementalBuildHelperRequest = null; - - if ( useIncrementalCompilation ) + try { - getLog().debug( "useIncrementalCompilation enabled" ); - try - { - canUpdateTarget = compiler.canUpdateTarget( compilerConfiguration ); + // MCOMPILER-366: if sources contain the module-descriptor it must be used to define the modulepath + sources = getCompileSources( compiler, compilerConfiguration ); - sources = getCompileSources( compiler, compilerConfiguration ); - - preparePaths( sources ); - - incrementalBuildHelperRequest = new IncrementalBuildHelperRequest().inputFiles( sources ); - - DirectoryScanResult dsr = computeInputFileTreeChanges( incrementalBuildHelper, sources ); - - boolean idk = compiler.getCompilerOutputStyle() - .equals( CompilerOutputStyle.ONE_OUTPUT_FILE_FOR_ALL_INPUT_FILES ) && !canUpdateTarget; - boolean dependencyChanged = isDependencyChanged(); - boolean sourceChanged = isSourceChanged( compilerConfiguration, compiler ); - boolean inputFileTreeChanged = hasInputFileTreeChanged( dsr ); - // CHECKSTYLE_OFF: LineLength - if ( idk - || dependencyChanged - || sourceChanged - || inputFileTreeChanged ) - // CHECKSTYLE_ON: LineLength - { - String cause = idk ? "idk" : ( dependencyChanged ? "dependency" - : ( sourceChanged ? "source" : "input tree" ) ); - getLog().info( "Changes detected - recompiling the module! :" + cause ); - if ( showCompilationChanges ) - { - for ( String fileAdded : dsr.getFilesAdded() ) - { - getLog().info( "\t+ " + fileAdded ); - } - for ( String fileRemoved : dsr.getFilesRemoved() ) - { - getLog().info( "\t- " + fileRemoved ); - } - } - - compilerConfiguration.setSourceFiles( sources ); - } - else - { - getLog().info( "Nothing to compile - all classes are up to date" ); - - return; - } - } - catch ( CompilerException e ) + if ( getLog().isDebugEnabled() ) { - throw new MojoExecutionException( "Error while computing stale sources.", e ); - } - } - else - { - getLog().debug( "useIncrementalCompilation disabled" ); - - Set staleSources; - try - { - staleSources = - computeStaleSources( compilerConfiguration, compiler, getSourceInclusionScanner( staleMillis ) ); - - canUpdateTarget = compiler.canUpdateTarget( compilerConfiguration ); - - if ( compiler.getCompilerOutputStyle().equals( CompilerOutputStyle.ONE_OUTPUT_FILE_FOR_ALL_INPUT_FILES ) - && !canUpdateTarget ) + getLog().debug( "#sources: " + sources.size() ); + for ( File file : sources ) { - getLog().info( "RESCANNING!" ); - // TODO: This second scan for source files is sub-optimal - String inputFileEnding = compiler.getInputFileEnding( compilerConfiguration ); - - staleSources = computeStaleSources( compilerConfiguration, compiler, - getSourceInclusionScanner( inputFileEnding ) ); + getLog().debug( file.getPath() ); } - } - catch ( CompilerException e ) - { - throw new MojoExecutionException( "Error while computing stale sources.", e ); - } - - if ( staleSources.isEmpty() ) - { - getLog().info( "Nothing to compile - all classes are up to date" ); - return; - } - - compilerConfiguration.setSourceFiles( staleSources ); - - try - { - // MCOMPILER-366: if sources contain the module-descriptor it must be used to define the modulepath - sources = getCompileSources( compiler, compilerConfiguration ); + preparePaths( sources ); + } + catch ( CompilerException e ) + { + throw new MojoExecutionException( "Error while computing stale sources.", e ); + } - if ( getLog().isDebugEnabled() ) - { - getLog().debug( "#sources: " + sources.size() ); - for ( File file : sources ) - { - getLog().debug( file.getPath() ); - } - } + compilerConfiguration.setSourceFiles( sources ); - preparePaths( sources ); - } - catch ( CompilerException e ) - { - throw new MojoExecutionException( "Error while computing stale sources.", e ); - } - } - // Dividing pathElements of classPath and modulePath is based on sourceFiles compilerConfiguration.setClasspathEntries( getClasspathElements() ); @@ -1044,6 +907,29 @@ else if ( CompilerConfiguration.CompilerReuseStrategy.ReuseSame.getStrategy().eq } } } + + if ( Files.isDirectory( getOutputDirectory().getAbsoluteFile().toPath() ) ) + { + try ( Stream dirs = Files.list( getOutputDirectory().getAbsoluteFile().toPath() ) + .filter( p -> !"META-INF".equals( p.getFileName().toString() ) ) ) + { + dirs.forEach( p -> + { + try + { + FileUtils.deleteDirectory( p.toFile() ); + } + catch ( IOException e ) + { + throw new UncheckedIOException( e ); + } + } ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Could not zap output directory", e ); + } + } // ---------------------------------------------------------------------- // Dump configuration @@ -1243,16 +1129,6 @@ else if ( !values[0].equals( descriptor.name() ) ) CompilerResult compilerResult; - - if ( useIncrementalCompilation ) - { - incrementalBuildHelperRequest.outputDirectory( getOutputDirectory() ); - - incrementalBuildHelper.beforeRebuildExecution( incrementalBuildHelperRequest ); - - getLog().debug( "incrementalBuildHelper#beforeRebuildExecution" ); - } - try { try @@ -1286,21 +1162,6 @@ else if ( !values[0].equals( descriptor.name() ) ) } } - if ( useIncrementalCompilation ) - { - if ( incrementalBuildHelperRequest.getOutputDirectory().exists() ) - { - getLog().debug( "incrementalBuildHelper#afterRebuildExecution" ); - // now scan the same directory again and create a diff - incrementalBuildHelper.afterRebuildExecution( incrementalBuildHelperRequest ); - } - else - { - getLog().debug( - "skip incrementalBuildHelper#afterRebuildExecution as the output directory doesn't exist" ); - } - } - List warnings = new ArrayList<>(); List errors = new ArrayList<>(); List others = new ArrayList<>(); @@ -1544,35 +1405,6 @@ private Set getCompileSources( Compiler compiler, CompilerConfiguration co protected abstract Set getExcludes(); - /** - * @param compilerConfiguration - * @param compiler - * @return true if at least a single source file is newer than it's class file - */ - private boolean isSourceChanged( CompilerConfiguration compilerConfiguration, Compiler compiler ) - throws CompilerException, MojoExecutionException - { - Set staleSources = - computeStaleSources( compilerConfiguration, compiler, getSourceInclusionScanner( staleMillis ) ); - - if ( getLog().isDebugEnabled() || showCompilationChanges ) - { - for ( File f : staleSources ) - { - if ( showCompilationChanges ) - { - getLog().info( "Stale source detected: " + f.getAbsolutePath() ); - } - else - { - getLog().debug( "Stale source detected: " + f.getAbsolutePath() ); - } - } - } - return !staleSources.isEmpty(); - } - - /** * try to get thread count if a Maven 3 build, using reflection as the plugin must not be maven3 api dependent * @@ -1590,7 +1422,6 @@ protected Date getBuildStartTime() return buildStartTime == null ? new Date() : buildStartTime; } - private String getMemoryValue( String setting ) { String value = null; @@ -1660,50 +1491,6 @@ private boolean isDigits( String string ) return true; } - private Set computeStaleSources( CompilerConfiguration compilerConfiguration, Compiler compiler, - SourceInclusionScanner scanner ) - throws MojoExecutionException, CompilerException - { - SourceMapping mapping = getSourceMapping( compilerConfiguration, compiler ); - - File outputDirectory; - CompilerOutputStyle outputStyle = compiler.getCompilerOutputStyle(); - if ( outputStyle == CompilerOutputStyle.ONE_OUTPUT_FILE_FOR_ALL_INPUT_FILES ) - { - outputDirectory = buildDirectory; - } - else - { - outputDirectory = getOutputDirectory(); - } - - scanner.addSourceMapping( mapping ); - - Set staleSources = new HashSet<>(); - - for ( String sourceRoot : getCompileSourceRoots() ) - { - File rootFile = new File( sourceRoot ); - - if ( !rootFile.isDirectory() ) - { - continue; - } - - try - { - staleSources.addAll( scanner.getIncludedSources( rootFile, outputDirectory ) ); - } - catch ( InclusionScanException e ) - { - throw new MojoExecutionException( - "Error scanning source root: \'" + sourceRoot + "\' for stale files to recompile.", e ); - } - } - - return staleSources; - } - private SourceMapping getSourceMapping( CompilerConfiguration compilerConfiguration, Compiler compiler ) throws CompilerException, MojoExecutionException { @@ -1749,88 +1536,6 @@ private static List removeEmptyCompileSourceRoots( List compileS return newCompileSourceRootsList; } - /** - * We just compare the timestamps of all local dependency files (inter-module dependency classpath) and the own - * generated classes and if we got a file which is >= the build-started timestamp, then we caught a file which - * got changed during this build. - * - * @return true if at least one single dependency has changed. - */ - protected boolean isDependencyChanged() - { - if ( session == null ) - { - // we just cannot determine it, so don't do anything beside logging - getLog().info( "Cannot determine build start date, skipping incremental build detection." ); - return false; - } - - if ( fileExtensions == null || fileExtensions.isEmpty() ) - { - fileExtensions = Collections.unmodifiableList( Arrays.asList( "class", "jar" ) ); - } - - Date buildStartTime = getBuildStartTime(); - - List pathElements = new ArrayList<>(); - pathElements.addAll( getClasspathElements() ); - pathElements.addAll( getModulepathElements() ); - - for ( String pathElement : pathElements ) - { - File artifactPath = new File( pathElement ); - if ( artifactPath.isDirectory() || artifactPath.isFile() ) - { - if ( hasNewFile( artifactPath, buildStartTime ) ) - { - if ( showCompilationChanges ) - { - getLog().info( "New dependency detected: " + artifactPath.getAbsolutePath() ); - } - else - { - getLog().debug( "New dependency detected: " + artifactPath.getAbsolutePath() ); - } - return true; - } - } - } - - // obviously there was no new file detected. - return false; - } - - /** - * @param classPathEntry entry to check - * @param buildStartTime time build start - * @return if any changes occurred - */ - private boolean hasNewFile( File classPathEntry, Date buildStartTime ) - { - if ( !classPathEntry.exists() ) - { - return false; - } - - if ( classPathEntry.isFile() ) - { - return classPathEntry.lastModified() >= buildStartTime.getTime() - && fileExtensions.contains( FileUtils.getExtension( classPathEntry.getName() ) ); - } - - File[] children = classPathEntry.listFiles(); - - for ( File child : children ) - { - if ( hasNewFile( child, buildStartTime ) ) - { - return true; - } - } - - return false; - } - private List resolveProcessorPathEntries() throws MojoExecutionException { @@ -1939,47 +1644,6 @@ private String getMavenCompilerPluginVersion() return pomProperties.getProperty( "version" ); } - private DirectoryScanResult computeInputFileTreeChanges( IncrementalBuildHelper ibh, Set inputFiles ) - throws MojoExecutionException - { - File mojoConfigBase = ibh.getMojoStatusDirectory(); - File mojoConfigFile = new File( mojoConfigBase, INPUT_FILES_LST_FILENAME ); - - String[] oldInputFiles = new String[0]; - - if ( mojoConfigFile.exists() ) - { - try - { - oldInputFiles = FileUtils.fileReadArray( mojoConfigFile ); - } - catch ( IOException e ) - { - throw new MojoExecutionException( "Error reading old mojo status " + mojoConfigFile, e ); - } - } - - String[] inputFileNames = inputFiles.stream().map( File::getAbsolutePath ).toArray( String[]::new ); - - DirectoryScanResult dsr = DirectoryScanner.diffFiles( oldInputFiles, inputFileNames ); - - try - { - FileUtils.fileWriteArray( mojoConfigFile, inputFileNames ); - } - catch ( IOException e ) - { - throw new MojoExecutionException( "Error while storing the mojo status", e ); - } - - return dsr; - } - - private boolean hasInputFileTreeChanged( DirectoryScanResult dsr ) - { - return ( dsr.getFilesAdded().length > 0 || dsr.getFilesRemoved().length > 0 ); - } - public void setTarget( String target ) { this.target = target; diff --git a/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTestCase.java b/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTestCase.java index 6c12627d..3e748b81 100644 --- a/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTestCase.java +++ b/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTestCase.java @@ -388,7 +388,6 @@ private CompilerMojo getCompilerMojo( String pomXml ) setVariableValueToObject( mojo, "compilePath", Collections.EMPTY_LIST ); setVariableValueToObject( mojo, "session", getMockMavenSession() ); setVariableValueToObject( mojo, "project", getMockMavenProject() ); - setVariableValueToObject( mojo, "mojoExecution", getMockMojoExecution() ); setVariableValueToObject( mojo, "source", AbstractCompilerMojo.DEFAULT_SOURCE ); setVariableValueToObject( mojo, "target", AbstractCompilerMojo.DEFAULT_TARGET ); @@ -444,7 +443,6 @@ private TestCompilerMojo getTestCompilerMojo( CompilerMojo compilerMojo, String setVariableValueToObject( mojo, "project", project ); setVariableValueToObject( mojo, "testPath", testClasspathList ); setVariableValueToObject( mojo, "session", getMockMavenSession() ); - setVariableValueToObject( mojo, "mojoExecution", getMockMojoExecution() ); setVariableValueToObject( mojo, "source", AbstractCompilerMojo.DEFAULT_SOURCE ); setVariableValueToObject( mojo, "target", AbstractCompilerMojo.DEFAULT_TARGET ); @@ -469,18 +467,4 @@ private MavenSession getMockMavenSession() when( session.getCurrentProject() ).thenReturn( getMockMavenProject() ); return session; } - - private MojoExecution getMockMojoExecution() - { - MojoDescriptor md = new MojoDescriptor(); - md.setGoal( "compile" ); - - MojoExecution me = new MojoExecution( md ); - - PluginDescriptor pd = new PluginDescriptor(); - pd.setArtifactId( "maven-compiler-plugin" ); - md.setPluginDescriptor( pd ); - - return me; - } }