Skip to content

Commit

Permalink
Merge pull request #71 from Greybird/master
Browse files Browse the repository at this point in the history
Expose test data publicly
  • Loading branch information
olivergondza committed Aug 4, 2017
2 parents c775db6 + 0d53590 commit a3f21be
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
3 changes: 1 addition & 2 deletions src/main/java/hudson/tasks/junit/JUnitResultArchiver.java
Expand Up @@ -177,12 +177,11 @@ public void perform(Run build, FilePath workspace, Launcher launcher,
}

// TODO: Move into JUnitParser [BUG 3123310]
List<Data> data = action.getData();
if (testDataPublishers != null) {
for (TestDataPublisher tdp : testDataPublishers) {
Data d = tdp.contributeTestData(build, workspace, launcher, listener, result);
if (d != null) {
data.add(d);
action.addData(d);
}
}
}
Expand Down
39 changes: 31 additions & 8 deletions src/main/java/hudson/tasks/junit/TestResultAction.java
Expand Up @@ -222,10 +222,12 @@ public List<TestAction> getActions(TestObject object) {
List<TestAction> result = new ArrayList<TestAction>();
// Added check for null testData to avoid NPE from issue 4257.
if (testData != null) {
for (Data data : testData)
for (TestAction ta : data.getTestAction(object))
if (ta != null)
result.add(ta);
synchronized (testData) {
for (Data data : testData)
for (TestAction ta : data.getTestAction(object))
if (ta != null)
result.add(ta);
}
}
return Collections.unmodifiableList(result);
}
Expand All @@ -234,8 +236,29 @@ List<Data> getData() {
return testData;
}

/**
* Replaces to collection of test data associated with this action.
*
* <p>
* This method will not automatically persist the data at the time of addition.
*
*/
public void setData(List<Data> testData) {
this.testData = testData;
this.testData = testData;
}

/**
* Adds a {@link Data} to the test data associated with this action.
*
* <p>
* This method will not automatically persist the data at the time of addition.
*
* @since TODO
*/
public void addData(Data data) {
synchronized (testData) {
this.testData.add(data);
}
}

/**
Expand All @@ -258,7 +281,7 @@ void mergeResult(TestResult additionalResult, TaskListener listener) {
public static abstract class Data {
/**
* Returns all TestActions for the testObject.
*
*
* @return
* Can be empty but never null. The caller must assume that the returned list is read-only.
*/
Expand All @@ -270,10 +293,10 @@ public Object readResolve() {
if (testData == null) {
testData = new ArrayList<Data>(0);
}

return this;
}

private static final Logger logger = Logger.getLogger(TestResultAction.class.getName());

private static final XStream XSTREAM = new XStream2();
Expand Down

0 comments on commit a3f21be

Please sign in to comment.