Fix Windows slash issue with ChangedFile

Update ChangedFile to clean paths when returning the relative name.

See gh-3082
This commit is contained in:
Phillip Webb
2015-06-02 09:36:04 -07:00
parent 2af2c4df0e
commit 4313a43cc8

View File

@@ -19,6 +19,7 @@ package org.springframework.boot.developertools.filewatch;
import java.io.File;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* A single file that has changed.
@@ -71,8 +72,10 @@ public final class ChangedFile {
* @return the relative name
*/
public String getRelativeName() {
String folderName = this.sourceFolder.getAbsoluteFile().getPath();
String fileName = this.file.getAbsoluteFile().getPath();
File folder = this.sourceFolder.getAbsoluteFile();
File file = this.file.getAbsoluteFile();
String folderName = StringUtils.cleanPath(folder.getPath());
String fileName = StringUtils.cleanPath(file.getPath());
Assert.state(fileName.startsWith(folderName), "The file " + fileName
+ " is not contained in the source folder " + folderName);
return fileName.substring(folderName.length() + 1);