Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
JENKINS-13046: Field for additional options for Xvfb
  • Loading branch information
zregvart committed Mar 12, 2012
1 parent 07a2053 commit 8b6ee55
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 45 deletions.
42 changes: 29 additions & 13 deletions src/main/java/org/jenkinsci/plugins/xvfb/XvfbBuildWrapper.java
Expand Up @@ -53,9 +53,6 @@

public class XvfbBuildWrapper extends BuildWrapper {

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

@Extension
public static class XvfbBuildWrapperDescriptor extends BuildWrapperDescriptor {

Expand Down Expand Up @@ -96,32 +93,38 @@ public void setInstallations(final XvfbInstallation... installations) {
}
}

/** default screen configuration for Xvfb, used by default, and if user left screen configuration blank */
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 long timeout;
private final long timeout;

/** Temporary directory to hold Xvfb session data, will not be persisted. */
private transient FilePath frameBufferDir;
private transient FilePath frameBufferDir;

/** Actual display name used, will not be persisted. */
private transient int displayNameUsed;
private transient int displayNameUsed;

/** Handle to the Xvfb process. */
private transient Proc process;
private transient Proc process;

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

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

Expand All @@ -134,6 +137,7 @@ public XvfbBuildWrapper(final String installationName, final Integer displayName

this.debug = Boolean.TRUE.equals(debug);
this.timeout = timeout * 1000;
this.additionalOptions = additionalOptions;
}

@Override
Expand Down Expand Up @@ -170,6 +174,10 @@ public Launcher decorateLauncher(final AbstractBuild build, final Launcher launc

cmd.add(":" + displayNameUsed).add("-screen").add("0").add(screen).add("-fbdir").add(frameBufferDir);

if (additionalOptions != null) {
cmd.addTokenized(additionalOptions);
}

final ProcStarter procStarter = launcher.launch().cmds(cmd);

listener.getLogger().print(Messages.XvfbBuildWrapper_Starting());
Expand All @@ -187,6 +195,10 @@ public Launcher decorateLauncher(final AbstractBuild build, final Launcher launc
return launcher;
}

public String getAdditionalOptions() {
return additionalOptions;
}

@Override
public XvfbBuildWrapperDescriptor getDescriptor() {
return (XvfbBuildWrapperDescriptor) super.getDescriptor();
Expand Down Expand Up @@ -220,6 +232,10 @@ public String getScreen() {
return screen;
}

public long getTimeout() {
return timeout;
}

public boolean isDebug() {
return debug;
}
Expand All @@ -233,7 +249,7 @@ public void makeBuildVariables(final AbstractBuild build, final Map<String, Stri
public Environment setUp(final AbstractBuild build, final Launcher launcher, final BuildListener listener) throws IOException, InterruptedException {
return new Environment() {
@Override
public void buildEnvVars(Map<String, String> env) {
public void buildEnvVars(final Map<String, String> env) {
env.put("DISPLAY", ":" + displayNameUsed);
}

Expand Down
Expand Up @@ -23,37 +23,43 @@ 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">

<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}">
${installation.name}
</f:option>
</j:forEach>
</select>
</f:entry>
</j:if>

<f:entry title="${%Xvfb specific displayname}" field="displayName">
<f:textbox value="${instance.displayName}" />
</f:entry>

<f:entry title="${%Timeout in seconds}" field="timeout">
<f:textbox value="${instance.timeout}" />
</f:entry>

<f:entry title="${%Xvfb screen}" field="screen">
<f:textbox value="${instance.screen}" />
</f:entry>

<f:entry title="${%Log Xvfb output}" field="debug">
<f:checkbox value="${instance.debug}" />
</f:entry>
</f:advanced>
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}">
${installation.name}
</f:option>
</j:forEach>
</select>
</f:entry>
</j:if>

<f:entry title="${%Xvfb specific displayname}" field="displayName">
<f:textbox value="${instance.displayName}" />
</f:entry>

<f:entry title="${%Timeout in seconds}" field="timeout">
<f:textbox value="${instance.timeout}" />
</f:entry>

<f:entry title="${%Xvfb screen}" field="screen">
<f:textbox value="${instance.screen}" />
</f:entry>

<f:entry title="${%Xvfb additional options}" field="additionalOptions">
<f:textbox value="${instance.additionalOptions}" />
</f:entry>

<f:entry title="${%Log Xvfb output}" field="debug">
<f:checkbox value="${instance.debug}" />
</f:entry>
</f:advanced>

</j:jelly>
@@ -0,0 +1,26 @@
<!--
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>Additional options to be added with the options above to the
Xvfb command line.</div>

0 comments on commit 8b6ee55

Please sign in to comment.