Skip to content
Permalink
Browse files

Fix JENKINS-6200

  • Loading branch information...
gboissinot committed May 8, 2013
1 parent e9265a7 commit 5128b7dc41c280a26388ace4ddae64266460e56a
Showing with 33 additions and 14 deletions.
  1. +33 −14 src/main/java/org/jenkinsci/plugins/xunit/XUnitPublisher.java
@@ -113,10 +113,22 @@ private boolean performXUnit(boolean dryRun, AbstractBuild<?, ?> build, BuildLis

xUnitLog.infoConsoleLogger("Starting to record.");

boolean noProcessingErrors = performTests(xUnitLog, build, listener);
if (!noProcessingErrors) {
boolean continueTestProcessing;
try {

continueTestProcessing = performTests(xUnitLog, build, listener);

} catch (StopTestProcessingException e) {
build.setResult(Result.FAILURE);
xUnitLog.infoConsoleLogger("Stopping recording.");
xUnitLog.infoConsoleLogger("There are errors when processing test results.");
xUnitLog.infoConsoleLogger("Skipping tests recording.");
xUnitLog.infoConsoleLogger("Stop build.");
return true;
}

if (!continueTestProcessing) {
xUnitLog.infoConsoleLogger("There are errors when processing test results.");
xUnitLog.infoConsoleLogger("Skipping tests recording.");
return true;
}

@@ -159,22 +171,30 @@ protected void configure() {
}).getInstance(XUnitReportProcessorService.class);
}

private boolean performTests(XUnitLog xUnitLog, AbstractBuild<?, ?> build, BuildListener listener) throws IOException, InterruptedException {

private boolean performTests(XUnitLog xUnitLog, AbstractBuild<?, ?> build, BuildListener listener) throws IOException, InterruptedException, StopTestProcessingException {
XUnitReportProcessorService xUnitReportService = getXUnitReportProcessorServiceObject(listener);
boolean noProcessingErrors = true;
boolean continueTestProcessing = true;
for (TestType tool : types) {
xUnitLog.infoConsoleLogger("Processing " + tool.getDescriptor().getDisplayName());
if (!isEmptyGivenPattern(xUnitReportService, tool)) {
String expandedPattern = getExpandedResolvedPattern(tool, build, listener);
XUnitToolInfo xUnitToolInfo = getXUnitToolInfoObject(tool, expandedPattern, build, listener);
XUnitTransformer xUnitTransformer = getXUnitTransformerObject(xUnitToolInfo, listener);
boolean resultTransformation = getWorkspace(build).act(xUnitTransformer);
if (!resultTransformation) {
noProcessingErrors = true;
boolean result = getWorkspace(build).act(xUnitTransformer);
if (!result) {
if (xUnitToolInfo.isStopProcessingIfError()) {
xUnitLog.infoConsoleLogger("Fail BUILD because 'set build failed if errors' option is activated.");
throw new StopTestProcessingException();
}
continueTestProcessing = false;
}
}
}
return noProcessingErrors;
return continueTestProcessing;
}

private class StopTestProcessingException extends Exception {
}

private boolean isEmptyGivenPattern(XUnitReportProcessorService xUnitReportService, TestType tool) {
@@ -187,7 +207,7 @@ private String getExpandedResolvedPattern(TestType tool, AbstractBuild build, Bu
return Util.replaceMacro(newExpandedPattern, build.getEnvironment(listener));
}

private XUnitToolInfo getXUnitToolInfoObject(TestType tool, String expandedPattern, AbstractBuild build, BuildListener listener) throws IOException, InterruptedException {
private XUnitToolInfo getXUnitToolInfoObject(TestType tool, String expandedPattern, AbstractBuild build, BuildListener listener) throws IOException, InterruptedException {
return new XUnitToolInfo(
new FilePath(new File(Hudson.getInstance().getRootDir(), "userContent")),
tool.getInputMetric(),
@@ -196,7 +216,7 @@ private XUnitToolInfo getXUnitToolInfoObject(TestType tool, String expandedPatte
tool.isFailIfNotNew(),
tool.isDeleteOutputFiles(), tool.isStopProcessingIfError(),
build.getTimeInMillis(),
(tool instanceof CustomType) ? getWorkspace(build).child( Util.replaceMacro( ((CustomType) tool).getCustomXSL() , build.getEnvironment(listener)) ) : null);
(tool instanceof CustomType) ? getWorkspace(build).child(Util.replaceMacro(((CustomType) tool).getCustomXSL(), build.getEnvironment(listener))) : null);
}

private FilePath getWorkspace(AbstractBuild build) {
@@ -441,10 +461,9 @@ public Publisher newInstance(StaplerRequest req, JSONObject formData) throws For
List<XUnitThreshold> thresholds = Descriptor.newInstancesFromHeteroList(
req, formData, "thresholds", getListXUnitThresholdDescriptors());
int thresholdMode = 0;
try{
try {
thresholdMode = formData.getInt("thresholdMode");
}
catch (JSONException e){
} catch (JSONException e) {
//ignore
}
return new XUnitPublisher(types.toArray(new TestType[types.size()]), thresholds.toArray(new XUnitThreshold[thresholds.size()]), thresholdMode);

0 comments on commit 5128b7d

Please sign in to comment.
You can’t perform that action at this time.