From: Vratko Polak Date: Mon, 1 Aug 2016 13:22:41 +0000 (+0200) Subject: Bug 6187: Force more maven resolution in karaf-plugin X-Git-Tag: release/boron~20 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=e3a66683bef02c1ee7890681ab4db7e27ea8890c;p=odlparent.git Bug 6187: Force more maven resolution in karaf-plugin Especially concerning level 1 feature repository dependencies. This fixed Bug 6187 in my local testing. + Improve logging. Change-Id: Ie973e3669510061afd59a6c9d22f7a9161f0bd13 Signed-off-by: Vratko Polak --- diff --git a/karaf-plugin/src/main/java/org/opendaylight/odlparent/AetherUtil.java b/karaf-plugin/src/main/java/org/opendaylight/odlparent/AetherUtil.java index d0de62184..293f7588a 100644 --- a/karaf-plugin/src/main/java/org/opendaylight/odlparent/AetherUtil.java +++ b/karaf-plugin/src/main/java/org/opendaylight/odlparent/AetherUtil.java @@ -13,7 +13,6 @@ import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; - import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.RepositorySystem; import org.eclipse.aether.RepositorySystemSession; @@ -82,6 +81,7 @@ public class AetherUtil { for (ArtifactResult artifactResult : results.getArtifactResults()) { artifacts.add(artifactResult.getArtifact()); } + LOG.trace("resolveDependencies({}) returns {}", dependencies, artifacts); return artifacts; } @@ -100,6 +100,7 @@ public class AetherUtil { LOG.warn("Unable to resolve artifact: {}", e.getMessage(), e); return null; } + LOG.trace("resolveArtifacts({}) returns {}", artifact, result.getArtifact()); return result.getArtifact(); } @@ -128,6 +129,7 @@ public class AetherUtil { result.add(artifact); } } + LOG.trace("resolveArtifacts({}) returns {}", coords, result); return result; } @@ -153,6 +155,7 @@ public class AetherUtil { for (String coord : coords) { result.add(toDependency(coord)); } + LOG.trace("toDependencies({}) returns {}", coords, result); return result; } diff --git a/karaf-plugin/src/main/java/org/opendaylight/odlparent/FeatureUtil.java b/karaf-plugin/src/main/java/org/opendaylight/odlparent/FeatureUtil.java index 0e6ca993d..4777d2368 100644 --- a/karaf-plugin/src/main/java/org/opendaylight/odlparent/FeatureUtil.java +++ b/karaf-plugin/src/main/java/org/opendaylight/odlparent/FeatureUtil.java @@ -17,7 +17,6 @@ import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; - import org.apache.karaf.features.internal.model.Bundle; import org.apache.karaf.features.internal.model.ConfigFile; import org.apache.karaf.features.internal.model.Feature; @@ -26,8 +25,12 @@ import org.apache.karaf.features.internal.model.JaxbUtil; import org.eclipse.aether.artifact.Artifact; import org.eclipse.aether.resolution.ArtifactResolutionException; import org.ops4j.pax.url.mvn.internal.Parser; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public final class FeatureUtil { + private static final Logger LOG = LoggerFactory.getLogger(FeatureUtil.class); + private FeatureUtil() { throw new UnsupportedOperationException(); } @@ -44,6 +47,7 @@ public final class FeatureUtil { for (URL url : urls) { result.add(toCoord(url)); } + LOG.trace("toCoord({}) returns {}", urls, result); return result; } @@ -66,6 +70,7 @@ public final class FeatureUtil { coord = coord + ":" + parser.getClassifier(); } coord = coord + ":" + parser.getVersion().replaceAll("\\$.*$", ""); + LOG.trace("toCoord({}) returns {}", url, coord); return coord; } @@ -81,6 +86,7 @@ public final class FeatureUtil { for (String url : repository) { result.add(toCoord(new URL(url))); } + LOG.trace("mvnUrlsToCoord({}) returns {}", repository, result); return result; } @@ -107,6 +113,7 @@ public final class FeatureUtil { for (Features feature : features) { result.addAll(featuresRepositoryToCoords(feature)); } + LOG.trace("featuresRepositoryToCoords({}) returns {}", features, result); return result; } @@ -125,6 +132,7 @@ public final class FeatureUtil { if (feature.getConfigfile() != null) { result.addAll(configFilesToCoords(feature.getConfigfile())); } + LOG.trace("featureToCoords({}) returns {}", feature.getName(), result); return result; } @@ -140,6 +148,7 @@ public final class FeatureUtil { for (ConfigFile configFile : configfiles) { result.add(toCoord(new URL(configFile.getLocation()))); } + LOG.trace("configFilesToCoords({}) returns {}", configfiles, result); return result; } @@ -155,6 +164,7 @@ public final class FeatureUtil { for (Bundle bundle : bundles) { result.add(toCoord(new URL(bundle.getLocation()))); } + LOG.trace("bundlesToCoords({}) returns {}", bundles, result); return result; } @@ -175,6 +185,7 @@ public final class FeatureUtil { result.addAll(featureToCoords(feature)); } } + LOG.trace("featuresToCoords({}) returns {}", features.getName(), result); return result; } @@ -191,6 +202,7 @@ public final class FeatureUtil { for (Features feature : features) { result.addAll(featuresToCoords(feature)); } + LOG.trace("featuresToCoords({}) returns {}", features, result); return result; } @@ -206,6 +218,7 @@ public final class FeatureUtil { for (Artifact artifact : featureArtifacts) { result.add(readFeature(artifact)); } + LOG.trace("readFeatures({}) returns {}", featureArtifacts, result); return result; } @@ -219,7 +232,9 @@ public final class FeatureUtil { public static Features readFeature(Artifact artifact) throws FileNotFoundException { File file = artifact.getFile(); FileInputStream stream = new FileInputStream(file); - return JaxbUtil.unmarshal(stream, false); + Features result = JaxbUtil.unmarshal(stream, false); + LOG.trace("readFeature({}) returns {} without resolving first", artifact, result.getName()); + return result; } /** @@ -234,7 +249,9 @@ public final class FeatureUtil { public static Features readFeature(AetherUtil aetherUtil, String coords) throws ArtifactResolutionException, FileNotFoundException { Artifact artifact = aetherUtil.resolveArtifact(coords); - return readFeature(artifact); + Features result = readFeature(artifact); + LOG.trace("readFeature({}) returns {} after resolving first", coords, result.getName()); + return result; } /** @@ -251,15 +268,21 @@ public final class FeatureUtil { public static Set findAllFeaturesRecursively( AetherUtil aetherUtil, Features features, Set existingCoords) throws MalformedURLException, FileNotFoundException, ArtifactResolutionException { + LOG.debug("findAllFeaturesRecursively({}) starts", features.getName()); + LOG.trace("findAllFeaturesRecursively knows about these coords: {}", existingCoords); Set result = new LinkedHashSet<>(); Set coords = FeatureUtil.featuresRepositoryToCoords(features); for (String coord : coords) { if (!existingCoords.contains(coord)) { + LOG.trace("findAllFeaturesRecursively() going to add {}", coord); existingCoords.add(coord); Features feature = FeatureUtil.readFeature(aetherUtil, coord); result.add(feature); + LOG.debug("findAllFeaturesRecursively() added {}", coord); result.addAll(findAllFeaturesRecursively(aetherUtil, FeatureUtil.readFeature(aetherUtil, coord), existingCoords)); + } else { + LOG.trace("findAllFeaturesRecursively() skips known {}", coord); } } return result; @@ -286,4 +309,19 @@ public final class FeatureUtil { return result; } + /** + * Unmarshals all the features (including known ones) starting from the given features. + * + * @param aetherUtil The Aether resolver. + * @param features The starting features. + * @return The features. + * @throws MalformedURLException if a URL is malformed. + * @throws FileNotFoundException if a file is missing. + * @throws ArtifactResolutionException if artifact coordinates can't be resolved. + */ + public static Set findAllFeaturesRecursively(AetherUtil aetherUtil, Set features) + throws MalformedURLException, FileNotFoundException, ArtifactResolutionException { + return findAllFeaturesRecursively(aetherUtil, features, new LinkedHashSet()); + } + } diff --git a/karaf-plugin/src/main/java/org/opendaylight/odlparent/KarafFeaturesDependencyFilter.java b/karaf-plugin/src/main/java/org/opendaylight/odlparent/KarafFeaturesDependencyFilter.java index 634091996..c97011c8d 100644 --- a/karaf-plugin/src/main/java/org/opendaylight/odlparent/KarafFeaturesDependencyFilter.java +++ b/karaf-plugin/src/main/java/org/opendaylight/odlparent/KarafFeaturesDependencyFilter.java @@ -9,7 +9,6 @@ package org.opendaylight.odlparent; import java.util.List; - import org.eclipse.aether.graph.DependencyFilter; import org.eclipse.aether.graph.DependencyNode; diff --git a/karaf-plugin/src/main/java/org/opendaylight/odlparent/MvnToAetherMapper.java b/karaf-plugin/src/main/java/org/opendaylight/odlparent/MvnToAetherMapper.java index 0a2cb84ab..dafbcb6a6 100644 --- a/karaf-plugin/src/main/java/org/opendaylight/odlparent/MvnToAetherMapper.java +++ b/karaf-plugin/src/main/java/org/opendaylight/odlparent/MvnToAetherMapper.java @@ -10,7 +10,6 @@ package org.opendaylight.odlparent; import java.util.ArrayList; import java.util.List; - import org.eclipse.aether.artifact.DefaultArtifact; import org.eclipse.aether.artifact.DefaultArtifactType; import org.eclipse.aether.graph.Dependency; diff --git a/karaf-plugin/src/main/java/org/opendaylight/odlparent/PopulateLocalRepoMojo.java b/karaf-plugin/src/main/java/org/opendaylight/odlparent/PopulateLocalRepoMojo.java index a77635e3e..928a1de7f 100644 --- a/karaf-plugin/src/main/java/org/opendaylight/odlparent/PopulateLocalRepoMojo.java +++ b/karaf-plugin/src/main/java/org/opendaylight/odlparent/PopulateLocalRepoMojo.java @@ -26,7 +26,6 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Properties; import java.util.Set; - import org.apache.karaf.features.internal.model.Features; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; @@ -115,16 +114,17 @@ public class PopulateLocalRepoMojo aetherUtil.resolveDependencies(MvnToAetherMapper.toAether(project.getDependencies()), new KarafFeaturesDependencyFilter())); Set features = FeatureUtil.readFeatures(featureArtifacts); - features.addAll(FeatureUtil.findAllFeaturesRecursively(aetherUtil, features, - FeatureUtil.featuresRepositoryToCoords(features))); + // Do not provide FeatureUtil.featuresRepositoryToCoords(features)) as existingCoords + // to findAllFeaturesRecursively, as those coords are not resolved yet, and it would lead to Bug 6187. + features.addAll(FeatureUtil.findAllFeaturesRecursively(aetherUtil, features)); for (Features feature : features) { - LOG.info("Features Repos discovered recursively: {}", feature.getName()); + LOG.info("Feature repository discovered recursively: {}", feature.getName()); } Set artifacts = aetherUtil.resolveArtifacts(FeatureUtil.featuresToCoords(features)); artifacts.addAll(featureArtifacts); for (Artifact artifact : artifacts) { - LOG.info("Artifacts to be installed: {}", artifact.toString()); + LOG.debug("Artifact to be installed: {}", artifact.toString()); } if (localRepo != null) { aetherUtil.installArtifacts(artifacts);