Java Code Examples for io.spring.initializr.metadata.BillOfMaterials#create()

The following examples show how to use io.spring.initializr.metadata.BillOfMaterials#create() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MetadataBuildItemResolverTests.java    From initializr with Apache License 2.0 6 votes vote down vote up
@Test
void resoleBomWithMatchingEntryAndCompatibilityRange() throws MalformedURLException {
	InitializrMetadata metadata = new InitializrMetadata();
	BillOfMaterials bom = BillOfMaterials.create("com.example", "bom", "0.0.1");
	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"), false));
	metadata.validate();
	MetadataBuildItemResolver resolver = new MetadataBuildItemResolver(metadata, VERSION_2_0_0);
	io.spring.initializr.generator.buildsystem.BillOfMaterials resolvedBom = resolver.resolveBom("test-bom");
	assertThat(resolvedBom.getGroupId()).isEqualTo("com.example");
	assertThat(resolvedBom.getArtifactId()).isEqualTo("bom");
	assertThat(resolvedBom.getVersion()).hasToString("1.1.0");
}
 
Example 2
Source File: BomRangesInfoContributorTests.java    From initializr with Apache License 2.0 6 votes vote down vote up
@Test
void withMappings() {
	BillOfMaterials bom = BillOfMaterials.create("com.example", "bom", "1.0.0");
	bom.getMappings().add(BillOfMaterials.Mapping.create("[1.3.0.RELEASE,1.3.8.RELEASE]", "1.1.0"));
	bom.getMappings().add(BillOfMaterials.Mapping.create("1.3.8.BUILD-SNAPSHOT", "1.1.1-SNAPSHOT"));
	InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addBom("foo", bom).build();
	Info info = getInfo(metadata);
	assertThat(info.getDetails()).containsKeys("bom-ranges");
	@SuppressWarnings("unchecked")
	Map<String, Object> ranges = (Map<String, Object>) info.getDetails().get("bom-ranges");
	assertThat(ranges).containsOnlyKeys("foo");
	@SuppressWarnings("unchecked")
	Map<String, Object> foo = (Map<String, Object>) ranges.get("foo");
	assertThat(foo).containsExactly(entry("1.1.0", "Spring Boot >=1.3.0.RELEASE and <=1.3.8.RELEASE"),
			entry("1.1.1-SNAPSHOT", "Spring Boot >=1.3.8.BUILD-SNAPSHOT"));
}
 
Example 3
Source File: BuildComplianceTests.java    From initializr with Apache License 2.0 6 votes vote down vote up
@ParameterizedTest
@MethodSource("parameters")
void bomWithOrdering(BuildSystem build, String fileName) {
	Dependency foo = Dependency.withId("foo", "org.acme", "foo");
	foo.setBom("foo-bom");
	BillOfMaterials barBom = BillOfMaterials.create("org.acme", "bar-bom", "1.0");
	barBom.setOrder(50);
	BillOfMaterials bizBom = BillOfMaterials.create("org.acme", "biz-bom");
	bizBom.setOrder(40);
	bizBom.getAdditionalBoms().add("bar-bom");
	bizBom.getMappings().add(BillOfMaterials.Mapping.create("1.0.0.RELEASE", "1.0"));
	BillOfMaterials fooBom = BillOfMaterials.create("org.acme", "foo-bom", "1.0");
	fooBom.setOrder(20);
	fooBom.getAdditionalBoms().add("biz-bom");
	InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addDependencyGroup("foo", foo)
			.addBom("foo-bom", fooBom).addBom("bar-bom", barBom).addBom("biz-bom", bizBom).build();
	ProjectStructure project = generateProject(java, build, "2.1.1.RELEASE",
			(description) -> description.addDependency("foo", MetadataBuildItemMapper.toDependency(foo)), metadata);
	assertThat(project).textFile(fileName).hasSameContentAs(
			new ClassPathResource("project/" + build + "/bom-ordering-" + getAssertFileName(fileName)));
}
 
Example 4
Source File: DefaultDependencyMetadataProviderTests.java    From initializr with Apache License 2.0 6 votes vote down vote up
@Test
void addBomAndRemoveDuplicates() {
	Dependency first = Dependency.withId("first", "org.foo", "first");
	first.setBom("bom-foo");
	Dependency second = Dependency.withId("second", "org.foo", "second");
	Dependency third = Dependency.withId("third", "org.foo", "third");
	third.setBom("bom-foo");

	BillOfMaterials bom = BillOfMaterials.create("org.foo", "bom");
	bom.getMappings().add(BillOfMaterials.Mapping.create("[1.0.0.RELEASE, 1.1.8.RELEASE)", "1.0.0.RELEASE"));
	bom.getMappings().add(BillOfMaterials.Mapping.create("1.1.8.RELEASE", "2.0.0.RELEASE"));
	InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addBom("bom-foo", bom)
			.addDependencyGroup("test", first, second, third).build();
	DependencyMetadata dependencyMetadata = this.provider.get(metadata, Version.parse("1.1.5.RELEASE"));
	assertThat(dependencyMetadata.getDependencies()).hasSize(3);
	assertThat(dependencyMetadata.getRepositories()).isEmpty();
	assertThat(dependencyMetadata.getBoms()).hasSize(1);
	assertThat(dependencyMetadata.getBoms().get("bom-foo").getGroupId()).isEqualTo("org.foo");
	assertThat(dependencyMetadata.getBoms().get("bom-foo").getArtifactId()).isEqualTo("bom");
	assertThat(dependencyMetadata.getBoms().get("bom-foo").getVersion()).isEqualTo("1.0.0.RELEASE");
}
 
Example 5
Source File: DefaultDependencyMetadataProviderTests.java    From initializr with Apache License 2.0 6 votes vote down vote up
private DependencyMetadata testRepoFromBomAccordingToVersion(String bootVersion) {
	Dependency first = Dependency.withId("first", "org.foo", "first");
	first.setRepository("repo-foo");
	Dependency second = Dependency.withId("second", "org.foo", "second");
	Dependency third = Dependency.withId("third", "org.foo", "third");
	third.setBom("bom-foo");

	BillOfMaterials bom = BillOfMaterials.create("org.foo", "bom");
	bom.getMappings().add(BillOfMaterials.Mapping.create("[1.0.0.RELEASE, 1.1.0.RELEASE)", "2.0.0.RELEASE",
			"repo-foo", "repo-bar"));
	bom.getMappings().add(BillOfMaterials.Mapping.create("1.1.0.RELEASE", "3.0.0.RELEASE", "repo-biz"));
	InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addBom("bom-foo", bom)
			.addRepository("repo-foo", "foo", "http://localhost", false)
			.addRepository("repo-bar", "bar", "http://localhost", false)
			.addRepository("repo-biz", "biz", "http://localhost", false)
			.addDependencyGroup("test", first, second, third).build();
	return this.provider.get(metadata, Version.parse(bootVersion));
}
 
Example 6
Source File: DependencyMetadataJsonMapperTests.java    From initializr with Apache License 2.0 6 votes vote down vote up
@Test
void mapDependency() throws Exception {
	Dependency d = Dependency.withId("foo", "org.foo", "foo");
	d.setRepository("my-repo");
	d.setBom("my-bom");
	Repository repository = new Repository();
	repository.setName("foo-repo");
	repository.setUrl(new URL("https://example.com/foo"));
	BillOfMaterials bom = BillOfMaterials.create("org.foo", "foo-bom", "1.0.0.RELEASE");
	DependencyMetadata metadata = new DependencyMetadata(Version.parse("1.2.0.RELEASE"),
			Collections.singletonMap(d.getId(), d), Collections.singletonMap("repo-id", repository),
			Collections.singletonMap("bom-id", bom));
	JSONObject content = new JSONObject(this.mapper.write(metadata));
	assertThat(content.getJSONObject("dependencies").getJSONObject("foo").getString("bom")).isEqualTo("my-bom");
	assertThat(content.getJSONObject("dependencies").getJSONObject("foo").getString("repository"))
			.isEqualTo("my-repo");
	assertThat(content.getJSONObject("repositories").getJSONObject("repo-id").getString("name"))
			.isEqualTo("foo-repo");
	assertThat(content.getJSONObject("boms").getJSONObject("bom-id").getString("artifactId")).isEqualTo("foo-bom");
	assertThat(content.getJSONObject("boms").getJSONObject("bom-id").getString("version"))
			.isEqualTo("1.0.0.RELEASE");
}
 
Example 7
Source File: SpringCloudProjectVersionResolverTests.java    From start.spring.io with Apache License 2.0 5 votes vote down vote up
@Test
void resolveWithNoSpringCloudBom() {
	BillOfMaterials bom = BillOfMaterials.create("com.example", "custom-bom", "1.0.0");
	InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addBom("custom-bom", bom).build();
	String version = new SpringCloudProjectVersionResolver(metadata, this.versionResolver)
			.resolveVersion(VersionParser.DEFAULT.parse("2.1.0.RELEASE"), "com.example:test");
	assertThat(version).isNull();
}
 
Example 8
Source File: SpringCloudProjectVersionResolverTests.java    From start.spring.io with Apache License 2.0 5 votes vote down vote up
@Test
void resolveWithUnknownArtifactId() {
	BillOfMaterials bom = BillOfMaterials.create("org.springframework.cloud", "spring-cloud-dependencies", "1.0.0");
	InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addBom("spring-cloud", bom).build();
	given(this.versionResolver.resolve("org.springframework.cloud", "spring-cloud-dependencies", "1.0.0"))
			.willReturn(Collections.singletonMap("org.springframework.cloud:spring-cloud", "1.1.0"));
	String version = new SpringCloudProjectVersionResolver(metadata, this.versionResolver)
			.resolveVersion(VersionParser.DEFAULT.parse("2.1.0.RELEASE"), "org.springframework.cloud:test");
	assertThat(version).isNull();
}
 
Example 9
Source File: SpringCloudProjectVersionResolverTests.java    From start.spring.io with Apache License 2.0 5 votes vote down vote up
@Test
void resolveManagedArtifact() {
	BillOfMaterials bom = BillOfMaterials.create("org.springframework.cloud", "spring-cloud-dependencies", "1.0.0");
	InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addBom("spring-cloud", bom).build();
	given(this.versionResolver.resolve("org.springframework.cloud", "spring-cloud-dependencies", "1.0.0"))
			.willReturn(Collections.singletonMap("org.springframework.cloud:spring-cloud", "1.1.0"));
	String version = new SpringCloudProjectVersionResolver(metadata, this.versionResolver)
			.resolveVersion(VersionParser.DEFAULT.parse("2.1.0.RELEASE"), "org.springframework.cloud:spring-cloud");
	assertThat(version).isEqualTo("1.1.0");
}
 
Example 10
Source File: MetadataBuildItemResolverTests.java    From initializr with Apache License 2.0 5 votes vote down vote up
@Test
void resoleBomWithMatchingEntry() {
	InitializrMetadata metadata = new InitializrMetadata();
	BillOfMaterials bom = BillOfMaterials.create("com.example", "bom", "2.0.0");
	metadata.getConfiguration().getEnv().getBoms().put("test-bom", bom);
	metadata.validate();
	MetadataBuildItemResolver resolver = new MetadataBuildItemResolver(metadata, VERSION_2_0_0);
	io.spring.initializr.generator.buildsystem.BillOfMaterials resolvedBom = resolver.resolveBom("test-bom");
	assertThat(resolvedBom.getGroupId()).isEqualTo("com.example");
	assertThat(resolvedBom.getArtifactId()).isEqualTo("bom");
	assertThat(resolvedBom.getVersion()).hasToString("2.0.0");
}
 
Example 11
Source File: MetadataBuildItemResolverTests.java    From initializr with Apache License 2.0 5 votes vote down vote up
@Test
void resoleBomWithNotMatchingEntry() {
	InitializrMetadata metadata = new InitializrMetadata();
	BillOfMaterials bom = BillOfMaterials.create("com.example", "bom", "2.0.0");
	metadata.getConfiguration().getEnv().getBoms().put("test-bom", bom);
	metadata.validate();
	MetadataBuildItemResolver resolver = new MetadataBuildItemResolver(metadata, VERSION_2_0_0);
	assertThat(resolver.resolveBom("does-not-exost")).isNull();
}
 
Example 12
Source File: DependencyRangesInfoContributorTests.java    From initializr with Apache License 2.0 5 votes vote down vote up
@Test
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, null));
	dependency.setBom("bom");
	InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addBom("bom", bom)
			.addDependencyGroup("foo", dependency).build();
	Info info = getInfo(metadata);
	assertThat(info.getDetails()).doesNotContainKeys("dependency-ranges");
}
 
Example 13
Source File: BomRangesInfoContributorTests.java    From initializr with Apache License 2.0 5 votes vote down vote up
@Test
void noMapping() {
	BillOfMaterials bom = BillOfMaterials.create("com.example", "bom", "1.0.0");
	InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addBom("foo", bom).build();
	Info info = getInfo(metadata);
	assertThat(info.getDetails()).doesNotContainKeys("bom-ranges");
}
 
Example 14
Source File: BuildComplianceTests.java    From initializr with Apache License 2.0 5 votes vote down vote up
@ParameterizedTest
@MethodSource("parameters")
void bomWithVersionProperty(BuildSystem build, String fileName) {
	Dependency foo = Dependency.withId("foo", "org.acme", "foo");
	foo.setBom("the-bom");
	BillOfMaterials bom = BillOfMaterials.create("org.acme", "foo-bom", "1.3.3");
	bom.setVersionProperty("foo.version");
	InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addDependencyGroup("foo", foo)
			.addBom("the-bom", bom).build();
	ProjectStructure project = generateProject(java, build, "2.1.1.RELEASE",
			(description) -> description.addDependency("foo", MetadataBuildItemMapper.toDependency(foo)), metadata);
	assertThat(project).textFile(fileName).hasSameContentAs(
			new ClassPathResource("project/" + build + "/bom-property-" + getAssertFileName(fileName)));
}
 
Example 15
Source File: InitializrMetadataTestBuilder.java    From initializr with Apache License 2.0 4 votes vote down vote up
public InitializrMetadataTestBuilder addBom(String id, String groupId, String artifactId, String version) {
	BillOfMaterials bom = BillOfMaterials.create(groupId, artifactId, version);
	return addBom(id, bom);
}