Skip to content

Commit

Permalink
[JENKINS-22075] - Properly handle missing tools in CustomToolInstallW…
Browse files Browse the repository at this point in the history
…rapper

Signed-off-by: Oleg Nenashev <o.v.nenashev@gmail.com>
  • Loading branch information
oleg-nenashev committed Mar 7, 2014
1 parent 3d1f96e commit 593b16c
Showing 1 changed file with 24 additions and 16 deletions.
Expand Up @@ -41,11 +41,11 @@
import hudson.tasks.BuildWrapperDescriptor;

import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

import net.sf.json.JSONObject;

Expand Down Expand Up @@ -78,11 +78,25 @@ public SelectedTool(String name) {
public String getName() {
return name;
}

@Override
public String toString() {
return name;
}

@CheckForNull
public CustomTool toCustomTool() {
return ((CustomTool.DescriptorImpl)Hudson.getInstance().getDescriptor(CustomTool.class)).byName(name);
}

@Nonnull
public CustomTool toCustomToolValidated() throws CustomToolException {
CustomTool tool = toCustomTool();
if (tool == null) {
throw new CustomToolException("Cannot get the tool "+name);
}
return tool;
}
}

private SelectedTool[] selectedTools = new SelectedTool[0];
Expand All @@ -106,14 +120,15 @@ public Environment setUp(AbstractBuild build, Launcher launcher,

final EnvVars buildEnv = build.getEnvironment(listener);
final Node node = build.getBuiltOn();

return new Environment(){
return new Environment() {
@Override
public void buildEnvVars(Map<String, String> env) {

// TODO: Inject Home dirs as well
for (CustomTool tool : getCustomToolsList()) {
if (tool.hasVersions()) {
for (SelectedTool selectedTool : selectedTools) {
CustomTool tool = selectedTool.toCustomTool();
if (tool != null && tool.hasVersions()) {
ToolVersion version = ToolVersion.getEffectiveToolVersion(tool, buildEnv, node);
if (version != null && !env.containsKey(version.getVariableName())) {
env.put(version.getVariableName(), version.getDefaultVersion());
Expand All @@ -128,15 +143,6 @@ public SelectedTool[] getSelectedTools() {
return selectedTools.clone();
}

// TODO: Check for null
private List<CustomTool> getCustomToolsList() {
List<CustomTool> tools = new ArrayList<CustomTool>();
for (SelectedTool selected : selectedTools) {
tools.add(selected.toCustomTool());
}
return tools;
}

/**
* The heart of the beast. Installs selected tools and exports their paths to the
* PATH and their HOMEs as environment variables.
Expand All @@ -145,7 +151,8 @@ private List<CustomTool> getCustomToolsList() {
@Override
public Launcher decorateLauncher(AbstractBuild build, final Launcher launcher,
BuildListener listener) throws IOException, InterruptedException,
RunnerAbortedException {
RunnerAbortedException {

EnvVars buildEnv = build.getEnvironment(listener);
final EnvVars homes = new EnvVars();
final EnvVars versions = new EnvVars();
Expand All @@ -163,7 +170,8 @@ public Launcher decorateLauncher(AbstractBuild build, final Launcher launcher,

// Each tool can export zero or many directories to the PATH
Node node = Computer.currentComputer().getNode();
for (CustomTool tool : getCustomToolsList()) {
for (SelectedTool selectedToolName : selectedTools) {
CustomTool tool = selectedToolName.toCustomToolValidated();
CustomToolsLogger.logMessage(listener, tool.getName(), "Starting installation");

// Check versioning
Expand Down

0 comments on commit 593b16c

Please sign in to comment.