Skip to content

Commit

Permalink
Revert "JENKINS-18607 Xvfb plugin doesn't work on matrix jobs with sl…
Browse files Browse the repository at this point in the history
…aves on the"

This reverts commit 61ca30d.
  • Loading branch information
Zoran Regvart committed Oct 6, 2013
1 parent 61ca30d commit 2b652cd
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 110 deletions.
111 changes: 39 additions & 72 deletions src/main/java/org/jenkinsci/plugins/xvfb/XvfbBuildWrapper.java
Expand Up @@ -50,10 +50,8 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;

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

import org.kohsuke.stapler.DataBoundConstructor;
Expand All @@ -62,6 +60,25 @@

public class XvfbBuildWrapper extends BuildWrapper {

@SuppressWarnings("rawtypes")
@Extension
public static final RunListener<Run> xvfbShutdownListener = new RunListener<Run>() {
@Override
public void onCompleted(Run r, TaskListener listener) {
XvfbEnvironment xvfbEnvironment = r.getAction(XvfbEnvironment.class);

if (xvfbEnvironment != null && xvfbEnvironment.isShutdownWithBuild()) {
try {
shutdownAndCleanup(xvfbEnvironment, listener);
} catch (IOException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
};

@Extension
public static class XvfbBuildWrapperDescriptor extends BuildWrapperDescriptor {

Expand Down Expand Up @@ -130,69 +147,38 @@ private FormValidation validateOptionalPositiveInteger(final String value) {
}
}

@SuppressWarnings("rawtypes")
@Extension
public static final RunListener<Run> xvfbShutdownListener = new RunListener<Run>() {
@Override
public void onCompleted(final Run r, final TaskListener listener) {
final XvfbEnvironment xvfbEnvironment = r.getAction(XvfbEnvironment.class);

if (xvfbEnvironment != null && xvfbEnvironment.isShutdownWithBuild()) {
try {
shutdownAndCleanup(xvfbEnvironment, listener);
} catch (final IOException e) {
throw new RuntimeException(e);
} catch (final InterruptedException e) {
throw new RuntimeException(e);
}
}
}
};

private static final int MILLIS_IN_SECOND = 1000;
private static final int MILLIS_IN_SECOND = 1000;

/** default screen configuration for Xvfb, used by default, and if user left screen configuration blank */
private static final String DEFAULT_SCREEN = "1024x768x24";

private static void shutdownAndCleanup(final XvfbEnvironment environment, final TaskListener listener) throws IOException, InterruptedException {
final FilePath frameBufferDir = environment.getFrameBufferDir();
final Proc process = environment.getProcess();

listener.getLogger().println(Messages.XvfbBuildWrapper_Stopping());
process.kill();
frameBufferDir.deleteRecursive();
}
private static final String DEFAULT_SCREEN = "1024x768x24";

/** Name of the installation used in a configured job. */
private final String installationName;
private final String installationName;

/** X11 DISPLAY name, if NULL chosen by random. */
private final Integer displayName;
private final Integer displayName;

/** Xvfb screen argument, in the form WxHxD (width x height x pixel depth), i.e. 800x600x8. */
private String screen = DEFAULT_SCREEN;
private String screen = DEFAULT_SCREEN;

/** Should the Xvfb output be displayed in job output. */
private boolean debug = false;
private boolean debug = false;

/** Time in milliseconds to wait for Xvfb initialization, by default 0 -- do not wait. */
private final long timeout;
private final long timeout;

/** Offset for display names, default is 1. Display names are taken from build executor's number, i.e. if the build is performed by executor 4, and offset is 100, display name will be 104. */
private int displayNameOffset = 1;
private int displayNameOffset = 1;

/** Additional options to be passed to Xvfb */
private final String additionalOptions;
private final String additionalOptions;

/** Should the Xvfb display be around for post build actions, i.e. should it terminate with the whole build */
private boolean shutdownWithBuild = false;

/** Should the displayName be offsetted by the node index */
private boolean useNodeOffsets = false;
private boolean shutdownWithBuild = false;

@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 useNodeOffsets) {
final String additionalOptions, Boolean shutdownWithBuild) {
this.installationName = installationName;
this.displayName = displayName;

Expand All @@ -214,8 +200,6 @@ public XvfbBuildWrapper(final String installationName, final Integer displayName
this.additionalOptions = additionalOptions;

this.shutdownWithBuild = shutdownWithBuild;

this.useNodeOffsets = useNodeOffsets;
}

public String getAdditionalOptions() {
Expand Down Expand Up @@ -271,27 +255,19 @@ public boolean isShutdownWithBuild() {
return shutdownWithBuild;
}

public boolean isUseNodeOffsets() {
return useNodeOffsets;
}

private XvfbEnvironment launchXvfb(@SuppressWarnings("rawtypes") final AbstractBuild build, final Launcher launcher, final BuildListener listener) throws IOException, InterruptedException {
int displayNameUsed;

final Computer currentComputer = Computer.currentComputer();
final Node currentNode = currentComputer.getNode();

if (displayName == null) {
final Executor executor = build.getExecutor();

final int nodeOffset = nodeOffsetFor(currentNode);

displayNameUsed = nodeOffset + executor.getNumber() + displayNameOffset;
displayNameUsed = executor.getNumber() + displayNameOffset;
}
else {
displayNameUsed = displayName;
}

final Computer currentComputer = Computer.currentComputer();
final Node currentNode = currentComputer.getNode();
final FilePath rootPath = currentNode.getRootPath();

final FilePath frameBufferDir = rootPath.createTempDir(build.getId(), "xvfb");
Expand Down Expand Up @@ -362,22 +338,13 @@ public void makeBuildVariables(@SuppressWarnings("rawtypes") final AbstractBuild
}
}

private int nodeOffsetFor(final Node currentNode) {
final String nodeName = currentNode.getNodeName();

if (!useNodeOffsets || "".equals(nodeName)) {
return 0;
}

final List<Node> nodes = Jenkins.getInstance().getNodes();

final int idx = nodes.indexOf(currentNode);

if (idx < 0) {
return 0;
}
private static void shutdownAndCleanup(XvfbEnvironment environment, TaskListener listener) throws IOException, InterruptedException {
final FilePath frameBufferDir = environment.getFrameBufferDir();
final Proc process = environment.getProcess();

return 1000 * (idx + 1);
listener.getLogger().println(Messages.XvfbBuildWrapper_Stopping());
process.kill();
frameBufferDir.deleteRecursive();
}

@Override
Expand Down
Expand Up @@ -22,14 +22,18 @@ 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 Down Expand Up @@ -61,13 +65,11 @@ SUCH DAMAGE.
<f:checkbox value="${instance.debug}" />
</f:entry>

<f:entry title="${%Shoutdown Xvfb with whole job, not just with the main build action}" field="shutdownWithBuild">
<f:entry
title="${%Shoutdown Xvfb with whole job, not just with the main build action}"
field="shutdownWithBuild">
<f:checkbox value="${instance.shutdownWithBuild}" />
</f:entry>

<f:entry title="${%Use display name node offset}" field="useNodeOffsets">
<f:checkbox value="${instance.useNodeOffsets}" />
</f:entry>
</f:advanced>

</j:jelly>

This file was deleted.

0 comments on commit 2b652cd

Please sign in to comment.