Skip to content

Commit

Permalink
Add get..PathString() methods to ProjectResource
Browse files Browse the repository at this point in the history
  • Loading branch information
fabapp2 committed Nov 12, 2023
1 parent be28378 commit ae7a1a5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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{}");
}, "");
}
Expand All @@ -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{}");
}, "");
}
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit ae7a1a5

Please sign in to comment.