CreateClusterAppMojo extends AbstractNbmMojo { 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(); if ( art != null && art.getDependencyTrail().size() > 2 && wrappedBundleCNBs.contains( spec ) ) { 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 { 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(); } } ent.cluster = depclusters.get( 0 ); known.add (ent); } } if (!toProcess.isEmpty()) { walkKnownBundleDependenciesDown(known, toProcess); } if (!toProcess.isEmpty()) { walkKnownBundleDependenciesUp(known, toProcess); } }  @Override void execute();  }
@Test public void assignClustersToBundles() throws Exception { ArrayList<BundleTuple> bundles = new ArrayList<BundleTuple>(); BundleTuple tup1 = createBundleTuple("a.b.c", new File(getClass().getResource( "/osgimanifests" + File.separator + "a.b.c.MF").toURI())); bundles.add( tup1 ); BundleTuple tup2 = createBundleTuple("b.c.d", new File(getClass().getResource( "/osgimanifests" + File.separator + "b.c.d.MF").toURI())); assertTrue(Arrays.toString( tup2.manifest.getOsgiImports().toArray()), tup2.manifest.getOsgiImports().contains( "a.b.c")); bundles.add( tup2 ); HashMap<String, Set<String>> clusterDeps = new HashMap<String, Set<String>>(); clusterDeps.put( "java", new HashSet<String>(Arrays.asList( new String[] {"i-a", "pl-b", "pl-c"}))); clusterDeps.put( "ide", new HashSet<String>(Arrays.asList( new String[] {"pl-b", "pl-c", "a.b.c"}))); CreateClusterAppMojo.assignClustersToBundles(bundles, Collections.<String>emptySet(), clusterDeps, Collections.<String, Set<String>>emptyMap(), null); assertEquals( "ide", tup1.cluster); assertEquals( "ide", tup2.cluster); clusterDeps.clear(); clusterDeps.put( "ide", new HashSet<String>(Arrays.asList( new String[] {"i-a", "pl-b", "pl-c"}))); clusterDeps.put( "java", new HashSet<String>(Arrays.asList( new String[] {"pl-b", "pl-c", "b.c.d"}))); tup2.cluster = null; tup1.cluster = null; CreateClusterAppMojo.assignClustersToBundles(bundles, Collections.<String>emptySet(), clusterDeps, Collections.<String, Set<String>>emptyMap(), null); assertEquals( "java", tup2.cluster); assertEquals( "java", tup1.cluster); }