mirror of
https://gitee.com/dcren/initializr.git
synced 2025-08-23 22:11:39 +08:00
Add support for repository mapping
This commit adds a way to map the repository of a dependency based on a compatibility range. Closes gh-1085
This commit is contained in:
parent
374459f800
commit
a8926c2da7
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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.
|
||||
@ -57,7 +57,7 @@ class DependencyRangesInfoContributorTests {
|
||||
void dependencyWithRangeOnArtifact() {
|
||||
Dependency dependency = Dependency.withId("foo", "com.example", "foo", "1.2.3.RELEASE");
|
||||
dependency.getMappings()
|
||||
.add(Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, "foo2", null, null));
|
||||
.add(Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, "foo2", null, null, null));
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addDependencyGroup("foo", dependency)
|
||||
.build();
|
||||
Info info = getInfo(metadata);
|
||||
@ -68,8 +68,8 @@ class DependencyRangesInfoContributorTests {
|
||||
void dependencyWithRangeAndBom() {
|
||||
BillOfMaterials bom = BillOfMaterials.create("com.example", "bom", "1.0.0");
|
||||
Dependency dependency = Dependency.withId("foo", "com.example", "foo", "1.2.3.RELEASE");
|
||||
dependency.getMappings()
|
||||
.add(Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null, "0.1.0.RELEASE", null));
|
||||
dependency.getMappings().add(
|
||||
Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null, "0.1.0.RELEASE", null, null));
|
||||
dependency.setBom("bom");
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addBom("bom", bom)
|
||||
.addDependencyGroup("foo", dependency).build();
|
||||
@ -96,9 +96,10 @@ class DependencyRangesInfoContributorTests {
|
||||
@Test
|
||||
void dependencyWithMappingAndOpenRange() {
|
||||
Dependency dependency = Dependency.withId("foo", null, null, "0.3.0.RELEASE");
|
||||
dependency.getMappings().add(
|
||||
Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null, "0.1.0.RELEASE", null, null));
|
||||
dependency.getMappings()
|
||||
.add(Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null, "0.1.0.RELEASE", null));
|
||||
dependency.getMappings().add(Dependency.Mapping.create("1.2.0.RELEASE", null, null, "0.2.0.RELEASE", null));
|
||||
.add(Dependency.Mapping.create("1.2.0.RELEASE", null, null, "0.2.0.RELEASE", null, null));
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
||||
.addDependencyGroup("test", dependency).build();
|
||||
Info info = getInfo(metadata);
|
||||
@ -111,10 +112,10 @@ class DependencyRangesInfoContributorTests {
|
||||
@Test
|
||||
void dependencyWithMappingAndNoOpenRange() {
|
||||
Dependency dependency = Dependency.withId("foo", null, null, "0.3.0.RELEASE");
|
||||
dependency.getMappings()
|
||||
.add(Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null, "0.1.0.RELEASE", null));
|
||||
dependency.getMappings()
|
||||
.add(Dependency.Mapping.create("[1.2.0.RELEASE, 1.3.0.RELEASE)", null, null, "0.2.0.RELEASE", null));
|
||||
dependency.getMappings().add(
|
||||
Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null, "0.1.0.RELEASE", null, null));
|
||||
dependency.getMappings().add(
|
||||
Dependency.Mapping.create("[1.2.0.RELEASE, 1.3.0.RELEASE)", null, null, "0.2.0.RELEASE", null, null));
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
||||
.addDependencyGroup("test", dependency).build();
|
||||
Info info = getInfo(metadata);
|
||||
|
@ -250,6 +250,7 @@ public class Dependency extends MetadataElement implements Describable {
|
||||
dependency.artifactId = (mapping.artifactId != null) ? mapping.artifactId : this.artifactId;
|
||||
dependency.version = (mapping.version != null) ? mapping.version : this.version;
|
||||
dependency.starter = (mapping.starter != null) ? mapping.starter : this.starter;
|
||||
dependency.repository = (mapping.repository != null) ? mapping.repository : this.repository;
|
||||
dependency.versionRequirement = mapping.range.toString();
|
||||
dependency.mappings = null;
|
||||
return dependency;
|
||||
@ -531,6 +532,12 @@ public class Dependency extends MetadataElement implements Describable {
|
||||
*/
|
||||
private Boolean starter;
|
||||
|
||||
/**
|
||||
* The extra repository to use for this mapping or {@code null} to use the
|
||||
* default.
|
||||
*/
|
||||
private String repository;
|
||||
|
||||
@JsonIgnore
|
||||
private VersionRange range;
|
||||
|
||||
@ -566,6 +573,14 @@ public class Dependency extends MetadataElement implements Describable {
|
||||
this.starter = starter;
|
||||
}
|
||||
|
||||
public String getRepository() {
|
||||
return this.repository;
|
||||
}
|
||||
|
||||
public void setRepository(String repository) {
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
public VersionRange getRange() {
|
||||
return this.range;
|
||||
}
|
||||
@ -578,13 +593,15 @@ public class Dependency extends MetadataElement implements Describable {
|
||||
this.compatibilityRange = compatibilityRange;
|
||||
}
|
||||
|
||||
public static Mapping create(String range, String groupId, String artifactId, String version, Boolean starter) {
|
||||
public static Mapping create(String range, String groupId, String artifactId, String version, Boolean starter,
|
||||
String repository) {
|
||||
Mapping mapping = new Mapping();
|
||||
mapping.compatibilityRange = range;
|
||||
mapping.groupId = groupId;
|
||||
mapping.artifactId = artifactId;
|
||||
mapping.version = version;
|
||||
mapping.starter = starter;
|
||||
mapping.repository = repository;
|
||||
return mapping;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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.
|
||||
@ -148,7 +148,7 @@ class DependencyTests {
|
||||
@Test
|
||||
void resolveInvalidMapping() {
|
||||
Dependency dependency = Dependency.withId("web");
|
||||
dependency.getMappings().add(Dependency.Mapping.create("foo-bar", null, null, "0.1.0.RELEASE", null));
|
||||
dependency.getMappings().add(Dependency.Mapping.create("foo-bar", null, null, "0.1.0.RELEASE", null, null));
|
||||
assertThatExceptionOfType(InvalidInitializrMetadataException.class).isThrownBy(dependency::resolve)
|
||||
.withMessageContaining("foo-bar");
|
||||
}
|
||||
@ -156,8 +156,8 @@ class DependencyTests {
|
||||
@Test
|
||||
void resolveVersionRequirement() {
|
||||
Dependency dependency = Dependency.withId("web");
|
||||
dependency.getMappings()
|
||||
.add(Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null, "0.1.0.RELEASE", null));
|
||||
dependency.getMappings().add(
|
||||
Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null, "0.1.0.RELEASE", null, null));
|
||||
dependency.resolve();
|
||||
Dependency resolved = dependency.resolve(Version.parse("1.1.5.RELEASE"));
|
||||
assertThat(resolved.getVersionRequirement()).isEqualTo(">=1.1.0.RELEASE and <1.2.0.RELEASE");
|
||||
@ -170,10 +170,10 @@ class DependencyTests {
|
||||
dependency.getKeywords().addAll(Arrays.asList("foo", "bar"));
|
||||
dependency.getAliases().add("the-web");
|
||||
dependency.getFacets().add("web");
|
||||
dependency.getMappings()
|
||||
.add(Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null, "0.1.0.RELEASE", null));
|
||||
dependency.getMappings()
|
||||
.add(Dependency.Mapping.create("[1.2.0.RELEASE, 1.3.0.RELEASE)", null, null, "0.2.0.RELEASE", null));
|
||||
dependency.getMappings().add(
|
||||
Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null, "0.1.0.RELEASE", null, null));
|
||||
dependency.getMappings().add(
|
||||
Dependency.Mapping.create("[1.2.0.RELEASE, 1.3.0.RELEASE)", null, null, "0.2.0.RELEASE", null, null));
|
||||
dependency.resolve();
|
||||
|
||||
validateResolvedWebDependency(dependency.resolve(Version.parse("1.1.5.RELEASE")), "org.springframework.boot",
|
||||
@ -191,10 +191,10 @@ class DependencyTests {
|
||||
dependency.getKeywords().addAll(Arrays.asList("foo", "bar"));
|
||||
dependency.getAliases().add("the-web");
|
||||
dependency.getFacets().add("web");
|
||||
dependency.getMappings()
|
||||
.add(Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", "org.spring.boot", null, null, null));
|
||||
dependency.getMappings()
|
||||
.add(Dependency.Mapping.create("[1.2.0.RELEASE, 1.3.0.RELEASE)", null, "starter-web", null, null));
|
||||
dependency.getMappings().add(
|
||||
Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", "org.spring.boot", null, null, null, null));
|
||||
dependency.getMappings().add(
|
||||
Dependency.Mapping.create("[1.2.0.RELEASE, 1.3.0.RELEASE)", null, "starter-web", null, null, null));
|
||||
dependency.resolve();
|
||||
|
||||
validateResolvedWebDependency(dependency.resolve(Version.parse("1.1.5.RELEASE")), "org.spring.boot",
|
||||
@ -212,10 +212,10 @@ class DependencyTests {
|
||||
dependency.getKeywords().addAll(Arrays.asList("foo", "bar"));
|
||||
dependency.getAliases().add("the-web");
|
||||
dependency.getFacets().add("web");
|
||||
dependency.getMappings()
|
||||
.add(Dependency.Mapping.create("[1.1.0.RELEASE, 1.1.x.RELEASE]", null, null, "0.1.0.RELEASE", null));
|
||||
dependency.getMappings().add(
|
||||
Dependency.Mapping.create("[1.1.x.BUILD-SNAPSHOT, 1.2.0.RELEASE)", null, null, "0.2.0.RELEASE", null));
|
||||
Dependency.Mapping.create("[1.1.0.RELEASE, 1.1.x.RELEASE]", null, null, "0.1.0.RELEASE", null, null));
|
||||
dependency.getMappings().add(Dependency.Mapping.create("[1.1.x.BUILD-SNAPSHOT, 1.2.0.RELEASE)", null, null,
|
||||
"0.2.0.RELEASE", null, null));
|
||||
dependency.resolve();
|
||||
|
||||
dependency.updateCompatibilityRange(new VersionParser(
|
||||
@ -242,36 +242,57 @@ class DependencyTests {
|
||||
@Test
|
||||
void resolveMatchingWithCustomGroupId() {
|
||||
Dependency dependency = Dependency.withId("foo", "com.acme", "foo", "0.3.0.RELEASE");
|
||||
dependency.getMappings().add(
|
||||
Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null, "1.0.0.RELEASE", null, null));
|
||||
dependency.getMappings()
|
||||
.add(Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null, "1.0.0.RELEASE", null));
|
||||
dependency.getMappings()
|
||||
.add(Dependency.Mapping.create("[1.2.0.RELEASE, 1.3.0.RELEASE)", null, "bar", null, null));
|
||||
.add(Dependency.Mapping.create("[1.2.0.RELEASE, 1.3.0.RELEASE)", null, "bar", null, null, null));
|
||||
dependency.resolve();
|
||||
validateResolvedDependency(dependency.resolve(Version.parse("1.1.5.RELEASE")), "foo", "com.acme", "foo",
|
||||
"1.0.0.RELEASE", true);
|
||||
"1.0.0.RELEASE", true, null);
|
||||
validateResolvedDependency(dependency.resolve(Version.parse("1.2.5.RELEASE")), "foo", "com.acme", "bar",
|
||||
"0.3.0.RELEASE", true);
|
||||
"0.3.0.RELEASE", true, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolveMatchingWithMappingThatDisablesStarter() {
|
||||
Dependency dependency = Dependency.withId("foo", "com.acme", "foo", "0.3.0.RELEASE");
|
||||
dependency.getMappings()
|
||||
.add(Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null, "1.0.0.RELEASE", false));
|
||||
dependency.getMappings().add(
|
||||
Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null, "1.0.0.RELEASE", false, null));
|
||||
dependency.resolve();
|
||||
validateResolvedDependency(dependency.resolve(Version.parse("1.1.5.RELEASE")), "foo", "com.acme", "foo",
|
||||
"1.0.0.RELEASE", false);
|
||||
"1.0.0.RELEASE", false, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolveMatchingWithMappingThatEnablesStarter() {
|
||||
Dependency dependency = Dependency.withId("foo", "com.acme", "foo", "0.3.0.RELEASE");
|
||||
dependency.setStarter(false);
|
||||
dependency.getMappings()
|
||||
.add(Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null, "1.0.0.RELEASE", true));
|
||||
dependency.getMappings().add(
|
||||
Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null, "1.0.0.RELEASE", true, null));
|
||||
dependency.resolve();
|
||||
validateResolvedDependency(dependency.resolve(Version.parse("1.1.5.RELEASE")), "foo", "com.acme", "foo",
|
||||
"1.0.0.RELEASE", true);
|
||||
"1.0.0.RELEASE", true, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolveMatchingWithMappingWithCustomRepository() {
|
||||
Dependency dependency = Dependency.withId("foo", "com.acme", "foo", "0.3.0.RELEASE");
|
||||
dependency.setRepository("basic-repository");
|
||||
dependency.getMappings().add(Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null,
|
||||
"1.0.0.RELEASE", null, "my-repository"));
|
||||
dependency.resolve();
|
||||
validateResolvedDependency(dependency.resolve(Version.parse("1.1.5.RELEASE")), "foo", "com.acme", "foo",
|
||||
"1.0.0.RELEASE", true, "my-repository");
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolveMatchingWithMappingWithRepository() {
|
||||
Dependency dependency = Dependency.withId("foo", "com.acme", "foo", "0.3.0.RELEASE");
|
||||
dependency.getMappings().add(Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null,
|
||||
"1.0.0.RELEASE", true, "basic-repository"));
|
||||
dependency.resolve();
|
||||
validateResolvedDependency(dependency.resolve(Version.parse("1.1.5.RELEASE")), "foo", "com.acme", "foo",
|
||||
"1.0.0.RELEASE", true, "basic-repository");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -293,19 +314,20 @@ class DependencyTests {
|
||||
private static void validateResolvedWebDependency(Dependency dependency, String expectedGroupId,
|
||||
String expectedArtifactId, String expectedVersion, boolean expectedStarter) {
|
||||
validateResolvedDependency(dependency, "web", expectedGroupId, expectedArtifactId, expectedVersion,
|
||||
expectedStarter);
|
||||
expectedStarter, null);
|
||||
assertThat(dependency.getKeywords()).hasSize(2);
|
||||
assertThat(dependency.getAliases()).hasSize(1);
|
||||
assertThat(dependency.getFacets()).hasSize(1);
|
||||
}
|
||||
|
||||
private static void validateResolvedDependency(Dependency dependency, String id, String expectedGroupId,
|
||||
String expectedArtifactId, String expectedVersion, boolean expectedStarter) {
|
||||
String expectedArtifactId, String expectedVersion, boolean expectedStarter, String expectedRepository) {
|
||||
assertThat(dependency.getId()).isEqualTo(id);
|
||||
assertThat(dependency.getGroupId()).isEqualTo(expectedGroupId);
|
||||
assertThat(dependency.getArtifactId()).isEqualTo(expectedArtifactId);
|
||||
assertThat(dependency.getVersion()).isEqualTo(expectedVersion);
|
||||
assertThat(dependency.isStarter()).isEqualTo(expectedStarter);
|
||||
assertThat(dependency.getRepository()).isEqualTo(expectedRepository);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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.
|
||||
@ -137,10 +137,10 @@ class InitializrMetadataTests {
|
||||
bom.getMappings().add(Mapping.create("[1.2.0.RELEASE,1.3.x.RELEASE]", "1.0.0"));
|
||||
bom.getMappings().add(Mapping.create("1.3.x.BUILD-SNAPSHOT", "1.1.0-BUILD-SNAPSHOT"));
|
||||
Dependency dependency = Dependency.withId("bar");
|
||||
dependency.getMappings().add(
|
||||
Dependency.Mapping.create("[1.3.0.RELEASE, 1.3.x.RELEASE]", null, null, "0.1.0.RELEASE", null, null));
|
||||
dependency.getMappings()
|
||||
.add(Dependency.Mapping.create("[1.3.0.RELEASE, 1.3.x.RELEASE]", null, null, "0.1.0.RELEASE", null));
|
||||
dependency.getMappings()
|
||||
.add(Dependency.Mapping.create("1.3.x.BUILD-SNAPSHOT", null, null, "0.2.0.RELEASE", null));
|
||||
.add(Dependency.Mapping.create("1.3.x.BUILD-SNAPSHOT", null, null, "0.2.0.RELEASE", null, null));
|
||||
|
||||
addTestDependencyGroup(metadata, dependency);
|
||||
metadata.getConfiguration().getEnv().getBoms().put("foo-bom", bom);
|
||||
|
@ -65,9 +65,9 @@ class MetadataBuildItemResolverTests {
|
||||
DependencyGroup group = DependencyGroup.create("test");
|
||||
Dependency dependency = Dependency.withId("test-dep", "com.example", "test");
|
||||
dependency.getMappings()
|
||||
.add(Mapping.create("[1.0.0.RELEASE, 2.0.0.RELEASE)", null, null, "1.0.0.RELEASE", null));
|
||||
.add(Mapping.create("[1.0.0.RELEASE, 2.0.0.RELEASE)", null, null, "1.0.0.RELEASE", null, null));
|
||||
dependency.getMappings()
|
||||
.add(Mapping.create("2.0.0.RELEASE", "com.example.override", "test-override", null, null));
|
||||
.add(Mapping.create("2.0.0.RELEASE", "com.example.override", "test-override", null, null, null));
|
||||
group.getContent().add(dependency);
|
||||
metadata.getDependencies().getContent().add(group);
|
||||
metadata.validate();
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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.
|
||||
@ -55,8 +55,9 @@ class DefaultDependencyMetadataProviderTests {
|
||||
void resolveDependencies() {
|
||||
Dependency first = Dependency.withId("first", "org.foo", "first");
|
||||
first.getMappings().add(Dependency.Mapping.create("[1.0.0.RELEASE, 1.1.0.RELEASE)", "org.bar", "second",
|
||||
"0.1.0.RELEASE", null));
|
||||
first.getMappings().add(Dependency.Mapping.create("1.1.0.RELEASE", "org.biz", "third", "0.2.0.RELEASE", null));
|
||||
"0.1.0.RELEASE", null, null));
|
||||
first.getMappings()
|
||||
.add(Dependency.Mapping.create("1.1.0.RELEASE", "org.biz", "third", "0.2.0.RELEASE", null, null));
|
||||
Dependency second = Dependency.withId("second", "org.foo", "second");
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
||||
.addDependencyGroup("test", first, second).build();
|
||||
|
Loading…
Reference in New Issue
Block a user