Fix checkstyle violations

This commit is contained in:
Phillip Webb
2018-05-31 16:10:09 -07:00
parent 45688ffcd2
commit 91a2db4176
26 changed files with 125 additions and 123 deletions

View File

@@ -172,7 +172,8 @@ public class CommandLineHelpGenerator {
.collect(Collectors.toList())) { .collect(Collectors.toList())) {
String[] data = new String[3]; String[] data = new String[3];
data[0] = dep.getId(); data[0] = dep.getId();
data[1] = dep.getDescription() != null ? dep.getDescription() : dep.getName(); data[1] = (dep.getDescription() != null ? dep.getDescription()
: dep.getName());
data[2] = dep.getVersionRequirement(); data[2] = dep.getVersionRequirement();
dependencyTable[i++] = data; dependencyTable[i++] = data;
} }
@@ -194,8 +195,8 @@ public class CommandLineHelpGenerator {
.collect(Collectors.toList())) { .collect(Collectors.toList())) {
String[] data = new String[typeTable[0].length]; String[] data = new String[typeTable[0].length];
data[0] = (type.isDefault() ? type.getId() + " *" : type.getId()); data[0] = (type.isDefault() ? type.getId() + " *" : type.getId());
data[1] = type.getDescription() != null ? type.getDescription() data[1] = (type.getDescription() != null ? type.getDescription()
: type.getName(); : type.getName());
if (addTags) { if (addTags) {
data[2] = buildTagRepresentation(type); data[2] = buildTagRepresentation(type);
} }

View File

@@ -217,8 +217,8 @@ public class ProjectGenerator {
try { try {
rootDir = File.createTempFile("tmp", "", getTemporaryDirectory()); rootDir = File.createTempFile("tmp", "", getTemporaryDirectory());
} }
catch (IOException e) { catch (IOException ex) {
throw new IllegalStateException("Cannot create temp dir", e); throw new IllegalStateException("Cannot create temp dir", ex);
} }
addTempFile(rootDir.getName(), rootDir); addTempFile(rootDir.getName(), rootDir);
rootDir.delete(); rootDir.delete();
@@ -615,8 +615,8 @@ public class ProjectGenerator {
} }
private void writeGradleWrapper(File dir, Version bootVersion) { private void writeGradleWrapper(File dir, Version bootVersion) {
String gradlePrefix = isGradle4Available(bootVersion) ? "gradle4" String gradlePrefix = (isGradle4Available(bootVersion) ? "gradle4"
: isGradle3Available(bootVersion) ? "gradle3" : "gradle"; : (isGradle3Available(bootVersion) ? "gradle3" : "gradle"));
writeTextResource(dir, "gradlew.bat", gradlePrefix + "/gradlew.bat"); writeTextResource(dir, "gradlew.bat", gradlePrefix + "/gradlew.bat");
writeTextResource(dir, "gradlew", gradlePrefix + "/gradlew"); writeTextResource(dir, "gradlew", gradlePrefix + "/gradlew");
@@ -682,8 +682,8 @@ public class ProjectGenerator {
try (OutputStream stream = new FileOutputStream(target)) { try (OutputStream stream = new FileOutputStream(target)) {
StreamUtils.copy(body, Charset.forName("UTF-8"), stream); StreamUtils.copy(body, Charset.forName("UTF-8"), stream);
} }
catch (Exception e) { catch (Exception ex) {
throw new IllegalStateException("Cannot write file " + target, e); throw new IllegalStateException("Cannot write file " + target, ex);
} }
} }
@@ -691,8 +691,8 @@ public class ProjectGenerator {
try (OutputStream stream = new FileOutputStream(target)) { try (OutputStream stream = new FileOutputStream(target)) {
StreamUtils.copy(body, stream); StreamUtils.copy(body, stream);
} }
catch (Exception e) { catch (Exception ex) {
throw new IllegalStateException("Cannot write file " + target, e); throw new IllegalStateException("Cannot write file " + target, ex);
} }
} }
@@ -757,8 +757,8 @@ public class ProjectGenerator {
} }
private String generateImport(String type, String language) { 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; return "import " + type + end;
} }

View File

@@ -134,9 +134,9 @@ public class ProjectRequest extends BasicProjectRequest {
* @param metadata the initializr metadata * @param metadata the initializr metadata
*/ */
public void resolve(InitializrMetadata metadata) { public void resolve(InitializrMetadata metadata) {
List<String> depIds = !getStyle().isEmpty() ? getStyle() : getDependencies(); List<String> depIds = (!getStyle().isEmpty() ? getStyle() : getDependencies());
String actualBootVersion = getBootVersion() != null ? getBootVersion() String actualBootVersion = (getBootVersion() != null ? getBootVersion()
: metadata.getBootVersions().getDefault().getId(); : metadata.getBootVersions().getDefault().getId());
Version requestedVersion = Version.parse(actualBootVersion); Version requestedVersion = Version.parse(actualBootVersion);
this.resolvedDependencies = depIds.stream().map((it) -> { this.resolvedDependencies = depIds.stream().map((it) -> {
Dependency dependency = metadata.getDependencies().get(it); Dependency dependency = metadata.getDependencies().get(it);

View File

@@ -149,8 +149,8 @@ public class Dependency extends MetadataElement implements Describable {
} }
public void setVersionRange(String versionRange) { public void setVersionRange(String versionRange) {
this.versionRange = StringUtils.hasText(versionRange) ? versionRange.trim() this.versionRange = (StringUtils.hasText(versionRange) ? versionRange.trim()
: null; : null);
} }
/** /**
@@ -170,8 +170,8 @@ public class Dependency extends MetadataElement implements Describable {
*/ */
public Dependency asSpringBootStarter(String name) { public Dependency asSpringBootStarter(String name) {
this.groupId = "org.springframework.boot"; this.groupId = "org.springframework.boot";
this.artifactId = StringUtils.hasText(name) ? "spring-boot-starter-" + name this.artifactId = (StringUtils.hasText(name) ? "spring-boot-starter-" + name
: "spring-boot-starter"; : "spring-boot-starter");
if (StringUtils.hasText(name)) { if (StringUtils.hasText(name)) {
setId(name); setId(name);
} }
@@ -247,12 +247,12 @@ public class Dependency extends MetadataElement implements Describable {
for (Mapping mapping : this.mappings) { for (Mapping mapping : this.mappings) {
if (mapping.range.match(bootVersion)) { if (mapping.range.match(bootVersion)) {
Dependency dependency = new Dependency(this); Dependency dependency = new Dependency(this);
dependency.groupId = mapping.groupId != null ? mapping.groupId dependency.groupId = (mapping.groupId != null ? mapping.groupId
: this.groupId; : this.groupId);
dependency.artifactId = mapping.artifactId != null ? mapping.artifactId dependency.artifactId = (mapping.artifactId != null ? mapping.artifactId
: this.artifactId; : this.artifactId);
dependency.version = mapping.version != null ? mapping.version dependency.version = (mapping.version != null ? mapping.version
: this.version; : this.version);
dependency.versionRequirement = mapping.range.toString(); dependency.versionRequirement = mapping.range.toString();
dependency.mappings = null; dependency.mappings = null;
return dependency; return dependency;

View File

@@ -240,8 +240,8 @@ public class InitializrConfiguration {
new Repository("Spring Milestones", new Repository("Spring Milestones",
new URL("https://repo.spring.io/milestone"), false)); new URL("https://repo.spring.io/milestone"), false));
} }
catch (MalformedURLException e) { catch (MalformedURLException ex) {
throw new IllegalStateException("Cannot parse URL", e); throw new IllegalStateException("Cannot parse URL", ex);
} }
} }
@@ -517,9 +517,9 @@ public class InitializrConfiguration {
* @return the parent POM * @return the parent POM
*/ */
public ParentPom resolveParentPom(String bootVersion) { public ParentPom resolveParentPom(String bootVersion) {
return StringUtils.hasText(this.parent.groupId) ? this.parent return (StringUtils.hasText(this.parent.groupId) ? this.parent
: new ParentPom("org.springframework.boot", : new ParentPom("org.springframework.boot",
"spring-boot-starter-parent", bootVersion); "spring-boot-starter-parent", bootVersion));
} }
/** /**

View File

@@ -274,7 +274,7 @@ public class InitializrMetadata {
private static String defaultId( private static String defaultId(
Defaultable<? extends DefaultMetadataElement> element) { Defaultable<? extends DefaultMetadataElement> element) {
DefaultMetadataElement defaultValue = element.getDefault(); DefaultMetadataElement defaultValue = element.getDefault();
return defaultValue != null ? defaultValue.getId() : null; return (defaultValue != null ? defaultValue.getId() : null);
} }
private static class ArtifactIdCapability extends TextCapability { private static class ArtifactIdCapability extends TextCapability {
@@ -289,7 +289,7 @@ public class InitializrMetadata {
@Override @Override
public String getContent() { public String getContent() {
String value = super.getContent(); String value = super.getContent();
return value == null ? this.nameCapability.getContent() : value; return (value != null ? value : this.nameCapability.getContent());
} }
} }

View File

@@ -98,8 +98,8 @@ public final class InitializrMetadataBuilder {
* @return a new {@link InitializrMetadata} instance * @return a new {@link InitializrMetadata} instance
*/ */
public InitializrMetadata build() { public InitializrMetadata build() {
InitializrConfiguration config = this.configuration != null ? this.configuration InitializrConfiguration config = (this.configuration != null ? this.configuration
: new InitializrConfiguration(); : new InitializrConfiguration());
InitializrMetadata metadata = createInstance(config); InitializrMetadata metadata = createInstance(config);
for (InitializrMetadataCustomizer customizer : this.customizers) { for (InitializrMetadataCustomizer customizer : this.customizers) {
customizer.customize(metadata); customizer.customize(metadata);
@@ -210,8 +210,8 @@ public final class InitializrMetadataBuilder {
InitializrMetadata.class); InitializrMetadata.class);
metadata.merge(anotherMetadata); metadata.merge(anotherMetadata);
} }
catch (Exception e) { catch (Exception ex) {
throw new IllegalStateException("Cannot merge", e); throw new IllegalStateException("Cannot merge", ex);
} }
} }

View File

@@ -158,8 +158,8 @@ public class Link {
try { try {
return new URI(result.get()); return new URI(result.get());
} }
catch (URISyntaxException e) { catch (URISyntaxException ex) {
throw new IllegalStateException("Invalid URL", e); throw new IllegalStateException("Invalid URL", ex);
} }
} }

View File

@@ -46,7 +46,7 @@ public class MetadataElement {
} }
public String getName() { public String getName() {
return this.name != null ? this.name : this.id; return (this.name != null ? this.name : this.id);
} }
public String getId() { public String getId() {

View File

@@ -69,9 +69,9 @@ public class TemplateRenderer {
Template template = getTemplate(name); Template template = getTemplate(name);
return template.execute(model); return template.execute(model);
} }
catch (Exception e) { catch (Exception ex) {
log.error("Cannot render: " + name, e); log.error("Cannot render: " + name, ex);
throw new IllegalStateException("Cannot render template", e); throw new IllegalStateException("Cannot render template", ex);
} }
} }
@@ -88,8 +88,8 @@ public class TemplateRenderer {
template = this.mustache.loader.getTemplate(name); template = this.mustache.loader.getTemplate(name);
return this.mustache.compile(template); return this.mustache.compile(template);
} }
catch (Exception e) { catch (Exception ex) {
throw new IllegalStateException("Cannot load template " + name, e); throw new IllegalStateException("Cannot load template " + name, ex);
} }
} }

View File

@@ -114,7 +114,7 @@ public final class Version implements Serializable, Comparable<Version> {
try { try {
return parse(text); return parse(text);
} }
catch (InvalidVersionException e) { catch (InvalidVersionException ex) {
return null; return null;
} }
} }
@@ -140,8 +140,8 @@ public final class Version implements Serializable, Comparable<Version> {
} }
private static int safeCompare(Integer first, Integer second) { private static int safeCompare(Integer first, Integer second) {
Integer firstIndex = first != null ? first : 0; Integer firstIndex = (first != null ? first : 0);
Integer secondIndex = second != null ? second : 0; Integer secondIndex = (second != null ? second : 0);
return firstIndex.compareTo(secondIndex); return firstIndex.compareTo(secondIndex);
} }
@@ -296,16 +296,17 @@ public final class Version implements Serializable, Comparable<Version> {
@Override @Override
public int compare(Qualifier o1, Qualifier o2) { public int compare(Qualifier o1, Qualifier o2) {
Qualifier first = o1 != null ? o1 : new Qualifier(RELEASE); Qualifier first = (o1 != null ? o1 : new Qualifier(RELEASE));
Qualifier second = o2 != null ? o2 : new Qualifier(RELEASE); Qualifier second = (o2 != null ? o2 : new Qualifier(RELEASE));
int qualifier = compareQualifier(first, second); int qualifier = compareQualifier(first, second);
return qualifier != 0 ? qualifier : compareQualifierVersion(first, second); return (qualifier != 0 ? qualifier : compareQualifierVersion(first, second));
} }
private static int compareQualifierVersion(Qualifier first, Qualifier second) { private static int compareQualifierVersion(Qualifier first, Qualifier second) {
Integer firstVersion = first.getVersion() != null ? first.getVersion() : 0; Integer firstVersion = (first.getVersion() != null ? first.getVersion() : 0);
Integer secondVersion = second.getVersion() != null ? second.getVersion() : 0; Integer secondVersion = (second.getVersion() != null ? second.getVersion()
: 0);
return firstVersion.compareTo(secondVersion); return firstVersion.compareTo(secondVersion);
} }
@@ -323,8 +324,8 @@ public final class Version implements Serializable, Comparable<Version> {
} }
private static int getQualifierIndex(String qualifier) { private static int getQualifierIndex(String qualifier) {
return StringUtils.hasText(qualifier) ? KNOWN_QUALIFIERS.indexOf(qualifier) return (StringUtils.hasText(qualifier) ? KNOWN_QUALIFIERS.indexOf(qualifier)
: 0; : 0);
} }
} }

View File

@@ -89,7 +89,7 @@ public class VersionParser {
} }
} }
if ("x".equals(minor) || "x".equals(patch)) { if ("x".equals(minor) || "x".equals(patch)) {
Integer minorInt = "x".equals(minor) ? null : Integer.parseInt(minor); Integer minorInt = ("x".equals(minor) ? null : Integer.parseInt(minor));
Version latest = findLatestVersion(major, minorInt, qualifier); Version latest = findLatestVersion(major, minorInt, qualifier);
if (latest == null) { if (latest == null) {
return new Version(major, return new Version(major,
@@ -159,7 +159,7 @@ public class VersionParser {
} }
return true; return true;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
return (matches.size() == 1 ? matches.get(0) : null); return (matches.size() != 1 ? null : matches.get(0));
} }
} }

View File

@@ -69,8 +69,8 @@ public class PomAssert {
try { try {
this.doc = XMLUnit.buildControlDocument(content); this.doc = XMLUnit.buildControlDocument(content);
} }
catch (Exception e) { catch (Exception ex) {
throw new IllegalArgumentException("Cannot parse XML", e); throw new IllegalArgumentException("Cannot parse XML", ex);
} }
this.parentPom = parseParent(); this.parentPom = parseParent();
parseProperties(); parseProperties();
@@ -96,8 +96,8 @@ public class PomAssert {
assertThat(this.eng.evaluate(createRootNodeXPath("groupId"), this.doc)) assertThat(this.eng.evaluate(createRootNodeXPath("groupId"), this.doc))
.isEqualTo(groupId); .isEqualTo(groupId);
} }
catch (XpathException e) { catch (XpathException ex) {
throw new IllegalStateException("Cannot find path", e); throw new IllegalStateException("Cannot find path", ex);
} }
return this; return this;
} }
@@ -107,8 +107,8 @@ public class PomAssert {
assertThat(this.eng.evaluate(createRootNodeXPath("artifactId"), this.doc)) assertThat(this.eng.evaluate(createRootNodeXPath("artifactId"), this.doc))
.isEqualTo(artifactId); .isEqualTo(artifactId);
} }
catch (XpathException e) { catch (XpathException ex) {
throw new IllegalStateException("Cannot find path", e); throw new IllegalStateException("Cannot find path", ex);
} }
return this; return this;
} }
@@ -118,8 +118,8 @@ public class PomAssert {
assertThat(this.eng.evaluate(createRootNodeXPath("version"), this.doc)) assertThat(this.eng.evaluate(createRootNodeXPath("version"), this.doc))
.isEqualTo(version); .isEqualTo(version);
} }
catch (XpathException e) { catch (XpathException ex) {
throw new IllegalStateException("Cannot find path", e); throw new IllegalStateException("Cannot find path", ex);
} }
return this; return this;
} }
@@ -129,8 +129,8 @@ public class PomAssert {
assertThat(this.eng.evaluate(createRootNodeXPath("packaging"), this.doc)) assertThat(this.eng.evaluate(createRootNodeXPath("packaging"), this.doc))
.isEqualTo(packaging); .isEqualTo(packaging);
} }
catch (XpathException e) { catch (XpathException ex) {
throw new IllegalStateException("Cannot find path", e); throw new IllegalStateException("Cannot find path", ex);
} }
return this; return this;
} }
@@ -140,8 +140,8 @@ public class PomAssert {
assertThat(this.eng.evaluate(createRootNodeXPath("name"), this.doc)) assertThat(this.eng.evaluate(createRootNodeXPath("name"), this.doc))
.isEqualTo(name); .isEqualTo(name);
} }
catch (XpathException e) { catch (XpathException ex) {
throw new IllegalStateException("Cannot find path", e); throw new IllegalStateException("Cannot find path", ex);
} }
return this; return this;
} }
@@ -151,8 +151,8 @@ public class PomAssert {
assertThat(this.eng.evaluate(createRootNodeXPath("description"), this.doc)) assertThat(this.eng.evaluate(createRootNodeXPath("description"), this.doc))
.isEqualTo(description); .isEqualTo(description);
} }
catch (XpathException e) { catch (XpathException ex) {
throw new IllegalStateException("Cannot find path", e); throw new IllegalStateException("Cannot find path", ex);
} }
return this; return this;
} }
@@ -163,8 +163,8 @@ public class PomAssert {
this.eng.evaluate(createPropertyNodeXpath("java.version"), this.doc)) this.eng.evaluate(createPropertyNodeXpath("java.version"), this.doc))
.isEqualTo(javaVersion); .isEqualTo(javaVersion);
} }
catch (XpathException e) { catch (XpathException ex) {
throw new IllegalStateException("Cannot find path", e); throw new IllegalStateException("Cannot find path", ex);
} }
return this; return this;
} }
@@ -259,8 +259,8 @@ public class PomAssert {
.getMatchingNodes(createRootNodeXPath("repositories"), this.doc) .getMatchingNodes(createRootNodeXPath("repositories"), this.doc)
.getLength()); .getLength());
} }
catch (XpathException e) { catch (XpathException ex) {
throw new IllegalStateException("Cannot find path", e); throw new IllegalStateException("Cannot find path", ex);
} }
return this; return this;
} }
@@ -283,8 +283,8 @@ public class PomAssert {
try { try {
assertThat(repository.getUrl()).isEqualTo(new URL(url)); assertThat(repository.getUrl()).isEqualTo(new URL(url));
} }
catch (MalformedURLException e) { catch (MalformedURLException ex) {
throw new IllegalArgumentException("Cannot parse URL", e); throw new IllegalArgumentException("Cannot parse URL", ex);
} }
} }
if (snapshotsEnabled) { if (snapshotsEnabled) {
@@ -305,8 +305,8 @@ public class PomAssert {
createRootNodeXPath("pluginRepositories/pom:pluginRepository/pom:id"), createRootNodeXPath("pluginRepositories/pom:pluginRepository/pom:id"),
this.doc); this.doc);
} }
catch (XpathException e) { catch (XpathException ex) {
throw new IllegalStateException("Cannot find path", e); throw new IllegalStateException("Cannot find path", ex);
} }
for (int i = 0; i < nodes.getLength(); i++) { for (int i = 0; i < nodes.getLength(); i++) {
if (name.equals(nodes.item(i).getTextContent())) { if (name.equals(nodes.item(i).getTextContent())) {
@@ -335,8 +335,8 @@ public class PomAssert {
this.doc)); this.doc));
return parent; return parent;
} }
catch (XpathException e) { catch (XpathException ex) {
throw new IllegalStateException("Cannot find path", e); throw new IllegalStateException("Cannot find path", ex);
} }
} }
@@ -346,8 +346,8 @@ public class PomAssert {
nodes = this.eng.getMatchingNodes(createRootNodeXPath("properties/*"), nodes = this.eng.getMatchingNodes(createRootNodeXPath("properties/*"),
this.doc); this.doc);
} }
catch (XpathException e) { catch (XpathException ex) {
throw new IllegalStateException("Cannot find path", e); throw new IllegalStateException("Cannot find path", ex);
} }
for (int i = 0; i < nodes.getLength(); i++) { for (int i = 0; i < nodes.getLength(); i++) {
Node item = nodes.item(i); Node item = nodes.item(i);
@@ -364,8 +364,8 @@ public class PomAssert {
nodes = this.eng.getMatchingNodes( nodes = this.eng.getMatchingNodes(
createRootNodeXPath("dependencies/pom:dependency"), this.doc); createRootNodeXPath("dependencies/pom:dependency"), this.doc);
} }
catch (XpathException e) { catch (XpathException ex) {
throw new IllegalStateException("Cannot find path", e); throw new IllegalStateException("Cannot find path", ex);
} }
for (int i = 0; i < nodes.getLength(); i++) { for (int i = 0; i < nodes.getLength(); i++) {
Node item = nodes.item(i); Node item = nodes.item(i);
@@ -407,8 +407,8 @@ public class PomAssert {
"dependencyManagement/pom:dependencies/pom:dependency"), "dependencyManagement/pom:dependencies/pom:dependency"),
this.doc); this.doc);
} }
catch (XpathException e) { catch (XpathException ex) {
throw new IllegalStateException("Cannot find path", e); throw new IllegalStateException("Cannot find path", ex);
} }
for (int i = 0; i < nodes.getLength(); i++) { for (int i = 0; i < nodes.getLength(); i++) {
Node item = nodes.item(i); Node item = nodes.item(i);
@@ -444,8 +444,8 @@ public class PomAssert {
nodes = this.eng.getMatchingNodes( nodes = this.eng.getMatchingNodes(
createRootNodeXPath("repositories/pom:repository"), this.doc); createRootNodeXPath("repositories/pom:repository"), this.doc);
} }
catch (XpathException e) { catch (XpathException ex) {
throw new IllegalStateException("Cannot find path", e); throw new IllegalStateException("Cannot find path", ex);
} }
for (int i = 0; i < nodes.getLength(); i++) { for (int i = 0; i < nodes.getLength(); i++) {
@@ -464,8 +464,8 @@ public class PomAssert {
try { try {
repository.setUrl(new URL(url.item(0).getTextContent())); repository.setUrl(new URL(url.item(0).getTextContent()));
} }
catch (MalformedURLException | DOMException e) { catch (MalformedURLException | DOMException ex) {
throw new IllegalStateException("Cannot parse URL", e); throw new IllegalStateException("Cannot parse URL", ex);
} }
} }
NodeList snapshots = element.getElementsByTagName("snapshots"); NodeList snapshots = element.getElementsByTagName("snapshots");

View File

@@ -87,8 +87,8 @@ public class ProjectAssert {
return new PomAssert(StreamUtils.copyToString( return new PomAssert(StreamUtils.copyToString(
new FileInputStream(file("pom.xml")), Charset.forName("UTF-8"))); new FileInputStream(file("pom.xml")), Charset.forName("UTF-8")));
} }
catch (IOException e) { catch (IOException ex) {
throw new IllegalArgumentException("Cannot resolve pom.xml", e); throw new IllegalArgumentException("Cannot resolve pom.xml", ex);
} }
} }
@@ -101,8 +101,8 @@ public class ProjectAssert {
return new GradleBuildAssert(StreamUtils.copyToString( return new GradleBuildAssert(StreamUtils.copyToString(
new FileInputStream(file("build.gradle")), Charset.forName("UTF-8"))); new FileInputStream(file("build.gradle")), Charset.forName("UTF-8")));
} }
catch (IOException e) { catch (IOException ex) {
throw new IllegalArgumentException("Cannot resolve build.gradle", e); throw new IllegalArgumentException("Cannot resolve build.gradle", ex);
} }
} }
@@ -116,8 +116,8 @@ public class ProjectAssert {
StreamUtils.copyToString(new FileInputStream(file("settings.gradle")), StreamUtils.copyToString(new FileInputStream(file("settings.gradle")),
Charset.forName("UTF-8"))); Charset.forName("UTF-8")));
} }
catch (IOException e) { catch (IOException ex) {
throw new IllegalArgumentException("Cannot resolve settings.gradle", e); throw new IllegalArgumentException("Cannot resolve settings.gradle", ex);
} }
} }
@@ -132,9 +132,9 @@ public class ProjectAssert {
return new SourceCodeAssert(sourceCodePath, StreamUtils.copyToString( return new SourceCodeAssert(sourceCodePath, StreamUtils.copyToString(
new FileInputStream(file(sourceCodePath)), Charset.forName("UTF-8"))); new FileInputStream(file(sourceCodePath)), Charset.forName("UTF-8")));
} }
catch (IOException e) { catch (IOException ex) {
throw new IllegalArgumentException("Cannot resolve path: " + sourceCodePath, throw new IllegalArgumentException("Cannot resolve path: " + sourceCodePath,
e); ex);
} }
} }
@@ -266,8 +266,8 @@ public class ProjectAssert {
try { try {
return PropertiesLoaderUtils.loadProperties(new FileSystemResource(f)); return PropertiesLoaderUtils.loadProperties(new FileSystemResource(f));
} }
catch (Exception e) { catch (Exception ex) {
throw new IllegalStateException("Cannot load Properties", e); throw new IllegalStateException("Cannot load Properties", ex);
} }
} }

View File

@@ -48,8 +48,8 @@ public class SourceCodeAssert {
assertThat(this.content).describedAs("Content for %s", this.name) assertThat(this.content).describedAs("Content for %s", this.name)
.isEqualTo(expectedContent.replaceAll("\r\n", "\n")); .isEqualTo(expectedContent.replaceAll("\r\n", "\n"));
} }
catch (IOException e) { catch (IOException ex) {
throw new IllegalStateException("Cannot read file", e); throw new IllegalStateException("Cannot read file", ex);
} }
return this; return this;
} }

View File

@@ -232,8 +232,8 @@ public class InitializrMetadataTestBuilder {
try { try {
repo.setUrl(new URL(url)); repo.setUrl(new URL(url));
} }
catch (MalformedURLException e) { catch (MalformedURLException ex) {
throw new IllegalArgumentException("Cannot create URL", e); throw new IllegalArgumentException("Cannot create URL", ex);
} }
repo.setSnapshotsEnabled(snapshotsEnabled); repo.setSnapshotsEnabled(snapshotsEnabled);
it.getConfiguration().getEnv().getRepositories().put(id, repo); it.getConfiguration().getEnv().getRepositories().put(id, repo);

View File

@@ -77,7 +77,7 @@ public class InitializrAutoConfiguration {
public InitializrAutoConfiguration( public InitializrAutoConfiguration(
ObjectProvider<List<ProjectRequestPostProcessor>> postProcessors) { ObjectProvider<List<ProjectRequestPostProcessor>> postProcessors) {
List<ProjectRequestPostProcessor> list = postProcessors.getIfAvailable(); List<ProjectRequestPostProcessor> list = postProcessors.getIfAvailable();
this.postProcessors = list != null ? list : new ArrayList<>(); this.postProcessors = (list != null ? list : new ArrayList<>());
} }
@Bean @Bean

View File

@@ -65,7 +65,7 @@ public class InitializrMetadataV21JsonMapper extends InitializrMetadataV2JsonMap
} }
private ObjectNode dependenciesLink(String appUrl) { private ObjectNode dependenciesLink(String appUrl) {
String uri = appUrl != null ? appUrl + "/dependencies" : "/dependencies"; String uri = (appUrl != null ? appUrl + "/dependencies" : "/dependencies");
UriTemplate uriTemplate = new UriTemplate(uri, this.dependenciesVariables); UriTemplate uriTemplate = new UriTemplate(uri, this.dependenciesVariables);
ObjectNode result = nodeFactory().objectNode(); ObjectNode result = nodeFactory().objectNode();
result.put("href", uriTemplate.toString()); result.put("href", uriTemplate.toString());

View File

@@ -114,7 +114,7 @@ public class InitializrMetadataV2JsonMapper implements InitializrMetadataJsonMap
} }
private String generateTemplatedUri(String appUrl, Type type) { private String generateTemplatedUri(String appUrl, Type type) {
String uri = appUrl != null ? appUrl + type.getAction() : type.getAction(); String uri = (appUrl != null ? appUrl + type.getAction() : type.getAction());
uri = uri + "?type=" + type.getId(); uri = uri + "?type=" + type.getId();
UriTemplate uriTemplate = new UriTemplate(uri, this.templateVariables); UriTemplate uriTemplate = new UriTemplate(uri, this.templateVariables);
return uriTemplate.toString(); return uriTemplate.toString();

View File

@@ -52,7 +52,7 @@ public abstract class AbstractInitializrController {
this.metadataProvider = metadataProvider; this.metadataProvider = metadataProvider;
this.linkTo = (link) -> { this.linkTo = (link) -> {
String result = resourceUrlProvider.getForLookupPath(link); String result = resourceUrlProvider.getForLookupPath(link);
return result == null ? link : result; return (result != null ? result : link);
}; };
} }

View File

@@ -203,8 +203,8 @@ public class MainController extends AbstractInitializrController {
private ResponseEntity<String> dependenciesFor(InitializrMetadataVersion version, private ResponseEntity<String> dependenciesFor(InitializrMetadataVersion version,
String bootVersion) { String bootVersion) {
InitializrMetadata metadata = this.metadataProvider.get(); InitializrMetadata metadata = this.metadataProvider.get();
Version v = bootVersion != null ? Version.parse(bootVersion) Version v = (bootVersion != null ? Version.parse(bootVersion)
: Version.parse(metadata.getBootVersions().getDefault().getId()); : Version.parse(metadata.getBootVersions().getDefault().getId()));
DependencyMetadata dependencyMetadata = this.dependencyMetadataProvider DependencyMetadata dependencyMetadata = this.dependencyMetadataProvider
.get(metadata, v); .get(metadata, v);
String content = new DependencyMetadataV21JsonMapper().write(dependencyMetadata); String content = new DependencyMetadataV21JsonMapper().write(dependencyMetadata);
@@ -324,15 +324,15 @@ public class MainController extends AbstractInitializrController {
try { try {
return URLEncoder.encode(tmp, "UTF-8") + "." + extension; return URLEncoder.encode(tmp, "UTF-8") + "." + extension;
} }
catch (UnsupportedEncodingException e) { catch (UnsupportedEncodingException ex) {
throw new IllegalStateException("Cannot encode URL", e); throw new IllegalStateException("Cannot encode URL", ex);
} }
} }
private static String getWrapperScript(ProjectRequest request) { private static String getWrapperScript(ProjectRequest request) {
String script = "gradle".equals(request.getBuild()) ? "gradlew" : "mvnw"; String script = ("gradle".equals(request.getBuild()) ? "gradlew" : "mvnw");
return request.getBaseDir() != null ? request.getBaseDir() + "/" + script return (request.getBaseDir() != null ? request.getBaseDir() + "/" + script
: script; : script);
} }
private ResponseEntity<byte[]> upload(File download, File dir, String fileName, private ResponseEntity<byte[]> upload(File download, File dir, String fileName,

View File

@@ -79,8 +79,8 @@ public class DefaultInitializrMetadataProvider implements InitializrMetadataProv
return new SpringBootMetadataReader(this.objectMapper, this.restTemplate, return new SpringBootMetadataReader(this.objectMapper, this.restTemplate,
url).getBootVersions(); url).getBootVersions();
} }
catch (Exception e) { catch (Exception ex) {
log.warn("Failed to fetch spring boot metadata", e); log.warn("Failed to fetch spring boot metadata", ex);
} }
} }
return null; return null;

View File

@@ -57,7 +57,7 @@ public class UiController {
List<DependencyGroup> dependencyGroups = this.metadataProvider.get() List<DependencyGroup> dependencyGroups = this.metadataProvider.get()
.getDependencies().getContent(); .getDependencies().getContent();
List<DependencyItem> content = new ArrayList<>(); List<DependencyItem> content = new ArrayList<>();
Version v = StringUtils.isEmpty(version) ? null : Version.parse(version); Version v = (StringUtils.isEmpty(version) ? null : Version.parse(version));
dependencyGroups.forEach((g) -> g.getContent().forEach((d) -> { dependencyGroups.forEach((g) -> g.getContent().forEach((d) -> {
if (v != null && d.getVersionRange() != null) { if (v != null && d.getVersionRange() != null) {
if (d.match(v)) { if (d.match(v)) {

View File

@@ -48,7 +48,7 @@ public abstract class AbstractInitializrControllerIntegrationTests
@Override @Override
protected String createUrl(String context) { protected String createUrl(String context) {
return context.startsWith("/") ? context : "/" + context; return (context.startsWith("/") ? context : "/" + context);
} }
public MockMvcClientHttpRequestFactory getRequests() { public MockMvcClientHttpRequestFactory getRequests() {

View File

@@ -226,8 +226,8 @@ public abstract class AbstractInitializrIntegrationTests {
} }
return new ProjectAssert(project); return new ProjectAssert(project);
} }
catch (Exception e) { catch (Exception ex) {
throw new IllegalStateException("Cannot unpack archive", e); throw new IllegalStateException("Cannot unpack archive", ex);
} }
} }
@@ -277,7 +277,7 @@ public abstract class AbstractInitializrIntegrationTests {
return new JSONObject(content); return new JSONObject(content);
} }
} }
catch (Exception e) { catch (Exception ex) {
throw new IllegalStateException("Cannot read JSON from path=" + path); throw new IllegalStateException("Cannot read JSON from path=" + path);
} }
} }

View File

@@ -202,7 +202,7 @@ final class JsonFieldProcessor {
List<String> segments, Match parent) { List<String> segments, Match parent) {
this.payload = payload; this.payload = payload;
this.path = path; this.path = path;
this.segments = segments == null ? path.getSegments() : segments; this.segments = (segments != null ? segments : path.getSegments());
this.parent = parent; this.parent = parent;
} }