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

View File

@ -65,7 +65,8 @@ public class AbstractProjectRequestPostProcessor implements ProjectRequestPostPr
*/
protected Dependency getDependency(ProjectRequest request, String id) {
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
public JCacheManagerCustomizer initializrCacheManagerCustomizer() {
return (cm) -> {
cm.createCache("initializr.metadata", config().setExpiryPolicyFactory(
CreatedExpiryPolicy.factoryOf(Duration.TEN_MINUTES)));
cm.createCache("initializr.dependency-metadata", config());
cm.createCache("initializr.project-resources", config());
return (cacheManager) -> {
cacheManager.createCache("initializr.metadata",
config().setExpiryPolicyFactory(
CreatedExpiryPolicy.factoryOf(Duration.TEN_MINUTES)));
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")
public DependencyMetadata get(InitializrMetadata metadata, Version bootVersion) {
Map<String, Dependency> dependencies = new LinkedHashMap<>();
for (Dependency d : metadata.getDependencies().getAll()) {
if (d.match(bootVersion)) {
dependencies.put(d.getId(), d.resolve(bootVersion));
for (Dependency dependency : metadata.getDependencies().getAll()) {
if (dependency.match(bootVersion)) {
dependencies.put(dependency.getId(), dependency.resolve(bootVersion));
}
}
Map<String, Repository> repositories = new LinkedHashMap<>();
for (Dependency d : dependencies.values()) {
if (d.getRepository() != null) {
repositories.put(d.getRepository(), metadata.getConfiguration().getEnv()
.getRepositories().get(d.getRepository()));
for (Dependency dependency : dependencies.values()) {
if (dependency.getRepository() != null) {
repositories.put(dependency.getRepository(), metadata.getConfiguration()
.getEnv().getRepositories().get(dependency.getRepository()));
}
}
Map<String, BillOfMaterials> boms = new LinkedHashMap<>();
for (Dependency d : dependencies.values()) {
if (d.getBom() != null) {
boms.put(d.getBom(), metadata.getConfiguration().getEnv().getBoms()
.get(d.getBom()).resolve(bootVersion));
for (Dependency dependency : dependencies.values()) {
if (dependency.getBom() != null) {
boms.put(dependency.getBom(), metadata.getConfiguration().getEnv()
.getBoms().get(dependency.getBom()).resolve(bootVersion));
}
}
// Each resolved bom may require additional repositories
for (BillOfMaterials b : boms.values()) {
for (String id : b.getRepositories()) {
for (BillOfMaterials bom : boms.values()) {
for (String id : bom.getRepositories()) {
repositories.put(id,
metadata.getConfiguration().getEnv().getRepositories().get(id));
}

View File

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

View File

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