Skip to content

Commit 6ed8982

Browse files
authored
fix: mvn binary in windows (#159)
## Description Use `mvn.cmd` as default binary for windows environments Use batch-mode for unattended builds and quiet flag to enhance performance **Related issue (if any):** fixes #158 ## Checklist - [x] I have followed this repository's contributing guidelines. - [x] I will adhere to the project's code of conduct. --------- Signed-off-by: Ruben Romero Montes <rromerom@redhat.com>
1 parent 0dd94ad commit 6ed8982

2 files changed

Lines changed: 16 additions & 11 deletions

File tree

src/main/java/com/redhat/exhort/providers/JavaMavenProvider.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public final class JavaMavenProvider extends BaseJavaProvider {
5454
private static final String PROP_JAVA_HOME = "JAVA_HOME";
5555
private static final Logger log = LoggersFactory.getLogger(JavaMavenProvider.class.getName());
5656
private final String mvnExecutable;
57-
private static final String MVN = "mvn";
57+
private static final String MVN = Operations.isWindows() ? "mvn.cmd" : "mvn";
5858
private static final String ARG_VERSION = "-v";
5959

6060
public JavaMavenProvider(Path manifest) {
@@ -65,7 +65,8 @@ public JavaMavenProvider(Path manifest) {
6565

6666
@Override
6767
public Content provideStack() throws IOException {
68-
var mvnCleanCmd = new String[] {mvnExecutable, "clean", "-f", manifest.toString()};
68+
var mvnCleanCmd =
69+
new String[] {mvnExecutable, "clean", "-f", manifest.toString(), "--batch-mode", "-q"};
6970
var mvnEnvs = getMvnExecEnvs();
7071
// execute the clean command
7172
Operations.runProcess(manifest.getParent(), mvnCleanCmd, mvnEnvs);
@@ -82,6 +83,8 @@ public Content provideStack() throws IOException {
8283
add(String.format("-DoutputFile=%s", tmpFile.toString()));
8384
add("-f");
8485
add(manifest.toString());
86+
add("--batch-mode");
87+
add("-q");
8588
}
8689
};
8790
// if we have dependencies marked as ignored, exclude them from the tree command
@@ -136,7 +139,9 @@ private Content generateSbomFromEffectivePom() throws IOException {
136139
"help:effective-pom",
137140
String.format("-Doutput=%s", tmpEffPom.toString()),
138141
"-f",
139-
manifest.toString()
142+
manifest.toString(),
143+
"--batch-mode",
144+
"-q"
140145
};
141146
// execute the effective pom command
142147
Operations.runProcess(manifest.getParent(), mvnEffPomCmd, getMvnExecEnvs());
@@ -372,13 +377,13 @@ public int hashCode() {
372377
private String selectMvnRuntime(final Path manifestPath) {
373378
boolean preferWrapper = Operations.getWrapperPreference(MVN);
374379
if (preferWrapper) {
375-
String wrapperName = isWindows() ? "mvnw.cmd" : "mvnw";
380+
String wrapperName = Operations.isWindows() ? "mvnw.cmd" : "mvnw";
376381
String mvnw = traverseForMvnw(wrapperName, manifestPath.toString());
377382
if (mvnw != null) {
378383
try {
379384
// verify maven wrapper is accessible
380385
Operations.runProcess(manifest.getParent(), mvnw, ARG_VERSION);
381-
log.fine("using maven wrapper from : " + mvnw);
386+
log.fine(String.format("using maven wrapper from : %s", mvnw));
382387
return mvnw;
383388
} catch (Exception e) {
384389
log.warning(
@@ -388,7 +393,7 @@ private String selectMvnRuntime(final Path manifestPath) {
388393
}
389394
// If maven wrapper is not requested or not accessible, fall back to use mvn
390395
String mvn = Operations.getExecutable(MVN, ARG_VERSION);
391-
log.fine("using mvn executable from : " + mvn);
396+
log.fine(String.format("using mvn executable from : %s", mvn));
392397
return mvn;
393398
}
394399

@@ -423,13 +428,9 @@ public static String traverseForMvnw(
423428
public static String normalizePath(String thePath) {
424429
Path normalized = Paths.get(thePath).toAbsolutePath().normalize();
425430
String result = normalized.toString();
426-
if (isWindows()) {
431+
if (Operations.isWindows()) {
427432
result = result.toLowerCase();
428433
}
429434
return result;
430435
}
431-
432-
private static boolean isWindows() {
433-
return System.getProperty("os.name").toLowerCase().contains("win");
434-
}
435436
}

src/main/java/com/redhat/exhort/tools/Operations.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,4 +349,8 @@ public static Optional<String> getGitRootDir(String cwd) {
349349
}
350350
return Optional.empty();
351351
}
352+
353+
public static boolean isWindows() {
354+
return System.getProperty("os.name").toLowerCase().contains("win");
355+
}
352356
}

0 commit comments

Comments
 (0)