Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-18814] - Throw errors if the configured tool cannot be found
  • Loading branch information
oleg-nenashev committed Mar 13, 2014
1 parent 593b16c commit 56b546e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 8 deletions.
Expand Up @@ -93,7 +93,8 @@ public CustomTool toCustomTool() {
public CustomTool toCustomToolValidated() throws CustomToolException {
CustomTool tool = toCustomTool();
if (tool == null) {
throw new CustomToolException("Cannot get the tool "+name);
throw new CustomToolException(
Messages.CustomTool_GetToolByName_ErrorMessage(name));
}
return tool;
}
Expand Down
Expand Up @@ -19,7 +19,6 @@
import hudson.Extension;
import hudson.Util;
import hudson.model.AbstractDescribableImpl;
import hudson.model.Describable;
import hudson.model.Descriptor;
import hudson.model.Label;
import hudson.model.Node;
Expand All @@ -33,9 +32,10 @@
* @since 0.3
*/
public class LabelSpecifics extends AbstractDescribableImpl<LabelSpecifics> implements Serializable {
private String label;
private String additionalVars;
private String exportedPaths;

private final String label;
private final String additionalVars;
private final String exportedPaths;

@DataBoundConstructor
public LabelSpecifics(String label, String additionalVars, String exportedPaths) {
Expand Down
Expand Up @@ -38,6 +38,7 @@ public class PathsList implements Serializable {
/**
* Constructor. Sets system's default separator and pathSeparator
* @param paths List of paths to be returned
* @param homeDir Home directory of the tool
*/
public PathsList(Collection<String> paths, String homeDir) {
this(paths, File.pathSeparator, File.separator, homeDir);
Expand Down Expand Up @@ -87,7 +88,7 @@ public boolean add(PathsList pathsList) {
}

/**
* Gets the list of installed tools
* Gets the list of installed tools.
* @return A list with valid delimiters or null if paths is empty
*/
public String toListString() {
Expand Down
@@ -1,2 +1,5 @@
Descriptor.DisplayName=Install custom tools
CustomTool.DescriptorImpl.DisplayName=Custom tool
CustomTool.DescriptorImpl.DisplayName=Custom tool
CustomTool.GetToolByName.ErrorMessage= \
Cannot find the {0} tool. Probably, it has been deleted from the \
global configuration.
Expand Up @@ -21,13 +21,15 @@
import com.synopsys.arc.jenkinsci.plugins.customtools.multiconfig.MulticonfigWrapperOptions;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.Result;
import hudson.tasks.BuildWrapper;
import hudson.tasks.Builder;
import hudson.tasks.Shell;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Future;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.HudsonTestCase;

/**
Expand All @@ -36,6 +38,9 @@
* @author Oleg Nenashev <nenashev@synopsys.com>, Synopsys Inc.
*/
public class CustomToolInstallWrapperTest extends HudsonTestCase {

private static final String NON_EXISTENT_TOOL = "non-existent";

/**
* Inserts {@link CustomToolInstallWrapper} after {@link StubWrapper}.
* @throws Exception
Expand Down Expand Up @@ -73,14 +78,32 @@ public void testNestedLauncherCalls() throws Exception {
nestedWrapperTestImpl(wrappers, false);
}

//@Bug(20560)
@Bug(20560)
public void testEmptyToolsList() throws Exception {
List<BuildWrapper> wrappers = new ArrayList<BuildWrapper>(0);
wrappers.add(new CommandCallerInstaller());
wrappers.add(new CustomToolInstallWrapper(null, MulticonfigWrapperOptions.DEFAULT, false));
nestedWrapperTestImpl(wrappers, false);
}

@Bug(0)
public void testDeletedTool() throws Exception {
FreeStyleProject project = createFreeStyleProject();

CustomToolInstallWrapper.SelectedTool[] tools =
new CustomToolInstallWrapper.SelectedTool[] {
new CustomToolInstallWrapper.SelectedTool(NON_EXISTENT_TOOL)
};

project.getBuildWrappersList().add(
new CustomToolInstallWrapper(tools, MulticonfigWrapperOptions.DEFAULT, false));

Future<FreeStyleBuild> build = project.scheduleBuild2(0);
assertBuildStatus(Result.FAILURE, build.get());
assertLogContains(
Messages.CustomTool_GetToolByName_ErrorMessage(NON_EXISTENT_TOOL), build.get());
}

/**
* Implements tests for nested wrappers.
* The test checks that environment variables have been set correctly.
Expand Down

0 comments on commit 56b546e

Please sign in to comment.