Fix compatiblity with Microsoft Windows

Closes gh-879
This commit is contained in:
Stephane Nicoll
2019-05-28 14:30:51 +02:00
parent 62d0a94364
commit e6f287b298
6 changed files with 29 additions and 12 deletions

View File

@@ -17,6 +17,7 @@
package io.spring.initializr.generator.test.project;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -75,7 +76,8 @@ public class ProjectStructure {
}
/**
* Return the relative paths of all files.
* Return the relative paths of all files. For consistency, always use {@code /} as
* path separator.
* @return the relative path of all files
*/
public List<String> getRelativePathsOfProjectFiles() {
@@ -84,8 +86,7 @@ public class ProjectStructure {
Files.walkFileTree(this.projectDirectory, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
relativePaths.add(ProjectStructure.this.projectDirectory
.relativize(file).toString());
relativePaths.add(createRelativePath(file));
return FileVisitResult.CONTINUE;
}
});
@@ -96,4 +97,12 @@ public class ProjectStructure {
return relativePaths;
}
private String createRelativePath(Path file) {
String relativePath = this.projectDirectory.relativize(file).toString();
if (FileSystems.getDefault().getSeparator().equals("\\")) {
return relativePath.replace('\\', '/');
}
return relativePath;
}
}