Java源码示例:io.spring.initializr.metadata.InitializrMetadata

示例1
@ParameterizedTest
@MethodSource("parameters")
void repositories(BuildSystem build, String fileName) {
	Dependency foo = Dependency.withId("foo", "org.acme", "foo");
	foo.setRepository("foo-repository");
	Dependency bar = Dependency.withId("bar", "org.acme", "bar");
	bar.setRepository("bar-repository");
	InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addDependencyGroup("test", foo, bar)
			.addRepository("foo-repository", "foo-repo", "https://example.com/foo", false)
			.addRepository("bar-repository", "bar-repo", "https://example.com/bar", true).build();
	ProjectStructure project = generateProject(java, build, "2.1.1.RELEASE", (description) -> {
		description.addDependency("foo", MetadataBuildItemMapper.toDependency(foo));
		description.addDependency("bar", MetadataBuildItemMapper.toDependency(bar));
	}, metadata);
	assertThat(project).textFile(fileName).hasSameContentAs(
			new ClassPathResource("project/" + build + "/repositories-" + getAssertFileName(fileName)));
}
 
示例2
@Override
public String write(InitializrMetadata metadata, String appUrl) {
	ObjectNode delegate = nodeFactory.objectNode();
	links(delegate, metadata.getTypes().getContent(), appUrl);
	dependencies(delegate, metadata.getDependencies());
	type(delegate, metadata.getTypes());
	singleSelect(delegate, metadata.getPackagings());
	singleSelect(delegate, metadata.getJavaVersions());
	singleSelect(delegate, metadata.getLanguages());
	singleSelect(delegate, metadata.getBootVersions(), this::mapVersionMetadata);
	text(delegate, metadata.getGroupId());
	text(delegate, metadata.getArtifactId());
	text(delegate, metadata.getVersion());
	text(delegate, metadata.getName());
	text(delegate, metadata.getDescription());
	text(delegate, metadata.getPackageName());
	return delegate.toString();
}
 
示例3
@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");
	SaganInitializrMetadataUpdateStrategy provider = new SaganInitializrMetadataUpdateStrategy(this.restTemplate,
			objectMapper);
	expectJson(metadata.getConfiguration().getEnv().getSpringBootMetadataUrl(),
			"metadata/sagan/spring-boot-no-default.json");

	InitializrMetadata updatedMetadata = provider.update(metadata);
	assertThat(updatedMetadata.getBootVersions()).isNotNull();
	List<DefaultMetadataElement> updatedBootVersions = updatedMetadata.getBootVersions().getContent();
	assertThat(updatedBootVersions).hasSize(5);
	assertBootVersion(updatedBootVersions.get(0), "2.5.0 (M1)", true);
	assertBootVersion(updatedBootVersions.get(1), "2.4.1 (SNAPSHOT)", false);
	assertBootVersion(updatedBootVersions.get(2), "2.4.0", false);
	assertBootVersion(updatedBootVersions.get(3), "2.3.8 (SNAPSHOT)", false);
	assertBootVersion(updatedBootVersions.get(4), "2.3.7", false);
}
 
示例4
@ParameterizedTest
@MethodSource("parameters")
void bomWithOrdering(BuildSystem 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();
	ProjectStructure project = generateProject(java, build, "2.1.1.RELEASE",
			(description) -> description.addDependency("foo", MetadataBuildItemMapper.toDependency(foo)), metadata);
	assertThat(project).textFile(fileName).hasSameContentAs(
			new ClassPathResource("project/" + build + "/bom-ordering-" + getAssertFileName(fileName)));
}
 
示例5
private DependencyMetadata testRepoFromBomAccordingToVersion(String bootVersion) {
	Dependency first = Dependency.withId("first", "org.foo", "first");
	first.setRepository("repo-foo");
	Dependency second = Dependency.withId("second", "org.foo", "second");
	Dependency third = Dependency.withId("third", "org.foo", "third");
	third.setBom("bom-foo");

	BillOfMaterials bom = BillOfMaterials.create("org.foo", "bom");
	bom.getMappings().add(BillOfMaterials.Mapping.create("[1.0.0.RELEASE, 1.1.0.RELEASE)", "2.0.0.RELEASE",
			"repo-foo", "repo-bar"));
	bom.getMappings().add(BillOfMaterials.Mapping.create("1.1.0.RELEASE", "3.0.0.RELEASE", "repo-biz"));
	InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addBom("bom-foo", bom)
			.addRepository("repo-foo", "foo", "http://localhost", false)
			.addRepository("repo-bar", "bar", "http://localhost", false)
			.addRepository("repo-biz", "biz", "http://localhost", false)
			.addDependencyGroup("test", first, second, third).build();
	return this.provider.get(metadata, Version.parse(bootVersion));
}
 
示例6
@Test
void dependencyWithMappingAndNoOpenRange() {
	Dependency dependency = Dependency.withId("foo", null, null, "0.3.0.RELEASE");
	dependency.getMappings().add(
			Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null, "0.1.0.RELEASE", null, null));
	dependency.getMappings().add(
			Dependency.Mapping.create("[1.2.0.RELEASE, 1.3.0.RELEASE)", null, null, "0.2.0.RELEASE", null, null));
	InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
			.addDependencyGroup("test", dependency).build();
	Info info = getInfo(metadata);
	assertDependencyId(info, "foo");
	Map<String, Object> foo = getDependencyRangeInfo(info, "foo");
	assertThat(foo).containsExactly(entry("0.1.0.RELEASE", "Spring Boot >=1.1.0.RELEASE and <1.2.0.RELEASE"),
			entry("0.2.0.RELEASE", "Spring Boot >=1.2.0.RELEASE and <1.3.0.RELEASE"),
			entry("managed", "Spring Boot >=1.3.0.RELEASE"));
}
 
示例7
@Test
void withMappings() {
	BillOfMaterials bom = BillOfMaterials.create("com.example", "bom", "1.0.0");
	bom.getMappings().add(BillOfMaterials.Mapping.create("[1.3.0.RELEASE,1.3.8.RELEASE]", "1.1.0"));
	bom.getMappings().add(BillOfMaterials.Mapping.create("1.3.8.BUILD-SNAPSHOT", "1.1.1-SNAPSHOT"));
	InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addBom("foo", bom).build();
	Info info = getInfo(metadata);
	assertThat(info.getDetails()).containsKeys("bom-ranges");
	@SuppressWarnings("unchecked")
	Map<String, Object> ranges = (Map<String, Object>) info.getDetails().get("bom-ranges");
	assertThat(ranges).containsOnlyKeys("foo");
	@SuppressWarnings("unchecked")
	Map<String, Object> foo = (Map<String, Object>) ranges.get("foo");
	assertThat(foo).containsExactly(entry("1.1.0", "Spring Boot >=1.3.0.RELEASE and <=1.3.8.RELEASE"),
			entry("1.1.1-SNAPSHOT", "Spring Boot >=1.3.8.BUILD-SNAPSHOT"));
}
 
示例8
/**
 * Validate the specified {@link ProjectRequest request} and initialize the specified
 * {@link ProjectDescription description}. Override any attribute of the description
 * that are managed by this instance.
 * @param request the request to validate
 * @param description the description to initialize
 * @param metadata the metadata instance to use to apply defaults if necessary
 */
public void convert(ProjectRequest request, MutableProjectDescription description, InitializrMetadata metadata) {
	validate(request, metadata);
	Version platformVersion = getPlatformVersion(request, metadata);
	List<Dependency> resolvedDependencies = getResolvedDependencies(request, platformVersion, metadata);
	validateDependencyRange(platformVersion, resolvedDependencies);

	description.setApplicationName(request.getApplicationName());
	description.setArtifactId(request.getArtifactId());
	description.setBaseDirectory(request.getBaseDir());
	description.setBuildSystem(getBuildSystem(request, metadata));
	description.setDescription(request.getDescription());
	description.setGroupId(request.getGroupId());
	description.setLanguage(Language.forId(request.getLanguage(), request.getJavaVersion()));
	description.setName(request.getName());
	description.setPackageName(request.getPackageName());
	description.setPackaging(Packaging.forId(request.getPackaging()));
	description.setPlatformVersion(platformVersion);
	description.setVersion(request.getVersion());
	resolvedDependencies.forEach((dependency) -> description.addDependency(dependency.getId(),
			MetadataBuildItemMapper.toDependency(dependency)));
}
 
示例9
@Test
void generateSpringBootCliCapabilities() throws IOException {
	InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addDependencyGroup("test",
			createDependency("id-b", "depB"), createDependency("id-a", "depA", "and some description")).build();
	String content = this.generator.generateSpringBootCliCapabilities(metadata, "https://fake-service");
	assertThat(content).contains("| Id");
	assertThat(content).contains("| Tags");
	assertThat(content).contains("id-a | and some description |");
	assertThat(content).contains("id-b | depB");
	assertThat(content).contains("https://fake-service");
	assertThat(content).doesNotContain("Examples:");
	assertThat(content).doesNotContain("curl");
	assertThat(content).doesNotContain("| Rel");
	assertThat(content).doesNotContain("| dependencies");
	assertThat(content).doesNotContain("| applicationName");
	assertThat(content).doesNotContain("| baseDir");
}
 
示例10
@ParameterizedTest
@MethodSource("parameters")
void annotationProcessorDependency(BuildSystem build, String fileName) {
	Dependency annotationProcessor = Dependency.withId("configuration-processor", "org.springframework.boot",
			"spring-boot-configuration-processor");
	Dependency dataJpa = Dependency.withId("data-jpa", "org.springframework.boot", "spring-boot-starter-data-jpa");
	annotationProcessor.setScope(Dependency.SCOPE_ANNOTATION_PROCESSOR);
	InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
			.addDependencyGroup("core", "web", "data-jpa")
			.addDependencyGroup("configuration-processor", annotationProcessor).build();
	ProjectStructure project = generateProject(java, build, "2.1.1.RELEASE", (description) -> {
		description.addDependency("configuration-processor",
				MetadataBuildItemMapper.toDependency(annotationProcessor));
		description.addDependency("web", MetadataBuildItemMapper.toDependency(WEB));
		description.addDependency("data-jpa", MetadataBuildItemMapper.toDependency(dataJpa));
	}, metadata);
	assertThat(project).textFile(fileName).hasSameContentAs(new ClassPathResource(
			"project/" + build + "/annotation-processor-dependency-" + getAssertFileName(fileName)));
}
 
示例11
protected String generateTypeTable(InitializrMetadata metadata, String linkHeader, boolean addTags) {
	String[][] typeTable = new String[metadata.getTypes().getContent().size() + 1][];
	if (addTags) {
		typeTable[0] = new String[] { linkHeader, "Description", "Tags" };
	}
	else {
		typeTable[0] = new String[] { linkHeader, "Description" };
	}
	int i = 1;
	for (Type type : metadata.getTypes().getContent().stream().sorted(Comparator.comparing(MetadataElement::getId))
			.collect(Collectors.toList())) {
		String[] data = new String[typeTable[0].length];
		data[0] = (type.isDefault() ? type.getId() + " *" : type.getId());
		data[1] = (type.getDescription() != null) ? type.getDescription() : type.getName();
		if (addTags) {
			data[2] = buildTagRepresentation(type);
		}
		typeTable[i++] = data;
	}
	return TableGenerator.generate(typeTable, this.maxColumnWidth);
}
 
示例12
@Test
void addBomAndRemoveDuplicates() {
	Dependency first = Dependency.withId("first", "org.foo", "first");
	first.setBom("bom-foo");
	Dependency second = Dependency.withId("second", "org.foo", "second");
	Dependency third = Dependency.withId("third", "org.foo", "third");
	third.setBom("bom-foo");

	BillOfMaterials bom = BillOfMaterials.create("org.foo", "bom");
	bom.getMappings().add(BillOfMaterials.Mapping.create("[1.0.0.RELEASE, 1.1.8.RELEASE)", "1.0.0.RELEASE"));
	bom.getMappings().add(BillOfMaterials.Mapping.create("1.1.8.RELEASE", "2.0.0.RELEASE"));
	InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addBom("bom-foo", bom)
			.addDependencyGroup("test", first, second, third).build();
	DependencyMetadata dependencyMetadata = this.provider.get(metadata, Version.parse("1.1.5.RELEASE"));
	assertThat(dependencyMetadata.getDependencies()).hasSize(3);
	assertThat(dependencyMetadata.getRepositories()).isEmpty();
	assertThat(dependencyMetadata.getBoms()).hasSize(1);
	assertThat(dependencyMetadata.getBoms().get("bom-foo").getGroupId()).isEqualTo("org.foo");
	assertThat(dependencyMetadata.getBoms().get("bom-foo").getArtifactId()).isEqualTo("bom");
	assertThat(dependencyMetadata.getBoms().get("bom-foo").getVersion()).isEqualTo("1.0.0.RELEASE");
}
 
示例13
@BeforeEach
void setup(@TempDir Path directory) {
	this.projectTester = new ProjectAssetTester().withIndentingWriterFactory()
			.withConfiguration(SourceCodeProjectGenerationConfiguration.class,
					KotlinProjectGenerationConfiguration.class, BuildProjectGenerationConfiguration.class,
					MavenProjectGenerationConfiguration.class)
			.withDirectory(directory).withBean(InitializrMetadata.class, () -> {
				io.spring.initializr.metadata.Dependency dependency = io.spring.initializr.metadata.Dependency
						.withId("foo");
				dependency.setFacets(Collections.singletonList("json"));
				return InitializrMetadataTestBuilder.withDefaults().addDependencyGroup("test", dependency).build();
			}).withDescriptionCustomizer((description) -> {
				description.setLanguage(new KotlinLanguage());
				if (description.getPlatformVersion() == null) {
					description.setPlatformVersion(Version.parse("2.1.0.RELEASE"));
				}
				description.setBuildSystem(new MavenBuildSystem());
			});
}
 
示例14
@Bean
KotlinVersionResolver kotlinVersionResolver(DependencyManagementVersionResolver versionResolver,
		InitializrMetadata metadata) {
	return new ManagedDependenciesKotlinVersionResolver(versionResolver,
			(description) -> new InitializrMetadataKotlinVersionResolver(metadata)
					.resolveKotlinVersion(description));
}
 
示例15
@Test
void convertShouldSetBuildSystemFromRequestTypeAndBuildTag() {
	Type type = new Type();
	type.setId("example-type");
	type.getTags().put("build", "gradle");
	InitializrMetadata testMetadata = InitializrMetadataTestBuilder.withDefaults().addType(type).build();
	ProjectRequest request = createProjectRequest();
	request.setType("example-type");
	ProjectDescription description = this.converter.convert(request, testMetadata);
	assertThat(description.getBuildSystem()).isInstanceOf(GradleBuildSystem.class);
}
 
示例16
@Override
public InitializrMetadata update(InitializrMetadata current) {
	String url = current.getConfiguration().getEnv().getSpringBootMetadataUrl();
	List<DefaultMetadataElement> bootVersions = fetchSpringBootVersions(url);
	if (bootVersions != null && !bootVersions.isEmpty()) {
		if (bootVersions.stream().noneMatch(DefaultMetadataElement::isDefault)) {
			// No default specified
			bootVersions.get(0).setDefault(true);
		}
		current.updateSpringBootVersions(bootVersions);
	}
	return current;
}
 
示例17
@Test
void strategyIsInvokedOnGet() {
	InitializrMetadata metadata = mock(InitializrMetadata.class);
	InitializrMetadata updatedMetadata = mock(InitializrMetadata.class);
	InitializrMetadataUpdateStrategy updateStrategy = mock(InitializrMetadataUpdateStrategy.class);
	given(updateStrategy.update(metadata)).willReturn(updatedMetadata);
	DefaultInitializrMetadataProvider provider = new DefaultInitializrMetadataProvider(metadata, updateStrategy);
	assertThat(provider.get()).isEqualTo(updatedMetadata);
	verify(updateStrategy).update(metadata);
}
 
示例18
@Test
void linksRendered() {
	Dependency dependency = Dependency.withId("foo", "com.example", "foo");
	dependency.getLinks().add(Link.create("guide", "https://example.com/how-to"));
	dependency.getLinks().add(Link.create("reference", "https://example.com/doc"));
	InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
			.addDependencyGroup("test", dependency).build();
	String json = this.jsonMapper.write(metadata, null);
	int first = json.indexOf("https://example.com/how-to");
	int second = json.indexOf("https://example.com/doc");
	// JSON objects are not ordered
	assertThat(first).isGreaterThan(0);
	assertThat(second).isGreaterThan(0);
}
 
示例19
private void validatePackaging(String packaging, InitializrMetadata metadata) {
	if (packaging != null) {
		DefaultMetadataElement packagingFromMetadata = metadata.getPackagings().get(packaging);
		if (packagingFromMetadata == null) {
			throw new InvalidProjectRequestException(
					"Unknown packaging '" + packaging + "' check project metadata");
		}
	}
}
 
示例20
@Test
void resolveWithUnknownArtifactId() {
	BillOfMaterials bom = BillOfMaterials.create("org.springframework.cloud", "spring-cloud-dependencies", "1.0.0");
	InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addBom("spring-cloud", bom).build();
	given(this.versionResolver.resolve("org.springframework.cloud", "spring-cloud-dependencies", "1.0.0"))
			.willReturn(Collections.singletonMap("org.springframework.cloud:spring-cloud", "1.1.0"));
	String version = new SpringCloudProjectVersionResolver(metadata, this.versionResolver)
			.resolveVersion(VersionParser.DEFAULT.parse("2.1.0.RELEASE"), "org.springframework.cloud:test");
	assertThat(version).isNull();
}
 
示例21
@Test
void configurationCanBeSerialized() throws URISyntaxException {
	RequestEntity<Void> request = RequestEntity.get(new URI("/metadata/config")).accept(MediaType.APPLICATION_JSON)
			.build();
	ResponseEntity<String> response = this.restTemplate.exchange(request, String.class);
	assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
	InitializrMetadata actual = InitializrMetadataBuilder.create()
			.withInitializrMetadata(new ByteArrayResource(response.getBody().getBytes())).build();
	assertThat(actual).isNotNull();
	InitializrMetadata expected = this.metadataProvider.get();
	assertThat(actual.getDependencies().getAll().size()).isEqualTo(expected.getDependencies().getAll().size());
	assertThat(actual.getConfiguration().getEnv().getBoms().size())
			.isEqualTo(expected.getConfiguration().getEnv().getBoms().size());
}
 
示例22
private void validateType(String type, InitializrMetadata metadata) {
	if (type != null) {
		Type typeFromMetadata = metadata.getTypes().get(type);
		if (typeFromMetadata == null) {
			throw new InvalidProjectRequestException("Unknown type '" + type + "' check project metadata");
		}
		if (!typeFromMetadata.getTags().containsKey("build")) {
			throw new InvalidProjectRequestException(
					"Invalid type '" + type + "' (missing build tag) check project metadata");
		}
	}
}
 
示例23
@Test
void resoleBomWithNotMatchingEntry() {
	InitializrMetadata metadata = new InitializrMetadata();
	BillOfMaterials bom = BillOfMaterials.create("com.example", "bom", "2.0.0");
	metadata.getConfiguration().getEnv().getBoms().put("test-bom", bom);
	metadata.validate();
	MetadataBuildItemResolver resolver = new MetadataBuildItemResolver(metadata, VERSION_2_0_0);
	assertThat(resolver.resolveBom("does-not-exost")).isNull();
}
 
示例24
@Test
void platformVersionUsingSemVerUseBackwardCompatibleFormat() throws JsonProcessingException {
	InitializrMetadata metadata = new InitializrMetadataTestBuilder().addBootVersion("2.5.0-SNAPSHOT", false)
			.addBootVersion("2.5.0-M2", false).addBootVersion("2.4.2", true).build();
	String json = this.jsonMapper.write(metadata, null);
	JsonNode result = objectMapper.readTree(json);
	JsonNode versions = result.get("bootVersion").get("values");
	assertThat(versions).hasSize(3);
	assertVersionMetadata(versions.get(0), "2.5.0.BUILD-SNAPSHOT", "2.5.0-SNAPSHOT");
	assertVersionMetadata(versions.get(1), "2.5.0.M2", "2.5.0-M2");
	assertVersionMetadata(versions.get(2), "2.4.2.RELEASE", "2.4.2");
}
 
示例25
@Test
void withAppUrl() throws IOException {
	InitializrMetadata metadata = new InitializrMetadataTestBuilder()
			.addType("foo", true, "/foo.zip", "none", "test").addDependencyGroup("foo", "one", "two").build();
	String json = this.jsonMapper.write(metadata, "http://server:8080/my-app");
	JsonNode result = objectMapper.readTree(json);
	assertThat(get(result, "_links.foo.href"))
			.isEqualTo("http://server:8080/my-app/foo.zip?type=foo{&dependencies,packaging,javaVersion,"
					+ "language,bootVersion,groupId,artifactId,version,name,description,packageName}");
}
 
示例26
@Test
void generateCurlCapabilities() throws IOException {
	InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addDependencyGroup("test",
			createDependency("id-b", "depB"), createDependency("id-a", "depA", "and some description")).build();
	String content = this.generator.generateCurlCapabilities(metadata, "https://fake-service");
	assertCommandLineCapabilities(content);
	assertThat(content).contains("id-a | and some description |");
	assertThat(content).contains("id-b | depB");
	assertThat(content).contains("https://fake-service");
	assertThat(content).contains("Examples:");
	assertThat(content).contains("curl https://fake-service");
}
 
示例27
@Test
void generateCapabilitiesWithCompatibilityRange() throws IOException {
	Dependency first = Dependency.withId("first");
	first.setDescription("first desc");
	first.setCompatibilityRange("1.2.0.RELEASE");
	Dependency second = Dependency.withId("second");
	second.setDescription("second desc");
	second.setCompatibilityRange(" [1.2.0.RELEASE,1.3.0.M1)  ");
	InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
			.addDependencyGroup("test", first, second).build();
	String content = this.generator.generateSpringBootCliCapabilities(metadata, "https://fake-service");
	assertThat(content).contains("| first  | first desc  | >=1.2.0.RELEASE               |");
	assertThat(content).contains("| second | second desc | >=1.2.0.RELEASE and <1.3.0.M1 |");
}
 
示例28
@Test
void dependencyNoMappingSimpleRange() {
	Dependency dependency = Dependency.withId("foo", "com.example", "foo", "1.2.3.RELEASE");
	dependency.setCompatibilityRange("[1.1.0.RELEASE, 1.5.0.RELEASE)");
	InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addDependencyGroup("foo", dependency)
			.build();
	Info info = getInfo(metadata);
	assertThat(info.getDetails()).containsKeys("dependency-ranges");
	@SuppressWarnings("unchecked")
	Map<String, Object> ranges = (Map<String, Object>) info.getDetails().get("dependency-ranges");
	assertThat(ranges).containsOnlyKeys("foo");
	@SuppressWarnings("unchecked")
	Map<String, Object> foo = (Map<String, Object>) ranges.get("foo");
	assertThat(foo).containsExactly(entry("1.2.3.RELEASE", "Spring Boot >=1.1.0.RELEASE and <1.5.0.RELEASE"));
}
 
示例29
@Test
void dependencyWithMappingAndOpenRange() {
	Dependency dependency = Dependency.withId("foo", null, null, "0.3.0.RELEASE");
	dependency.getMappings().add(
			Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null, "0.1.0.RELEASE", null, null));
	dependency.getMappings()
			.add(Dependency.Mapping.create("1.2.0.RELEASE", null, null, "0.2.0.RELEASE", null, null));
	InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
			.addDependencyGroup("test", dependency).build();
	Info info = getInfo(metadata);
	assertDependencyId(info, "foo");
	Map<String, Object> foo = getDependencyRangeInfo(info, "foo");
	assertThat(foo).containsExactly(entry("0.1.0.RELEASE", "Spring Boot >=1.1.0.RELEASE and <1.2.0.RELEASE"),
			entry("0.2.0.RELEASE", "Spring Boot >=1.2.0.RELEASE"));
}
 
示例30
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, this.maxColumnWidth);
}