Skip to content
Permalink
Browse files

[FIXED JENKINS-15907] Fixed critical issue with TAP plugin overwritin…

…g files when copying from slave to master.
  • Loading branch information...
kinow committed Nov 25, 2012
1 parent 25be38e commit 50853ef30862775cfa3d21ade4154ea924714c15
Showing with 20 additions and 8 deletions.
  1. +20 −8 src/main/java/org/tap4j/plugin/TapPublisher.java
@@ -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;
@@ -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;
@@ -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) {
@@ -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

0 comments on commit 50853ef

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