mirror of
https://gitee.com/dcren/initializr.git
synced 2025-12-20 03:49:58 +08:00
Use Java 17 constructs
This commit is contained in:
@@ -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");
|
||||
* 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) {
|
||||
List<String> imports = tasks.importedTypes().sorted().collect(Collectors.toList());
|
||||
List<String> imports = tasks.importedTypes().sorted().toList();
|
||||
imports.forEach((importedType) -> writer.println("import " + importedType));
|
||||
if (!imports.isEmpty()) {
|
||||
writer.println();
|
||||
@@ -163,24 +163,15 @@ public abstract class GradleBuildWriter {
|
||||
if (type == null) {
|
||||
return "implementation";
|
||||
}
|
||||
switch (type) {
|
||||
case ANNOTATION_PROCESSOR:
|
||||
return "annotationProcessor";
|
||||
case COMPILE:
|
||||
return "implementation";
|
||||
case COMPILE_ONLY:
|
||||
return "compileOnly";
|
||||
case PROVIDED_RUNTIME:
|
||||
return "providedRuntime";
|
||||
case RUNTIME:
|
||||
return "runtimeOnly";
|
||||
case TEST_COMPILE:
|
||||
return "testImplementation";
|
||||
case TEST_RUNTIME:
|
||||
return "testRuntimeOnly";
|
||||
default:
|
||||
throw new IllegalStateException("Unrecognized dependency type '" + type + "'");
|
||||
}
|
||||
return switch (type) {
|
||||
case ANNOTATION_PROCESSOR -> "annotationProcessor";
|
||||
case COMPILE -> "implementation";
|
||||
case COMPILE_ONLY -> "compileOnly";
|
||||
case PROVIDED_RUNTIME -> "providedRuntime";
|
||||
case RUNTIME -> "runtimeOnly";
|
||||
case TEST_COMPILE -> "testImplementation";
|
||||
case TEST_RUNTIME -> "testRuntimeOnly";
|
||||
};
|
||||
}
|
||||
|
||||
private void writeBoms(IndentingWriter writer, GradleBuild build) {
|
||||
|
||||
@@ -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");
|
||||
* 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) {
|
||||
configurations.names()
|
||||
.forEach((configuration) -> writer.println("val " + configuration + " by configurations.creating"));
|
||||
if (!configurations.customizations().findFirst().isPresent()) {
|
||||
if (configurations.customizations().findFirst().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
writer.println("configurations {");
|
||||
|
||||
@@ -263,24 +263,15 @@ public class MavenBuildWriter {
|
||||
if (type == null) {
|
||||
return null;
|
||||
}
|
||||
switch (type) {
|
||||
case ANNOTATION_PROCESSOR:
|
||||
return null;
|
||||
case COMPILE:
|
||||
return null;
|
||||
case COMPILE_ONLY:
|
||||
return null;
|
||||
case PROVIDED_RUNTIME:
|
||||
return "provided";
|
||||
case RUNTIME:
|
||||
return "runtime";
|
||||
case TEST_COMPILE:
|
||||
return "test";
|
||||
case TEST_RUNTIME:
|
||||
return "test";
|
||||
default:
|
||||
throw new IllegalStateException("Unrecognized dependency type '" + type + "'");
|
||||
}
|
||||
return switch (type) {
|
||||
case ANNOTATION_PROCESSOR -> null;
|
||||
case COMPILE -> null;
|
||||
case COMPILE_ONLY -> null;
|
||||
case PROVIDED_RUNTIME -> "provided";
|
||||
case RUNTIME -> "runtime";
|
||||
case TEST_COMPILE -> "test";
|
||||
case TEST_RUNTIME -> "test";
|
||||
};
|
||||
}
|
||||
|
||||
private boolean isOptional(Dependency dependency) {
|
||||
|
||||
@@ -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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -315,11 +315,10 @@ public class MavenPlugin {
|
||||
this.settings.add(nestedSetting);
|
||||
return nestedSetting;
|
||||
}).getValue();
|
||||
if (!(value instanceof ConfigurationBuilder)) {
|
||||
if (!(value instanceof ConfigurationBuilder nestedConfiguration)) {
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"Could not customize parameter '%s', a single value %s is already registered", name, value));
|
||||
}
|
||||
ConfigurationBuilder nestedConfiguration = (ConfigurationBuilder) value;
|
||||
consumer.accept(nestedConfiguration);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
* 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) {
|
||||
throw new IllegalArgumentException("Indent level must not be negative, got" + level);
|
||||
}
|
||||
StringBuilder indentBuilder = new StringBuilder();
|
||||
for (int i = 0; i < level; i++) {
|
||||
indentBuilder.append(this.indent);
|
||||
}
|
||||
return indentBuilder.toString();
|
||||
return String.valueOf(this.indent).repeat(level);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
* 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())) {
|
||||
imports.addAll(attribute.getValues().stream().map((value) -> value.substring(0, value.lastIndexOf(".")))
|
||||
.collect(Collectors.toList()));
|
||||
.toList());
|
||||
}
|
||||
});
|
||||
return imports;
|
||||
|
||||
@@ -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");
|
||||
* 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())) {
|
||||
imports.addAll(attribute.getValues().stream().map((value) -> value.substring(0, value.lastIndexOf(".")))
|
||||
.collect(Collectors.toList()));
|
||||
.toList());
|
||||
}
|
||||
});
|
||||
return imports;
|
||||
|
||||
@@ -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");
|
||||
* 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())) {
|
||||
imports.addAll(attribute.getValues().stream().map((value) -> value.substring(0, value.lastIndexOf(".")))
|
||||
.collect(Collectors.toList()));
|
||||
.toList());
|
||||
}
|
||||
});
|
||||
return imports;
|
||||
|
||||
@@ -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");
|
||||
* 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.Path;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
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 projectDirectory = initializerProjectDirectory(projectRoot, description);
|
||||
List<ProjectContributor> contributors = context.getBeanProvider(ProjectContributor.class).orderedStream()
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
for (ProjectContributor contributor : contributors) {
|
||||
contributor.contribute(projectDirectory);
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
* 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) {
|
||||
return () -> {
|
||||
if (description instanceof MutableProjectDescription) {
|
||||
MutableProjectDescription mutableDescription = (MutableProjectDescription) description;
|
||||
if (description instanceof MutableProjectDescription mutableDescription) {
|
||||
ProjectDescriptionDiffFactory diffFactory = context.getBeanProvider(ProjectDescriptionDiffFactory.class)
|
||||
.getIfAvailable(DefaultProjectDescriptionDiffFactory::new);
|
||||
// Create the diff here so that it takes a copy of the description
|
||||
|
||||
@@ -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");
|
||||
* 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.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import io.spring.initializr.generator.version.Version.Qualifier;
|
||||
|
||||
@@ -50,7 +49,7 @@ public class VersionParser {
|
||||
private static final Pattern VERSION_REGEX = Pattern
|
||||
.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;
|
||||
|
||||
@@ -153,7 +152,7 @@ public class VersionParser {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}).collect(Collectors.toList());
|
||||
}).toList();
|
||||
return (matches.size() != 1) ? null : matches.get(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -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");
|
||||
* 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
|
||||
*/
|
||||
public String toCamelCaseFormat() {
|
||||
String[] tokens = this.property.split("\\-|\\.");
|
||||
String[] tokens = this.property.split("[-.]");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < tokens.length; i++) {
|
||||
String part = tokens[i];
|
||||
|
||||
Reference in New Issue
Block a user