Skip to content
Permalink
Browse files

[JENKINS-26940] Print message when installer isn't applicable (#2598)

* [JENKINS-26940] Print message when installer isn't applicable

* [JENKINS-26940] Only print when none found, add test
  • Loading branch information
daniel-beck authored and oleg-nenashev committed Oct 25, 2016
1 parent 37c4736 commit ae29e6b2463754778c3988e62292a07a846ffe57
@@ -28,6 +28,7 @@
import hudson.model.Node;
import hudson.model.TaskListener;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.Semaphore;
@@ -50,6 +51,9 @@ public String getToolHome(Node node, ToolInstallation tool, TaskListener log) th
if (isp == null) {
return null;
}

ArrayList<String> inapplicableInstallersMessages = new ArrayList<String>();

for (ToolInstaller installer : isp.installers) {
if (installer.appliesTo(node)) {
Semaphore semaphore;
@@ -69,8 +73,16 @@ public String getToolHome(Node node, ToolInstallation tool, TaskListener log) th
} finally {
semaphore.release();
}
} else {
inapplicableInstallersMessages.add(Messages.CannotBeInstalled(
installer.getDescriptor().getDisplayName(),
tool.getName(),
node.getDisplayName()));
}
}
for (String message : inapplicableInstallersMessages) {
log.getLogger().println(message);
}
return null;
}

@@ -37,3 +37,4 @@ JDKInstaller.DescriptorImpl.displayName=Install from java.sun.com
JDKInstaller.DescriptorImpl.doCheckId=Define JDK ID
JDKInstaller.DescriptorImpl.doCheckAcceptLicense=You must agree to the license to download the JDK.
ToolDescriptor.NotADirectory={0} is not a directory on the Jenkins master (but perhaps it exists on some agents)
CannotBeInstalled=Installer "{0}" cannot be used to install "{1}" on the node "{2}"
@@ -35,6 +35,8 @@
import hudson.tasks.Shell;
import hudson.util.StreamTaskListener;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import org.junit.Test;
import static org.junit.Assert.*;
@@ -98,4 +100,41 @@
r.assertLogContains("/opt/jdk1", b6);
}

@Issue("JENKINS-26940")
@Test
public void testMessageLoggedWhenNoInstallerFound() throws Exception {
final CommandInstaller ci = new CommandInstaller("wrong1", "echo hello", "/opt/jdk");
final BatchCommandInstaller bci = new BatchCommandInstaller("wrong2", "echo hello", "/opt/jdk2");
InstallSourceProperty isp = new InstallSourceProperty(Arrays.asList(ci, bci));

JDK jdk = new JDK("jdk", null, Collections.singletonList(isp));
r.jenkins.getJDKs().add(jdk);


FreeStyleProject p = r.createFreeStyleProject();
p.setJDK(jdk);
p.getBuildersList().add(new Shell("echo $JAVA_HOME"));
FreeStyleBuild b1 = r.buildAndAssertSuccess(p);
r.assertLogContains(hudson.tools.Messages.CannotBeInstalled(ci.getDescriptor().getDisplayName(), jdk.getName(), r.jenkins.getDisplayName()), b1);
r.assertLogContains(hudson.tools.Messages.CannotBeInstalled(bci.getDescriptor().getDisplayName(), jdk.getName(), r.jenkins.getDisplayName()), b1);
}

@Issue("JENKINS-26940")
@Test
public void testNoMessageLoggedWhenAnyInstallerFound() throws Exception {
final CommandInstaller ci = new CommandInstaller("wrong1", "echo hello", "/opt/jdk");
final CommandInstaller ci2 = new CommandInstaller("master", "echo hello", "/opt/jdk2");
InstallSourceProperty isp = new InstallSourceProperty(Arrays.asList(ci, ci2));

JDK jdk = new JDK("jdk", null, Collections.singletonList(isp));
r.jenkins.getJDKs().add(jdk);


FreeStyleProject p = r.createFreeStyleProject();
p.setJDK(jdk);
p.getBuildersList().add(new Shell("echo $JAVA_HOME"));
FreeStyleBuild b1 = r.buildAndAssertSuccess(p);
r.assertLogNotContains(ci.getDescriptor().getDisplayName(), b1);
}

}

0 comments on commit ae29e6b

Please sign in to comment.