/** * Resolve this instance according to the specified Spring Boot {@link Version}. * Return a {@link BillOfMaterials} instance that holds the version, repositories and * additional BOMs to use, if any. * @param bootVersion the Spring Boot version * @return the bill of materials */ public BillOfMaterials resolve(Version bootVersion) { if (this.mappings.isEmpty()) { return this; } for (Mapping mapping : this.mappings) { if (mapping.range.match(bootVersion)) { BillOfMaterials resolvedBom = new BillOfMaterials( (mapping.groupId != null) ? mapping.groupId : this.groupId, (mapping.artifactId != null) ? mapping.artifactId : this.artifactId, mapping.version); resolvedBom.setVersionProperty(this.versionProperty); resolvedBom.setOrder(this.order); resolvedBom.repositories.addAll(!mapping.repositories.isEmpty() ? mapping.repositories : this.repositories); resolvedBom.additionalBoms.addAll(!mapping.additionalBoms.isEmpty() ? mapping.additionalBoms : this.additionalBoms); return resolvedBom; } } throw new IllegalStateException("No suitable mapping was found for " + this + " and version " + bootVersion); }
/** * Create a {@link BillOfMaterials} for the spring boot BOM. * @param bootVersion the Spring Boot version * @param versionProperty the property that contains the version * @return a new {@link BillOfMaterials} instance */ public BillOfMaterials createSpringBootBom(String bootVersion, String versionProperty) { BillOfMaterials bom = BillOfMaterials.create("org.springframework.boot", "spring-boot-dependencies", bootVersion); bom.setVersionProperty(VersionProperty.of(versionProperty)); bom.setOrder(100); return bom; }
@ParameterizedTest @MethodSource("parameters") public void bomWithOrdering(String 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(); applyMetadata(metadata); ProjectRequest request = createProjectRequestForType(build, "foo"); ProjectAssert project = generateProject(request); project.sourceCodeAssert(fileName).equalsTo(new ClassPathResource( "project/" + build + "/bom-ordering-" + getAssertFileName(fileName))); }