/** * Return the element with the specified id or {@code null} if no such element exists. * @param id the ID of the element to find * @return the element or {@code null} */ public DefaultMetadataElement get(String id) { return this.content.stream().filter((it) -> id.equals(it.getId())).findFirst() .orElse(null); }
private static String defaultId( Defaultable<? extends DefaultMetadataElement> element) { DefaultMetadataElement defaultValue = element.getDefault(); return (defaultValue != null) ? defaultValue.getId() : null; }
@Override public void merge(List<DefaultMetadataElement> otherContent) { otherContent.forEach((it) -> { if (get(it.getId()) == null) { this.content.add(it); } }); }
protected void singleSelect(ObjectNode parent, SingleSelectCapability capability) { ObjectNode single = nodeFactory.objectNode(); single.put("type", capability.getType().getName()); DefaultMetadataElement defaultType = capability.getDefault(); if (defaultType != null) { single.put("default", defaultType.getId()); } ArrayNode values = nodeFactory.arrayNode(); values.addAll(capability.getContent().stream().map(this::mapValue) .collect(Collectors.toList())); single.set("values", values); parent.set(capability.getId(), single); }
/** * Update the available Spring Boot versions with the specified capabilities. * @param versionsMetadata the Spring Boot boot versions metadata to use */ public void updateSpringBootVersions(List<DefaultMetadataElement> versionsMetadata) { this.bootVersions.getContent().clear(); this.bootVersions.getContent().addAll(versionsMetadata); List<Version> bootVersions = this.bootVersions.getContent().stream() .map((it) -> Version.parse(it.getId())).collect(Collectors.toList()); VersionParser parser = new VersionParser(bootVersions); this.dependencies.updateVersionRange(parser); this.configuration.getEnv().getBoms().values() .forEach((it) -> it.updateVersionRange(parser)); this.configuration.getEnv().getKotlin().updateVersionRange(parser); }
private ResponseEntity<String> dependenciesFor(InitializrMetadataVersion version, String bootVersion) { InitializrMetadata metadata = this.metadataProvider.get(); Version v = (bootVersion != null) ? Version.parse(bootVersion) : Version.parse(metadata.getBootVersions().getDefault().getId()); DependencyMetadata dependencyMetadata = this.dependencyMetadataProvider .get(metadata, v); String content = new DependencyMetadataV21JsonMapper().write(dependencyMetadata); return ResponseEntity.ok().contentType(version.getMediaType()) .eTag(createUniqueId(content)) .cacheControl(CacheControl.maxAge(7, TimeUnit.DAYS)).body(content); }
@Test void initializeSetsMetadataDefaults() { ProjectRequest request = initProjectRequest(); assertThat(request.getName()).isEqualTo(this.metadata.getName().getContent()); assertThat(request.getType()) .isEqualTo(this.metadata.getTypes().getDefault().getId()); assertThat(request.getDescription()) .isEqualTo(this.metadata.getDescription().getContent()); assertThat(request.getGroupId()) .isEqualTo(this.metadata.getGroupId().getContent()); assertThat(request.getArtifactId()) .isEqualTo(this.metadata.getArtifactId().getContent()); assertThat(request.getVersion()) .isEqualTo(this.metadata.getVersion().getContent()); assertThat(request.getBootVersion()) .isEqualTo(this.metadata.getBootVersions().getDefault().getId()); assertThat(request.getPackaging()) .isEqualTo(this.metadata.getPackagings().getDefault().getId()); }
@Test void readAvailableVersions() throws IOException { this.server.expect(requestTo("https://spring.io/project_metadata/spring-boot")) .andRespond(withSuccess( new ClassPathResource("metadata/sagan/spring-boot.json"), MediaType.APPLICATION_JSON)); List<DefaultMetadataElement> versions = new SpringBootMetadataReader( this.objectMapper, this.restTemplate, this.metadata.getConfiguration().getEnv().getSpringBootMetadataUrl()) .getBootVersions(); assertThat(versions).as("spring boot versions should not be null").isNotNull(); AtomicBoolean defaultFound = new AtomicBoolean(false); versions.forEach((it) -> { assertThat(it.getId()).as("Id must be set").isNotNull(); assertThat(it.getName()).as("Name must be set").isNotNull(); if (it.isDefault()) { if (defaultFound.get()) { fail("One default version was already found " + it.getId()); } defaultFound.set(true); } }); this.server.verify(); }
@Test void defaultBootVersionIsAlwaysSet() { InitializrMetadata metadata = new InitializrMetadataTestBuilder() .addBootVersion("0.0.9.RELEASE", true) .addBootVersion("0.0.8.RELEASE", false).build(); assertThat(metadata.getBootVersions().getDefault().getId()) .isEqualTo("0.0.9.RELEASE"); DefaultInitializrMetadataProvider provider = new DefaultInitializrMetadataProvider( metadata, objectMapper, this.restTemplate); expectJson(metadata.getConfiguration().getEnv().getSpringBootMetadataUrl(), "metadata/sagan/spring-boot-no-default.json"); InitializrMetadata updatedMetadata = provider.get(); assertThat(updatedMetadata.getBootVersions()).isNotNull(); List<DefaultMetadataElement> updatedBootVersions = updatedMetadata .getBootVersions().getContent(); assertThat(updatedBootVersions).hasSize(4); assertBootVersion(updatedBootVersions.get(0), "1.3.1 (SNAPSHOT)", true); assertBootVersion(updatedBootVersions.get(1), "1.3.0", false); assertBootVersion(updatedBootVersions.get(2), "1.2.6 (SNAPSHOT)", false); assertBootVersion(updatedBootVersions.get(3), "1.2.5", false); }
@Test void bootVersionsAreReplaced() { InitializrMetadata metadata = new InitializrMetadataTestBuilder() .addBootVersion("0.0.9.RELEASE", true) .addBootVersion("0.0.8.RELEASE", false).build(); assertThat(metadata.getBootVersions().getDefault().getId()) .isEqualTo("0.0.9.RELEASE"); DefaultInitializrMetadataProvider provider = new DefaultInitializrMetadataProvider( metadata, objectMapper, this.restTemplate); expectJson(metadata.getConfiguration().getEnv().getSpringBootMetadataUrl(), "metadata/sagan/spring-boot.json"); InitializrMetadata updatedMetadata = provider.get(); assertThat(updatedMetadata.getBootVersions()).isNotNull(); List<DefaultMetadataElement> updatedBootVersions = updatedMetadata .getBootVersions().getContent(); assertThat(updatedBootVersions).hasSize(4); assertBootVersion(updatedBootVersions.get(0), "1.4.1 (SNAPSHOT)", false); assertBootVersion(updatedBootVersions.get(1), "1.4.0", true); assertBootVersion(updatedBootVersions.get(2), "1.3.8 (SNAPSHOT)", false); assertBootVersion(updatedBootVersions.get(3), "1.3.7", false); }
List<String> depIds = (!getStyle().isEmpty() ? getStyle() : getDependencies()); String actualBootVersion = (getBootVersion() != null) ? getBootVersion() : metadata.getBootVersions().getDefault().getId(); Version requestedVersion = Version.parse(actualBootVersion); this.resolvedDependencies = depIds.stream().map((it) -> {