Merge pull request #752 from govi20

* pr/752:
  Polish "Polish local variables and lambda names"
  Polish local variables and lambda names
  Polish
This commit is contained in:
Stephane Nicoll 2018-10-28 07:26:00 +09:00
commit 73bbd32a42
6 changed files with 58 additions and 55 deletions

View File

@ -45,9 +45,9 @@ public class DependencyRangesInfoContributor implements InfoContributor {
@Override @Override
public void contribute(Info.Builder builder) { public void contribute(Info.Builder builder) {
Map<String, Object> details = new LinkedHashMap<>(); Map<String, Object> details = new LinkedHashMap<>();
this.metadataProvider.get().getDependencies().getAll().forEach((d) -> { this.metadataProvider.get().getDependencies().getAll().forEach((dependency) -> {
if (d.getBom() == null) { if (dependency.getBom() == null) {
contribute(details, d); contribute(details, dependency);
} }
}); });
if (!details.isEmpty()) { if (!details.isEmpty()) {
@ -55,16 +55,16 @@ public class DependencyRangesInfoContributor implements InfoContributor {
} }
} }
private void contribute(Map<String, Object> details, Dependency d) { private void contribute(Map<String, Object> details, Dependency dependency) {
if (!ObjectUtils.isEmpty(d.getMappings())) { if (!ObjectUtils.isEmpty(dependency.getMappings())) {
Map<String, VersionRange> dep = new LinkedHashMap<>(); Map<String, VersionRange> dep = new LinkedHashMap<>();
d.getMappings().forEach((it) -> { dependency.getMappings().forEach((it) -> {
if (it.getRange() != null && it.getVersion() != null) { if (it.getRange() != null && it.getVersion() != null) {
dep.put(it.getVersion(), it.getRange()); dep.put(it.getVersion(), it.getRange());
} }
}); });
if (!dep.isEmpty()) { if (!dep.isEmpty()) {
if (d.getRange() == null) { if (dependency.getRange() == null) {
boolean openRange = dep.values().stream() boolean openRange = dep.values().stream()
.anyMatch((v) -> v.getHigherVersion() == null); .anyMatch((v) -> v.getHigherVersion() == null);
if (!openRange) { if (!openRange) {
@ -76,14 +76,14 @@ public class DependencyRangesInfoContributor implements InfoContributor {
dep.forEach((k, r) -> { dep.forEach((k, r) -> {
depInfo.put(k, "Spring Boot " + r); depInfo.put(k, "Spring Boot " + r);
}); });
details.put(d.getId(), depInfo); details.put(dependency.getId(), depInfo);
} }
} }
else if (d.getVersion() != null && d.getRange() != null) { else if (dependency.getVersion() != null && dependency.getRange() != null) {
Map<String, Object> dep = new LinkedHashMap<>(); Map<String, Object> dep = new LinkedHashMap<>();
String requirement = "Spring Boot " + d.getRange(); String requirement = "Spring Boot " + dependency.getRange();
dep.put(d.getVersion(), requirement); dep.put(dependency.getVersion(), requirement);
details.put(d.getId(), dep); details.put(dependency.getId(), dep);
} }
} }

View File

@ -65,7 +65,8 @@ public class AbstractProjectRequestPostProcessor implements ProjectRequestPostPr
*/ */
protected Dependency getDependency(ProjectRequest request, String id) { protected Dependency getDependency(ProjectRequest request, String id) {
return request.getResolvedDependencies().stream() return request.getResolvedDependencies().stream()
.filter((d) -> id.equals(d.getId())).findFirst().orElse(null); .filter((dependency) -> id.equals(dependency.getId())).findFirst()
.orElse(null);
} }
/** /**

View File

@ -166,11 +166,12 @@ public class InitializrAutoConfiguration {
@Bean @Bean
public JCacheManagerCustomizer initializrCacheManagerCustomizer() { public JCacheManagerCustomizer initializrCacheManagerCustomizer() {
return (cm) -> { return (cacheManager) -> {
cm.createCache("initializr.metadata", config().setExpiryPolicyFactory( cacheManager.createCache("initializr.metadata",
CreatedExpiryPolicy.factoryOf(Duration.TEN_MINUTES))); config().setExpiryPolicyFactory(
cm.createCache("initializr.dependency-metadata", config()); CreatedExpiryPolicy.factoryOf(Duration.TEN_MINUTES)));
cm.createCache("initializr.project-resources", config()); cacheManager.createCache("initializr.dependency-metadata", config());
cacheManager.createCache("initializr.project-resources", config());
}; };
} }

View File

@ -40,30 +40,30 @@ public class DefaultDependencyMetadataProvider implements DependencyMetadataProv
@Cacheable(cacheNames = "initializr.dependency-metadata", key = "#p1") @Cacheable(cacheNames = "initializr.dependency-metadata", key = "#p1")
public DependencyMetadata get(InitializrMetadata metadata, Version bootVersion) { public DependencyMetadata get(InitializrMetadata metadata, Version bootVersion) {
Map<String, Dependency> dependencies = new LinkedHashMap<>(); Map<String, Dependency> dependencies = new LinkedHashMap<>();
for (Dependency d : metadata.getDependencies().getAll()) { for (Dependency dependency : metadata.getDependencies().getAll()) {
if (d.match(bootVersion)) { if (dependency.match(bootVersion)) {
dependencies.put(d.getId(), d.resolve(bootVersion)); dependencies.put(dependency.getId(), dependency.resolve(bootVersion));
} }
} }
Map<String, Repository> repositories = new LinkedHashMap<>(); Map<String, Repository> repositories = new LinkedHashMap<>();
for (Dependency d : dependencies.values()) { for (Dependency dependency : dependencies.values()) {
if (d.getRepository() != null) { if (dependency.getRepository() != null) {
repositories.put(d.getRepository(), metadata.getConfiguration().getEnv() repositories.put(dependency.getRepository(), metadata.getConfiguration()
.getRepositories().get(d.getRepository())); .getEnv().getRepositories().get(dependency.getRepository()));
} }
} }
Map<String, BillOfMaterials> boms = new LinkedHashMap<>(); Map<String, BillOfMaterials> boms = new LinkedHashMap<>();
for (Dependency d : dependencies.values()) { for (Dependency dependency : dependencies.values()) {
if (d.getBom() != null) { if (dependency.getBom() != null) {
boms.put(d.getBom(), metadata.getConfiguration().getEnv().getBoms() boms.put(dependency.getBom(), metadata.getConfiguration().getEnv()
.get(d.getBom()).resolve(bootVersion)); .getBoms().get(dependency.getBom()).resolve(bootVersion));
} }
} }
// Each resolved bom may require additional repositories // Each resolved bom may require additional repositories
for (BillOfMaterials b : boms.values()) { for (BillOfMaterials bom : boms.values()) {
for (String id : b.getRepositories()) { for (String id : bom.getRepositories()) {
repositories.put(id, repositories.put(id,
metadata.getConfiguration().getEnv().getRepositories().get(id)); metadata.getConfiguration().getEnv().getRepositories().get(id));
} }

View File

@ -55,15 +55,15 @@ public class SpringBootMetadataReader {
* @return the versions * @return the versions
*/ */
public List<DefaultMetadataElement> getBootVersions() { public List<DefaultMetadataElement> getBootVersions() {
ArrayNode array = (ArrayNode) this.content.get("projectReleases"); ArrayNode releases = (ArrayNode) this.content.get("projectReleases");
List<DefaultMetadataElement> list = new ArrayList<>(); List<DefaultMetadataElement> list = new ArrayList<>();
for (JsonNode it : array) { for (JsonNode node : releases) {
DefaultMetadataElement version = new DefaultMetadataElement(); DefaultMetadataElement version = new DefaultMetadataElement();
version.setId(it.get("version").textValue()); version.setId(node.get("version").textValue());
String name = it.get("versionDisplayName").textValue(); String name = node.get("versionDisplayName").textValue();
version.setName( version.setName(
it.get("snapshot").booleanValue() ? name + " (SNAPSHOT)" : name); node.get("snapshot").booleanValue() ? name + " (SNAPSHOT)" : name);
version.setDefault(it.get("current").booleanValue()); version.setDefault(node.get("current").booleanValue());
list.add(version); list.add(version);
} }
return list; return list;

View File

@ -57,15 +57,16 @@ 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 requestedVersion = (StringUtils.isEmpty(version) ? null
dependencyGroups.forEach((g) -> g.getContent().forEach((d) -> { : Version.parse(version));
if (v != null && d.getVersionRange() != null) { dependencyGroups.forEach((group) -> group.getContent().forEach((dependency) -> {
if (d.match(v)) { if (requestedVersion != null && dependency.getVersionRange() != null) {
content.add(new DependencyItem(g.getName(), d)); if (dependency.match(requestedVersion)) {
content.add(new DependencyItem(group.getName(), dependency));
} }
} }
else { else {
content.add(new DependencyItem(g.getName(), d)); content.add(new DependencyItem(group.getName(), dependency));
} }
})); }));
String json = writeDependencies(content); String json = writeDependencies(content);
@ -76,27 +77,27 @@ public class UiController {
private static String writeDependencies(List<DependencyItem> items) { private static String writeDependencies(List<DependencyItem> items) {
ObjectNode json = JsonNodeFactory.instance.objectNode(); ObjectNode json = JsonNodeFactory.instance.objectNode();
ArrayNode maps = JsonNodeFactory.instance.arrayNode(); ArrayNode maps = JsonNodeFactory.instance.arrayNode();
items.forEach((d) -> maps.add(mapDependency(d))); items.forEach((dependency) -> maps.add(mapDependency(dependency)));
json.set("dependencies", maps); json.set("dependencies", maps);
return json.toString(); return json.toString();
} }
private static ObjectNode mapDependency(DependencyItem item) { private static ObjectNode mapDependency(DependencyItem item) {
ObjectNode node = JsonNodeFactory.instance.objectNode(); ObjectNode node = JsonNodeFactory.instance.objectNode();
Dependency d = item.dependency; Dependency dependency = item.dependency;
node.put("id", d.getId()); node.put("id", dependency.getId());
node.put("name", d.getName()); node.put("name", dependency.getName());
node.put("group", item.group); node.put("group", item.group);
if (d.getDescription() != null) { if (dependency.getDescription() != null) {
node.put("description", d.getDescription()); node.put("description", dependency.getDescription());
} }
if (d.getWeight() > 0) { if (dependency.getWeight() > 0) {
node.put("weight", d.getWeight()); node.put("weight", dependency.getWeight());
} }
if (!CollectionUtils.isEmpty(d.getKeywords()) if (!CollectionUtils.isEmpty(dependency.getKeywords())
|| !CollectionUtils.isEmpty(d.getAliases())) { || !CollectionUtils.isEmpty(dependency.getAliases())) {
List<String> all = new ArrayList<>(d.getKeywords()); List<String> all = new ArrayList<>(dependency.getKeywords());
all.addAll(d.getAliases()); all.addAll(dependency.getAliases());
node.put("keywords", StringUtils.collectionToCommaDelimitedString(all)); node.put("keywords", StringUtils.collectionToCommaDelimitedString(all));
} }
return node; return node;