Skip to content

Commit

Permalink
Merge pull request #655 from philwebb:cleanup
Browse files Browse the repository at this point in the history
* pr/655:
  Polish contribution
  Fix IDE warnings
  Fix checkstyle violations
  Migrate tests to AssertJ
  Apply automatic cleanup rules
  Reformat code
  Add Eclipse IDE support files
  Format POM.xml files
  • Loading branch information
snicoll committed Apr 16, 2018
2 parents 899f6d3 + 432be66 commit 5409185
Show file tree
Hide file tree
Showing 162 changed files with 4,035 additions and 2,789 deletions.
315 changes: 315 additions & 0 deletions eclipse/eclipse-code-formatter.xml

Large diffs are not rendered by default.

412 changes: 412 additions & 0 deletions eclipse/org.eclipse.jdt.core.prefs

Large diffs are not rendered by default.

125 changes: 125 additions & 0 deletions eclipse/org.eclipse.jdt.ui.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
cleanup.add_default_serial_version_id=true
cleanup.add_generated_serial_version_id=false
cleanup.add_missing_annotations=true
cleanup.add_missing_deprecated_annotations=true
cleanup.add_missing_methods=false
cleanup.add_missing_nls_tags=false
cleanup.add_missing_override_annotations=true
cleanup.add_missing_override_annotations_interface_methods=true
cleanup.add_serial_version_id=false
cleanup.always_use_blocks=true
cleanup.always_use_parentheses_in_expressions=false
cleanup.always_use_this_for_non_static_field_access=true
cleanup.always_use_this_for_non_static_method_access=false
cleanup.convert_functional_interfaces=false
cleanup.convert_to_enhanced_for_loop=false
cleanup.correct_indentation=false
cleanup.format_source_code=true
cleanup.format_source_code_changes_only=false
cleanup.insert_inferred_type_arguments=false
cleanup.make_local_variable_final=false
cleanup.make_parameters_final=false
cleanup.make_private_fields_final=false
cleanup.make_type_abstract_if_missing_method=false
cleanup.make_variable_declarations_final=false
cleanup.never_use_blocks=false
cleanup.never_use_parentheses_in_expressions=true
cleanup.organize_imports=true
cleanup.qualify_static_field_accesses_with_declaring_class=false
cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
cleanup.qualify_static_member_accesses_with_declaring_class=true
cleanup.qualify_static_method_accesses_with_declaring_class=false
cleanup.remove_private_constructors=true
cleanup.remove_redundant_type_arguments=true
cleanup.remove_trailing_whitespaces=true
cleanup.remove_trailing_whitespaces_all=true
cleanup.remove_trailing_whitespaces_ignore_empty=false
cleanup.remove_unnecessary_casts=true
cleanup.remove_unnecessary_nls_tags=false
cleanup.remove_unused_imports=true
cleanup.remove_unused_local_variables=false
cleanup.remove_unused_private_fields=true
cleanup.remove_unused_private_members=false
cleanup.remove_unused_private_methods=true
cleanup.remove_unused_private_types=true
cleanup.sort_members=false
cleanup.sort_members_all=false
cleanup.use_anonymous_class_creation=false
cleanup.use_blocks=true
cleanup.use_blocks_only_for_return_and_throw=false
cleanup.use_lambda=true
cleanup.use_parentheses_in_expressions=false
cleanup.use_this_for_non_static_field_access=true
cleanup.use_this_for_non_static_field_access_only_if_necessary=false
cleanup.use_this_for_non_static_method_access=false
cleanup.use_this_for_non_static_method_access_only_if_necessary=true
cleanup.use_type_arguments=false
cleanup_profile=_Spring Cleanup Conventions
cleanup_settings_version=2
eclipse.preferences.version=1
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
formatter_profile=_Spring Java Conventions
formatter_settings_version=13
org.eclipse.jdt.ui.exception.name=e
org.eclipse.jdt.ui.gettersetter.use.is=true
org.eclipse.jdt.ui.ignorelowercasenames=true
org.eclipse.jdt.ui.importorder=java;javax;;org.springframework;\#;
org.eclipse.jdt.ui.javadoc=true
org.eclipse.jdt.ui.keywordthis=false
org.eclipse.jdt.ui.ondemandthreshold=9999
org.eclipse.jdt.ui.overrideannotation=true
org.eclipse.jdt.ui.staticondemandthreshold=9999
org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\n * @return the ${bare_field_name}\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\n * @param ${param} the ${bare_field_name} to set\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\n * ${tags}\n */</template><template autoinsert\="false" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/*\n * Copyright 2012-2018 the original author or authors.\n *\n * Licensed under the Apache License, Version 2.0 (the "License");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http\://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an "AS IS" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */</template><template autoinsert\="false" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\n * @author ${user}\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\n * \n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\n * ${tags}\n */</template><template autoinsert\="true" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/* (non-Javadoc)\n * ${see_to_overridden}\n */</template><template autoinsert\="true" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\n * ${tags}\n * ${see_to_target}\n */</template><template autoinsert\="false" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">${filecomment}\n\n${package_declaration}\n${typecomment}\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody">\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\n</template><template autoinsert\="false" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\nthrow new UnsupportedOperationException("Auto-generated method stub", ${exception_var});</template><template autoinsert\="false" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated method stub\nthrow new UnsupportedOperationException("Auto-generated method stub");</template><template autoinsert\="true" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\n// ${todo} Auto-generated constructor stub</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates>
sp_cleanup.add_default_serial_version_id=true
sp_cleanup.add_generated_serial_version_id=false
sp_cleanup.add_missing_annotations=true
sp_cleanup.add_missing_deprecated_annotations=true
sp_cleanup.add_missing_methods=false
sp_cleanup.add_missing_nls_tags=false
sp_cleanup.add_missing_override_annotations=true
sp_cleanup.add_missing_override_annotations_interface_methods=true
sp_cleanup.add_serial_version_id=false
sp_cleanup.always_use_blocks=true
sp_cleanup.always_use_parentheses_in_expressions=true
sp_cleanup.always_use_this_for_non_static_field_access=true
sp_cleanup.always_use_this_for_non_static_method_access=false
sp_cleanup.convert_to_enhanced_for_loop=false
sp_cleanup.correct_indentation=false
sp_cleanup.format_source_code=true
sp_cleanup.format_source_code_changes_only=false
sp_cleanup.make_local_variable_final=false
sp_cleanup.make_parameters_final=false
sp_cleanup.make_private_fields_final=false
sp_cleanup.make_type_abstract_if_missing_method=false
sp_cleanup.make_variable_declarations_final=false
sp_cleanup.never_use_blocks=false
sp_cleanup.never_use_parentheses_in_expressions=false
sp_cleanup.on_save_use_additional_actions=true
sp_cleanup.organize_imports=true
sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
sp_cleanup.qualify_static_member_accesses_with_declaring_class=true
sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
sp_cleanup.remove_private_constructors=true
sp_cleanup.remove_trailing_whitespaces=true
sp_cleanup.remove_trailing_whitespaces_all=true
sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
sp_cleanup.remove_unnecessary_casts=true
sp_cleanup.remove_unnecessary_nls_tags=false
sp_cleanup.remove_unused_imports=true
sp_cleanup.remove_unused_local_variables=false
sp_cleanup.remove_unused_private_fields=true
sp_cleanup.remove_unused_private_members=false
sp_cleanup.remove_unused_private_methods=true
sp_cleanup.remove_unused_private_types=true
sp_cleanup.sort_members=false
sp_cleanup.sort_members_all=false
sp_cleanup.use_blocks=true
sp_cleanup.use_blocks_only_for_return_and_throw=false
sp_cleanup.use_parentheses_in_expressions=false
sp_cleanup.use_this_for_non_static_field_access=true
sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=false
sp_cleanup.use_this_for_non_static_method_access=false
sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
9 changes: 7 additions & 2 deletions initializr-actuator/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.spring.initializr</groupId>
Expand All @@ -9,6 +10,10 @@
<artifactId>initializr-actuator</artifactId>
<name>Spring Initializr :: Actuator</name>

<properties>
<main.basedir>${basedir}/..</main.basedir>
</properties>

<dependencies>
<dependency>
<groupId>io.spring.initializr</groupId>
Expand All @@ -31,7 +36,7 @@
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator-autoconfigure</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public class InitializrMetricsConfiguration {

@Bean
@ConditionalOnSingleCandidate(MeterRegistry.class)
public ProjectGenerationMetricsListener metricsListener(
MeterRegistry meterRegistry) {
public ProjectGenerationMetricsListener metricsListener(MeterRegistry meterRegistry) {
return new ProjectGenerationMetricsListener(meterRegistry);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class InitializrStatsAutoConfiguration {

private final StatsProperties statsProperties;

public InitializrStatsAutoConfiguration(StatsProperties statsProperties) {
InitializrStatsAutoConfiguration(StatsProperties statsProperties) {
this.statsProperties = statsProperties;
}

Expand All @@ -58,7 +58,7 @@ public ProjectGenerationStatPublisher projectRequestStatHandler(
InitializrMetadataProvider provider,
RestTemplateBuilder restTemplateBuilder) {
return new ProjectGenerationStatPublisher(
new ProjectRequestDocumentFactory(provider), statsProperties,
new ProjectRequestDocumentFactory(provider), this.statsProperties,
restTemplateBuilder, statsRetryTemplate());
}

Expand All @@ -70,7 +70,7 @@ public RetryTemplate statsRetryTemplate() {
backOffPolicy.setInitialInterval(3000L);
backOffPolicy.setMultiplier(3);
SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(
statsProperties.getElastic().getMaxAttempts(),
this.statsProperties.getElastic().getMaxAttempts(),
Collections.singletonMap(Exception.class, true));
retryTemplate.setBackOffPolicy(backOffPolicy);
retryTemplate.setRetryPolicy(retryPolicy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import org.springframework.boot.actuate.info.InfoContributor;

/**
* An {@link InfoContributor} that exposes the actual ranges used by each bom
* defined in the project.
* An {@link InfoContributor} that exposes the actual ranges used by each bom defined in
* the project.
*
* @author Stephane Nicoll
*/
Expand All @@ -41,16 +41,18 @@ public BomRangesInfoContributor(InitializrMetadataProvider metadataProvider) {
@Override
public void contribute(Info.Builder builder) {
Map<String, Object> details = new LinkedHashMap<>();
metadataProvider.get().getConfiguration().getEnv().getBoms().forEach((k, v) -> {
if (v.getMappings() != null && !v.getMappings().isEmpty()) {
Map<String, Object> bom = new LinkedHashMap<>();
v.getMappings().forEach(it -> {
String requirement = "Spring Boot " + it.determineVersionRangeRequirement();
bom.put(it.getVersion(), requirement);
this.metadataProvider.get().getConfiguration().getEnv().getBoms()
.forEach((k, v) -> {
if (v.getMappings() != null && !v.getMappings().isEmpty()) {
Map<String, Object> bom = new LinkedHashMap<>();
v.getMappings().forEach((it) -> {
String requirement = "Spring Boot "
+ it.determineVersionRangeRequirement();
bom.put(it.getVersion(), requirement);
});
details.put(k, bom);
}
});
details.put(k, bom);
}
});
if (!details.isEmpty()) {
builder.withDetail("bom-ranges", details);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.LinkedHashMap;
import java.util.Map;

import io.spring.initializr.metadata.Dependency;
import io.spring.initializr.metadata.InitializrMetadataProvider;
import io.spring.initializr.util.Version;
import io.spring.initializr.util.VersionRange;
Expand All @@ -28,8 +29,8 @@
import org.springframework.util.ObjectUtils;

/**
* An {@link InfoContributor} that exposes the actual ranges used by dependencies
* defined in the project that have an explicit version (i.e. not relying on a bom).
* An {@link InfoContributor} that exposes the actual ranges used by dependencies defined
* in the project that have an explicit version (i.e. not relying on a bom).
*
* @author Stephane Nicoll
*/
Expand All @@ -44,51 +45,60 @@ public DependencyRangesInfoContributor(InitializrMetadataProvider metadataProvid
@Override
public void contribute(Info.Builder builder) {
Map<String, Object> details = new LinkedHashMap<>();
metadataProvider.get().getDependencies().getAll().forEach(d -> {
this.metadataProvider.get().getDependencies().getAll().forEach((d) -> {
if (d.getBom() == null) {
if (!ObjectUtils.isEmpty(d.getMappings())) {
Map<String, VersionRange> dep = new LinkedHashMap<>();
d.getMappings().forEach(it -> {
if (it.getRange() != null && it.getVersion() != null) {
dep.put(it.getVersion(), it.getRange());
}
});
if (!dep.isEmpty()) {
if (d.getRange() == null) {
boolean openRange = dep.values().stream().anyMatch(
v -> v.getHigherVersion() == null);
if (!openRange) {
Version higher = null;
for (VersionRange versionRange : dep.values()) {
Version candidate = versionRange.getHigherVersion();
if (higher == null) {
higher = candidate;
}
else if (candidate.compareTo(higher) > 0) {
higher = candidate;
}
} ;
dep.put("managed", new VersionRange(higher));
}
}
Map<String, Object> depInfo = new LinkedHashMap<>();
dep.forEach((k, r) -> {
depInfo.put(k, "Spring Boot " + r);
});
details.put(d.getId(), depInfo);
}
}
else if (d.getVersion() != null && d.getRange() != null) {
Map<String, Object> dep = new LinkedHashMap<>();
String requirement = "Spring Boot " + d.getRange();
dep.put(d.getVersion(), requirement);
details.put(d.getId(), dep);
}
contribute(details, d);
}
});
if (!details.isEmpty()) {
builder.withDetail("dependency-ranges", details);
}
}

private void contribute(Map<String, Object> details, Dependency d) {
if (!ObjectUtils.isEmpty(d.getMappings())) {
Map<String, VersionRange> dep = new LinkedHashMap<>();
d.getMappings().forEach((it) -> {
if (it.getRange() != null && it.getVersion() != null) {
dep.put(it.getVersion(), it.getRange());
}
});
if (!dep.isEmpty()) {
if (d.getRange() == null) {
boolean openRange = dep.values().stream()
.anyMatch((v) -> v.getHigherVersion() == null);
if (!openRange) {
Version higher = getHigher(dep);
dep.put("managed", new VersionRange(higher));
}
}
Map<String, Object> depInfo = new LinkedHashMap<>();
dep.forEach((k, r) -> {
depInfo.put(k, "Spring Boot " + r);
});
details.put(d.getId(), depInfo);
}
}
else if (d.getVersion() != null && d.getRange() != null) {
Map<String, Object> dep = new LinkedHashMap<>();
String requirement = "Spring Boot " + d.getRange();
dep.put(d.getVersion(), requirement);
details.put(d.getId(), dep);
}
}

private Version getHigher(Map<String, VersionRange> dep) {
Version higher = null;
for (VersionRange versionRange : dep.values()) {
Version candidate = versionRange.getHigherVersion();
if (higher == null) {
higher = candidate;
}
else if (candidate.compareTo(higher) > 0) {
higher = candidate;
}
}
return higher;
}

}
Loading

0 comments on commit 5409185

Please sign in to comment.