Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id F1EA6200BEF for ; Wed, 4 Jan 2017 22:06:23 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id F1681160B3A; Wed, 4 Jan 2017 21:06:23 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 7A831160B21 for ; Wed, 4 Jan 2017 22:06:22 +0100 (CET) Received: (qmail 72701 invoked by uid 500); 4 Jan 2017 21:06:21 -0000 Mailing-List: contact commits-help@karaf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@karaf.apache.org Delivered-To: mailing list commits@karaf.apache.org Received: (qmail 72686 invoked by uid 99); 4 Jan 2017 21:06:21 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Jan 2017 21:06:21 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 70F8DDF9FA; Wed, 4 Jan 2017 21:06:21 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: jbonofre@apache.org To: commits@karaf.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: karaf git commit: [KARAF-4897] Add an option to simplify bundle dependencies Date: Wed, 4 Jan 2017 21:06:21 +0000 (UTC) archived-at: Wed, 04 Jan 2017 21:06:24 -0000 Repository: karaf Updated Branches: refs/heads/karaf-4.0.x 84515ee44 -> 8ea352180 [KARAF-4897] Add an option to simplify bundle dependencies Project: http://git-wip-us.apache.org/repos/asf/karaf/repo Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/8ea35218 Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/8ea35218 Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/8ea35218 Branch: refs/heads/karaf-4.0.x Commit: 8ea352180978d69efd29d9daa90f474d52be41a8 Parents: 84515ee Author: Stephen Kitt Authored: Thu Dec 15 10:50:25 2016 +0100 Committer: Jean-Baptiste Onofré Committed: Wed Jan 4 21:50:14 2017 +0100 ---------------------------------------------------------------------- .../src/it/test-simplify-bundles/control.xml | 39 ++++++++++ .../src/it/test-simplify-bundles/pom.xml | 76 ++++++++++++++++++ .../simplify-bundle-a/pom.xml | 54 +++++++++++++ .../simplify-bundle-a/src/main/java/test/A.java | 25 ++++++ .../simplify-bundle-b/pom.xml | 66 ++++++++++++++++ .../simplify-bundle-b/src/main/java/test/B.java | 25 ++++++ .../simplify-feature-a/pom.xml | 71 +++++++++++++++++ .../simplify-feature-as-is/pom.xml | 71 +++++++++++++++++ .../simplify-feature-reduced/pom.xml | 72 +++++++++++++++++ .../simplify-features/pom.xml | 81 ++++++++++++++++++++ .../src/it/test-simplify-bundles/verify.bsh | 34 ++++++++ .../features/GenerateDescriptorMojo.java | 28 ++++++- 12 files changed, 641 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/karaf/blob/8ea35218/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/control.xml ---------------------------------------------------------------------- diff --git a/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/control.xml b/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/control.xml new file mode 100644 index 0000000..94cb36a --- /dev/null +++ b/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/control.xml @@ -0,0 +1,39 @@ + + + + + mvn:test/simplify-feature-a/1.0-SNAPSHOT/xml/features + +
Check that bundles are simplified
+ simplify-feature-a + mvn:test/simplify-bundle-b/1.0-SNAPSHOT + mvn:test/simplify-bundle-a/1.0-SNAPSHOT +
+ +
Check that bundles are simplified
+ simplify-feature-a + mvn:test/simplify-bundle-b/1.0-SNAPSHOT +
+ +
Check that bundles are simplified
+ simplify-feature-as-is + simplify-feature-reduced +
+
http://git-wip-us.apache.org/repos/asf/karaf/blob/8ea35218/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/pom.xml ---------------------------------------------------------------------- diff --git a/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/pom.xml b/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/pom.xml new file mode 100644 index 0000000..b61c6a3 --- /dev/null +++ b/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/pom.xml @@ -0,0 +1,76 @@ + + + + + + 4.0.0 + + test + test-simplify-bundles + 1.0-SNAPSHOT + + pom + + Check that bundles are simplified + + + + + UTF-8 + + + + simplify-bundle-a + simplify-bundle-b + simplify-feature-a + simplify-feature-as-is + simplify-feature-reduced + simplify-features + + + + + + org.apache.felix + maven-bundle-plugin + true + + + org.apache.karaf.tooling + karaf-maven-plugin + @pom.version@ + + + generate-features-file + package + + features-generate-descriptor + + + + + + + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/karaf/blob/8ea35218/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/simplify-bundle-a/pom.xml ---------------------------------------------------------------------- diff --git a/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/simplify-bundle-a/pom.xml b/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/simplify-bundle-a/pom.xml new file mode 100644 index 0000000..27dfccd --- /dev/null +++ b/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/simplify-bundle-a/pom.xml @@ -0,0 +1,54 @@ + + + + + 4.0.0 + + test + test-simplify-bundles + 1.0-SNAPSHOT + ../pom.xml + + + test + simplify-bundle-a + 1.0-SNAPSHOT + + bundle + + + UTF-8 + + + + + + + + + org.apache.felix + maven-bundle-plugin + 2.3.7 + true + + + + http://git-wip-us.apache.org/repos/asf/karaf/blob/8ea35218/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/simplify-bundle-a/src/main/java/test/A.java ---------------------------------------------------------------------- diff --git a/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/simplify-bundle-a/src/main/java/test/A.java b/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/simplify-bundle-a/src/main/java/test/A.java new file mode 100644 index 0000000..9aa5496 --- /dev/null +++ b/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/simplify-bundle-a/src/main/java/test/A.java @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package test.a; + +public class A +{ + public static String ASTRING = "A-string"; +} http://git-wip-us.apache.org/repos/asf/karaf/blob/8ea35218/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/simplify-bundle-b/pom.xml ---------------------------------------------------------------------- diff --git a/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/simplify-bundle-b/pom.xml b/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/simplify-bundle-b/pom.xml new file mode 100644 index 0000000..f84310f --- /dev/null +++ b/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/simplify-bundle-b/pom.xml @@ -0,0 +1,66 @@ + + + + + 4.0.0 + + test + test-simplify-bundles + 1.0-SNAPSHOT + ../pom.xml + + + test + simplify-bundle-b + 1.0-SNAPSHOT + + bundle + + + UTF-8 + + + + + test + simplify-feature-a + 1.0-SNAPSHOT + xml + features + + + test + simplify-bundle-a + 1.0-SNAPSHOT + + + + + + + org.apache.felix + maven-bundle-plugin + 2.3.7 + true + + + + http://git-wip-us.apache.org/repos/asf/karaf/blob/8ea35218/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/simplify-bundle-b/src/main/java/test/B.java ---------------------------------------------------------------------- diff --git a/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/simplify-bundle-b/src/main/java/test/B.java b/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/simplify-bundle-b/src/main/java/test/B.java new file mode 100644 index 0000000..b66ddea --- /dev/null +++ b/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/simplify-bundle-b/src/main/java/test/B.java @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package test.b; + +public class B +{ + public static String BSTRING = "B-string"; +} http://git-wip-us.apache.org/repos/asf/karaf/blob/8ea35218/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/simplify-feature-a/pom.xml ---------------------------------------------------------------------- diff --git a/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/simplify-feature-a/pom.xml b/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/simplify-feature-a/pom.xml new file mode 100644 index 0000000..abbf8a9 --- /dev/null +++ b/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/simplify-feature-a/pom.xml @@ -0,0 +1,71 @@ + + + + + 4.0.0 + + test + test-simplify-bundles + 1.0-SNAPSHOT + ../pom.xml + + + test + simplify-feature-a + 1.0-SNAPSHOT + + feature + + + UTF-8 + + + + + test + simplify-bundle-a + 1.0-SNAPSHOT + + + + + + + org.apache.karaf.tooling + karaf-maven-plugin + @pom.version@ + true + + + generate-features-file + package + + features-generate-descriptor + + + true + + + + + + + http://git-wip-us.apache.org/repos/asf/karaf/blob/8ea35218/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/simplify-feature-as-is/pom.xml ---------------------------------------------------------------------- diff --git a/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/simplify-feature-as-is/pom.xml b/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/simplify-feature-as-is/pom.xml new file mode 100644 index 0000000..3bab1f6 --- /dev/null +++ b/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/simplify-feature-as-is/pom.xml @@ -0,0 +1,71 @@ + + + + + 4.0.0 + + test + test-simplify-bundles + 1.0-SNAPSHOT + ../pom.xml + + + test + simplify-feature-as-is + 1.0-SNAPSHOT + + feature + + + UTF-8 + + + + + test + simplify-bundle-b + 1.0-SNAPSHOT + + + + + + + org.apache.karaf.tooling + karaf-maven-plugin + @pom.version@ + true + + + generate-features-file + package + + features-generate-descriptor + + + true + + + + + + + http://git-wip-us.apache.org/repos/asf/karaf/blob/8ea35218/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/simplify-feature-reduced/pom.xml ---------------------------------------------------------------------- diff --git a/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/simplify-feature-reduced/pom.xml b/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/simplify-feature-reduced/pom.xml new file mode 100644 index 0000000..0c3247b --- /dev/null +++ b/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/simplify-feature-reduced/pom.xml @@ -0,0 +1,72 @@ + + + + + 4.0.0 + + test + test-simplify-bundles + 1.0-SNAPSHOT + ../pom.xml + + + test + simplify-feature-reduced + 1.0-SNAPSHOT + + feature + + + UTF-8 + + + + + test + simplify-bundle-b + 1.0-SNAPSHOT + + + + + + + org.apache.karaf.tooling + karaf-maven-plugin + @pom.version@ + true + + + generate-features-file + package + + features-generate-descriptor + + + true + true + + + + + + + http://git-wip-us.apache.org/repos/asf/karaf/blob/8ea35218/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/simplify-features/pom.xml ---------------------------------------------------------------------- diff --git a/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/simplify-features/pom.xml b/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/simplify-features/pom.xml new file mode 100644 index 0000000..da5ca35 --- /dev/null +++ b/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/simplify-features/pom.xml @@ -0,0 +1,81 @@ + + + + + 4.0.0 + + test + test-simplify-bundles + 1.0-SNAPSHOT + ../pom.xml + + + test + simplify-features + 1.0-SNAPSHOT + + feature + + + UTF-8 + + + + + test + simplify-feature-as-is + 1.0-SNAPSHOT + xml + features + + + test + simplify-feature-reduced + 1.0-SNAPSHOT + xml + features + + + + + + + org.apache.karaf.tooling + karaf-maven-plugin + @pom.version@ + true + + + generate-features-file + package + + features-generate-descriptor + + + true + true + + + + + + + http://git-wip-us.apache.org/repos/asf/karaf/blob/8ea35218/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/verify.bsh ---------------------------------------------------------------------- diff --git a/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/verify.bsh b/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/verify.bsh new file mode 100644 index 0000000..78f37fd --- /dev/null +++ b/tooling/karaf-maven-plugin/src/it/test-simplify-bundles/verify.bsh @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.custommonkey.xmlunit.*; +import java.io.*; +import java.lang.*; + +Reader r = new FileReader(new File(basedir, "control.xml")); + +// load the features file pushed to the repository +File generated = new File(basedir, "simplify-features/target/feature/feature.xml"); +if (generated.exists()) { + try { + XMLAssert.assertXMLEqual(r, new FileReader(generated)); + return true; + } catch (Throwable ignored) { } +} +return false; http://git-wip-us.apache.org/repos/asf/karaf/blob/8ea35218/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 1ee0a65..55355a4 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 @@ -251,6 +251,14 @@ public class GenerateDescriptorMojo extends MojoSupport { @Parameter(defaultValue = "false") private boolean includeTransitiveVersionRanges; + /** + * Flag indicating whether the plugin should simplify bundle dependencies. If the flag is set to {@code true} + * and a bundle dependency is determined to be included in a feature dependency, the bundle dependency is + * dropped. + */ + @Parameter(defaultValue = "false") + private boolean simplifyBundleDependencies; + // ************************************************* // READ-ONLY MAVEN PLUGIN PARAMETERS // ************************************************* @@ -459,7 +467,11 @@ public class GenerateDescriptorMojo extends MojoSupport { if (bundle == null) { bundle = objectFactory.createBundle(); bundle.setLocation(bundleName); - if (!"provided".equals(entry.getScope()) || !ignoreScopeProvided) { + // Check the features this feature depends on don't already contain the dependency + // TODO Perhaps only for transitive dependencies? + boolean includedTransitively = + simplifyBundleDependencies && isBundleIncludedTransitively(feature, otherFeatures, bundle); + if (!includedTransitively && (!"provided".equals(entry.getScope()) || !ignoreScopeProvided)) { feature.getBundle().add(bundle); } } @@ -543,6 +555,20 @@ public class GenerateDescriptorMojo extends MojoSupport { } } + private boolean isBundleIncludedTransitively(Feature feature, Map otherFeatures, + Bundle bundle) { + for (Dependency dependency : feature.getFeature()) { + Feature otherFeature = otherFeatures.get(dependency); + if (otherFeature != null) { + if (otherFeature.getBundle().contains(bundle) || isBundleIncludedTransitively(otherFeature, + otherFeatures, bundle)) { + return true; + } + } + } + return false; + } + /** * Extract the MANIFEST from the give file. */