|
17 | 17 | */
|
18 | 18 | package com.axelor.gradle;
|
19 | 19 |
|
| 20 | +import com.google.common.cache.CacheBuilder; |
| 21 | +import com.google.common.cache.CacheLoader; |
| 22 | +import com.google.common.cache.LoadingCache; |
20 | 23 | import java.io.File;
|
21 | 24 | import java.io.IOException;
|
22 | 25 | import java.util.ArrayList;
|
|
38 | 41 |
|
39 | 42 | public class AxelorUtils {
|
40 | 43 |
|
| 44 | + private AxelorUtils() {} |
| 45 | + |
| 46 | + private static LoadingCache<Project, List<Project>> includedBuildRootsCache = |
| 47 | + CacheBuilder.newBuilder() |
| 48 | + .build( |
| 49 | + new CacheLoader<Project, List<Project>>() { |
| 50 | + @Override |
| 51 | + public List<Project> load(Project project) throws Exception { |
| 52 | + return project.getGradle().getIncludedBuilds().stream() |
| 53 | + .map(b -> ((IncludedBuildInternal) b).getTarget()) |
| 54 | + .map(b -> b.getBuild().getRootProject()) |
| 55 | + .collect(Collectors.toList()); |
| 56 | + } |
| 57 | + }); |
| 58 | + |
41 | 59 | public static String toRelativePath(Project project, File file) {
|
42 | 60 | return project.getProjectDir().toPath().relativize(file.toPath()).toString();
|
43 | 61 | }
|
44 | 62 |
|
45 |
| - private static Stream<Project> includedBuildRoots(Project project) { |
46 |
| - return project.getGradle().getIncludedBuilds().stream() |
47 |
| - .map(b -> ((IncludedBuildInternal) b).getTarget()) |
48 |
| - .map(b -> b.getBuild().getRootProject()); |
| 63 | + private static List<Project> includedBuildRoots(Project project) { |
| 64 | + return includedBuildRootsCache.getUnchecked(project); |
49 | 65 | }
|
50 | 66 |
|
51 | 67 | public static List<Project> findIncludedBuildProjects(Project project) {
|
52 |
| - return includedBuildRoots(project) |
| 68 | + return includedBuildRoots(project).stream() |
53 | 69 | .flatMap(root -> Stream.concat(Stream.of(root), root.getSubprojects().stream()))
|
54 | 70 | .collect(Collectors.toList());
|
55 | 71 | }
|
@@ -118,7 +134,11 @@ public static Project findProject(Project project, ResolvedArtifact artifact) {
|
118 | 134 | Project sub = project.findProject(path);
|
119 | 135 | // consider projects from included builds
|
120 | 136 | if (sub == null) {
|
121 |
| - sub = includedBuildRoots(project).map(p -> p.findProject(path)).findFirst().orElse(null); |
| 137 | + sub = |
| 138 | + includedBuildRoots(project).stream() |
| 139 | + .map(p -> p.findProject(path)) |
| 140 | + .findFirst() |
| 141 | + .orElse(null); |
122 | 142 | }
|
123 | 143 | return sub;
|
124 | 144 | }
|
|
0 commit comments