Skip to content

Commit 5705364

Browse files
committed
Add test for local maven repo set in settings.xml
1 parent d92c71c commit 5705364

File tree

5 files changed

+19
-9
lines changed

5 files changed

+19
-9
lines changed

components/sbm-core/src/main/java/org/springframework/sbm/build/impl/RewriteMavenParser.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ public List<Xml.Document> parse(String... sources) {
7575
@Override
7676
public List<Xml.Document> parse(ExecutionContext ctx, String... sources) {
7777
mavenSettingsInitializer.initializeMavenSettings(ctx);
78-
parser.parse(ctx, sources);
79-
return Parser.super.parse(ctx, sources);
78+
return parser.parse(ctx, sources);
8079
}
8180

8281
/**

components/sbm-core/src/test/java/org/springframework/sbm/build/impl/MavenSettingsInitializerTest.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.nio.file.Path;
2626

2727
import static org.assertj.core.api.Assertions.assertThat;
28-
import static org.junit.jupiter.api.Assertions.*;
2928

3029
/**
3130
* @author Fabian Krüger
@@ -72,14 +71,22 @@ void mavenParserMustAdhereToSettingsXmlTest() throws URISyntaxException {
7271
MavenRepository localRepository = mavenExecutionContextView.getLocalRepository();
7372
assertThat(localRepository.isSnapshots()).isTrue();
7473

75-
// assertThat(localRepository.getUri()).isEqualTo("file:" + fakedUserHome + "/.m2/repository/");
76-
assertThat(localRepository.getUri()).isEqualTo(MavenRepository.MAVEN_LOCAL_DEFAULT.getUri());
74+
String tmpDir = removeTrailingSlash(System.getProperty("java.io.tmpdir"));
75+
String customLocalRepository = new URI("file://" + tmpDir).toString();
76+
assertThat(removeTrailingSlash(localRepository.getUri())).isEqualTo(customLocalRepository);
7777
assertThat(localRepository.isSnapshots()).isTrue();
7878
assertThat(localRepository.isKnownToExist()).isTrue();
7979
assertThat(localRepository.getUsername()).isNull();
8080
assertThat(localRepository.getPassword()).isNull();
8181
}
8282

83+
String removeTrailingSlash(String string) {
84+
if(string.endsWith("/")){
85+
return string.substring(0, string.length()-1);
86+
}
87+
return string;
88+
}
89+
8390
@AfterEach
8491
public void reset() {
8592
// reset

components/sbm-core/src/test/java/org/springframework/sbm/build/impl/RewriteMavenParserTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ void customExecutionContextGiven() {
4949
String pom = PomBuilder.buildPom("com.example:project:1.0").build();
5050
ExecutionContext ctx = new RewriteExecutionContext();
5151
sut.parse(ctx, pom);
52-
// first time when initializing the parser
53-
// second time in the parse method to guarantee ExecutionContext is enriched with MavenSettings
54-
verify(mavenSettingsInitializer, times(2)).initializeMavenSettings(ctx);
52+
verify(mavenSettingsInitializer).initializeMavenSettings(ctx);
5553
}
5654

5755
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.m2/repository/
2+
.config
3+
.rewrite

components/sbm-core/testcode/project-with-maven-settings/user-home/.m2/settings.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
<settings xsi:schemaLocation='http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd'
33
xmlns='http://maven.apache.org/SETTINGS/1.0.0' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
44

5+
<localRepository>${java.io.tmpdir}</localRepository>
56
<profiles>
67
<profile>
7-
<activeByDefault>true</activeByDefault>
8+
<activation>
9+
<activeByDefault>true</activeByDefault>
10+
</activation>
811
<repositories>
912
<repository>
1013
<snapshots>

0 commit comments

Comments
 (0)