/** * Create a new {@link DependencyGroup} instance with the given name. * @param name the name of the group * @return a new {@link DependencyGroup} instance */ public static DependencyGroup create(String name) { DependencyGroup group = new DependencyGroup(); group.setName(name); return group; }
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; }
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; }
private void index() { this.indexedDependencies.clear(); this.content.forEach((group) -> group.content.forEach((dependency) -> { // Apply defaults if (dependency.getVersionRange() == null && group.getVersionRange() != null) { dependency.setVersionRange(group.getVersionRange()); } if (dependency.getBom() == null && group.getBom() != null) { dependency.setBom(group.getBom()); } if (dependency.getRepository() == null && group.getRepository() != null) { dependency.setRepository(group.getRepository()); } dependency.resolve(); indexDependency(dependency.getId(), dependency); for (String alias : dependency.getAliases()) { indexDependency(alias, dependency); } })); }
@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 addDefaultRepository() { Dependency first = Dependency.withId("first"); Dependency second = Dependency.withId("second"); second.setRepository("da-repo"); DependencyGroup group = createDependencyGroup("test", first, second); group.setRepository("test-repo"); DependenciesCapability capability = new DependenciesCapability(); capability.getContent().add(group); capability.validate(); assertThat(capability.get("first").getRepository()).isEqualTo("test-repo"); assertThat(capability.get("second").getRepository()).isEqualTo("da-repo"); }
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; }
@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); }
@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); }