static void assignClustersToBundles()

in nbm-maven-plugin/src/main/java/org/apache/netbeans/nbm/CreateClusterAppMojo.java [1164:1234]


    static void assignClustersToBundles( List<BundleTuple> bundles, Set<String> wrappedBundleCNBs,
                                         Map<String, Set<String>> clusterDependencies,
                                         Map<String, Set<String>> cluster2depClusters, Log log )
    {
        List<BundleTuple> toProcess = new ArrayList<>();
        List<BundleTuple> known = new ArrayList<>();
        for ( Iterator<BundleTuple> it = bundles.iterator(); it.hasNext(); )
        {
            BundleTuple ent = it.next();
            Artifact art = ent.artifact;
            ExamineManifest ex = ent.manifest;
            String spec = ex.getModule();
            //null check for tests
            //have a way to force inclusion of osgi items. Direct dependency is never wrapped by modules.
            if ( art != null && art.getDependencyTrail().size() > 2 && wrappedBundleCNBs.contains( spec ) )
            {
                // we already have this one as a wrapped module.
                log.debug( "Not including bundle " + art.getDependencyConflictId()
                        + ". It is already included in a NetBeans module" );
                it.remove();
                continue;
            }
            List<String> depclusters = findByDependencies( clusterDependencies, spec );
            if ( depclusters.size() == 1 )
            {
                ent.cluster = depclusters.get( 0 );
                known.add( ent );
            }
            else if ( depclusters.isEmpty() )
            {
                toProcess.add( ent );
            }
            else
            {
                //more results.. from 2 dependent clusters pick the one that is lower in the stack.
                for ( Iterator<String> it2 = depclusters.iterator(); it2.hasNext(); )
                {
                    String s = it2.next();
                    Set<String> depsCs = cluster2depClusters.get( s );
                    boolean removeS = false;
                    for ( String sDep : depclusters )
                    {
                        if ( s.equals( sDep ) )
                        {
                            continue;
                        }
                        if ( depsCs != null && depsCs.contains( sDep ) )
                        {
                            removeS = true;
                        }
                    }
                    if ( removeS )
                    {
                        it2.remove();
                    }
                }
                //TODO still some free room there,
                //what if they don't directly depend on each other but still are related
                ent.cluster = depclusters.get( 0 );
                known.add( ent );
            }
        }
        if ( !toProcess.isEmpty() )
        {
            walkKnownBundleDependenciesDown( known, toProcess );
        }
        if ( !toProcess.isEmpty() )
        {
            walkKnownBundleDependenciesUp( known, toProcess );
        }
    }