Skip to content

Commit

Permalink
JENKINS-23155 Only run plugin under Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoran Regvart committed May 25, 2014
1 parent e524bdc commit 8351332
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 11 deletions.
50 changes: 49 additions & 1 deletion src/main/java/org/jenkinsci/plugins/xvfb/XvfbBuildWrapper.java
Expand Up @@ -31,16 +31,21 @@
import hudson.Launcher;
import hudson.Launcher.ProcStarter;
import hudson.Proc;
import hudson.Util;
import hudson.XmlFile;
import hudson.model.AutoCompletionCandidates;
import hudson.model.BuildListener;
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;
import hudson.model.Node;
import hudson.model.Run;
import hudson.model.Run.RunnerAbortedException;
import hudson.model.labels.LabelAtom;
import hudson.model.listeners.RunListener;
import hudson.remoting.Callable;
import hudson.remoting.Channel;
Expand All @@ -62,12 +67,14 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;

import jenkins.model.Jenkins;
import net.sf.json.JSONObject;

import org.kohsuke.stapler.AncestorInPath;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
Expand Down Expand Up @@ -140,6 +147,18 @@ private FormValidation validateOptionalPositiveInteger(final String value) {

return FormValidation.validatePositiveInteger(value);
}

public AutoCompletionCandidates doAutoCompleteAssignedLabels(@AncestorInPath AbstractProject<?, ?> project, @QueryParameter String value) {
final AbstractProjectDescriptor projectDescriptor = (AbstractProjectDescriptor) project.getDescriptorByName(project.getClass().getName());

return projectDescriptor.doAutoCompleteAssignedLabelString(value);
}

public FormValidation doCheckAssignedLabels(@AncestorInPath AbstractProject<?, ?> project, @QueryParameter String value) {
final AbstractProjectDescriptor projectDescriptor = (AbstractProjectDescriptor) project.getDescriptorByName(project.getClass().getName());

return projectDescriptor.doCheckAssignedLabelString(value);
}
}

private static final String STDERR_FD = "2";
Expand Down Expand Up @@ -313,9 +332,12 @@ public Void call() throws InterruptedException {
/** Let Xvfb pick display number */
private boolean autoDisplayName = false;

/** Run only on ondes labeled */
private final String assignedLabels;

@DataBoundConstructor
public XvfbBuildWrapper(final String installationName, final Integer displayName, final String screen, final Boolean debug, final int timeout, final int displayNameOffset,
final String additionalOptions, final Boolean shutdownWithBuild, final Boolean autoDisplayName) {
final String additionalOptions, final Boolean shutdownWithBuild, final Boolean autoDisplayName, String assignedLabels) {
this.installationName = installationName;
this.displayName = displayName;

Expand Down Expand Up @@ -343,12 +365,18 @@ public XvfbBuildWrapper(final String installationName, final Integer displayName
if (autoDisplayName != null) {
this.autoDisplayName = autoDisplayName;
}

this.assignedLabels = Util.fixEmptyAndTrim(assignedLabels);
}

public String getAdditionalOptions() {
return additionalOptions;
}

public String getAssignedLabels() {
return assignedLabels;
}

@Override
public XvfbBuildWrapperDescriptor getDescriptor() {
return (XvfbBuildWrapperDescriptor) super.getDescriptor();
Expand Down Expand Up @@ -506,6 +534,26 @@ 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()) {
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) {
// not running on node with requested label
return new Environment() {
};
}
}

if (!launcher.isUnix()) {
listener.getLogger().println(Messages.XvfbBuildWrapper_NotUnix());

Expand Down
Expand Up @@ -22,18 +22,14 @@ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
-->
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define"
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">

<f:advanced>
<j:if test="${!empty(descriptor.installations)}">
<f:entry title="${%Xvfb installation}" field="installationName">
<select name="xvfb.installationName" class="setting-input">
<j:forEach var="installation"
items="${descriptor.installations}">
<f:option
selected="${installation.name == instance.installationName}"
value="${installation.name}">
<j:forEach var="installation" items="${descriptor.installations}">
<f:option selected="${installation.name == instance.installationName}" value="${installation.name}">
${installation.name}
</f:option>
</j:forEach>
Expand All @@ -49,6 +45,10 @@ SUCH DAMAGE.
<f:textbox value="${instance.displayName}" />
</f:entry>

<f:entry title="${%Start only on nodes labeled}" field="assignedLabels">
<f:textbox autoCompleteDelimChar=" " value="${instance.assignedLabels}" />
</f:entry>

<f:entry title="${%Timeout in seconds}" field="timeout">
<f:textbox value="${instance.timeout}" />
</f:entry>
Expand All @@ -69,9 +69,7 @@ SUCH DAMAGE.
<f:checkbox value="${instance.debug}" />
</f:entry>

<f:entry
title="${%Shutdown Xvfb with whole job, not just with the main build action}"
field="shutdownWithBuild">
<f:entry title="${%Shutdown Xvfb with whole job, not just with the main build action}" field="shutdownWithBuild">
<f:checkbox value="${instance.shutdownWithBuild}" />
</f:entry>
</f:advanced>
Expand Down
@@ -0,0 +1,29 @@
<!--
Copyright (c) 2012 Zoran Regvart All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
-->
<div>
If you want to start Xvfb only on specific nodes specify its name or
label. See the <i>Restrict where this project can be run</i> option for
label expressions that you can use.
</div>

0 comments on commit 8351332

Please sign in to comment.