Skip to content
Permalink
Browse files
JENKINS-23155 Only run plugin under Linux (revised code for future co…
…mpatibility)
  • Loading branch information
Zoran Regvart committed May 31, 2014
1 parent e032bdb commit 34229d91801f058b0c1c9ee4d216a78a79fcdf2e
Showing with 49 additions and 16 deletions.
  1. +45 −16 src/main/java/org/jenkinsci/plugins/xvfb/XvfbBuildWrapper.java
  2. +4 −0 src/main/resources/org/jenkinsci/plugins/xvfb/Messages.properties
@@ -38,7 +38,6 @@
import hudson.model.TaskListener;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.AbstractProject.AbstractProjectDescriptor;
import hudson.model.Computer;
import hudson.model.Executor;
import hudson.model.Label;
@@ -79,6 +78,8 @@
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;

import antlr.ANTLRException;

public class XvfbBuildWrapper extends BuildWrapper {

@Extension(ordinal = Double.MAX_VALUE)
@@ -148,16 +149,46 @@ private FormValidation validateOptionalPositiveInteger(final String value) {
return FormValidation.validatePositiveInteger(value);
}

/** adopted from @see hudson.model.AbstractProject.AbstractProjectDescriptor#doAutoCompleteAssignedLabels */
public AutoCompletionCandidates doAutoCompleteAssignedLabels(@AncestorInPath AbstractProject<?, ?> project, @QueryParameter String value) {
final AbstractProjectDescriptor projectDescriptor = (AbstractProjectDescriptor) project.getDescriptorByName(project.getClass().getName());
final AutoCompletionCandidates candidates = new AutoCompletionCandidates();
final Set<Label> labels = Jenkins.getInstance().getLabels();

return projectDescriptor.doAutoCompleteAssignedLabelString(value);
for (Label label : labels) {
if (value == null || label.getName().startsWith(value)) {
candidates.add(label.getName());
}
}

return candidates;
}

/** adopted from @see hudson.model.AbstractProject.AbstractProjectDescriptor#doCheckAssignedLabels */
public FormValidation doCheckAssignedLabels(@AncestorInPath AbstractProject<?, ?> project, @QueryParameter String value) {
final AbstractProjectDescriptor projectDescriptor = (AbstractProjectDescriptor) project.getDescriptorByName(project.getClass().getName());
if (Util.fixEmpty(value) == null) {
return FormValidation.ok();
}

try {
Label.parseExpression(value);
} catch (ANTLRException e) {
return FormValidation.error(e, Messages.XvfbBuildWrapper_AssignedLabelString_InvalidBooleanExpression(e.getMessage()));
}

final Jenkins jenkins = Jenkins.getInstance();
final Label label = jenkins.getLabel(value);

return projectDescriptor.doCheckAssignedLabelString(value);
if (label.isEmpty()) {
for (LabelAtom labelAtom : label.listAtoms()) {
if (labelAtom.isEmpty()) {
LabelAtom nearest = LabelAtom.findNearest(labelAtom.getName());
return FormValidation.warning(Messages.XvfbBuildWrapper_AssignedLabelString_NoMatch_DidYouMean(labelAtom.getName(), nearest.getDisplayName()));
}
}
return FormValidation.warning(Messages.XvfbBuildWrapper_AssignedLabelString_NoMatch());
}

return FormValidation.okWithMarkup(Messages.XvfbBuildWrapper_LabelLink(jenkins.getRootUrl(), label.getUrl(), label.getNodes().size() + label.getClouds().size()));
}
}

@@ -534,20 +565,18 @@ public void makeBuildVariables(@SuppressWarnings("rawtypes") final AbstractBuild

@Override
public Environment setUp(@SuppressWarnings("rawtypes") final AbstractBuild build, final Launcher launcher, final BuildListener listener) throws IOException, InterruptedException {
final Set<LabelAtom> labels = Label.parse(assignedLabels);
if (!labels.isEmpty()) {
if (assignedLabels != null || assignedLabels.trim().isEmpty()) {
final Label label;
try {
label = Label.parseExpression(assignedLabels);
} catch (ANTLRException e) {
throw new IOException(e);
}

final Computer computer = Computer.currentComputer();
final Node node = computer.getNode();

boolean foundMatch = false;
for (LabelAtom label : labels) {
if (label.matches(node)) {
foundMatch = true;
break;
}
}

if (!foundMatch) {
if (!label.matches(node)) {
// not running on node with requested label
return new Environment() {
};
@@ -29,6 +29,10 @@ XvfbBuildWrapper.NoInstallationsConfigured = No Xvfb installations defined, plea
XvfbBuildWrapper.FailedToStart = Xvfb failed to start, consult the lines above for errors
XvfbBuildWrapper.KillingZombies = Trying to kill zombie Xvfb process that\u2019s occupying display name: {0} and frame buffer directory: {1}
XvfbBuildWrapper.ZombieSlainFailed = Unable to kill zombie Xvfb process, you\u2019ll need to do your own slaying.
XvfbBuildWrapper.AssignedLabelString.InvalidBooleanExpression = Invalid boolean expression: {0}
XvfbBuildWrapper.AssignedLabelString.NoMatch.DidYouMean = There\u2019s no slave/cloud that matches this assignment. Did you mean \u2018{1}\u2019 instead of \u2018{0}\u2019?
XvfbBuildWrapper.AssignedLabelString.NoMatch = There\u2019s no slave/cloud that matches this assignment
XvfbBuildWrapper.LabelLink = Slaves in <a href="{0}{1}">label</a>: {2}

XvfbInstallation.DisplayName = Xvfb installation
XvfbInstallation.HomeNotDirectory = Home path is not a directory: {0}

0 comments on commit 34229d9

Please sign in to comment.