Skip to content

Commit

Permalink
Unify windows path for local M2 repo
Browse files Browse the repository at this point in the history
  • Loading branch information
fabapp2 committed Oct 9, 2023
1 parent 590cc44 commit ffd9bb2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.springframework.sbm.build.impl.RewriteMavenParser;
import org.springframework.sbm.engine.events.*;
import org.springframework.sbm.scopes.ProjectMetadata;
import org.springframework.sbm.utils.LinuxWindowsPathUnifier;
import org.springframework.stereotype.Component;

import java.io.IOException;
Expand Down Expand Up @@ -73,9 +74,10 @@ public List<SourceFile> parse(Path projectDirectory, List<Resource> resources) {
projectMetadata.setMavenSettings(mavenSettings);
MavenExecutionContextView mavenExecutionContext = MavenExecutionContextView.view(executionContext);
mavenExecutionContext.setMavenSettings(mavenSettings);
// if(mavenExecutionContext.getLocalRepository() == null) {
MavenExecutionContextView.view(executionContext).setLocalRepository(new MavenRepository("local", "file://" + Path.of(System.getProperty("user.home")).resolve(".m2/repository"), null, null, false, null, null, null));
// }
Path localRepo = Path.of(System.getProperty("user.home")).resolve(".m2/repository");
String unifiedLocalRepo = LinuxWindowsPathUnifier.unifyPath(localRepo);
String uri = "%s://%s".formatted("file", unifiedLocalRepo);
MavenExecutionContextView.view(executionContext).setLocalRepository(new MavenRepository("local", uri, null, null, false, null, null, null));
// default local repo provided by MavenExecutionContextView misses two '/' in the path
mavenConfigHandler.injectMavenConfigIntoSystemProperties(resources);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@

public class LinuxWindowsPathUnifier {

public String unifyPath(Path path) {
public static String unifyPath(Path path) {
return unifyPath(path.toString());
}

public String unifyPath(String path) {
public static String unifyPath(String path) {
path = StringUtils.cleanPath(path);
if (isWindows()) {
path = transformToLinuxPath(path);
}
return path;
}

boolean isWindows() {
public static boolean isWindows() {
return System.getProperty("os.name").contains("Windows");
}

private String transformToLinuxPath(String path) {
private static String transformToLinuxPath(String path) {
return path.replaceAll("^[\\w]+:\\/?", "/");
}
}

0 comments on commit ffd9bb2

Please sign in to comment.