Skip to content

Commit

Permalink
Revise repository addition logic for snapshot versions
Browse files Browse the repository at this point in the history
  • Loading branch information
inanemed committed Apr 15, 2024
1 parent 9283dca commit 49f6c77
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ public void customize(Build build) {
build.repositories().add("maven-central");
if (this.springBootVersion.getQualifier() != null) {
String qualifier = this.springBootVersion.getQualifier().getId();
Integer patch = this.springBootVersion.getPatch();
if (!qualifier.equals("RELEASE")) {
if (qualifier.contains("SNAPSHOT")) {
if (patch == 0) {
addMilestoneRepository(build);
}
addSnapshotRepository(build);
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,38 @@ void addMavenCentralAndMilestonesWhenUsingSemVerReleaseCandidate() {
void addMavenCentralAndNonReleaseWhenUsingSnapshot() {
MavenBuild build = new MavenBuild();
new SpringBootVersionRepositoriesBuildCustomizer(Version.parse("2.1.0.BUILD-SNAPSHOT")).customize(build);
assertNonReleaseRepositories(build);
assertNonReleaseRepositoriesWhenPatchIsZero(build);
}

@Test
void addMavenCentralAndNonReleaseWhenUsingSemVerSnapshot() {
MavenBuild build = new MavenBuild();
new SpringBootVersionRepositoriesBuildCustomizer(Version.parse("2.1.0-SNAPSHOT")).customize(build);
assertNonReleaseRepositories(build);
assertNonReleaseRepositoriesWhenPatchIsZero(build);
}

private void assertNonReleaseRepositories(MavenBuild build) {
@Test
void addMavenCentralAndNonReleaseWhenUsingSemVerSnapshotAndPatchDifferentToZero() {
MavenBuild build = new MavenBuild();
new SpringBootVersionRepositoriesBuildCustomizer(Version.parse("2.1.1-SNAPSHOT")).customize(build);
assertNonReleaseRepositoriesWhenPatchIsDifferentToZero(build);
}

private void assertNonReleaseRepositoriesWhenPatchIsZero(MavenBuild build) {
List<MavenRepository> repositories = build.repositories().items().collect(Collectors.toList());
assertThat(repositories).hasSize(3);
assertThat(repositories.get(0)).isEqualTo(MavenRepository.MAVEN_CENTRAL);
assertThat(repositories.get(1)).hasFieldOrPropertyWithValue("id", "spring-milestones")
.hasFieldOrPropertyWithValue("name", "Spring Milestones")
.hasFieldOrPropertyWithValue("url", "https://repo.spring.io/milestone")
.hasFieldOrPropertyWithValue("snapshotsEnabled", false);
assertThat(repositories.get(2)).hasFieldOrPropertyWithValue("id", "spring-snapshots")
.hasFieldOrPropertyWithValue("name", "Spring Snapshots")
.hasFieldOrPropertyWithValue("url", "https://repo.spring.io/snapshot")
.hasFieldOrPropertyWithValue("snapshotsEnabled", true);
}

private void assertNonReleaseRepositoriesWhenPatchIsDifferentToZero(MavenBuild build) {
List<MavenRepository> repositories = build.repositories().items().collect(Collectors.toList());
assertThat(repositories).hasSize(2);
assertThat(repositories.get(0)).isEqualTo(MavenRepository.MAVEN_CENTRAL);
Expand Down

0 comments on commit 49f6c77

Please sign in to comment.