Skip to content

Commit

Permalink
Merge pull request #21673 from aloubyansky/codestart-test-mvn-settings
Browse files Browse the repository at this point in the history
Propagate the Maven settings argument when testing codestart-generated projects
  • Loading branch information
aloubyansky authored Nov 24, 2021
2 parents be015ef + 24946e6 commit a2b667a
Showing 1 changed file with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.quarkus.devtools.testing;

import io.quarkus.bootstrap.resolver.maven.options.BootstrapMavenOptions;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -71,8 +72,14 @@ public static int run(Path projectDir, Wrapper wrapper) {
command.add(projectDir.resolve(wrapper.getExec()).toAbsolutePath().toString());
command.addAll(Arrays.asList(wrapper.getCmdArgs()));

if (System.getProperties().containsKey("maven.repo.local")) {
command.add("-Dmaven.repo.local=" + System.getProperty("maven.repo.local"));
propagateSystemPropertyIfSet("maven.repo.local", command);

if (wrapper == Wrapper.MAVEN) {
final String mavenSettings = getMavenSettingsArg();
if (mavenSettings != null) {
command.add("-s");
command.add(mavenSettings);
}
}

try {
Expand All @@ -95,6 +102,26 @@ public static int run(Path projectDir, Wrapper wrapper) {
return -1;
}

private static String getMavenSettingsArg() {
final String mavenSettings = System.getProperty("maven.settings");
if (mavenSettings != null) {
return mavenSettings;
}
return BootstrapMavenOptions.newInstance().getOptionValue(BootstrapMavenOptions.ALTERNATE_USER_SETTINGS);
}

private static void propagateSystemPropertyIfSet(String name, List<String> command) {
if (System.getProperties().containsKey(name)) {
final StringBuilder buf = new StringBuilder();
buf.append("-D").append(name);
final String value = System.getProperty(name);
if (value != null && !value.isEmpty()) {
buf.append("=").append(value);
}
command.add(buf.toString());
}
}

private static void streamToSysOutSysErr(final Process process) {
streamOutputToSysOut(process);
streamErrorToSysErr(process);
Expand Down

0 comments on commit a2b667a

Please sign in to comment.