Skip to content

Commit

Permalink
Forward port helidon-io#498
Browse files Browse the repository at this point in the history
Fix MavenProjectSupplier to work properly on windows.
Project config 'project.resourcedirs' is split using ':', however that conflicts with windows drive notation.

Fixes helidon-io#357 helidon-io#483
  • Loading branch information
romain-grecourt committed Dec 24, 2021
1 parent 563b1ad commit 2be4fcb
Showing 1 changed file with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.helidon.build.devloop.maven;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.FileTime;
Expand Down Expand Up @@ -78,6 +79,9 @@ public class MavenProjectSupplier implements ProjectSupplier {
private static final String TARGET_DIR_NAME = "target";
private static final String POM_FILE = "pom.xml";
private static final String DOT = ".";
private static final List<String> FS_ROOTS = Arrays.stream(File.listRoots())
.map(File::getPath)
.collect(Collectors.toList());

private static final Predicate<Path> NOT_HIDDEN = file -> {
final String name = file.getFileName().toString();
Expand Down Expand Up @@ -258,11 +262,25 @@ private Project createProject(Path projectDir, BuildType buildType) {
// Add resource components

for (String resourcesDirEntry : resourcesDirs) {
String[] dir = resourcesDirEntry.split(ProjectConfig.RESOURCE_INCLUDE_EXCLUDE_SEPARATOR);
String resourcesDir = dir[0];

// capture the file system root part of the entry
// on Windows this will be the drive (E.g. C:\), on Unix, just a slash
String prefix = FS_ROOTS.stream()
.filter(resourcesDirEntry::startsWith)
.findFirst()
.orElse("");

// split the non prefix part of the entry
String[] dir = resourcesDirEntry
.substring(prefix.length())
.split(ProjectConfig.RESOURCE_INCLUDE_EXCLUDE_SEPARATOR);

String resourcesDir = prefix + dir[0];
List<String> includes = includeExcludeList(dir, 1);
List<String> excludes = includeExcludeList(dir, 2);
BiPredicate<Path, Path> filter = filter(includes, excludes);

// resourcesDirPath may not be nested inside projectDir if resourcesDir is absolute
Path resourcesDirPath = projectDir.resolve(resourcesDir);
if (Files.isDirectory(resourcesDirPath)) {
BuildRootType buildRootType = BuildRootType.create(DirectoryType.Resources, filter);
Expand Down

0 comments on commit 2be4fcb

Please sign in to comment.