Skip to content
Permalink
Browse files

Merge pull request #5 from jglick/SimpleBuildWrapper-JENKINS-24673

[JENKINS-26477] SimpleBuildWrapper integration
  • Loading branch information
jglick committed Jun 10, 2015
2 parents 4871130 + 4825c96 commit 4d7c6b521d21f8fcbe8e358eb578ed5b89603a8b
58 pom.xml
@@ -3,7 +3,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.444</version>
<version>1.609.1</version>
</parent>

<artifactId>xvnc</artifactId>
@@ -23,15 +23,69 @@
<email>ogondza@gmail.com</email>
</developer>
</developers>
<scm>
<licenses>
<license>
<name>MIT License</name>
<url>http://opensource.org/licenses/MIT</url>
</license>
</licenses>
<scm>
<connection>scm:git:git://github.com/jenkinsci/${project.artifactId}-plugin.git</connection>
<developerConnection>scm:git:git@github.com:jenkinsci/${project.artifactId}-plugin.git</developerConnection>
<url>http://github.com/jenkinsci/${project.artifactId}-plugin</url>
<tag>HEAD</tag>
</scm>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<workflow.version>1.8</workflow.version>
</properties>
<dependencies>
<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>
</dependencies>
<build>
<plugins>
<plugin>
@@ -1,23 +1,22 @@
package hudson.plugins.xvnc;

import hudson.Extension;
import hudson.model.Node;
import hudson.slaves.NodeProperty;
import hudson.slaves.NodePropertyDescriptor;

import hudson.model.Saveable;
import java.io.IOException;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;

import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* Manages the display numbers in use.
*
* @author Kohsuke Kawaguchi
*/
final class DisplayAllocator {

transient Saveable owner;

/**
* Display numbers in use.
*/
@@ -27,6 +26,16 @@
public DisplayAllocator() {
}

private void save() {
if (owner != null) {
try {
owner.save();
} catch (IOException x) {
Logger.getLogger(DisplayAllocator.class.getName()).log(Level.WARNING, null, x);
}
}
}

private int getRandomValue(final int min, final int max) {
return min + (new Random().nextInt(getRange(min, max)));
}
@@ -35,7 +44,14 @@ private int getRange(final int min, final int max) {
return (max + 1) - min;
}

public synchronized int allocate(final int minDisplayNumber, final int maxDisplayNumber) {
public int allocate(final int minDisplayNumber, final int maxDisplayNumber) {
try {
return doAllocate(minDisplayNumber, maxDisplayNumber);
} finally {
save();
}
}
private synchronized int doAllocate(final int minDisplayNumber, final int maxDisplayNumber) {
if (noDisplayNumbersLeft(minDisplayNumber, maxDisplayNumber)) {
if (!blacklistedNumbers.isEmpty()) {
blacklistedNumbers.clear();
@@ -61,34 +77,19 @@ private boolean noDisplayNumbersLeft(final int min, final int max) {
return allocatedNumbers.size() + blacklistedNumbers.size() >= getRange(min, max);
}

public synchronized void free(int n) {
allocatedNumbers.remove(n);
public void free(int n) {
synchronized (this) {
allocatedNumbers.remove(n);
}
save();
}

public void blacklist(int badDisplay) {
free(badDisplay);
blacklistedNumbers.add(badDisplay);
}

@Restricted(NoExternalUse.class)
/*package*/ static final class Property extends NodeProperty<Node> {

private transient /*final*/ DisplayAllocator allocator = new DisplayAllocator();

/*package*/ DisplayAllocator getAllocator() {
return allocator;
}

private Object readResolve() {
allocator = new DisplayAllocator();
return this;
}

@Extension
public static class DescriptorImpl extends NodePropertyDescriptor {

@Override
public String getDisplayName() { return null; }
synchronized (this) {
allocatedNumbers.remove(badDisplay);
blacklistedNumbers.add(badDisplay);
}
save();
}

}

0 comments on commit 4d7c6b5

Please sign in to comment.
You can’t perform that action at this time.