CreateClusterAppMojo extends AbstractNbmMojo { static Map<String, Set<String>> computeClusterOrdering( Map<String, Set<String>> clusterDependencies, Map<String, Set<String>> clusterModules ) { Map<String, Set<String>> cluster2depClusters = new HashMap<>(); for ( Map.Entry<String, Set<String>> entry : clusterDependencies.entrySet() ) { String cluster = entry.getKey(); Set<String> deps = entry.getValue(); for (Map.Entry<String, Set<String>> subEnt : clusterModules.entrySet()) { if (subEnt.getKey().equals( cluster) ) { continue; } Sets.SetView<String> is = Sets.intersection(subEnt.getValue(), deps ); if (!is.isEmpty()) { addToMap( cluster2depClusters, cluster, Collections.singletonList( subEnt.getKey() ) ); } } } return cluster2depClusters; }  @Override void execute();  }
@Test public void computeClusterOrderingTest() throws Exception { HashMap<String, Set<String>> clusterDeps = new HashMap<String, Set<String>>(); HashMap<String, Set<String>> clusterModules = new HashMap<String, Set<String>>(); clusterModules.put( "platform", new HashSet<String>(Arrays.asList( new String[] {"pl-a", "pl-b", "pl-c"}))); clusterModules.put( "ide", new HashSet<String>(Arrays.asList( new String[] {"i-a", "i-b", "i-c"}))); clusterModules.put( "java", new HashSet<String>(Arrays.asList( new String[] {"j-a", "j-b", "j-c"}))); 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"}))); Map<String, Set<String>> res = CreateClusterAppMojo.computeClusterOrdering( clusterDeps, clusterModules); assertNotNull( res ); Set<String> resJava = res.get( "java"); assertNotNull( resJava ); assertEquals( resJava.size(), 2); assertTrue( resJava.contains( "ide")); assertTrue( resJava.contains( "platform")); Set<String> resIde = res.get( "ide"); assertNotNull( resIde ); assertEquals( resIde.size(), 1); assertTrue( resIde.contains( "platform")); }