Skip to content

Commit

Permalink
[FIXED JENKINS-15907] Fixed critical issue with TAP plugin overwritin…
Browse files Browse the repository at this point in the history
…g files when copying from slave to master.
  • Loading branch information
kinow committed Nov 25, 2012
1 parent 25be38e commit 50853ef
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/main/java/org/tap4j/plugin/TapPublisher.java
Expand Up @@ -26,6 +26,7 @@
import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
import hudson.Util;
import hudson.matrix.MatrixAggregatable;
import hudson.matrix.MatrixAggregator;
import hudson.matrix.MatrixBuild;
Expand Down Expand Up @@ -227,7 +228,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
reports = checkReports(build, reports, logger);
}

boolean filesSaved = saveReports(getTapReportDirectory(build), reports,logger);
boolean filesSaved = saveReports(build.getWorkspace(), getTapReportDirectory(build), reports, logger);
if (!filesSaved) {
logger.println("Failed to save TAP reports");
return Boolean.TRUE;
Expand Down Expand Up @@ -299,23 +300,20 @@ private TapResult loadResults(AbstractBuild<?, ?> owner,
}

/**
* @param workspace
* @param tapDir
* @param reports
* @param logger
* @return
*/
private boolean saveReports(FilePath tapDir, FilePath[] reports,
private boolean saveReports(FilePath workspace, FilePath tapDir, FilePath[] reports,
PrintStream logger) {
logger.println("Saving reports...");
try {
tapDir.mkdirs();
// int i = 0;
for (FilePath report : reports) {
// String name = "tap-report" + (i > 0 ? "-" + i : "")
// + ".tap";
// i++;
// TODO: !
FilePath dst = tapDir.child(report.getName());
//FilePath dst = tapDir.child(report.getName());
FilePath dst = getDistDir(workspace, tapDir, report);
report.copyTo(dst);
}
} catch (Exception e) {
Expand All @@ -324,6 +322,20 @@ private boolean saveReports(FilePath tapDir, FilePath[] reports,
}
return true;
}

private FilePath getDistDir(FilePath workspace, FilePath tapDir, FilePath orig) {
if(orig == null)
return null;
StringBuilder difference = new StringBuilder();
FilePath parent = orig.getParent();
do {
if(parent.equals(workspace))
break;
difference.insert(0, parent.getName() + File.separatorChar);
} while((parent = parent.getParent()) !=null);
difference.append(orig.getName());
return tapDir.child(difference.toString());
}

/**
* @param build
Expand Down

0 comments on commit 50853ef

Please sign in to comment.