diff --git a/plexus-compiler-api/pom.xml b/plexus-compiler-api/pom.xml
index 5d712ba6..a51f98d8 100644
--- a/plexus-compiler-api/pom.xml
+++ b/plexus-compiler-api/pom.xml
@@ -5,7 +5,7 @@
org.codehaus.plexus
plexus-compiler
- 2.14.2
+ 2.15.0
plexus-compiler-api
diff --git a/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/AbstractCompiler.java b/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/AbstractCompiler.java
index 13f5b47b..0acb4694 100644
--- a/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/AbstractCompiler.java
+++ b/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/AbstractCompiler.java
@@ -26,9 +26,9 @@
import java.io.File;
import java.io.IOException;
import java.util.Collections;
-import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import java.util.TreeSet;
import org.codehaus.plexus.util.DirectoryScanner;
import org.slf4j.Logger;
@@ -99,18 +99,22 @@ protected org.codehaus.plexus.logging.Logger getLogger() {
public abstract String getCompilerId();
+ @Override
public CompilerResult performCompile(CompilerConfiguration configuration) throws CompilerException {
throw new CompilerNotImplementedException("The performCompile method has not been implemented.");
}
+ @Override
public CompilerOutputStyle getCompilerOutputStyle() {
return compilerOutputStyle;
}
+ @Override
public String getInputFileEnding(CompilerConfiguration configuration) throws CompilerException {
return inputFileEnding;
}
+ @Override
public String getOutputFileEnding(CompilerConfiguration configuration) throws CompilerException {
if (compilerOutputStyle != CompilerOutputStyle.ONE_OUTPUT_FILE_PER_INPUT_FILE) {
throw new RuntimeException("This compiler implementation doesn't have one output file per input file.");
@@ -119,6 +123,7 @@ public String getOutputFileEnding(CompilerConfiguration configuration) throws Co
return outputFileEnding;
}
+ @Override
public String getOutputFile(CompilerConfiguration configuration) throws CompilerException {
if (compilerOutputStyle != CompilerOutputStyle.ONE_OUTPUT_FILE_FOR_ALL_INPUT_FILES) {
throw new RuntimeException("This compiler implementation doesn't have one output file for all files.");
@@ -127,6 +132,7 @@ public String getOutputFile(CompilerConfiguration configuration) throws Compiler
return outputFile;
}
+ @Override
public boolean canUpdateTarget(CompilerConfiguration configuration) throws CompilerException {
return true;
}
@@ -174,7 +180,7 @@ protected static Set getSourceFilesForSourceRoot(CompilerConfiguration c
String[] sourceDirectorySources = scanner.getIncludedFiles();
- Set sources = new HashSet<>();
+ Set sources = new TreeSet<>();
for (String sourceDirectorySource : sourceDirectorySources) {
File f = new File(sourceLocation, sourceDirectorySource);
@@ -186,7 +192,7 @@ protected static Set getSourceFilesForSourceRoot(CompilerConfiguration c
}
protected static String[] getSourceFiles(CompilerConfiguration config) {
- Set sources = new HashSet<>();
+ Set sources = new TreeSet<>();
Set sourceFiles = config.getSourceFiles();
@@ -262,19 +268,31 @@ private static String getCanonicalPath(File origFile) throws CompilerException {
protected void logCompiling(String[] sourceFiles, CompilerConfiguration config) {
if (log.isInfoEnabled()) {
- String to = (config.getWorkingDirectory() == null)
- ? config.getOutputLocation()
- : config.getWorkingDirectory()
- .toPath()
- .relativize(new File(config.getOutputLocation()).toPath())
- .toString();
log.info("Compiling "
+ (sourceFiles == null
? ""
: (sourceFiles.length + " source file" + (sourceFiles.length == 1 ? " " : "s ")))
+ "with "
+ getCompilerId() + " [" + config.describe() + "]" + " to "
- + to);
+ + getRelativeWorkingDirectory(config));
}
}
+
+ private static String getRelativeWorkingDirectory(CompilerConfiguration config) {
+ String to;
+ if (config.getWorkingDirectory() == null) {
+ to = config.getOutputLocation();
+ } else {
+ try {
+ to = config.getWorkingDirectory()
+ .toPath()
+ .relativize(new File(config.getOutputLocation()).toPath())
+ .toString();
+ } catch (IllegalArgumentException e) {
+ // may happen on Windows if the working directory is on a different drive
+ to = config.getOutputLocation();
+ }
+ }
+ return to;
+ }
}
diff --git a/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/CompilerConfiguration.java b/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/CompilerConfiguration.java
index 2907988e..a1680c2e 100644
--- a/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/CompilerConfiguration.java
+++ b/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/CompilerConfiguration.java
@@ -500,10 +500,20 @@ public void setOptimize(boolean optimize) {
this.optimize = optimize;
}
+ /**
+ * @deprecated Don't use any longer because this is just the configured version which does not necessarily match the version
+ * of the actually executed compiler binary
+ */
+ @Deprecated
public String getCompilerVersion() {
return compilerVersion;
}
+ /**
+ * @deprecated Don't use any longer because this is just the configured version which does not necessarily match the version
+ * of the actually executed compiler binary
+ */
+ @Deprecated
public void setCompilerVersion(String compilerVersion) {
this.compilerVersion = compilerVersion;
}
diff --git a/plexus-compiler-its/pom.xml b/plexus-compiler-its/pom.xml
index 9cfda9f1..387dd83b 100644
--- a/plexus-compiler-its/pom.xml
+++ b/plexus-compiler-its/pom.xml
@@ -5,7 +5,7 @@
org.codehaus.plexus
plexus-compiler
- 2.14.2
+ 2.15.0
plexus-compiler-its
@@ -36,6 +36,10 @@
org.codehaus.plexus
plexus-compiler-javac-errorprone
+
+ org.codehaus.plexus
+ plexus-compiler-manager
+
diff --git a/plexus-compiler-its/src/main/it/MCOMPILER-346-mre/pom.xml b/plexus-compiler-its/src/main/it/MCOMPILER-346-mre/pom.xml
index c8a739f3..661cafa8 100644
--- a/plexus-compiler-its/src/main/it/MCOMPILER-346-mre/pom.xml
+++ b/plexus-compiler-its/src/main/it/MCOMPILER-346-mre/pom.xml
@@ -64,6 +64,11 @@
plexus-compiler-api
${plexus.compiler.version}
+
+ org.codehaus.plexus
+ plexus-compiler-manager
+ ${plexus.compiler.version}
+
org.codehaus.plexus
plexus-compiler-javac
diff --git a/plexus-compiler-its/src/main/it/aspectj-compiler/pom.xml b/plexus-compiler-its/src/main/it/aspectj-compiler/pom.xml
index 4638fbcb..f9c68382 100644
--- a/plexus-compiler-its/src/main/it/aspectj-compiler/pom.xml
+++ b/plexus-compiler-its/src/main/it/aspectj-compiler/pom.xml
@@ -48,6 +48,11 @@
plexus-compiler-api
${plexus.compiler.version}
+
+ org.codehaus.plexus
+ plexus-compiler-manager
+ ${plexus.compiler.version}
+
org.codehaus.plexus
plexus-compiler-aspectj
diff --git a/plexus-compiler-its/src/main/it/eclipse-compiler-mapstruct/pom.xml b/plexus-compiler-its/src/main/it/eclipse-compiler-mapstruct/pom.xml
index 39d0796b..77c88a83 100644
--- a/plexus-compiler-its/src/main/it/eclipse-compiler-mapstruct/pom.xml
+++ b/plexus-compiler-its/src/main/it/eclipse-compiler-mapstruct/pom.xml
@@ -24,18 +24,16 @@
4.0.0
org.codehaus.plexus.compiler.it
- simple-javac
+ eclipse-compiler-mapstruct
1.0-SNAPSHOT
- Test for default configuration
-
UTF-8
UTF-8
1.8
1.8
@pom.version@
- 1.5.2.Final
+ 1.5.5.Final
@@ -61,6 +59,11 @@
plexus-compiler-api
${plexus.compiler.version}
+
+ org.codehaus.plexus
+ plexus-compiler-manager
+ ${plexus.compiler.version}
+
org.codehaus.plexus
plexus-compiler-eclipse
diff --git a/plexus-compiler-its/src/main/it/eclipse-compiler-procpath/invoker.properties b/plexus-compiler-its/src/main/it/eclipse-compiler-procpath/invoker.properties
new file mode 100644
index 00000000..3b37b5f6
--- /dev/null
+++ b/plexus-compiler-its/src/main/it/eclipse-compiler-procpath/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.maven.version = 3.9.6+
+
+invoker.goals = clean compile
+invoker.buildResult = success
diff --git a/plexus-compiler-its/src/main/it/eclipse-compiler-procpath/pom.xml b/plexus-compiler-its/src/main/it/eclipse-compiler-procpath/pom.xml
new file mode 100644
index 00000000..b3238814
--- /dev/null
+++ b/plexus-compiler-its/src/main/it/eclipse-compiler-procpath/pom.xml
@@ -0,0 +1,84 @@
+
+
+
+
+ 4.0.0
+
+ org.codehaus.plexus.compiler.it
+ eclipse-compiler-procpath
+ 1.0-SNAPSHOT
+
+
+ UTF-8
+ UTF-8
+ 1.8
+ 1.8
+ @pom.version@
+ 1.5.5.Final
+
+
+
+
+ org.mapstruct
+ mapstruct
+ ${org.mapstruct.version}
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ @maven.compiler.version@
+
+ eclipse
+
+
+ org.mapstruct
+ mapstruct-processor
+ ${org.mapstruct.version}
+
+
+
+
+
+ org.codehaus.plexus
+ plexus-compiler-api
+ ${plexus.compiler.version}
+
+
+ org.codehaus.plexus
+ plexus-compiler-manager
+ ${plexus.compiler.version}
+
+
+ org.codehaus.plexus
+ plexus-compiler-eclipse
+ ${plexus.compiler.version}
+
+
+
+
+
+
+
diff --git a/plexus-compiler-its/src/main/it/eclipse-compiler-procpath/src/main/java/Car.java b/plexus-compiler-its/src/main/it/eclipse-compiler-procpath/src/main/java/Car.java
new file mode 100644
index 00000000..80fe8cd4
--- /dev/null
+++ b/plexus-compiler-its/src/main/it/eclipse-compiler-procpath/src/main/java/Car.java
@@ -0,0 +1,24 @@
+/*
+ * 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 Car
+{
+ public String make;
+ public int numberOfSeats;
+}
diff --git a/plexus-compiler-its/src/main/it/eclipse-compiler-procpath/src/main/java/CarDto.java b/plexus-compiler-its/src/main/it/eclipse-compiler-procpath/src/main/java/CarDto.java
new file mode 100644
index 00000000..285dd338
--- /dev/null
+++ b/plexus-compiler-its/src/main/it/eclipse-compiler-procpath/src/main/java/CarDto.java
@@ -0,0 +1,24 @@
+/*
+ * 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 CarDto
+{
+ public String make;
+ public int seatCount;
+}
diff --git a/plexus-compiler-its/src/main/it/eclipse-compiler-procpath/src/main/java/CarMapper.java b/plexus-compiler-its/src/main/it/eclipse-compiler-procpath/src/main/java/CarMapper.java
new file mode 100644
index 00000000..ba869a16
--- /dev/null
+++ b/plexus-compiler-its/src/main/it/eclipse-compiler-procpath/src/main/java/CarMapper.java
@@ -0,0 +1,32 @@
+/*
+ * 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 org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+import org.mapstruct.factory.Mappers;
+
+@Mapper
+public interface CarMapper
+{
+
+ CarMapper INSTANCE = Mappers.getMapper( CarMapper.class );
+
+ @Mapping( source = "numberOfSeats", target = "seatCount" )
+ CarDto carToCarDto( Car car );
+}
diff --git a/plexus-compiler-its/src/main/it/eclipse-compiler-procpath/verify.groovy b/plexus-compiler-its/src/main/it/eclipse-compiler-procpath/verify.groovy
new file mode 100644
index 00000000..9cbd3c62
--- /dev/null
+++ b/plexus-compiler-its/src/main/it/eclipse-compiler-procpath/verify.groovy
@@ -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.
+ */
+def mapperImplClass = new File( basedir, "target/classes/CarMapperImpl.class" )
+assert mapperImplClass.exists()
+
diff --git a/plexus-compiler-its/src/main/it/error-prone-compiler/pom.xml b/plexus-compiler-its/src/main/it/error-prone-compiler/pom.xml
index 1a63924f..87f7947f 100644
--- a/plexus-compiler-its/src/main/it/error-prone-compiler/pom.xml
+++ b/plexus-compiler-its/src/main/it/error-prone-compiler/pom.xml
@@ -83,6 +83,11 @@
plexus-compiler-api
${plexus.compiler.version}
+
+ org.codehaus.plexus
+ plexus-compiler-manager
+ ${plexus.compiler.version}
+
org.codehaus.plexus
plexus-compiler-javac-errorprone
diff --git a/plexus-compiler-its/src/main/it/missing-warnings/pom.xml b/plexus-compiler-its/src/main/it/missing-warnings/pom.xml
index 42af0b33..81200739 100644
--- a/plexus-compiler-its/src/main/it/missing-warnings/pom.xml
+++ b/plexus-compiler-its/src/main/it/missing-warnings/pom.xml
@@ -25,6 +25,11 @@
plexus-compiler-api
${plexus.compiler.version}
+
+ org.codehaus.plexus
+ plexus-compiler-manager
+ ${plexus.compiler.version}
+
org.codehaus.plexus
plexus-compiler-javac
@@ -42,4 +47,4 @@
UTF-8
@pom.version@
-
\ No newline at end of file
+
diff --git a/plexus-compiler-its/src/main/it/simple-eclipse-compiler-fail/pom.xml b/plexus-compiler-its/src/main/it/simple-eclipse-compiler-fail/pom.xml
index 03a77f48..d8a2ce41 100644
--- a/plexus-compiler-its/src/main/it/simple-eclipse-compiler-fail/pom.xml
+++ b/plexus-compiler-its/src/main/it/simple-eclipse-compiler-fail/pom.xml
@@ -61,6 +61,11 @@
plexus-compiler-api
${plexus.compiler.version}
+
+ org.codehaus.plexus
+ plexus-compiler-manager
+ ${plexus.compiler.version}
+
org.codehaus.plexus
plexus-compiler-eclipse
diff --git a/plexus-compiler-its/src/main/it/simple-eclipse-compiler/pom.xml b/plexus-compiler-its/src/main/it/simple-eclipse-compiler/pom.xml
index 54694e38..365df38a 100644
--- a/plexus-compiler-its/src/main/it/simple-eclipse-compiler/pom.xml
+++ b/plexus-compiler-its/src/main/it/simple-eclipse-compiler/pom.xml
@@ -61,6 +61,11 @@
plexus-compiler-api
${plexus.compiler.version}
+
+ org.codehaus.plexus
+ plexus-compiler-manager
+ ${plexus.compiler.version}
+
org.codehaus.plexus
plexus-compiler-eclipse
diff --git a/plexus-compiler-its/src/main/it/simple-javac-fork/pom.xml b/plexus-compiler-its/src/main/it/simple-javac-fork/pom.xml
index 2ed55a79..2e654657 100644
--- a/plexus-compiler-its/src/main/it/simple-javac-fork/pom.xml
+++ b/plexus-compiler-its/src/main/it/simple-javac-fork/pom.xml
@@ -63,6 +63,11 @@
plexus-compiler-api
${plexus.compiler.version}
+
+ org.codehaus.plexus
+ plexus-compiler-manager
+ ${plexus.compiler.version}
+
org.codehaus.plexus
plexus-compiler-javac
diff --git a/plexus-compiler-its/src/main/it/simple-javac/pom.xml b/plexus-compiler-its/src/main/it/simple-javac/pom.xml
index a400f268..ca0f36d7 100644
--- a/plexus-compiler-its/src/main/it/simple-javac/pom.xml
+++ b/plexus-compiler-its/src/main/it/simple-javac/pom.xml
@@ -63,6 +63,11 @@
plexus-compiler-api
${plexus.compiler.version}
+
+ org.codehaus.plexus
+ plexus-compiler-manager
+ ${plexus.compiler.version}
+
org.codehaus.plexus
plexus-compiler-javac
diff --git a/plexus-compiler-manager/pom.xml b/plexus-compiler-manager/pom.xml
index 74d40139..efc953b3 100644
--- a/plexus-compiler-manager/pom.xml
+++ b/plexus-compiler-manager/pom.xml
@@ -5,7 +5,7 @@
org.codehaus.plexus
plexus-compiler
- 2.14.2
+ 2.15.0
plexus-compiler-manager
@@ -21,6 +21,10 @@
javax.inject
javax.inject
+
+ org.slf4j
+ slf4j-api
+
org.codehaus.plexus
plexus-xml
diff --git a/plexus-compiler-manager/src/main/java/org/codehaus/plexus/compiler/manager/DefaultCompilerManager.java b/plexus-compiler-manager/src/main/java/org/codehaus/plexus/compiler/manager/DefaultCompilerManager.java
index 29af62f7..b8024a22 100644
--- a/plexus-compiler-manager/src/main/java/org/codehaus/plexus/compiler/manager/DefaultCompilerManager.java
+++ b/plexus-compiler-manager/src/main/java/org/codehaus/plexus/compiler/manager/DefaultCompilerManager.java
@@ -25,30 +25,52 @@
*/
import javax.inject.Inject;
import javax.inject.Named;
+import javax.inject.Provider;
import java.util.Map;
import org.codehaus.plexus.compiler.Compiler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* @author Trygve Laugstøl
*/
@Named
public class DefaultCompilerManager implements CompilerManager {
+ private static final String ERROR_MESSAGE = "Compiler '{}' could not be instantiated or injected properly. "
+ + "If you spelled the compiler ID correctly and all necessary dependencies are on the classpath, "
+ + "then next you can try running the build with -Dsisu.debug, looking for exceptions.";
+ private static final String ERROR_MESSAGE_DETAIL = "TypeNotPresentException caused by UnsupportedClassVersionError "
+ + "might indicate, that the compiler needs a more recent Java runtime. "
+ + "IllegalArgumentException in ClassReader. might mean, that you need to upgrade Maven.";
+
@Inject
- private Map compilers;
+ private Map> compilers;
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
// ----------------------------------------------------------------------
// CompilerManager Implementation
// ----------------------------------------------------------------------
public Compiler getCompiler(String compilerId) throws NoSuchCompilerException {
- Compiler compiler = compilers.get(compilerId);
+ // Provider is lazy -> presence of provider means compiler is present, but not yet constructed
+ Provider compilerProvider = compilers.get(compilerId);
- if (compiler == null) {
+ if (compilerProvider == null) {
+ // Compiler could not be injected for some reason
+ log.error(ERROR_MESSAGE + " " + ERROR_MESSAGE_DETAIL, compilerId);
throw new NoSuchCompilerException(compilerId);
}
- return compiler;
+ // Provider exists, but compiler was not created yet
+ try {
+ return compilerProvider.get();
+ } catch (Exception e) {
+ // DI could not construct compiler
+ log.error(ERROR_MESSAGE, compilerId);
+ throw new NoSuchCompilerException(compilerId, e);
+ }
}
}
diff --git a/plexus-compiler-manager/src/main/java/org/codehaus/plexus/compiler/manager/NoSuchCompilerException.java b/plexus-compiler-manager/src/main/java/org/codehaus/plexus/compiler/manager/NoSuchCompilerException.java
index e40c6462..135f0950 100644
--- a/plexus-compiler-manager/src/main/java/org/codehaus/plexus/compiler/manager/NoSuchCompilerException.java
+++ b/plexus-compiler-manager/src/main/java/org/codehaus/plexus/compiler/manager/NoSuchCompilerException.java
@@ -31,8 +31,11 @@ public class NoSuchCompilerException extends Exception {
private final String compilerId;
public NoSuchCompilerException(String compilerId) {
- super("No such compiler '" + compilerId + "'.");
+ this(compilerId, null);
+ }
+ public NoSuchCompilerException(String compilerId, Throwable cause) {
+ super("No such compiler '" + compilerId + "'", cause);
this.compilerId = compilerId;
}
diff --git a/plexus-compiler-test/pom.xml b/plexus-compiler-test/pom.xml
index f80f1b4b..01fb72d3 100644
--- a/plexus-compiler-test/pom.xml
+++ b/plexus-compiler-test/pom.xml
@@ -5,7 +5,7 @@
org.codehaus.plexus
plexus-compiler
- 2.14.2
+ 2.15.0
plexus-compiler-test
@@ -13,6 +13,10 @@
Plexus Compiler Test Harness
+
+ javax.inject
+ javax.inject
+
org.codehaus.plexus
plexus-compiler-api
@@ -36,22 +40,12 @@
org.apache.maven
maven-artifact
- ${maven.version}
+ ${mavenVersion}
org.apache.maven
maven-core
- ${maven.version}
-
-
- org.apache.maven
- maven-compat
- ${maven.version}
-
-
- org.apache.maven
- maven-settings
- ${maven.version}
+ ${mavenVersion}
org.codehaus.plexus
diff --git a/plexus-compiler-test/src/main/java/org/codehaus/plexus/compiler/AbstractCompilerTest.java b/plexus-compiler-test/src/main/java/org/codehaus/plexus/compiler/AbstractCompilerTest.java
index 977ffbd1..09ab0b6b 100644
--- a/plexus-compiler-test/src/main/java/org/codehaus/plexus/compiler/AbstractCompilerTest.java
+++ b/plexus-compiler-test/src/main/java/org/codehaus/plexus/compiler/AbstractCompilerTest.java
@@ -34,19 +34,19 @@
import java.util.Map;
import java.util.stream.Collectors;
+import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.handler.DefaultArtifactHandler;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.repository.DefaultArtifactRepository;
-import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.artifact.versioning.VersionRange;
-import org.apache.maven.settings.Settings;
-import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader;
import org.codehaus.plexus.testing.PlexusTest;
import org.codehaus.plexus.util.FileUtils;
-import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.StringUtils;
+import org.eclipse.aether.DefaultRepositorySystemSession;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.impl.LocalRepositoryProvider;
+import org.eclipse.aether.repository.LocalRepository;
+import org.eclipse.aether.repository.LocalRepositoryManager;
import org.hamcrest.io.FileMatchers;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -54,6 +54,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
/**
*
@@ -70,28 +71,25 @@ public abstract class AbstractCompilerTest {
private Map compilers;
@Inject
- private ArtifactRepositoryLayout repositoryLayout;
+ private LocalRepositoryProvider localRepositoryProvider;
- private ArtifactRepository localRepository;
+ private LocalRepositoryManager localRepositoryManager;
protected abstract String getRoleHint();
@BeforeEach
final void setUpLocalRepo() throws Exception {
String localRepo = System.getProperty("maven.repo.local");
+ assertThat("system property maven.repo.local", localRepo, notNullValue());
- if (localRepo == null) {
- File settingsFile = new File(System.getProperty("user.home"), ".m2/settings.xml");
- if (settingsFile.exists()) {
- Settings settings = new SettingsXpp3Reader().read(ReaderFactory.newXmlReader(settingsFile));
- localRepo = settings.getLocalRepository();
- }
- }
- if (localRepo == null) {
- localRepo = System.getProperty("user.home") + "/.m2/repository";
- }
+ LocalRepository localRepository = new LocalRepository(localRepo);
+ assertThat(
+ "test prerequisite: local repository path: " + localRepository.getBasedir(),
+ localRepository.getBasedir(),
+ FileMatchers.aReadableFile());
- localRepository = new DefaultArtifactRepository("local", "file://" + localRepo, repositoryLayout);
+ RepositorySystemSession session = new DefaultRepositorySystemSession();
+ localRepositoryManager = localRepositoryProvider.newLocalRepositoryManager(session, localRepository);
}
protected void setCompilerDebug(boolean flag) {
@@ -116,7 +114,7 @@ protected List getClasspath() throws Exception {
File file = getLocalArtifactPath("commons-lang", "commons-lang", "2.0", "jar");
assertThat(
- "test prerequisite: commons-lang library must be available in local repository, expected ",
+ "test prerequisite: commons-lang library must be available in local repository at " + file,
file,
FileMatchers.aReadableFile());
@@ -330,6 +328,8 @@ protected String getJavaVersion() {
}
protected File getLocalArtifactPath(Artifact artifact) {
- return new File(localRepository.getBasedir(), localRepository.pathOf(artifact));
+ return new File(
+ localRepositoryManager.getRepository().getBasedir(),
+ localRepositoryManager.getPathForLocalArtifact(RepositoryUtils.toArtifact(artifact)));
}
}
diff --git a/plexus-compilers/plexus-compiler-aspectj/pom.xml b/plexus-compilers/plexus-compiler-aspectj/pom.xml
index 9584b07a..4a4e12fd 100644
--- a/plexus-compilers/plexus-compiler-aspectj/pom.xml
+++ b/plexus-compilers/plexus-compiler-aspectj/pom.xml
@@ -5,7 +5,7 @@
org.codehaus.plexus
plexus-compilers
- 2.14.2
+ 2.15.0
plexus-compiler-aspectj
@@ -32,6 +32,10 @@
aspectjtools
${aspectj.version}
+
+ org.codehaus.plexus
+ plexus-utils
+
diff --git a/plexus-compilers/plexus-compiler-csharp/pom.xml b/plexus-compilers/plexus-compiler-csharp/pom.xml
index dadb83e6..e3c34baa 100644
--- a/plexus-compilers/plexus-compiler-csharp/pom.xml
+++ b/plexus-compilers/plexus-compiler-csharp/pom.xml
@@ -5,7 +5,7 @@
org.codehaus.plexus
plexus-compilers
- 2.14.2
+ 2.15.0
plexus-compiler-csharp
@@ -22,11 +22,6 @@
org.codehaus.plexus
plexus-utils
-
- org.junit.jupiter
- junit-jupiter-api
- test
-
org.hamcrest
hamcrest
diff --git a/plexus-compilers/plexus-compiler-eclipse/pom.xml b/plexus-compilers/plexus-compiler-eclipse/pom.xml
index bb8913d6..50388318 100644
--- a/plexus-compilers/plexus-compiler-eclipse/pom.xml
+++ b/plexus-compilers/plexus-compiler-eclipse/pom.xml
@@ -5,7 +5,7 @@
org.codehaus.plexus
plexus-compilers
- 2.14.2
+ 2.15.0
plexus-compiler-eclipse
@@ -18,10 +18,6 @@
-
- org.codehaus.plexus
- plexus-compiler-api
-
org.codehaus.plexus
plexus-utils
@@ -36,9 +32,8 @@
javax.inject
- org.junit.jupiter
- junit-jupiter-api
- test
+ org.slf4j
+ slf4j-api
org.junit.jupiter
@@ -53,7 +48,7 @@
org.codehaus.plexus
plexus-testing
- compile
+ test
diff --git a/plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler.java b/plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler.java
index ae5ff088..f14db674 100644
--- a/plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler.java
+++ b/plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler.java
@@ -147,7 +147,21 @@ public CompilerResult performCompile(CompilerConfiguration config) throws Compil
args.add("-d");
args.add(config.getOutputLocation());
+ // -- classpath
+ // must be done before annotation processors: https://bugs.eclipse.org/bugs/show_bug.cgi?id=573833
+ List classpathEntries = new ArrayList<>(config.getClasspathEntries());
+ classpathEntries.add(config.getOutputLocation());
+ args.add("-classpath");
+ args.add(getPathString(classpathEntries));
+
+ List modulepathEntries = config.getModulepathEntries();
+ if (modulepathEntries != null && !modulepathEntries.isEmpty()) {
+ args.add("--module-path");
+ args.add(getPathString(modulepathEntries));
+ }
+
// Annotation processors defined?
+ // must be done after classpath: https://bugs.eclipse.org/bugs/show_bug.cgi?id=573833
if (!isPreJava1_6(config)) {
File generatedSourcesDir = config.getGeneratedSourcesDirectory();
if (generatedSourcesDir != null) {
@@ -198,18 +212,6 @@ public CompilerResult performCompile(CompilerConfiguration config) throws Compil
}
}
- // -- classpath
- List classpathEntries = new ArrayList<>(config.getClasspathEntries());
- classpathEntries.add(config.getOutputLocation());
- args.add("-classpath");
- args.add(getPathString(classpathEntries));
-
- List modulepathEntries = config.getModulepathEntries();
- if (modulepathEntries != null && !modulepathEntries.isEmpty()) {
- args.add("--module-path");
- args.add(getPathString(modulepathEntries));
- }
-
// Collect sources
List allSources = Arrays.asList(getSourceFiles(config));
List messageList = new ArrayList<>();
diff --git a/plexus-compilers/plexus-compiler-javac-errorprone/pom.xml b/plexus-compilers/plexus-compiler-javac-errorprone/pom.xml
index 967ac3c8..54a67bee 100644
--- a/plexus-compilers/plexus-compiler-javac-errorprone/pom.xml
+++ b/plexus-compilers/plexus-compiler-javac-errorprone/pom.xml
@@ -5,7 +5,7 @@
org.codehaus.plexus
plexus-compilers
- 2.14.2
+ 2.15.0
plexus-compiler-javac-errorprone
@@ -20,10 +20,6 @@
-
- org.codehaus.plexus
- plexus-utils
-
org.codehaus.plexus
plexus-compiler-javac
diff --git a/plexus-compilers/plexus-compiler-javac/pom.xml b/plexus-compilers/plexus-compiler-javac/pom.xml
index 3440da79..43d4ae83 100644
--- a/plexus-compilers/plexus-compiler-javac/pom.xml
+++ b/plexus-compilers/plexus-compiler-javac/pom.xml
@@ -5,7 +5,7 @@
org.codehaus.plexus
plexus-compilers
- 2.14.2
+ 2.15.0
plexus-compiler-javac
@@ -23,9 +23,8 @@
javax.inject
- org.junit.jupiter
- junit-jupiter-api
- test
+ org.slf4j
+ slf4j-api
org.junit.jupiter
diff --git a/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java b/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java
index 1e97f8e7..f25e099b 100644
--- a/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java
+++ b/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java
@@ -59,12 +59,16 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Deque;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Properties;
+import java.util.Set;
import java.util.StringTokenizer;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedDeque;
+import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.codehaus.plexus.compiler.AbstractCompiler;
@@ -108,6 +112,11 @@ public class JavacCompiler extends AbstractCompiler {
private final Deque> javacClasses = new ConcurrentLinkedDeque<>();
+ private static final Pattern JAVA_MAJOR_AND_MINOR_VERSION_PATTERN = Pattern.compile("\\d+(\\.\\d+)?");
+
+ /** Cache of javac version per executable (never invalidated) */
+ private static final Map VERSION_PER_EXECUTABLE = new ConcurrentHashMap<>();
+
@Inject
private InProcessCompiler inProcessCompiler;
@@ -128,6 +137,44 @@ public String getCompilerId() {
return "javac";
}
+ private String getInProcessJavacVersion() throws CompilerException {
+ return System.getProperty("java.version");
+ }
+
+ private String getOutOfProcessJavacVersion(String executable) throws CompilerException {
+ String version = VERSION_PER_EXECUTABLE.get(executable);
+ if (version == null) {
+ Commandline cli = new Commandline();
+ cli.setExecutable(executable);
+ /*
+ * The option "-version" should be supported by javac since 1.6 (https://docs.oracle.com/javase/6/docs/technotes/tools/solaris/javac.html)
+ * up to 21 (https://docs.oracle.com/en/java/javase/21/docs/specs/man/javac.html#standard-options)
+ */
+ cli.addArguments(new String[] {"-version"}); //
+ CommandLineUtils.StringStreamConsumer out = new CommandLineUtils.StringStreamConsumer();
+ try {
+ int exitCode = CommandLineUtils.executeCommandLine(cli, out, out);
+ if (exitCode != 0) {
+ throw new CompilerException("Could not retrieve version from " + executable + ". Exit code "
+ + exitCode + ", Output: " + out.getOutput());
+ }
+ } catch (CommandLineException e) {
+ throw new CompilerException("Error while executing the external compiler " + executable, e);
+ }
+ version = extractMajorAndMinorVersion(out.getOutput());
+ VERSION_PER_EXECUTABLE.put(executable, version);
+ }
+ return version;
+ }
+
+ static String extractMajorAndMinorVersion(String text) {
+ Matcher matcher = JAVA_MAJOR_AND_MINOR_VERSION_PATTERN.matcher(text);
+ if (!matcher.find()) {
+ throw new IllegalArgumentException("Could not extract version from \"" + text + "\"");
+ }
+ return matcher.group();
+ }
+
@Override
public CompilerResult performCompile(CompilerConfiguration config) throws CompilerException {
File destinationDir = new File(config.getOutputLocation());
@@ -144,27 +191,25 @@ public CompilerResult performCompile(CompilerConfiguration config) throws Compil
logCompiling(sourceFiles, config);
- String[] args = buildCompilerArguments(config, sourceFiles);
+ final String javacVersion;
+ final String executable;
+ if (config.isFork()) {
+ executable = getJavacExecutable(config);
+ javacVersion = getOutOfProcessJavacVersion(executable);
+ } else {
+ javacVersion = getInProcessJavacVersion();
+ executable = null;
+ }
+
+ String[] args = buildCompilerArguments(config, sourceFiles, javacVersion);
CompilerResult result;
if (config.isFork()) {
- String executable = config.getExecutable();
-
- if (StringUtils.isEmpty(executable)) {
- try {
- executable = getJavacExecutable();
- } catch (IOException e) {
- if (getLog().isWarnEnabled()) {
- getLog().warn("Unable to autodetect 'javac' path, using 'javac' from the environment.");
- }
- executable = "javac";
- }
- }
result = compileOutOfProcess(config, executable, args);
} else {
- if (isJava16() && !config.isForceJavacCompilerUse()) {
+ if (hasJavaxToolProvider() && !config.isForceJavacCompilerUse()) {
// use fqcn to prevent loading of the class on 1.5 environment !
result = inProcessCompiler().compileInProcess(args, config, sourceFiles);
} else {
@@ -179,7 +224,11 @@ protected InProcessCompiler inProcessCompiler() {
return inProcessCompiler;
}
- protected static boolean isJava16() {
+ /**
+ *
+ * @return {@code true} if the current context class loader has access to {@code javax.tools.ToolProvider}
+ */
+ protected static boolean hasJavaxToolProvider() {
try {
Thread.currentThread().getContextClassLoader().loadClass("javax.tools.ToolProvider");
return true;
@@ -189,10 +238,18 @@ protected static boolean isJava16() {
}
public String[] createCommandLine(CompilerConfiguration config) throws CompilerException {
- return buildCompilerArguments(config, getSourceFiles(config));
+ final String javacVersion;
+ if (config.isFork()) {
+ String executable = getJavacExecutable(config);
+ javacVersion = getOutOfProcessJavacVersion(executable);
+ } else {
+ javacVersion = getInProcessJavacVersion();
+ }
+ return buildCompilerArguments(config, getSourceFiles(config), javacVersion);
}
- public static String[] buildCompilerArguments(CompilerConfiguration config, String[] sourceFiles) {
+ public static String[] buildCompilerArguments(
+ CompilerConfiguration config, String[] sourceFiles, String javacVersion) {
List args = new ArrayList<>();
// ----------------------------------------------------------------------
@@ -231,11 +288,11 @@ public static String[] buildCompilerArguments(CompilerConfiguration config, Stri
args.add(getPathString(sourceLocations));
}
- if (!isJava16() || config.isForceJavacCompilerUse() || config.isFork()) {
+ if (!hasJavaxToolProvider() || config.isForceJavacCompilerUse() || config.isFork()) {
args.addAll(Arrays.asList(sourceFiles));
}
- if (!isPreJava16(config)) {
+ if (JavaVersion.JAVA_1_6.isOlderOrEqualTo(javacVersion)) {
// now add jdk 1.6 annotation processing related parameters
if (config.getGeneratedSourcesDirectory() != null) {
@@ -288,7 +345,7 @@ public static String[] buildCompilerArguments(CompilerConfiguration config, Stri
args.add("-verbose");
}
- if (!isPreJava18(config) && config.isParameters()) {
+ if (JavaVersion.JAVA_1_8.isOlderOrEqualTo(javacVersion) && config.isParameters()) {
args.add("-parameters");
}
@@ -324,7 +381,7 @@ public static String[] buildCompilerArguments(CompilerConfiguration config, Stri
args.add("-Werror");
}
- if (!StringUtils.isEmpty(config.getReleaseVersion())) {
+ if (JavaVersion.JAVA_9.isOlderOrEqualTo(javacVersion) && !StringUtils.isEmpty(config.getReleaseVersion())) {
args.add("--release");
args.add(config.getReleaseVersion());
} else {
@@ -338,17 +395,17 @@ public static String[] buildCompilerArguments(CompilerConfiguration config, Stri
args.add(config.getTargetVersion());
}
- if (!suppressSource(config) && StringUtils.isEmpty(config.getSourceVersion())) {
+ if (JavaVersion.JAVA_1_4.isOlderOrEqualTo(javacVersion) && StringUtils.isEmpty(config.getSourceVersion())) {
// If omitted, later JDKs complain about a 1.1 target
args.add("-source");
args.add("1.3");
- } else if (!suppressSource(config)) {
+ } else if (JavaVersion.JAVA_1_4.isOlderOrEqualTo(javacVersion)) {
args.add("-source");
args.add(config.getSourceVersion());
}
}
- if (!suppressEncoding(config) && !StringUtils.isEmpty(config.getSourceEncoding())) {
+ if (JavaVersion.JAVA_1_4.isOlderOrEqualTo(javacVersion) && !StringUtils.isEmpty(config.getSourceEncoding())) {
args.add("-encoding");
args.add(config.getSourceEncoding());
}
@@ -376,7 +433,7 @@ public static String[] buildCompilerArguments(CompilerConfiguration config, Stri
args.add(value);
}
- if (!config.isFork()) {
+ if (!config.isFork() && !args.contains("-XDuseUnsharedTable=false")) {
args.add("-XDuseUnsharedTable=true");
}
@@ -384,115 +441,38 @@ public static String[] buildCompilerArguments(CompilerConfiguration config, Stri
}
/**
- * Determine if the compiler is a version prior to 1.4.
- * This is needed as 1.3 and earlier did not support -source or -encoding parameters
- *
- * @param config The compiler configuration to test.
- * @return true if the compiler configuration represents a Java 1.4 compiler or later, false otherwise
- */
- private static boolean isPreJava14(CompilerConfiguration config) {
- String v = config.getCompilerVersion();
-
- if (v == null) {
- return false;
- }
-
- return v.startsWith("1.3") || v.startsWith("1.2") || v.startsWith("1.1") || v.startsWith("1.0");
- }
-
- /**
- * Determine if the compiler is a version prior to 1.6.
- * This is needed for annotation processing parameters.
- *
- * @param config The compiler configuration to test.
- * @return true if the compiler configuration represents a Java 1.6 compiler or later, false otherwise
+ * Represents a particular Java version (through their according version prefixes)
*/
- private static boolean isPreJava16(CompilerConfiguration config) {
- String v = config.getReleaseVersion();
-
- if (v == null) {
- v = config.getCompilerVersion();
- }
-
- if (v == null) {
- v = config.getSourceVersion();
+ enum JavaVersion {
+ JAVA_1_3_OR_OLDER("1.3", "1.2", "1.1", "1.0"),
+ JAVA_1_4("1.4"),
+ JAVA_1_5("1.5"),
+ JAVA_1_6("1.6"),
+ JAVA_1_7("1.7"),
+ JAVA_1_8("1.8"),
+ JAVA_9("9"); // since Java 9 a different versioning scheme was used (https://openjdk.org/jeps/223)
+ final Set versionPrefixes;
+
+ JavaVersion(String... versionPrefixes) {
+ this.versionPrefixes = new HashSet<>(Arrays.asList(versionPrefixes));
}
- if (v == null) {
- return true;
- }
-
- return v.startsWith("5")
- || v.startsWith("1.5")
- || v.startsWith("1.4")
- || v.startsWith("1.3")
- || v.startsWith("1.2")
- || v.startsWith("1.1")
- || v.startsWith("1.0");
- }
-
- private static boolean isPreJava18(CompilerConfiguration config) {
- String v = config.getReleaseVersion();
-
- if (v == null) {
- v = config.getCompilerVersion();
- }
-
- if (v == null) {
- v = config.getSourceVersion();
- }
-
- if (v == null) {
- return true;
- }
-
- return v.startsWith("7")
- || v.startsWith("1.7")
- || v.startsWith("6")
- || v.startsWith("1.6")
- || v.startsWith("1.5")
- || v.startsWith("1.4")
- || v.startsWith("1.3")
- || v.startsWith("1.2")
- || v.startsWith("1.1")
- || v.startsWith("1.0");
- }
-
- private static boolean isPreJava9(CompilerConfiguration config) {
-
- String v = config.getReleaseVersion();
-
- if (v == null) {
- v = config.getCompilerVersion();
- }
-
- if (v == null) {
- v = config.getSourceVersion();
- }
-
- if (v == null) {
+ /**
+ * The internal logic checks if the given version starts with the prefix of one of the enums preceding the current one.
+ *
+ * @param version the version to check
+ * @return {@code true} if the version represented by this enum is older than or equal (in its minor and major version) to a given version
+ */
+ boolean isOlderOrEqualTo(String version) {
+ // go through all previous enums
+ JavaVersion[] allJavaVersionPrefixes = JavaVersion.values();
+ for (int n = ordinal() - 1; n > -1; n--) {
+ if (allJavaVersionPrefixes[n].versionPrefixes.stream().anyMatch(version::startsWith)) {
+ return false;
+ }
+ }
return true;
}
-
- return v.startsWith("8")
- || v.startsWith("1.8")
- || v.startsWith("7")
- || v.startsWith("1.7")
- || v.startsWith("1.6")
- || v.startsWith("1.5")
- || v.startsWith("1.4")
- || v.startsWith("1.3")
- || v.startsWith("1.2")
- || v.startsWith("1.1")
- || v.startsWith("1.0");
- }
-
- private static boolean suppressSource(CompilerConfiguration config) {
- return isPreJava14(config);
- }
-
- private static boolean suppressEncoding(CompilerConfiguration config) {
- return isPreJava14(config);
}
/**
@@ -638,6 +618,10 @@ private static CompilerResult compileInProcess0(Class> javacClass, String[] ar
private static final Pattern STACK_TRACE_OTHER_LINE =
Pattern.compile("^(?:Caused by:\\s.*|\\s*at .*|\\s*\\.\\.\\.\\s\\d+\\smore)$");
+ // Match generic javac errors with 'javac:' prefix, JMV init and boot layer init errors
+ private static final Pattern JAVAC_OR_JVM_ERROR =
+ Pattern.compile("^(?:javac:|Error occurred during initialization of (?:boot layer|VM)).*", Pattern.DOTALL);
+
/**
* Parse the output from the compiler into a list of CompilerMessage objects
*
@@ -664,10 +648,8 @@ static List parseModernStream(int exitCode, BufferedReader inpu
// maybe better to ignore only the summary and mark the rest as error
String bufferAsString = buffer.toString();
if (buffer.length() > 0) {
- if (bufferAsString.startsWith("javac:")) {
+ if (JAVAC_OR_JVM_ERROR.matcher(bufferAsString).matches()) {
errors.add(new CompilerMessage(bufferAsString, CompilerMessage.Kind.ERROR));
- } else if (bufferAsString.startsWith("Error occurred during initialization of boot layer")) {
- errors.add(new CompilerMessage(bufferAsString, CompilerMessage.Kind.OTHER));
} else if (hasPointer) {
// A compiler message remains in buffer at end of parse stream
errors.add(parseModernError(exitCode, bufferAsString));
@@ -923,11 +905,33 @@ private File createFileWithArguments(String[] args, String outputDirectory) thro
}
}
+ /**
+ * Get the path of the javac tool executable to use.
+ * Either given through explicit configuration or via {@link #getJavacExecutable()}.
+ * @param config the configuration
+ * @return the path of the javac tool
+ */
+ protected String getJavacExecutable(CompilerConfiguration config) {
+ String executable = config.getExecutable();
+
+ if (StringUtils.isEmpty(executable)) {
+ try {
+ executable = getJavacExecutable();
+ } catch (IOException e) {
+ if (getLog().isWarnEnabled()) {
+ getLog().warn("Unable to autodetect 'javac' path, using 'javac' from the environment.");
+ }
+ executable = "javac";
+ }
+ }
+ return executable;
+ }
+
/**
* Get the path of the javac tool executable: try to find it depending the OS or the java.home
* system property or the JAVA_HOME
environment variable.
*
- * @return the path of the Javadoc tool
+ * @return the path of the javac tool
* @throws IOException if not found
*/
private static String getJavacExecutable() throws IOException {
diff --git a/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/AbstractJavacCompilerTest.java b/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/AbstractJavacCompilerTest.java
index 9cb656a5..a91ebd8c 100644
--- a/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/AbstractJavacCompilerTest.java
+++ b/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/AbstractJavacCompilerTest.java
@@ -34,12 +34,10 @@
import org.codehaus.plexus.compiler.AbstractCompilerTest;
import org.codehaus.plexus.compiler.CompilerConfiguration;
import org.codehaus.plexus.util.StringUtils;
-import org.hamcrest.Matchers;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
/**
* @author Jason van Zyl
@@ -207,22 +205,19 @@ protected Collection expectedOutputFiles() {
"org/codehaus/foo/ReservedWord.class");
}
- protected void internalTest(CompilerConfiguration compilerConfiguration, List expectedArguments) {
- internalTest(compilerConfiguration, expectedArguments, new String[0]);
+ protected void internalTest(
+ CompilerConfiguration compilerConfiguration, List expectedArguments, String javacVersion) {
+ internalTest(compilerConfiguration, expectedArguments, new String[0], javacVersion);
}
public void internalTest(
- CompilerConfiguration compilerConfiguration, List expectedArguments, String[] sources) {
- String[] actualArguments = JavacCompiler.buildCompilerArguments(compilerConfiguration, sources);
-
- assertThat(
- "The expected and actual argument list sizes differ.",
- actualArguments,
- Matchers.arrayWithSize(expectedArguments.size()));
+ CompilerConfiguration compilerConfiguration,
+ List expectedArguments,
+ String[] sources,
+ String javacVersion) {
+ String[] actualArguments = JavacCompiler.buildCompilerArguments(compilerConfiguration, sources, javacVersion);
- for (int i = 0; i < actualArguments.length; i++) {
- assertThat("Unexpected argument", actualArguments[i], is(expectedArguments.get(i)));
- }
+ assertArrayEquals(actualArguments, expectedArguments.toArray(new String[0]));
}
@Test
@@ -231,11 +226,9 @@ public void testBuildCompilerArgs13() {
CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
- compilerConfiguration.setCompilerVersion("1.3");
-
populateArguments(compilerConfiguration, expectedArguments, true, true, false);
- internalTest(compilerConfiguration, expectedArguments);
+ internalTest(compilerConfiguration, expectedArguments, "1.3");
}
@Test
@@ -244,11 +237,9 @@ public void testBuildCompilerArgs14() {
CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
- compilerConfiguration.setCompilerVersion("1.4");
-
populateArguments(compilerConfiguration, expectedArguments, false, false, false);
- internalTest(compilerConfiguration, expectedArguments);
+ internalTest(compilerConfiguration, expectedArguments, "1.4");
}
@Test
@@ -257,11 +248,9 @@ public void testBuildCompilerArgs15() {
CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
- compilerConfiguration.setCompilerVersion("1.5");
-
populateArguments(compilerConfiguration, expectedArguments, false, false, false);
- internalTest(compilerConfiguration, expectedArguments);
+ internalTest(compilerConfiguration, expectedArguments, "1.5");
}
@Test
@@ -270,11 +259,9 @@ public void testBuildCompilerArgs18() {
CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
- compilerConfiguration.setCompilerVersion("1.8");
-
populateArguments(compilerConfiguration, expectedArguments, false, false, true);
- internalTest(compilerConfiguration, expectedArguments);
+ internalTest(compilerConfiguration, expectedArguments, "1.8");
}
@Test
@@ -283,9 +270,9 @@ public void testBuildCompilerArgsUnspecifiedVersion() {
CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
- populateArguments(compilerConfiguration, expectedArguments, false, false, false);
+ populateArguments(compilerConfiguration, expectedArguments, false, false, true);
- internalTest(compilerConfiguration, expectedArguments);
+ internalTest(compilerConfiguration, expectedArguments, "unknown");
}
@Test
@@ -298,9 +285,9 @@ public void testBuildCompilerDebugLevel() {
compilerConfiguration.setDebugLevel("none");
- populateArguments(compilerConfiguration, expectedArguments, false, false, false);
+ populateArguments(compilerConfiguration, expectedArguments, false, false, true);
- internalTest(compilerConfiguration, expectedArguments);
+ internalTest(compilerConfiguration, expectedArguments, "1.8");
}
// PLXCOMP-190
@@ -334,7 +321,7 @@ public void testJRuntimeArguments() {
compilerConfiguration.setCustomCompilerArgumentsAsMap(customCompilerArguments);
// don't expect this argument!!
- internalTest(compilerConfiguration, expectedArguments);
+ internalTest(compilerConfiguration, expectedArguments, "1.8");
}
@Test
@@ -370,7 +357,7 @@ public void testModulePathAnnotations() throws Exception {
// unshared table
expectedArguments.add("-XDuseUnsharedTable=true");
- internalTest(compilerConfiguration, expectedArguments, source);
+ internalTest(compilerConfiguration, expectedArguments, source, "11.0.1");
}
@Test
@@ -399,7 +386,7 @@ public void testModulePath() throws Exception {
// unshared table
expectedArguments.add("-XDuseUnsharedTable=true");
- internalTest(compilerConfiguration, expectedArguments);
+ internalTest(compilerConfiguration, expectedArguments, "11.0.1");
}
@Test
@@ -427,7 +414,7 @@ public void testModuleVersion() {
// unshared table
expectedArguments.add("-XDuseUnsharedTable=true");
- internalTest(compilerConfiguration, expectedArguments);
+ internalTest(compilerConfiguration, expectedArguments, "11.0.1");
}
@Test
@@ -449,7 +436,7 @@ public void testReleaseVersion() {
// unshared table
expectedArguments.add("-XDuseUnsharedTable=true");
- internalTest(compilerConfiguration, expectedArguments);
+ internalTest(compilerConfiguration, expectedArguments, "11.0.1");
}
@Test
@@ -476,7 +463,7 @@ public void testFailOnWarning() {
// unshared table
expectedArguments.add("-XDuseUnsharedTable=true");
- internalTest(compilerConfiguration, expectedArguments);
+ internalTest(compilerConfiguration, expectedArguments, "1.8");
}
@Test
@@ -507,7 +494,30 @@ public void testMultipleAddExports() {
// unshared table
expectedArguments.add("-XDuseUnsharedTable=true");
- internalTest(compilerConfiguration, expectedArguments);
+ internalTest(compilerConfiguration, expectedArguments, "1.8");
+ }
+
+ @Test
+ public void testWithGivenUnsharedTable() {
+ List expectedArguments = new ArrayList<>();
+
+ CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
+
+ // outputLocation
+ compilerConfiguration.setOutputLocation("/output");
+ expectedArguments.add("-d");
+ expectedArguments.add(new File("/output").getAbsolutePath());
+
+ // releaseVersion
+ compilerConfiguration.setReleaseVersion("6");
+ expectedArguments.add("--release");
+ expectedArguments.add("6");
+
+ // unshared table
+ compilerConfiguration.addCompilerCustomArgument("-XDuseUnsharedTable=false", null);
+ expectedArguments.add("-XDuseUnsharedTable=false");
+
+ internalTest(compilerConfiguration, expectedArguments, "11.0.1");
}
/* This test fails on Java 1.4. The multiple parameters of the same source file cause an error, as it is interpreted as a DuplicateClass
diff --git a/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/ErrorMessageParserTest.java b/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/ErrorMessageParserTest.java
index d8f01590..5ab3c822 100644
--- a/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/ErrorMessageParserTest.java
+++ b/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/ErrorMessageParserTest.java
@@ -1010,7 +1010,7 @@ public void testIssue37() throws IOException {
}
@Test
- public void testJvmError() throws Exception {
+ public void testJvmBootLayerInitializationError() throws Exception {
String out = "Error occurred during initialization of boot layer" + EOL
+ "java.lang.module.FindException: Module java.xml.bind not found";
@@ -1018,8 +1018,21 @@ public void testJvmError() throws Exception {
JavacCompiler.parseModernStream(1, new BufferedReader(new StringReader(out)));
assertThat(compilerErrors, notNullValue());
+ assertThat(compilerErrors.size(), is(1));
+ assertThat(compilerErrors.get(0).getKind(), is(CompilerMessage.Kind.ERROR));
+ }
+
+ @Test
+ public void testJvmInitializationError() throws Exception {
+ String out = "Error occurred during initialization of VM" + EOL
+ + "Initial heap size set to a larger value than the maximum heap size";
+ List compilerErrors =
+ JavacCompiler.parseModernStream(1, new BufferedReader(new StringReader(out)));
+
+ assertThat(compilerErrors, notNullValue());
assertThat(compilerErrors.size(), is(1));
+ assertThat(compilerErrors.get(0).getKind(), is(CompilerMessage.Kind.ERROR));
}
@Test
diff --git a/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/JavacCompilerTest.java b/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/JavacCompilerTest.java
index 8a182fcf..3cbc4f12 100644
--- a/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/JavacCompilerTest.java
+++ b/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/JavacCompilerTest.java
@@ -7,7 +7,9 @@
import java.util.stream.Stream;
import org.codehaus.plexus.compiler.CompilerMessage;
+import org.codehaus.plexus.compiler.javac.JavacCompiler.JavaVersion;
import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
@@ -18,6 +20,9 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.notNullValue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@@ -103,4 +108,22 @@ private static Stream testParseModernStream_withAnnotationProcessingE
"JDK 21 German",
"\n\nEin Annotationsprozessor hat eine nicht abgefangene Ausnahme ausgelöst.\nDetails finden Sie im folgenden Stacktrace.\n\n"));
}
+
+ @Test
+ void testJavaVersionPrefixes() {
+ assertFalse(JavaVersion.JAVA_1_4.isOlderOrEqualTo("1.3"));
+ assertTrue(JavaVersion.JAVA_1_4.isOlderOrEqualTo("1.4"));
+ assertTrue(JavaVersion.JAVA_1_4.isOlderOrEqualTo("1.4.0_something"));
+ assertFalse(JavaVersion.JAVA_1_5.isOlderOrEqualTo("1.4"));
+ assertTrue(JavaVersion.JAVA_1_8.isOlderOrEqualTo("1.8"));
+ assertTrue(JavaVersion.JAVA_1_8.isOlderOrEqualTo("22.0.2-something"));
+ assertTrue(JavaVersion.JAVA_1_8.isOlderOrEqualTo("unknown"));
+ }
+
+ @Test
+ void testExtractMajorAndMinorVersion() {
+ assertEquals("11.0", JavacCompiler.extractMajorAndMinorVersion("javac 11.0.22"));
+ assertEquals("11.0", JavacCompiler.extractMajorAndMinorVersion("11.0.22"));
+ assertEquals("21", JavacCompiler.extractMajorAndMinorVersion("javac 21"));
+ }
}
diff --git a/plexus-compilers/pom.xml b/plexus-compilers/pom.xml
index 6f741fc7..d60cafd6 100644
--- a/plexus-compilers/pom.xml
+++ b/plexus-compilers/pom.xml
@@ -5,7 +5,7 @@
org.codehaus.plexus
plexus-compiler
- 2.14.2
+ 2.15.0
plexus-compilers
@@ -36,6 +36,13 @@
plexus-compiler-test
test
+
+
+ commons-lang
+ commons-lang
+ 2.0
+ test
+
diff --git a/pom.xml b/pom.xml
index 86debbd6..709cc4df 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,11 +5,11 @@
org.codehaus.plexus
plexus
- 16
+ 17
plexus-compiler
- 2.14.2
+ 2.15.0
pom
Plexus Compiler
@@ -26,7 +26,7 @@
${scm.url}
${scm.url}
- plexus-compiler-2.14.2
+ plexus-compiler-2.15.0
http://github.com/codehaus-plexus/plexus-compiler/tree/${project.scm.tag}/
@@ -44,14 +44,14 @@
scm:git:git@github.com:codehaus-plexus/plexus-compiler.git
8
true
- 2023-12-20T20:24:00Z
- 5.10.1
+ 2024-03-10T16:44:32Z
1.9.21
- 3.5.4
- 2.23.0
+ 3.6.3
+ ${mavenVersion}
+ 2.25.0
false
clean install
- 3.12.0
+ 3.12.1
@@ -86,10 +86,15 @@
plexus-compiler-javac
${project.version}
+
+ org.codehaus.plexus
+ plexus-compiler-manager
+ ${project.version}
+
org.codehaus.plexus
plexus-component-annotations
- 2.1.1
+ 2.2.0
javax.inject
@@ -99,7 +104,7 @@
org.junit
junit-bom
- ${jupiter.version}
+ ${junit5Version}
pom
import
@@ -136,7 +141,12 @@
org.codehaus.plexus
plexus-xml
- 4.0.1
+ 3.0.0
+
+
+ org.slf4j
+ slf4j-api
+ 1.7.36
@@ -149,6 +159,9 @@
maven-surefire-plugin
${redirectTestOutputToFile}
+
+ ${settings.localRepository}
+
@@ -206,36 +219,4 @@
-
-
-
- maven.repo.local
-
-
- maven.repo.local
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
-
-
-
- maven.repo.local
- ${maven.repo.local}
-
-
-
-
-
-
-
-
-