Skip to content

Commit

Permalink
Merge pull request #2 from jglick/RunAction2-JENKINS-20950
Browse files Browse the repository at this point in the history
[JENKINS-20950] Use RunAction2
  • Loading branch information
rsandell committed Dec 13, 2013
2 parents 2842fd9 + 9bd3d38 commit 60e54b2
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 23 deletions.
4 changes: 1 addition & 3 deletions pom.xml
Expand Up @@ -3,9 +3,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.424</version>
<!-- which version of Jenkins is this plugin built against? -->
<relativePath>pom.xml</relativePath>
<version>1.509.3</version>
</parent>

<groupId>com.sonyericsson.hudson.plugins.metadata</groupId>
Expand Down
Expand Up @@ -168,7 +168,7 @@ public static MetadataContainer<MetadataValue> getContainer(String node, String
if (action != null) {
container = action;
} else if (createContainer) {
action = new MetadataBuildAction(buildByNumber);
action = new MetadataBuildAction();
buildByNumber.addAction(action);
container = action;
} else {
Expand Down
Expand Up @@ -55,7 +55,7 @@ public void onCompleted(AbstractBuild build, TaskListener listener) {
logger.entering(BuildContributorsController.class.getName(), "onCompleted({0})", build);
MetadataBuildAction action = build.getAction(MetadataBuildAction.class);
if (action == null) {
action = new MetadataBuildAction(build);
action = new MetadataBuildAction();
build.addAction(action);
}
listener.getLogger().println(Messages.BuildContributorsController_LogMessage_Collecting());
Expand Down Expand Up @@ -91,7 +91,7 @@ public void onStarted(AbstractBuild build, TaskListener listener) {
}
MetadataBuildAction action = build.getAction(MetadataBuildAction.class);
if (action == null) {
action = new MetadataBuildAction(build);
action = new MetadataBuildAction();
build.addAction(action);
}

Expand Down
Expand Up @@ -28,7 +28,6 @@
import com.sonyericsson.hudson.plugins.metadata.Messages;
import com.sonyericsson.hudson.plugins.metadata.model.values.MetadataValue;
import com.sonyericsson.hudson.plugins.metadata.model.values.ParentUtil;
import hudson.model.Action;
import hudson.model.Hudson;
import hudson.model.Run;
import hudson.security.ACL;
Expand All @@ -38,6 +37,7 @@
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import jenkins.model.RunAction2;

/**
* Holds the meta data for a run.
Expand All @@ -47,17 +47,12 @@
@edu.umd.cs.findbugs.annotations.SuppressWarnings(
value = "UG_SYNC_SET_UNSYNC_GET",
justification = "It is synchronized")
public class MetadataBuildAction implements Action, MetadataContainer<MetadataValue> {
public class MetadataBuildAction implements RunAction2, MetadataContainer<MetadataValue> {

private Run run;
private transient Run run;
private List<MetadataValue> values;

/**
* Standard constructor.
*
* @param run The run that this action is added to.
* @param values the meta data for this run.
*/
@Deprecated
public MetadataBuildAction(Run run, List<MetadataValue> values) {
this.run = run;
if (values == null) {
Expand All @@ -66,11 +61,7 @@ public MetadataBuildAction(Run run, List<MetadataValue> values) {
this.values = values;
}

/**
* Standard constructor.
*
* @param run The run that this action is added to.
*/
@Deprecated
public MetadataBuildAction(Run run) {
this(run, null);
}
Expand All @@ -97,6 +88,16 @@ public String getUrlName() {
return Constants.COMMON_URL_NAME;
}

@Override
public void onAttached(Run<?,?> r) {
this.run = r;
}

@Override
public void onLoad(Run<?,?> r) {
this.run = r;
}

/**
* The run that this action is added to.
*
Expand Down
Expand Up @@ -363,7 +363,6 @@ public void testGetContainerNoMetadataOnBuildCreate() throws Exception {

MetadataParent container = CliUtils.getContainer(null, "theJob", 1, true);
assertNotNull(container);
assertSame(build, Whitebox.getInternalState(container, "run"));
verify(build).addAction(isA(MetadataBuildAction.class));
}

Expand Down
Expand Up @@ -94,7 +94,7 @@ public void testFilterACL() throws Exception {
hudson.addView(view);

WebClient web = createWebClient();
Page page = web.goTo("/view/Test/api/json", "application/javascript");
Page page = web.goTo("/view/Test/api/json", "application/json");
JSONObject json = (JSONObject)JSONSerializer.toJSON(page.getWebResponse().getContentAsString());
//Just to test that we can find both in an open installation.
assertTrue(json.has("jobs"));
Expand All @@ -108,7 +108,7 @@ public void testFilterACL() throws Exception {
web = createWebClient();
web = web.login("testuser");

page = web.goTo("/view/Test/api/json", "application/javascript");
page = web.goTo("/view/Test/api/json", "application/json");
json = (JSONObject)JSONSerializer.toJSON(page.getWebResponse().getContentAsString());
//Does it still applies to secured projects?
assertTrue(json.has("jobs"));
Expand Down

0 comments on commit 60e54b2

Please sign in to comment.