Skip to content

Commit

Permalink
Merge pull request #289 from kazuki-ma
Browse files Browse the repository at this point in the history
* gh-289:
  Polish "Cache names of local projects"
  Cache names of local projects

Closes gh-289
  • Loading branch information
wilkinsona committed Jan 13, 2021
2 parents b071a2e + 066521d commit 4f40c4b
Showing 1 changed file with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2018 the original author or authors.
* Copyright 2014-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -45,6 +45,8 @@ class VersionConfiguringAction implements Action<DependencyResolveDetails> {

private Set<String> directDependencies;

private Set<String> localProjectNames;

VersionConfiguringAction(Project project,
DependencyManagementContainer dependencyManagementContainer,
Configuration configuration) {
Expand Down Expand Up @@ -97,16 +99,15 @@ private boolean isDirectDependency(DependencyResolveDetails details) {

private boolean isDependencyOnLocalProject(Project project,
DependencyResolveDetails details) {
return getAllLocalProjectNames(project.getRootProject()).contains(details.getRequested()
.getGroup() + ":" + details.getRequested().getName());
}

private Set<String> getAllLocalProjectNames(Project rootProject) {
Set<String> names = new HashSet<String>();
for (Project localProject: rootProject.getAllprojects()) {
names.add(localProject.getGroup() + ":" + localProject.getName());
if (this.localProjectNames == null) {
Set<String> names = new HashSet<String>();
for (Project localProject : project.getRootProject().getAllprojects()) {
names.add(localProject.getGroup() + ":" + localProject.getName());
}
this.localProjectNames = names;
}
return names;
}

return localProjectNames
.contains(details.getRequested().getGroup() + ":" + details.getRequested().getName());
}
}

0 comments on commit 4f40c4b

Please sign in to comment.