Skip to content
Permalink
Browse files
Merge pull request #27 from mathieu-pousse/master
[FIXED JENKINS-21467]. Tries to revert the file name for the original ...
  • Loading branch information
mixalturek committed Jan 24, 2014
2 parents e09bf66 + db4e6b3 commit 2e8cb21bcfabbf442a7f5f3ce332ae79c40d3d2f
Showing 1 changed file with 34 additions and 1 deletion.
@@ -102,6 +102,39 @@ public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListene
return true;
}

/**
* Let's try to find out the original file name.
* <p>
* If the OS we are running on the master and the slave are different,
* there are some back slash forward conversion to apply.
*
* @param source the file object representing the source file
* @return see description
*/
private String revertToOriginalFileName(final File source) {

String fileSeparator = System.getProperty("file.separator");
if (source.getPath().startsWith(fileSeparator)) {
// well, for sure the file comes from unix like OS
if (fileSeparator.equals("\\")) {
// but as we are running on windows, we must revert the mapping
return source.getPath().replaceAll("\\\\", "/");
} else {
// unix file but we are running on unix... no problem
return source.getAbsolutePath();
}
} else {
// starts with a drive letter...
if (source.getPath().startsWith(fileSeparator)) {
// and we are running on windows. Too easy !
return source.getAbsolutePath();
} else {
// hum... revert the back slashes
return source.getPath().replaceAll("/", "\\");
}
}
}

/**
* Copy files to a build results directory. The copy of a file will be
* stored in plugin's subdirectory and a hashcode of its absolute path will
@@ -136,7 +169,7 @@ private void copyFilesToBuildDirectory(List<File> sourceFiles,

if(!masterFile.exists()){
FileOutputStream outputStream = new FileOutputStream(masterFile);
new FilePath(channel, sourceFile.getAbsolutePath())
new FilePath(channel, revertToOriginalFileName(sourceFile))
.copyTo(outputStream);
}
}

0 comments on commit 2e8cb21

Please sign in to comment.