Upgrade to spring javaformat 0.0.38

This commit is contained in:
Stephane Nicoll
2023-04-03 14:57:51 +02:00
parent 32b5db7a5a
commit 5e97a01e99
207 changed files with 2449 additions and 1746 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-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.
@@ -200,9 +200,9 @@ public class BillOfMaterials {
resolvedBom.setVersionProperty(this.versionProperty);
resolvedBom.setOrder(this.order);
resolvedBom.repositories
.addAll(!mapping.repositories.isEmpty() ? mapping.repositories : this.repositories);
.addAll(!mapping.repositories.isEmpty() ? mapping.repositories : this.repositories);
resolvedBom.additionalBoms
.addAll(!mapping.additionalBoms.isEmpty() ? mapping.additionalBoms : this.additionalBoms);
.addAll(!mapping.additionalBoms.isEmpty() ? mapping.additionalBoms : this.additionalBoms);
return resolvedBom;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-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.
@@ -65,8 +65,8 @@ public class DependenciesCapability extends ServiceCapability<List<DependencyGro
* @return all dependencies
*/
public Collection<Dependency> getAll() {
return Collections.unmodifiableCollection(
this.indexedDependencies.values().stream().distinct().collect(Collectors.toList()));
return Collections
.unmodifiableCollection(this.indexedDependencies.values().stream().distinct().collect(Collectors.toList()));
}
public void validate() {
@@ -81,7 +81,7 @@ public class DependenciesCapability extends ServiceCapability<List<DependencyGro
public void merge(List<DependencyGroup> otherContent) {
otherContent.forEach((group) -> {
if (this.content.stream()
.noneMatch((it) -> group.getName() != null && group.getName().equals(it.getName()))) {
.noneMatch((it) -> group.getName() != null && group.getName().equals(it.getName()))) {
this.content.add(group);
}
});

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-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.
@@ -144,8 +144,10 @@ public class InitializrConfiguration {
}
private static String splitCamelCase(String text) {
return String.join("", Arrays.stream(text.split("(?<!(^|[A-Z]))(?=[A-Z])|(?<!^)(?=[A-Z][a-z])"))
.map((it) -> StringUtils.capitalize(it.toLowerCase())).toArray(String[]::new));
return String.join("",
Arrays.stream(text.split("(?<!(^|[A-Z]))(?=[A-Z])|(?<!^)(?=[A-Z][a-z])"))
.map((it) -> StringUtils.capitalize(it.toLowerCase()))
.toArray(String[]::new));
}
private static boolean hasInvalidChar(String text) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-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.
@@ -201,8 +201,10 @@ public class InitializrMetadata {
*/
public void updateSpringBootVersions(List<DefaultMetadataElement> versionsMetadata) {
this.bootVersions.setContent(versionsMetadata);
List<Version> bootVersions = this.bootVersions.getContent().stream().map((it) -> Version.parse(it.getId()))
.collect(Collectors.toList());
List<Version> bootVersions = this.bootVersions.getContent()
.stream()
.map((it) -> Version.parse(it.getId()))
.collect(Collectors.toList());
VersionParser parser = new VersionParser(bootVersions);
this.dependencies.updateCompatibilityRange(parser);
this.configuration.getEnv().updateCompatibilityRange(parser);
@@ -296,7 +298,7 @@ public class InitializrMetadata {
}
else if (this.groupId.getContent() != null && this.artifactId.getContent() != null) {
return InitializrConfiguration
.cleanPackageName(this.groupId.getContent() + "." + this.artifactId.getContent());
.cleanPackageName(this.groupId.getContent() + "." + this.artifactId.getContent());
}
return null;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-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.
@@ -132,8 +132,10 @@ public class Repository {
@Override
public String toString() {
return new StringJoiner(", ", Repository.class.getSimpleName() + "[", "]").add("name='" + this.name + "'")
.add("url=" + this.url).add("releasesEnabled=" + this.releasesEnabled)
.add("snapshotsEnabled=" + this.snapshotsEnabled).toString();
.add("url=" + this.url)
.add("releasesEnabled=" + this.releasesEnabled)
.add("snapshotsEnabled=" + this.snapshotsEnabled)
.toString();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-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.
@@ -45,9 +45,12 @@ public final class MetadataBuildItemMapper {
VersionReference versionReference = (dependency.getVersion() != null)
? VersionReference.ofValue(dependency.getVersion()) : null;
return io.spring.initializr.generator.buildsystem.Dependency
.withCoordinates(dependency.getGroupId(), dependency.getArtifactId()).version(versionReference)
.scope(toDependencyScope(dependency.getScope())).classifier(dependency.getClassifier())
.type(dependency.getType()).build();
.withCoordinates(dependency.getGroupId(), dependency.getArtifactId())
.version(versionReference)
.scope(toDependencyScope(dependency.getScope()))
.classifier(dependency.getClassifier())
.type(dependency.getType())
.build();
}
private static DependencyScope toDependencyScope(String scope) {
@@ -74,7 +77,10 @@ public final class MetadataBuildItemMapper {
VersionReference version = (bom.getVersionProperty() != null)
? VersionReference.ofProperty(bom.getVersionProperty()) : VersionReference.ofValue(bom.getVersion());
return io.spring.initializr.generator.buildsystem.BillOfMaterials
.withCoordinates(bom.getGroupId(), bom.getArtifactId()).version(version).order(bom.getOrder()).build();
.withCoordinates(bom.getGroupId(), bom.getArtifactId())
.version(version)
.order(bom.getOrder())
.build();
}
/**
@@ -89,9 +95,11 @@ public final class MetadataBuildItemMapper {
return null;
}
return io.spring.initializr.generator.buildsystem.MavenRepository
.withIdAndUrl(id, repository.getUrl().toExternalForm()).name(repository.getName())
.releasesEnabled(repository.isReleasesEnabled()).snapshotsEnabled(repository.isSnapshotsEnabled())
.build();
.withIdAndUrl(id, repository.getUrl().toExternalForm())
.name(repository.getName())
.releasesEnabled(repository.isReleasesEnabled())
.snapshotsEnabled(repository.isSnapshotsEnabled())
.build();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-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.
@@ -120,7 +120,8 @@ class BillOfMaterialsTests {
bom.getMappings().add(Mapping.create("[1.3.0.M1, 1.4.0.M1)", "1.2.0"));
bom.validate();
assertThatExceptionOfType(InvalidInitializrMetadataException.class)
.isThrownBy(() -> bom.resolve(Version.parse("1.4.1.RELEASE"))).withMessageContaining("1.4.1.RELEASE");
.isThrownBy(() -> bom.resolve(Version.parse("1.4.1.RELEASE")))
.withMessageContaining("1.4.1.RELEASE");
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-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.
@@ -92,14 +92,14 @@ class DependencyTests {
@Test
void invalidDependency() {
assertThatExceptionOfType(InvalidInitializrMetadataException.class)
.isThrownBy(() -> new Dependency().resolve());
.isThrownBy(() -> new Dependency().resolve());
}
@Test
void invalidDependencyScope() {
Dependency dependency = Dependency.withId("web");
assertThatExceptionOfType(InvalidInitializrMetadataException.class)
.isThrownBy(() -> dependency.setScope("whatever"));
.isThrownBy(() -> dependency.setScope("whatever"));
}
@@ -108,7 +108,7 @@ class DependencyTests {
Dependency dependency = Dependency.withId("web");
dependency.setCompatibilityRange("A.B.C");
assertThatExceptionOfType(InvalidInitializrMetadataException.class).isThrownBy(dependency::resolve)
.withMessageContaining("A.B.C");
.withMessageContaining("A.B.C");
}
@Test
@@ -149,16 +149,17 @@ class DependencyTests {
void resolveInvalidMapping() {
Dependency dependency = Dependency.withId("web");
dependency.getMappings()
.add(Dependency.Mapping.create("foo-bar", null, null, "0.1.0.RELEASE", null, null, null));
.add(Dependency.Mapping.create("foo-bar", null, null, "0.1.0.RELEASE", null, null, null));
assertThatExceptionOfType(InvalidInitializrMetadataException.class).isThrownBy(dependency::resolve)
.withMessageContaining("foo-bar");
.withMessageContaining("foo-bar");
}
@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, null, null));
dependency.getMappings()
.add(Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null, "0.1.0.RELEASE", null, 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");
@@ -171,10 +172,12 @@ 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, null, null));
dependency.getMappings().add(Dependency.Mapping.create("[1.2.0.RELEASE, 1.3.0.RELEASE)", null, null,
"0.2.0.RELEASE", null, null, null));
dependency.getMappings()
.add(Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null, "0.1.0.RELEASE", null, null,
null));
dependency.getMappings()
.add(Dependency.Mapping.create("[1.2.0.RELEASE, 1.3.0.RELEASE)", null, null, "0.2.0.RELEASE", null, null,
null));
dependency.resolve();
validateResolvedWebDependency(dependency.resolve(Version.parse("1.1.5.RELEASE")), "org.springframework.boot",
@@ -192,10 +195,12 @@ 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, null, null));
dependency.getMappings().add(Dependency.Mapping.create("[1.2.0.RELEASE, 1.3.0.RELEASE)", null, "starter-web",
null, null, null, null));
dependency.getMappings()
.add(Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", "org.spring.boot", null, null, null, null,
null));
dependency.getMappings()
.add(Dependency.Mapping.create("[1.2.0.RELEASE, 1.3.0.RELEASE)", null, "starter-web", null, null, null,
null));
dependency.resolve();
validateResolvedWebDependency(dependency.resolve(Version.parse("1.1.5.RELEASE")), "org.spring.boot",
@@ -213,10 +218,12 @@ 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, 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, null));
dependency.getMappings()
.add(Dependency.Mapping.create("[1.1.0.RELEASE, 1.1.x.RELEASE]", null, null, "0.1.0.RELEASE", null, 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, null));
dependency.resolve();
dependency.updateCompatibilityRange(new VersionParser(
@@ -243,10 +250,11 @@ 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, null));
dependency.getMappings()
.add(Dependency.Mapping.create("[1.2.0.RELEASE, 1.3.0.RELEASE)", null, "bar", null, null, null, null));
.add(Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null, "1.0.0.RELEASE", null, null,
null));
dependency.getMappings()
.add(Dependency.Mapping.create("[1.2.0.RELEASE, 1.3.0.RELEASE)", null, "bar", null, null, null, null));
dependency.resolve();
validateResolvedDependency(dependency.resolve(Version.parse("1.1.5.RELEASE")), "foo", "com.acme", "foo",
"1.0.0.RELEASE", true, null, null);
@@ -257,8 +265,9 @@ class DependencyTests {
@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, null, null));
dependency.getMappings()
.add(Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null, "1.0.0.RELEASE", false, null,
null));
dependency.resolve();
validateResolvedDependency(dependency.resolve(Version.parse("1.1.5.RELEASE")), "foo", "com.acme", "foo",
"1.0.0.RELEASE", false, null, null);
@@ -268,8 +277,9 @@ class DependencyTests {
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, null, null));
dependency.getMappings()
.add(Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null, "1.0.0.RELEASE", true, null,
null));
dependency.resolve();
validateResolvedDependency(dependency.resolve(Version.parse("1.1.5.RELEASE")), "foo", "com.acme", "foo",
"1.0.0.RELEASE", true, null, null);
@@ -279,8 +289,9 @@ class DependencyTests {
void resolveMatchingWithMappingWithCustomBom() {
Dependency dependency = Dependency.withId("foo", "com.acme", "foo", "0.3.0.RELEASE");
dependency.setBom("basic-bom");
dependency.getMappings().add(Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null,
"1.0.0.RELEASE", null, "my-bom", null));
dependency.getMappings()
.add(Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null, "1.0.0.RELEASE", null,
"my-bom", null));
dependency.resolve();
validateResolvedDependency(dependency.resolve(Version.parse("1.1.5.RELEASE")), "foo", "com.acme", "foo",
"1.0.0.RELEASE", true, "my-bom", null);
@@ -289,8 +300,9 @@ class DependencyTests {
@Test
void resolveMatchingWithMappingWithBom() {
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-bom", null));
dependency.getMappings()
.add(Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null, "1.0.0.RELEASE", true,
"basic-bom", null));
dependency.resolve();
validateResolvedDependency(dependency.resolve(Version.parse("1.1.5.RELEASE")), "foo", "com.acme", "foo",
"1.0.0.RELEASE", true, "basic-bom", null);
@@ -300,8 +312,9 @@ class DependencyTests {
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, null, "my-repository"));
dependency.getMappings()
.add(Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null, "1.0.0.RELEASE", null, null,
"my-repository"));
dependency.resolve();
validateResolvedDependency(dependency.resolve(Version.parse("1.1.5.RELEASE")), "foo", "com.acme", "foo",
"1.0.0.RELEASE", true, null, "my-repository");
@@ -310,8 +323,9 @@ class DependencyTests {
@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, null, "basic-repository"));
dependency.getMappings()
.add(Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null, "1.0.0.RELEASE", true, null,
"basic-repository"));
dependency.resolve();
validateResolvedDependency(dependency.resolve(Version.parse("1.1.5.RELEASE")), "foo", "com.acme", "foo",
"1.0.0.RELEASE", true, null, "basic-repository");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-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.
@@ -90,31 +90,31 @@ class InitializrConfigurationTests {
@Test
void generateApplicationNameNull() {
assertThat(this.properties.generateApplicationName(null))
.isEqualTo(this.properties.getEnv().getFallbackApplicationName());
.isEqualTo(this.properties.getEnv().getFallbackApplicationName());
}
@Test
void generateApplicationNameInvalidStartCharacter() {
assertThat(this.properties.generateApplicationName("1MyDemo"))
.isEqualTo(this.properties.getEnv().getFallbackApplicationName());
.isEqualTo(this.properties.getEnv().getFallbackApplicationName());
}
@Test
void generateApplicationNameInvalidPartCharacter() {
assertThat(this.properties.generateApplicationName("MyDe|mo"))
.isEqualTo(this.properties.getEnv().getFallbackApplicationName());
.isEqualTo(this.properties.getEnv().getFallbackApplicationName());
}
@Test
void generateApplicationNameInvalidApplicationName() {
assertThat(this.properties.generateApplicationName("SpringBoot"))
.isEqualTo(this.properties.getEnv().getFallbackApplicationName());
.isEqualTo(this.properties.getEnv().getFallbackApplicationName());
}
@Test
void generateApplicationNameAnotherInvalidApplicationName() {
assertThat(this.properties.generateApplicationName("Spring"))
.isEqualTo(this.properties.getEnv().getFallbackApplicationName());
.isEqualTo(this.properties.getEnv().getFallbackApplicationName());
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-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.
@@ -49,7 +49,8 @@ class InitializrMetadataBuilderTests {
void mergeIdenticalConfig() {
InitializrProperties bean = load(new ClassPathResource("application-test-default.yml"));
InitializrMetadata metadata = InitializrMetadataBuilder.fromInitializrProperties(bean)
.withInitializrProperties(bean, true).build();
.withInitializrProperties(bean, true)
.build();
assertDefaultConfig(metadata);
}
@@ -58,7 +59,8 @@ class InitializrMetadataBuilderTests {
InitializrProperties config = load(new ClassPathResource("application-test-default.yml"));
InitializrProperties customDefaultsConfig = load(new ClassPathResource("application-test-custom-defaults.yml"));
InitializrMetadata metadata = InitializrMetadataBuilder.fromInitializrProperties(config)
.withInitializrProperties(customDefaultsConfig).build();
.withInitializrProperties(customDefaultsConfig)
.build();
assertDefaultConfig(metadata);
assertThat(metadata.getGroupId().getContent()).isEqualTo("org.foo");
assertThat(metadata.getArtifactId().getContent()).isEqualTo("foo-bar");
@@ -71,7 +73,8 @@ class InitializrMetadataBuilderTests {
@Test
void mergeMetadata() {
InitializrMetadata metadata = InitializrMetadataBuilder.create()
.withInitializrMetadata(new ClassPathResource("metadata/config/test-min.json")).build();
.withInitializrMetadata(new ClassPathResource("metadata/config/test-min.json"))
.build();
assertThat(metadata.getConfiguration().getEnv().isForceSsl()).isEqualTo(true);
assertThat(metadata.getDependencies().getContent()).hasSize(1);
Dependency dependency = metadata.getDependencies().get("test");
@@ -93,7 +96,8 @@ class InitializrMetadataBuilderTests {
@Test
void mergeMetadataWithBom() {
InitializrMetadata metadata = InitializrMetadataBuilder.create()
.withInitializrMetadata(new ClassPathResource("metadata/config/test-bom.json")).build();
.withInitializrMetadata(new ClassPathResource("metadata/config/test-bom.json"))
.build();
Map<String, BillOfMaterials> boms = metadata.getConfiguration().getEnv().getBoms();
assertThat(boms).hasSize(2);
@@ -113,7 +117,8 @@ class InitializrMetadataBuilderTests {
@Test
void mergeMetadataWithRepository() throws Exception {
InitializrMetadata metadata = InitializrMetadataBuilder.create()
.withInitializrMetadata(new ClassPathResource("metadata/config/test-repository.json")).build();
.withInitializrMetadata(new ClassPathResource("metadata/config/test-repository.json"))
.build();
Map<String, Repository> repositories = metadata.getConfiguration().getEnv().getRepositories();
assertThat(repositories).hasSize(4); // 2 standard repos
@@ -135,7 +140,8 @@ class InitializrMetadataBuilderTests {
InitializrProperties config = load(new ClassPathResource("application-test-default.yml"));
InitializrProperties customDefaultsConfig = load(new ClassPathResource("application-test-custom-env.yml"));
InitializrMetadata metadata = InitializrMetadataBuilder.fromInitializrProperties(config)
.withInitializrProperties(customDefaultsConfig).build();
.withInitializrProperties(customDefaultsConfig)
.build();
InitializrConfiguration.Env defaultEnv = new InitializrConfiguration().getEnv();
InitializrConfiguration.Env actualEnv = metadata.getConfiguration().getEnv();
assertThat(actualEnv.getArtifactRepository()).isEqualTo(defaultEnv.getArtifactRepository());
@@ -149,7 +155,8 @@ class InitializrMetadataBuilderTests {
InitializrProperties config = load(new ClassPathResource("application-test-default.yml"));
InitializrProperties customDefaultsConfig = load(new ClassPathResource("application-test-custom-env.yml"));
InitializrMetadata metadata = InitializrMetadataBuilder.fromInitializrProperties(config)
.withInitializrProperties(customDefaultsConfig, true).build();
.withInitializrProperties(customDefaultsConfig, true)
.build();
InitializrConfiguration.Env defaultEnv = new InitializrConfiguration().getEnv();
InitializrConfiguration.Env actualEnv = metadata.getConfiguration().getEnv();
assertThat(actualEnv.getArtifactRepository()).isEqualTo("https://repo.spring.io/lib-release/");
@@ -164,7 +171,8 @@ class InitializrMetadataBuilderTests {
InitializrProperties config = load(new ClassPathResource("application-test-default.yml"));
InitializrProperties forceSslConfig = load(new ClassPathResource("application-test-ssl.yml"));
InitializrMetadata metadata = InitializrMetadataBuilder.fromInitializrProperties(config)
.withInitializrProperties(forceSslConfig, true).build();
.withInitializrProperties(forceSslConfig, true)
.build();
InitializrConfiguration.Env actualEnv = metadata.getConfiguration().getEnv();
assertThat(actualEnv.isForceSsl()).isEqualTo(true);
}
@@ -175,7 +183,8 @@ class InitializrMetadataBuilderTests {
Dependency dependency = Dependency.withId("com.foo:foo:1.0.0");
group.getContent().add(dependency);
InitializrMetadata metadata = InitializrMetadataBuilder.create()
.withCustomizer((m) -> m.getDependencies().getContent().add(group)).build();
.withCustomizer((m) -> m.getDependencies().getContent().add(group))
.build();
assertThat(metadata.getDependencies().getContent()).hasSize(1);
assertThat(metadata.getDependencies().getContent().get(0)).isEqualTo(group);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-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.
@@ -43,10 +43,13 @@ class InitializrMetadataTests {
Dependency foo = Dependency.withId("foo", "org.acme", "foo");
foo.setBom("foo-bom");
addTestDependencyGroup(metadata, foo);
metadata.getConfiguration().getEnv().getBoms().put("my-bom",
BillOfMaterials.create("org.acme", "foo", "1.2.3"));
metadata.getConfiguration()
.getEnv()
.getBoms()
.put("my-bom", BillOfMaterials.create("org.acme", "foo", "1.2.3"));
assertThatExceptionOfType(InvalidInitializrMetadataException.class).isThrownBy(metadata::validate)
.withMessageContaining("foo-bom").withMessageContaining("my-bom");
.withMessageContaining("foo-bom")
.withMessageContaining("my-bom");
}
@Test
@@ -55,10 +58,13 @@ class InitializrMetadataTests {
Dependency foo = Dependency.withId("foo", "org.acme", "foo");
foo.setRepository("foo-repo");
addTestDependencyGroup(metadata, foo);
metadata.getConfiguration().getEnv().getRepositories().put("my-repo",
new Repository("repo", new URL("https://example.com/repo")));
metadata.getConfiguration()
.getEnv()
.getRepositories()
.put("my-repo", new Repository("repo", new URL("https://example.com/repo")));
assertThatExceptionOfType(InvalidInitializrMetadataException.class).isThrownBy(metadata::validate)
.withMessageContaining("foo-repo").withMessageContaining("my-repo");
.withMessageContaining("foo-repo")
.withMessageContaining("my-repo");
}
@Test
@@ -66,7 +72,8 @@ class InitializrMetadataTests {
InitializrMetadata metadata = initializeMetadata();
metadata.getConfiguration().getEnv().getBoms().put("foo-bom", BillOfMaterials.create("org.acme", "foo-bom"));
assertThatExceptionOfType(InvalidInitializrMetadataException.class).isThrownBy(metadata::validate)
.withMessageContaining("No version").withMessageContaining("foo-bom");
.withMessageContaining("No version")
.withMessageContaining("foo-bom");
}
@Test
@@ -76,7 +83,8 @@ class InitializrMetadataTests {
bom.getRepositories().add("foo-repo");
metadata.getConfiguration().getEnv().getBoms().put("foo-bom", bom);
assertThatExceptionOfType(InvalidInitializrMetadataException.class).isThrownBy(metadata::validate)
.withMessageContaining("invalid repository id foo-repo").withMessageContaining("foo-bom");
.withMessageContaining("invalid repository id foo-repo")
.withMessageContaining("foo-bom");
}
@Test
@@ -88,7 +96,8 @@ class InitializrMetadataTests {
metadata.getConfiguration().getEnv().getBoms().put("foo-bom", bom);
metadata.getConfiguration().getEnv().getBoms().put("bar-bom", barBom);
assertThatExceptionOfType(InvalidInitializrMetadataException.class).isThrownBy(metadata::validate)
.withMessageContaining("invalid additional bom").withMessageContaining("biz-bom");
.withMessageContaining("invalid additional bom")
.withMessageContaining("biz-bom");
}
@Test
@@ -99,7 +108,8 @@ class InitializrMetadataTests {
bom.getMappings().add(Mapping.create("FOO_BAR", "1.2.0"));
metadata.getConfiguration().getEnv().getBoms().put("foo-bom", bom);
assertThatExceptionOfType(InvalidInitializrMetadataException.class).isThrownBy(metadata::validate)
.withMessageContaining("FOO_BAR").withMessageContaining("foo-bom");
.withMessageContaining("FOO_BAR")
.withMessageContaining("foo-bom");
}
@Test
@@ -112,8 +122,9 @@ class InitializrMetadataTests {
bom.getMappings().add(mapping);
metadata.getConfiguration().getEnv().getBoms().put("foo-bom", bom);
assertThatExceptionOfType(InvalidInitializrMetadataException.class).isThrownBy(metadata::validate)
.withMessageContaining("invalid repository id foo-repo").withMessageContaining("1.3.0.M2")
.withMessageContaining("foo-bom");
.withMessageContaining("invalid repository id foo-repo")
.withMessageContaining("1.3.0.M2")
.withMessageContaining("foo-bom");
}
@Test
@@ -126,8 +137,9 @@ class InitializrMetadataTests {
bom.getMappings().add(mapping);
metadata.getConfiguration().getEnv().getBoms().put("foo-bom", bom);
assertThatExceptionOfType(InvalidInitializrMetadataException.class).isThrownBy(metadata::validate)
.withMessageContaining("invalid additional bom").withMessageContaining("1.3.0.M2")
.withMessageContaining("bar-bom");
.withMessageContaining("invalid additional bom")
.withMessageContaining("1.3.0.M2")
.withMessageContaining("bar-bom");
}
@Test
@@ -137,10 +149,11 @@ 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, null));
dependency.getMappings()
.add(Dependency.Mapping.create("1.3.x.BUILD-SNAPSHOT", null, null, "0.2.0.RELEASE", null, null, null));
.add(Dependency.Mapping.create("[1.3.0.RELEASE, 1.3.x.RELEASE]", null, null, "0.1.0.RELEASE", null, null,
null));
dependency.getMappings()
.add(Dependency.Mapping.create("1.3.x.BUILD-SNAPSHOT", null, null, "0.2.0.RELEASE", null, null, null));
addTestDependencyGroup(metadata, dependency);
metadata.getConfiguration().getEnv().getBoms().put("foo-bom", bom);
@@ -154,16 +167,26 @@ class InitializrMetadataTests {
DefaultMetadataElement.create("1.3.6.RELEASE", "1.3.6", false),
DefaultMetadataElement.create("1.3.7.BUILD-SNAPSHOT", "1.3.7", false));
metadata.updateSpringBootVersions(bootVersions);
assertThat(metadata.getConfiguration().getEnv().getBoms().get("foo-bom").resolve(Version.parse("1.3.6.RELEASE"))
.getVersion()).isEqualTo("1.0.0");
assertThat(metadata.getConfiguration().getEnv().getBoms().get("foo-bom")
.resolve(Version.parse("1.3.7.BUILD-SNAPSHOT")).getVersion()).isEqualTo("1.1.0-BUILD-SNAPSHOT");
assertThat(metadata.getConfiguration()
.getEnv()
.getBoms()
.get("foo-bom")
.resolve(Version.parse("1.3.6.RELEASE"))
.getVersion()).isEqualTo("1.0.0");
assertThat(metadata.getConfiguration()
.getEnv()
.getBoms()
.get("foo-bom")
.resolve(Version.parse("1.3.7.BUILD-SNAPSHOT"))
.getVersion()).isEqualTo("1.1.0-BUILD-SNAPSHOT");
assertThat(metadata.getDependencies().get("bar").resolve(Version.parse("1.3.6.RELEASE")).getVersion())
.isEqualTo("0.1.0.RELEASE");
.isEqualTo("0.1.0.RELEASE");
assertThat(metadata.getDependencies().get("bar").resolve(Version.parse("1.3.7.BUILD-SNAPSHOT")).getVersion())
.isEqualTo("0.2.0.RELEASE");
assertThat(metadata.getConfiguration().getEnv().getKotlin()
.resolveKotlinVersion(Version.parse("1.3.7.BUILD-SNAPSHOT"))).isEqualTo("1.2");
.isEqualTo("0.2.0.RELEASE");
assertThat(metadata.getConfiguration()
.getEnv()
.getKotlin()
.resolveKotlinVersion(Version.parse("1.3.7.BUILD-SNAPSHOT"))).isEqualTo("1.2");
}
@Test
@@ -173,7 +196,7 @@ class InitializrMetadataTests {
parent.setGroupId("org.foo");
parent.setArtifactId("foo-parent");
assertThatExceptionOfType(InvalidInitializrMetadataException.class).isThrownBy(metadata::validate)
.withMessageContaining("Custom maven pom requires groupId, artifactId and version");
.withMessageContaining("Custom maven pom requires groupId, artifactId and version");
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-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.
@@ -88,7 +88,7 @@ class LinkTests {
Link link = Link.create("reference", "https://example.com/{a}/2/{b}");
link.resolve();
assertThatIllegalArgumentException().isThrownBy(() -> link.expand(Collections.singletonMap("a", "test")))
.withMessageContaining("missing value for 'b'");
.withMessageContaining("missing value for 'b'");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-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.
@@ -65,15 +65,15 @@ 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, null, null));
.add(Mapping.create("[1.0.0.RELEASE, 2.0.0.RELEASE)", null, null, "1.0.0.RELEASE", null, null, null));
dependency.getMappings()
.add(Mapping.create("2.0.0.RELEASE", "com.example.override", "test-override", null, null, null, null));
.add(Mapping.create("2.0.0.RELEASE", "com.example.override", "test-override", null, null, null, null));
group.getContent().add(dependency);
metadata.getDependencies().getContent().add(group);
metadata.validate();
MetadataBuildItemResolver resolver = new MetadataBuildItemResolver(metadata, VERSION_2_0_0);
io.spring.initializr.generator.buildsystem.Dependency resolveDependency = resolver
.resolveDependency("test-dep");
.resolveDependency("test-dep");
assertThat(resolveDependency.getGroupId()).isEqualTo("com.example.override");
assertThat(resolveDependency.getArtifactId()).isEqualTo("test-override");
assertThat(resolveDependency.getVersion()).isNull();
@@ -111,8 +111,10 @@ class MetadataBuildItemResolverTests {
bom.getMappings().add(BillOfMaterials.Mapping.create("[1.0.0.RELEASE, 2.0.0.RELEASE)", "1.0.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().getRepositories().put("test-repo",
new Repository("test", new URL("https://example.com/repo")));
metadata.getConfiguration()
.getEnv()
.getRepositories()
.put("test-repo", new Repository("test", new URL("https://example.com/repo")));
metadata.validate();
MetadataBuildItemResolver resolver = new MetadataBuildItemResolver(metadata, VERSION_2_0_0);
io.spring.initializr.generator.buildsystem.BillOfMaterials resolvedBom = resolver.resolveBom("test-bom");
@@ -134,8 +136,10 @@ class MetadataBuildItemResolverTests {
@Test
void resoleRepositoryWithMatchingReleasesOnlyRepository() throws MalformedURLException {
InitializrMetadata metadata = new InitializrMetadata();
metadata.getConfiguration().getEnv().getRepositories().put("test-repo",
new Repository("test", new URL("https://example.com/repo")));
metadata.getConfiguration()
.getEnv()
.getRepositories()
.put("test-repo", new Repository("test", new URL("https://example.com/repo")));
metadata.validate();
MetadataBuildItemResolver resolver = new MetadataBuildItemResolver(metadata, VERSION_2_0_0);
MavenRepository repository = resolver.resolveRepository("test-repo");
@@ -149,8 +153,10 @@ class MetadataBuildItemResolverTests {
@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.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");
@@ -164,8 +170,10 @@ class MetadataBuildItemResolverTests {
@Test
void resoleRepositoryWithNonMatchingEntry() throws MalformedURLException {
InitializrMetadata metadata = new InitializrMetadata();
metadata.getConfiguration().getEnv().getRepositories().put("test-repo",
new Repository("test", new URL("https://example.com/repo")));
metadata.getConfiguration()
.getEnv()
.getRepositories()
.put("test-repo", new Repository("test", new URL("https://example.com/repo")));
metadata.validate();
MetadataBuildItemResolver resolver = new MetadataBuildItemResolver(metadata, VERSION_2_0_0);
assertThat(resolver.resolveRepository("does-not-exist")).isNull();