Reformat code

Format code using a pre-release version of the spring-javaformat plugin.
This commit is contained in:
Phillip Webb
2018-04-11 22:08:13 -07:00
parent 0c0556c585
commit 3d4efbf525
103 changed files with 763 additions and 643 deletions

View File

@@ -22,26 +22,38 @@ import java.util.List;
import org.springframework.util.StringUtils;
/**
* The base settings of a project request. Only these can be bound by user's
* input.
* The base settings of a project request. Only these can be bound by user's input.
*
* @author Stephane Nicoll
*/
public class BasicProjectRequest {
private List<String> style = new ArrayList<>();
private List<String> dependencies = new ArrayList<>();
private String name;
private String type;
private String description;
private String groupId;
private String artifactId;
private String version;
private String bootVersion;
private String packaging;
private String applicationName;
private String language;
private String packageName;
private String javaVersion;
// The base directory to create in the archive - no baseDir by default

View File

@@ -35,8 +35,8 @@ public class BuildProperties {
private final TreeMap<String, Supplier<String>> maven = new TreeMap<>();
/**
* Gradle-specific build properties, added to the {@code buildscript} section
* of the gradle build.
* Gradle-specific build properties, added to the {@code buildscript} section of the
* gradle build.
*/
private final TreeMap<String, Supplier<String>> gradle = new TreeMap<>();

View File

@@ -101,6 +101,7 @@ public class ProjectGenerator {
private String tmpdir;
private File temporaryDirectory;
private transient Map<String, List<File>> temporaryFiles = new LinkedHashMap<>();
public InitializrMetadataProvider getMetadataProvider() {
@@ -354,8 +355,7 @@ public class ProjectGenerator {
}
// Kotlin supported as of M6
final boolean kotlinSupport = VERSION_2_0_0_M6
.compareTo(bootVersion) <= 0;
final boolean kotlinSupport = VERSION_2_0_0_M6.compareTo(bootVersion) <= 0;
model.put("kotlinSupport", kotlinSupport);
if (isMavenBuild(request)) {
@@ -379,9 +379,9 @@ public class ProjectGenerator {
model.put("hasRepositories", true);
}
List<Map<String,String>> resolvedBoms = buildResolvedBoms(request);
List<Map<String, String>> resolvedBoms = buildResolvedBoms(request);
model.put("resolvedBoms", resolvedBoms);
ArrayList<Map<String,String>> reversedBoms = new ArrayList<>(resolvedBoms);
ArrayList<Map<String, String>> reversedBoms = new ArrayList<>(resolvedBoms);
Collections.reverse(reversedBoms);
model.put("reversedBoms", reversedBoms);
@@ -398,19 +398,19 @@ public class ProjectGenerator {
request.getBoms().forEach((k, v) -> {
if (v.getVersionProperty() != null) {
request.getBuildProperties().getVersions().computeIfAbsent(
v.getVersionProperty(), key -> v::getVersion);
request.getBuildProperties().getVersions()
.computeIfAbsent(v.getVersionProperty(), key -> v::getVersion);
}
});
Map<String, String> versions = new LinkedHashMap<>();
model.put("buildPropertiesVersions", versions.entrySet());
request.getBuildProperties().getVersions().forEach((k, v) ->
versions.put(computeVersionProperty(request,k), v.get()));
request.getBuildProperties().getVersions().forEach(
(k, v) -> versions.put(computeVersionProperty(request, k), v.get()));
Map<String, String> gradle = new LinkedHashMap<>();
model.put("buildPropertiesGradle", gradle.entrySet());
request.getBuildProperties().getGradle().forEach((k, v) ->
gradle.put(k, v.get()));
request.getBuildProperties().getGradle()
.forEach((k, v) -> gradle.put(k, v.get()));
Map<String, String> maven = new LinkedHashMap<>();
model.put("buildPropertiesMaven", maven.entrySet());
request.getBuildProperties().getMaven().forEach((k, v) -> maven.put(k, v.get()));
@@ -431,24 +431,20 @@ public class ProjectGenerator {
setupApplicationModel(request, model);
// Gradle plugin has changed as from 1.3.0
model.put("bootOneThreeAvailable", VERSION_1_3_0_M1
.compareTo(bootVersion) <= 0);
model.put("bootOneThreeAvailable", VERSION_1_3_0_M1.compareTo(bootVersion) <= 0);
model.put("bootTwoZeroAvailable", VERSION_2_0_0_M1
.compareTo(bootVersion) <= 0);
model.put("bootTwoZeroAvailable", VERSION_2_0_0_M1.compareTo(bootVersion) <= 0);
// Gradle plugin has changed again as from 1.4.2
model.put("springBootPluginName",
(VERSION_1_4_2_M1
.compareTo(bootVersion) <= 0
? "org.springframework.boot" : "spring-boot"));
model.put("springBootPluginName", (VERSION_1_4_2_M1.compareTo(bootVersion) <= 0
? "org.springframework.boot" : "spring-boot"));
// New testing stuff
model.put("newTestInfrastructure", isNewTestInfrastructureAvailable(request));
// Servlet Initializer
model.put("servletInitializrImport", new Imports(request.getLanguage()).add(
getServletInitializrClass(request)).toString());
model.put("servletInitializrImport", new Imports(request.getLanguage())
.add(getServletInitializrClass(request)).toString());
// Kotlin-specific dep
model.put("kotlinStdlibArtifactId", getKotlinStdlibArtifactId(request));
@@ -471,20 +467,20 @@ public class ProjectGenerator {
return model;
}
private List<Map<String,String>> buildResolvedBoms(ProjectRequest request) {
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) {
private Map<String, String> toBomModel(ProjectRequest request, BillOfMaterials bom) {
Map<String, String> model = new HashMap<>();
model.put("groupId", bom.getGroupId());
model.put("artifactId", bom.getArtifactId());
model.put("versionToken", (bom.getVersionProperty() != null
? "${" + computeVersionProperty(request, bom.getVersionProperty()) + "}"
: bom.getVersion()));
model.put("versionToken",
(bom.getVersionProperty() != null ? "${"
+ computeVersionProperty(request, bom.getVersionProperty()) + "}"
: bom.getVersion()));
return model;
}
@@ -510,14 +506,12 @@ public class ProjectGenerator {
imports.add("org.springframework.boot.autoconfigure.EnableAutoConfiguration")
.add("org.springframework.context.annotation.ComponentScan")
.add("org.springframework.context.annotation.Configuration");
annotations.add("@EnableAutoConfiguration")
.add("@ComponentScan")
annotations.add("@EnableAutoConfiguration").add("@ComponentScan")
.add("@Configuration");
}
model.put("applicationImports", imports.toString());
model.put("applicationAnnotations", annotations.toString());
}
protected void setupTestModel(ProjectRequest request, Map<String, Object> model) {
@@ -537,7 +531,8 @@ public class ProjectGenerator {
testAnnotations.add("@WebAppConfiguration");
}
model.put("testImports", imports.withFinalCarriageReturn().toString());
model.put("testAnnotations", testAnnotations.withFinalCarriageReturn().toString());
model.put("testAnnotations",
testAnnotations.withFinalCarriageReturn().toString());
}
protected String getServletInitializrClass(ProjectRequest request) {
@@ -607,8 +602,8 @@ public class ProjectGenerator {
}
private void writeGradleWrapper(File dir, Version bootVersion) {
String gradlePrefix = isGradle4Available(bootVersion) ? "gradle4" :
isGradle3Available(bootVersion) ? "gradle3" : "gradle";
String gradlePrefix = isGradle4Available(bootVersion) ? "gradle4"
: isGradle3Available(bootVersion) ? "gradle3" : "gradle";
writeTextResource(dir, "gradlew.bat", gradlePrefix + "/gradlew.bat");
writeTextResource(dir, "gradlew", gradlePrefix + "/gradlew");
@@ -695,8 +690,7 @@ public class ProjectGenerator {
private static List<Dependency> filterDependencies(List<Dependency> dependencies,
String scope) {
return dependencies.stream().filter(dep -> scope.equals(dep.getScope()))
.sorted(DependencyComparator.INSTANCE)
.collect(Collectors.toList());
.sorted(DependencyComparator.INSTANCE).collect(Collectors.toList());
}
private static class DependencyComparator implements Comparator<Dependency> {
@@ -730,7 +724,9 @@ public class ProjectGenerator {
private static class Imports {
private final List<String> statements = new ArrayList<>();
private final String language;
private boolean finalCarriageReturn;
public Imports(String language) {
@@ -748,7 +744,8 @@ public class ProjectGenerator {
}
private String generateImport(String type, String language) {
String end = ("groovy".equals(language) || "kotlin".equals(language)) ? "" : ";";
String end = ("groovy".equals(language) || "kotlin".equals(language)) ? ""
: ";";
return "import " + type + end;
}
@@ -765,6 +762,7 @@ public class ProjectGenerator {
private static class Annotations {
private final List<String> statements = new ArrayList<>();
private boolean finalCarriageReturn;
public Annotations add(String type) {

View File

@@ -59,6 +59,7 @@ public class ProjectRequest extends BasicProjectRequest {
private final BuildProperties buildProperties = new BuildProperties();
private List<String> facets = new ArrayList<>();
private String build;
public List<Dependency> getResolvedDependencies() {
@@ -214,8 +215,8 @@ public class ProjectRequest extends BasicProjectRequest {
.getRepositories().get("spring-milestones"));
}
boms.values().forEach(it -> it.getRepositories().forEach(key -> {
repositories.computeIfAbsent(key, s -> metadata.getConfiguration()
.getEnv().getRepositories().get(s));
repositories.computeIfAbsent(key,
s -> metadata.getConfiguration().getEnv().getRepositories().get(s));
}));
}
@@ -245,8 +246,8 @@ public class ProjectRequest extends BasicProjectRequest {
private void resolveBom(InitializrMetadata metadata, String bomId,
Version requestedVersion) {
if (!boms.containsKey(bomId)) {
BillOfMaterials bom = metadata.getConfiguration().getEnv().getBoms().get(bomId)
.resolve(requestedVersion);
BillOfMaterials bom = metadata.getConfiguration().getEnv().getBoms()
.get(bomId).resolve(requestedVersion);
bom.getAdditionalBoms()
.forEach(id -> resolveBom(metadata, id, requestedVersion));
boms.put(bomId, bom);
@@ -303,12 +304,10 @@ public class ProjectRequest extends BasicProjectRequest {
public String toString() {
return "ProjectRequest [" + "parameters=" + parameters + ", "
+ (resolvedDependencies != null
? "resolvedDependencies=" + resolvedDependencies + ", "
: "")
+ "boms=" + boms + ", " + "repositories="
+ repositories + ", " + "buildProperties="
+ buildProperties + ", " + (facets != null
? "facets=" + facets + ", " : "")
? "resolvedDependencies=" + resolvedDependencies + ", " : "")
+ "boms=" + boms + ", " + "repositories=" + repositories + ", "
+ "buildProperties=" + buildProperties + ", "
+ (facets != null ? "facets=" + facets + ", " : "")
+ (build != null ? "build=" + build : "") + "]";
}

View File

@@ -26,6 +26,7 @@ package io.spring.initializr.generator;
public abstract class ProjectRequestEvent {
private final ProjectRequest projectRequest;
private final long timestamp;
protected ProjectRequestEvent(ProjectRequest projectRequest) {

View File

@@ -28,26 +28,32 @@ import io.spring.initializr.metadata.InitializrMetadata;
public interface ProjectRequestPostProcessor {
/**
* Apply this post processor to the given {@code ProjectRequest} <i>before</i> it
* gets resolved against the specified {@code InitializrMetadata}.
* <p>Consider using this hook to customize basic settings of the {@code request};
* for more advanced logic (in particular with regards to dependencies), consider
* using {@code postProcessAfterResolution}.
* Apply this post processor to the given {@code ProjectRequest} <i>before</i> it gets
* resolved against the specified {@code InitializrMetadata}.
* <p>
* Consider using this hook to customize basic settings of the {@code request}; for
* more advanced logic (in particular with regards to dependencies), consider using
* {@code postProcessAfterResolution}.
* @param request an unresolved {@link ProjectRequest}
* @param metadata the metadata to use to resolve this request
* @see ProjectRequest#resolve(InitializrMetadata)
*/
default void postProcessBeforeResolution(ProjectRequest request, InitializrMetadata metadata) {}
default void postProcessBeforeResolution(ProjectRequest request,
InitializrMetadata metadata) {
}
/**
* Apply this post processor to the given {@code ProjectRequest} <i>after</i> it has
* been resolved against the specified {@code InitializrMetadata}.
* <p>Dependencies, repositories, bills of materials, default properties and others
* <p>
* Dependencies, repositories, bills of materials, default properties and others
* aspects of the request will have been resolved prior to invocation. In particular,
* note that no further validation checks will be performed.
* @param request an resolved {@code ProjectRequest}
* @param metadata the metadata that were used to resolve this request
*/
default void postProcessAfterResolution(ProjectRequest request, InitializrMetadata metadata) {}
default void postProcessAfterResolution(ProjectRequest request,
InitializrMetadata metadata) {
}
}

View File

@@ -38,12 +38,19 @@ import io.spring.initializr.util.VersionRange;
public class BillOfMaterials {
private String groupId;
private String artifactId;
private String version;
private VersionProperty versionProperty;
private Integer order = Integer.MAX_VALUE;
private List<String> additionalBoms = new ArrayList<>();
private List<String> repositories = new ArrayList<>();
private final List<Mapping> mappings = new ArrayList<>();
public BillOfMaterials() {
@@ -88,8 +95,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.
* When this is set, a version property is automatically added rather than setting the
* version in the bom declaration itself.
*/
public VersionProperty getVersionProperty() {
return versionProperty;
@@ -187,8 +194,8 @@ public class BillOfMaterials {
return resolvedBom;
}
}
throw new IllegalStateException(
"No suitable mapping was found for " + this + " and version " + bootVersion);
throw new IllegalStateException("No suitable mapping was found for " + this
+ " and version " + bootVersion);
}
@Override
@@ -196,8 +203,8 @@ public class BillOfMaterials {
return "BillOfMaterials [" + (groupId != null ? "groupId=" + groupId + ", " : "")
+ (artifactId != null ? "artifactId=" + artifactId + ", " : "")
+ (version != null ? "version=" + version + ", " : "")
+ (versionProperty != null ? "versionProperty=" + versionProperty + ", "
: "")
+ (versionProperty != null
? "versionProperty=" + versionProperty + ", " : "")
+ (order != null ? "order=" + order + ", " : "")
+ (additionalBoms != null ? "additionalBoms=" + additionalBoms + ", "
: "")

View File

@@ -17,8 +17,7 @@
package io.spring.initializr.metadata;
/**
* A {@link MetadataElement} that specifies if its
* the default for a given capability.
* A {@link MetadataElement} that specifies if its the default for a given capability.
*
* @author Stephane Nicoll
*/
@@ -50,7 +49,8 @@ public class DefaultMetadataElement extends MetadataElement {
return new DefaultMetadataElement(id, defaultValue);
}
public static DefaultMetadataElement create(String id, String name, boolean defaultValue) {
public static DefaultMetadataElement create(String id, String name,
boolean defaultValue) {
return new DefaultMetadataElement(id, name, defaultValue);
}

View File

@@ -87,8 +87,7 @@ public class DependenciesCapability extends ServiceCapability<List<DependencyGro
indexedDependencies.clear();
content.forEach(group -> group.content.forEach(dependency -> {
// Apply defaults
if (dependency.getVersionRange() == null
&& group.getVersionRange() != null) {
if (dependency.getVersionRange() == null && group.getVersionRange() != null) {
dependency.setVersionRange(group.getVersionRange());
}
if (dependency.getBom() == null && group.getBom() != null) {

View File

@@ -40,22 +40,36 @@ import org.springframework.util.StringUtils;
public class Dependency extends MetadataElement implements Describable {
public static final String SCOPE_COMPILE = "compile";
public static final String SCOPE_COMPILE_ONLY = "compileOnly";
public static final String SCOPE_RUNTIME = "runtime";
public static final String SCOPE_PROVIDED = "provided";
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);
private List<String> aliases = new ArrayList<>();
private List<String> facets = new ArrayList<>();
private String groupId;
private String artifactId;
private String version;
private String type;
private List<Mapping> mappings = new ArrayList<>();
private String scope = SCOPE_COMPILE;
private String description;
private String versionRange;
@JsonIgnore
@@ -65,6 +79,7 @@ public class Dependency extends MetadataElement implements Describable {
private VersionRange range;
private String bom;
private String repository;
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
@@ -394,10 +409,9 @@ public class Dependency extends MetadataElement implements Describable {
@Override
public String toString() {
return "Dependency{" + "id='" + getId() + '\'' +
", groupId='" + groupId + '\'' +
", artifactId='" + artifactId + '\'' +
", version='" + version + '\'' + '}';
return "Dependency{" + "id='" + getId() + '\'' + ", groupId='" + groupId + '\''
+ ", artifactId='" + artifactId + '\'' + ", version='" + version + '\''
+ '}';
}
/**
@@ -473,6 +487,7 @@ public class Dependency extends MetadataElement implements Describable {
mapping.version = version;
return mapping;
}
}
public static Dependency create(String groupId, String artifactId, String version,

View File

@@ -127,16 +127,13 @@ public class InitializrConfiguration {
}
private static String unsplitWords(String text) {
return String
.join("", Arrays.stream(text
.split("(_|-| |:)+")).map(StringUtils::capitalize)
.toArray(String[]::new));
return String.join("", Arrays.stream(text.split("(_|-| |:)+"))
.map(StringUtils::capitalize).toArray(String[]::new));
}
private static String splitCamelCase(String text) {
return String
.join("", Arrays.stream(text
.split("(?<!(^|[A-Z]))(?=[A-Z])|(?<!^)(?=[A-Z][a-z])"))
return String.join("",
Arrays.stream(text.split("(?<!(^|[A-Z]))(?=[A-Z])|(?<!^)(?=[A-Z][a-z])"))
.map(it -> StringUtils.capitalize(it.toLowerCase()))
.toArray(String[]::new));
}
@@ -410,12 +407,14 @@ public class InitializrConfiguration {
mappings.forEach(m -> {
if (m.versionRange == null) {
throw new InvalidInitializrMetadataException(
"VersionRange is mandatory, invalid version mapping for " + this);
"VersionRange is mandatory, invalid version mapping for "
+ this);
}
m.range = simpleParser.parseRange(m.versionRange);
if (m.version == null) {
throw new InvalidInitializrMetadataException(
"Version is mandatory, invalid version mapping for " + this);
"Version is mandatory, invalid version mapping for "
+ this);
}
});
}
@@ -427,7 +426,9 @@ public class InitializrConfiguration {
}
catch (InvalidVersionException ex) {
throw new InvalidInitializrMetadataException(
"Invalid version range " + it.versionRange + " for " + this, ex);
"Invalid version range " + it.versionRange + " for "
+ this,
ex);
}
});
}
@@ -501,7 +502,7 @@ public class InitializrConfiguration {
public ParentPom resolveParentPom(String bootVersion) {
return StringUtils.hasText(parent.groupId) ? parent
: new ParentPom("org.springframework.boot",
"spring-boot-starter-parent", bootVersion);
"spring-boot-starter-parent", bootVersion);
}
public static class ParentPom {
@@ -572,8 +573,8 @@ public class InitializrConfiguration {
&& !StringUtils.hasText(artifactId)
&& !StringUtils.hasText(version))
|| (StringUtils.hasText(groupId)
&& StringUtils.hasText(artifactId)
&& StringUtils.hasText(version)))) {
&& StringUtils.hasText(artifactId)
&& StringUtils.hasText(version)))) {
throw new InvalidInitializrMetadataException("Custom maven pom "
+ "requires groupId, artifactId and version");
}

View File

@@ -39,23 +39,23 @@ public class InitializrMetadata {
private final TypeCapability types = new TypeCapability();
private final SingleSelectCapability bootVersions = new SingleSelectCapability("bootVersion",
"Spring Boot Version", "spring boot version");
private final SingleSelectCapability bootVersions = new SingleSelectCapability(
"bootVersion", "Spring Boot Version", "spring boot version");
private final SingleSelectCapability packagings = new SingleSelectCapability("packaging",
"Packaging", "project packaging");
private final SingleSelectCapability packagings = new SingleSelectCapability(
"packaging", "Packaging", "project packaging");
private final SingleSelectCapability javaVersions = new SingleSelectCapability("javaVersion",
"Java Version", "language level");
private final SingleSelectCapability javaVersions = new SingleSelectCapability(
"javaVersion", "Java Version", "language level");
private final SingleSelectCapability languages = new SingleSelectCapability("language",
"Language", "programming language");
private final SingleSelectCapability languages = new SingleSelectCapability(
"language", "Language", "programming language");
private final TextCapability name = new TextCapability("name", "Name",
"project name (infer application name)");
private final TextCapability description = new TextCapability("description", "Description",
"project description");
private final TextCapability description = new TextCapability("description",
"Description", "project description");
private final TextCapability groupId = new TextCapability("groupId", "Group",
"project coordinates");
@@ -235,7 +235,8 @@ public class InitializrMetadata {
/**
* Create a {@link BillOfMaterials} for the spring boot BOM.
*/
public BillOfMaterials createSpringBootBom(String bootVersion, String versionProperty) {
public BillOfMaterials createSpringBootBom(String bootVersion,
String versionProperty) {
BillOfMaterials bom = BillOfMaterials.create("org.springframework.boot",
"spring-boot-dependencies", bootVersion);
bom.setVersionProperty(new VersionProperty(versionProperty));
@@ -262,12 +263,14 @@ public class InitializrMetadata {
return defaults;
}
private static String defaultId(Defaultable<? extends DefaultMetadataElement> element) {
private static String defaultId(
Defaultable<? extends DefaultMetadataElement> element) {
DefaultMetadataElement defaultValue = element.getDefault();
return defaultValue != null ? defaultValue.getId() : null;
}
private static class ArtifactIdCapability extends TextCapability {
private final TextCapability nameCapability;
ArtifactIdCapability(TextCapability nameCapability) {
@@ -280,10 +283,13 @@ public class InitializrMetadata {
String value = super.getContent();
return value == null ? nameCapability.getContent() : value;
}
}
private static class PackageCapability extends TextCapability {
private final TextCapability groupId;
private final TextCapability artifactId;
PackageCapability(TextCapability groupId, TextCapability artifactId) {
@@ -305,6 +311,7 @@ public class InitializrMetadata {
}
return null;
}
}
}

View File

@@ -38,6 +38,7 @@ import org.springframework.util.StringUtils;
public class InitializrMetadataBuilder {
private final List<InitializrMetadataCustomizer> customizers = new ArrayList<>();
private final InitializrConfiguration configuration;
private InitializrMetadataBuilder(InitializrConfiguration configuration) {
@@ -168,6 +169,7 @@ public class InitializrMetadataBuilder {
properties.getDescription().apply(metadata.getDescription());
properties.getPackageName().apply(metadata.getPackageName());
}
}
private static class ResourceInitializrMetadataCustomizer

View File

@@ -24,8 +24,8 @@ package io.spring.initializr.metadata;
public interface InitializrMetadataCustomizer {
/**
* Customize the {@link InitializrMetadata}, updating or moving around
* capabilities before they are validated.
* Customize the {@link InitializrMetadata}, updating or moving around capabilities
* before they are validated.
*/
void customize(InitializrMetadata metadata);

View File

@@ -24,9 +24,8 @@ package io.spring.initializr.metadata;
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 metadata to use. Rather than keeping a handle to a particular instance,
* implementations may decide to refresh or recompute the metadata if necessary.
*/
InitializrMetadata get();

View File

@@ -209,6 +209,7 @@ public class InitializrProperties extends InitializrConfiguration {
capability.setContent(value);
}
}
}
}

View File

@@ -33,4 +33,5 @@ public class InvalidInitializrMetadataException extends InitializrException {
public InvalidInitializrMetadataException(String message) {
super(message);
}
}

View File

@@ -60,4 +60,5 @@ public class MetadataElement {
public void setName(String name) {
this.name = name;
}
}

View File

@@ -27,7 +27,9 @@ import java.net.URL;
public class Repository {
private String name;
private URL url;
private boolean snapshotsEnabled;
public Repository() {

View File

@@ -39,8 +39,8 @@ public enum ServiceCapabilityType {
SINGLE_SELECT("single-select"),
/**
* A hierarchical set of values (values in values) with the ability to
* select multiple values.
* A hierarchical set of values (values in values) with the ability to select multiple
* values.
*/
HIERARCHICAL_MULTI_SELECT("hierarchical-multi-select");

View File

@@ -54,4 +54,3 @@ public class TextCapability extends ServiceCapability<String> {
}
}

View File

@@ -24,7 +24,8 @@ import java.util.List;
*
* @author Stephane Nicoll
*/
public class TypeCapability extends ServiceCapability<List<Type>> implements Defaultable<Type> {
public class TypeCapability extends ServiceCapability<List<Type>>
implements Defaultable<Type> {
private final List<Type> content = new ArrayList<>();
@@ -52,8 +53,8 @@ public class TypeCapability extends ServiceCapability<List<Type>> implements Def
*/
@Override
public Type getDefault() {
return content.stream().filter(DefaultMetadataElement::isDefault)
.findFirst().orElse(null);
return content.stream().filter(DefaultMetadataElement::isDefault).findFirst()
.orElse(null);
}
@Override

View File

@@ -82,6 +82,7 @@ public class Agent {
BROWSER("browser", "Browser");
final String id;
final String name;
public String getId() {
@@ -96,15 +97,18 @@ public class Agent {
this.id = id;
this.name = name;
}
}
private static class UserAgentHandler {
private static final Pattern TOOL_REGEX = Pattern.compile("([^\\/]*)\\/([^ ]*).*");
private static final Pattern TOOL_REGEX = Pattern
.compile("([^\\/]*)\\/([^ ]*).*");
private static final Pattern STS_REGEX = Pattern.compile("STS (.*)");
private static final Pattern NETBEANS_REGEX = Pattern.compile("nb-springboot-plugin\\/(.*)");
private static final Pattern NETBEANS_REGEX = Pattern
.compile("nb-springboot-plugin\\/(.*)");
public static Agent parse(String userAgent) {
Matcher matcher = TOOL_REGEX.matcher(userAgent);

View File

@@ -43,8 +43,8 @@ public class TemplateRenderer {
private boolean cache = true;
private final Compiler mustache;
private final ConcurrentMap<String, Template> templateCaches =
new ConcurrentReferenceHashMap<>();
private final ConcurrentMap<String, Template> templateCaches = new ConcurrentReferenceHashMap<>();
public TemplateRenderer(Compiler mustache) {
this.mustache = mustache;

View File

@@ -25,31 +25,32 @@ import java.util.List;
import org.springframework.util.StringUtils;
/**
* Define the version number of a module. A typical version is represented
* as {@code MAJOR.MINOR.PATCH.QUALIFIER} where the qualifier can have an
* extra version.
* Define the version number of a module. A typical version is represented as
* {@code MAJOR.MINOR.PATCH.QUALIFIER} where the qualifier can have an extra version.
* <p>
* For example: {@code 1.2.0.RC1} is the first release candidate of 1.2.0
* and {@code 1.5.0.M4} is the fourth milestone of 1.5.0. The special
* {@code RELEASE} qualifier indicates a final release (a.k.a. GA)
* For example: {@code 1.2.0.RC1} is the first release candidate of 1.2.0 and
* {@code 1.5.0.M4} is the fourth milestone of 1.5.0. The special {@code RELEASE}
* qualifier indicates a final release (a.k.a. GA)
* <p>
* The main purpose of parsing a version is to compare it with another
* version, see {@link Comparable}.
* The main purpose of parsing a version is to compare it with another version, see
* {@link Comparable}.
*
* @author Stephane Nicoll
*/
@SuppressWarnings("serial")
public final class Version implements Serializable, Comparable<Version> {
private static final VersionQualifierComparator qualifierComparator =
new VersionQualifierComparator();
private static final VersionQualifierComparator qualifierComparator = new VersionQualifierComparator();
private static final VersionParser parser =
new VersionParser(Collections.emptyList());
private static final VersionParser parser = new VersionParser(
Collections.emptyList());
private final Integer major;
private final Integer minor;
private final Integer patch;
private final Qualifier qualifier;
// For Jackson
@@ -83,9 +84,11 @@ public final class Version implements Serializable, Comparable<Version> {
@Override
public String toString() {
return major + "." + minor + "." + patch +
(qualifier != null ? "." + qualifier.qualifier +
(qualifier.version != null ? qualifier.version : "") : "");
return major + "." + minor + "." + patch
+ (qualifier != null
? "." + qualifier.qualifier
+ (qualifier.version != null ? qualifier.version : "")
: "");
}
/**
@@ -150,6 +153,7 @@ public final class Version implements Serializable, Comparable<Version> {
}
private String qualifier;
private Integer version;
public String getQualifier() {
@@ -207,8 +211,8 @@ public final class Version implements Serializable, Comparable<Version> {
return false;
return true;
}
}
}
@Override
public int hashCode() {
@@ -299,6 +303,7 @@ public final class Version implements Serializable, Comparable<Version> {
return StringUtils.hasText(qualifier) ? KNOWN_QUALIFIERS.indexOf(qualifier)
: 0;
}
}
}

View File

@@ -42,13 +42,14 @@ import org.springframework.util.StringUtils;
*/
public class VersionParser {
public static final VersionParser DEFAULT = new VersionParser(Collections.emptyList());
public static final VersionParser DEFAULT = new VersionParser(
Collections.emptyList());
private static final Pattern VERSION_REGEX =
Pattern.compile("^(\\d+)\\.(\\d+|x)\\.(\\d+|x)(?:\\.([^0-9]+)(\\d+)?)?$");
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;
@@ -68,9 +69,9 @@ public class VersionParser {
Assert.notNull(text, "Text must not be null");
Matcher matcher = VERSION_REGEX.matcher(text.trim());
if (!matcher.matches()) {
throw new InvalidVersionException("Could not determine version based on '"
+ text + "': version format " + "is Minor.Major.Patch.Qualifier "
+ "(e.g. 1.0.5.RELEASE)");
throw new InvalidVersionException(
"Could not determine version based on '" + text + "': version format "
+ "is Minor.Major.Patch.Qualifier " + "(e.g. 1.0.5.RELEASE)");
}
Integer major = Integer.valueOf(matcher.group(1));
String minor = matcher.group(2);
@@ -88,8 +89,8 @@ public class VersionParser {
Integer minorInt = "x".equals(minor) ? null : Integer.parseInt(minor);
Version latest = findLatestVersion(major, minorInt, qualifier);
if (latest == null) {
return new Version(major, ("x".equals(minor) ? 999
: Integer.parseInt(minor)),
return new Version(major,
("x".equals(minor) ? 999 : Integer.parseInt(minor)),
("x".equals(patch) ? 999 : Integer.parseInt(patch)), qualifier);
}
return new Version(major, latest.getMinor(), latest.getPatch(),
@@ -137,7 +138,8 @@ public class VersionParser {
Version lowerVersion = parse(matcher.group(2));
Version higherVersion = parse(matcher.group(3));
boolean higherInclusive = matcher.group(4).equals("]");
return new VersionRange(lowerVersion, lowerInclusive, higherVersion, higherInclusive);
return new VersionRange(lowerVersion, lowerInclusive, higherVersion,
higherInclusive);
}
private Version findLatestVersion(Integer major, Integer minor,

View File

@@ -25,8 +25,8 @@ import com.fasterxml.jackson.annotation.JsonValue;
import org.springframework.util.StringUtils;
/**
* Represents a valid property for a version. A property must be lower case and
* can define a dot or an hyphen to separate words. For instance, "foo-acme.version",
* Represents a valid property for a version. A property must be lower case and can define
* a dot or an hyphen to separate words. For instance, "foo-acme.version",
* "foo.acme.version" or "foo-acme-version" are valid properties.
*
* @author Stephane Nicoll
@@ -47,7 +47,7 @@ public class VersionProperty implements Serializable, Comparable<VersionProperty
public String toCamelCaseFormat() {
String[] tokens = this.property.split("\\-|\\.");
StringBuilder sb = new StringBuilder();
for (int i = 0; i < tokens.length; i++) {
for (int i = 0; i < tokens.length; i++) {
String part = tokens[i];
if (i > 0) {
part = StringUtils.capitalize(part);
@@ -62,12 +62,11 @@ public class VersionProperty implements Serializable, Comparable<VersionProperty
return this.property;
}
private static String validateFormat(String property) {
for (char c : property.toCharArray()) {
if (Character.isUpperCase(c)) {
throw new IllegalArgumentException(
"Invalid property '" + property + "', must not contain upper case");
throw new IllegalArgumentException("Invalid property '" + property
+ "', must not contain upper case");
}
if (!Character.isLetterOrDigit(c) && !SUPPORTED_CHARS.contains(c)) {
throw new IllegalArgumentException(
@@ -89,8 +88,10 @@ public class VersionProperty implements Serializable, Comparable<VersionProperty
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
VersionProperty that = (VersionProperty) o;

View File

@@ -19,16 +19,16 @@ package io.spring.initializr.util;
import org.springframework.util.Assert;
/**
* Define a {@link Version} range. A square bracket "[" or "]" denotes an inclusive
* end of the range and a round bracket "(" or ")" denotes an exclusive end of the
* range. A range can also be unbounded by defining a a single {@link Version}. The
* examples below make this clear.
* Define a {@link Version} range. A square bracket "[" or "]" denotes an inclusive end of
* the range and a round bracket "(" or ")" denotes an exclusive end of the range. A range
* can also be unbounded by defining a a single {@link Version}. The examples below make
* this clear.
*
* <ul>
* <li>"[1.2.0.RELEASE,1.3.0.RELEASE)" version 1.2.0 and any version after
* this, up to, but not including, version 1.3.0.</li>
* <li>"(2.0.0.RELEASE,3.2.0.RELEASE]" any version after 2.0.0 up to and
* including version 3.2.0.</li>
* <li>"[1.2.0.RELEASE,1.3.0.RELEASE)" version 1.2.0 and any version after this, up to,
* but not including, version 1.3.0.</li>
* <li>"(2.0.0.RELEASE,3.2.0.RELEASE]" any version after 2.0.0 up to and including version
* 3.2.0.</li>
* <li>"1.4.5.RELEASE", version 1.4.5 and all later versions.</li>
* </ul>
*
@@ -37,8 +37,11 @@ import org.springframework.util.Assert;
public class VersionRange {
final Version lowerVersion;
final boolean lowerInclusive;
final Version higherVersion;
final boolean higherInclusive;
// For Jackson
@@ -60,8 +63,8 @@ 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.
* Specify if the {@link Version} matches this range. Returns {@code true} if the
* version is contained within this range, {@code false} otherwise.
*/
public boolean match(Version version) {
Assert.notNull(version, "Version must not be null");

View File

@@ -101,17 +101,18 @@ public abstract class AbstractProjectGeneratorTests {
}
protected void applyMetadata(InitializrMetadata metadata) {
projectGenerator.setMetadataProvider(new SimpleInitializrMetadataProvider(metadata));
projectGenerator
.setMetadataProvider(new SimpleInitializrMetadataProvider(metadata));
}
protected void verifyProjectSuccessfulEventFor(ProjectRequest request) {
verify(eventPublisher, times(1)).publishEvent(
argThat(new ProjectGeneratedEventMatcher(request)));
verify(eventPublisher, times(1))
.publishEvent(argThat(new ProjectGeneratedEventMatcher(request)));
}
protected void verifyProjectFailedEventFor(ProjectRequest request, Exception ex) {
verify(eventPublisher, times(1)).publishEvent(
argThat(new ProjectFailedEventMatcher(request, ex)));
verify(eventPublisher, times(1))
.publishEvent(argThat(new ProjectFailedEventMatcher(request, ex)));
}
protected static class ProjectGeneratedEventMatcher
@@ -127,6 +128,7 @@ public abstract class AbstractProjectGeneratorTests {
public boolean matches(ProjectGeneratedEvent event) {
return request.equals(event.getProjectRequest());
}
}
private static class ProjectFailedEventMatcher
@@ -146,6 +148,7 @@ public abstract class AbstractProjectGeneratorTests {
return request.equals(event.getProjectRequest())
&& cause.equals(event.getCause());
}
}
}

View File

@@ -106,13 +106,12 @@ public class CommandLineHelpGeneratorTests {
@Test
public void generateSpringBootCliCapabilities() {
InitializrMetadata metadata = InitializrMetadataTestBuilder
.withDefaults()
.addDependencyGroup("test",
createDependency("id-b", "depB"),
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
.addDependencyGroup("test", createDependency("id-b", "depB"),
createDependency("id-a", "depA", "and some description"))
.build();
String content = generator.generateSpringBootCliCapabilities(metadata, "https://fake-service");
String content = generator.generateSpringBootCliCapabilities(metadata,
"https://fake-service");
assertThat(content, containsString("| Id"));
assertThat(content, containsString("| Tags"));
assertThat(content, containsString("id-a | and some description |"));
@@ -134,11 +133,10 @@ public class CommandLineHelpGeneratorTests {
Dependency second = Dependency.withId("second");
second.setDescription("second desc");
second.setVersionRange(" [1.2.0.RELEASE,1.3.0.M1) ");
InitializrMetadata metadata = InitializrMetadataTestBuilder
.withDefaults()
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
.addDependencyGroup("test", first, second).build();
String content = generator.generateSpringBootCliCapabilities(
metadata, "https://fake-service");
String content = generator.generateSpringBootCliCapabilities(metadata,
"https://fake-service");
assertThat(content, containsString(
"| first | first desc | >=1.2.0.RELEASE |"));
assertThat(content, containsString(

View File

@@ -73,12 +73,12 @@ public class CustomProjectGeneratorTests extends AbstractProjectGeneratorTests {
InOrder inOrder = Mockito.inOrder(eventPublisher, customFileGenerated);
inOrder.verify(customFileGenerated, times(1)).run();
inOrder.verify(eventPublisher, times(1)).publishEvent(
argThat(new ProjectGeneratedEventMatcher(request)));
inOrder.verify(eventPublisher, times(1))
.publishEvent(argThat(new ProjectGeneratedEventMatcher(request)));
}
private static class MyProjectGenerator extends ProjectGenerator {
private Runnable customFileGenerated = mock(Runnable.class);
@Override
@@ -92,6 +92,7 @@ public class CustomProjectGeneratorTests extends AbstractProjectGeneratorTests {
}
return dir;
}
}
}

View File

@@ -44,7 +44,9 @@ public class ProjectGeneratorBuildTests extends AbstractProjectGeneratorTests {
}
private final String build;
private final String fileName;
private final String assertFileName;
public ProjectGeneratorBuildTests(String build, String fileName) {
@@ -96,17 +98,17 @@ public class ProjectGeneratorBuildTests extends AbstractProjectGeneratorTests {
request.setPackaging("war");
request.setLanguage(language);
ProjectAssert project = generateProject(request);
project.sourceCodeAssert(fileName).equalsTo(new ClassPathResource(
"project/" + language + "/war/" + assertFileName));
project.sourceCodeAssert(fileName).equalsTo(
new ClassPathResource("project/" + language + "/war/" + assertFileName));
}
@Test
public void versionOverride() {
ProjectRequest request = createProjectRequest("web");
request.getBuildProperties().getVersions().put(
new VersionProperty("spring-foo.version"), () -> "0.1.0.RELEASE");
request.getBuildProperties().getVersions().put(
new VersionProperty("spring-bar.version"), () -> "0.2.0.RELEASE");
request.getBuildProperties().getVersions()
.put(new VersionProperty("spring-foo.version"), () -> "0.1.0.RELEASE");
request.getBuildProperties().getVersions()
.put(new VersionProperty("spring-bar.version"), () -> "0.2.0.RELEASE");
ProjectAssert project = generateProject(request);
project.sourceCodeAssert(fileName).equalsTo(new ClassPathResource(
"project/" + build + "/version-override-" + assertFileName));
@@ -133,8 +135,7 @@ public class ProjectGeneratorBuildTests extends AbstractProjectGeneratorTests {
foo.setScope(Dependency.SCOPE_COMPILE_ONLY);
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
.addDependencyGroup("core", "web", "data-jpa")
.addDependencyGroup("foo", foo)
.build();
.addDependencyGroup("foo", foo).build();
applyMetadata(metadata);
ProjectRequest request = createProjectRequest("foo", "web", "data-jpa");
ProjectAssert project = generateProject(request);
@@ -146,24 +147,19 @@ public class ProjectGeneratorBuildTests extends AbstractProjectGeneratorTests {
public void bomWithOrdering() {
Dependency foo = Dependency.withId("foo", "org.acme", "foo");
foo.setBom("foo-bom");
BillOfMaterials barBom = BillOfMaterials.create("org.acme", "bar-bom",
"1.0");
BillOfMaterials barBom = BillOfMaterials.create("org.acme", "bar-bom", "1.0");
barBom.setOrder(50);
BillOfMaterials bizBom = BillOfMaterials.create("org.acme", "biz-bom");
bizBom.setOrder(40);
bizBom.getAdditionalBoms().add("bar-bom");
bizBom.getMappings().add(BillOfMaterials.Mapping.create("1.0.0.RELEASE", "1.0"));
BillOfMaterials fooBom = BillOfMaterials.create("org.acme", "foo-bom",
"1.0");
BillOfMaterials fooBom = BillOfMaterials.create("org.acme", "foo-bom", "1.0");
fooBom.setOrder(20);
fooBom.getAdditionalBoms().add("biz-bom");
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
.addDependencyGroup("foo", foo)
.addBom("foo-bom", fooBom)
.addBom("bar-bom", barBom)
.addBom("biz-bom", bizBom)
.build();
.addDependencyGroup("foo", foo).addBom("foo-bom", fooBom)
.addBom("bar-bom", barBom).addBom("biz-bom", bizBom).build();
applyMetadata(metadata);
ProjectRequest request = createProjectRequest("foo");
ProjectAssert project = generateProject(request);
@@ -198,7 +194,8 @@ public class ProjectGeneratorBuildTests extends AbstractProjectGeneratorTests {
request.setBootVersion("2.0.0.M5");
ProjectAssert project = generateProject(request);
project.sourceCodeAssert("src/main/kotlin/com/example/demo/DemoApplication.kt")
.equalsTo(new ClassPathResource("project/kotlin/spring-boot-2.0/DemoApplicationLegacy.kt.gen"));
.equalsTo(new ClassPathResource(
"project/kotlin/spring-boot-2.0/DemoApplicationLegacy.kt.gen"));
project.sourceCodeAssert(fileName).equalsTo(new ClassPathResource(
"project/" + build + "/kotlin-springboot2-legacy-" + assertFileName));
}
@@ -210,7 +207,8 @@ public class ProjectGeneratorBuildTests extends AbstractProjectGeneratorTests {
request.setBootVersion("2.0.0.M6");
ProjectAssert project = generateProject(request);
project.sourceCodeAssert("src/main/kotlin/com/example/demo/DemoApplication.kt")
.equalsTo(new ClassPathResource("project/kotlin/spring-boot-2.0/DemoApplication.kt.gen"));
.equalsTo(new ClassPathResource(
"project/kotlin/spring-boot-2.0/DemoApplication.kt.gen"));
project.sourceCodeAssert(fileName).equalsTo(new ClassPathResource(
"project/" + build + "/kotlin-springboot2-" + assertFileName));
}

View File

@@ -43,7 +43,9 @@ public class ProjectGeneratorLanguageTests extends AbstractProjectGeneratorTests
}
private final String language;
private final String extension;
private final String expectedExtension;
public ProjectGeneratorLanguageTests(String language, String extension) {
@@ -87,8 +89,8 @@ public class ProjectGeneratorLanguageTests extends AbstractProjectGeneratorTests
request.setLanguage(language);
ProjectAssert project = generateProject(request);
project.sourceCodeAssert(
"src/test/" + language + "/com/example/demo/DemoApplicationTests." + extension)
project.sourceCodeAssert("src/test/" + language
+ "/com/example/demo/DemoApplicationTests." + extension)
.equalsTo(new ClassPathResource("project/" + language
+ "/standard/DemoApplicationTests." + expectedExtension));
}
@@ -99,8 +101,8 @@ public class ProjectGeneratorLanguageTests extends AbstractProjectGeneratorTests
request.setLanguage(language);
ProjectAssert project = generateProject(request);
project.sourceCodeAssert(
"src/test/" + language + "/com/example/demo/DemoApplicationTests." + extension)
project.sourceCodeAssert("src/test/" + language
+ "/com/example/demo/DemoApplicationTests." + extension)
.equalsTo(new ClassPathResource("project/" + language
+ "/standard/DemoApplicationTestsWeb." + expectedExtension));
}
@@ -125,7 +127,6 @@ public class ProjectGeneratorLanguageTests extends AbstractProjectGeneratorTests
testServletInitializr("2.0.0.M3", "spring-boot-2.0");
}
private void testServletInitializr(String bootVersion, String expectedOutput) {
ProjectRequest request = createProjectRequest();
request.setLanguage(language);
@@ -134,10 +135,10 @@ public class ProjectGeneratorLanguageTests extends AbstractProjectGeneratorTests
request.setBootVersion(bootVersion);
}
ProjectAssert project = generateProject(request);
project.sourceCodeAssert(
"src/main/" + language + "/com/example/demo/ServletInitializer." + extension)
.equalsTo(new ClassPathResource("project/" + language
+ "/" + expectedOutput + "/ServletInitializer." + expectedExtension));
project.sourceCodeAssert("src/main/" + language
+ "/com/example/demo/ServletInitializer." + extension)
.equalsTo(new ClassPathResource("project/" + language + "/"
+ expectedOutput + "/ServletInitializer." + expectedExtension));
}
@Test
@@ -147,8 +148,8 @@ public class ProjectGeneratorLanguageTests extends AbstractProjectGeneratorTests
request.setBootVersion("1.4.0.M1");
ProjectAssert project = generateProject(request);
project.sourceCodeAssert(
"src/test/" + language + "/com/example/demo/DemoApplicationTests." + extension)
project.sourceCodeAssert("src/test/" + language
+ "/com/example/demo/DemoApplicationTests." + extension)
.equalsTo(new ClassPathResource("project/" + language
+ "/standard/DemoApplicationTests." + expectedExtension));
}
@@ -160,8 +161,8 @@ public class ProjectGeneratorLanguageTests extends AbstractProjectGeneratorTests
request.setBootVersion("1.4.0.M2");
ProjectAssert project = generateProject(request);
project.sourceCodeAssert(
"src/test/" + language + "/com/example/demo/DemoApplicationTests." + extension)
project.sourceCodeAssert("src/test/" + language
+ "/com/example/demo/DemoApplicationTests." + extension)
.equalsTo(new ClassPathResource("project/" + language
+ "/spring-boot-1.4/DemoApplicationTests." + expectedExtension));
}
@@ -173,8 +174,8 @@ public class ProjectGeneratorLanguageTests extends AbstractProjectGeneratorTests
request.setBootVersion("1.4.0.M2");
ProjectAssert project = generateProject(request);
project.sourceCodeAssert(
"src/test/" + language + "/com/example/demo/DemoApplicationTests." + extension)
project.sourceCodeAssert("src/test/" + language
+ "/com/example/demo/DemoApplicationTests." + extension)
.equalsTo(new ClassPathResource("project/" + language
+ "/spring-boot-1.4/DemoApplicationTests." + expectedExtension));
}

View File

@@ -77,7 +77,8 @@ public class ProjectGeneratorTests extends AbstractProjectGeneratorTests {
ProjectAssert gradleProject = generateProject(request).isGradleProject();
gradleProject.gradleBuildAssert()
.contains("compile('org.springframework.boot:spring-boot-starter-web')")
.contains("testCompile('org.springframework.boot:spring-boot-starter-test')");
.contains(
"testCompile('org.springframework.boot:spring-boot-starter-test')");
gradleProject.gradleSettingsAssert().hasProjectName("demo");
verifyProjectSuccessfulEventFor(request);
}
@@ -181,8 +182,7 @@ public class ProjectGeneratorTests extends AbstractProjectGeneratorTests {
request.setType("gradle-project");
generateProject(request).isJavaWarProject().isGradleProject().gradleBuildAssert()
// This is tagged as web facet so it brings the web one
.contains("apply plugin: 'war'")
.contains("compile('org.foo:thymeleaf')")
.contains("apply plugin: 'war'").contains("compile('org.foo:thymeleaf')")
.doesNotContain(
"compile('org.springframework.boot:spring-boot-starter-web')")
.contains(
@@ -196,9 +196,8 @@ public class ProjectGeneratorTests extends AbstractProjectGeneratorTests {
public void gradleWarPomWithoutWebFacet() {
ProjectRequest request = createProjectRequest("data-jpa");
request.setPackaging("war");
generateGradleBuild(request)
.contains(
"compile('org.springframework.boot:spring-boot-starter-data-jpa')")
generateGradleBuild(request).contains(
"compile('org.springframework.boot:spring-boot-starter-data-jpa')")
// Added by warpackaging
.contains("compile('org.springframework.boot:spring-boot-starter-web')")
.contains(
@@ -213,8 +212,7 @@ public class ProjectGeneratorTests extends AbstractProjectGeneratorTests {
ProjectRequest request = createProjectRequest("web");
request.setGroupId("org.acme");
request.setArtifactId("42foo");
generateProject(request)
.isJavaProject("org/acme/foo", "DemoApplication");
generateProject(request).isJavaProject("org/acme/foo", "DemoApplication");
}
@Test
@@ -235,10 +233,8 @@ public class ProjectGeneratorTests extends AbstractProjectGeneratorTests {
}
private void assertProjectWithPackageNameWithVersion(ProjectRequest request) {
generateProject(request)
.isJavaProject("org/acme/foo145", "DemoApplication")
.sourceCodeAssert(
"src/main/java/org/acme/foo145/DemoApplication.java")
generateProject(request).isJavaProject("org/acme/foo145", "DemoApplication")
.sourceCodeAssert("src/main/java/org/acme/foo145/DemoApplication.java")
.contains("package org.acme.foo145;");
}
@@ -769,8 +765,8 @@ public class ProjectGeneratorTests extends AbstractProjectGeneratorTests {
public void buildPropertiesMaven() {
ProjectRequest request = createProjectRequest("web");
request.getBuildProperties().getMaven().put("name", () -> "test");
request.getBuildProperties().getVersions().put(
new VersionProperty("foo.version"), () -> "1.2.3");
request.getBuildProperties().getVersions().put(new VersionProperty("foo.version"),
() -> "1.2.3");
request.getBuildProperties().getGradle().put("ignore.property", () -> "yes");
generateMavenPom(request).hasProperty("name", "test")
@@ -781,14 +777,12 @@ public class ProjectGeneratorTests extends AbstractProjectGeneratorTests {
public void buildPropertiesGradle() {
ProjectRequest request = createProjectRequest("web");
request.getBuildProperties().getGradle().put("name", () -> "test");
request.getBuildProperties().getVersions().put(
new VersionProperty("foo.version"), () -> "1.2.3");
request.getBuildProperties().getVersions().put(new VersionProperty("foo.version"),
() -> "1.2.3");
request.getBuildProperties().getMaven().put("ignore.property", () -> "yes");
generateGradleBuild(request).contains("name = 'test'")
.contains("ext {")
.contains("fooVersion = '1.2.3'")
.doesNotContain("ignore.property");
generateGradleBuild(request).contains("name = 'test'").contains("ext {")
.contains("fooVersion = '1.2.3'").doesNotContain("ignore.property");
}
@Test
@@ -847,12 +841,10 @@ public class ProjectGeneratorTests extends AbstractProjectGeneratorTests {
.addDependencyGroup("sample", depOne, depTwo).build();
applyMetadata(metadata);
ProjectRequest request = createProjectRequest("one", "web", "two", "data-jpa");
assertThat(generateGradleBuild(request).getGradleBuild())
.containsSubsequence(
"compile('org.springframework.boot:spring-boot-starter-data-jpa')",
"compile('org.springframework.boot:spring-boot-starter-web')",
"compile('com.example:second:1.2.3')",
"compile('org.acme:first:1.2.3')");
assertThat(generateGradleBuild(request).getGradleBuild()).containsSubsequence(
"compile('org.springframework.boot:spring-boot-starter-data-jpa')",
"compile('org.springframework.boot:spring-boot-starter-web')",
"compile('com.example:second:1.2.3')", "compile('org.acme:first:1.2.3')");
}
@Test

View File

@@ -40,12 +40,11 @@ import static org.junit.Assert.assertEquals;
public class ProjectRequestResolverTests {
private InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
.addDependencyGroup("test", "web", "security", "data-jpa")
.build();
.addDependencyGroup("test", "web", "security", "data-jpa").build();
final List<ProjectRequestPostProcessor> postProcessors = new ArrayList<>();
final GenericProjectRequestPostProcessor processor =
new GenericProjectRequestPostProcessor();
final GenericProjectRequestPostProcessor processor = new GenericProjectRequestPostProcessor();
@Before
public void setup() {
@@ -98,6 +97,7 @@ public class ProjectRequestResolverTests {
implements ProjectRequestPostProcessor {
final Map<String, Object> before = new LinkedHashMap<>();
final Map<String, Object> after = new LinkedHashMap<>();
@Override

View File

@@ -40,8 +40,8 @@ public class ProjectRequestTests {
@Rule
public final ExpectedException thrown = ExpectedException.none();
private InitializrMetadata metadata = InitializrMetadataTestBuilder
.withDefaults().build();
private InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
.build();
@Test
public void initializeGroupIdAndArtifactId() {
@@ -163,10 +163,10 @@ public class ProjectRequestTests {
@Test
public void resolveDependencyVersion() {
Dependency dependency = createDependency("org.foo", "bar", "1.2.0.RELEASE");
dependency.getMappings().add(Mapping.create(
"[1.0.0.RELEASE, 1.1.0.RELEASE)", null, null, "0.1.0.RELEASE"));
dependency.getMappings().add(Mapping.create(
"1.1.0.RELEASE", null, null, "0.2.0.RELEASE"));
dependency.getMappings().add(Mapping.create("[1.0.0.RELEASE, 1.1.0.RELEASE)",
null, null, "0.1.0.RELEASE"));
dependency.getMappings()
.add(Mapping.create("1.1.0.RELEASE", null, null, "0.2.0.RELEASE"));
metadata = InitializrMetadataTestBuilder.withDefaults()
.addDependencyGroup("code", dependency).build();
@@ -310,9 +310,9 @@ public class ProjectRequestTests {
bom.getAdditionalBoms().add("bar-bom");
BillOfMaterials additionalBom = BillOfMaterials.create("com.example", "bar-bom",
"1.1.0");
metadata = InitializrMetadataTestBuilder.withDefaults()
.addBom("foo-bom", bom).addBom("bar-bom", additionalBom)
.addDependencyGroup("test", dependency).build();
metadata = InitializrMetadataTestBuilder.withDefaults().addBom("foo-bom", bom)
.addBom("bar-bom", additionalBom).addDependencyGroup("test", dependency)
.build();
ProjectRequest request = initProjectRequest();
request.getStyle().add("foo");
request.resolve(metadata);
@@ -332,8 +332,8 @@ public class ProjectRequestTests {
bom.getAdditionalBoms().add("bar-bom");
BillOfMaterials additionalBom = BillOfMaterials.create("com.example", "bar-bom",
"1.1.0");
metadata = InitializrMetadataTestBuilder.withDefaults()
.addBom("foo-bom", bom).addBom("bar-bom", additionalBom)
metadata = InitializrMetadataTestBuilder.withDefaults().addBom("foo-bom", bom)
.addBom("bar-bom", additionalBom)
.addDependencyGroup("test", dependency, anotherDependency).build();
ProjectRequest request = initProjectRequest();
request.getStyle().addAll(Arrays.asList("foo", "bar"));
@@ -351,8 +351,7 @@ public class ProjectRequestTests {
dependency.setRepository("foo-repo");
BillOfMaterials bom = BillOfMaterials.create("com.example", "foo-bom", "1.0.0");
bom.getRepositories().add("bar-repo");
metadata = InitializrMetadataTestBuilder.withDefaults()
.addBom("foo-bom", bom)
metadata = InitializrMetadataTestBuilder.withDefaults().addBom("foo-bom", bom)
.addRepository("foo-repo", "foo-repo", "http://example.com/foo", false)
.addRepository("bar-repo", "bar-repo", "http://example.com/bar", false)
.addDependencyGroup("test", dependency).build();
@@ -379,8 +378,7 @@ public class ProjectRequestTests {
bom.getRepositories().add("bar-repo");
Dependency anotherDependency = Dependency.withId("bar");
anotherDependency.setRepository("bar-repo");
metadata = InitializrMetadataTestBuilder.withDefaults()
.addBom("foo-bom", bom)
metadata = InitializrMetadataTestBuilder.withDefaults().addBom("foo-bom", bom)
.addRepository("foo-repo", "foo-repo", "http://example.com/foo", false)
.addRepository("bar-repo", "bar-repo", "http://example.com/bar", false)
.addDependencyGroup("test", dependency, anotherDependency).build();
@@ -423,4 +421,5 @@ public class ProjectRequestTests {
assertEquals(artifactId, actual.getArtifactId());
assertEquals(version, actual.getVersion());
}
}

View File

@@ -231,15 +231,16 @@ public class DependencyTests {
dependency.getFacets().add("web");
dependency.getMappings().add(Dependency.Mapping
.create("[1.1.0.RELEASE, 1.1.x.RELEASE]", null, null, "0.1.0.RELEASE"));
dependency.getMappings().add(Dependency.Mapping
.create("[1.1.x.BUILD-SNAPSHOT, 1.2.0.RELEASE)", null, null, "0.2.0.RELEASE"));
dependency.getMappings().add(Dependency.Mapping.create(
"[1.1.x.BUILD-SNAPSHOT, 1.2.0.RELEASE)", null, null, "0.2.0.RELEASE"));
dependency.resolve();
dependency.updateVersionRanges(new VersionParser(Arrays.asList(
Version.parse("1.1.5.RELEASE"), Version.parse("1.1.6.BUILD-SNAPSHOT"))));
validateResolvedWebDependency(dependency.resolve(Version.parse("1.1.5.RELEASE")),
"org.springframework.boot", "spring-boot-starter-web", "0.1.0.RELEASE");
validateResolvedWebDependency(dependency.resolve(Version.parse("1.1.6.BUILD-SNAPSHOT")),
validateResolvedWebDependency(
dependency.resolve(Version.parse("1.1.6.BUILD-SNAPSHOT")),
"org.springframework.boot", "spring-boot-starter-web", "0.2.0.RELEASE");
validateResolvedWebDependency(dependency.resolve(Version.parse("2.1.3.M1")),
"org.springframework.boot", "spring-boot-starter-web", "0.3.0.RELEASE"); // default
@@ -250,7 +251,8 @@ public class DependencyTests {
"org.springframework.boot", "spring-boot-starter-web", "0.1.0.RELEASE");
validateResolvedWebDependency(dependency.resolve(Version.parse("1.1.6.RELEASE")),
"org.springframework.boot", "spring-boot-starter-web", "0.1.0.RELEASE");
validateResolvedWebDependency(dependency.resolve(Version.parse("1.1.7.BUILD-SNAPSHOT")),
validateResolvedWebDependency(
dependency.resolve(Version.parse("1.1.7.BUILD-SNAPSHOT")),
"org.springframework.boot", "spring-boot-starter-web", "0.2.0.RELEASE");
validateResolvedWebDependency(dependency.resolve(Version.parse("2.1.3.M1")),
"org.springframework.boot", "spring-boot-starter-web", "0.3.0.RELEASE"); // default
@@ -273,8 +275,8 @@ public class DependencyTests {
private static void validateResolvedWebDependency(Dependency dependency,
String expectedGroupId, String expectedArtifactId, String expectedVersion) {
validateResolvedDependency(dependency, "web", expectedGroupId,
expectedArtifactId, expectedVersion);
validateResolvedDependency(dependency, "web", expectedGroupId, expectedArtifactId,
expectedVersion);
assertEquals(2, dependency.getKeywords().size());
assertEquals(1, dependency.getAliases().size());
assertEquals(1, dependency.getFacets().size());

View File

@@ -39,123 +39,146 @@ public class InitializrConfigurationTests {
@Test
public void generateApplicationNameSimpleApplication() {
assertEquals("DemoApplication", this.properties.generateApplicationName("demoApplication"));
assertEquals("DemoApplication",
this.properties.generateApplicationName("demoApplication"));
}
@Test
public void generateApplicationNameSimpleCamelCase() {
assertEquals("MyDemoApplication", this.properties.generateApplicationName("myDemo"));
assertEquals("MyDemoApplication",
this.properties.generateApplicationName("myDemo"));
}
@Test
public void generateApplicationNameSimpleUnderscore() {
assertEquals("MyDemoApplication", this.properties.generateApplicationName("my_demo"));
assertEquals("MyDemoApplication",
this.properties.generateApplicationName("my_demo"));
}
@Test
public void generateApplicationNameSimpleColon() {
assertEquals("MyDemoApplication", this.properties.generateApplicationName("my:demo"));
assertEquals("MyDemoApplication",
this.properties.generateApplicationName("my:demo"));
}
@Test
public void generateApplicationNameSimpleSpace() {
assertEquals("MyDemoApplication", this.properties.generateApplicationName("my demo"));
assertEquals("MyDemoApplication",
this.properties.generateApplicationName("my demo"));
}
@Test
public void generateApplicationNameSimpleDash() {
assertEquals("MyDemoApplication", this.properties.generateApplicationName("my-demo"));
assertEquals("MyDemoApplication",
this.properties.generateApplicationName("my-demo"));
}
@Test
public void generateApplicationNameUpperCaseUnderscore() {
assertEquals("MyDemoApplication", this.properties.generateApplicationName("MY_DEMO"));
assertEquals("MyDemoApplication",
this.properties.generateApplicationName("MY_DEMO"));
}
@Test
public void generateApplicationNameUpperCaseDash() {
assertEquals("MyDemoApplication", this.properties.generateApplicationName("MY-DEMO"));
assertEquals("MyDemoApplication",
this.properties.generateApplicationName("MY-DEMO"));
}
@Test
public void generateApplicationNameMultiSpaces() {
assertEquals("MyDemoApplication", this.properties.generateApplicationName(" my demo "));
assertEquals("MyDemoApplication",
this.properties.generateApplicationName(" my demo "));
}
@Test
public void generateApplicationNameMultiSpacesUpperCase() {
assertEquals("MyDemoApplication", this.properties.generateApplicationName(" MY DEMO "));
assertEquals("MyDemoApplication",
this.properties.generateApplicationName(" MY DEMO "));
}
@Test
public void generateApplicationNameNull() {
assertEquals(this.properties.getEnv().getFallbackApplicationName(), this.properties.generateApplicationName(null));
assertEquals(this.properties.getEnv().getFallbackApplicationName(),
this.properties.generateApplicationName(null));
}
@Test
public void generateApplicationNameInvalidStartCharacter() {
assertEquals(this.properties.getEnv().getFallbackApplicationName(), this.properties.generateApplicationName("1MyDemo"));
assertEquals(this.properties.getEnv().getFallbackApplicationName(),
this.properties.generateApplicationName("1MyDemo"));
}
@Test
public void generateApplicationNameInvalidPartCharacter() {
assertEquals(this.properties.getEnv().getFallbackApplicationName(), this.properties.generateApplicationName("MyDe|mo"));
assertEquals(this.properties.getEnv().getFallbackApplicationName(),
this.properties.generateApplicationName("MyDe|mo"));
}
@Test
public void generateApplicationNameInvalidApplicationName() {
assertEquals(this.properties.getEnv().getFallbackApplicationName(), this.properties.generateApplicationName("SpringBoot"));
assertEquals(this.properties.getEnv().getFallbackApplicationName(),
this.properties.generateApplicationName("SpringBoot"));
}
@Test
public void generateApplicationNameAnotherInvalidApplicationName() {
assertEquals(this.properties.getEnv().getFallbackApplicationName(), this.properties.generateApplicationName("Spring"));
assertEquals(this.properties.getEnv().getFallbackApplicationName(),
this.properties.generateApplicationName("Spring"));
}
@Test
public void generatePackageNameSimple() {
assertEquals("com.foo", this.properties.cleanPackageName("com.foo", "com.example"));
assertEquals("com.foo",
this.properties.cleanPackageName("com.foo", "com.example"));
}
@Test
public void generatePackageNameSimpleUnderscore() {
assertEquals("com.my_foo", this.properties.cleanPackageName("com.my_foo", "com.example"));
assertEquals("com.my_foo",
this.properties.cleanPackageName("com.my_foo", "com.example"));
}
@Test
public void generatePackageNameSimpleColon() {
assertEquals("com.foo", this.properties.cleanPackageName("com:foo", "com.example"));
assertEquals("com.foo",
this.properties.cleanPackageName("com:foo", "com.example"));
}
@Test
public void generatePackageNameMultipleDashers() {
assertEquals("com.foobar", this.properties.cleanPackageName("com.foo--bar", "com.example"));
assertEquals("com.foobar",
this.properties.cleanPackageName("com.foo--bar", "com.example"));
}
@Test
public void generatePackageNameMultipleSpaces() {
assertEquals("com.foo", this.properties.cleanPackageName(" com foo ", "com.example"));
assertEquals("com.foo",
this.properties.cleanPackageName(" com foo ", "com.example"));
}
@Test
public void generatePackageNameNull() {
assertEquals("com.example", this.properties.cleanPackageName(null, "com.example"));
assertEquals("com.example",
this.properties.cleanPackageName(null, "com.example"));
}
@Test
public void generatePackageNameInvalidStartCharacter() {
assertEquals("com.foo", this.properties.cleanPackageName("0com.foo", "com.example"));
assertEquals("com.foo",
this.properties.cleanPackageName("0com.foo", "com.example"));
}
@Test
public void generatePackageNameVersion() {
assertEquals("com.foo.test145", this.properties.cleanPackageName(
"com.foo.test-1.4.5", "com.example"));
assertEquals("com.foo.test145",
this.properties.cleanPackageName("com.foo.test-1.4.5", "com.example"));
}
@Test
public void generatePackageNameInvalidPackageName() {
assertEquals("com.example", this.properties.cleanPackageName("org.springframework", "com.example"));
assertEquals("com.example",
this.properties.cleanPackageName("org.springframework", "com.example"));
}
@Test
@@ -168,8 +191,8 @@ public class InitializrConfigurationTests {
public void resolveKotlinVersionMatchingMapping() {
Kotlin kotlin = this.properties.getEnv().getKotlin();
kotlin.setDefaultVersion("1.2.3");
kotlin.getMappings().add(createKotlinVersionMapping(
"[1.4.0.RELEASE,1.5.0.RELEASE)", "1.5"));
kotlin.getMappings()
.add(createKotlinVersionMapping("[1.4.0.RELEASE,1.5.0.RELEASE)", "1.5"));
kotlin.getMappings().add(createKotlinVersionMapping("1.5.0.RELEASE", "1.6"));
kotlin.validate();
assertThat(kotlin.resolveKotlinVersion(Version.parse("1.5.3.RELEASE")))
@@ -180,15 +203,15 @@ public class InitializrConfigurationTests {
public void resolveKotlinVersionUsingDefault() {
Kotlin kotlin = this.properties.getEnv().getKotlin();
kotlin.setDefaultVersion("1.2.3");
kotlin.getMappings().add(createKotlinVersionMapping(
"[1.4.0.RELEASE,1.5.0.RELEASE)", "1.5"));
kotlin.getMappings()
.add(createKotlinVersionMapping("[1.4.0.RELEASE,1.5.0.RELEASE)", "1.5"));
kotlin.validate();
assertThat(kotlin.resolveKotlinVersion(Version.parse("1.3.2.RELEASE")))
.isEqualTo("1.2.3");
}
private Kotlin.Mapping createKotlinVersionMapping(String versionRange,
String kotlinVersion){
String kotlinVersion) {
Kotlin.Mapping mapping = new Kotlin.Mapping();
mapping.setVersionRange(versionRange);
mapping.setVersion(kotlinVersion);

View File

@@ -166,17 +166,18 @@ public class InitializrMetadataTests {
public void updateSpringBootVersions() {
BillOfMaterials bom = BillOfMaterials.create("org.acme", "foo-bom");
bom.getMappings().add(Mapping.create("[1.2.0.RELEASE,1.3.x.RELEASE]", "1.0.0"));
bom.getMappings().add(Mapping.create("1.3.x.BUILD-SNAPSHOT", "1.1.0-BUILD-SNAPSHOT"));
bom.getMappings()
.add(Mapping.create("1.3.x.BUILD-SNAPSHOT", "1.1.0-BUILD-SNAPSHOT"));
Dependency dependency = Dependency.withId("bar");
dependency.getMappings().add(Dependency.Mapping.create(
"[1.3.0.RELEASE, 1.3.x.RELEASE]", null, null, "0.1.0.RELEASE"));
dependency.getMappings().add(Dependency.Mapping.create(
"1.3.x.BUILD-SNAPSHOT", null, null, "0.2.0.RELEASE"));
InitializrMetadata metadata = InitializrMetadataTestBuilder
.withDefaults().addDependencyGroup("test", dependency)
.addBom("foo-bom", bom)
dependency.getMappings().add(Dependency.Mapping
.create("[1.3.0.RELEASE, 1.3.x.RELEASE]", null, null, "0.1.0.RELEASE"));
dependency.getMappings().add(Dependency.Mapping.create("1.3.x.BUILD-SNAPSHOT",
null, null, "0.2.0.RELEASE"));
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
.addDependencyGroup("test", dependency).addBom("foo-bom", bom)
.setKotlinEnv("1.3",
createKotlinVersionMapping("[1.2.0.RELEASE,1.3.x.RELEASE]", "1.1"),
createKotlinVersionMapping("[1.2.0.RELEASE,1.3.x.RELEASE]",
"1.1"),
createKotlinVersionMapping("1.3.x.BUILD-SNAPSHOT", "1.2"))
.build();
@@ -187,13 +188,17 @@ public class InitializrMetadataTests {
assertThat(metadata.getConfiguration().getEnv().getBoms().get("foo-bom")
.resolve(Version.parse("1.3.6.RELEASE")).getVersion()).isEqualTo("1.0.0");
assertThat(metadata.getConfiguration().getEnv().getBoms().get("foo-bom")
.resolve(Version.parse("1.3.7.BUILD-SNAPSHOT")).getVersion()).isEqualTo("1.1.0-BUILD-SNAPSHOT");
.resolve(Version.parse("1.3.7.BUILD-SNAPSHOT")).getVersion())
.isEqualTo("1.1.0-BUILD-SNAPSHOT");
assertThat(metadata.getDependencies().get("bar")
.resolve(Version.parse("1.3.6.RELEASE")).getVersion()).isEqualTo("0.1.0.RELEASE");
.resolve(Version.parse("1.3.6.RELEASE")).getVersion())
.isEqualTo("0.1.0.RELEASE");
assertThat(metadata.getDependencies().get("bar")
.resolve(Version.parse("1.3.7.BUILD-SNAPSHOT")).getVersion()).isEqualTo("0.2.0.RELEASE");
.resolve(Version.parse("1.3.7.BUILD-SNAPSHOT")).getVersion())
.isEqualTo("0.2.0.RELEASE");
assertThat(metadata.getConfiguration().getEnv().getKotlin()
.resolveKotlinVersion(Version.parse("1.3.7.BUILD-SNAPSHOT"))).isEqualTo("1.2");
.resolveKotlinVersion(Version.parse("1.3.7.BUILD-SNAPSHOT")))
.isEqualTo("1.2");
}
@Test
@@ -208,7 +213,8 @@ public class InitializrMetadataTests {
@Test
public void stripInvalidCharsFromPackage() {
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().build();
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
.build();
metadata.getGroupId().setContent("org.acme");
metadata.getArtifactId().setContent("2foo.bar");
assertThat(metadata.getPackageName().getContent()).isEqualTo("org.acme.foo.bar");
@@ -220,7 +226,7 @@ public class InitializrMetadataTests {
}
private Kotlin.Mapping createKotlinVersionMapping(String versionRange,
String kotlinVersion){
String kotlinVersion) {
Kotlin.Mapping mapping = new Kotlin.Mapping();
mapping.setVersionRange(versionRange);
mapping.setVersion(kotlinVersion);

View File

@@ -47,11 +47,17 @@ import static org.assertj.core.api.Assertions.assertThat;
public class PomAssert {
private final XpathEngine eng;
private final Document doc;
private final ParentPom parentPom;
private final Map<String, String> properties = new LinkedHashMap<>();
private final Map<String, Dependency> dependencies = new LinkedHashMap<>();
private final Map<String, BillOfMaterials> boms = new LinkedHashMap<>();
private final Map<String, Repository> repositories = new LinkedHashMap<>();
public PomAssert(String content) {
@@ -129,8 +135,7 @@ public class PomAssert {
public PomAssert hasName(String name) {
try {
assertThat(eng.evaluate(createRootNodeXPath("name"), doc))
.isEqualTo(name);
assertThat(eng.evaluate(createRootNodeXPath("name"), doc)).isEqualTo(name);
}
catch (XpathException e) {
throw new IllegalStateException("Cannot find path", e);
@@ -392,11 +397,8 @@ public class PomAssert {
private void parseBoms() {
NodeList nodes;
try {
nodes = eng
.getMatchingNodes(
createRootNodeXPath(
"dependencyManagement/pom:dependencies/pom:dependency"),
doc);
nodes = eng.getMatchingNodes(createRootNodeXPath(
"dependencyManagement/pom:dependencies/pom:dependency"), doc);
}
catch (XpathException e) {
throw new IllegalStateException("Cannot find path", e);

View File

@@ -41,6 +41,7 @@ public class ProjectAssert {
public static final String DEFAULT_APPLICATION_NAME = "DemoApplication";
private final File dir;
private Boolean mavenProject;
public File getDir() {
@@ -70,8 +71,9 @@ public class ProjectAssert {
*/
public ProjectAssert hasBaseDir(String name) {
File projectDir = file(name);
assertThat(projectDir).describedAs("No directory %s found in %s", name,
dir.getAbsolutePath()).exists();
assertThat(projectDir)
.describedAs("No directory %s found in %s", name, dir.getAbsolutePath())
.exists();
assertThat(projectDir).isDirectory();
// Replacing the root dir so that other assertions match the root
return new ProjectAssert(projectDir);
@@ -108,8 +110,9 @@ public class ProjectAssert {
*/
public GradleSettingsAssert gradleSettingsAssert() {
try {
return new GradleSettingsAssert(StreamUtils.copyToString(
new FileInputStream(file("settings.gradle")), Charset.forName("UTF-8")));
return new GradleSettingsAssert(
StreamUtils.copyToString(new FileInputStream(file("settings.gradle")),
Charset.forName("UTF-8")));
}
catch (IOException e) {
throw new IllegalArgumentException("Cannot resolve settings.gradle", e);
@@ -212,8 +215,8 @@ public class ProjectAssert {
String packageName = expectedPackageName.replace(".", "/");
return isGenericProject(expectedPackageName, expectedApplicationName,
codeLocation, extension).hasStaticAndTemplatesResources(true)
.hasFile("src/main/" + codeLocation + "/" + packageName
+ "/ServletInitializer." + extension);
.hasFile("src/main/" + codeLocation + "/" + packageName
+ "/ServletInitializer." + extension);
}
public ProjectAssert hasStaticAndTemplatesResources(boolean web) {
@@ -244,8 +247,9 @@ public class ProjectAssert {
public ProjectAssert assertFile(String localPath, boolean exist) {
File candidate = file(localPath);
assertThat(candidate.exists()).describedAs("Invalid presence (%s) exist for %s",
exist, localPath).isEqualTo(exist);
assertThat(candidate.exists())
.describedAs("Invalid presence (%s) exist for %s", exist, localPath)
.isEqualTo(exist);
return this;
}

View File

@@ -33,6 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat;
public class SourceCodeAssert {
private final String name;
private final String content;
public SourceCodeAssert(String name, String content) {

View File

@@ -158,7 +158,8 @@ public class InitializrMetadataTestBuilder {
}
public InitializrMetadataTestBuilder addDefaultBootVersions() {
return addBootVersion("1.1.2.RELEASE", false).addBootVersion("1.2.3.RELEASE", true)
return addBootVersion("1.1.2.RELEASE", false)
.addBootVersion("1.2.3.RELEASE", true)
.addBootVersion("1.3.0.BUILD-SNAPSHOT", false);
}
@@ -180,14 +181,15 @@ public class InitializrMetadataTestBuilder {
}
public InitializrMetadataTestBuilder addBom(String id, BillOfMaterials bom) {
builder.withCustomizer(it -> it.getConfiguration().getEnv()
.getBoms().put(id, bom));
builder.withCustomizer(
it -> it.getConfiguration().getEnv().getBoms().put(id, bom));
return this;
}
public InitializrMetadataTestBuilder setGradleEnv(String dependencyManagementPluginVersion) {
builder.withCustomizer(it -> it.getConfiguration().getEnv().getGradle().
setDependencyManagementPluginVersion(dependencyManagementPluginVersion));
public InitializrMetadataTestBuilder setGradleEnv(
String dependencyManagementPluginVersion) {
builder.withCustomizer(it -> it.getConfiguration().getEnv().getGradle()
.setDependencyManagementPluginVersion(dependencyManagementPluginVersion));
return this;
}

View File

@@ -74,7 +74,8 @@ public class AgentTests {
@Test
public void checkIntelliJIDEAWithVersion() {
Agent agent = Agent.fromUserAgent("IntelliJ IDEA/144.2 (Community edition; en-us)");
Agent agent = Agent
.fromUserAgent("IntelliJ IDEA/144.2 (Community edition; en-us)");
assertThat(agent.getId(), equalTo(Agent.AgentId.INTELLIJ_IDEA));
assertThat(agent.getVersion(), is("144.2"));
}

View File

@@ -90,8 +90,7 @@ public class VersionParserTests {
List<Version> currentVersions = Arrays.asList(parser.parse("1.3.8.RELEASE"),
parser.parse("1.3.9.BUILD-SNAPSHOT"));
parser = new VersionParser(currentVersions);
assertThat(parser.parse("1.x.x.RELEASE").toString(),
equalTo("1.3.8.RELEASE"));
assertThat(parser.parse("1.x.x.RELEASE").toString(), equalTo("1.3.8.RELEASE"));
}
@Test
@@ -99,8 +98,7 @@ public class VersionParserTests {
List<Version> currentVersions = Arrays.asList(parser.parse("1.3.8.RELEASE"),
parser.parse("1.4.0.BUILD-SNAPSHOT"));
parser = new VersionParser(currentVersions);
assertThat(parser.parse("1.4.x").toString(),
equalTo("1.4.0.BUILD-SNAPSHOT"));
assertThat(parser.parse("1.4.x").toString(), equalTo("1.4.0.BUILD-SNAPSHOT"));
}
@Test

View File

@@ -34,26 +34,26 @@ public class VersionPropertyTests {
@Test
public void testStandardProperty() {
assertThat(new VersionProperty("spring-boot.version")
.toStandardFormat()).isEqualTo("spring-boot.version");
assertThat(new VersionProperty("spring-boot.version").toStandardFormat())
.isEqualTo("spring-boot.version");
}
@Test
public void testCamelCaseProperty() {
assertThat(new VersionProperty("spring-boot.version")
.toCamelCaseFormat()).isEqualTo("springBootVersion");
assertThat(new VersionProperty("spring-boot.version").toCamelCaseFormat())
.isEqualTo("springBootVersion");
}
@Test
public void testStandardPropertyWithNoSeparator() {
assertThat(new VersionProperty("springbootversion")
.toStandardFormat()).isEqualTo("springbootversion");
assertThat(new VersionProperty("springbootversion").toStandardFormat())
.isEqualTo("springbootversion");
}
@Test
public void testCamelCasePropertyWithNoSeparator() {
assertThat(new VersionProperty("springbootversion")
.toCamelCaseFormat()).isEqualTo("springbootversion");
assertThat(new VersionProperty("springbootversion").toCamelCaseFormat())
.isEqualTo("springbootversion");
}
@Test

View File

@@ -100,30 +100,34 @@ public class VersionRangeTests {
@Test
public void matchLatestVersion() {
assertThat("1.2.8.RELEASE", match("[1.2.0.RELEASE,1.2.x.BUILD-SNAPSHOT]",
new VersionParser(Collections.singletonList(
Version.parse("1.2.9.BUILD-SNAPSHOT")))));
assertThat("1.2.8.RELEASE",
match("[1.2.0.RELEASE,1.2.x.BUILD-SNAPSHOT]",
new VersionParser(Collections
.singletonList(Version.parse("1.2.9.BUILD-SNAPSHOT")))));
}
@Test
public void matchOverLatestVersion() {
assertThat("1.2.10.RELEASE", not(match("[1.2.0.RELEASE,1.2.x.BUILD-SNAPSHOT]",
new VersionParser(Collections.singletonList(
Version.parse("1.2.9.BUILD-SNAPSHOT"))))));
assertThat("1.2.10.RELEASE",
not(match("[1.2.0.RELEASE,1.2.x.BUILD-SNAPSHOT]",
new VersionParser(Collections
.singletonList(Version.parse("1.2.9.BUILD-SNAPSHOT"))))));
}
@Test
public void matchAsOfCurrentVersion() {
assertThat("1.3.5.RELEASE", match("[1.3.x.RELEASE,1.3.x.BUILD-SNAPSHOT]",
new VersionParser(Arrays.asList(Version.parse("1.3.4.RELEASE"),
Version.parse("1.3.6.BUILD-SNAPSHOT")))));
assertThat("1.3.5.RELEASE",
match("[1.3.x.RELEASE,1.3.x.BUILD-SNAPSHOT]",
new VersionParser(Arrays.asList(Version.parse("1.3.4.RELEASE"),
Version.parse("1.3.6.BUILD-SNAPSHOT")))));
}
@Test
public void matchOverAsOfCurrentVersion() {
assertThat("1.3.5.RELEASE", not(match("[1.3.x.RELEASE,1.3.x.BUILD-SNAPSHOT]",
new VersionParser(Arrays.asList(Version.parse("1.3.7.RELEASE"),
Version.parse("1.3.6.BUILD-SNAPSHOT"))))));
assertThat("1.3.5.RELEASE",
not(match("[1.3.x.RELEASE,1.3.x.BUILD-SNAPSHOT]",
new VersionParser(Arrays.asList(Version.parse("1.3.7.RELEASE"),
Version.parse("1.3.6.BUILD-SNAPSHOT"))))));
}
private static VersionRangeMatcher match(String range) {
@@ -134,10 +138,10 @@ public class VersionRangeTests {
return new VersionRangeMatcher(range, parser);
}
static class VersionRangeMatcher extends BaseMatcher<String> {
private final VersionRange range;
private final VersionParser parser;
VersionRangeMatcher(String text, VersionParser parser) {
@@ -157,6 +161,7 @@ public class VersionRangeTests {
public void describeTo(Description description) {
description.appendText(range.toString());
}
}
}

View File

@@ -31,7 +31,8 @@ import static org.hamcrest.Matchers.lessThan;
*/
public class VersionTests {
private static final VersionParser parser = new VersionParser(Collections.emptyList());
private static final VersionParser parser = new VersionParser(
Collections.emptyList());
@Test
public void equalNoQualifier() {