1 |
commit: 9f694b0493877d9bf6f86b8be26f9e98a3d80eb4 |
2 |
Author: Miroslav Šulc <fordfrog <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sun Nov 3 13:54:04 2019 +0000 |
4 |
Commit: Miroslav Šulc <fordfrog <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun Nov 3 13:54:04 2019 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/java-ebuilder.git/commit/?id=9f694b04 |
7 |
|
8 |
changed handling of java eclasses |
9 |
|
10 |
1) now parsing all java eclasses |
11 |
2) all java eclasses are written to the cache file |
12 |
3) usage of each java eclass is written to the output when regreshing cache |
13 |
|
14 |
Signed-off-by: Miroslav Šulc <fordfrog <AT> gentoo.org> |
15 |
|
16 |
.../gentoo/java/ebuilder/portage/CacheItem.java | 30 ++-- |
17 |
.../java/ebuilder/portage/PortageParser.java | 154 +++++++++------------ |
18 |
2 files changed, 86 insertions(+), 98 deletions(-) |
19 |
|
20 |
diff --git a/src/main/java/org/gentoo/java/ebuilder/portage/CacheItem.java b/src/main/java/org/gentoo/java/ebuilder/portage/CacheItem.java |
21 |
index feff43d..e48177f 100644 |
22 |
--- a/src/main/java/org/gentoo/java/ebuilder/portage/CacheItem.java |
23 |
+++ b/src/main/java/org/gentoo/java/ebuilder/portage/CacheItem.java |
24 |
@@ -1,5 +1,10 @@ |
25 |
package org.gentoo.java.ebuilder.portage; |
26 |
|
27 |
+import java.util.ArrayList; |
28 |
+import java.util.Arrays; |
29 |
+import java.util.Collections; |
30 |
+import java.util.List; |
31 |
+ |
32 |
/** |
33 |
* Container for cache item information. |
34 |
* |
35 |
@@ -20,9 +25,9 @@ public class CacheItem { |
36 |
*/ |
37 |
private final String groupId; |
38 |
/** |
39 |
- * Main Java eclass inherited. |
40 |
+ * List of inherited java eclasses, in the order as they are inherited. |
41 |
*/ |
42 |
- private final String javaEclass; |
43 |
+ private final List<String> javaEclasses; |
44 |
/** |
45 |
* Maven version (of package jar). |
46 |
*/ |
47 |
@@ -60,12 +65,12 @@ public class CacheItem { |
48 |
* @param groupId {@link #groupId} |
49 |
* @param artifactId {@link #artifactId} |
50 |
* @param mavenVersion {@link #mavenVersion} |
51 |
- * @param javaEclass {@link #javaEclass} |
52 |
+ * @param javaEclasses {@link #javaEclasses} |
53 |
*/ |
54 |
public CacheItem(final String category, final String pkg, |
55 |
final String version, final String slot, final String useFlag, |
56 |
final String groupId, final String artifactId, |
57 |
- final String mavenVersion, final String javaEclass) { |
58 |
+ final String mavenVersion, final List<String> javaEclasses) { |
59 |
this.category = category; |
60 |
this.pkg = pkg; |
61 |
this.version = version; |
62 |
@@ -74,7 +79,8 @@ public class CacheItem { |
63 |
this.groupId = groupId; |
64 |
this.artifactId = artifactId; |
65 |
this.mavenVersion = mavenVersion; |
66 |
- this.javaEclass = javaEclass; |
67 |
+ this.javaEclasses |
68 |
+ = Collections.unmodifiableList(new ArrayList<>(javaEclasses)); |
69 |
|
70 |
parsedMavenVersion = mavenVersion == null |
71 |
? null : new MavenVersion(mavenVersion); |
72 |
@@ -110,10 +116,10 @@ public class CacheItem { |
73 |
mavenVersion = null; |
74 |
} |
75 |
|
76 |
- if (parts.length > 8) { |
77 |
- javaEclass = parts[8].isEmpty() ? null : parts[8]; |
78 |
+ if (parts.length > 8 && !parts[0].isEmpty()) { |
79 |
+ javaEclasses = Arrays.asList(parts[8].split(",")); |
80 |
} else { |
81 |
- javaEclass = null; |
82 |
+ javaEclasses = null; |
83 |
} |
84 |
} catch (final ArrayIndexOutOfBoundsException ex) { |
85 |
throw new RuntimeException("Failed to parse cache line: " + line, |
86 |
@@ -152,12 +158,12 @@ public class CacheItem { |
87 |
} |
88 |
|
89 |
/** |
90 |
- * Getter for {@link #javaEclass}. |
91 |
+ * Getter for {@link #javaEclasses}. |
92 |
* |
93 |
- * @return {@link #javaEclass} |
94 |
+ * @return {@link #javaEclasses} |
95 |
*/ |
96 |
- public String getJavaEclass() { |
97 |
- return javaEclass; |
98 |
+ public List<String> getJavaEclasses() { |
99 |
+ return Collections.unmodifiableList(javaEclasses); |
100 |
} |
101 |
|
102 |
/** |
103 |
|
104 |
diff --git a/src/main/java/org/gentoo/java/ebuilder/portage/PortageParser.java b/src/main/java/org/gentoo/java/ebuilder/portage/PortageParser.java |
105 |
index 8d49411..9da0fb7 100644 |
106 |
--- a/src/main/java/org/gentoo/java/ebuilder/portage/PortageParser.java |
107 |
+++ b/src/main/java/org/gentoo/java/ebuilder/portage/PortageParser.java |
108 |
@@ -11,11 +11,14 @@ import java.nio.file.Path; |
109 |
import java.nio.file.StandardOpenOption; |
110 |
import java.text.MessageFormat; |
111 |
import java.util.ArrayList; |
112 |
+import java.util.Arrays; |
113 |
+import java.util.Collections; |
114 |
import java.util.HashMap; |
115 |
import java.util.List; |
116 |
import java.util.Map; |
117 |
import java.util.regex.Matcher; |
118 |
import java.util.regex.Pattern; |
119 |
+import java.util.stream.Collectors; |
120 |
import org.gentoo.java.ebuilder.Config; |
121 |
|
122 |
/** |
123 |
@@ -33,22 +36,10 @@ public class PortageParser { |
124 |
* Current ant utilities eclass name. |
125 |
*/ |
126 |
private static final String ECLASS_ANT_TASKS = "ant-tasks"; |
127 |
- /** |
128 |
- * Current java package eclass name. |
129 |
- */ |
130 |
- private static final String ECLASS_JAVA_PKG = "java-pkg-2"; |
131 |
/** |
132 |
* Current java optional package eclass name. |
133 |
*/ |
134 |
private static final String ECLASS_JAVA_PKG_OPT = "java-pkg-opt-2"; |
135 |
- /** |
136 |
- * Current java simple package eclass name. |
137 |
- */ |
138 |
- private static final String ECLASS_JAVA_PKG_SIMPLE = "java-pkg-simple"; |
139 |
- /** |
140 |
- * Current java utilities eclass name. |
141 |
- */ |
142 |
- private static final String ECLASS_JAVA_UTILS = "java-utils-2"; |
143 |
/** |
144 |
* Pattern for parsing ebuild file name. |
145 |
*/ |
146 |
@@ -117,28 +108,9 @@ public class PortageParser { |
147 |
*/ |
148 |
private final List<CacheItem> cacheItems = new ArrayList<>(40_000); |
149 |
/** |
150 |
- * Count of ebuilds inheriting {@link #ECLASS_ANT_TASKS} as the main eclass. |
151 |
- */ |
152 |
- private int eclassAntTasksCount; |
153 |
- /** |
154 |
- * Count of ebuilds inheriting {@link #ECLASS_JAVA_PKG} as the main eclass. |
155 |
- */ |
156 |
- private int eclassJavaPkgCount; |
157 |
- /** |
158 |
- * Count of ebuilds inheriting {@link #ECLASS_JAVA_PKG_OPT} as the main |
159 |
- * eclass. |
160 |
+ * Used for cellecting counts of java eclasses. |
161 |
*/ |
162 |
- private int eclassJavaPkgOptCount; |
163 |
- /** |
164 |
- * Count of ebuilds inheriting {@link #ECLASS_JAVA_PKG_SIMPLE} as the main |
165 |
- * eclass. |
166 |
- */ |
167 |
- private int eclassJavaPkgSimpleCount; |
168 |
- /** |
169 |
- * Count of ebuilds inheriting {@link #ECLASS_JAVA_UTILS} as the main |
170 |
- * eclass. |
171 |
- */ |
172 |
- private int eclassJavaUtilsCount; |
173 |
+ private final Map<String, Integer> eclassesCounts = new HashMap<>(10); |
174 |
/** |
175 |
* Number of processed categories. Updated during parsing the tree. |
176 |
*/ |
177 |
@@ -164,11 +136,7 @@ public class PortageParser { |
178 |
processedCategories = 0; |
179 |
processedPackages = 0; |
180 |
processedEbuilds = 0; |
181 |
- eclassAntTasksCount = 0; |
182 |
- eclassJavaPkgCount = 0; |
183 |
- eclassJavaPkgOptCount = 0; |
184 |
- eclassJavaPkgSimpleCount = 0; |
185 |
- eclassJavaUtilsCount = 0; |
186 |
+ eclassesCounts.clear(); |
187 |
|
188 |
config.getStdoutWriter().println("Parsing portage tree @ " |
189 |
+ config.getPortageTree() + " ..."); |
190 |
@@ -176,43 +144,69 @@ public class PortageParser { |
191 |
|
192 |
final long endTimestamp = System.currentTimeMillis(); |
193 |
|
194 |
- config.getStdoutWriter().println(MessageFormat.format( |
195 |
+ config.getStdoutWriter().print(MessageFormat.format( |
196 |
"Parsed {0} categories {1} packages {2} ebuilds in {3}ms and " |
197 |
- + "found {4} java ebuilds (main java eclass: {5} = {6}, " |
198 |
- + "{7} = {8}, {9} = {10}, {11} = {12}, {13} = {14})", |
199 |
+ + "found {4} java ebuilds", |
200 |
processedCategories, processedPackages, processedEbuilds, |
201 |
- endTimestamp - startTimestamp, cacheItems.size(), |
202 |
- ECLASS_ANT_TASKS, eclassAntTasksCount, ECLASS_JAVA_PKG, |
203 |
- eclassJavaPkgCount, ECLASS_JAVA_PKG_OPT, eclassJavaPkgOptCount, |
204 |
- ECLASS_JAVA_PKG_SIMPLE, eclassJavaPkgSimpleCount, |
205 |
- ECLASS_JAVA_UTILS, eclassJavaUtilsCount)); |
206 |
+ endTimestamp - startTimestamp, cacheItems.size())); |
207 |
+ |
208 |
+ final List<String> sortedEclasses |
209 |
+ = new ArrayList<>(eclassesCounts.keySet()); |
210 |
+ Collections.sort(sortedEclasses); |
211 |
+ |
212 |
+ config.getStdoutWriter().print((" (used java eclasses: ")); |
213 |
+ |
214 |
+ for (int i = 0; i < sortedEclasses.size(); i++) { |
215 |
+ if (i > 0) { |
216 |
+ config.getStdoutWriter().print(", "); |
217 |
+ } |
218 |
+ |
219 |
+ final String eclass = sortedEclasses.get(i); |
220 |
+ |
221 |
+ config.getStdoutWriter().print(eclass); |
222 |
+ config.getStdoutWriter().print(" = "); |
223 |
+ config.getStdoutWriter().print(eclassesCounts.get(eclass)); |
224 |
+ } |
225 |
+ |
226 |
+ config.getStdoutWriter().println(")"); |
227 |
|
228 |
config.getStdoutWriter().print("Writing cache file..."); |
229 |
writeCacheFile(config); |
230 |
config.getStdoutWriter().println("done"); |
231 |
} |
232 |
|
233 |
+ /** |
234 |
+ * Increases counter for each eclass from the list. |
235 |
+ * |
236 |
+ * @param eclasses list of eclasses |
237 |
+ */ |
238 |
+ private void countEclasses(final List<String> eclasses) { |
239 |
+ eclasses.forEach((eclass) -> { |
240 |
+ final Integer count = eclassesCounts.get(eclass); |
241 |
+ |
242 |
+ if (count == null) { |
243 |
+ eclassesCounts.put(eclass, 1); |
244 |
+ } else { |
245 |
+ eclassesCounts.put(eclass, count + 1); |
246 |
+ } |
247 |
+ }); |
248 |
+ } |
249 |
+ |
250 |
/** |
251 |
* Extracts the most important java eclass from ebuild inherit line. |
252 |
* |
253 |
* @param inheritLine ebuild inherit line |
254 |
* |
255 |
- * @return java eclass or null |
256 |
+ * @return list of inherited java eclasses or null |
257 |
*/ |
258 |
- private String getJavaInheritEclass(final String inheritLine) { |
259 |
- if (inheritLine.contains(ECLASS_JAVA_PKG)) { |
260 |
- return ECLASS_JAVA_PKG; |
261 |
- } else if (inheritLine.contains(ECLASS_JAVA_PKG_OPT)) { |
262 |
- return ECLASS_JAVA_PKG_OPT; |
263 |
- } else if (inheritLine.contains(ECLASS_JAVA_PKG_SIMPLE)) { |
264 |
- return ECLASS_JAVA_PKG_SIMPLE; |
265 |
- } else if (inheritLine.contains(ECLASS_JAVA_UTILS)) { |
266 |
- return ECLASS_JAVA_UTILS; |
267 |
- } else if (inheritLine.contains(ECLASS_ANT_TASKS)) { |
268 |
- return ECLASS_ANT_TASKS; |
269 |
- } else { |
270 |
- return null; |
271 |
- } |
272 |
+ private List<String> getJavaInheritEclasses(final String inheritLine) { |
273 |
+ final String[] lines |
274 |
+ = inheritLine.replaceAll("^inherit\\s+", "").split("\\s+"); |
275 |
+ |
276 |
+ return Arrays.stream(lines). |
277 |
+ filter((line) -> line.startsWith("java-") |
278 |
+ || ECLASS_ANT_TASKS.equals(line)). |
279 |
+ collect(Collectors.toList()); |
280 |
} |
281 |
|
282 |
/** |
283 |
@@ -257,7 +251,7 @@ public class PortageParser { |
284 |
final String pkg = ebuild.getParentFile().getName(); |
285 |
final String version = filename.substring(pkg.length() + 1); |
286 |
final Map<String, String> variables = new HashMap<>(20); |
287 |
- String eclass = null; |
288 |
+ List<String> eclasses = null; |
289 |
String slot = "0"; |
290 |
String useFlag = null; |
291 |
String mavenId = null; |
292 |
@@ -290,9 +284,9 @@ public class PortageParser { |
293 |
} |
294 |
|
295 |
if (line.startsWith("inherit ")) { |
296 |
- eclass = getJavaInheritEclass(line); |
297 |
+ eclasses = getJavaInheritEclasses(line); |
298 |
|
299 |
- if (eclass == null) { |
300 |
+ if (eclasses == null || eclasses.isEmpty()) { |
301 |
return; |
302 |
} |
303 |
} else if (line.startsWith("SLOT=")) { |
304 |
@@ -313,11 +307,11 @@ public class PortageParser { |
305 |
throw new RuntimeException("Failed to read ebuild", ex); |
306 |
} |
307 |
|
308 |
- if (eclass == null) { |
309 |
+ if (eclasses == null) { |
310 |
return; |
311 |
} |
312 |
|
313 |
- if (ECLASS_JAVA_PKG_OPT.equals(eclass) && useFlag == null) { |
314 |
+ if (eclasses.contains(ECLASS_JAVA_PKG_OPT) && useFlag == null) { |
315 |
useFlag = "java"; |
316 |
} |
317 |
|
318 |
@@ -358,25 +352,9 @@ public class PortageParser { |
319 |
} |
320 |
|
321 |
cacheItems.add(new CacheItem(category, pkg, version, slot, useFlag, |
322 |
- groupId, artifactId, mavenVersion, eclass)); |
323 |
- |
324 |
- switch (eclass) { |
325 |
- case ECLASS_ANT_TASKS: |
326 |
- eclassAntTasksCount++; |
327 |
- break; |
328 |
- case ECLASS_JAVA_PKG: |
329 |
- eclassJavaPkgCount++; |
330 |
- break; |
331 |
- case ECLASS_JAVA_PKG_OPT: |
332 |
- eclassJavaPkgOptCount++; |
333 |
- break; |
334 |
- case ECLASS_JAVA_PKG_SIMPLE: |
335 |
- eclassJavaPkgSimpleCount++; |
336 |
- break; |
337 |
- case ECLASS_JAVA_UTILS: |
338 |
- eclassJavaUtilsCount++; |
339 |
- break; |
340 |
- } |
341 |
+ groupId, artifactId, mavenVersion, eclasses)); |
342 |
+ |
343 |
+ countEclasses(eclasses); |
344 |
} |
345 |
|
346 |
/** |
347 |
@@ -511,7 +489,11 @@ public class PortageParser { |
348 |
writer.write(cacheItem.getMavenVersion() == null |
349 |
? "" : cacheItem.getMavenVersion()); |
350 |
writer.write(':'); |
351 |
- writer.write(cacheItem.getJavaEclass()); |
352 |
+ |
353 |
+ if (cacheItem.getJavaEclasses() != null |
354 |
+ && !cacheItem.getJavaEclasses().isEmpty()) { |
355 |
+ writer.write(String.join(",", cacheItem.getJavaEclasses())); |
356 |
+ } |
357 |
|
358 |
writer.write('\n'); |
359 |
} |