2626import java .util .Collection ;
2727import java .util .Comparator ;
2828import java .util .HashMap ;
29+ import java .util .HashSet ;
2930import java .util .LinkedHashSet ;
3031import java .util .List ;
3132import java .util .Map ;
33+ import java .util .Set ;
3234import java .util .jar .JarInputStream ;
3335import java .util .jar .Manifest ;
3436
3739import javax .xml .stream .XMLStreamException ;
3840
3941import org .apache .karaf .features .internal .model .*;
42+ import org .apache .karaf .tooling .utils .Dependency31Helper ;
4043import org .apache .karaf .tooling .utils .DependencyHelper ;
4144import org .apache .karaf .tooling .utils .DependencyHelperFactory ;
4245import org .apache .karaf .tooling .utils .LocalDependency ;
@@ -490,6 +493,7 @@ private void writeFeatures(PrintStream out) throws ArtifactResolutionException,
490493 // TODO Initialise the repositories from the existing feature file if any
491494 Map <Dependency , Feature > otherFeatures = new HashMap <>();
492495 Map <Feature , String > featureRepositories = new HashMap <>();
496+ Set <Object > recognizedFeatures = new HashSet <>();
493497 FeaturesCache cache = new FeaturesCache (featuresCacheSize , artifactCacheSize );
494498 for (final LocalDependency entry : localDependencies ) {
495499 Object artifact = entry .getArtifact ();
@@ -499,7 +503,7 @@ private void writeFeatures(PrintStream out) throws ArtifactResolutionException,
499503 }
500504
501505 processFeatureArtifact (features , feature , otherFeatures , featureRepositories , cache , artifact ,
502- entry .getParent (), true );
506+ entry .getParent (), true , recognizedFeatures );
503507 }
504508 // Do not retain cache beyond this point
505509 cache = null ;
@@ -514,7 +518,7 @@ private void writeFeatures(PrintStream out) throws ArtifactResolutionException,
514518 continue ;
515519 }
516520
517- if (!this .dependencyHelper .isArtifactAFeature (artifact )) {
521+ if (!this .dependencyHelper .isArtifactAFeature (artifact ) && ! recognizedFeatures . contains ( artifact ) ) {
518522 String bundleName = this .dependencyHelper .artifactToMvn (artifact , getVersionOrRange (entry .getParent (), artifact ));
519523
520524 for (ConfigFile cf : feature .getConfigfile ()) {
@@ -609,19 +613,33 @@ private void writeFeatures(PrintStream out) throws ArtifactResolutionException,
609613
610614 private void processFeatureArtifact (Features features , Feature feature , Map <Dependency , Feature > otherFeatures ,
611615 Map <Feature , String > featureRepositories , FeaturesCache cache ,
612- Object artifact , Object parent , boolean add )
616+ Object artifact , Object parent , boolean add , Set < Object > recognizedFeatures )
613617 throws MojoExecutionException , XMLStreamException , JAXBException , IOException {
614- if (this .dependencyHelper .isArtifactAFeature (artifact ) && FEATURE_CLASSIFIER .equals (
615- this .dependencyHelper .getClassifier (artifact ))) {
616- File featuresFile = this .dependencyHelper .resolve (artifact , getLog ());
618+ boolean isFeature = this .dependencyHelper .isArtifactAFeature (artifact );
619+ File featuresFile = null ;
620+ if (!isFeature ) {
621+ // For XML artifacts with non-standard classifiers, resolve and check content
622+ featuresFile = this .dependencyHelper .resolve (artifact , getLog ());
623+ if (featuresFile != null && featuresFile .exists ()
624+ && Dependency31Helper .isFeaturesXml (featuresFile )) {
625+ isFeature = true ;
626+ }
627+ }
628+ if (isFeature ) {
629+ if (recognizedFeatures != null ) {
630+ recognizedFeatures .add (artifact );
631+ }
632+ if (featuresFile == null ) {
633+ featuresFile = this .dependencyHelper .resolve (artifact , getLog ());
634+ }
617635 if (featuresFile == null || !featuresFile .exists ()) {
618636 throw new MojoExecutionException (
619637 "Cannot locate file for feature: " + artifact + " at " + featuresFile );
620638 }
621639 Features includedFeatures = cache .getFeature (featuresFile );
622640 for (String repository : includedFeatures .getRepository ()) {
623641 processFeatureArtifact (features , feature , otherFeatures , featureRepositories , cache ,
624- cache .getArtifact (repository ), parent , false );
642+ cache .getArtifact (repository ), parent , false , recognizedFeatures );
625643 }
626644 for (Feature includedFeature : includedFeatures .getFeature ()) {
627645 Dependency dependency = new Dependency (includedFeature .getName (), includedFeature .getVersion ());
0 commit comments