Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
committed
Oct 12, 2013
1 parent
e6a5255
commit d960207
Showing
2 changed files
with
70 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters