Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[FIXED JENKINS-21467]. Tries to revert the file name for the original ... #27

Merged
merged 1 commit into from
Jan 24, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion src/main/java/hudson/plugins/sloccount/SloccountPublisher.java
Original file line number Diff line number Diff line change
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