Skip to content

Commit

Permalink
Fix for [JENKINS-21467]. Tries to revert the file name for the origin…
Browse files Browse the repository at this point in the history
…al file system
  • Loading branch information
mathieu-pousse committed Jan 22, 2014
1 parent e09bf66 commit db4e6b3
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion src/main/java/hudson/plugins/sloccount/SloccountPublisher.java
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit db4e6b3

Please sign in to comment.