You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2022/04/21 08:47:28 UTC
[camel] 01/06: CAMEL-17894: reduce SpiGeneratorMojo method sizes to simplify performance analysis
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 247d67231888e7b464c8517e27768aaf6ebfd155
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Wed Apr 20 16:37:06 2022 +0200
CAMEL-17894: reduce SpiGeneratorMojo
method sizes to simplify performance analysis
---
.../camel/maven/packaging/SpiGeneratorMojo.java | 56 ++++++++++++++--------
1 file changed, 35 insertions(+), 21 deletions(-)
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpiGeneratorMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpiGeneratorMojo.java
index 4a56d73546a..0975be40487 100644
--- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpiGeneratorMojo.java
+++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpiGeneratorMojo.java
@@ -17,6 +17,7 @@
package org.apache.camel.maven.packaging;
import java.io.File;
+import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
@@ -167,27 +168,7 @@ public class SpiGeneratorMojo extends AbstractGeneratorMojo {
for (String cpe : project.getCompileClasspathElements()) {
Matcher matcher = cpePattern.matcher(cpe);
if (matcher.matches()) {
- try (JarFile jf = new JarFile(cpe)) {
- JarEntry indexEntry = jf.getJarEntry("META-INF/jandex.idx");
- if (indexEntry != null) {
- try (InputStream is = jf.getInputStream(indexEntry)) {
- indices.add(new IndexReader(is).read());
- }
- } else {
- final Indexer indexer = new Indexer();
-
- List<JarEntry> classes = jf.stream()
- .filter(je -> je.getName().endsWith(".class"))
- .collect(Collectors.toList());
-
- for (JarEntry je : classes) {
- try (InputStream is = jf.getInputStream(je)) {
- indexer.index(is);
- }
- }
- indices.add(indexer.complete());
- }
- }
+ addIndex(indices, cpe);
}
}
return CompositeIndex.create(indices);
@@ -196,6 +177,39 @@ public class SpiGeneratorMojo extends AbstractGeneratorMojo {
}
}
+ private void addIndex(List<IndexView> indices, String cpe) throws IOException {
+ try (JarFile jf = new JarFile(cpe)) {
+ JarEntry indexEntry = jf.getJarEntry("META-INF/jandex.idx");
+ if (indexEntry != null) {
+ readIndexFromJandex(indices, jf, indexEntry);
+ } else {
+ createIndexFromClass(indices, jf);
+ }
+ }
+ }
+
+ private void createIndexFromClass(List<IndexView> indices, JarFile jf) throws IOException {
+ final Indexer indexer = new Indexer();
+
+ List<JarEntry> classes = jf.stream()
+ .filter(je -> je.getName().endsWith(".class"))
+ .collect(Collectors.toList());
+
+ for (JarEntry je : classes) {
+ try (InputStream is = jf.getInputStream(je)) {
+ indexer.index(is);
+ }
+ }
+
+ indices.add(indexer.complete());
+ }
+
+ private void readIndexFromJandex(List<IndexView> indices, JarFile jf, JarEntry indexEntry) throws IOException {
+ try (InputStream is = jf.getInputStream(indexEntry)) {
+ indices.add(new IndexReader(is).read());
+ }
+ }
+
private String generateConstantProviderClass(String fqn, Map<String, String> fields) {
String pn = fqn.substring(0, fqn.lastIndexOf('.'));
String cn = fqn.substring(fqn.lastIndexOf('.') + 1);