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 15:19:59 UTC
[1/3] karaf git commit: Reuse extracted manifest
Repository: karaf
Updated Branches:
refs/heads/karaf-4.1.x 74bbcc47c -> ecf0bde71
Reuse extracted manifest
Obtaining the manifest can cost us some IO. Treat it as an invariant
when determining whether a file is a bundle.
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/ecf0bde7
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/ecf0bde7
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/ecf0bde7
Branch: refs/heads/karaf-4.1.x
Commit: ecf0bde71d92fa4203230ee6137fa221f9d58677
Parents: 82e2439
Author: Robert Varga <ni...@hq.sk>
Authored: Sun Aug 13 20:26:17 2017 +0200
Committer: Christian Schneider <ch...@die-schneider.net>
Committed: Wed Aug 23 17:19:52 2017 +0200
----------------------------------------------------------------------
.../apache/karaf/tooling/features/GenerateDescriptorMojo.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/ecf0bde7/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 6eb5ef1..f975dbf 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
@@ -487,8 +487,6 @@ public class GenerateDescriptorMojo extends MojoSupport {
if (!this.dependencyHelper.isArtifactAFeature(artifact)) {
String bundleName = this.dependencyHelper.artifactToMvn(artifact, getVersionOrRange(entry.getParent(), artifact));
- File bundleFile = this.dependencyHelper.resolve(artifact, getLog());
- Manifest manifest = getManifest(bundleFile);
for (ConfigFile cf : feature.getConfigfile()) {
if (bundleName.equals(cf.getLocation().replace('\n', ' ').trim())) {
@@ -497,7 +495,9 @@ public class GenerateDescriptorMojo extends MojoSupport {
}
}
- if (manifest == null || !ManifestUtils.isBundle(getManifest(bundleFile))) {
+ File bundleFile = this.dependencyHelper.resolve(artifact, getLog());
+ Manifest manifest = getManifest(bundleFile);
+ if (manifest == null || !ManifestUtils.isBundle(manifest)) {
bundleName = "wrap:" + bundleName;
needWrap = true;
}
[2/3] karaf git commit: Cache unmarshalled Features
Posted by cs...@apache.org.
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/82e2439f
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/82e2439f
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/82e2439f
Branch: refs/heads/karaf-4.1.x
Commit: 82e2439f2c97f7d510998529dad6fba91e727e07
Parents: e2415b8
Author: Robert Varga <ni...@hq.sk>
Authored: Sun Aug 13 19:38:26 2017 +0200
Committer: Christian Schneider <ch...@die-schneider.net>
Committed: Wed Aug 23 17:19:52 2017 +0200
----------------------------------------------------------------------
.../features/GenerateDescriptorMojo.java | 30 ++++++++++++++++----
1 file changed, 24 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/82e2439f/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 222c51f..6eb5ef1 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
@@ -39,6 +39,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;
@@ -459,7 +460,8 @@ public class GenerateDescriptorMojo extends MojoSupport {
// the feature's Maven artifact to allow for multi-feature repositories)
// TODO Initialise the repositories from the existing feature file if any
Map<Dependency, Feature> otherFeatures = new HashMap<>();
- Map<Feature, String> featureRepositories = new HashMap<Feature, String>();
+ Map<Feature, String> featureRepositories = new HashMap<>();
+ FeaturesCache cache = new FeaturesCache();
for (final LocalDependency entry : localDependencies) {
Object artifact = entry.getArtifact();
@@ -467,9 +469,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) {
@@ -561,7 +565,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(
@@ -571,9 +575,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()) {
@@ -940,4 +944,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;
+ }
+ }
}
[3/3] karaf git commit: Use java.util.file.Files.newInputStream()
Posted by cs...@apache.org.
Use java.util.file.Files.newInputStream()
Instead of wiring to FileInputStream, which is hard to GC due to
the presence of finalize(), use Files.newInputStream.
Brings down feature generation time in OpenDaylight, before:
real 2m5.828s
user 2m14.886s
sys 0m20.849s
after:
real 1m46.523s
user 1m59.258s
sys 0m17.048s
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/e2415b8a
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/e2415b8a
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/e2415b8a
Branch: refs/heads/karaf-4.1.x
Commit: e2415b8af82db7b223054e7814eaefb733a64aeb
Parents: 74bbcc4
Author: Robert Varga <ni...@hq.sk>
Authored: Sun Aug 13 18:56:29 2017 +0200
Committer: Christian Schneider <ch...@die-schneider.net>
Committed: Wed Aug 23 17:19:52 2017 +0200
----------------------------------------------------------------------
.../features/GenerateDescriptorMojo.java | 36 +++++++++-----------
.../apache/karaf/tooling/utils/MojoSupport.java | 12 +++----
2 files changed, 22 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/e2415b8a/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 c6dc9fc..222c51f 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
@@ -23,7 +23,6 @@ import static org.apache.karaf.deployer.kar.KarArtifactInstaller.FEATURE_CLASSIF
import java.io.BufferedInputStream;
import java.io.BufferedWriter;
import java.io.File;
-import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -31,6 +30,7 @@ import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.StringWriter;
+import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -605,7 +605,7 @@ public class GenerateDescriptorMojo extends MojoSupport {
}
}
- private Dependency findMatchingDependency(List<Dependency> dependencies, Dependency reference) {
+ private static Dependency findMatchingDependency(List<Dependency> dependencies, Dependency reference) {
String referenceName = reference.getName();
for (Dependency dependency : dependencies) {
if (referenceName.equals(dependency.getName())) {
@@ -615,7 +615,7 @@ public class GenerateDescriptorMojo extends MojoSupport {
return null;
}
- private void mergeDependencies(Dependency target, Dependency source) {
+ private static void mergeDependencies(Dependency target, Dependency source) {
if (target.getVersion() == null || Feature.DEFAULT_VERSION.equals(target.getVersion())) {
target.setVersion(source.getVersion());
}
@@ -646,30 +646,28 @@ public class GenerateDescriptorMojo extends MojoSupport {
*/
private Manifest getManifest(File file) throws IOException {
- InputStream is;
+ final InputStream is;
try {
- is = new BufferedInputStream(new FileInputStream(file));
+ is = Files.newInputStream(file.toPath());
} catch (Exception e) {
getLog().warn("Error while opening artifact", e);
return null;
}
- try {
- is.mark(256 * 1024);
- JarInputStream jar = new JarInputStream(is);
- Manifest m = jar.getManifest();
- if (m == null) {
- getLog().warn("Manifest not present in the first entry of the zip - " + file.getName());
+ try (BufferedInputStream bis = new BufferedInputStream(is)) {
+ bis.mark(256 * 1024);
+
+ try (JarInputStream jar = new JarInputStream(bis)) {
+ Manifest m = jar.getManifest();
+ if (m == null) {
+ getLog().warn("Manifest not present in the first entry of the zip - " + file.getName());
+ }
+ return m;
}
- jar.close();
- return m;
- } finally {
- // just in case when we did not open bundle
- is.close();
}
}
- private Features readFeaturesFile(File featuresFile) throws XMLStreamException, JAXBException, IOException {
+ private static Features readFeaturesFile(File featuresFile) throws XMLStreamException, JAXBException, IOException {
return JaxbUtil.unmarshal(featuresFile.toURI().toASCIIString(), false);
}
@@ -879,7 +877,7 @@ public class GenerateDescriptorMojo extends MojoSupport {
}
}
- private Features toFeatures(Collection<Bundle> addedBundles, Collection<Dependency> addedDependencys, ObjectFactory objectFactory) {
+ private static Features toFeatures(Collection<Bundle> addedBundles, Collection<Dependency> addedDependencys, ObjectFactory objectFactory) {
Features features = objectFactory.createFeaturesRoot();
Feature feature = objectFactory.createFeature();
feature.getBundle().addAll(addedBundles);
@@ -889,7 +887,7 @@ public class GenerateDescriptorMojo extends MojoSupport {
}
- private void writeDependencies(Features features, File file) throws JAXBException, IOException {
+ private static void writeDependencies(Features features, File file) throws JAXBException, IOException {
file.getParentFile().mkdirs();
if (!file.getParentFile().exists() || !file.getParentFile().isDirectory()) {
throw new IOException("Cannot create directory at " + file.getParent());
http://git-wip-us.apache.org/repos/asf/karaf/blob/e2415b8a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/utils/MojoSupport.java
----------------------------------------------------------------------
diff --git a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/utils/MojoSupport.java b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/utils/MojoSupport.java
index 71134bb..168e7cb 100644
--- a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/utils/MojoSupport.java
+++ b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/utils/MojoSupport.java
@@ -18,11 +18,12 @@
package org.apache.karaf.tooling.utils;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
+import java.io.InputStream;
import java.io.IOException;
+import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
+import java.nio.file.Files;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
@@ -354,11 +355,8 @@ public abstract class MojoSupport extends AbstractMojo {
File targetDir = destFile.getParentFile();
ensureDirExists(targetDir);
- try {
- try (
- FileInputStream is = new FileInputStream(sourceFile);
- FileOutputStream bos = new FileOutputStream(destFile)
- ) {
+ try (InputStream is = Files.newInputStream(sourceFile.toPath())) {
+ try (OutputStream bos = Files.newOutputStream(destFile.toPath())) {
StreamUtils.copy(is, bos);
}
} catch (IOException e) {