You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by cs...@apache.org on 2017/08/23 14:49:50 UTC
[2/3] karaf git commit: Cache unmarshalled Features
Cache unmarshalled Features
If we are processing a deep feature tree with multiple dependencies
referencing same features (like in the case of OpenDaylight), we end
up unmarshalling the same features over and over again.
Rather than doing that, instantiate a cache, which will hold a weak
reference to features already encountered.
Before:
real 1m46.523s
user 1m59.258s
sys 0m17.048s
After:
real 0m42.642s
user 1m0.892s
sys 0m10.148s
Signed-off-by: Robert Varga <ni...@hq.sk>
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/9714d76b
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/9714d76b
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/9714d76b
Branch: refs/heads/master
Commit: 9714d76be6442faca13e6f45f02a27eac52b8ebb
Parents: ed79796
Author: Robert Varga <ni...@hq.sk>
Authored: Sun Aug 13 19:38:26 2017 +0200
Committer: Robert Varga <ni...@hq.sk>
Committed: Wed Aug 23 14:22:59 2017 +0200
----------------------------------------------------------------------
.../features/GenerateDescriptorMojo.java | 28 ++++++++++++++++----
1 file changed, 23 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/9714d76b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java
----------------------------------------------------------------------
diff --git a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java
index a6141ba..e4bcf07 100644
--- a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java
+++ b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java
@@ -38,6 +38,7 @@ import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
+import java.util.WeakHashMap;
import java.util.jar.JarInputStream;
import java.util.jar.Manifest;
@@ -456,6 +457,7 @@ public class GenerateDescriptorMojo extends MojoSupport {
// TODO Initialise the repositories from the existing feature file if any
Map<Dependency, Feature> otherFeatures = new HashMap<>();
Map<Feature, String> featureRepositories = new HashMap<>();
+ FeaturesCache cache = new FeaturesCache();
for (final LocalDependency entry : localDependencies) {
Object artifact = entry.getArtifact();
@@ -463,9 +465,11 @@ public class GenerateDescriptorMojo extends MojoSupport {
continue;
}
- processFeatureArtifact(features, feature, otherFeatures, featureRepositories, artifact, entry.getParent(),
- true);
+ processFeatureArtifact(features, feature, otherFeatures, featureRepositories, cache, artifact,
+ entry.getParent(), true);
}
+ // Do not retain cache beyond this point
+ cache = null;
// Second pass to look for bundles
if (addBundlesToPrimaryFeature) {
@@ -557,7 +561,7 @@ public class GenerateDescriptorMojo extends MojoSupport {
}
private void processFeatureArtifact(Features features, Feature feature, Map<Dependency, Feature> otherFeatures,
- Map<Feature, String> featureRepositories,
+ Map<Feature, String> featureRepositories, FeaturesCache cache,
Object artifact, Object parent, boolean add)
throws MojoExecutionException, XMLStreamException, JAXBException, IOException {
if (this.dependencyHelper.isArtifactAFeature(artifact) && FEATURE_CLASSIFIER.equals(
@@ -567,9 +571,9 @@ public class GenerateDescriptorMojo extends MojoSupport {
throw new MojoExecutionException(
"Cannot locate file for feature: " + artifact + " at " + featuresFile);
}
- Features includedFeatures = readFeaturesFile(featuresFile);
+ Features includedFeatures = cache.get(featuresFile);
for (String repository : includedFeatures.getRepository()) {
- processFeatureArtifact(features, feature, otherFeatures, featureRepositories,
+ processFeatureArtifact(features, feature, otherFeatures, featureRepositories, cache,
new DefaultArtifact(MavenUtil.mvnToAether(repository)), parent, false);
}
for (Feature includedFeature : includedFeatures.getFeature()) {
@@ -921,4 +925,18 @@ public class GenerateDescriptorMojo extends MojoSupport {
return "\tTree listing is saved here: " + treeListFile.getAbsolutePath() + "\n";
}
+ private static final class FeaturesCache {
+ private final Map<File, Features> map = new WeakHashMap<>();
+
+ Features get(final File featuresFile) throws XMLStreamException, JAXBException, IOException {
+ final Features existing = map.get(featuresFile);
+ if (existing != null) {
+ return existing;
+ }
+
+ final Features computed = readFeaturesFile(featuresFile);
+ map.put(featuresFile, computed);
+ return computed;
+ }
+ }
}