Skip to content
Permalink
Browse files

Move all ClaimBuildAction references to ClaimWrapper class

This is done to ensure that the Claim plugin remains an optional dependency.

[FIXED JENKINS-19961]
  • Loading branch information...
David Resnick
David Resnick committed Oct 12, 2013
1 parent e6a5255 commit d960207f55fb4b30208bedbe805ea761e50dc2e6
Showing with 70 additions and 25 deletions.
  1. +60 −0 src/main/java/hudson/model/ClaimWrapper.java
  2. +10 −25 src/main/java/hudson/model/JobViewEntry.java
@@ -0,0 +1,60 @@
package hudson.model;

import hudson.plugins.claim.ClaimBuildAction;

import java.util.List;

import org.jfree.util.Log;

/**
* Wraps ClaimBuildAction to ensure that the Claim plugin remains optional
* to the Radiator View.
*/
public class ClaimWrapper {

private ClaimBuildAction claimBuildAction;

private ClaimWrapper(ClaimBuildAction claimBuildAction) {
this.claimBuildAction = claimBuildAction;
}

/**
* Returns ClaimWrapper containing the claim for the specified run
* if there is a single ClaimBuildAction for the run. Returns null
* otherwise.
*
* @param run
* @return null if no single ClaimBuildAction for the run param.
*/
static public ClaimWrapper builder(Run<?, ?> run) {
ClaimBuildAction claimForRun = getClaimForRun(run);
if (claimForRun == null) {
return null;
}
return new ClaimWrapper(claimForRun);
}

static private ClaimBuildAction getClaimForRun(Run<?, ?> run) {
ClaimBuildAction claimAction = null;
List<ClaimBuildAction> claimActionList = run
.getActions(ClaimBuildAction.class);
if (claimActionList.size() == 1) {
claimAction = claimActionList.get(0);
} else if (claimActionList.size() > 1) {
Log.warn("Multiple ClaimBuildActions found for job ");
}
return claimAction;
}

public boolean isClaimed() {
return claimBuildAction.isClaimed();
}

public String getReason() {
return claimBuildAction.getReason();
}

public String getClaimedByName() {
return claimBuildAction.getClaimedByName();
}
}
@@ -3,7 +3,6 @@
import hudson.Functions;
import hudson.matrix.MatrixRun;
import hudson.matrix.MatrixBuild;
import hudson.plugins.claim.ClaimBuildAction;
import hudson.tasks.test.AbstractTestResultAction;

import java.text.NumberFormat;
@@ -15,7 +14,6 @@
import java.util.Set;

import org.apache.commons.lang.StringUtils;
import org.jfree.util.Log;

/**
* Represents a job to be shown in a view. Based heavily on the XFPanelEntry in
@@ -423,14 +421,14 @@ public String getClaim() {
MatrixBuild matrixBuild = (hudson.matrix.MatrixBuild) lastBuild;
claim = buildMatrixClaimString(matrixBuild, true);
} else {
ClaimBuildAction claimAction = getClaimForRun(lastBuild);
if (claimAction != null && claimAction.isClaimed()) {
ClaimWrapper claimWrapper = ClaimWrapper.builder(lastBuild);
if (claimWrapper != null && claimWrapper.isClaimed()) {
StringBuilder sb = new StringBuilder();
if (claimAction.getReason() != null) {
sb.append(claimAction.getReason()).append(" ");
if (claimWrapper.getReason() != null) {
sb.append(claimWrapper.getReason()).append(" ");
}
sb.append("(");
sb.append(claimAction.getClaimedByName());
sb.append(claimWrapper.getClaimedByName());
sb.append(").");
claim = sb.toString();
} else {
@@ -470,16 +468,16 @@ private String buildMatrixClaimString(MatrixBuild matrixBuild, boolean includeCl
if (!(Result.FAILURE.equals(result) || Result.UNSTABLE.equals(result))) {
continue;
}
ClaimBuildAction claimAction = getClaimForRun(combination);
if (claimAction != null && claimAction.isClaimed()) {
ClaimWrapper claimWrapper = ClaimWrapper.builder(combination);
if (claimWrapper != null && claimWrapper.isClaimed()) {
claimed.append(combination.getParent().getCombination()
.toString());
claimed.append(": ");
if (claimAction.getReason() != null) {
claimed.append(claimAction.getReason()).append(" ");
if (claimWrapper.getReason() != null) {
claimed.append(claimWrapper.getReason()).append(" ");
}
claimed.append("(");
claimed.append(claimAction.getClaimedByName());
claimed.append(claimWrapper.getClaimedByName());
claimed.append(").<br/>");
} else {
unclaimed.append(combination.getParent().getCombination().toString());
@@ -494,19 +492,6 @@ private String buildMatrixClaimString(MatrixBuild matrixBuild, boolean includeCl
return claims;
}

private ClaimBuildAction getClaimForRun(Run<?, ?> run) {
ClaimBuildAction claimAction = null;
List<ClaimBuildAction> claimActionList = run
.getActions(ClaimBuildAction.class);
if (claimActionList.size() == 1) {
claimAction = claimActionList.get(0);
} else if (claimActionList.size() > 1) {
Log.warn("Multiple ClaimBuildActions found for job "
+ job.toString());
}
return claimAction;
}

public boolean isClaimed() {
return !NOT_CLAIMED.equals(getClaim());
}

0 comments on commit d960207

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