Skip to content

Commit

Permalink
Fix local Maven URL
Browse files Browse the repository at this point in the history
This is provided with 'file:' as prefix but without '//' in MavenRepository
  • Loading branch information
fabapp2 committed Nov 7, 2023
1 parent 8bca7d1 commit e72628a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public class MavenSettingsInitializer {
*/
public void initializeMavenSettings() {
String repo = "file://" + Path.of(System.getProperty("user.home")).resolve(".m2/repository") + "/";
MavenRepository mavenRepository = new MavenRepository("local", new File(System.getProperty("user.home") + "/.m2/repository").toURI().toString(), "true", "true", true, null, null, false);
MavenSettings mavenSettings = new MavenSettings(repo, null, null, null, null, null);
MavenRepository mavenRepository = new MavenRepository("local", repo, "true", "true", true, null, null, false);
MavenSettings mavenSettings = new MavenSettings(repo, mavenRepository, null, null, null, null);
// Read .m2/settings.xml
// TODO: Add support for global Maven settings (${maven.home}/conf/settings.xml).
Path mavenSettingsFile = Path.of(System.getProperty("user.home")).resolve(".m2/settings.xml");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2021 - 2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openrewrite.maven;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.openrewrite.maven.tree.MavenRepository;

import java.io.File;

import static org.assertj.core.api.Assertions.assertThat;

/**
* @author Fabian Krüger
*/
public class MavenRepositoryLocalRepoTest {

@Test
@DisplayName("calculate local Maven repository")
void calculateLocalMavenRepository() {
String repoPath = System.getProperty("user.home") + "/.m2/repository";
MavenRepository MAVEN_LOCAL_DEFAULT = new MavenRepository("local", new File(repoPath).toURI().toString(), "true", "true", true, null, null, false);
assertThat(MAVEN_LOCAL_DEFAULT.getUri()).isEqualTo("file://" + repoPath.toString());
}
}

0 comments on commit e72628a

Please sign in to comment.