From ae7a1a51382106391ca6ef5efef578b2e24324fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Kr=C3=BCger?= <56278322+fabapp2@users.noreply.github.com> Date: Mon, 13 Nov 2023 00:22:56 +0100 Subject: [PATCH] Add get..PathString() methods to ProjectResource --- .../sbm/project/resource/ProjectResource.java | 11 +++++++++++ .../resource/RewriteSourceFileHolder.java | 16 ++++++++++++++++ .../build/api/Module_searchMainJava_Test.java | 9 ++++----- .../build/impl/MavenSettingsInitializerTest.java | 7 ++++--- 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/components/sbm-core/src/main/java/org/springframework/sbm/project/resource/ProjectResource.java b/components/sbm-core/src/main/java/org/springframework/sbm/project/resource/ProjectResource.java index e556f8e30..ff55cdd85 100644 --- a/components/sbm-core/src/main/java/org/springframework/sbm/project/resource/ProjectResource.java +++ b/components/sbm-core/src/main/java/org/springframework/sbm/project/resource/ProjectResource.java @@ -29,11 +29,22 @@ public interface ProjectResource { */ Path getSourcePath(); + /** + * @return the OS agnostic path representation of {@link #getSourcePath()}. + */ + String getSourcePathString(); + Path getAbsolutePath(); + /** + * @return the OS agnostic path representation of {@link #getAbsolutePath()}. + */ + String getAbsolutePathString(); + void delete(); boolean isDeleted(); void moveTo(Path newPath); + } diff --git a/components/sbm-core/src/main/java/org/springframework/sbm/project/resource/RewriteSourceFileHolder.java b/components/sbm-core/src/main/java/org/springframework/sbm/project/resource/RewriteSourceFileHolder.java index 28bc6c8ff..368929cef 100644 --- a/components/sbm-core/src/main/java/org/springframework/sbm/project/resource/RewriteSourceFileHolder.java +++ b/components/sbm-core/src/main/java/org/springframework/sbm/project/resource/RewriteSourceFileHolder.java @@ -53,11 +53,27 @@ public Path getSourcePath() { return LinuxWindowsPathUnifier.unify(sourceFile.getSourcePath()); } + /** + * {@inheritDoc} + */ + @Override + public String getSourcePathString() { + return LinuxWindowsPathUnifier.unifyPath(getSourcePath()); + } + @Override public Path getAbsolutePath() { return LinuxWindowsPathUnifier.unify(absoluteProjectDir.resolve(getSourcePath()).normalize().toAbsolutePath()); } + /** + * {@inheritDoc} + */ + @Override + public String getAbsolutePathString() { + return LinuxWindowsPathUnifier.unifyPath(getAbsolutePath()); + } + /** * Move the represented resource to another location. *

diff --git a/components/sbm-core/src/test/java/org/springframework/sbm/build/api/Module_searchMainJava_Test.java b/components/sbm-core/src/test/java/org/springframework/sbm/build/api/Module_searchMainJava_Test.java index a93a9169b..db4a573db 100644 --- a/components/sbm-core/src/test/java/org/springframework/sbm/build/api/Module_searchMainJava_Test.java +++ b/components/sbm-core/src/test/java/org/springframework/sbm/build/api/Module_searchMainJava_Test.java @@ -26,7 +26,6 @@ import org.springframework.sbm.project.resource.RewriteSourceFileHolder; import org.springframework.sbm.project.resource.TestProjectContext; import org.springframework.sbm.project.resource.filter.ProjectResourceFinder; -import org.springframework.sbm.utils.LinuxWindowsPathUnifier; import java.nio.file.Path; import java.util.List; @@ -84,7 +83,7 @@ void withClassesInSrcMainJavaProvidesProjectResourcesWithMainClasses() { verifySearchMain(context, projectResourceSet -> { assertThat(projectResourceSet.list()).hasSize(1); - assertThat(LinuxWindowsPathUnifier.unifyPath(projectResourceSet.get(0).getSourcePath())).isEqualTo("src/main/java/SomeClass.java"); + assertThat(projectResourceSet.get(0).getSourcePathString()).isEqualTo("src/main/java/SomeClass.java"); assertThat(projectResourceSet.get(0).print()).isEqualTo("public class SomeClass{}"); }, ""); } @@ -99,7 +98,7 @@ void withClassesInTestAndMain_providesClassesFromMain() { verifySearchMain(context, projectResourceSet -> { assertThat(projectResourceSet.list()).hasSize(1); - assertThat(LinuxWindowsPathUnifier.unifyPath(projectResourceSet.get(0).getSourcePath())).isEqualTo("src/main/java/SomeClass.java"); + assertThat(projectResourceSet.get(0).getSourcePathString()).isEqualTo("src/main/java/SomeClass.java"); assertThat(projectResourceSet.get(0).print()).isEqualTo("public class SomeClass{}"); }, ""); } @@ -221,7 +220,7 @@ void withClassesInMainAndTest_providesClassesFromSrcMainJava() { verifySearchMain(context, (projectResourceSet) -> { assertThat(projectResourceSet.list()).hasSize(1); - assertThat(LinuxWindowsPathUnifier.unifyPath(projectResourceSet.list().get(0).getSourcePath())).isEqualTo("application/src/main/java/SomeClass.java"); + assertThat(projectResourceSet.list().get(0).getSourcePathString()).isEqualTo("application/src/main/java/SomeClass.java"); assertThat(projectResourceSet.list().get(0).print()).isEqualTo("public class SomeClass{}"); }, "application"); @@ -238,7 +237,7 @@ void withClassesInMain_providesClassesFromSrcMainJava() { verifySearchMain(context, projectResourceSet -> { assertThat(projectResourceSet.list()).hasSize(1); - assertThat(LinuxWindowsPathUnifier.unifyPath(projectResourceSet.list().get(0).getSourcePath())).isEqualTo("application/src/main/java/SomeClass.java"); + assertThat(projectResourceSet.list().get(0).getSourcePathString()).isEqualTo("application/src/main/java/SomeClass.java"); assertThat(projectResourceSet.list().get(0).print()).isEqualTo("public class SomeClass{}"); }, "application"); diff --git a/components/sbm-core/src/test/java/org/springframework/sbm/build/impl/MavenSettingsInitializerTest.java b/components/sbm-core/src/test/java/org/springframework/sbm/build/impl/MavenSettingsInitializerTest.java index 2c70c9c95..2530e107a 100644 --- a/components/sbm-core/src/test/java/org/springframework/sbm/build/impl/MavenSettingsInitializerTest.java +++ b/components/sbm-core/src/test/java/org/springframework/sbm/build/impl/MavenSettingsInitializerTest.java @@ -15,12 +15,13 @@ */ package org.springframework.sbm.build.impl; -import org.junit.jupiter.api.*; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openrewrite.maven.MavenExecutionContextView; import org.openrewrite.maven.tree.MavenRepository; import org.springframework.sbm.openrewrite.RewriteExecutionContext; -import java.net.URISyntaxException; import java.nio.file.Path; import static org.assertj.core.api.Assertions.assertThat; @@ -63,7 +64,7 @@ void mavenParserMustAdhereToSettingsXmlTest() { assertThat(mavenRepository.getId()).isEqualTo("central"); assertThat(mavenRepository.getUri()).isEqualTo("https://jcenter.bintray.com"); assertThat(mavenRepository.getReleases()).isNull(); - assertThat(mavenRepository.getSnapshots()).isEqualToIgnoringCase("false"); + assertThat(mavenRepository.getSnapshots()).isEqualTo("false"); MavenRepository localRepository = mavenExecutionContextView.getLocalRepository(); assertThat(localRepository.getSnapshots()).isNull();