mirror of
https://gitee.com/dcren/initializr.git
synced 2026-02-25 21:22:58 +08:00
Handle both snapshots and releases enabled flags in Maven Pom
This commit improves the handling of repositories with Maven. Previously, the writer wrongly assumed that the default for releases and snapshots are true and false respectively. However, both defaults are true which means that snapshots repository are considered for releases, and releases repositories are considered for snapshots. MavenRepository has now separate flags for those and the writer makes sure to only update the `enabled` flag if the chosen value is not true. This doesn't increase the content for repository definitions while offering better performance for dependencies resolution. Closes gh-1226
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2020 the original author or authors.
|
* Copyright 2012-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -29,11 +29,12 @@ import io.spring.initializr.generator.version.Version;
|
|||||||
class SpringBootVersionRepositoriesBuildCustomizer implements BuildCustomizer<Build> {
|
class SpringBootVersionRepositoriesBuildCustomizer implements BuildCustomizer<Build> {
|
||||||
|
|
||||||
private static final MavenRepository SPRING_MILESTONES = MavenRepository
|
private static final MavenRepository SPRING_MILESTONES = MavenRepository
|
||||||
.withIdAndUrl("spring-milestones", "https://repo.spring.io/milestone").name("Spring Milestones").build();
|
.withIdAndUrl("spring-milestones", "https://repo.spring.io/milestone").name("Spring Milestones")
|
||||||
|
.onlyReleases().build();
|
||||||
|
|
||||||
private static final MavenRepository SPRING_SNAPSHOTS = MavenRepository
|
private static final MavenRepository SPRING_SNAPSHOTS = MavenRepository
|
||||||
.withIdAndUrl("spring-snapshots", "https://repo.spring.io/snapshot").name("Spring Snapshots")
|
.withIdAndUrl("spring-snapshots", "https://repo.spring.io/snapshot").name("Spring Snapshots")
|
||||||
.snapshotsEnabled(true).build();
|
.onlySnapshots().build();
|
||||||
|
|
||||||
private final Version springBootVersion;
|
private final Version springBootVersion;
|
||||||
|
|
||||||
|
|||||||
@@ -218,8 +218,8 @@ class BuildComplianceTests extends AbstractComplianceTests {
|
|||||||
Dependency bar = Dependency.withId("bar", "org.acme", "bar");
|
Dependency bar = Dependency.withId("bar", "org.acme", "bar");
|
||||||
bar.setRepository("bar-repository");
|
bar.setRepository("bar-repository");
|
||||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addDependencyGroup("test", foo, bar)
|
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addDependencyGroup("test", foo, bar)
|
||||||
.addRepository("foo-repository", "foo-repo", "https://example.com/foo", false)
|
.addReleasesRepository("foo-repository", "foo-repo", "https://example.com/foo")
|
||||||
.addRepository("bar-repository", "bar-repo", "https://example.com/bar", true).build();
|
.addSnapshotsRepository("bar-repository", "bar-repo", "https://example.com/bar").build();
|
||||||
ProjectStructure project = generateProject(java, build, "2.4.1", (description) -> {
|
ProjectStructure project = generateProject(java, build, "2.4.1", (description) -> {
|
||||||
description.addDependency("foo", MetadataBuildItemMapper.toDependency(foo));
|
description.addDependency("foo", MetadataBuildItemMapper.toDependency(foo));
|
||||||
description.addDependency("bar", MetadataBuildItemMapper.toDependency(bar));
|
description.addDependency("bar", MetadataBuildItemMapper.toDependency(bar));
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2020 the original author or authors.
|
* Copyright 2012-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -75,8 +75,8 @@ class DependencyManagementBuildCustomizerTests {
|
|||||||
BillOfMaterials bom = BillOfMaterials.create("com.example", "foo-bom", "1.0.0");
|
BillOfMaterials bom = BillOfMaterials.create("com.example", "foo-bom", "1.0.0");
|
||||||
bom.getRepositories().add("bar-repo");
|
bom.getRepositories().add("bar-repo");
|
||||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addBom("foo-bom", bom)
|
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addBom("foo-bom", bom)
|
||||||
.addRepository("foo-repo", "foo-repo", "https://example.com/foo", false)
|
.addReleasesRepository("foo-repo", "foo-repo", "https://example.com/foo")
|
||||||
.addRepository("bar-repo", "bar-repo", "https://example.com/bar", false)
|
.addReleasesRepository("bar-repo", "bar-repo", "https://example.com/bar")
|
||||||
.addDependencyGroup("test", dependency).build();
|
.addDependencyGroup("test", dependency).build();
|
||||||
Build build = createBuild(metadata);
|
Build build = createBuild(metadata);
|
||||||
build.dependencies().add(dependency.getId());
|
build.dependencies().add(dependency.getId());
|
||||||
|
|||||||
@@ -45,6 +45,9 @@
|
|||||||
<id>spring-milestones</id>
|
<id>spring-milestones</id>
|
||||||
<name>Spring Milestones</name>
|
<name>Spring Milestones</name>
|
||||||
<url>https://repo.spring.io/milestone</url>
|
<url>https://repo.spring.io/milestone</url>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</snapshots>
|
||||||
</repository>
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
<pluginRepositories>
|
<pluginRepositories>
|
||||||
@@ -52,6 +55,9 @@
|
|||||||
<id>spring-milestones</id>
|
<id>spring-milestones</id>
|
||||||
<name>Spring Milestones</name>
|
<name>Spring Milestones</name>
|
||||||
<url>https://repo.spring.io/milestone</url>
|
<url>https://repo.spring.io/milestone</url>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</snapshots>
|
||||||
</pluginRepository>
|
</pluginRepository>
|
||||||
</pluginRepositories>
|
</pluginRepositories>
|
||||||
|
|
||||||
|
|||||||
@@ -49,14 +49,17 @@
|
|||||||
<id>foo-repository</id>
|
<id>foo-repository</id>
|
||||||
<name>foo-repo</name>
|
<name>foo-repo</name>
|
||||||
<url>https://example.com/foo</url>
|
<url>https://example.com/foo</url>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</snapshots>
|
||||||
</repository>
|
</repository>
|
||||||
<repository>
|
<repository>
|
||||||
<id>bar-repository</id>
|
<id>bar-repository</id>
|
||||||
<name>bar-repo</name>
|
<name>bar-repo</name>
|
||||||
<url>https://example.com/bar</url>
|
<url>https://example.com/bar</url>
|
||||||
<snapshots>
|
<releases>
|
||||||
<enabled>true</enabled>
|
<enabled>false</enabled>
|
||||||
</snapshots>
|
</releases>
|
||||||
</repository>
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2020 the original author or authors.
|
* Copyright 2012-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -230,7 +230,16 @@ public class InitializrMetadataTestBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public InitializrMetadataTestBuilder addRepository(String id, String name, String url, boolean snapshotsEnabled) {
|
public InitializrMetadataTestBuilder addReleasesRepository(String id, String name, String url) {
|
||||||
|
return addRepository(id, name, url, true, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public InitializrMetadataTestBuilder addSnapshotsRepository(String id, String name, String url) {
|
||||||
|
return addRepository(id, name, url, false, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public InitializrMetadataTestBuilder addRepository(String id, String name, String url, boolean releasesEnabled,
|
||||||
|
boolean snapshotsEnabled) {
|
||||||
this.builder.withCustomizer((it) -> {
|
this.builder.withCustomizer((it) -> {
|
||||||
Repository repo = new Repository();
|
Repository repo = new Repository();
|
||||||
repo.setName(name);
|
repo.setName(name);
|
||||||
@@ -240,6 +249,7 @@ public class InitializrMetadataTestBuilder {
|
|||||||
catch (MalformedURLException ex) {
|
catch (MalformedURLException ex) {
|
||||||
throw new IllegalArgumentException("Cannot create URL", ex);
|
throw new IllegalArgumentException("Cannot create URL", ex);
|
||||||
}
|
}
|
||||||
|
repo.setReleasesEnabled(releasesEnabled);
|
||||||
repo.setSnapshotsEnabled(snapshotsEnabled);
|
repo.setSnapshotsEnabled(snapshotsEnabled);
|
||||||
it.getConfiguration().getEnv().getRepositories().put(id, repo);
|
it.getConfiguration().getEnv().getRepositories().put(id, repo);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -432,6 +432,14 @@ public class MavenBuildAssert extends AbstractTextAssert<MavenBuildAssert> {
|
|||||||
throw new IllegalStateException("Cannot parse URL", ex);
|
throw new IllegalStateException("Cannot parse URL", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
NodeList releases = element.getElementsByTagName("releases");
|
||||||
|
if (releases.getLength() > 0) {
|
||||||
|
Element releasesElement = (Element) releases.item(0);
|
||||||
|
NodeList releasesEnabled = releasesElement.getElementsByTagName("enabled");
|
||||||
|
if (releasesEnabled.getLength() > 0) {
|
||||||
|
repository.setReleasesEnabled("true".equals(releasesEnabled.item(0).getTextContent()));
|
||||||
|
}
|
||||||
|
}
|
||||||
NodeList snapshots = element.getElementsByTagName("snapshots");
|
NodeList snapshots = element.getElementsByTagName("snapshots");
|
||||||
if (snapshots.getLength() > 0) {
|
if (snapshots.getLength() > 0) {
|
||||||
Element snapshotsElement = (Element) snapshots.item(0);
|
Element snapshotsElement = (Element) snapshots.item(0);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2019 the original author or authors.
|
* Copyright 2012-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -20,6 +20,7 @@ package io.spring.initializr.generator.buildsystem;
|
|||||||
* A Maven repository.
|
* A Maven repository.
|
||||||
*
|
*
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
|
* @author Stephane Nicoll
|
||||||
*/
|
*/
|
||||||
public class MavenRepository {
|
public class MavenRepository {
|
||||||
|
|
||||||
@@ -27,7 +28,8 @@ public class MavenRepository {
|
|||||||
* Maven Central.
|
* Maven Central.
|
||||||
*/
|
*/
|
||||||
public static final MavenRepository MAVEN_CENTRAL = MavenRepository
|
public static final MavenRepository MAVEN_CENTRAL = MavenRepository
|
||||||
.withIdAndUrl("maven-central", "https://repo.maven.apache.org/maven2").name("Maven Central").build();
|
.withIdAndUrl("maven-central", "https://repo.maven.apache.org/maven2").name("Maven Central").onlyReleases()
|
||||||
|
.build();
|
||||||
|
|
||||||
private final String id;
|
private final String id;
|
||||||
|
|
||||||
@@ -35,12 +37,15 @@ public class MavenRepository {
|
|||||||
|
|
||||||
private final String url;
|
private final String url;
|
||||||
|
|
||||||
|
private final boolean releasesEnabled;
|
||||||
|
|
||||||
private final boolean snapshotsEnabled;
|
private final boolean snapshotsEnabled;
|
||||||
|
|
||||||
protected MavenRepository(Builder builder) {
|
protected MavenRepository(Builder builder) {
|
||||||
this.id = builder.id;
|
this.id = builder.id;
|
||||||
this.name = builder.name;
|
this.name = builder.name;
|
||||||
this.url = builder.url;
|
this.url = builder.url;
|
||||||
|
this.releasesEnabled = builder.releasesEnabled;
|
||||||
this.snapshotsEnabled = builder.snapshotsEnabled;
|
this.snapshotsEnabled = builder.snapshotsEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,6 +84,14 @@ public class MavenRepository {
|
|||||||
return this.url;
|
return this.url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return whether releases are enabled on the repository.
|
||||||
|
* @return {@code true} to enable releases, {@code false} otherwise
|
||||||
|
*/
|
||||||
|
public boolean isReleasesEnabled() {
|
||||||
|
return this.releasesEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return whether snapshots are enabled on the repository.
|
* Return whether snapshots are enabled on the repository.
|
||||||
* @return {@code true} to enable snapshots, {@code false} otherwise
|
* @return {@code true} to enable snapshots, {@code false} otherwise
|
||||||
@@ -95,6 +108,8 @@ public class MavenRepository {
|
|||||||
|
|
||||||
private String url;
|
private String url;
|
||||||
|
|
||||||
|
private boolean releasesEnabled = true;
|
||||||
|
|
||||||
private boolean snapshotsEnabled;
|
private boolean snapshotsEnabled;
|
||||||
|
|
||||||
public Builder(String id, String url) {
|
public Builder(String id, String url) {
|
||||||
@@ -133,6 +148,16 @@ public class MavenRepository {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify whether releases are enabled.
|
||||||
|
* @param releasesEnabled whether releases are served by the repository
|
||||||
|
* @return this for method chaining
|
||||||
|
*/
|
||||||
|
public Builder releasesEnabled(boolean releasesEnabled) {
|
||||||
|
this.releasesEnabled = releasesEnabled;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specify whether snapshots are enabled.
|
* Specify whether snapshots are enabled.
|
||||||
* @param snapshotsEnabled whether snapshots are served by the repository
|
* @param snapshotsEnabled whether snapshots are served by the repository
|
||||||
@@ -143,6 +168,22 @@ public class MavenRepository {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify that the repository should only be used for releases.
|
||||||
|
* @return this for method chaining
|
||||||
|
*/
|
||||||
|
public Builder onlyReleases() {
|
||||||
|
return releasesEnabled(true).snapshotsEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify that the repository should only be used for snapshots.
|
||||||
|
* @return this for method chaining
|
||||||
|
*/
|
||||||
|
public Builder onlySnapshots() {
|
||||||
|
return snapshotsEnabled(true).releasesEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build a {@link MavenRepository} with the current state of this builder.
|
* Build a {@link MavenRepository} with the current state of this builder.
|
||||||
* @return a {@link MavenRepository}
|
* @return a {@link MavenRepository}
|
||||||
|
|||||||
@@ -442,8 +442,11 @@ public class MavenBuildWriter {
|
|||||||
writeSingleElement(writer, "id", repository.getId());
|
writeSingleElement(writer, "id", repository.getId());
|
||||||
writeSingleElement(writer, "name", repository.getName());
|
writeSingleElement(writer, "name", repository.getName());
|
||||||
writeSingleElement(writer, "url", repository.getUrl());
|
writeSingleElement(writer, "url", repository.getUrl());
|
||||||
if (repository.isSnapshotsEnabled()) {
|
if (!repository.isReleasesEnabled()) {
|
||||||
writeElement(writer, "snapshots", () -> writeSingleElement(writer, "enabled", Boolean.toString(true)));
|
writeElement(writer, "releases", () -> writeSingleElement(writer, "enabled", Boolean.toString(false)));
|
||||||
|
}
|
||||||
|
if (!repository.isSnapshotsEnabled()) {
|
||||||
|
writeElement(writer, "snapshots", () -> writeSingleElement(writer, "enabled", Boolean.toString(false)));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2019 the original author or authors.
|
* Copyright 2012-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -39,6 +39,7 @@ class MavenRepositoryContainerTests {
|
|||||||
assertThat(repository).isNotNull();
|
assertThat(repository).isNotNull();
|
||||||
assertThat(repository.getName()).isEqualTo("my repo");
|
assertThat(repository.getName()).isEqualTo("my repo");
|
||||||
assertThat(repository.getUrl()).isEqualTo("https://example.com/releases");
|
assertThat(repository.getUrl()).isEqualTo("https://example.com/releases");
|
||||||
|
assertThat(repository.isReleasesEnabled()).isTrue();
|
||||||
assertThat(repository.isSnapshotsEnabled()).isFalse();
|
assertThat(repository.isSnapshotsEnabled()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,6 +57,7 @@ class MavenRepositoryContainerTests {
|
|||||||
assertThat(repository).isNotNull();
|
assertThat(repository).isNotNull();
|
||||||
assertThat(repository.getName()).isEqualTo("my repo");
|
assertThat(repository.getName()).isEqualTo("my repo");
|
||||||
assertThat(repository.getUrl()).isEqualTo("https://example.com/releases");
|
assertThat(repository.getUrl()).isEqualTo("https://example.com/releases");
|
||||||
|
assertThat(repository.isReleasesEnabled()).isTrue();
|
||||||
assertThat(repository.isSnapshotsEnabled()).isFalse();
|
assertThat(repository.isSnapshotsEnabled()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +65,7 @@ class MavenRepositoryContainerTests {
|
|||||||
void addMavenRepositoryWithSnapshotsEnabled() {
|
void addMavenRepositoryWithSnapshotsEnabled() {
|
||||||
MavenRepositoryContainer container = createTestContainer();
|
MavenRepositoryContainer container = createTestContainer();
|
||||||
container.add(MavenRepository.withIdAndUrl("custom", "https://example.com/snapshots").name("custom-snapshots")
|
container.add(MavenRepository.withIdAndUrl("custom", "https://example.com/snapshots").name("custom-snapshots")
|
||||||
.snapshotsEnabled(true));
|
.onlySnapshots());
|
||||||
assertThat(container.ids()).containsOnly("custom");
|
assertThat(container.ids()).containsOnly("custom");
|
||||||
assertThat(container.items()).hasSize(1);
|
assertThat(container.items()).hasSize(1);
|
||||||
assertThat(container.isEmpty()).isFalse();
|
assertThat(container.isEmpty()).isFalse();
|
||||||
@@ -72,6 +74,7 @@ class MavenRepositoryContainerTests {
|
|||||||
assertThat(repository).isNotNull();
|
assertThat(repository).isNotNull();
|
||||||
assertThat(repository.getName()).isEqualTo("custom-snapshots");
|
assertThat(repository.getName()).isEqualTo("custom-snapshots");
|
||||||
assertThat(repository.getUrl()).isEqualTo("https://example.com/snapshots");
|
assertThat(repository.getUrl()).isEqualTo("https://example.com/snapshots");
|
||||||
|
assertThat(repository.isReleasesEnabled()).isFalse();
|
||||||
assertThat(repository.isSnapshotsEnabled()).isTrue();
|
assertThat(repository.isSnapshotsEnabled()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2021 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 io.spring.initializr.generator.buildsystem;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for {@link MavenRepository}.
|
||||||
|
*
|
||||||
|
* @author Stephane Nicoll
|
||||||
|
*/
|
||||||
|
class MavenRepositoryTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void repositoryWithDetails() {
|
||||||
|
MavenRepository repo = MavenRepository.withIdAndUrl("test", "https://repo.example.com").name("Test repository")
|
||||||
|
.build();
|
||||||
|
assertThat(repo.getId()).isEqualTo("test");
|
||||||
|
assertThat(repo.getUrl()).isEqualTo("https://repo.example.com");
|
||||||
|
assertThat(repo.getName()).isEqualTo("Test repository");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void repositoryByDefaultOnlyUseReleases() {
|
||||||
|
MavenRepository repo = MavenRepository.withIdAndUrl("test", "https://repo.example.com").build();
|
||||||
|
assertThat(repo.isReleasesEnabled()).isTrue();
|
||||||
|
assertThat(repo.isSnapshotsEnabled()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void repositoryWithOnlyReleases() {
|
||||||
|
MavenRepository repo = MavenRepository.withIdAndUrl("test", "https://repo.example.com").onlyReleases().build();
|
||||||
|
assertThat(repo.isReleasesEnabled()).isTrue();
|
||||||
|
assertThat(repo.isSnapshotsEnabled()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void repositoryWithOnlySnapshots() {
|
||||||
|
MavenRepository repo = MavenRepository.withIdAndUrl("test", "https://repo.example.com").onlySnapshots().build();
|
||||||
|
assertThat(repo.isReleasesEnabled()).isFalse();
|
||||||
|
assertThat(repo.isSnapshotsEnabled()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void repositoryWithReleasesAndSnapshots() {
|
||||||
|
MavenRepository repo = MavenRepository.withIdAndUrl("test", "https://repo.example.com").releasesEnabled(true)
|
||||||
|
.snapshotsEnabled(true).build();
|
||||||
|
assertThat(repo.isReleasesEnabled()).isTrue();
|
||||||
|
assertThat(repo.isSnapshotsEnabled()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2020 the original author or authors.
|
* Copyright 2012-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -124,8 +124,8 @@ class GroovyDslGradleBuildWriterTests {
|
|||||||
@Test
|
@Test
|
||||||
void gradleBuildWithSnapshotRepository() {
|
void gradleBuildWithSnapshotRepository() {
|
||||||
GradleBuild build = new GradleBuild();
|
GradleBuild build = new GradleBuild();
|
||||||
build.repositories().add(MavenRepository.withIdAndUrl("spring-snapshots", "https://repo.spring.io/snapshot")
|
build.repositories().add(
|
||||||
.snapshotsEnabled(true));
|
MavenRepository.withIdAndUrl("spring-snapshots", "https://repo.spring.io/snapshot").onlySnapshots());
|
||||||
List<String> lines = generateBuild(build);
|
List<String> lines = generateBuild(build);
|
||||||
assertThat(lines).containsSequence("repositories {", " maven { url 'https://repo.spring.io/snapshot' }",
|
assertThat(lines).containsSequence("repositories {", " maven { url 'https://repo.spring.io/snapshot' }",
|
||||||
"}");
|
"}");
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ class GroovyDslGradleSettingsWriterTests {
|
|||||||
GradleBuild build = new GradleBuild();
|
GradleBuild build = new GradleBuild();
|
||||||
build.pluginRepositories()
|
build.pluginRepositories()
|
||||||
.add(MavenRepository.withIdAndUrl("spring-snapshots", "https://repo.spring.io/snapshot")
|
.add(MavenRepository.withIdAndUrl("spring-snapshots", "https://repo.spring.io/snapshot")
|
||||||
.name("Spring Snapshots").snapshotsEnabled(true));
|
.name("Spring Snapshots").onlySnapshots());
|
||||||
List<String> lines = generateSettings(build);
|
List<String> lines = generateSettings(build);
|
||||||
assertThat(lines).containsSequence("pluginManagement {", " repositories {",
|
assertThat(lines).containsSequence("pluginManagement {", " repositories {",
|
||||||
" maven { url 'https://repo.spring.io/snapshot' }", " gradlePluginPortal()", " }",
|
" maven { url 'https://repo.spring.io/snapshot' }", " gradlePluginPortal()", " }",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2020 the original author or authors.
|
* Copyright 2012-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -150,8 +150,8 @@ class KotlinDslGradleBuildWriterTests {
|
|||||||
@Test
|
@Test
|
||||||
void gradleBuildWithSnapshotRepository() {
|
void gradleBuildWithSnapshotRepository() {
|
||||||
GradleBuild build = new GradleBuild();
|
GradleBuild build = new GradleBuild();
|
||||||
build.repositories().add(MavenRepository.withIdAndUrl("spring-snapshots", "https://repo.spring.io/snapshot")
|
build.repositories().add(
|
||||||
.snapshotsEnabled(true));
|
MavenRepository.withIdAndUrl("spring-snapshots", "https://repo.spring.io/snapshot").onlySnapshots());
|
||||||
List<String> lines = generateBuild(build);
|
List<String> lines = generateBuild(build);
|
||||||
assertThat(lines).containsSequence("repositories {",
|
assertThat(lines).containsSequence("repositories {",
|
||||||
" maven { url = uri(\"https://repo.spring.io/snapshot\") }", "}");
|
" maven { url = uri(\"https://repo.spring.io/snapshot\") }", "}");
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ class KotlinDslGradleSettingsWriterTests {
|
|||||||
GradleBuild build = new GradleBuild();
|
GradleBuild build = new GradleBuild();
|
||||||
build.pluginRepositories()
|
build.pluginRepositories()
|
||||||
.add(MavenRepository.withIdAndUrl("spring-snapshots", "https://repo.spring.io/snapshot")
|
.add(MavenRepository.withIdAndUrl("spring-snapshots", "https://repo.spring.io/snapshot")
|
||||||
.name("Spring Snapshots").snapshotsEnabled(true));
|
.name("Spring Snapshots").onlySnapshots());
|
||||||
List<String> lines = generateSettings(build);
|
List<String> lines = generateSettings(build);
|
||||||
assertThat(lines).containsSequence("pluginManagement {", " repositories {",
|
assertThat(lines).containsSequence("pluginManagement {", " repositories {",
|
||||||
" maven { url = uri(\"https://repo.spring.io/snapshot\") }", " gradlePluginPortal()",
|
" maven { url = uri(\"https://repo.spring.io/snapshot\") }", " gradlePluginPortal()",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2020 the original author or authors.
|
* Copyright 2012-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -638,70 +638,104 @@ class MavenBuildWriterTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void pomWithRepository() {
|
void pomWithReleasesOnlyRepository() {
|
||||||
MavenBuild build = new MavenBuild();
|
MavenBuild build = new MavenBuild();
|
||||||
build.settings().coordinates("com.example.demo", "demo");
|
build.settings().coordinates("com.example.demo", "demo");
|
||||||
build.repositories().add(MavenRepository.withIdAndUrl("spring-milestones", "https://repo.spring.io/milestone")
|
build.repositories().add(MavenRepository.withIdAndUrl("spring-milestones", "https://repo.spring.io/milestone")
|
||||||
.name("Spring Milestones"));
|
.name("Spring Milestones"));
|
||||||
generatePom(build, (pom) -> {
|
generatePom(build, (pom) -> {
|
||||||
assertThat(pom).textAtPath("/project/repositories/repository/id").isEqualTo("spring-milestones");
|
NodeAssert repository = pom.nodeAtPath("/project/repositories/repository");
|
||||||
assertThat(pom).textAtPath("/project/repositories/repository/name").isEqualTo("Spring Milestones");
|
assertThat(repository).textAtPath("id").isEqualTo("spring-milestones");
|
||||||
assertThat(pom).textAtPath("/project/repositories/repository/url")
|
assertThat(repository).textAtPath("name").isEqualTo("Spring Milestones");
|
||||||
.isEqualTo("https://repo.spring.io/milestone");
|
assertThat(repository).textAtPath("url").isEqualTo("https://repo.spring.io/milestone");
|
||||||
assertThat(pom).nodeAtPath("/project/repositories/repository/snapshots").isNull();
|
assertThat(repository).nodeAtPath("releases").isNull();
|
||||||
|
assertThat(repository).textAtPath("snapshots/enabled").isEqualTo("false");
|
||||||
assertThat(pom).nodeAtPath("/project/pluginRepositories").isNull();
|
assertThat(pom).nodeAtPath("/project/pluginRepositories").isNull();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void pomWithPluginRepository() {
|
void pomWithReleasesOnlyPluginRepository() {
|
||||||
MavenBuild build = new MavenBuild();
|
MavenBuild build = new MavenBuild();
|
||||||
build.settings().coordinates("com.example.demo", "demo");
|
build.settings().coordinates("com.example.demo", "demo");
|
||||||
build.pluginRepositories().add(MavenRepository
|
build.pluginRepositories().add(MavenRepository
|
||||||
.withIdAndUrl("spring-milestones", "https://repo.spring.io/milestone").name("Spring Milestones"));
|
.withIdAndUrl("spring-milestones", "https://repo.spring.io/milestone").name("Spring Milestones"));
|
||||||
generatePom(build, (pom) -> {
|
generatePom(build, (pom) -> {
|
||||||
assertThat(pom).textAtPath("/project/pluginRepositories/pluginRepository/id")
|
NodeAssert repository = pom.nodeAtPath("/project/pluginRepositories/pluginRepository");
|
||||||
.isEqualTo("spring-milestones");
|
assertThat(repository).textAtPath("id").isEqualTo("spring-milestones");
|
||||||
assertThat(pom).textAtPath("/project/pluginRepositories/pluginRepository/name")
|
assertThat(repository).textAtPath("name").isEqualTo("Spring Milestones");
|
||||||
.isEqualTo("Spring Milestones");
|
assertThat(repository).textAtPath("url").isEqualTo("https://repo.spring.io/milestone");
|
||||||
assertThat(pom).textAtPath("/project/pluginRepositories/pluginRepository/url")
|
assertThat(repository).nodeAtPath("releases").isNull();
|
||||||
.isEqualTo("https://repo.spring.io/milestone");
|
assertThat(repository).textAtPath("snapshots/enabled").isEqualTo("false");
|
||||||
assertThat(pom).nodeAtPath("/project/repositories/repository/snapshots").isNull();
|
|
||||||
assertThat(pom).nodeAtPath("/project/repositories").isNull();
|
assertThat(pom).nodeAtPath("/project/repositories").isNull();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void pomWithSnapshotRepository() {
|
void pomWithSnapshotsOnlyRepository() {
|
||||||
MavenBuild build = new MavenBuild();
|
MavenBuild build = new MavenBuild();
|
||||||
build.settings().coordinates("com.example.demo", "demo");
|
build.settings().coordinates("com.example.demo", "demo");
|
||||||
build.repositories().add(MavenRepository.withIdAndUrl("spring-snapshots", "https://repo.spring.io/snapshot")
|
build.repositories().add(MavenRepository.withIdAndUrl("spring-snapshots", "https://repo.spring.io/snapshot")
|
||||||
.name("Spring Snapshots").snapshotsEnabled(true));
|
.name("Spring Snapshots").onlySnapshots());
|
||||||
generatePom(build, (pom) -> {
|
generatePom(build, (pom) -> {
|
||||||
assertThat(pom).textAtPath("/project/repositories/repository/id").isEqualTo("spring-snapshots");
|
NodeAssert repository = pom.nodeAtPath("/project/repositories/repository");
|
||||||
assertThat(pom).textAtPath("/project/repositories/repository/name").isEqualTo("Spring Snapshots");
|
assertThat(repository).textAtPath("id").isEqualTo("spring-snapshots");
|
||||||
assertThat(pom).textAtPath("/project/repositories/repository/url")
|
assertThat(repository).textAtPath("name").isEqualTo("Spring Snapshots");
|
||||||
.isEqualTo("https://repo.spring.io/snapshot");
|
assertThat(repository).textAtPath("url").isEqualTo("https://repo.spring.io/snapshot");
|
||||||
assertThat(pom).textAtPath("/project/repositories/repository/snapshots/enabled").isEqualTo("true");
|
assertThat(repository).textAtPath("releases/enabled").isEqualTo("false");
|
||||||
|
assertThat(repository).nodeAtPath("snapshots").isNull();
|
||||||
assertThat(pom).nodeAtPath("/project/pluginRepositories").isNull();
|
assertThat(pom).nodeAtPath("/project/pluginRepositories").isNull();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void pomWithSnapshotPluginRepository() {
|
void pomWithSnapshotsOnlyPluginRepository() {
|
||||||
MavenBuild build = new MavenBuild();
|
MavenBuild build = new MavenBuild();
|
||||||
build.settings().coordinates("com.example.demo", "demo");
|
build.settings().coordinates("com.example.demo", "demo");
|
||||||
build.pluginRepositories()
|
build.pluginRepositories()
|
||||||
.add(MavenRepository.withIdAndUrl("spring-snapshots", "https://repo.spring.io/snapshot")
|
.add(MavenRepository.withIdAndUrl("spring-snapshots", "https://repo.spring.io/snapshot")
|
||||||
.name("Spring Snapshots").snapshotsEnabled(true));
|
.name("Spring Snapshots").onlySnapshots());
|
||||||
generatePom(build, (pom) -> {
|
generatePom(build, (pom) -> {
|
||||||
assertThat(pom).textAtPath("/project/pluginRepositories/pluginRepository/id").isEqualTo("spring-snapshots");
|
NodeAssert repository = pom.nodeAtPath("/project/pluginRepositories/pluginRepository");
|
||||||
assertThat(pom).textAtPath("/project/pluginRepositories/pluginRepository/name")
|
assertThat(repository).textAtPath("id").isEqualTo("spring-snapshots");
|
||||||
.isEqualTo("Spring Snapshots");
|
assertThat(repository).textAtPath("name").isEqualTo("Spring Snapshots");
|
||||||
assertThat(pom).textAtPath("/project/pluginRepositories/pluginRepository/url")
|
assertThat(repository).textAtPath("url").isEqualTo("https://repo.spring.io/snapshot");
|
||||||
.isEqualTo("https://repo.spring.io/snapshot");
|
assertThat(repository).textAtPath("releases/enabled").isEqualTo("false");
|
||||||
assertThat(pom).textAtPath("/project/pluginRepositories/pluginRepository/snapshots/enabled")
|
assertThat(repository).nodeAtPath("snapshots").isNull();
|
||||||
.isEqualTo("true");
|
assertThat(pom).nodeAtPath("/project/repositories").isNull();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void pomWithReleasesAndSnapshotsRepository() {
|
||||||
|
MavenBuild build = new MavenBuild();
|
||||||
|
build.settings().coordinates("com.example.demo", "demo");
|
||||||
|
build.repositories().add(MavenRepository.withIdAndUrl("example", "https://repo.example.com/")
|
||||||
|
.name("Example Repo").releasesEnabled(true).snapshotsEnabled(true));
|
||||||
|
generatePom(build, (pom) -> {
|
||||||
|
NodeAssert repository = pom.nodeAtPath("/project/repositories/repository");
|
||||||
|
assertThat(repository).textAtPath("id").isEqualTo("example");
|
||||||
|
assertThat(repository).textAtPath("name").isEqualTo("Example Repo");
|
||||||
|
assertThat(repository).textAtPath("url").isEqualTo("https://repo.example.com/");
|
||||||
|
assertThat(repository).nodeAtPath("releases").isNull();
|
||||||
|
assertThat(repository).nodeAtPath("snapshots").isNull();
|
||||||
|
assertThat(pom).nodeAtPath("/project/pluginRepositories").isNull();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void pomWithReleasesAndSnapshotsPluginRepository() {
|
||||||
|
MavenBuild build = new MavenBuild();
|
||||||
|
build.settings().coordinates("com.example.demo", "demo");
|
||||||
|
build.pluginRepositories().add(MavenRepository.withIdAndUrl("example", "https://repo.example.com/")
|
||||||
|
.name("Example Repo").releasesEnabled(true).snapshotsEnabled(true));
|
||||||
|
generatePom(build, (pom) -> {
|
||||||
|
NodeAssert repository = pom.nodeAtPath("/project/pluginRepositories/pluginRepository");
|
||||||
|
assertThat(repository).textAtPath("id").isEqualTo("example");
|
||||||
|
assertThat(repository).textAtPath("name").isEqualTo("Example Repo");
|
||||||
|
assertThat(repository).textAtPath("url").isEqualTo("https://repo.example.com/");
|
||||||
|
assertThat(repository).nodeAtPath("releases").isNull();
|
||||||
|
assertThat(repository).nodeAtPath("snapshots").isNull();
|
||||||
assertThat(pom).nodeAtPath("/project/repositories").isNull();
|
assertThat(pom).nodeAtPath("/project/repositories").isNull();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2020 the original author or authors.
|
* Copyright 2012-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -250,9 +250,9 @@ public class InitializrConfiguration {
|
|||||||
public Env() {
|
public Env() {
|
||||||
try {
|
try {
|
||||||
this.repositories.put("spring-snapshots",
|
this.repositories.put("spring-snapshots",
|
||||||
new Repository("Spring Snapshots", new URL("https://repo.spring.io/snapshot"), true));
|
new Repository("Spring Snapshots", new URL("https://repo.spring.io/snapshot"), false, true));
|
||||||
this.repositories.put("spring-milestones",
|
this.repositories.put("spring-milestones",
|
||||||
new Repository("Spring Milestones", new URL("https://repo.spring.io/milestone"), false));
|
new Repository("Spring Milestones", new URL("https://repo.spring.io/milestone"), true, false));
|
||||||
}
|
}
|
||||||
catch (MalformedURLException ex) {
|
catch (MalformedURLException ex) {
|
||||||
throw new IllegalStateException("Cannot parse URL", ex);
|
throw new IllegalStateException("Cannot parse URL", ex);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2019 the original author or authors.
|
* Copyright 2012-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
package io.spring.initializr.metadata;
|
package io.spring.initializr.metadata;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.StringJoiner;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define a repository to be represented in the generated project if a dependency refers
|
* Define a repository to be represented in the generated project if a dependency refers
|
||||||
@@ -30,14 +31,21 @@ public class Repository {
|
|||||||
|
|
||||||
private URL url;
|
private URL url;
|
||||||
|
|
||||||
|
private boolean releasesEnabled = true;
|
||||||
|
|
||||||
private boolean snapshotsEnabled;
|
private boolean snapshotsEnabled;
|
||||||
|
|
||||||
public Repository() {
|
public Repository() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Repository(String name, URL url, boolean snapshotsEnabled) {
|
public Repository(String name, URL url) {
|
||||||
|
this(name, url, true, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Repository(String name, URL url, boolean releasesEnabled, boolean snapshotsEnabled) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
|
this.releasesEnabled = releasesEnabled;
|
||||||
this.snapshotsEnabled = snapshotsEnabled;
|
this.snapshotsEnabled = snapshotsEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,6 +65,14 @@ public class Repository {
|
|||||||
this.url = url;
|
this.url = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isReleasesEnabled() {
|
||||||
|
return this.releasesEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReleasesEnabled(boolean releasesEnabled) {
|
||||||
|
this.releasesEnabled = releasesEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isSnapshotsEnabled() {
|
public boolean isSnapshotsEnabled() {
|
||||||
return this.snapshotsEnabled;
|
return this.snapshotsEnabled;
|
||||||
}
|
}
|
||||||
@@ -85,6 +101,9 @@ public class Repository {
|
|||||||
else if (!this.name.equals(other.name)) {
|
else if (!this.name.equals(other.name)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (this.releasesEnabled != other.releasesEnabled) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (this.snapshotsEnabled != other.snapshotsEnabled) {
|
if (this.snapshotsEnabled != other.snapshotsEnabled) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -104,6 +123,7 @@ public class Repository {
|
|||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
int result = 1;
|
int result = 1;
|
||||||
result = prime * result + ((this.name == null) ? 0 : this.name.hashCode());
|
result = prime * result + ((this.name == null) ? 0 : this.name.hashCode());
|
||||||
|
result = prime * result + (this.releasesEnabled ? 1231 : 1237);
|
||||||
result = prime * result + (this.snapshotsEnabled ? 1231 : 1237);
|
result = prime * result + (this.snapshotsEnabled ? 1231 : 1237);
|
||||||
result = prime * result + ((this.url == null) ? 0 : this.url.hashCode());
|
result = prime * result + ((this.url == null) ? 0 : this.url.hashCode());
|
||||||
return result;
|
return result;
|
||||||
@@ -111,9 +131,9 @@ public class Repository {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Repository [" + ((this.name != null) ? "name=" + this.name + ", " : "")
|
return new StringJoiner(", ", Repository.class.getSimpleName() + "[", "]").add("name='" + this.name + "'")
|
||||||
+ ((this.url != null) ? "url=" + this.url + ", " : "") + "snapshotsEnabled=" + this.snapshotsEnabled
|
.add("url=" + this.url).add("releasesEnabled=" + this.releasesEnabled)
|
||||||
+ "]";
|
.add("snapshotsEnabled=" + this.snapshotsEnabled).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2020 the original author or authors.
|
* Copyright 2012-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -96,7 +96,8 @@ public final class MetadataBuildItemMapper {
|
|||||||
}
|
}
|
||||||
return io.spring.initializr.generator.buildsystem.MavenRepository
|
return io.spring.initializr.generator.buildsystem.MavenRepository
|
||||||
.withIdAndUrl(id, repository.getUrl().toExternalForm()).name(repository.getName())
|
.withIdAndUrl(id, repository.getUrl().toExternalForm()).name(repository.getName())
|
||||||
.snapshotsEnabled(repository.isSnapshotsEnabled()).build();
|
.releasesEnabled(repository.isReleasesEnabled()).snapshotsEnabled(repository.isSnapshotsEnabled())
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2020 the original author or authors.
|
* Copyright 2012-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -56,7 +56,7 @@ class InitializrMetadataTests {
|
|||||||
foo.setRepository("foo-repo");
|
foo.setRepository("foo-repo");
|
||||||
addTestDependencyGroup(metadata, foo);
|
addTestDependencyGroup(metadata, foo);
|
||||||
metadata.getConfiguration().getEnv().getRepositories().put("my-repo",
|
metadata.getConfiguration().getEnv().getRepositories().put("my-repo",
|
||||||
new Repository("repo", new URL("https://example.com/repo"), true));
|
new Repository("repo", new URL("https://example.com/repo")));
|
||||||
assertThatExceptionOfType(InvalidInitializrMetadataException.class).isThrownBy(metadata::validate)
|
assertThatExceptionOfType(InvalidInitializrMetadataException.class).isThrownBy(metadata::validate)
|
||||||
.withMessageContaining("foo-repo").withMessageContaining("my-repo");
|
.withMessageContaining("foo-repo").withMessageContaining("my-repo");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2020 the original author or authors.
|
* Copyright 2012-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -112,7 +112,7 @@ class MetadataBuildItemResolverTests {
|
|||||||
bom.getMappings().add(BillOfMaterials.Mapping.create("2.0.0.RELEASE", "1.1.0"));
|
bom.getMappings().add(BillOfMaterials.Mapping.create("2.0.0.RELEASE", "1.1.0"));
|
||||||
metadata.getConfiguration().getEnv().getBoms().put("test-bom", bom);
|
metadata.getConfiguration().getEnv().getBoms().put("test-bom", bom);
|
||||||
metadata.getConfiguration().getEnv().getRepositories().put("test-repo",
|
metadata.getConfiguration().getEnv().getRepositories().put("test-repo",
|
||||||
new Repository("test", new URL("https://example.com/repo"), false));
|
new Repository("test", new URL("https://example.com/repo")));
|
||||||
metadata.validate();
|
metadata.validate();
|
||||||
MetadataBuildItemResolver resolver = new MetadataBuildItemResolver(metadata, VERSION_2_0_0);
|
MetadataBuildItemResolver resolver = new MetadataBuildItemResolver(metadata, VERSION_2_0_0);
|
||||||
io.spring.initializr.generator.buildsystem.BillOfMaterials resolvedBom = resolver.resolveBom("test-bom");
|
io.spring.initializr.generator.buildsystem.BillOfMaterials resolvedBom = resolver.resolveBom("test-bom");
|
||||||
@@ -132,24 +132,40 @@ class MetadataBuildItemResolverTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void resoleRepositoryWithMatchingEntry() throws MalformedURLException {
|
void resoleRepositoryWithMatchingReleasesOnlyRepository() throws MalformedURLException {
|
||||||
InitializrMetadata metadata = new InitializrMetadata();
|
InitializrMetadata metadata = new InitializrMetadata();
|
||||||
metadata.getConfiguration().getEnv().getRepositories().put("test-repo",
|
metadata.getConfiguration().getEnv().getRepositories().put("test-repo",
|
||||||
new Repository("test", new URL("https://example.com/repo"), false));
|
new Repository("test", new URL("https://example.com/repo")));
|
||||||
metadata.validate();
|
metadata.validate();
|
||||||
MetadataBuildItemResolver resolver = new MetadataBuildItemResolver(metadata, VERSION_2_0_0);
|
MetadataBuildItemResolver resolver = new MetadataBuildItemResolver(metadata, VERSION_2_0_0);
|
||||||
MavenRepository repository = resolver.resolveRepository("test-repo");
|
MavenRepository repository = resolver.resolveRepository("test-repo");
|
||||||
assertThat(repository.getId()).isEqualTo("test-repo");
|
assertThat(repository.getId()).isEqualTo("test-repo");
|
||||||
assertThat(repository.getName()).isEqualTo("test");
|
assertThat(repository.getName()).isEqualTo("test");
|
||||||
assertThat(repository.getUrl()).isEqualTo("https://example.com/repo");
|
assertThat(repository.getUrl()).isEqualTo("https://example.com/repo");
|
||||||
|
assertThat(repository.isReleasesEnabled()).isTrue();
|
||||||
assertThat(repository.isSnapshotsEnabled()).isFalse();
|
assertThat(repository.isSnapshotsEnabled()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void resoleRepositoryWithMatchingSnapshotsOnlyRepository() throws MalformedURLException {
|
||||||
|
InitializrMetadata metadata = new InitializrMetadata();
|
||||||
|
metadata.getConfiguration().getEnv().getRepositories().put("test-repo",
|
||||||
|
new Repository("test", new URL("https://example.com/repo"), false, true));
|
||||||
|
metadata.validate();
|
||||||
|
MetadataBuildItemResolver resolver = new MetadataBuildItemResolver(metadata, VERSION_2_0_0);
|
||||||
|
MavenRepository repository = resolver.resolveRepository("test-repo");
|
||||||
|
assertThat(repository.getId()).isEqualTo("test-repo");
|
||||||
|
assertThat(repository.getName()).isEqualTo("test");
|
||||||
|
assertThat(repository.getUrl()).isEqualTo("https://example.com/repo");
|
||||||
|
assertThat(repository.isReleasesEnabled()).isFalse();
|
||||||
|
assertThat(repository.isSnapshotsEnabled()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void resoleRepositoryWithNonMatchingEntry() throws MalformedURLException {
|
void resoleRepositoryWithNonMatchingEntry() throws MalformedURLException {
|
||||||
InitializrMetadata metadata = new InitializrMetadata();
|
InitializrMetadata metadata = new InitializrMetadata();
|
||||||
metadata.getConfiguration().getEnv().getRepositories().put("test-repo",
|
metadata.getConfiguration().getEnv().getRepositories().put("test-repo",
|
||||||
new Repository("test", new URL("https://example.com/repo"), false));
|
new Repository("test", new URL("https://example.com/repo")));
|
||||||
metadata.validate();
|
metadata.validate();
|
||||||
MetadataBuildItemResolver resolver = new MetadataBuildItemResolver(metadata, VERSION_2_0_0);
|
MetadataBuildItemResolver resolver = new MetadataBuildItemResolver(metadata, VERSION_2_0_0);
|
||||||
assertThat(resolver.resolveRepository("does-not-exist")).isNull();
|
assertThat(resolver.resolveRepository("does-not-exist")).isNull();
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2020 the original author or authors.
|
* Copyright 2012-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -83,7 +83,7 @@ class DefaultDependencyMetadataProviderTests {
|
|||||||
Dependency third = Dependency.withId("third", "org.foo", "third");
|
Dependency third = Dependency.withId("third", "org.foo", "third");
|
||||||
third.setRepository("repo-foo");
|
third.setRepository("repo-foo");
|
||||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
||||||
.addRepository("repo-foo", "my-repo", "http://localhost", false)
|
.addReleasesRepository("repo-foo", "my-repo", "http://localhost")
|
||||||
.addDependencyGroup("test", first, second, third).build();
|
.addDependencyGroup("test", first, second, third).build();
|
||||||
DependencyMetadata dependencyMetadata = this.provider.get(metadata, Version.parse("1.1.5.RELEASE"));
|
DependencyMetadata dependencyMetadata = this.provider.get(metadata, Version.parse("1.1.5.RELEASE"));
|
||||||
assertThat(dependencyMetadata.getDependencies()).hasSize(3);
|
assertThat(dependencyMetadata.getDependencies()).hasSize(3);
|
||||||
@@ -155,9 +155,9 @@ class DefaultDependencyMetadataProviderTests {
|
|||||||
"repo-foo", "repo-bar"));
|
"repo-foo", "repo-bar"));
|
||||||
bom.getMappings().add(BillOfMaterials.Mapping.create("1.1.0.RELEASE", "3.0.0.RELEASE", "repo-biz"));
|
bom.getMappings().add(BillOfMaterials.Mapping.create("1.1.0.RELEASE", "3.0.0.RELEASE", "repo-biz"));
|
||||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addBom("bom-foo", bom)
|
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addBom("bom-foo", bom)
|
||||||
.addRepository("repo-foo", "foo", "http://localhost", false)
|
.addReleasesRepository("repo-foo", "foo", "http://localhost")
|
||||||
.addRepository("repo-bar", "bar", "http://localhost", false)
|
.addReleasesRepository("repo-bar", "bar", "http://localhost")
|
||||||
.addRepository("repo-biz", "biz", "http://localhost", false)
|
.addReleasesRepository("repo-biz", "biz", "http://localhost")
|
||||||
.addDependencyGroup("test", first, second, third).build();
|
.addDependencyGroup("test", first, second, third).build();
|
||||||
return this.provider.get(metadata, Version.parse(bootVersion));
|
return this.provider.get(metadata, Version.parse(bootVersion));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,27 +74,32 @@
|
|||||||
"my-api-repo-1": {
|
"my-api-repo-1": {
|
||||||
"name": "repo1",
|
"name": "repo1",
|
||||||
"url": "https://example.com/repo1",
|
"url": "https://example.com/repo1",
|
||||||
|
"releasesEnabled": true,
|
||||||
"snapshotsEnabled": false
|
"snapshotsEnabled": false
|
||||||
},
|
},
|
||||||
"my-api-repo-2": {
|
"my-api-repo-2": {
|
||||||
"name": "repo2",
|
"name": "repo2",
|
||||||
"url": "https://example.com/repo2",
|
"url": "https://example.com/repo2",
|
||||||
|
"releasesEnabled": true,
|
||||||
"snapshotsEnabled": false
|
"snapshotsEnabled": false
|
||||||
},
|
},
|
||||||
"my-api-repo-3": {
|
"my-api-repo-3": {
|
||||||
"name": "repo3",
|
"name": "repo3",
|
||||||
"url": "https://example.com/repo3",
|
"url": "https://example.com/repo3",
|
||||||
|
"releasesEnabled": true,
|
||||||
"snapshotsEnabled": false
|
"snapshotsEnabled": false
|
||||||
},
|
},
|
||||||
"spring-milestones": {
|
"spring-milestones": {
|
||||||
"name": "Spring Milestones",
|
"name": "Spring Milestones",
|
||||||
"snapshotsEnabled": false,
|
"url": "https://repo.spring.io/milestone",
|
||||||
"url": "https://repo.spring.io/milestone"
|
"releasesEnabled": true,
|
||||||
|
"snapshotsEnabled": false
|
||||||
},
|
},
|
||||||
"spring-snapshots": {
|
"spring-snapshots": {
|
||||||
"name": "Spring Snapshots",
|
"name": "Spring Snapshots",
|
||||||
"snapshotsEnabled": true,
|
"url": "https://repo.spring.io/snapshot",
|
||||||
"url": "https://repo.spring.io/snapshot"
|
"releasesEnabled": false,
|
||||||
|
"snapshotsEnabled": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"boms": {
|
"boms": {
|
||||||
|
|||||||
Reference in New Issue
Block a user