Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/it/MCOMPILER-578/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 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.java.version = 17+
invoker.goals = clean compile
invoker.goals.2 = compile
78 changes: 78 additions & 0 deletions src/it/MCOMPILER-578/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.compiler.it</groupId>
<artifactId>mcompiler-578</artifactId>
<version>1.0-SNAPSHOT</version>

<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>@project.version@</version>
<configuration>
<createMissingPackageInfoClass>false</createMissingPackageInfoClass>
</configuration>
<executions>
<execution>
<id>default-compile</id>
<configuration>
<release>${java.vm.specification.version}</release>
</configuration>
</execution>
<execution>
<id>base-modules-compile</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<release>11</release>
<includes>
<include>module-info.java</include>
</includes>
</configuration>
</execution>
<execution>
<id>base-compile</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<release>8</release>
<excludes>
<exclude>module-info.java</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
21 changes: 21 additions & 0 deletions src/it/MCOMPILER-578/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -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.
*/
module org.example {
exports org.example;
}
21 changes: 21 additions & 0 deletions src/it/MCOMPILER-578/src/main/java/org/example/Example.java
Original file line number Diff line number Diff line change
@@ -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.
*/
package org.example;

public class Example {}
19 changes: 19 additions & 0 deletions src/it/MCOMPILER-578/src/main/java/org/example/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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.
*/
package org.example;
35 changes: 35 additions & 0 deletions src/it/MCOMPILER-578/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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 majorVersion = { File classFile ->
assert classFile.isFile()
byte[] bytes = classFile.bytes
assert bytes.length >= 8
((bytes[6] & 0xFF) << 8) | (bytes[7] & 0xFF)
}

def exampleClass = new File( basedir, 'target/classes/org/example/Example.class' )
def exampleMajorVersion = majorVersion( exampleClass )
// major_version: 52 = Java 8, from the base-compile execution.
assert exampleMajorVersion == 52

def moduleInfoClass = new File( basedir, 'target/classes/module-info.class' )
def moduleInfoMajorVersion = majorVersion( moduleInfoClass )
// major_version: 55 = Java 11, from the base-modules-compile execution.
assert moduleInfoMajorVersion == 55
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@

compilerConfiguration.setWorkingDirectory(basedir);

compilerConfiguration.setCompilerVersion(compilerVersion);

Check warning on line 895 in src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-17-zulu 3.10.0-rc-1

setCompilerVersion(java.lang.String) in org.codehaus.plexus.compiler.CompilerConfiguration has been deprecated

Check warning on line 895 in src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-8-zulu 3.10.0-rc-1

setCompilerVersion(java.lang.String) in org.codehaus.plexus.compiler.CompilerConfiguration has been deprecated

Check warning on line 895 in src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-21-temurin 3.10.0-rc-1

setCompilerVersion(java.lang.String) in org.codehaus.plexus.compiler.CompilerConfiguration has been deprecated

Check warning on line 895 in src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-21-temurin 4.0.0-rc-4

setCompilerVersion(java.lang.String) in org.codehaus.plexus.compiler.CompilerConfiguration has been deprecated

Check warning on line 895 in src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-21-zulu 3.10.0-rc-1

setCompilerVersion(java.lang.String) in org.codehaus.plexus.compiler.CompilerConfiguration has been deprecated

Check warning on line 895 in src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-21-temurin 4.0.0-rc-4

setCompilerVersion(java.lang.String) in org.codehaus.plexus.compiler.CompilerConfiguration has been deprecated

Check warning on line 895 in src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-21-zulu 3.10.0-rc-1

setCompilerVersion(java.lang.String) in org.codehaus.plexus.compiler.CompilerConfiguration has been deprecated

Check warning on line 895 in src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-8-adopt-openj9 3.10.0-rc-1

setCompilerVersion(java.lang.String) in org.codehaus.plexus.compiler.CompilerConfiguration has been deprecated

Check warning on line 895 in src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-21-zulu 4.0.0-rc-4

setCompilerVersion(java.lang.String) in org.codehaus.plexus.compiler.CompilerConfiguration has been deprecated

Check warning on line 895 in src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-21-microsoft 3.10.0-rc-1

setCompilerVersion(java.lang.String) in org.codehaus.plexus.compiler.CompilerConfiguration has been deprecated

Check warning on line 895 in src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-8-temurin 3.10.0-rc-1

setCompilerVersion(java.lang.String) in org.codehaus.plexus.compiler.CompilerConfiguration has been deprecated

Check warning on line 895 in src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-8-zulu 3.10.0-rc-1

setCompilerVersion(java.lang.String) in org.codehaus.plexus.compiler.CompilerConfiguration has been deprecated

Check warning on line 895 in src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-25-zulu 3.10.0-rc-1

setCompilerVersion(java.lang.String) in org.codehaus.plexus.compiler.CompilerConfiguration has been deprecated

Check warning on line 895 in src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-21-temurin 3.10.0-rc-1

setCompilerVersion(java.lang.String) in org.codehaus.plexus.compiler.CompilerConfiguration has been deprecated

Check warning on line 895 in src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-25-temurin 3.10.0-rc-1

setCompilerVersion(java.lang.String) in org.codehaus.plexus.compiler.CompilerConfiguration has been deprecated

Check warning on line 895 in src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-21-microsoft 4.0.0-rc-4

setCompilerVersion(java.lang.String) in org.codehaus.plexus.compiler.CompilerConfiguration has been deprecated

Check warning on line 895 in src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-25-temurin 3.10.0-rc-1

setCompilerVersion(java.lang.String) in org.codehaus.plexus.compiler.CompilerConfiguration has been deprecated

Check warning on line 895 in src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-25-zulu 4.0.0-rc-4

setCompilerVersion(java.lang.String) in org.codehaus.plexus.compiler.CompilerConfiguration has been deprecated

Check warning on line 895 in src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-21-zulu 4.0.0-rc-4

setCompilerVersion(java.lang.String) in org.codehaus.plexus.compiler.CompilerConfiguration has been deprecated

Check warning on line 895 in src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-25-zulu 3.10.0-rc-1

setCompilerVersion(java.lang.String) in org.codehaus.plexus.compiler.CompilerConfiguration has been deprecated

Check warning on line 895 in src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-21-microsoft 3.10.0-rc-1

setCompilerVersion(java.lang.String) in org.codehaus.plexus.compiler.CompilerConfiguration has been deprecated

Check warning on line 895 in src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-25-temurin 4.0.0-rc-4

setCompilerVersion(java.lang.String) in org.codehaus.plexus.compiler.CompilerConfiguration has been deprecated

Check warning on line 895 in src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-21-adopt-openj9 3.10.0-rc-1

setCompilerVersion(java.lang.String) in org.codehaus.plexus.compiler.CompilerConfiguration has been deprecated

Check warning on line 895 in src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-25-temurin 4.0.0-rc-4

setCompilerVersion(java.lang.String) in org.codehaus.plexus.compiler.CompilerConfiguration has been deprecated

Check warning on line 895 in src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-21-adopt-openj9 3.10.0-rc-1

setCompilerVersion(java.lang.String) in org.codehaus.plexus.compiler.CompilerConfiguration has been deprecated

Check warning on line 895 in src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-21-microsoft 4.0.0-rc-4

setCompilerVersion(java.lang.String) in org.codehaus.plexus.compiler.CompilerConfiguration has been deprecated

Check warning on line 895 in src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-21-adopt-openj9 4.0.0-rc-4

setCompilerVersion(java.lang.String) in org.codehaus.plexus.compiler.CompilerConfiguration has been deprecated

Check warning on line 895 in src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-25-zulu 4.0.0-rc-4

setCompilerVersion(java.lang.String) in org.codehaus.plexus.compiler.CompilerConfiguration has been deprecated

Check warning on line 895 in src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-21-adopt-openj9 4.0.0-rc-4

setCompilerVersion(java.lang.String) in org.codehaus.plexus.compiler.CompilerConfiguration has been deprecated

compilerConfiguration.setBuildDirectory(buildDirectory);

Expand Down Expand Up @@ -930,6 +930,9 @@

final Set<File> sources;

Set<Path> outputs = Collections.emptySet();
String compilerExecution = mojoExecution.getGoal() + '@' + mojoExecution.getExecutionId();

IncrementalBuildHelperRequest incrementalBuildHelperRequest = null;

if (useIncrementalCompilation) {
Expand All @@ -941,6 +944,9 @@

preparePaths(sources);

// Expected output paths let us detect overwrites that IncrementalBuildHelper cannot see.
outputs = getOutputPaths(compilerConfiguration, compiler, sources);

incrementalBuildHelperRequest = new IncrementalBuildHelperRequest().inputFiles(sources);

// Strategies used to detect modifications.
Expand All @@ -954,9 +960,18 @@
String inputFileTreeChanged = hasInputFileTreeChanged(incrementalBuildHelper, sources)
? "added or removed source files"
: null;
// A different execution may have overwritten an otherwise up-to-date output.
String outputChanged = hasPreviouslyCompiledOutput(compilerExecution, outputs)
? "output from another compiler execution"
: null;

// Get the first cause for the rebuild compilation detection.
String cause = Stream.of(immutableOutputFile, dependencyChanged, sourceChanged, inputFileTreeChanged)
String cause = Stream.of(
immutableOutputFile,
dependencyChanged,
sourceChanged,
inputFileTreeChanged,
outputChanged)
.filter(Objects::nonNull)
.findFirst()
.orElse(null);
Expand Down Expand Up @@ -1267,6 +1282,8 @@
getLog().debug(
"skip incrementalBuildHelper#afterRebuildExecution as the output directory doesn't exist");
}
// Make these outputs visible to later compiler executions in this Maven session.
recordCompiledOutputs(compilerExecution, outputs);
}

List<CompilerMessage> warnings = new ArrayList<>();
Expand Down Expand Up @@ -1569,6 +1586,56 @@
return staleSources;
}

/**
* Maps selected sources to their expected compiler outputs.
*
* @param compilerConfiguration the compiler configuration
* @param compiler the selected compiler
* @param sources sources selected by the current execution
* @return normalized absolute output paths
*/
private Set<Path> getOutputPaths(CompilerConfiguration compilerConfiguration, Compiler compiler, Set<File> sources)
throws CompilerException, MojoExecutionException {
SourceMapping mapping = getSourceMapping(compilerConfiguration, compiler);

File outputDirectory =
compiler.getCompilerOutputStyle() == CompilerOutputStyle.ONE_OUTPUT_FILE_FOR_ALL_INPUT_FILES
? buildDirectory
: getOutputDirectory();
try {
return CompilationOutputRegistry.mapOutputs(mapping, outputDirectory, getCompileSourceRoots(), sources);
} catch (InclusionScanException e) {
throw new MojoExecutionException("Error mapping sources to their outputs.", e);
}
}

/**
* Checks whether a different compiler execution last processed an expected output.
*
* @param compilerExecution the current execution
* @param outputs expected outputs of the current execution
* @return whether an output overlaps with another execution
*/
private boolean hasPreviouslyCompiledOutput(String compilerExecution, Set<Path> outputs) {
Optional<Path> output = CompilationOutputRegistry.find(getPluginContext(), compilerExecution, outputs);
if (output.isPresent() && showCompilationChanges) {
getLog().info("\tOutput from another compiler execution: " + output.get());
} else if (output.isPresent()) {
getLog().debug("\tOutput from another compiler execution: " + output.get());
}
return output.isPresent();
}
Comment on lines +1619 to +1627

/**
* Registers the current execution as the last processor of its expected outputs.
*
* @param compilerExecution the current execution
* @param outputs expected outputs of the current execution
*/
private void recordCompiledOutputs(String compilerExecution, Set<Path> outputs) {
CompilationOutputRegistry.register(getPluginContext(), compilerExecution, outputs);
}

private SourceMapping getSourceMapping(CompilerConfiguration compilerConfiguration, Compiler compiler)
throws CompilerException, MojoExecutionException {
CompilerOutputStyle outputStyle = compiler.getCompilerOutputStyle();
Expand Down
Loading
Loading