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 684c2527e9f..0f8c3862059 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 @@ -26,9 +26,11 @@ import java.util.Collection; import java.util.Comparator; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.jar.JarInputStream; import java.util.jar.Manifest; @@ -37,6 +39,7 @@ import javax.xml.stream.XMLStreamException; import org.apache.karaf.features.internal.model.*; +import org.apache.karaf.tooling.utils.Dependency31Helper; import org.apache.karaf.tooling.utils.DependencyHelper; import org.apache.karaf.tooling.utils.DependencyHelperFactory; import org.apache.karaf.tooling.utils.LocalDependency; @@ -490,6 +493,7 @@ private void writeFeatures(PrintStream out) throws ArtifactResolutionException, // TODO Initialise the repositories from the existing feature file if any Map otherFeatures = new HashMap<>(); Map featureRepositories = new HashMap<>(); + Set recognizedFeatures = new HashSet<>(); FeaturesCache cache = new FeaturesCache(featuresCacheSize, artifactCacheSize); for (final LocalDependency entry : localDependencies) { Object artifact = entry.getArtifact(); @@ -499,7 +503,7 @@ private void writeFeatures(PrintStream out) throws ArtifactResolutionException, } processFeatureArtifact(features, feature, otherFeatures, featureRepositories, cache, artifact, - entry.getParent(), true); + entry.getParent(), true, recognizedFeatures); } // Do not retain cache beyond this point cache = null; @@ -514,7 +518,7 @@ private void writeFeatures(PrintStream out) throws ArtifactResolutionException, continue; } - if (!this.dependencyHelper.isArtifactAFeature(artifact)) { + if (!this.dependencyHelper.isArtifactAFeature(artifact) && !recognizedFeatures.contains(artifact)) { String bundleName = this.dependencyHelper.artifactToMvn(artifact, getVersionOrRange(entry.getParent(), artifact)); for (ConfigFile cf : feature.getConfigfile()) { @@ -609,11 +613,25 @@ private void writeFeatures(PrintStream out) throws ArtifactResolutionException, private void processFeatureArtifact(Features features, Feature feature, Map otherFeatures, Map featureRepositories, FeaturesCache cache, - Object artifact, Object parent, boolean add) + Object artifact, Object parent, boolean add, Set recognizedFeatures) throws MojoExecutionException, XMLStreamException, JAXBException, IOException { - if (this.dependencyHelper.isArtifactAFeature(artifact) && FEATURE_CLASSIFIER.equals( - this.dependencyHelper.getClassifier(artifact))) { - File featuresFile = this.dependencyHelper.resolve(artifact, getLog()); + boolean isFeature = this.dependencyHelper.isArtifactAFeature(artifact); + File featuresFile = null; + if (!isFeature) { + // For XML artifacts with non-standard classifiers, resolve and check content + featuresFile = this.dependencyHelper.resolve(artifact, getLog()); + if (featuresFile != null && featuresFile.exists() + && Dependency31Helper.isFeaturesXml(featuresFile)) { + isFeature = true; + } + } + if (isFeature) { + if (recognizedFeatures != null) { + recognizedFeatures.add(artifact); + } + if (featuresFile == null) { + featuresFile = this.dependencyHelper.resolve(artifact, getLog()); + } if (featuresFile == null || !featuresFile.exists()) { throw new MojoExecutionException( "Cannot locate file for feature: " + artifact + " at " + featuresFile); @@ -621,7 +639,7 @@ private void processFeatureArtifact(Features features, Feature feature, Map