Skip to content

Commit e9c98a4

Browse files
jansohnslawekjaranowski
authored andcommitted
[MJAR-310] fixed toolchain version detection when toolchain paths contain white spaces
1 parent a5554bb commit e9c98a4

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed

pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,6 @@
130130
</dependency>
131131

132132
<!-- plexus -->
133-
<dependency>
134-
<groupId>org.codehaus.plexus</groupId>
135-
<artifactId>plexus-utils</artifactId>
136-
</dependency>
137133
<dependency>
138134
<groupId>org.codehaus.plexus</groupId>
139135
<artifactId>plexus-archiver</artifactId>

src/main/java/org/apache/maven/plugins/jar/ToolchainsJdkSpecification.java

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@
2121
import javax.inject.Named;
2222
import javax.inject.Singleton;
2323

24+
import java.io.BufferedReader;
2425
import java.io.IOException;
26+
import java.io.InputStream;
27+
import java.io.InputStreamReader;
2528
import java.io.UncheckedIOException;
2629
import java.nio.file.Path;
2730
import java.nio.file.Paths;
@@ -30,9 +33,6 @@
3033
import java.util.Optional;
3134

3235
import org.apache.maven.toolchain.Toolchain;
33-
import org.codehaus.plexus.util.cli.CommandLineException;
34-
import org.codehaus.plexus.util.cli.CommandLineUtils;
35-
import org.codehaus.plexus.util.cli.Commandline;
3636
import org.slf4j.Logger;
3737
import org.slf4j.LoggerFactory;
3838

@@ -70,15 +70,12 @@ private Path getCanonicalPath(Path path) {
7070

7171
private String getSpecForPath(Path path) {
7272
try {
73-
Commandline cl = new Commandline(path.toString());
74-
cl.createArg().setValue("-version");
75-
CommandLineUtils.StringStreamConsumer out = new CommandLineUtils.StringStreamConsumer();
76-
CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
77-
CommandLineUtils.executeCommandLine(cl, out, err);
78-
String version = out.getOutput().trim();
79-
if (version.isEmpty()) {
80-
version = err.getOutput().trim();
81-
}
73+
ProcessBuilder processBuilder = new ProcessBuilder(path.toString(), "-version");
74+
processBuilder.redirectErrorStream(true);
75+
Process process = processBuilder.start();
76+
String version = readOutput(process.getInputStream()).trim();
77+
process.waitFor();
78+
8279
if (version.startsWith("javac ")) {
8380
version = version.substring(6);
8481
if (version.startsWith("1.")) {
@@ -88,12 +85,26 @@ private String getSpecForPath(Path path) {
8885
}
8986
return version;
9087
} else {
91-
logger.warn("Unrecognized output form " + path + " -version - " + version);
92-
return null;
88+
logger.warn("Unrecognized output from {}: {}", processBuilder.command(), version);
9389
}
94-
} catch (CommandLineException | IndexOutOfBoundsException e) {
95-
logger.warn("Failed to execute: " + path + " - " + e.getMessage());
96-
return null;
90+
} catch (IndexOutOfBoundsException | IOException e) {
91+
logger.warn("Failed to execute: {} - {}", path, e.getMessage());
92+
} catch (InterruptedException e) {
93+
Thread.currentThread().interrupt();
94+
}
95+
96+
return null;
97+
}
98+
99+
private String readOutput(InputStream inputstream) throws IOException {
100+
BufferedReader br = new BufferedReader(new InputStreamReader(inputstream));
101+
102+
StringBuilder output = new StringBuilder();
103+
String line;
104+
while ((line = br.readLine()) != null) {
105+
output.append(line + System.lineSeparator());
97106
}
107+
108+
return output.toString();
98109
}
99110
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy