This is an automated email from the ASF dual-hosted git repository.
sjaranowski pushed a commit to branch maven-jar-plugin-3.x
in repository https://gitbox.apache.org/repos/asf/maven-jar-plugin.git
The following commit(s) were added to refs/heads/maven-jar-plugin-3.x by this
push:
new 704a35c Ignore stderr when parsing javac version from toolchain (#471)
704a35c is described below
commit 704a35caecb49c72ea87956e4210cd082df18065
Author: Jared Stehler <[email protected]>
AuthorDate: Sun Nov 9 15:50:09 2025 -0500
Ignore stderr when parsing javac version from toolchain (#471)
* Ignore stderr when parsing javac version from toolchain
* parse version from stdout, fall back to stderr for older javac
---------
Co-authored-by: Slawomir Jaranowski <[email protected]>
---
src/it/github-470/invoker.properties | 20 ++++++++
src/it/github-470/pom.xml | 60 ++++++++++++++++++++++
.../src/main/java/myproject/HelloWorld.java | 36 +++++++++++++
src/it/github-470/verify.groovy | 26 ++++++++++
.../plugins/jar/ToolchainsJdkSpecification.java | 41 ++++++++++-----
5 files changed, 171 insertions(+), 12 deletions(-)
diff --git a/src/it/github-470/invoker.properties
b/src/it/github-470/invoker.properties
new file mode 100644
index 0000000..97785e8
--- /dev/null
+++ b/src/it/github-470/invoker.properties
@@ -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.toolchain.jdk.version = 17
+
+invoker.environmentVariables.JAVA_TOOL_OPTIONS = -XX:ActiveProcessorCount=1
diff --git a/src/it/github-470/pom.xml b/src/it/github-470/pom.xml
new file mode 100644
index 0000000..4220c39
--- /dev/null
+++ b/src/it/github-470/pom.xml
@@ -0,0 +1,60 @@
+<?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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>gh-470</artifactId>
+ <name>gh-470</name>
+ <packaging>jar</packaging>
+ <version>1.0-SNAPSHOT</version>
+ <organization>
+ <name>jar plugin it</name>
+ </organization>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-toolchains-plugin</artifactId>
+ <version>3.1.0</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>toolchain</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <toolchains>
+ <jdk>
+ <version>17</version>
+ </jdk>
+ </toolchains>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>@project.version@</version>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/src/it/github-470/src/main/java/myproject/HelloWorld.java
b/src/it/github-470/src/main/java/myproject/HelloWorld.java
new file mode 100644
index 0000000..fd0ad83
--- /dev/null
+++ b/src/it/github-470/src/main/java/myproject/HelloWorld.java
@@ -0,0 +1,36 @@
+package myproject;
+
+/*
+ * 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.
+ */
+
+/**
+ * The classic Hello World App.
+ */
+public class HelloWorld {
+
+ /**
+ * Main method.
+ *
+ * @param args Not used
+ */
+ public static void main( String[] args )
+ {
+ System.out.println( "Hi!" );
+ }
+}
\ No newline at end of file
diff --git a/src/it/github-470/verify.groovy b/src/it/github-470/verify.groovy
new file mode 100644
index 0000000..78efc30
--- /dev/null
+++ b/src/it/github-470/verify.groovy
@@ -0,0 +1,26 @@
+/*
+ * 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 java.util.jar.JarFile
+
+def mrjar = new JarFile(new File(basedir, 'target/gh-470-1.0-SNAPSHOT.jar'))
+def manifest = mrjar.manifest.mainAttributes
+
+assert manifest.getValue("Build-Jdk-Spec") == "17"
+assert manifest.getValue("Build-Tool-Jdk-Spec") ==
System.getProperty("java.specification.version")
diff --git
a/src/main/java/org/apache/maven/plugins/jar/ToolchainsJdkSpecification.java
b/src/main/java/org/apache/maven/plugins/jar/ToolchainsJdkSpecification.java
index ef992ab..5d01d41 100644
--- a/src/main/java/org/apache/maven/plugins/jar/ToolchainsJdkSpecification.java
+++ b/src/main/java/org/apache/maven/plugins/jar/ToolchainsJdkSpecification.java
@@ -71,22 +71,26 @@ class ToolchainsJdkSpecification {
private String getSpecForPath(Path path) {
try {
ProcessBuilder processBuilder = new
ProcessBuilder(path.toString(), "-version");
- processBuilder.redirectErrorStream(true);
+ processBuilder.redirectErrorStream(false);
Process process = processBuilder.start();
- String version = readOutput(process.getInputStream()).trim();
+ String stdout = readOutput(process.getInputStream()).trim();
+ String stderr = readOutput(process.getErrorStream()).trim();
process.waitFor();
- if (version.startsWith("javac ")) {
- version = version.substring(6);
- if (version.startsWith("1.")) {
- version = version.substring(0, 3);
- } else {
- version = version.substring(0, 2);
- }
- return version;
- } else {
- logger.warn("Unrecognized output from {}: {}",
processBuilder.command(), version);
+ String version = tryParseVersion(stdout);
+ if (version == null) {
+ version = tryParseVersion(stderr);
+ }
+
+ if (version == null) {
+ logger.warn(
+ "Unrecognized output from {}: stdout: {}, stderr: {}",
+ processBuilder.command(),
+ stdout,
+ stderr);
}
+
+ return version;
} catch (IndexOutOfBoundsException | IOException e) {
logger.warn("Failed to execute: {} - {}", path, e.getMessage());
} catch (InterruptedException e) {
@@ -96,6 +100,19 @@ class ToolchainsJdkSpecification {
return null;
}
+ private String tryParseVersion(String version) {
+ if (version.startsWith("javac ")) {
+ version = version.substring(6);
+ if (version.startsWith("1.")) {
+ version = version.substring(0, 3);
+ } else {
+ version = version.substring(0, 2);
+ }
+ return version;
+ }
+ return null;
+ }
+
private String readOutput(InputStream inputstream) throws IOException {
BufferedReader br = new BufferedReader(new
InputStreamReader(inputstream));