From 64c681e56d8a21daa8d2ca3b83521c51dda77554 Mon Sep 17 00:00:00 2001 From: Stephen Kitt Date: Fri, 27 May 2016 16:20:21 +0200 Subject: [PATCH] [KARAF-1583] Add repository dependencies Any repository dependencies encountered while processing feature dependencies are added to the repositories. We track feature-repository correspondences and only add necessary repositories after processing all the features, so we end up adding repositories necessary to find feature dependencies, but nothing else. Repositories are tracked explicitly to allow later integration of repositories mentioned in pre-existing feature.xml files; this will allow large feature repositories to be used optimally. Signed-off-by: Stephen Kitt --- .../test-repository-dependencies/control.xml | 27 +++++++ .../dependency-bundle-a/pom.xml | 60 ++++++++++++++ .../src/main/java/test/A.java | 25 ++++++ .../dependency-bundle-b/pom.xml | 51 ++++++++++++ .../src/main/java/test/B.java | 25 ++++++ .../dependency-feature-a/pom.xml | 67 ++++++++++++++++ .../dependency-feature-b/pom.xml | 67 ++++++++++++++++ .../it/test-repository-dependencies/pom.xml | 78 +++++++++++++++++++ .../test-repository-dependencies/verify.bsh | 35 +++++++++ .../features/GenerateDescriptorMojo.java | 38 ++++++--- 10 files changed, 461 insertions(+), 12 deletions(-) create mode 100644 tooling/karaf-maven-plugin/src/it/test-repository-dependencies/control.xml create mode 100644 tooling/karaf-maven-plugin/src/it/test-repository-dependencies/dependency-bundle-a/pom.xml create mode 100644 tooling/karaf-maven-plugin/src/it/test-repository-dependencies/dependency-bundle-a/src/main/java/test/A.java create mode 100644 tooling/karaf-maven-plugin/src/it/test-repository-dependencies/dependency-bundle-b/pom.xml create mode 100644 tooling/karaf-maven-plugin/src/it/test-repository-dependencies/dependency-bundle-b/src/main/java/test/B.java create mode 100644 tooling/karaf-maven-plugin/src/it/test-repository-dependencies/dependency-feature-a/pom.xml create mode 100644 tooling/karaf-maven-plugin/src/it/test-repository-dependencies/dependency-feature-b/pom.xml create mode 100644 tooling/karaf-maven-plugin/src/it/test-repository-dependencies/pom.xml create mode 100644 tooling/karaf-maven-plugin/src/it/test-repository-dependencies/verify.bsh diff --git a/tooling/karaf-maven-plugin/src/it/test-repository-dependencies/control.xml b/tooling/karaf-maven-plugin/src/it/test-repository-dependencies/control.xml new file mode 100644 index 00000000000..0cde6c9bee8 --- /dev/null +++ b/tooling/karaf-maven-plugin/src/it/test-repository-dependencies/control.xml @@ -0,0 +1,27 @@ + + + + + mvn:test/dependency-feature-b/1.0-SNAPSHOT/xml/features + + dependency-feature-b + mvn:test/dependency-bundle-a/1.0-SNAPSHOT + + diff --git a/tooling/karaf-maven-plugin/src/it/test-repository-dependencies/dependency-bundle-a/pom.xml b/tooling/karaf-maven-plugin/src/it/test-repository-dependencies/dependency-bundle-a/pom.xml new file mode 100644 index 00000000000..574d05b8371 --- /dev/null +++ b/tooling/karaf-maven-plugin/src/it/test-repository-dependencies/dependency-bundle-a/pom.xml @@ -0,0 +1,60 @@ + + + + + 4.0.0 + + test + test-repository-dependencies + 1.0-SNAPSHOT + ../pom.xml + + + test + dependency-bundle-a + 1.0-SNAPSHOT + bundle + + + UTF-8 + + + + + test + dependency-feature-b + ${project.version} + features + xml + + + + + + + org.apache.felix + maven-bundle-plugin + 2.3.7 + true + + + + diff --git a/tooling/karaf-maven-plugin/src/it/test-repository-dependencies/dependency-bundle-a/src/main/java/test/A.java b/tooling/karaf-maven-plugin/src/it/test-repository-dependencies/dependency-bundle-a/src/main/java/test/A.java new file mode 100644 index 00000000000..9aa5496e849 --- /dev/null +++ b/tooling/karaf-maven-plugin/src/it/test-repository-dependencies/dependency-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"; +} diff --git a/tooling/karaf-maven-plugin/src/it/test-repository-dependencies/dependency-bundle-b/pom.xml b/tooling/karaf-maven-plugin/src/it/test-repository-dependencies/dependency-bundle-b/pom.xml new file mode 100644 index 00000000000..639b73d259c --- /dev/null +++ b/tooling/karaf-maven-plugin/src/it/test-repository-dependencies/dependency-bundle-b/pom.xml @@ -0,0 +1,51 @@ + + + + + 4.0.0 + + test + test-repository-dependencies + 1.0-SNAPSHOT + ../pom.xml + + + test + dependency-bundle-b + 1.0-SNAPSHOT + + bundle + + + UTF-8 + + + + + + org.apache.felix + maven-bundle-plugin + 2.3.7 + true + + + + diff --git a/tooling/karaf-maven-plugin/src/it/test-repository-dependencies/dependency-bundle-b/src/main/java/test/B.java b/tooling/karaf-maven-plugin/src/it/test-repository-dependencies/dependency-bundle-b/src/main/java/test/B.java new file mode 100644 index 00000000000..b66ddeafec3 --- /dev/null +++ b/tooling/karaf-maven-plugin/src/it/test-repository-dependencies/dependency-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"; +} diff --git a/tooling/karaf-maven-plugin/src/it/test-repository-dependencies/dependency-feature-a/pom.xml b/tooling/karaf-maven-plugin/src/it/test-repository-dependencies/dependency-feature-a/pom.xml new file mode 100644 index 00000000000..4a7e0a2d14a --- /dev/null +++ b/tooling/karaf-maven-plugin/src/it/test-repository-dependencies/dependency-feature-a/pom.xml @@ -0,0 +1,67 @@ + + + + + 4.0.0 + + test + test-repository-dependencies + 1.0-SNAPSHOT + ../pom.xml + + + test + dependency-feature-a + 1.0-SNAPSHOT + feature + + + UTF-8 + + + + + test + dependency-bundle-a + ${project.version} + + + + + + + org.apache.karaf.tooling + karaf-maven-plugin + @pom.version@ + true + + + generate-features-file + package + + features-generate-descriptor + + + + + + + diff --git a/tooling/karaf-maven-plugin/src/it/test-repository-dependencies/dependency-feature-b/pom.xml b/tooling/karaf-maven-plugin/src/it/test-repository-dependencies/dependency-feature-b/pom.xml new file mode 100644 index 00000000000..8f02f5189b6 --- /dev/null +++ b/tooling/karaf-maven-plugin/src/it/test-repository-dependencies/dependency-feature-b/pom.xml @@ -0,0 +1,67 @@ + + + + + 4.0.0 + + test + test-repository-dependencies + 1.0-SNAPSHOT + ../pom.xml + + + test + dependency-feature-b + 1.0-SNAPSHOT + feature + + + UTF-8 + + + + + test + dependency-bundle-b + ${project.version} + + + + + + + org.apache.karaf.tooling + karaf-maven-plugin + @pom.version@ + true + + + generate-features-file + package + + features-generate-descriptor + + + + + + + diff --git a/tooling/karaf-maven-plugin/src/it/test-repository-dependencies/pom.xml b/tooling/karaf-maven-plugin/src/it/test-repository-dependencies/pom.xml new file mode 100644 index 00000000000..063e4ff3750 --- /dev/null +++ b/tooling/karaf-maven-plugin/src/it/test-repository-dependencies/pom.xml @@ -0,0 +1,78 @@ + + + + + + 4.0.0 + + test + test-repository-dependencies + 1.0-SNAPSHOT + pom + + + UTF-8 + + + + + + dependency-feature-a + dependency-bundle-a + dependency-feature-b + dependency-bundle-b + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + 256M + ${compiler.fork} + + + + org.apache.felix + maven-bundle-plugin + true + + + org.apache.karaf.tooling + karaf-maven-plugin + @pom.version@ + + + generate-features-file + package + + features-generate-descriptor + + + + + + + + + + diff --git a/tooling/karaf-maven-plugin/src/it/test-repository-dependencies/verify.bsh b/tooling/karaf-maven-plugin/src/it/test-repository-dependencies/verify.bsh new file mode 100644 index 00000000000..97f7ccc25c2 --- /dev/null +++ b/tooling/karaf-maven-plugin/src/it/test-repository-dependencies/verify.bsh @@ -0,0 +1,35 @@ +/* + * 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, "dependency-feature-a/target/feature/feature.xml" ); +if (generated.exists()) { + try { + XMLAssert.assertXMLEqual(r, new FileReader(generated)); + return true; + } catch (Throwable ignored) { } +} + +return false; 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 bba5e55ca2d..821cc93e125 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 @@ -417,8 +417,11 @@ private void writeFeatures(PrintStream out) throws ArtifactResolutionException, boolean needWrap = false; // First pass to look for features - // Track other features we depend on + // Track other features we depend on and their repositories (we track repositories instead of building them from + // the feature's Maven artifact to allow for multi-feature repositories) + // TODO Initialise the repositories from the existing feature file if any Map otherFeatures = new HashMap<>(); + Map featureRepositories = new HashMap(); for (final LocalDependency entry : localDependencies) { Object artifact = entry.getArtifact(); @@ -426,7 +429,8 @@ private void writeFeatures(PrintStream out) throws ArtifactResolutionException, continue; } - processFeatureArtifact(features, feature, otherFeatures, artifact, entry.getParent(), true); + processFeatureArtifact(features, feature, otherFeatures, featureRepositories, artifact, entry.getParent(), + true); } // Second pass to look for bundles @@ -484,6 +488,19 @@ private void writeFeatures(PrintStream out) throws ArtifactResolutionException, features.getFeature().add(feature); } + // Add any missing repositories for the included features + for (Feature includedFeature : features.getFeature()) { + for (Dependency dependency : includedFeature.getFeature()) { + Feature dependedFeature = otherFeatures.get(dependency); + if (dependedFeature != null && !features.getFeature().contains(dependedFeature)) { + String repository = featureRepositories.get(dependedFeature); + if (repository != null && !features.getRepository().contains(repository)) { + features.getRepository().add(repository); + } + } + } + } + JaxbUtil.marshal(features, out); try { checkChanges(features, objectFactory); @@ -494,6 +511,7 @@ private void writeFeatures(PrintStream out) throws ArtifactResolutionException, } private void processFeatureArtifact(Features features, Feature feature, Map otherFeatures, + Map featureRepositories, Object artifact, Object parent, boolean add) throws MojoExecutionException, XMLStreamException, JAXBException, IOException { if (this.dependencyHelper.isArtifactAFeature(artifact) && FEATURE_CLASSIFIER.equals( @@ -505,7 +523,7 @@ private void processFeatureArtifact(Features features, Feature feature, Map