private static void assertDefaultConfig(InitializrMetadata metadata) { assertThat(metadata).isNotNull(); assertThat(metadata.getDependencies().getAll()).hasSize(8); assertThat(metadata.getDependencies().getContent()).hasSize(2); assertThat(metadata.getTypes().getContent()).hasSize(4); }
@Test void addDefaultBom() { Dependency first = Dependency.withId("first"); Dependency second = Dependency.withId("second"); second.setBom("da-bom"); DependencyGroup group = createDependencyGroup("test", first, second); group.setBom("test-bom"); DependenciesCapability capability = new DependenciesCapability(); capability.getContent().add(group); capability.validate(); assertThat(capability.get("first").getBom()).isEqualTo("test-bom"); assertThat(capability.get("second").getBom()).isEqualTo("da-bom"); }
@Test void mergeAddEntry() { DependenciesCapability capability = createDependenciesCapability("foo", Dependency.withId("first"), Dependency.withId("second")); DependenciesCapability anotherCapability = createDependenciesCapability("foo", Dependency.withId("bar"), Dependency.withId("biz")); anotherCapability.getContent() .add(createDependencyGroup("bar", Dependency.withId("third"))); capability.merge(anotherCapability); assertThat(capability.getContent()).hasSize(2); assertThat(capability.get("first")).isNotNull(); assertThat(capability.get("second")).isNotNull(); assertThat(capability.get("third")).isNotNull(); }
protected void dependencies(ObjectNode parent, DependenciesCapability capability) { ObjectNode dependencies = nodeFactory.objectNode(); dependencies.put("type", capability.getType().getName()); ArrayNode values = nodeFactory.arrayNode(); values.addAll(capability.getContent().stream().map(this::mapDependencyGroup) .collect(Collectors.toList())); dependencies.set("values", values); parent.set(capability.getId(), dependencies); }
private static DependenciesCapability createDependenciesCapability(String groupName, Dependency... dependencies) { DependenciesCapability capability = new DependenciesCapability(); DependencyGroup group = createDependencyGroup(groupName, dependencies); capability.getContent().add(group); return capability; }
@Override public void contribute(Info.Builder builder) { Map<String, Object> details = new LinkedHashMap<>(); this.metadataProvider.get().getDependencies().getAll().forEach((dependency) -> { if (dependency.getBom() == null) { contribute(details, dependency); } }); if (!details.isEmpty()) { builder.withDetail("dependency-ranges", details); } }
@GetMapping(path = "/ui/dependencies", produces = "application/json") public ResponseEntity<String> dependencies( @RequestParam(required = false) String version) { List<DependencyGroup> dependencyGroups = this.metadataProvider.get() .getDependencies().getContent(); List<DependencyItem> content = new ArrayList<>(); Version requestedVersion = (StringUtils.isEmpty(version) ? null : Version.parse(version)); dependencyGroups.forEach((group) -> group.getContent().forEach((dependency) -> { if (requestedVersion != null && dependency.getVersionRange() != null) { if (dependency.match(requestedVersion)) { content.add(new DependencyItem(group.getName(), dependency)); } } else { content.add(new DependencyItem(group.getName(), dependency)); } })); String json = writeDependencies(content); return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON) .eTag(createUniqueId(json)).body(json); }
@Test void addDependencyWithAliases() { Dependency dependency = Dependency.withId("first"); dependency.getAliases().add("alias1"); dependency.getAliases().add("alias2"); DependenciesCapability capability = createDependenciesCapability("foo", dependency); capability.validate(); assertThat(capability.get("first")).isSameAs(dependency); assertThat(capability.get("alias1")).isSameAs(dependency); assertThat(capability.get("alias2")).isSameAs(dependency); }
private Dependency determineWebDependency(InitializrMetadata metadata) { Dependency web = metadata.getDependencies().get("web"); if (web != null) { return web; } return Dependency.withId("web").asSpringBootStarter("web"); }
@Test void mergeMetadata() { InitializrMetadata metadata = InitializrMetadataBuilder.create() .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"); assertThat(dependency).isNotNull(); assertThat(dependency.getGroupId()).isEqualTo("org.springframework.boot"); assertThat(metadata.getTypes().getContent()).hasSize(1); assertThat(metadata.getBootVersions().getContent()).hasSize(2); assertThat(metadata.getPackagings().getContent()).hasSize(2); assertThat(metadata.getJavaVersions().getContent()).hasSize(1); assertThat(metadata.getLanguages().getContent()).hasSize(3); assertThat(metadata.getName().getContent()).isEqualTo("metadata-merge"); assertThat(metadata.getDescription().getContent()) .isEqualTo("Demo project for metadata merge"); assertThat(metadata.getGroupId().getContent()).isEqualTo("org.acme"); assertThat(metadata.getArtifactId().getContent()).isEqualTo("metadata"); assertThat(metadata.getVersion().getContent()).isEqualTo("1.0.0-SNAPSHOT"); assertThat(metadata.getPackageName().getContent()).isEqualTo("org.acme.demo"); }
/** * Merge this instance with the specified argument. * @param other the other instance */ public void merge(InitializrMetadata other) { this.configuration.merge(other.configuration); this.dependencies.merge(other.dependencies); this.types.merge(other.types); this.bootVersions.merge(other.bootVersions); this.packagings.merge(other.packagings); this.javaVersions.merge(other.javaVersions); this.languages.merge(other.languages); this.name.merge(other.name); this.description.merge(other.description); this.groupId.merge(other.groupId); this.artifactId.merge(other.artifactId); this.version.merge(other.version); this.packageName.merge(other.packageName); }
protected String generateDependencyTable(InitializrMetadata metadata) { String[][] dependencyTable = new String[metadata.getDependencies().getAll().size() + 1][]; dependencyTable[0] = new String[] { "Id", "Description", "Required version" }; int i = 1; for (Dependency dep : metadata.getDependencies().getAll().stream() .sorted(Comparator.comparing(MetadataElement::getId)) .collect(Collectors.toList())) { String[] data = new String[3]; data[0] = dep.getId(); data[1] = (dep.getDescription() != null) ? dep.getDescription() : dep.getName(); data[2] = dep.getVersionRequirement(); dependencyTable[i++] = data; } return TableGenerator.generate(dependencyTable); }
private void addTestDependencyGroup(InitializrMetadata metadata, Dependency... dependencies) { DependencyGroup group = DependencyGroup.create("test"); for (Dependency dependency : dependencies) { group.getContent().add(dependency); } metadata.getDependencies().getContent().add(group); }
@Test void indexedDependencies() { Dependency dependency = Dependency.withId("first"); Dependency dependency2 = Dependency.withId("second"); DependenciesCapability capability = createDependenciesCapability("foo", dependency, dependency2); capability.validate(); assertThat(capability.get("first")).isSameAs(dependency); assertThat(capability.get("second")).isSameAs(dependency2); assertThat(capability.get("anotherId")).isNull(); }
dependencies.addAll(request.getDependencies()); List<String> validDependencies = dependencies.stream() .filter((id) -> metadata.getDependencies().get(id) != null) .collect(Collectors.toList()); document.setDependencies(new DependencyInformation(validDependencies));
@Test void aliasClashWithAnotherDependency() { Dependency dependency = Dependency.withId("first"); dependency.getAliases().add("alias1"); dependency.getAliases().add("alias2"); Dependency dependency2 = Dependency.withId("alias2"); DependenciesCapability capability = new DependenciesCapability(); capability.getContent().add(createDependencyGroup("foo", dependency)); capability.getContent().add(createDependencyGroup("bar", dependency2)); assertThatIllegalArgumentException().isThrownBy(capability::validate) .withMessageContaining("alias2"); }
@Override public void customize(InitializrMetadata metadata) { metadata.getDependencies().merge(this.properties.getDependencies()); metadata.getTypes().merge(this.properties.getTypes()); metadata.getBootVersions().merge(this.properties.getBootVersions()); metadata.getPackagings().merge(this.properties.getPackagings()); metadata.getJavaVersions().merge(this.properties.getJavaVersions()); metadata.getLanguages().merge(this.properties.getLanguages()); this.properties.getGroupId().apply(metadata.getGroupId()); this.properties.getArtifactId().apply(metadata.getArtifactId()); this.properties.getVersion().apply(metadata.getVersion()); this.properties.getName().apply(metadata.getName()); this.properties.getDescription().apply(metadata.getDescription()); this.properties.getPackageName().apply(metadata.getPackageName()); }
@Test void addDefaultVersionRange() { Dependency first = Dependency.withId("first"); Dependency second = Dependency.withId("second"); second.setVersionRange("1.2.3.RELEASE"); DependencyGroup group = createDependencyGroup("test", first, second); group.setVersionRange("1.2.0.RELEASE"); DependenciesCapability capability = new DependenciesCapability(); capability.getContent().add(group); capability.validate(); assertThat(capability.get("first").getVersionRange()).isEqualTo("1.2.0.RELEASE"); assertThat(capability.get("second").getVersionRange()).isEqualTo("1.2.3.RELEASE"); }
public DependencyMetadata get(InitializrMetadata metadata, Version bootVersion) { Map<String, Dependency> dependencies = new LinkedHashMap<>(); for (Dependency dependency : metadata.getDependencies().getAll()) { if (dependency.match(bootVersion)) { dependencies.put(dependency.getId(), dependency.resolve(bootVersion));