Skip to content

Commit

Permalink
Fix JENKINS-17438
Browse files Browse the repository at this point in the history
  • Loading branch information
gboissinot committed Jan 1, 2014
1 parent 7fe9aa7 commit 9f47888
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
34 changes: 24 additions & 10 deletions src/main/java/org/jenkinsci/plugins/xunit/XUnitProcessor.java
Expand Up @@ -107,7 +107,7 @@ private boolean performTests(XUnitLog xUnitLog, AbstractBuild<?, ?> build, Build
String expandedPattern = getExpandedResolvedPattern(tool, build, listener);
XUnitToolInfo xUnitToolInfo = getXUnitToolInfoObject(tool, expandedPattern, build, listener);
XUnitTransformer xUnitTransformer = getXUnitTransformerObject(xUnitToolInfo, listener);
boolean result = false;
boolean result;
try {
result = getWorkspace(build).act(xUnitTransformer);
findTest = true;
Expand Down Expand Up @@ -152,7 +152,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, final BuildListener listener) throws IOException, InterruptedException {
private XUnitToolInfo getXUnitToolInfoObject(final TestType tool, final String expandedPattern, final AbstractBuild build, final BuildListener listener) throws IOException, InterruptedException {

InputMetric inputMetric = tool.getInputMetric();
inputMetric = Guice.createInjector(new AbstractModule() {
Expand All @@ -173,10 +173,29 @@ protected void configure() {
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) ? getCustomStylesheet(tool, build, listener) : null);

}

private FilePath getCustomStylesheet(final TestType tool, final AbstractBuild build, final BuildListener listener) throws IOException, InterruptedException {

final FilePath workspace = getWorkspace(build);
final String customXSLPath = Util.replaceMacro(((CustomType) tool).getCustomXSL(), build.getEnvironment(listener));

//Try full path
FilePath customXSLFilePath = new FilePath(new File(customXSLPath));
if (!customXSLFilePath.exists()) {
//Try from workspace
customXSLFilePath = workspace.child(customXSLPath);
}

if (!customXSLFilePath.exists()) {
throw new XUnitException("The given xsl '" + customXSLPath + "'doesn't exist.");
}

return customXSLFilePath;
}

private FilePath getWorkspace(AbstractBuild build) {
FilePath workspace = build.getWorkspace();
if (workspace == null) {
Expand Down Expand Up @@ -211,9 +230,6 @@ private TestResultAction getPreviousTestResultAction(AbstractBuild<?, ?> build)
return getTestResultAction(previousBuild);
}

/**
* Records the test results into the current build and return the number of tests
*/
private void recordTestResult(AbstractBuild<?, ?> build, BuildListener listener, XUnitLog xUnitLog) throws XUnitException {
TestResultAction existingAction = build.getAction(TestResultAction.class);
final long buildTime = build.getTimestamp().getTimeInMillis();
Expand Down Expand Up @@ -267,10 +283,8 @@ private TestResult getTestResult(final AbstractBuild<?, ?> build,
public TestResult invoke(File ws, VirtualChannel channel) throws IOException {
final long nowSlave = System.currentTimeMillis();
File generatedJunitDir = new File(ws, GENERATED_JUNIT_DIR);
//Try to create the file if it was deleted or something was wrong
if (!generatedJunitDir.mkdirs()) {
throw new XUnitException("Cannot create " + generatedJunitDir.getAbsolutePath());
}
//Ignore return value
generatedJunitDir.mkdirs();
FileSet fs = Util.createFileSet(generatedJunitDir, junitFilePattern);
DirectoryScanner ds = fs.getDirectoryScanner();
String[] files = ds.getIncludedFiles();
Expand Down
Expand Up @@ -72,10 +72,6 @@ public File convert(XUnitToolInfo xUnitToolInfo, File inputFile, File workspace,

private File convertCustomInputMetric(XUnitToolInfo xUnitToolInfo, File inputFile, File workspace, InputMetric inputMetric, File junitTargetFile) throws IOException, InterruptedException, XUnitException {
CustomInputMetric customInputMetric = (CustomInputMetric) inputMetric;
FilePath xslFilePath = xUnitToolInfo.getCusXSLFile();
if (!xslFilePath.exists()) {
throw new XUnitException("The input xsl '" + xslFilePath.getName() + "' relative to the workspace '" + workspace + "'doesn't exist.");
}
customInputMetric.setCustomXSLFile(new File(xUnitToolInfo.getCusXSLFile().getRemote()));
inputMetric.convert(inputFile, junitTargetFile);
return junitTargetFile;
Expand All @@ -86,7 +82,7 @@ private File convertInputMetricXSL(XUnitToolInfo xUnitToolInfo, File inputFile,
FilePath userXSLFilePath = xUnitToolInfo.getUserContentRoot().child(inputMetricXSL.getUserContentXSLDirRelativePath());

if (userXSLFilePath.exists()) {
xUnitLog.infoConsoleLogger("Trying to use the native embedded stylesheet.");
xUnitLog.infoConsoleLogger("Using the native embedded stylesheet in JENKINS_HOME.");
try {
return convertInputMetricXSLWithUserXSL(inputFile, junitTargetFile, inputMetricXSL, userXSLFilePath);
} catch (XUnitException xe) {
Expand Down

0 comments on commit 9f47888

Please sign in to comment.