diff --git a/base/pom.xml b/base/pom.xml index be93feb2..32f2b9a0 100644 --- a/base/pom.xml +++ b/base/pom.xml @@ -72,5 +72,20 @@ com.pivovarit throwing-function + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.assertj + assertj-core + test + \ No newline at end of file diff --git a/base/src/main/java/org/ndx/aadarchi/base/utils/FileResolver.java b/base/src/main/java/org/ndx/aadarchi/base/utils/FileResolver.java index 0e64e56a..418017c0 100644 --- a/base/src/main/java/org/ndx/aadarchi/base/utils/FileResolver.java +++ b/base/src/main/java/org/ndx/aadarchi/base/utils/FileResolver.java @@ -37,7 +37,8 @@ public Path fileAsUrltoPath(String file) { if (file.startsWith("file:")) { return Paths.get(new URL(file).toURI()); } else { - return new File(basedir, file).toPath(); + // Maybe the file should be resolved as a full path file + return basedir.toPath().resolve(file); } } catch (MalformedURLException | URISyntaxException e) { throw new UnableToResolveFileException(String.format("Unable to transform String %s into a file/path object", file), e); diff --git a/base/src/test/java/org/ndx/aadarchi/base/utils/FileResolverTest.java b/base/src/test/java/org/ndx/aadarchi/base/utils/FileResolverTest.java new file mode 100644 index 00000000..dc5172bf --- /dev/null +++ b/base/src/test/java/org/ndx/aadarchi/base/utils/FileResolverTest.java @@ -0,0 +1,38 @@ +package org.ndx.aadarchi.base.utils; + +import java.io.File; +import java.nio.file.Path; + +import org.junit.jupiter.api.Test; +import org.assertj.core.api.Assertions; + +class FileResolverTest { + + @Test + void can_resolve_subfolder() { + FileResolver resolver = new FileResolver(); + // Given + // This file resolves as project base execution dir + String userDir = System.getProperty("user.dir"); + File userFile = new File(userDir); + resolver.basedir = new File(userDir); + // When + Path resolved = resolver.fileAsUrltoPath("src/main/java"); + // Then + Assertions.assertThat(resolved).isEqualTo(new File(userFile, "src/main/java").toPath()); + } + @Test + void bug_291_absolute_path_cant_be_resolved() { + FileResolver resolver = new FileResolver(); + // Given + // This file resolves as project base execution dir + String userDir = System.getProperty("user.dir"); + File userFile = new File(userDir); + resolver.basedir = new File(userDir); + // When + Path resolved = resolver.fileAsUrltoPath(userDir); + // Then + Assertions.assertThat(resolved).isEqualTo(userFile.toPath()); + } + +}