Use Java 17 constructs

This commit is contained in:
Stephane Nicoll 2022-11-08 16:35:59 +09:00
parent d88285934c
commit ec48337dac
20 changed files with 76 additions and 117 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2020 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -87,9 +87,8 @@ public class ProjectRequestDocumentFactory {
} }
// Let's make sure that the document is flagged as invalid no matter what // Let's make sure that the document is flagged as invalid no matter what
if (event instanceof ProjectFailedEvent) { if (event instanceof ProjectFailedEvent failed) {
ErrorStateInformation errorState = document.triggerError(); ErrorStateInformation errorState = document.triggerError();
ProjectFailedEvent failed = (ProjectFailedEvent) event;
if (failed.getCause() != null) { if (failed.getCause() != null) {
errorState.setMessage(failed.getCause().getMessage()); errorState.setMessage(failed.getCause().getMessage());
} }
@ -112,8 +111,7 @@ public class ProjectRequestDocumentFactory {
} }
private ClientInformation determineClientInformation(ProjectRequest request) { private ClientInformation determineClientInformation(ProjectRequest request) {
if (request instanceof WebProjectRequest) { if (request instanceof WebProjectRequest webProjectRequest) {
WebProjectRequest webProjectRequest = (WebProjectRequest) request;
Agent agent = determineAgent(webProjectRequest); Agent agent = determineAgent(webProjectRequest);
String ip = determineIp(webProjectRequest); String ip = determineIp(webProjectRequest);
String country = determineCountry(webProjectRequest); String country = determineCountry(webProjectRequest);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -173,7 +173,7 @@ public class GradleProjectGenerationConfiguration {
@Bean @Bean
@ConditionalOnPlatformVersion("2.2.0.M3") @ConditionalOnPlatformVersion("2.2.0.M3")
BuildCustomizer<GradleBuild> testTaskContributor() { BuildCustomizer<GradleBuild> testTaskContributor() {
return new BuildCustomizer<GradleBuild>() { return new BuildCustomizer<>() {
@Override @Override
public void customize(GradleBuild build) { public void customize(GradleBuild build) {
build.tasks().customize("test", (test) -> test.invoke("useJUnitPlatform")); build.tasks().customize("test", (test) -> test.invoke("useJUnitPlatform"));
@ -216,7 +216,7 @@ public class GradleProjectGenerationConfiguration {
@Bean @Bean
@ConditionalOnPlatformVersion("2.2.0.M3") @ConditionalOnPlatformVersion("2.2.0.M3")
BuildCustomizer<GradleBuild> testTaskContributor() { BuildCustomizer<GradleBuild> testTaskContributor() {
return new BuildCustomizer<GradleBuild>() { return new BuildCustomizer<>() {
@Override @Override
public void customize(GradleBuild build) { public void customize(GradleBuild build) {
build.tasks().customizeWithType("Test", (test) -> test.invoke("useJUnitPlatform")); build.tasks().customizeWithType("Test", (test) -> test.invoke("useJUnitPlatform"));

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -354,9 +354,8 @@ public class MavenBuildAssert extends AbstractTextAssert<MavenBuildAssert> {
} }
private static Dependency toDependency(Node item) { private static Dependency toDependency(Node item) {
if (item instanceof Element) { if (item instanceof Element element) {
Dependency dependency = new Dependency(); Dependency dependency = new Dependency();
Element element = (Element) item;
NodeList groupId = element.getElementsByTagName("groupId"); NodeList groupId = element.getElementsByTagName("groupId");
if (groupId.getLength() > 0) { if (groupId.getLength() > 0) {
dependency.setGroupId(groupId.item(0).getTextContent()); dependency.setGroupId(groupId.item(0).getTextContent());
@ -383,8 +382,7 @@ public class MavenBuildAssert extends AbstractTextAssert<MavenBuildAssert> {
} }
private static BillOfMaterials toBom(Node item) { private static BillOfMaterials toBom(Node item) {
if (item instanceof Element) { if (item instanceof Element element) {
Element element = (Element) item;
NodeList type = element.getElementsByTagName("type"); NodeList type = element.getElementsByTagName("type");
NodeList scope = element.getElementsByTagName("scope"); NodeList scope = element.getElementsByTagName("scope");
if (isBom(type, scope)) { if (isBom(type, scope)) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -132,7 +132,7 @@ public abstract class AbstractProjectAssert<SELF extends AbstractProjectAssert<S
private List<String> getRelativePathsOfProjectFiles() { private List<String> getRelativePathsOfProjectFiles() {
List<String> relativePaths = new ArrayList<>(); List<String> relativePaths = new ArrayList<>();
try { try {
Files.walkFileTree(this.actual, new SimpleFileVisitor<Path>() { Files.walkFileTree(this.actual, new SimpleFileVisitor<>() {
@Override @Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
relativePaths.add(createRelativePath(file)); relativePaths.add(createRelativePath(file));

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2020 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -75,7 +75,7 @@ public abstract class GradleBuildWriter {
} }
private void writeImports(IndentingWriter writer, GradleTaskContainer tasks) { private void writeImports(IndentingWriter writer, GradleTaskContainer tasks) {
List<String> imports = tasks.importedTypes().sorted().collect(Collectors.toList()); List<String> imports = tasks.importedTypes().sorted().toList();
imports.forEach((importedType) -> writer.println("import " + importedType)); imports.forEach((importedType) -> writer.println("import " + importedType));
if (!imports.isEmpty()) { if (!imports.isEmpty()) {
writer.println(); writer.println();
@ -163,24 +163,15 @@ public abstract class GradleBuildWriter {
if (type == null) { if (type == null) {
return "implementation"; return "implementation";
} }
switch (type) { return switch (type) {
case ANNOTATION_PROCESSOR: case ANNOTATION_PROCESSOR -> "annotationProcessor";
return "annotationProcessor"; case COMPILE -> "implementation";
case COMPILE: case COMPILE_ONLY -> "compileOnly";
return "implementation"; case PROVIDED_RUNTIME -> "providedRuntime";
case COMPILE_ONLY: case RUNTIME -> "runtimeOnly";
return "compileOnly"; case TEST_COMPILE -> "testImplementation";
case PROVIDED_RUNTIME: case TEST_RUNTIME -> "testRuntimeOnly";
return "providedRuntime"; };
case RUNTIME:
return "runtimeOnly";
case TEST_COMPILE:
return "testImplementation";
case TEST_RUNTIME:
return "testRuntimeOnly";
default:
throw new IllegalStateException("Unrecognized dependency type '" + type + "'");
}
} }
private void writeBoms(IndentingWriter writer, GradleBuild build) { private void writeBoms(IndentingWriter writer, GradleBuild build) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2020 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -125,7 +125,7 @@ public class KotlinDslGradleBuildWriter extends GradleBuildWriter {
protected void writeConfigurations(IndentingWriter writer, GradleConfigurationContainer configurations) { protected void writeConfigurations(IndentingWriter writer, GradleConfigurationContainer configurations) {
configurations.names() configurations.names()
.forEach((configuration) -> writer.println("val " + configuration + " by configurations.creating")); .forEach((configuration) -> writer.println("val " + configuration + " by configurations.creating"));
if (!configurations.customizations().findFirst().isPresent()) { if (configurations.customizations().findFirst().isEmpty()) {
return; return;
} }
writer.println("configurations {"); writer.println("configurations {");

View File

@ -263,24 +263,15 @@ public class MavenBuildWriter {
if (type == null) { if (type == null) {
return null; return null;
} }
switch (type) { return switch (type) {
case ANNOTATION_PROCESSOR: case ANNOTATION_PROCESSOR -> null;
return null; case COMPILE -> null;
case COMPILE: case COMPILE_ONLY -> null;
return null; case PROVIDED_RUNTIME -> "provided";
case COMPILE_ONLY: case RUNTIME -> "runtime";
return null; case TEST_COMPILE -> "test";
case PROVIDED_RUNTIME: case TEST_RUNTIME -> "test";
return "provided"; };
case RUNTIME:
return "runtime";
case TEST_COMPILE:
return "test";
case TEST_RUNTIME:
return "test";
default:
throw new IllegalStateException("Unrecognized dependency type '" + type + "'");
}
} }
private boolean isOptional(Dependency dependency) { private boolean isOptional(Dependency dependency) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2020 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -315,11 +315,10 @@ public class MavenPlugin {
this.settings.add(nestedSetting); this.settings.add(nestedSetting);
return nestedSetting; return nestedSetting;
}).getValue(); }).getValue();
if (!(value instanceof ConfigurationBuilder)) { if (!(value instanceof ConfigurationBuilder nestedConfiguration)) {
throw new IllegalArgumentException(String.format( throw new IllegalArgumentException(String.format(
"Could not customize parameter '%s', a single value %s is already registered", name, value)); "Could not customize parameter '%s', a single value %s is already registered", name, value));
} }
ConfigurationBuilder nestedConfiguration = (ConfigurationBuilder) value;
consumer.accept(nestedConfiguration); consumer.accept(nestedConfiguration);
return this; return this;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -43,11 +43,7 @@ public class SimpleIndentStrategy implements Function<Integer, String> {
if (level < 0) { if (level < 0) {
throw new IllegalArgumentException("Indent level must not be negative, got" + level); throw new IllegalArgumentException("Indent level must not be negative, got" + level);
} }
StringBuilder indentBuilder = new StringBuilder(); return String.valueOf(this.indent).repeat(level);
for (int i = 0; i < level; i++) {
indentBuilder.append(this.indent);
}
return indentBuilder.toString();
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -285,7 +285,7 @@ public class GroovySourceCodeWriter implements SourceCodeWriter<GroovySourceCode
} }
if (Enum.class.isAssignableFrom(attribute.getType())) { if (Enum.class.isAssignableFrom(attribute.getType())) {
imports.addAll(attribute.getValues().stream().map((value) -> value.substring(0, value.lastIndexOf("."))) imports.addAll(attribute.getValues().stream().map((value) -> value.substring(0, value.lastIndexOf(".")))
.collect(Collectors.toList())); .toList());
} }
}); });
return imports; return imports;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -288,7 +288,7 @@ public class JavaSourceCodeWriter implements SourceCodeWriter<JavaSourceCode> {
} }
if (Enum.class.isAssignableFrom(attribute.getType())) { if (Enum.class.isAssignableFrom(attribute.getType())) {
imports.addAll(attribute.getValues().stream().map((value) -> value.substring(0, value.lastIndexOf("."))) imports.addAll(attribute.getValues().stream().map((value) -> value.substring(0, value.lastIndexOf(".")))
.collect(Collectors.toList())); .toList());
} }
}); });
return imports; return imports;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -333,7 +333,7 @@ public class KotlinSourceCodeWriter implements SourceCodeWriter<KotlinSourceCode
} }
if (Enum.class.isAssignableFrom(attribute.getType())) { if (Enum.class.isAssignableFrom(attribute.getType())) {
imports.addAll(attribute.getValues().stream().map((value) -> value.substring(0, value.lastIndexOf("."))) imports.addAll(attribute.getValues().stream().map((value) -> value.substring(0, value.lastIndexOf(".")))
.collect(Collectors.toList())); .toList());
} }
}); });
return imports; return imports;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,7 +20,6 @@ import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import io.spring.initializr.generator.project.contributor.ProjectContributor; import io.spring.initializr.generator.project.contributor.ProjectContributor;
@ -58,7 +57,7 @@ public class DefaultProjectAssetGenerator implements ProjectAssetGenerator<Path>
Path projectRoot = resolveProjectDirectoryFactory(context).createProjectDirectory(description); Path projectRoot = resolveProjectDirectoryFactory(context).createProjectDirectory(description);
Path projectDirectory = initializerProjectDirectory(projectRoot, description); Path projectDirectory = initializerProjectDirectory(projectRoot, description);
List<ProjectContributor> contributors = context.getBeanProvider(ProjectContributor.class).orderedStream() List<ProjectContributor> contributors = context.getBeanProvider(ProjectContributor.class).orderedStream()
.collect(Collectors.toList()); .toList();
for (ProjectContributor contributor : contributors) { for (ProjectContributor contributor : contributors) {
contributor.contribute(projectDirectory); contributor.contribute(projectDirectory);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -140,8 +140,7 @@ public class ProjectGenerator {
private Supplier<ProjectDescription> resolve(ProjectDescription description, ProjectGenerationContext context) { private Supplier<ProjectDescription> resolve(ProjectDescription description, ProjectGenerationContext context) {
return () -> { return () -> {
if (description instanceof MutableProjectDescription) { if (description instanceof MutableProjectDescription mutableDescription) {
MutableProjectDescription mutableDescription = (MutableProjectDescription) description;
ProjectDescriptionDiffFactory diffFactory = context.getBeanProvider(ProjectDescriptionDiffFactory.class) ProjectDescriptionDiffFactory diffFactory = context.getBeanProvider(ProjectDescriptionDiffFactory.class)
.getIfAvailable(DefaultProjectDescriptionDiffFactory::new); .getIfAvailable(DefaultProjectDescriptionDiffFactory::new);
// Create the diff here so that it takes a copy of the description // Create the diff here so that it takes a copy of the description

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2020 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,7 +20,6 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors;
import io.spring.initializr.generator.version.Version.Qualifier; import io.spring.initializr.generator.version.Version.Qualifier;
@ -50,7 +49,7 @@ public class VersionParser {
private static final Pattern VERSION_REGEX = Pattern private static final Pattern VERSION_REGEX = Pattern
.compile("^(\\d+)\\.(\\d+|x)\\.(\\d+|x)(?:([.|-])([^0-9]+)(\\d+)?)?$"); .compile("^(\\d+)\\.(\\d+|x)\\.(\\d+|x)(?:([.|-])([^0-9]+)(\\d+)?)?$");
private static final Pattern RANGE_REGEX = Pattern.compile("(\\(|\\[)(.*),(.*)(\\)|\\])"); private static final Pattern RANGE_REGEX = Pattern.compile("([(\\[])(.*),(.*)([)\\]])");
private final List<Version> latestVersions; private final List<Version> latestVersions;
@ -153,7 +152,7 @@ public class VersionParser {
return false; return false;
} }
return true; return true;
}).collect(Collectors.toList()); }).toList();
return (matches.size() != 1) ? null : matches.get(0); return (matches.size() != 1) ? null : matches.get(0);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -77,7 +77,7 @@ public final class VersionProperty implements Serializable, Comparable<VersionPr
* @return the property in camel case format * @return the property in camel case format
*/ */
public String toCamelCaseFormat() { public String toCamelCaseFormat() {
String[] tokens = this.property.split("\\-|\\."); String[] tokens = this.property.split("[-.]");
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (int i = 0; i < tokens.length; i++) { for (int i = 0; i < tokens.length; i++) {
String part = tokens[i]; String part = tokens[i];

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2020 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,8 +17,6 @@
package io.spring.initializr.metadata; package io.spring.initializr.metadata;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.StringTokenizer; import java.util.StringTokenizer;
@ -74,8 +72,8 @@ public class Dependency extends MetadataElement implements Describable {
/** /**
* All scope types. * All scope types.
*/ */
public static final List<String> SCOPE_ALL = Collections.unmodifiableList(Arrays.asList(SCOPE_COMPILE, public static final List<String> SCOPE_ALL = List.of(SCOPE_COMPILE, SCOPE_RUNTIME, SCOPE_COMPILE_ONLY,
SCOPE_RUNTIME, SCOPE_COMPILE_ONLY, SCOPE_ANNOTATION_PROCESSOR, SCOPE_PROVIDED, SCOPE_TEST)); SCOPE_ANNOTATION_PROCESSOR, SCOPE_PROVIDED, SCOPE_TEST);
private List<String> aliases = new ArrayList<>(); private List<String> aliases = new ArrayList<>();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2020 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -85,13 +85,11 @@ public class SingleSelectCapability extends ServiceCapability<List<DefaultMetada
@Override @Override
public void merge(List<DefaultMetadataElement> otherContent) { public void merge(List<DefaultMetadataElement> otherContent) {
withWritableContent((content) -> { withWritableContent((content) -> otherContent.forEach((it) -> {
otherContent.forEach((it) -> { if (get(it.getId()) == null) {
if (get(it.getId()) == null) { this.content.add(it);
this.content.add(it); }
} }));
});
});
} }
private <T> T withReadableContent(Function<List<DefaultMetadataElement>, T> consumer) { private <T> T withReadableContent(Function<List<DefaultMetadataElement>, T> consumer) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -51,21 +51,15 @@ public final class MetadataBuildItemMapper {
} }
private static DependencyScope toDependencyScope(String scope) { private static DependencyScope toDependencyScope(String scope) {
switch (scope) { return switch (scope) {
case Dependency.SCOPE_ANNOTATION_PROCESSOR: case Dependency.SCOPE_ANNOTATION_PROCESSOR -> DependencyScope.ANNOTATION_PROCESSOR;
return DependencyScope.ANNOTATION_PROCESSOR; case Dependency.SCOPE_COMPILE -> DependencyScope.COMPILE;
case Dependency.SCOPE_COMPILE: case Dependency.SCOPE_RUNTIME -> DependencyScope.RUNTIME;
return DependencyScope.COMPILE; case Dependency.SCOPE_COMPILE_ONLY -> DependencyScope.COMPILE_ONLY;
case Dependency.SCOPE_RUNTIME: case Dependency.SCOPE_PROVIDED -> DependencyScope.PROVIDED_RUNTIME;
return DependencyScope.RUNTIME; case Dependency.SCOPE_TEST -> DependencyScope.TEST_COMPILE;
case Dependency.SCOPE_COMPILE_ONLY: default -> null;
return DependencyScope.COMPILE_ONLY; };
case Dependency.SCOPE_PROVIDED:
return DependencyScope.PROVIDED_RUNTIME;
case Dependency.SCOPE_TEST:
return DependencyScope.TEST_COMPILE;
}
return null;
} }
/** /**

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2020 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -24,7 +24,6 @@ import java.util.LinkedHashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
import io.spring.initializr.generator.io.template.TemplateRenderer; import io.spring.initializr.generator.io.template.TemplateRenderer;
import io.spring.initializr.metadata.Dependency; import io.spring.initializr.metadata.Dependency;
@ -135,7 +134,7 @@ public class CommandLineHelpGenerator {
String[][] parameterTable = new String[defaults.size() + 1][]; String[][] parameterTable = new String[defaults.size() + 1][];
parameterTable[0] = new String[] { "Parameter", "Description", "Default value" }; parameterTable[0] = new String[] { "Parameter", "Description", "Default value" };
int i = 1; int i = 1;
for (String id : defaults.keySet().stream().sorted().collect(Collectors.toList())) { for (String id : defaults.keySet().stream().sorted().toList()) {
String[] data = new String[3]; String[] data = new String[3];
data[0] = id; data[0] = id;
data[1] = (String) parametersDescription.get(id); data[1] = (String) parametersDescription.get(id);
@ -159,7 +158,7 @@ public class CommandLineHelpGenerator {
String[][] parameterTable = new String[defaults.size() + 1][]; String[][] parameterTable = new String[defaults.size() + 1][];
parameterTable[0] = new String[] { "Id", "Description", "Default value" }; parameterTable[0] = new String[] { "Id", "Description", "Default value" };
int i = 1; int i = 1;
for (String id : defaults.keySet().stream().sorted().collect(Collectors.toList())) { for (String id : defaults.keySet().stream().sorted().toList()) {
String[] data = new String[3]; String[] data = new String[3];
data[0] = id; data[0] = id;
data[1] = (String) parametersDescription.get(id); data[1] = (String) parametersDescription.get(id);
@ -175,7 +174,7 @@ public class CommandLineHelpGenerator {
dependencyTable[0] = new String[] { "Id", "Description", "Required version" }; dependencyTable[0] = new String[] { "Id", "Description", "Required version" };
int i = 1; int i = 1;
for (Dependency dep : metadata.getDependencies().getAll().stream() for (Dependency dep : metadata.getDependencies().getAll().stream()
.sorted(Comparator.comparing(MetadataElement::getId)).collect(Collectors.toList())) { .sorted(Comparator.comparing(MetadataElement::getId)).toList()) {
String[] data = new String[3]; String[] data = new String[3];
data[0] = dep.getId(); data[0] = dep.getId();
data[1] = (dep.getDescription() != null) ? dep.getDescription() : dep.getName(); data[1] = (dep.getDescription() != null) ? dep.getDescription() : dep.getName();
@ -195,7 +194,7 @@ public class CommandLineHelpGenerator {
} }
int i = 1; int i = 1;
for (Type type : metadata.getTypes().getContent().stream().sorted(Comparator.comparing(MetadataElement::getId)) for (Type type : metadata.getTypes().getContent().stream().sorted(Comparator.comparing(MetadataElement::getId))
.collect(Collectors.toList())) { .toList()) {
String[] data = new String[typeTable[0].length]; String[] data = new String[typeTable[0].length];
data[0] = (type.isDefault() ? type.getId() + " *" : type.getId()); data[0] = (type.isDefault() ? type.getId() + " *" : type.getId());
data[1] = (type.getDescription() != null) ? type.getDescription() : type.getName(); data[1] = (type.getDescription() != null) ? type.getDescription() : type.getName();