From 2be4fcb8d355a42d4beceb83e17ef1f21774d67c Mon Sep 17 00:00:00 2001 From: Romain Grecourt Date: Thu, 23 Dec 2021 17:15:43 -0800 Subject: [PATCH] Forward port #498 Fix MavenProjectSupplier to work properly on windows. Project config 'project.resourcedirs' is split using ':', however that conflicts with windows drive notation. Fixes #357 #483 --- .../devloop/maven/MavenProjectSupplier.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/dev-loop/dev-loop/src/main/java/io/helidon/build/devloop/maven/MavenProjectSupplier.java b/dev-loop/dev-loop/src/main/java/io/helidon/build/devloop/maven/MavenProjectSupplier.java index ebc780168..b0ce03680 100644 --- a/dev-loop/dev-loop/src/main/java/io/helidon/build/devloop/maven/MavenProjectSupplier.java +++ b/dev-loop/dev-loop/src/main/java/io/helidon/build/devloop/maven/MavenProjectSupplier.java @@ -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; @@ -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 FS_ROOTS = Arrays.stream(File.listRoots()) + .map(File::getPath) + .collect(Collectors.toList()); private static final Predicate NOT_HIDDEN = file -> { final String name = file.getFileName().toString(); @@ -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 includes = includeExcludeList(dir, 1); List excludes = includeExcludeList(dir, 2); BiPredicate 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);