Skip to content

Commit

Permalink
Merge pull request #15 from olivergondza/adapt-to-new-vncserver
Browse files Browse the repository at this point in the history
Adapt to new vncserver
  • Loading branch information
olivergondza committed Oct 7, 2021
2 parents 5c917ea + 3c5720f commit a283cd7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 32 deletions.
4 changes: 3 additions & 1 deletion Jenkinsfile
Expand Up @@ -4,7 +4,9 @@ node('docker') {
docker.image('jenkins/ath:acceptance-test-harness-1.73').inside {
stage('test') {
checkout scm
sh 'mvn -B --no-transfer-progress clean package -Dmaven.test.failure.ignore'
// Skipping enforcer inside ATH container as the maven there is too old
// TODO: remove after https://github.com/jenkinsci/acceptance-test-harness/pull/690
sh 'mvn -B --no-transfer-progress clean package -Dmaven.test.failure.ignore -Denforcer.skip'
junit '**/target/surefire-reports/TEST-*.xml'
}
}
Expand Down
30 changes: 13 additions & 17 deletions pom.xml
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>3.55</version>
<version>4.27</version>
</parent>

<artifactId>xvnc</artifactId>
Expand Down Expand Up @@ -31,58 +31,54 @@
<tag>HEAD</tag>
</scm>
<properties>
<jenkins.version>2.60</jenkins.version>
<jenkins.version>2.277.3</jenkins.version>
<java.level>8</java.level>
<workflow.version>1.8</workflow.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.277.x</artifactId>
<version>950.v396cb834de1e</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>structs</artifactId>
<version>1.5</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-job</artifactId>
<version>${workflow.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-basic-steps</artifactId>
<version>${workflow.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps</artifactId>
<version>${workflow.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-durable-task-step</artifactId>
<version>${workflow.version}</version>
<scope>test</scope>
</dependency>
<dependency> <!-- StepConfigTester -->
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>${workflow.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency> <!-- SemaphoreStep -->
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-support</artifactId>
<version>${workflow.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency> <!-- JenkinsRuleExt -->
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-aggregator</artifactId>
<version>${workflow.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/hudson/plugins/xvnc/DisplayAllocator.java
Expand Up @@ -15,6 +15,7 @@
*/
final class DisplayAllocator {

public static final Random RANDOM = new Random();
transient Saveable owner;

/**
Expand All @@ -37,7 +38,7 @@ private void save() {
}

private int getRandomValue(final int min, final int max) {
return min + (new Random().nextInt(getRange(min, max)));
return min + (RANDOM.nextInt(getRange(min, max)));
}

private int getRange(final int min, final int max) {
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/hudson/plugins/xvnc/Xvnc.java
Expand Up @@ -45,7 +45,6 @@
*/
public class Xvnc extends SimpleBuildWrapper {
private static final String XAUTHORITY_ENV = "XAUTHORITY";
public static final String VNCSERVER = "vncserver";
/**
* Whether or not to take a screenshot upon completion of the build.
*/
Expand Down Expand Up @@ -138,13 +137,13 @@ private void doSetUp(Context context, Run<?,?> build, FilePath workspace, Node n

final Proc proc = launcher.launch().cmds(cmds).envs(xauthorityEnv).stdout(logger).pwd(workspace).start();
final String vncserverCommand;
if (cmds[0].endsWith(VNCSERVER) && cmd.contains(":$DISPLAY_NUMBER")) {
// Command just started the server; -kill will stop it.
if (cmds[0].endsWith("vncserver") && cmd.contains(":$DISPLAY_NUMBER")) {
// vncserver command starts the server in the background; -kill will stop it.
vncserverCommand = cmds[0];
int exit = proc.join();
if (exit != 0) {
// XXX I18N
String message = "Failed to run \'" + actualCmd + "\' (exit code " + exit + "), blacklisting display #" + displayNumber +
String message = "Failed to run '" + actualCmd + "' (exit code " + exit + "), blacklisting display #" + displayNumber +
"; consider checking the \"Clean up before start\" option";
// Do not release it; it may be "stuck" until cleaned up by an administrator.
//allocator.free(displayNumber);
Expand All @@ -165,24 +164,25 @@ private void doSetUp(Context context, Run<?,?> build, FilePath workspace, Node n
context.setDisposer(new DisposerImpl(displayNumber, xauthorityEnv, vncserverCommand, takeScreenshot, xauthority != null ? xauthority.getRemote() : null));
}

// vncserver was the default choice for years. Use it if it is present, fallback to Xvnc if that is present, use
// vncserver if all that fails to error in a predictable way.
// vncserver was the default choice for years, distributions switching to systemd activation stopped supporting it.
// The vncserver from tigervnc 1.11.0+ does not support needed options at all, so Xvnc is prefered
private String detectXvncCommand(FilePath workspace, Launcher launcher) throws InterruptedException {

try {
launcher.launch().cmds(VNCSERVER, "-list").pwd(workspace).join();
return VNCSERVER;
} catch (IOException ex) {
launcher.launch().cmds("Xvnc", "-help").pwd(workspace).join();
return "Xvnc";
} catch (IOException exx) {
// Fallback
}

try {
launcher.launch().cmds("Xvnc", "-help").pwd(workspace).join();
return "Xvnc";
} catch (IOException exx) {
launcher.launch().cmds("vncserver", "-list").pwd(workspace).join();
return "vncserver";
} catch (IOException ex) {
// Fallback
}
return VNCSERVER;

return "Xvnc"; // Return default choice, so the build fails pointing out the problem
}

/**
Expand Down

0 comments on commit a283cd7

Please sign in to comment.