Fix checkstyle violations

Fix checkstyle violations using a pre-release version of the
spring-javaformat rules.
This commit is contained in:
Phillip Webb
2018-04-11 22:24:03 -07:00
parent eb5211960c
commit 923fb58ffc
69 changed files with 626 additions and 365 deletions

View File

@@ -53,6 +53,9 @@ public class CommandLineHelpGenerator {
/**
* Generate the capabilities of the service as a generic plain text document. Used
* when no particular agent was detected.
* @param metadata the initializr metadata
* @param serviceUrl the service URL
* @return the generic capabilities text document
*/
public String generateGenericCapabilities(InitializrMetadata metadata,
String serviceUrl) {
@@ -63,6 +66,9 @@ public class CommandLineHelpGenerator {
/**
* Generate the capabilities of the service using "curl" as a plain text document.
* @param metadata the initializr metadata
* @param serviceUrl the service URL
* @return the generic capabilities text document
*/
public String generateCurlCapabilities(InitializrMetadata metadata,
String serviceUrl) {
@@ -74,6 +80,9 @@ public class CommandLineHelpGenerator {
/**
* Generate the capabilities of the service using "HTTPie" as a plain text document.
* @param metadata the initializr metadata
* @param serviceUrl the service URL
* @return the generic capabilities text document
*/
public String generateHttpieCapabilities(InitializrMetadata metadata,
String serviceUrl) {
@@ -86,6 +95,9 @@ public class CommandLineHelpGenerator {
/**
* Generate the capabilities of the service using Spring Boot CLI as a plain text
* document.
* @param metadata the initializr metadata
* @param serviceUrl the service URL
* @return the generic capabilities text document
*/
public String generateSpringBootCliCapabilities(InitializrMetadata metadata,
String serviceUrl) {
@@ -216,10 +228,13 @@ public class CommandLineHelpGenerator {
}
return String.join(",",
type.getTags().entrySet().stream()
.map(entry -> entry.getKey() + ":" + entry.getValue())
.map((entry) -> entry.getKey() + ":" + entry.getValue())
.toArray(String[]::new));
}
/**
* Utility to generate a text table.
*/
private static class TableGenerator {
static final String NEW_LINE = System.getProperty("line.separator");
@@ -229,6 +244,8 @@ public class CommandLineHelpGenerator {
* <p>
* The {@code content} is a two-dimensional array holding the rows of the table.
* The first entry holds the header of the table.
* @param content the table content
* @return the generated table
*/
public static String generate(String[][] content) {
StringBuilder sb = new StringBuilder();

View File

@@ -32,6 +32,7 @@ public class ProjectFailedEvent extends ProjectRequestEvent {
/**
* Return the cause of the failure.
* @return the cause of the failure
*/
public Exception getCause() {
return this.cause;

View File

@@ -142,6 +142,8 @@ public class ProjectGenerator {
/**
* Generate a Maven pom for the specified {@link ProjectRequest}.
* @param request the project request
* @return the Maven POM
*/
public byte[] generateMavenPom(ProjectRequest request) {
try {
@@ -162,6 +164,8 @@ public class ProjectGenerator {
/**
* Generate a Gradle build file for the specified {@link ProjectRequest}.
* @param request the project request
* @return the gradle build
*/
public byte[] generateGradleBuild(ProjectRequest request) {
try {
@@ -184,6 +188,8 @@ public class ProjectGenerator {
/**
* Generate a project structure for the specified {@link ProjectRequest}. Returns a
* directory containing the project.
* @param request the project request
* @return the generated project structure
*/
public File generateProjectStructure(ProjectRequest request) {
try {
@@ -201,6 +207,9 @@ public class ProjectGenerator {
/**
* Generate a project structure for the specified {@link ProjectRequest} and resolved
* model.
* @param request the project request
* @param model the source model
* @return the generated project structure
*/
protected File generateProjectStructure(ProjectRequest request,
Map<String, Object> model) {
@@ -268,7 +277,10 @@ public class ProjectGenerator {
/**
* Create a distribution file for the specified project structure directory and
* extension
* extension.
* @param dir the directory
* @param extension the file extension
* @return the distribution file
*/
public File createDistributionFile(File dir, String extension) {
File download = new File(getTemporaryDirectory(), dir.getName() + extension);
@@ -286,6 +298,7 @@ public class ProjectGenerator {
/**
* Clean all the temporary files that are related to this root directory.
* @param dir the directory to clean
* @see #createDistributionFile
*/
public void cleanTempFiles(File dir) {
@@ -313,7 +326,7 @@ public class ProjectGenerator {
}
/**
* Generate a {@code .gitignore} file for the specified {@link ProjectRequest}
* Generate a {@code .gitignore} file for the specified {@link ProjectRequest}.
* @param dir the root directory of the project
* @param request the request to handle
*/
@@ -331,7 +344,7 @@ public class ProjectGenerator {
/**
* Resolve the specified {@link ProjectRequest} and return the model to use to
* generate the project
* generate the project.
* @param originalRequest the request to handle
* @return a model for that request
*/
@@ -399,7 +412,7 @@ public class ProjectGenerator {
request.getBoms().forEach((k, v) -> {
if (v.getVersionProperty() != null) {
request.getBuildProperties().getVersions()
.computeIfAbsent(v.getVersionProperty(), key -> v::getVersion);
.computeIfAbsent(v.getVersionProperty(), (key) -> v::getVersion);
}
});
@@ -470,7 +483,7 @@ public class ProjectGenerator {
private List<Map<String, String>> buildResolvedBoms(ProjectRequest request) {
return request.getBoms().values().stream()
.sorted(Comparator.comparing(BillOfMaterials::getOrder))
.map(bom -> toBomModel(request, bom)).collect(Collectors.toList());
.map((bom) -> toBomModel(request, bom)).collect(Collectors.toList());
}
private Map<String, String> toBomModel(ProjectRequest request, BillOfMaterials bom) {
@@ -684,12 +697,12 @@ public class ProjectGenerator {
}
private void addTempFile(String group, File file) {
this.temporaryFiles.computeIfAbsent(group, key -> new ArrayList<>()).add(file);
this.temporaryFiles.computeIfAbsent(group, (key) -> new ArrayList<>()).add(file);
}
private static List<Dependency> filterDependencies(List<Dependency> dependencies,
String scope) {
return dependencies.stream().filter(dep -> scope.equals(dep.getScope()))
return dependencies.stream().filter((dep) -> scope.equals(dep.getScope()))
.sorted(DependencyComparator.INSTANCE).collect(Collectors.toList());
}
@@ -729,7 +742,7 @@ public class ProjectGenerator {
private boolean finalCarriageReturn;
public Imports(String language) {
Imports(String language) {
this.language = language;
}

View File

@@ -88,6 +88,7 @@ public class ProjectRequest extends BasicProjectRequest {
/**
* Return the additional parameters that can be used to further identify the request.
* @return the parameters
*/
public Map<String, Object> getParameters() {
return this.parameters;
@@ -103,6 +104,7 @@ public class ProjectRequest extends BasicProjectRequest {
/**
* Return the build properties.
* @return the build properties
*/
public BuildProperties getBuildProperties() {
return this.buildProperties;
@@ -111,6 +113,7 @@ public class ProjectRequest extends BasicProjectRequest {
/**
* Initializes this instance with the defaults defined in the specified
* {@link InitializrMetadata}.
* @param metadata the initializr metadata
*/
public void initialize(InitializrMetadata metadata) {
BeanWrapperImpl bean = new BeanWrapperImpl(this);
@@ -126,14 +129,15 @@ public class ProjectRequest extends BasicProjectRequest {
}
/**
* Resolve this instance against the specified {@link InitializrMetadata}
* Resolve this instance against the specified {@link InitializrMetadata}.
* @param metadata the initializr metadata
*/
public void resolve(InitializrMetadata metadata) {
List<String> depIds = !getStyle().isEmpty() ? getStyle() : getDependencies();
String actualBootVersion = getBootVersion() != null ? getBootVersion()
: metadata.getBootVersions().getDefault().getId();
Version requestedVersion = Version.parse(actualBootVersion);
this.resolvedDependencies = depIds.stream().map(it -> {
this.resolvedDependencies = depIds.stream().map((it) -> {
Dependency dependency = metadata.getDependencies().get(it);
if (dependency == null) {
throw new InvalidProjectRequestException(
@@ -141,8 +145,8 @@ public class ProjectRequest extends BasicProjectRequest {
}
return dependency.resolve(requestedVersion);
}).collect(Collectors.toList());
this.resolvedDependencies.forEach(it -> {
it.getFacets().forEach(facet -> {
this.resolvedDependencies.forEach((it) -> {
it.getFacets().forEach((facet) -> {
if (!this.facets.contains(facet)) {
this.facets.add(facet);
}
@@ -157,7 +161,7 @@ public class ProjectRequest extends BasicProjectRequest {
}
if (it.getRepository() != null) {
String repositoryId = it.getRepository();
this.repositories.computeIfAbsent(repositoryId, s -> metadata
this.repositories.computeIfAbsent(repositoryId, (s) -> metadata
.getConfiguration().getEnv().getRepositories().get(s));
}
});
@@ -205,6 +209,8 @@ public class ProjectRequest extends BasicProjectRequest {
/**
* Set the repositories that this instance should use based on the
* {@link InitializrMetadata} and the requested Spring Boot {@link Version}.
* @param metadata the initializr metadata
* @param requestedVersion the requested version
*/
protected void initializeRepositories(InitializrMetadata metadata,
Version requestedVersion) {
@@ -214,9 +220,9 @@ public class ProjectRequest extends BasicProjectRequest {
this.repositories.put("spring-milestones", metadata.getConfiguration()
.getEnv().getRepositories().get("spring-milestones"));
}
this.boms.values().forEach(it -> it.getRepositories().forEach(key -> {
this.boms.values().forEach((it) -> it.getRepositories().forEach((key) -> {
this.repositories.computeIfAbsent(key,
s -> metadata.getConfiguration().getEnv().getRepositories().get(s));
(s) -> metadata.getConfiguration().getEnv().getRepositories().get(s));
}));
}
@@ -252,7 +258,7 @@ public class ProjectRequest extends BasicProjectRequest {
BillOfMaterials bom = metadata.getConfiguration().getEnv().getBoms()
.get(bomId).resolve(requestedVersion);
bom.getAdditionalBoms()
.forEach(id -> resolveBom(metadata, id, requestedVersion));
.forEach((id) -> resolveBom(metadata, id, requestedVersion));
this.boms.put(bomId, bom);
}
}
@@ -260,6 +266,7 @@ public class ProjectRequest extends BasicProjectRequest {
/**
* Update this request once it has been resolved with the specified
* {@link InitializrMetadata}.
* @param metadata the initializr metadata
*/
protected void afterResolution(InitializrMetadata metadata) {
if ("war".equals(getPackaging())) {
@@ -280,7 +287,7 @@ public class ProjectRequest extends BasicProjectRequest {
}
/**
* Add a default dependency if the project does not define any dependency
* Add a default dependency if the project does not define any dependency.
*/
protected void addDefaultDependency() {
Dependency root = new Dependency();
@@ -291,13 +298,16 @@ public class ProjectRequest extends BasicProjectRequest {
/**
* Specify if this request has the web facet enabled.
* @return {@code true} if the project has the web facet
*/
public boolean hasWebFacet() {
return hasFacet("web");
}
/**
* Specify if this request has the specified facet enabled
* Specify if this request has the specified facet enabled.
* @param facet the facet to check
* @return {@code true} if the project has the facet
*/
public boolean hasFacet(String facet) {
return this.facets.contains(facet);

View File

@@ -36,6 +36,7 @@ public abstract class ProjectRequestEvent {
/**
* Return the {@link ProjectRequest} used to generate the project.
* @return the project request
*/
public ProjectRequest getProjectRequest() {
return this.projectRequest;
@@ -43,6 +44,7 @@ public abstract class ProjectRequestEvent {
/**
* Return the timestamp at which the request was processed.
* @return the timestamp that the request was processed
*/
public long getTimestamp() {
return this.timestamp;

View File

@@ -84,6 +84,7 @@ public class BillOfMaterials {
/**
* Return the version of the BOM. Can be {@code null} if it is provided via a mapping.
* @return The version of the BOM or {@code null}
*/
public String getVersion() {
return this.version;
@@ -96,7 +97,8 @@ public class BillOfMaterials {
/**
* Return the {@link VersionProperty} to use to externalize the version of the BOM.
* When this is set, a version property is automatically added rather than setting the
* version in the bom declaration itself.
* version in the BOM declaration itself.
* @return the version property
*/
public VersionProperty getVersionProperty() {
return this.versionProperty;
@@ -113,7 +115,8 @@ public class BillOfMaterials {
/**
* Return the relative order of this BOM where lower values have higher priority. The
* default value is {@code Integer.MAX_VALUE}, indicating lowest priority. The Spring
* Boot dependencies bom has an order of 100.
* Boot dependencies BOM has an order of 100.
* @return the relative order of this BOM
*/
public Integer getOrder() {
return this.order;
@@ -126,6 +129,7 @@ public class BillOfMaterials {
/**
* Return the BOM(s) that should be automatically included if this BOM is required.
* Can be {@code null} if it is provided via a mapping.
* @return the additional BOMs
*/
public List<String> getAdditionalBoms() {
return this.additionalBoms;
@@ -138,6 +142,7 @@ public class BillOfMaterials {
/**
* Return the repositories that are required if this BOM is required. Can be
* {@code null} if it is provided via a mapping.
* @return the repositories
*/
public List<String> getRepositories() {
return this.repositories;
@@ -160,7 +165,7 @@ public class BillOfMaterials {
}
public void updateVersionRange(VersionParser versionParser) {
this.mappings.forEach(it -> {
this.mappings.forEach((it) -> {
try {
it.range = versionParser.parseRange(it.versionRange);
}
@@ -175,6 +180,8 @@ public class BillOfMaterials {
* Resolve this instance according to the specified Spring Boot {@link Version}.
* Return a {@link BillOfMaterials} instance that holds the version, repositories and
* additional BOMs to use, if any.
* @param bootVersion the Spring Boot version
* @return the bill of materials
*/
public BillOfMaterials resolve(Version bootVersion) {
if (this.mappings.isEmpty()) {
@@ -213,6 +220,18 @@ public class BillOfMaterials {
+ "]";
}
public static BillOfMaterials create(String groupId, String artifactId) {
return new BillOfMaterials(groupId, artifactId);
}
public static BillOfMaterials create(String groupId, String artifactId,
String version) {
return new BillOfMaterials(groupId, artifactId, version);
}
/**
* Mapping information.
*/
public static class Mapping {
private String versionRange;
@@ -303,13 +322,4 @@ public class BillOfMaterials {
}
public static BillOfMaterials create(String groupId, String artifactId) {
return new BillOfMaterials(groupId, artifactId);
}
public static BillOfMaterials create(String groupId, String artifactId,
String version) {
return new BillOfMaterials(groupId, artifactId, version);
}
}

View File

@@ -16,8 +16,18 @@
package io.spring.initializr.metadata;
/**
* Metadata with a default value.
*
* @param <T> The value type
* @author Stephane Nicoll
*/
public interface Defaultable<T> {
/**
* Return the default value.
* @return the default value
*/
T getDefault();
}

View File

@@ -52,13 +52,16 @@ public class DependenciesCapability extends ServiceCapability<List<DependencyGro
/**
* Return the {@link Dependency} with the specified id or {@code null} if no such
* dependency exists.
* @param id the ID of the dependency
* @return the dependency or {@code null}
*/
public Dependency get(String id) {
return this.indexedDependencies.get(id);
}
/**
* Return all dependencies as a flat collection
* Return all dependencies as a flat collection.
* @return all dependencies
*/
public Collection<Dependency> getAll() {
return Collections.unmodifiableCollection(this.indexedDependencies.values());
@@ -70,13 +73,13 @@ public class DependenciesCapability extends ServiceCapability<List<DependencyGro
public void updateVersionRange(VersionParser versionParser) {
this.indexedDependencies.values()
.forEach(it -> it.updateVersionRanges(versionParser));
.forEach((it) -> it.updateVersionRanges(versionParser));
}
@Override
public void merge(List<DependencyGroup> otherContent) {
otherContent.forEach(group -> {
if (this.content.stream().noneMatch(it -> group.getName() != null
otherContent.forEach((group) -> {
if (this.content.stream().noneMatch((it) -> group.getName() != null
&& group.getName().equals(it.getName()))) {
this.content.add(group);
}
@@ -86,7 +89,7 @@ public class DependenciesCapability extends ServiceCapability<List<DependencyGro
private void index() {
this.indexedDependencies.clear();
this.content.forEach(group -> group.content.forEach(dependency -> {
this.content.forEach((group) -> group.content.forEach((dependency) -> {
// Apply defaults
if (dependency.getVersionRange() == null && group.getVersionRange() != null) {
dependency.setVersionRange(group.getVersionRange());

View File

@@ -18,6 +18,7 @@ package io.spring.initializr.metadata;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;
@@ -39,18 +40,37 @@ import org.springframework.util.StringUtils;
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class Dependency extends MetadataElement implements Describable {
/**
* Compile Scope.
*/
public static final String SCOPE_COMPILE = "compile";
/**
* Compile Only Scope.
*/
public static final String SCOPE_COMPILE_ONLY = "compileOnly";
/**
* Runtime Scope.
*/
public static final String SCOPE_RUNTIME = "runtime";
/**
* Provided Scope.
*/
public static final String SCOPE_PROVIDED = "provided";
/**
* Test Scope.
*/
public static final String SCOPE_TEST = "test";
public static final List<String> SCOPE_ALL = Arrays.asList(SCOPE_COMPILE,
SCOPE_RUNTIME, SCOPE_COMPILE_ONLY, SCOPE_PROVIDED, SCOPE_TEST);
/**
* All scope types.
*/
public static final List<String> SCOPE_ALL = Collections
.unmodifiableList(Arrays.asList(SCOPE_COMPILE, SCOPE_RUNTIME,
SCOPE_COMPILE_ONLY, SCOPE_PROVIDED, SCOPE_TEST));
private List<String> aliases = new ArrayList<>();
@@ -134,17 +154,19 @@ public class Dependency extends MetadataElement implements Describable {
}
/**
* Specify if the dependency has its coordinates set, i.e. {@code groupId} and
* Returns if the dependency has its coordinates set, i.e. {@code groupId} and
* {@code artifactId}.
* @return if the dependency has coordinates
*/
private boolean hasCoordinates() {
return this.groupId != null && this.artifactId != null;
}
/**
* Define this dependency as a standard spring boot starter with the specified name
* <p>
* Define this dependency as a standard spring boot starter with the specified name.
* If no name is specified, the root "spring-boot-starter" is assumed.
* @param name the starter name or {@code null}
* @return this instance
*/
public Dependency asSpringBootStarter(String name) {
this.groupId = "org.springframework.boot";
@@ -203,7 +225,7 @@ public class Dependency extends MetadataElement implements Describable {
ex);
}
}
this.mappings.forEach(it -> {
this.mappings.forEach((it) -> {
try {
it.range = versionParser.parseRange(it.versionRange);
}
@@ -218,6 +240,8 @@ public class Dependency extends MetadataElement implements Describable {
* Resolve this instance according to the specified Spring Boot {@link Version}.
* Return a {@link Dependency} instance that has its state resolved against the
* specified version.
* @param bootVersion the Spring Boot version
* @return this instance
*/
public Dependency resolve(Version bootVersion) {
for (Mapping mapping : this.mappings) {
@@ -239,6 +263,8 @@ public class Dependency extends MetadataElement implements Describable {
/**
* Specify if this dependency is available for the specified Spring Boot version.
* @param version the version the check
* @return of the version matches
*/
public boolean match(Version version) {
if (this.range != null) {
@@ -248,7 +274,8 @@ public class Dependency extends MetadataElement implements Describable {
}
/**
* Generate an id using the groupId and artifactId
* Generate an id using the groupId and artifactId.
* @return the generated ID
*/
public String generateId() {
if (this.groupId == null || this.artifactId == null) {
@@ -294,6 +321,7 @@ public class Dependency extends MetadataElement implements Describable {
/**
* Return the default version, can be {@code null} to indicate that the version is
* managed by the project and does not need to be specified.
* @return The default version or {@code null}
*/
public String getVersion() {
return this.version;
@@ -306,6 +334,7 @@ public class Dependency extends MetadataElement implements Describable {
/**
* Return the type, can be {@code null} to indicate that the default type should be
* used (i.e. {@code jar}).
* @return the type or {@code null}
*/
public String getType() {
return this.type;
@@ -318,6 +347,7 @@ public class Dependency extends MetadataElement implements Describable {
/**
* Return the dependency mapping if an attribute of the dependency differs according
* to the Spring Boot version. If no mapping matches, default attributes are used.
* @return the dependency mappings
*/
public List<Mapping> getMappings() {
return this.mappings;
@@ -415,6 +445,43 @@ public class Dependency extends MetadataElement implements Describable {
+ this.version + '\'' + '}';
}
public static Dependency create(String groupId, String artifactId, String version,
String scope) {
Dependency dependency = withId(null, groupId, artifactId, version);
dependency.setScope(scope);
return dependency;
}
public static Dependency withId(String id, String groupId, String artifactId,
String version, String scope) {
Dependency dependency = new Dependency();
dependency.setId(id);
dependency.groupId = groupId;
dependency.artifactId = artifactId;
dependency.version = version;
dependency.scope = (scope != null ? scope : SCOPE_COMPILE);
return dependency;
}
public static Dependency withId(String id, String groupId, String artifactId,
String version) {
return withId(id, groupId, artifactId, version, null);
}
public static Dependency withId(String id, String groupId, String artifactId) {
return withId(id, groupId, artifactId, null);
}
public static Dependency withId(String id, String scope) {
Dependency dependency = withId(id, null, null);
dependency.setScope(scope);
return dependency;
}
public static Dependency withId(String id) {
return withId(id, SCOPE_COMPILE);
}
/**
* Map several attribute of the dependency for a given version range.
*/
@@ -491,41 +558,4 @@ public class Dependency extends MetadataElement implements Describable {
}
public static Dependency create(String groupId, String artifactId, String version,
String scope) {
Dependency dependency = withId(null, groupId, artifactId, version);
dependency.setScope(scope);
return dependency;
}
public static Dependency withId(String id, String groupId, String artifactId,
String version, String scope) {
Dependency dependency = new Dependency();
dependency.setId(id);
dependency.groupId = groupId;
dependency.artifactId = artifactId;
dependency.version = version;
dependency.scope = (scope != null ? scope : SCOPE_COMPILE);
return dependency;
}
public static Dependency withId(String id, String groupId, String artifactId,
String version) {
return withId(id, groupId, artifactId, version, null);
}
public static Dependency withId(String id, String groupId, String artifactId) {
return withId(id, groupId, artifactId, null);
}
public static Dependency withId(String id, String scope) {
Dependency dependency = withId(id, null, null);
dependency.setScope(scope);
return dependency;
}
public static Dependency withId(String id) {
return withId(id, SCOPE_COMPILE);
}
}

View File

@@ -43,6 +43,7 @@ public class DependencyGroup {
/**
* Return the name of this group.
* @return the name of the group
*/
public String getName() {
return this.name;
@@ -55,6 +56,7 @@ public class DependencyGroup {
/**
* Return the default version range to apply to all dependencies of this group unless
* specified otherwise.
* @return the version range
*/
public String getVersionRange() {
return this.versionRange;
@@ -67,6 +69,7 @@ public class DependencyGroup {
/**
* Return the default bom to associate to all dependencies of this group unless
* specified otherwise.
* @return the BOM
*/
public String getBom() {
return this.bom;
@@ -79,6 +82,7 @@ public class DependencyGroup {
/**
* Return the default repository to associate to all dependencies of this group unless
* specified otherwise.
* @return the repository
*/
public String getRepository() {
return this.repository;
@@ -90,11 +94,17 @@ public class DependencyGroup {
/**
* Return the {@link Dependency dependencies} of this group.
* @return the content
*/
public List<Dependency> getContent() {
return this.content;
}
/**
* 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);

View File

@@ -27,7 +27,10 @@ public interface DependencyMetadataProvider {
/**
* Return the dependency metadata to use for the specified {@code bootVersion}.
* @param metadata the intializr metadata
* @param bootVersion the Spring Boot version
* @return the dependency metadata
*/
DependencyMetadata get(InitializrMetadata metadata, Version bootVersion);
}
}

View File

@@ -16,8 +16,17 @@
package io.spring.initializr.metadata;
/**
* An item that can describe itself.
*
* @author Stephane Nicoll
*/
public interface Describable {
/**
* Returns the item description.
* @return the description
*/
String getDescription();
}

View File

@@ -62,12 +62,14 @@ public class InitializrConfiguration {
/**
* Generate a suitable application name based on the specified name. If no suitable
* application name can be generated from the specified {@code name}, the
* {@link Env#fallbackApplicationName} is used instead.
* {@link Env#getFallbackApplicationName()} is used instead.
* <p>
* No suitable application name can be generated if the name is {@code null} or if it
* contains an invalid character for a class identifier.
* @see Env#fallbackApplicationName
* @see Env#invalidApplicationNames
* @param name The the source name
* @return the generated application name
* @see Env#getFallbackApplicationName()
* @see Env#getInvalidApplicationNames()
*/
public String generateApplicationName(String name) {
if (!StringUtils.hasText(name)) {
@@ -96,7 +98,10 @@ public class InitializrConfiguration {
* <p>
* The package name cannot be cleaned if the specified {@code packageName} is
* {@code null} or if it contains an invalid character for a class identifier.
* @see Env#invalidPackageNames
* @param packageName The package name
* @param defaultPackageName the default package name
* @return the cleaned package name
* @see Env#getInvalidPackageNames()
*/
public String cleanPackageName(String packageName, String defaultPackageName) {
if (!StringUtils.hasText(packageName)) {
@@ -133,7 +138,7 @@ public class InitializrConfiguration {
private static String splitCamelCase(String text) {
return String.join("",
Arrays.stream(text.split("(?<!(^|[A-Z]))(?=[A-Z])|(?<!^)(?=[A-Z][a-z])"))
.map(it -> StringUtils.capitalize(it.toLowerCase()))
.map((it) -> StringUtils.capitalize(it.toLowerCase()))
.toArray(String[]::new));
}
@@ -339,6 +344,9 @@ public class InitializrConfiguration {
other.repositories.forEach(this.repositories::putIfAbsent);
}
/**
* Gradle details.
*/
public static class Gradle {
/**
@@ -361,6 +369,9 @@ public class InitializrConfiguration {
}
/**
* Kotlin details.
*/
public static class Kotlin {
/**
@@ -405,7 +416,7 @@ public class InitializrConfiguration {
public void validate() {
VersionParser simpleParser = new VersionParser(Collections.emptyList());
this.mappings.forEach(m -> {
this.mappings.forEach((m) -> {
if (m.versionRange == null) {
throw new InvalidInitializrMetadataException(
"VersionRange is mandatory, invalid version mapping for "
@@ -421,7 +432,7 @@ public class InitializrConfiguration {
}
public void updateVersionRange(VersionParser versionParser) {
this.mappings.forEach(it -> {
this.mappings.forEach((it) -> {
try {
it.range = versionParser.parseRange(it.versionRange);
}
@@ -478,6 +489,9 @@ public class InitializrConfiguration {
}
/**
* Maven details.
*/
public static class Maven {
/**
@@ -499,6 +513,8 @@ public class InitializrConfiguration {
/**
* Resolve the parent pom to use. If no custom parent pom is set, the standard
* spring boot parent pom with the specified {@code bootVersion} is used.
* @param bootVersion The Spring Boot version
* @return the parent POM
*/
public ParentPom resolveParentPom(String bootVersion) {
return StringUtils.hasText(this.parent.groupId) ? this.parent
@@ -506,6 +522,9 @@ public class InitializrConfiguration {
"spring-boot-starter-parent", bootVersion);
}
/**
* Parent POM details.
*/
public static class ParentPom {
/**

View File

@@ -129,7 +129,7 @@ public class InitializrMetadata {
}
/**
* Merge this instance with the specified argument
* Merge this instance with the specified argument.
* @param other the other instance
*/
public void merge(InitializrMetadata other) {
@@ -215,17 +215,19 @@ public class InitializrMetadata {
this.bootVersions.getContent().clear();
this.bootVersions.getContent().addAll(versionsMetadata);
List<Version> bootVersions = this.bootVersions.getContent().stream()
.map(it -> Version.parse(it.getId())).collect(Collectors.toList());
.map((it) -> Version.parse(it.getId())).collect(Collectors.toList());
VersionParser parser = new VersionParser(bootVersions);
this.dependencies.updateVersionRange(parser);
this.configuration.getEnv().getBoms().values()
.forEach(it -> it.updateVersionRange(parser));
.forEach((it) -> it.updateVersionRange(parser));
this.configuration.getEnv().getKotlin().updateVersionRange(parser);
}
/**
* Create an URL suitable to download Spring Boot cli for the specified version and
* extension.
* @param extension the required extension
* @return the download URL
*/
public String createCliDistributionURl(String extension) {
String bootVersion = defaultId(this.bootVersions);
@@ -236,6 +238,9 @@ public class InitializrMetadata {
/**
* Create a {@link BillOfMaterials} for the spring boot BOM.
* @param bootVersion the Spring Boot version
* @param versionProperty the property that contains the version
* @return a new {@link BillOfMaterials} instance
*/
public BillOfMaterials createSpringBootBom(String bootVersion,
String versionProperty) {
@@ -248,6 +253,7 @@ public class InitializrMetadata {
/**
* Return the defaults for the capabilities defined on this instance.
* @return the default capabilities
*/
public Map<String, Object> defaults() {
Map<String, Object> defaults = new LinkedHashMap<>();

View File

@@ -35,7 +35,7 @@ import org.springframework.util.StringUtils;
* @author Stephane Nicoll
* @see InitializrMetadataCustomizer
*/
public class InitializrMetadataBuilder {
public final class InitializrMetadataBuilder {
private final List<InitializrMetadataCustomizer> customizers = new ArrayList<>();
@@ -45,27 +45,11 @@ public class InitializrMetadataBuilder {
this.configuration = configuration;
}
/**
* Create a builder instance from the specified {@link InitializrProperties}.
* Initialize the configuration to use.
* @see #withInitializrProperties(InitializrProperties)
*/
public static InitializrMetadataBuilder fromInitializrProperties(
InitializrProperties configuration) {
return new InitializrMetadataBuilder(configuration)
.withInitializrProperties(configuration);
}
/**
* Create an empty builder instance with a default {@link InitializrConfiguration}
*/
public static InitializrMetadataBuilder create() {
return new InitializrMetadataBuilder(new InitializrConfiguration());
}
/**
* Add a {@link InitializrProperties} to be merged with other content. Merges the
* settings only and not the configuration.
* @param properties the properties to use
* @return this instance
* @see #withInitializrProperties(InitializrProperties, boolean)
*/
public InitializrMetadataBuilder withInitializrProperties(
@@ -77,6 +61,7 @@ public class InitializrMetadataBuilder {
* Add a {@link InitializrProperties} to be merged with other content.
* @param properties the settings to merge onto this instance
* @param mergeConfiguration specify if service configuration should be merged as well
* @return this instance
*/
public InitializrMetadataBuilder withInitializrProperties(
InitializrProperties properties, boolean mergeConfiguration) {
@@ -89,6 +74,7 @@ public class InitializrMetadataBuilder {
/**
* Add a {@link InitializrMetadata} to be merged with other content.
* @param resource a resource to a json document describing the metadata to include
* @return this instance
*/
public InitializrMetadataBuilder withInitializrMetadata(Resource resource) {
return withCustomizer(new ResourceInitializrMetadataCustomizer(resource));
@@ -97,6 +83,8 @@ public class InitializrMetadataBuilder {
/**
* Add a {@link InitializrMetadataCustomizer}. customizers are invoked in their order
* of addition.
* @param customizer the customizer to add
* @return this instance
* @see InitializrMetadataCustomizer
*/
public InitializrMetadataBuilder withCustomizer(
@@ -107,6 +95,7 @@ public class InitializrMetadataBuilder {
/**
* Build a {@link InitializrMetadata} based on the state of this builder.
* @return a new {@link InitializrMetadata} instance
*/
public InitializrMetadata build() {
InitializrConfiguration config = this.configuration != null ? this.configuration
@@ -121,7 +110,9 @@ public class InitializrMetadataBuilder {
}
/**
* Creates an empty instance based on the specified {@link InitializrConfiguration}
* Creates an empty instance based on the specified {@link InitializrConfiguration}.
* @param configuration the configuration
* @return a new {@link InitializrMetadata} instance
*/
protected InitializrMetadata createInstance(InitializrConfiguration configuration) {
return new InitializrMetadata(configuration);
@@ -129,6 +120,7 @@ public class InitializrMetadataBuilder {
/**
* Apply defaults to capabilities that have no value.
* @param metadata the initializr metadata
*/
protected void applyDefaults(InitializrMetadata metadata) {
if (!StringUtils.hasText(metadata.getName().getContent())) {
@@ -145,6 +137,27 @@ public class InitializrMetadataBuilder {
}
}
/**
* Create a builder instance from the specified {@link InitializrProperties}.
* Initialize the configuration to use.
* @param configuration the configuration to use
* @return a new {@link InitializrMetadataBuilder} instance
* @see #withInitializrProperties(InitializrProperties)
*/
public static InitializrMetadataBuilder fromInitializrProperties(
InitializrProperties configuration) {
return new InitializrMetadataBuilder(configuration)
.withInitializrProperties(configuration);
}
/**
* Create an empty builder instance with a default {@link InitializrConfiguration}.
* @return a new {@link InitializrMetadataBuilder} instance
*/
public static InitializrMetadataBuilder create() {
return new InitializrMetadataBuilder(new InitializrConfiguration());
}
private static class InitializerPropertiesCustomizer
implements InitializrMetadataCustomizer {

View File

@@ -26,6 +26,7 @@ public interface InitializrMetadataCustomizer {
/**
* Customize the {@link InitializrMetadata}, updating or moving around capabilities
* before they are validated.
* @param metadata the initalizr metadata
*/
void customize(InitializrMetadata metadata);

View File

@@ -26,7 +26,8 @@ public interface InitializrMetadataProvider {
/**
* Return the metadata to use. Rather than keeping a handle to a particular instance,
* implementations may decide to refresh or recompute the metadata if necessary.
* @return the initializr metadata
*/
InitializrMetadata get();
}
}

View File

@@ -153,6 +153,9 @@ public class InitializrProperties extends InitializrConfiguration {
return this.packageName;
}
/**
* A simple element from the properties.
*/
public static class SimpleElement {
/**

View File

@@ -147,7 +147,7 @@ public class Link {
*/
public URI expand(Map<String, String> parameters) {
AtomicReference<String> result = new AtomicReference<>(this.href);
this.templateVariables.forEach(var -> {
this.templateVariables.forEach((var) -> {
Object value = parameters.get(var);
if (value == null) {
throw new IllegalArgumentException("Could not expand " + this.href

View File

@@ -17,7 +17,7 @@
package io.spring.initializr.metadata;
/**
* A basic metadata element
* A basic metadata element.
*
* @author Stephane Nicoll
*/
@@ -61,4 +61,4 @@ public class MetadataElement {
this.name = name;
}
}
}

View File

@@ -26,6 +26,7 @@ import org.springframework.util.StringUtils;
* Defines a capability of the initializr service. Each capability is defined by a id and
* a {@link ServiceCapabilityType type}.
*
* @param <T> The content type
* @author Stephane Nicoll
*/
@JsonIgnoreProperties({ "default", "all" })
@@ -81,11 +82,13 @@ public abstract class ServiceCapability<T> implements Cloneable {
/**
* Return the "content" of this capability. The structure of the content vastly
* depends on the {@link ServiceCapability type} of the capability.
* @return the content
*/
public abstract T getContent();
/**
* Merge the content of this instance with the specified content.
* @param otherContent the content to merge
* @see #merge(io.spring.initializr.metadata.ServiceCapability)
*/
public abstract void merge(T otherContent);
@@ -94,6 +97,7 @@ public abstract class ServiceCapability<T> implements Cloneable {
* Merge this capability with the specified argument. The service capabilities should
* match (i.e have the same {@code id} and {@code type}). Sub-classes may merge
* additional content.
* @param other the content to merge
*/
public void merge(ServiceCapability<T> other) {
Assert.notNull(other, "Other must not be null");

View File

@@ -58,15 +58,17 @@ public class SingleSelectCapability
/**
* Return the element with the specified id or {@code null} if no such element exists.
* @param id the ID of the element to find
* @return the element or {@code null}
*/
public DefaultMetadataElement get(String id) {
return this.content.stream().filter(it -> id.equals(it.getId())).findFirst()
return this.content.stream().filter((it) -> id.equals(it.getId())).findFirst()
.orElse(null);
}
@Override
public void merge(List<DefaultMetadataElement> otherContent) {
otherContent.forEach(it -> {
otherContent.forEach((it) -> {
if (get(it.getId()) == null) {
this.content.add(it);
}

View File

@@ -41,10 +41,12 @@ public class TypeCapability extends ServiceCapability<List<Type>>
/**
* Return the {@link Type} with the specified id or {@code null} if no such type
* exists.
* @param id the ID to find
* @return the Type or {@code null}
*/
public Type get(String id) {
return this.content.stream()
.filter(it -> id.equals(it.getId()) || id.equals(it.getStsId()))
.filter((it) -> id.equals(it.getId()) || id.equals(it.getStsId()))
.findFirst().orElse(null);
}
@@ -59,7 +61,7 @@ public class TypeCapability extends ServiceCapability<List<Type>>
@Override
public void merge(List<Type> otherContent) {
otherContent.forEach(it -> {
otherContent.forEach((it) -> {
if (get(it.getId()) == null) {
this.content.add(it);
}

View File

@@ -32,7 +32,7 @@ public class Agent {
private final AgentId id;
/**
* The version of the agent, if any
* The version of the agent, if any.
*/
private final String version;
@@ -63,22 +63,49 @@ public class Agent {
*/
public enum AgentId {
/**
* CURL.
*/
CURL("curl", "curl"),
/**
* HTTPie.
*/
HTTPIE("httpie", "HTTPie"),
/**
* JBoss Forge.
*/
JBOSS_FORGE("jbossforge", "SpringBootForgeCli"),
/**
* The Spring Boot CLI.
*/
SPRING_BOOT_CLI("spring", "SpringBootCli"),
/**
* Spring Tools Suite.
*/
STS("sts", "STS"),
/**
* IntelliJ IDEA.
*/
INTELLIJ_IDEA("intellijidea", "IntelliJ IDEA"),
/**
* Netbeans.
*/
NETBEANS("netbeans", "NetBeans"),
/**
* Visual Studio Code.
*/
VSCODE("vscode", "vscode"),
/**
* A generic browser.
*/
BROWSER("browser", "Browser");
final String id;

View File

@@ -34,6 +34,8 @@ import org.springframework.core.io.ResourceLoader;
import org.springframework.util.ConcurrentReferenceHashMap;
/**
* A template renderer backed by Mustache.
*
* @author Dave Syer
*/
public class TemplateRenderer {
@@ -46,14 +48,14 @@ public class TemplateRenderer {
private final ConcurrentMap<String, Template> templateCaches = new ConcurrentReferenceHashMap<>();
public TemplateRenderer(Compiler mustache) {
this.mustache = mustache;
}
public TemplateRenderer() {
this(mustacheCompiler());
}
public TemplateRenderer(Compiler mustache) {
this.mustache = mustache;
}
public boolean isCache() {
return this.cache;
}
@@ -99,7 +101,7 @@ public class TemplateRenderer {
ResourceLoader resourceLoader = new DefaultResourceLoader();
String prefix = "classpath:/templates/";
Charset charset = Charset.forName("UTF-8");
return name -> new InputStreamReader(
return (name) -> new InputStreamReader(
resourceLoader.getResource(prefix + name).getInputStream(), charset);
}

View File

@@ -145,6 +145,68 @@ public final class Version implements Serializable, Comparable<Version> {
return firstIndex.compareTo(secondIndex);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.major == null) ? 0 : this.major.hashCode());
result = prime * result + ((this.minor == null) ? 0 : this.minor.hashCode());
result = prime * result + ((this.patch == null) ? 0 : this.patch.hashCode());
result = prime * result
+ ((this.qualifier == null) ? 0 : this.qualifier.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
Version other = (Version) obj;
if (this.major == null) {
if (other.major != null) {
return false;
}
}
else if (!this.major.equals(other.major)) {
return false;
}
if (this.minor == null) {
if (other.minor != null) {
return false;
}
}
else if (!this.minor.equals(other.minor)) {
return false;
}
if (this.patch == null) {
if (other.patch != null) {
return false;
}
}
else if (!this.patch.equals(other.patch)) {
return false;
}
if (this.qualifier == null) {
if (other.qualifier != null) {
return false;
}
}
else if (!this.qualifier.equals(other.qualifier)) {
return false;
}
return true;
}
/**
* A version qualifier.
*/
public static class Qualifier implements Serializable {
public Qualifier(String qualifier) {
@@ -222,65 +284,6 @@ public final class Version implements Serializable, Comparable<Version> {
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.major == null) ? 0 : this.major.hashCode());
result = prime * result + ((this.minor == null) ? 0 : this.minor.hashCode());
result = prime * result + ((this.patch == null) ? 0 : this.patch.hashCode());
result = prime * result
+ ((this.qualifier == null) ? 0 : this.qualifier.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
Version other = (Version) obj;
if (this.major == null) {
if (other.major != null) {
return false;
}
}
else if (!this.major.equals(other.major)) {
return false;
}
if (this.minor == null) {
if (other.minor != null) {
return false;
}
}
else if (!this.minor.equals(other.minor)) {
return false;
}
if (this.patch == null) {
if (other.patch != null) {
return false;
}
}
else if (!this.patch.equals(other.patch)) {
return false;
}
if (this.qualifier == null) {
if (other.qualifier != null) {
return false;
}
}
else if (!this.qualifier.equals(other.qualifier)) {
return false;
}
return true;
}
private static class VersionQualifierComparator implements Comparator<Qualifier> {
static final String RELEASE = "RELEASE";

View File

@@ -42,6 +42,9 @@ import org.springframework.util.StringUtils;
*/
public class VersionParser {
/**
* The default {@link VersionParser}.
*/
public static final VersionParser DEFAULT = new VersionParser(
Collections.emptyList());
@@ -144,7 +147,7 @@ public class VersionParser {
private Version findLatestVersion(Integer major, Integer minor,
Version.Qualifier qualifier) {
List<Version> matches = this.latestVersions.stream().filter(it -> {
List<Version> matches = this.latestVersions.stream().filter((it) -> {
if (major != null && !major.equals(it.getMajor())) {
return false;
}

View File

@@ -43,6 +43,7 @@ public class VersionProperty implements Serializable, Comparable<VersionProperty
/**
* Return a camel cased representation of this instance.
* @return the property in camel case format
*/
public String toCamelCaseFormat() {
String[] tokens = this.property.split("\\-|\\.");

View File

@@ -36,13 +36,13 @@ import org.springframework.util.Assert;
*/
public class VersionRange {
final Version lowerVersion;
private final Version lowerVersion;
final boolean lowerInclusive;
private final boolean lowerInclusive;
final Version higherVersion;
private final Version higherVersion;
final boolean higherInclusive;
private final boolean higherInclusive;
// For Jackson
@SuppressWarnings("unused")
@@ -65,22 +65,24 @@ public class VersionRange {
/**
* Specify if the {@link Version} matches this range. Returns {@code true} if the
* version is contained within this range, {@code false} otherwise.
* @param version the version to check
* @return {@code true} if the version matches
*/
public boolean match(Version version) {
Assert.notNull(version, "Version must not be null");
int lower = lowerVersion.compareTo(version);
int lower = this.lowerVersion.compareTo(version);
if (lower > 0) {
return false;
}
else if (!lowerInclusive && lower == 0) {
else if (!this.lowerInclusive && lower == 0) {
return false;
}
if (higherVersion != null) {
int higher = higherVersion.compareTo(version);
if (this.higherVersion != null) {
int higher = this.higherVersion.compareTo(version);
if (higher < 0) {
return false;
}
else if (!higherInclusive && higher == 0) {
else if (!this.higherInclusive && higher == 0) {
return false;
}
}
@@ -88,29 +90,30 @@ public class VersionRange {
}
public Version getLowerVersion() {
return lowerVersion;
return this.lowerVersion;
}
public boolean isLowerInclusive() {
return lowerInclusive;
return this.lowerInclusive;
}
public Version getHigherVersion() {
return higherVersion;
return this.higherVersion;
}
public boolean isHigherInclusive() {
return higherInclusive;
return this.higherInclusive;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
if (lowerVersion != null) {
sb.append(lowerInclusive ? ">=" : ">").append(lowerVersion);
if (this.lowerVersion != null) {
sb.append(this.lowerInclusive ? ">=" : ">").append(this.lowerVersion);
}
if (higherVersion != null) {
sb.append(" and ").append(higherInclusive ? "<=" : "<").append(higherVersion);
if (this.higherVersion != null) {
sb.append(" and ").append(this.higherInclusive ? "<=" : "<")
.append(this.higherVersion);
}
return sb.toString();
}
@@ -119,11 +122,12 @@ public class VersionRange {
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (higherInclusive ? 1231 : 1237);
result = prime * result + (this.higherInclusive ? 1231 : 1237);
result = prime * result
+ ((higherVersion == null) ? 0 : higherVersion.hashCode());
result = prime * result + (lowerInclusive ? 1231 : 1237);
result = prime * result + ((lowerVersion == null) ? 0 : lowerVersion.hashCode());
+ ((this.higherVersion == null) ? 0 : this.higherVersion.hashCode());
result = prime * result + (this.lowerInclusive ? 1231 : 1237);
result = prime * result
+ ((this.lowerVersion == null) ? 0 : this.lowerVersion.hashCode());
return result;
}
@@ -139,26 +143,26 @@ public class VersionRange {
return false;
}
VersionRange other = (VersionRange) obj;
if (higherInclusive != other.higherInclusive) {
if (this.higherInclusive != other.higherInclusive) {
return false;
}
if (higherVersion == null) {
if (this.higherVersion == null) {
if (other.higherVersion != null) {
return false;
}
}
else if (!higherVersion.equals(other.higherVersion)) {
else if (!this.higherVersion.equals(other.higherVersion)) {
return false;
}
if (lowerInclusive != other.lowerInclusive) {
if (this.lowerInclusive != other.lowerInclusive) {
return false;
}
if (lowerVersion == null) {
if (this.lowerVersion == null) {
if (other.lowerVersion != null) {
return false;
}
}
else if (!lowerVersion.equals(other.lowerVersion)) {
else if (!this.lowerVersion.equals(other.lowerVersion)) {
return false;
}
return true;

View File

@@ -23,9 +23,6 @@ import org.junit.runners.Parameterized;
import org.springframework.core.io.ClassPathResource;
import static io.spring.initializr.test.generator.ProjectAssert.DEFAULT_APPLICATION_NAME;
import static io.spring.initializr.test.generator.ProjectAssert.DEFAULT_PACKAGE_NAME;
/**
* Project generator tests for supported languages.
*
@@ -58,8 +55,8 @@ public class ProjectGeneratorLanguageTests extends AbstractProjectGeneratorTests
public void standardJar() {
ProjectRequest request = createProjectRequest();
request.setLanguage(this.language);
generateProject(request).isGenericProject(DEFAULT_PACKAGE_NAME,
DEFAULT_APPLICATION_NAME, this.language, this.extension);
generateProject(request).isGenericProject(ProjectAssert.DEFAULT_PACKAGE_NAME,
ProjectAssert.DEFAULT_APPLICATION_NAME, this.language, this.extension);
}
@Test
@@ -67,8 +64,8 @@ public class ProjectGeneratorLanguageTests extends AbstractProjectGeneratorTests
ProjectRequest request = createProjectRequest("web");
request.setLanguage(this.language);
request.setPackaging("war");
generateProject(request).isGenericWarProject(DEFAULT_PACKAGE_NAME,
DEFAULT_APPLICATION_NAME, this.language, this.extension);
generateProject(request).isGenericWarProject(ProjectAssert.DEFAULT_PACKAGE_NAME,
ProjectAssert.DEFAULT_APPLICATION_NAME, this.language, this.extension);
}
@Test

View File

@@ -193,7 +193,8 @@ public class InitializrMetadataBuilderTests {
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();
.withCustomizer((m) -> m.getDependencies().getContent().add(group))
.build();
assertThat(metadata.getDependencies().getContent()).hasSize(1);
assertThat(metadata.getDependencies().getContent().get(0)).isEqualTo(group);
}

View File

@@ -51,7 +51,7 @@ public class InitializrMetadataTestBuilder {
}
public InitializrMetadataTestBuilder addDependencyGroup(String name, String... ids) {
this.builder.withCustomizer(it -> {
this.builder.withCustomizer((it) -> {
DependencyGroup group = new DependencyGroup();
group.setName(name);
for (String id : ids) {
@@ -66,7 +66,7 @@ public class InitializrMetadataTestBuilder {
public InitializrMetadataTestBuilder addDependencyGroup(String name,
Dependency... dependencies) {
this.builder.withCustomizer(it -> {
this.builder.withCustomizer((it) -> {
DependencyGroup group = new DependencyGroup();
group.setName(name);
group.getContent().addAll(Arrays.asList(dependencies));
@@ -105,7 +105,7 @@ public class InitializrMetadataTestBuilder {
}
public InitializrMetadataTestBuilder addType(Type type) {
this.builder.withCustomizer(it -> it.getTypes().getContent().add(type));
this.builder.withCustomizer((it) -> it.getTypes().getContent().add(type));
return this;
}
@@ -114,7 +114,7 @@ public class InitializrMetadataTestBuilder {
}
public InitializrMetadataTestBuilder addPackaging(String id, boolean defaultValue) {
this.builder.withCustomizer(it -> {
this.builder.withCustomizer((it) -> {
DefaultMetadataElement packaging = new DefaultMetadataElement();
packaging.setId(id);
packaging.setName(id);
@@ -131,7 +131,7 @@ public class InitializrMetadataTestBuilder {
public InitializrMetadataTestBuilder addJavaVersion(String version,
boolean defaultValue) {
this.builder.withCustomizer(it -> {
this.builder.withCustomizer((it) -> {
DefaultMetadataElement element = new DefaultMetadataElement();
element.setId(version);
element.setName(version);
@@ -147,7 +147,7 @@ public class InitializrMetadataTestBuilder {
}
public InitializrMetadataTestBuilder addLanguage(String id, boolean defaultValue) {
this.builder.withCustomizer(it -> {
this.builder.withCustomizer((it) -> {
DefaultMetadataElement element = new DefaultMetadataElement();
element.setId(id);
element.setName(id);
@@ -164,7 +164,7 @@ public class InitializrMetadataTestBuilder {
}
public InitializrMetadataTestBuilder addBootVersion(String id, boolean defaultValue) {
this.builder.withCustomizer(it -> {
this.builder.withCustomizer((it) -> {
DefaultMetadataElement element = new DefaultMetadataElement();
element.setId(id);
element.setName(id);
@@ -182,20 +182,20 @@ public class InitializrMetadataTestBuilder {
public InitializrMetadataTestBuilder addBom(String id, BillOfMaterials bom) {
this.builder.withCustomizer(
it -> it.getConfiguration().getEnv().getBoms().put(id, bom));
(it) -> it.getConfiguration().getEnv().getBoms().put(id, bom));
return this;
}
public InitializrMetadataTestBuilder setGradleEnv(
String dependencyManagementPluginVersion) {
this.builder.withCustomizer(it -> it.getConfiguration().getEnv().getGradle()
this.builder.withCustomizer((it) -> it.getConfiguration().getEnv().getGradle()
.setDependencyManagementPluginVersion(dependencyManagementPluginVersion));
return this;
}
public InitializrMetadataTestBuilder setKotlinEnv(String defaultKotlinVersion,
Kotlin.Mapping... mappings) {
this.builder.withCustomizer(it -> {
this.builder.withCustomizer((it) -> {
it.getConfiguration().getEnv().getKotlin()
.setDefaultVersion(defaultKotlinVersion);
for (Kotlin.Mapping mapping : mappings) {
@@ -207,7 +207,7 @@ public class InitializrMetadataTestBuilder {
public InitializrMetadataTestBuilder setMavenParent(String groupId, String artifactId,
String version, boolean includeSpringBootBom) {
this.builder.withCustomizer(it -> {
this.builder.withCustomizer((it) -> {
ParentPom parent = it.getConfiguration().getEnv().getMaven().getParent();
parent.setGroupId(groupId);
parent.setArtifactId(artifactId);
@@ -219,7 +219,7 @@ public class InitializrMetadataTestBuilder {
public InitializrMetadataTestBuilder addRepository(String id, String name, String url,
boolean snapshotsEnabled) {
this.builder.withCustomizer(it -> {
this.builder.withCustomizer((it) -> {
Repository repo = new Repository();
repo.setName(name);
try {
@@ -234,4 +234,4 @@ public class InitializrMetadataTestBuilder {
return this;
}
}
}