Skip to content

Commit

Permalink
Merge pull request #159 from jprinet/fix/isunix_from_api
Browse files Browse the repository at this point in the history
Fix Maven version discrepancy
  • Loading branch information
wolfs authored Jul 5, 2022
2 parents c2ac252 + 73c198f commit b50e939
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 23 deletions.
12 changes: 0 additions & 12 deletions src/main/java/hudson/FilePathUtil.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import hudson.EnvVars;
import hudson.FilePath;
import hudson.FilePathUtil;
import hudson.model.Computer;
import hudson.model.Node;
import hudson.slaves.EnvironmentVariablesNodeProperty;
import jenkins.model.Jenkins;
Expand All @@ -21,7 +21,7 @@ public class MavenBuildScanInjection implements BuildScanInjection {
private static final Logger LOGGER = Logger.getLogger(MavenBuildScanInjection.class.getName());

private static final String LIB_DIR_PATH = "jenkins-gradle-plugin/lib";
private static final String GE_MVN_LIB_NAME = "gradle-enterprise-maven-extension-1.14.2.jar";
private static final String GE_MVN_LIB_NAME = "gradle-enterprise-maven-extension-1.14.3.jar";
private static final String CCUD_LIB_NAME = "common-custom-user-data-maven-extension-1.10.1.jar";
// Maven system properties passed on the CLI to a Maven build
private static final String GRADLE_ENTERPRISE_URL_PROPERTY_KEY = "gradle.enterprise.url";
Expand Down Expand Up @@ -71,7 +71,7 @@ public void inject(Node node, EnvVars envGlobal, EnvVars envComputer) {

private void injectMavenExtension(Node node, FilePath rootPath) {
try {
String cp = constructExtClasspath(rootPath);
String cp = constructExtClasspath(rootPath, isUnix(node));
List<String> mavenOptsKeyValuePairs = new ArrayList<>();
mavenOptsKeyValuePairs.add(asSystemProperty(MAVEN_EXT_CLASS_PATH_PROPERTY_KEY, cp));
mavenOptsKeyValuePairs.add(asSystemProperty(GRADLE_SCAN_UPLOAD_IN_BACKGROUND_PROPERTY_KEY, "false"));
Expand All @@ -88,6 +88,10 @@ private void injectMavenExtension(Node node, FilePath rootPath) {
}
}

private boolean isUnix(Node node) {
Computer computer = node.toComputer();
return computer == null || Boolean.TRUE.equals(computer.isUnix());
}

private void removeMavenExtension(Node node, FilePath rootPath) {
try {
Expand All @@ -99,17 +103,17 @@ private void removeMavenExtension(Node node, FilePath rootPath) {
}
}

private String constructExtClasspath(FilePath rootPath) throws IOException, InterruptedException {
private String constructExtClasspath(FilePath rootPath, boolean isUnix) throws IOException, InterruptedException {
List<FilePath> libs = new LinkedList<>();
libs.add(copyResourceToAgent(GE_MVN_LIB_NAME, rootPath));
if (getGlobalEnvVar(GE_CCUD_VERSION_VAR) != null) {
libs.add(copyResourceToAgent(CCUD_LIB_NAME, rootPath));
}
return libs.stream().map(FilePath::getRemote).collect(Collectors.joining(getDelimiter(rootPath)));
return libs.stream().map(FilePath::getRemote).collect(Collectors.joining(getDelimiter(isUnix)));
}

private String getDelimiter(FilePath path) {
return FilePathUtil.isUnix(path) ? ":" : ";";
private String getDelimiter(boolean isUnix) {
return isUnix ? ":" : ";";
}

private String getGlobalEnvVar(String varName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ task hello {

j.jenkins.globalNodeProperties.add(nodeProperty)

// trigger BuildScanInjectionListener.onConfigurationChange()
j.createSlave()
// sync changes
restartSlave(slave)
}

private void disableBuildInjection(DumbSlave slave, String gradleVersion) {
Expand All @@ -176,8 +176,12 @@ task hello {
j.jenkins.globalNodeProperties.clear()
j.jenkins.globalNodeProperties.add(nodeProperty)

// trigger BuildScanInjectionListener.onConfigurationChange()
j.createSlave()
// sync changes
restartSlave(slave)
}

private void restartSlave(DumbSlave slave) {
j.disconnectSlave(slave)
j.waitOnline(slave)
}
}

0 comments on commit b50e939

Please sign in to comment.