Skip to content

Commit

Permalink
Merge pull request #19 from cyrille-leclerc/JENKINS-42179
Browse files Browse the repository at this point in the history
[JENKINS-42179] use the JAVA_TOOL_OPTIONS environment variable to pass `-Dmaven.ext.class.path`
  • Loading branch information
alvarolobato committed Feb 21, 2017
2 parents fa0f352 + 3952f7f commit 50291c9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
9 changes: 9 additions & 0 deletions jenkins-plugin/pom.xml
Expand Up @@ -86,6 +86,15 @@
<version>4.69</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<!--
Match the version used in jenkins-core
-->
<version>2.6</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
Expand Down
Expand Up @@ -45,9 +45,6 @@
import java.util.logging.Logger;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.apache.commons.lang.StringUtils;
import org.jenkinsci.lib.configprovider.model.Config;
Expand Down Expand Up @@ -98,6 +95,10 @@ class WithMavenStepExecution extends StepExecution {
private final transient FilePath ws;
private final transient Launcher launcher;
private final transient EnvVars env;
/*
* TODO document the role of envOverride in regard to env. cleclerc suspects that the environment variables defined
* in "envOverride" will override the environment variables defined in "env"
*/
private transient EnvVars envOverride;
private final transient Run<?, ?> build;

Expand Down Expand Up @@ -225,7 +226,17 @@ private void setupMaven() throws AbortException, IOException, InterruptedExcepti

FilePath mvnExec = new FilePath(ws.getChannel(), mvnExecPath);
FilePath mavenSpyJarPath = setupMavenSpy();
String content = mavenWrapperContent(mvnExec, setupSettingFile(), setupGlobalSettingFile(), setupMavenLocalRepo(), mavenSpyJarPath);

// JAVA_TOOL_OPTIONS: https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/envvars002.html
String javaToolsOptions = env.get("JAVA_TOOL_OPTIONS", "");
if (StringUtils.isNotEmpty(javaToolsOptions)) {
javaToolsOptions += " ";
}
javaToolsOptions += "-Dmaven.ext.class.path=\"" + mavenSpyJarPath.getRemote() + "\" " +
"-Dorg.jenkinsci.plugins.pipeline.maven.reportsFolder=\"" + this.tempBinDir.getRemote() + "\" ";
envOverride.put("JAVA_TOOL_OPTIONS", javaToolsOptions);

String content = mavenWrapperContent(mvnExec, setupSettingFile(), setupGlobalSettingFile(), setupMavenLocalRepo());

createWrapperScript(tempBinDir, mvnExec.getName(), content);

Expand Down Expand Up @@ -401,11 +412,10 @@ private String readFromProcess(String... args) throws InterruptedException {
* @param settingsFile settings file
* @param globalSettingsFile global settings file
* @param mavenLocalRepo maven local repo location
* @param mavenSpyJarPath path to the maven-spy jar
* @return wrapper script content
* @throws AbortException when problems creating content
*/
private String mavenWrapperContent(FilePath mvnExec, String settingsFile, String globalSettingsFile, String mavenLocalRepo, @Nullable FilePath mavenSpyJarPath) throws AbortException {
private String mavenWrapperContent(FilePath mvnExec, String settingsFile, String globalSettingsFile, String mavenLocalRepo) throws AbortException {

ArgumentListBuilder argList = new ArgumentListBuilder(mvnExec.getRemote());

Expand All @@ -428,11 +438,6 @@ private String mavenWrapperContent(FilePath mvnExec, String settingsFile, String
argList.add("--batch-mode");
argList.add("--show-version");

if (mavenSpyJarPath != null) {
argList.add("-Dmaven.ext.class.path=\"" + mavenSpyJarPath.getRemote() + "\"");
argList.add("-Dorg.jenkinsci.plugins.pipeline.maven.reportsFolder=\"" + this.tempBinDir.getRemote() + "\"");
}

StringBuilder c = new StringBuilder();

if (isUnix) {
Expand Down

0 comments on commit 50291c9

Please sign in to comment.