Skip to content
Permalink
Browse files

Merge pull request #12 from synopsys-arc-oss/additional_variables_fix

[FIXED JENKINS-19889] - Additional variables fix
  • Loading branch information...
oleg-nenashev committed Nov 13, 2013
2 parents 99eaa76 + ed6e1e6 commit dcf9ac719bd1ad6947f63c41a32d8c978b5f28a0
@@ -8,6 +8,7 @@

<groupId>com.cloudbees.jenkins.plugins</groupId>
<artifactId>custom-tools-plugin</artifactId>
<name>Jenkins Custom Tools Plugin</name>
<version>0.5-SNAPSHOT</version>
<packaging>hpi</packaging>
<url>https://wiki.jenkins-ci.org/display/JENKINS/Custom+Tools+Plugin</url>
@@ -64,14 +64,16 @@
private static final LabelSpecifics[] EMPTY_LABELS = new LabelSpecifics[0];
private transient String correctedHome;
private final ToolVersionConfig toolVersion;
private final String additionalVariables;

@DataBoundConstructor
public CustomTool(String name, String home, List properties,
String exportedPaths, LabelSpecifics[] labelSpecifics, ToolVersionConfig toolVersion) {
String exportedPaths, LabelSpecifics[] labelSpecifics, ToolVersionConfig toolVersion, String additionalVariables) {
super(name, home, properties);
this.exportedPaths = exportedPaths;
this.labelSpecifics = labelSpecifics;
this.toolVersion = toolVersion;
this.additionalVariables = additionalVariables;
}

public String getExportedPaths() {
@@ -98,27 +100,41 @@ public void correctHome(PathsList pathList) {
public LabelSpecifics[] getLabelSpecifics() {
return (labelSpecifics!=null) ? labelSpecifics : EMPTY_LABELS;
}

/**Check if the tool has additional variables set*/
public boolean hasAdditionalVariables() {
return additionalVariables != null;
}

public String getAdditionalVariables() {
return additionalVariables;
}

@Override
public CustomTool forEnvironment(EnvVars environment) {
return new CustomTool(getName(), environment.expand(getHome()),
getProperties().toList(), environment.expand(exportedPaths),
LabelSpecifics.substitute(getLabelSpecifics(), environment), toolVersion);
LabelSpecifics.substitute(getLabelSpecifics(), environment),
toolVersion, environment.expand(additionalVariables));
}

@Override
public CustomTool forNode(Node node, TaskListener log) throws IOException,
InterruptedException {
String substitutedPath = EnvStringParseHelper.resolveExportedPath(exportedPaths, node);
String substitutedHomeDir = EnvStringParseHelper.resolveExportedPath(translateFor(node, log), node);
String substitutedAdditionalVariables = EnvStringParseHelper.resolveExportedPath(additionalVariables, node);

return new CustomTool(getName(), substitutedHomeDir, getProperties().toList(),
substitutedPath, LabelSpecifics.substitute(getLabelSpecifics(), node), toolVersion);
substitutedPath, LabelSpecifics.substitute(getLabelSpecifics(), node),
toolVersion, substitutedAdditionalVariables);
}

//FIXME: just a stub
public CustomTool forBuildProperties(Map<JobPropertyDescriptor,JobProperty> properties) {
return new CustomTool(getName(), getHome(), getProperties().toList(), getExportedPaths(), getLabelSpecifics(), toolVersion);
return new CustomTool(getName(), getHome(), getProperties().toList(),
getExportedPaths(), getLabelSpecifics(),
toolVersion, getAdditionalVariables());
}

/**
@@ -176,11 +176,17 @@ public Launcher decorateLauncher(AbstractBuild build, final Launcher launcher,
throw new AbortException(ex.getMessage());
}

// Prepare additional variables
// Handle global options of the tool
//TODO: convert to label specifics?
PathsList installedPaths = installed.getPaths(node);
installed.correctHome(installedPaths);
paths.add(installedPaths);
if (installed.hasAdditionalVariables()) {
additionalVarInjectors.add(
EnvVariablesInjector.Create(installed.getAdditionalVariables()));
}

// Handle label-specific options of the tool
for (LabelSpecifics spec : installed.getLabelSpecifics()) {
if (!spec.appliesTo(node)) {
continue;
@@ -82,7 +82,7 @@ public static String resolveExportedPath(String exportedPaths, Node node) {
*/
public static String substituteNodeProperty(String macroString, NodeProperty<?> property) {
// Get environment variables
if (EnvironmentVariablesNodeProperty.class.equals(property.getClass())) {
if (property != null && property instanceof EnvironmentVariablesNodeProperty) {
EnvironmentVariablesNodeProperty prop = (EnvironmentVariablesNodeProperty)property;
return resolveExportedPath(macroString, prop.getEnvVars());
}
@@ -40,6 +40,7 @@
import org.jvnet.hudson.test.HudsonTestCase;

import com.cloudbees.jenkins.plugins.customtools.CustomTool.DescriptorImpl;
import com.synopsys.arc.jenkinsci.plugins.customtools.LabelSpecifics;
import com.synopsys.arc.jenkinsci.plugins.customtools.multiconfig.MulticonfigWrapperOptions;
import com.synopsys.arc.jenkinsci.plugins.customtools.versions.ToolVersionConfig;

@@ -78,7 +79,26 @@ public void testBasicCase() throws Exception {
project.getBuildersList().add(b);
Future<FreeStyleBuild> build = project.scheduleBuild2(0);
assertBuildStatusSuccess(build);

}

// @Bug(19889). https://issues.jenkins-ci.org/browse/JENKINS-19889
//TODO: Just a stub for testing. Make the test automatic
public void testAdditionalVars() throws Exception {
hudson.setNumExecutors(0);
createSlave();
tools = hudson.getDescriptorByType(CustomTool.DescriptorImpl.class);
tools.setInstallations(createEnvPrinterTool("MyTrue", null, "TEST_ADD_VAR=test"));
FreeStyleProject project = createFreeStyleProject();
CustomToolInstallWrapper.SelectedTool selectedTool = new CustomToolInstallWrapper.SelectedTool("MyTrue");

CustomToolInstallWrapper wrapper = new CustomToolInstallWrapper(
new CustomToolInstallWrapper.SelectedTool[] { selectedTool }, MulticonfigWrapperOptions.DEFAULT, false);
project.getBuildWrappersList().add(wrapper);
Builder b = new Shell("env; mytrue");
project.getBuildersList().add(b);
Future<FreeStyleBuild> build = project.scheduleBuild2(0);
assertBuildStatusSuccess(build);
}

private CustomTool createTool(String name) throws IOException {
@@ -89,7 +109,19 @@ private CustomTool createTool(String name) throws IOException {
List<ToolProperty<ToolInstallation>> properties = new ArrayList<ToolProperty<ToolInstallation>>();
properties.add(new InstallSourceProperty(installers));

CustomTool installation = new CustomTool("MyTrue", null, properties, "./", null, ToolVersionConfig.DEFAULT);
CustomTool installation = new CustomTool("MyTrue", null, properties, "./", null, ToolVersionConfig.DEFAULT, null);
return installation;
}

//TODO: refactor and generalize
private CustomTool createEnvPrinterTool(String name, LabelSpecifics[] specifics, String additionalVars) throws IOException {
List<ToolInstaller> installers = new ArrayList<ToolInstaller>();
installers.add(new CommandInstaller(null, "ln -s `which true` mytrue", "./"));

List<ToolProperty<ToolInstallation>> properties = new ArrayList<ToolProperty<ToolInstallation>>();
properties.add(new InstallSourceProperty(installers));

CustomTool installation = new CustomTool(name, null, properties, "./", specifics, ToolVersionConfig.DEFAULT, additionalVars);
return installation;
}

0 comments on commit dcf9ac7

Please sign in to comment.
You can’t perform that action at this time.