Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b53770c

Browse files
jglickolivergondza
authored andcommittedJan 5, 2014
[FIXED JENKINS-18410] AbstractTestResultAction should be a RunAction2 so it need not persist its owning build.
(cherry picked from commit fcdf749) Conflicts: changelog.html
1 parent 0b20686 commit b53770c

9 files changed

+56
-14
lines changed
 

‎core/src/main/java/hudson/tasks/junit/JUnitResultArchiver.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ public boolean perform(AbstractBuild build, Launcher launcher,
133133
TestResult result = parse(testResults, build, launcher, listener);
134134

135135
try {
136+
// TODO can the build argument be omitted now, or is it used prior to the call to addAction?
136137
action = new TestResultAction(build, result, listener);
137138
} catch (NullPointerException npe) {
138139
throw new AbortException(Messages.JUnitResultArchiver_BadXML(testResults));
@@ -173,7 +174,7 @@ public boolean perform(AbstractBuild build, Launcher launcher,
173174
return true;
174175
}
175176

176-
build.getActions().add(action);
177+
build.addAction(action);
177178
CHECKPOINT.report();
178179

179180
if (action.getResult().getFailCount() > 0)

‎core/src/main/java/hudson/tasks/junit/TestResultAction.java

+6
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,17 @@ public class TestResultAction extends AbstractTestResultAction<TestResultAction>
6262
private Integer totalCount;
6363
private List<Data> testData = new ArrayList<Data>();
6464

65+
@Deprecated
6566
public TestResultAction(AbstractBuild owner, TestResult result, BuildListener listener) {
6667
super(owner);
6768
setResult(result, listener);
6869
}
6970

71+
/** @since 1.544 */
72+
public TestResultAction(TestResult result, BuildListener listener) {
73+
this(null, result, listener);
74+
}
75+
7076
/**
7177
* Overwrites the {@link TestResult} by a new data set.
7278
*/

‎core/src/main/java/hudson/tasks/test/AbstractTestResultAction.java

+23-9
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@
2828
import hudson.tasks.junit.CaseResult;
2929
import hudson.util.*;
3030
import hudson.util.ChartUtil.NumberOnlyBuildLabel;
31+
32+
import java.awt.*;
33+
import java.io.IOException;
34+
import java.util.Collections;
35+
import java.util.List;
36+
import java.util.Map;
37+
import java.util.concurrent.ConcurrentHashMap;
38+
import jenkins.model.RunAction2;
3139
import org.jfree.chart.ChartFactory;
3240
import org.jfree.chart.JFreeChart;
3341
import org.jfree.chart.axis.CategoryAxis;
@@ -44,13 +52,6 @@
4452
import org.kohsuke.stapler.export.Exported;
4553
import org.kohsuke.stapler.export.ExportedBean;
4654

47-
import java.awt.*;
48-
import java.io.IOException;
49-
import java.util.Collections;
50-
import java.util.List;
51-
import java.util.Map;
52-
import java.util.concurrent.ConcurrentHashMap;
53-
5455
/**
5556
* Common base class for recording test result.
5657
*
@@ -61,15 +62,28 @@
6162
* @author Kohsuke Kawaguchi
6263
*/
6364
@ExportedBean
64-
public abstract class AbstractTestResultAction<T extends AbstractTestResultAction> implements HealthReportingAction {
65-
public final AbstractBuild<?,?> owner;
65+
public abstract class AbstractTestResultAction<T extends AbstractTestResultAction> implements HealthReportingAction, RunAction2 {
66+
public transient AbstractBuild<?,?> owner;
6667

6768
private Map<String,String> descriptions = new ConcurrentHashMap<String, String>();
6869

70+
/** @since 1.544 */
71+
protected AbstractTestResultAction() {}
72+
73+
/** @deprecated Use the default constructor and just call {@link Run#addAction} to associate the build with the action. */
74+
@Deprecated
6975
protected AbstractTestResultAction(AbstractBuild owner) {
7076
this.owner = owner;
7177
}
7278

79+
@Override public void onAttached(Run<?, ?> r) {
80+
this.owner = (AbstractBuild<?,?>) r;
81+
}
82+
83+
@Override public void onLoad(Run<?, ?> r) {
84+
this.owner = (AbstractBuild<?,?>) r;
85+
}
86+
7387
/**
7488
* Gets the number of failed tests.
7589
*/

‎core/src/main/java/hudson/tasks/test/AggregatedTestResultAction.java

+4
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,14 @@ public Child(String name, int build) {
6767
*/
6868
public final List<Child> children = new ArrayList<Child>();
6969

70+
@Deprecated
7071
public AggregatedTestResultAction(AbstractBuild owner) {
7172
super(owner);
7273
}
7374

75+
/** @since 1.544 */
76+
public AggregatedTestResultAction() {}
77+
7478
protected void update(List<? extends AbstractTestResultAction> children) {
7579
failCount = skipCount = totalCount = 0;
7680
this.children.clear();

‎core/src/main/java/hudson/tasks/test/AggregatedTestResultPublisher.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public AggregatedTestResultPublisher(String jobs, boolean includeFailedBuilds) {
8787

8888
public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
8989
// add a TestResult just so that it can show up later.
90-
build.addAction(new TestResultAction(jobs,includeFailedBuilds,build));
90+
build.addAction(new TestResultAction(jobs, includeFailedBuilds));
9191
return true;
9292
}
9393

@@ -131,6 +131,11 @@ public static final class TestResultAction extends AbstractTestResultAction {
131131
private transient List<AbstractProject> didntRun;
132132
private transient List<AbstractProject> noFingerprints;
133133

134+
public TestResultAction(String jobs, boolean includeFailedBuilds) {
135+
this(jobs, includeFailedBuilds, null);
136+
}
137+
138+
@Deprecated
134139
public TestResultAction(String jobs, boolean includeFailedBuilds, AbstractBuild<?,?> owner) {
135140
super(owner);
136141
this.includeFailedBuilds = includeFailedBuilds;

‎core/src/main/java/hudson/tasks/test/MatrixTestResult.java

+5
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,15 @@
3838
* @author Kohsuke Kawaguchi
3939
*/
4040
public class MatrixTestResult extends AggregatedTestResultAction {
41+
42+
@Deprecated
4143
public MatrixTestResult(MatrixBuild owner) {
4244
super(owner);
4345
}
4446

47+
/** @since 1.544 */
48+
public MatrixTestResult() {}
49+
4550
/**
4651
* Use the configuration name.
4752
*/

‎core/src/main/java/hudson/tasks/test/TestResultAggregator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public TestResultAggregator(MatrixBuild build, Launcher launcher, BuildListener
4646

4747
@Override
4848
public boolean startBuild() throws InterruptedException, IOException {
49-
result = new MatrixTestResult(build);
49+
result = new MatrixTestResult();
5050
build.addAction(result);
5151
return true;
5252
}

‎test/src/test/java/hudson/tasks/test/TrivialTestResultAction.java

+7
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,19 @@
3232
public class TrivialTestResultAction extends AbstractTestResultAction<TrivialTestResultAction> implements StaplerProxy {
3333

3434
protected TrivialTestResult result;
35+
36+
@Deprecated
3537
protected TrivialTestResultAction(AbstractBuild owner, TrivialTestResult result) {
3638
super(owner);
3739
this.result = result;
3840
this.result.setParentAction(this);
3941
}
4042

43+
/** @since 1.544 */
44+
protected TrivialTestResultAction(TrivialTestResult result) {
45+
this(null, result);
46+
}
47+
4148
/**
4249
* Gets the number of failed tests.
4350
*/

‎test/src/test/java/hudson/tasks/test/TrivialTestResultRecorder.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ public boolean perform(AbstractBuild<?, ?> build,
4848
System.out.println("performing TrviialTestResultRecorder");
4949
listener.getLogger().println("perfoming TrivialTestResultRecorder");
5050
TrivialTestResult r = new TrivialTestResult("gubernatorial");
51-
TrivialTestResultAction action = new TrivialTestResultAction(build, r);
51+
TrivialTestResultAction action = new TrivialTestResultAction(r);
5252
r.setParentAction(action);
53-
build.getActions().add(action);
53+
build.addAction(action);
5454
listener.getLogger().println("done with TrivialTestResultRecorder");
5555
System.out.println("done with TrivialTestResultRecorder");
5656
return true;

0 commit comments

Comments
 (0)
Please sign in to comment.