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;
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();
}
for (URL url : urls) {
result.add(toCoord(url));
}
+ LOG.trace("toCoord({}) returns {}", urls, result);
return result;
}
coord = coord + ":" + parser.getClassifier();
}
coord = coord + ":" + parser.getVersion().replaceAll("\\$.*$", "");
+ LOG.trace("toCoord({}) returns {}", url, coord);
return coord;
}
for (String url : repository) {
result.add(toCoord(new URL(url)));
}
+ LOG.trace("mvnUrlsToCoord({}) returns {}", repository, result);
return result;
}
for (Features feature : features) {
result.addAll(featuresRepositoryToCoords(feature));
}
+ LOG.trace("featuresRepositoryToCoords({}) returns {}", features, result);
return result;
}
if (feature.getConfigfile() != null) {
result.addAll(configFilesToCoords(feature.getConfigfile()));
}
+ LOG.trace("featureToCoords({}) returns {}", feature.getName(), result);
return result;
}
for (ConfigFile configFile : configfiles) {
result.add(toCoord(new URL(configFile.getLocation())));
}
+ LOG.trace("configFilesToCoords({}) returns {}", configfiles, result);
return result;
}
for (Bundle bundle : bundles) {
result.add(toCoord(new URL(bundle.getLocation())));
}
+ LOG.trace("bundlesToCoords({}) returns {}", bundles, result);
return result;
}
result.addAll(featureToCoords(feature));
}
}
+ LOG.trace("featuresToCoords({}) returns {}", features.getName(), result);
return result;
}
for (Features feature : features) {
result.addAll(featuresToCoords(feature));
}
+ LOG.trace("featuresToCoords({}) returns {}", features, result);
return result;
}
for (Artifact artifact : featureArtifacts) {
result.add(readFeature(artifact));
}
+ LOG.trace("readFeatures({}) returns {}", featureArtifacts, result);
return result;
}
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;
}
/**
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;
}
/**
public static Set<Features> findAllFeaturesRecursively(
AetherUtil aetherUtil, Features features, Set<String> existingCoords)
throws MalformedURLException, FileNotFoundException, ArtifactResolutionException {
+ LOG.debug("findAllFeaturesRecursively({}) starts", features.getName());
+ LOG.trace("findAllFeaturesRecursively knows about these coords: {}", existingCoords);
Set<Features> result = new LinkedHashSet<>();
Set<String> 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;
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<Features> findAllFeaturesRecursively(AetherUtil aetherUtil, Set<Features> features)
+ throws MalformedURLException, FileNotFoundException, ArtifactResolutionException {
+ return findAllFeaturesRecursively(aetherUtil, features, new LinkedHashSet<String>());
+ }
+
}
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;
aetherUtil.resolveDependencies(MvnToAetherMapper.toAether(project.getDependencies()),
new KarafFeaturesDependencyFilter()));
Set<Features> 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<Artifact> 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);