Skip to content

Commit 4f40c4b

Browse files
committed
Merge pull request #289 from kazuki-ma
* gh-289: Polish "Cache names of local projects" Cache names of local projects Closes gh-289
2 parents b071a2e + 066521d commit 4f40c4b

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/main/java/io/spring/gradle/dependencymanagement/internal/VersionConfiguringAction.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2018 the original author or authors.
2+
* Copyright 2014-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -45,6 +45,8 @@ class VersionConfiguringAction implements Action<DependencyResolveDetails> {
4545

4646
private Set<String> directDependencies;
4747

48+
private Set<String> localProjectNames;
49+
4850
VersionConfiguringAction(Project project,
4951
DependencyManagementContainer dependencyManagementContainer,
5052
Configuration configuration) {
@@ -97,16 +99,15 @@ private boolean isDirectDependency(DependencyResolveDetails details) {
9799

98100
private boolean isDependencyOnLocalProject(Project project,
99101
DependencyResolveDetails details) {
100-
return getAllLocalProjectNames(project.getRootProject()).contains(details.getRequested()
101-
.getGroup() + ":" + details.getRequested().getName());
102-
}
103-
104-
private Set<String> getAllLocalProjectNames(Project rootProject) {
105-
Set<String> names = new HashSet<String>();
106-
for (Project localProject: rootProject.getAllprojects()) {
107-
names.add(localProject.getGroup() + ":" + localProject.getName());
102+
if (this.localProjectNames == null) {
103+
Set<String> names = new HashSet<String>();
104+
for (Project localProject : project.getRootProject().getAllprojects()) {
105+
names.add(localProject.getGroup() + ":" + localProject.getName());
106+
}
107+
this.localProjectNames = names;
108108
}
109-
return names;
110-
}
111109

110+
return localProjectNames
111+
.contains(details.getRequested().getGroup() + ":" + details.getRequested().getName());
112+
}
112113
}

0 commit comments

Comments
 (0)