protected ObjectNode mapDependencyGroup(DependencyGroup group) { ObjectNode result = nodeFactory.objectNode(); result.put("name", group.getName()); if ((group instanceof Describable) && ((Describable) group).getDescription() != null) { result.put("description", ((Describable) group).getDescription()); } ArrayNode items = nodeFactory.arrayNode(); group.getContent().forEach((it) -> { JsonNode dependency = mapDependency(it); if (dependency != null) { items.add(dependency); } }); result.set("values", items); return result; }
private static DependencyGroup createDependencyGroup(String groupName, Dependency... dependencies) { DependencyGroup group = DependencyGroup.create(groupName); for (Dependency dependency : dependencies) { group.getContent().add(dependency); } return group; }
@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); }
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); }
public InitializrMetadataTestBuilder addDependencyGroup(String name, Dependency... dependencies) { this.builder.withCustomizer((it) -> { DependencyGroup group = new DependencyGroup(); group.setName(name); group.getContent().addAll(Arrays.asList(dependencies)); it.getDependencies().getContent().add(group); }); return this; }
@Test void addDependencyInCustomizer() { DependencyGroup group = DependencyGroup.create("Extra"); 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(); assertThat(metadata.getDependencies().getContent()).hasSize(1); assertThat(metadata.getDependencies().getContent().get(0)).isEqualTo(group); }
public InitializrMetadataTestBuilder addDependencyGroup(String name, String... ids) { this.builder.withCustomizer((it) -> { DependencyGroup group = new DependencyGroup(); group.setName(name); for (String id : ids) { Dependency dependency = new Dependency(); dependency.setId(id); group.getContent().add(dependency); } it.getDependencies().getContent().add(group); }); return this; }