Skip to content
Merged
43 changes: 39 additions & 4 deletions src/main/java/hudson/plugins/testlink/TestLinkBuildAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,52 @@

import hudson.model.Action;
import hudson.model.AbstractBuild;
import hudson.model.Run;
import hudson.plugins.testlink.util.TestLinkHelper;

import java.io.Serializable;

import jenkins.model.RunAction2;
import org.kohsuke.stapler.StaplerProxy;

/**
* @author Bruno P. Kinoshita - http://www.kinoshita.eti.br
* @since 1.0
*/
public class TestLinkBuildAction implements Action, Serializable, StaplerProxy {
public class TestLinkBuildAction implements RunAction2, Serializable, StaplerProxy {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surprisingly, #25 does not do that


private static final long serialVersionUID = -914904584770393909L;

public static final String DISPLAY_NAME = "TestLink";
public static final String ICON_FILE_NAME = "/plugin/testlink/icons/testlink-24.png";
public static final String URL_NAME = "testLinkResult";

private AbstractBuild<?, ?> build;
private transient Run<?, ?> build;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good, making this transient should solve a host of issues.

private TestLinkResult result;

public TestLinkBuildAction(TestLinkResult result) {
this.result = result;
}

/**
* @deprecated Use {@link #TestLinkBuildAction(TestLinkResult)} without build definition.
*/
@Deprecated
public TestLinkBuildAction(AbstractBuild<?, ?> build, TestLinkResult result) {
this.build = build;
this.result = result;
}

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

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

public String getDisplayName() {
return DISPLAY_NAME;
}
Expand All @@ -67,10 +87,25 @@ public Object getTarget() {
return this.result;
}

public AbstractBuild<?, ?> getBuild() {
/**
* Gets Run to which the action is attached.
* @return Run instance
* @since TODO
*/
public Run<?, ?> getRun() {
return build;
}

/**
* @deprecated Use {@link #getRun()}
*/
public AbstractBuild<?, ?> getBuild() {
if (build instanceof AbstractBuild<?, ?>) {
return (AbstractBuild<?, ?>)build;
}
throw new IllegalStateException("Calling old API against a non-AbstractBuild run type. Run: " + build);
}

/**
* @return TestLink job execution result
*/
Expand Down Expand Up @@ -107,7 +142,7 @@ public TestLinkResult getPreviousResult() {
*/
public TestLinkBuildAction getPreviousAction() {
if (this.build != null) {
AbstractBuild<?, ?> previousBuild = this.build.getPreviousBuild();
Run<?, ?> previousBuild = this.build.getPreviousBuild();
if (previousBuild != null) {
return previousBuild.getAction(TestLinkBuildAction.class);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/hudson/plugins/testlink/TestLinkBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,

listener.getLogger().println(Messages.TestLinkBuilder_ShowFoundTestResults(report.getTestsTotal()));

final TestLinkResult result = new TestLinkResult(report, build);
final TestLinkBuildAction buildAction = new TestLinkBuildAction(build, result);
final TestLinkResult result = new TestLinkResult(report);
final TestLinkBuildAction buildAction = new TestLinkBuildAction(result);
build.addAction(buildAction);

if(report.getTestsTotal() <= 0 && this.getFailIfNoResults() == Boolean.TRUE) {
Expand Down
24 changes: 22 additions & 2 deletions src/main/java/hudson/plugins/testlink/TestLinkResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,39 @@
/**
* @author Bruno P. Kinoshita - http://www.kinoshita.eti.br
* @since 1.0
* @see TestLinkBuildAction
*/
public class TestLinkResult implements Serializable {

private static final long serialVersionUID = 3355678827881770594L;

private Report report;
private AbstractBuild<?, ?> build;
private final Report report;

// It would be possible to link actions, but there is no immediate need in the plugin API
private final transient AbstractBuild<?, ?> build;

/**
* Constructor
* @param report
*/
public TestLinkResult(Report report) {
this.report = report;
this.build = null;
}

/**
* @deprecated Use {@link #TestLinkResult(Report)}
*/
@Deprecated
public TestLinkResult(Report report, AbstractBuild<?, ?> build) {
this.report = report;
this.build = build;
}

/**
* @deprecated No longer used AND not persisted during restarts
*/
@Deprecated
public AbstractBuild<?, ?> getOwner() {
return this.build;
}
Expand Down
9 changes: 9 additions & 0 deletions src/main/resources/META-INF/hudson.remoting.ClassFilter
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# In TestCaseWrapper, contains only base classes
br.eti.kinoshita.testlinkjavaapi.model.Attachment

# Test case and nested classes which may need whitelisting, no deserialization logic there
br.eti.kinoshita.testlinkjavaapi.model.TestCase
br.eti.kinoshita.testlinkjavaapi.model.TestCaseStep
br.eti.kinoshita.testlinkjavaapi.model.CustomField
br.eti.kinoshita.testlinkjavaapi.model.Platform

Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ public void testWithJenkinsObjects() {
hudsonBuild1 = project.createExecutable();
hudsonBuild1.number = 1;
Report report = new Report(1, null);
TestLinkResult result = new TestLinkResult(report, hudsonBuild1);
TestLinkBuildAction buildAction = new TestLinkBuildAction(hudsonBuild1, result);
TestLinkResult result = new TestLinkResult(report);
TestLinkBuildAction buildAction = new TestLinkBuildAction(result);
hudsonBuild1.addAction(buildAction);
hudsonBuild1.run();

hudsonBuild2 = project.createExecutable();
Report report2 = new Report(1, null);
TestLinkResult result2 = new TestLinkResult(report2, hudsonBuild1);
TestLinkBuildAction buildAction2 = new TestLinkBuildAction(hudsonBuild1, result2);
TestLinkResult result2 = new TestLinkResult(report2);
TestLinkBuildAction buildAction2 = new TestLinkBuildAction(result2);
hudsonBuild2.addAction(buildAction2);
hudsonBuild2.run();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,10 @@ public void testTestLinkResult()
{
Report report = new Report(1, null);
AbstractBuild<?, ?> build = null;
TestLinkResult tlr = new TestLinkResult(report, build);
TestLinkResult tlr = new TestLinkResult(report);

assertNotNull( tlr );

assertNull( tlr.getOwner() );

assertNotNull( tlr.getReport() );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,11 @@ public void setUp() throws Exception {
class ResultSeekerBuilder extends Builder implements Serializable {

private static final long serialVersionUID = 3497104063426101764L;

private ResultSeeker seeker;
private TestCaseWrapper[] tcs;
private TestLinkSiteFake testlink;

// Not serialized to the disk - test class
private transient ResultSeeker seeker;
private transient TestCaseWrapper[] tcs;
private transient TestLinkSiteFake testlink;

public ResultSeekerBuilder(ResultSeeker seeker, TestCaseWrapper[] tcs, TestLinkSiteFake testlink) {
this.seeker = seeker;
Expand Down