ModuleUtils { public static List<Dependency> getAllDependencies(final Module module) { final Set<Dependency> dependencies = new HashSet<Dependency>(); final List<String> producedArtifacts = new ArrayList<String>(); for(final Artifact artifact: getAllArtifacts(module)){ producedArtifacts.add(artifact.getGavc()); } dependencies.addAll(getAllDependencies(module, producedArtifacts)); return new ArrayList<Dependency>(dependencies); } private  ModuleUtils(); static List<Artifact> getAllArtifacts(final Module module); static List<Dependency> getAllDependencies(final Module module); static Set<Dependency> getAllDependencies(final Module module, final List<String> producedArtifacts); static List<Dependency> getCorporateDependencies(final Module module, final List<String> corporateFilters); static List<Dependency> getThirdPartyLibraries(final Module module, final List<String> corporateFilters);  }
@Test public void testGetAllDependenciesOfAnEmptyModule(){ final Module module = DataModelFactory.createModule("module1", "1.0.0-SNAPSHOT"); final List<Dependency> dependencies = ModuleUtils.getAllDependencies(module); assertNotNull(dependencies); assertEquals(0, dependencies.size()); }
@Test public void testGetAllDependenciesWithSubModules(){ final Module module = DataModelFactory.createModule("module1", "1.0.0-SNAPSHOT"); final Artifact artifact = DataModelFactory.createArtifact("com.my.company", "dependency1", "1.0.0-SNAPSHOT", null, "jar", "jar"); final Dependency dependency = DataModelFactory.createDependency(artifact, Scope.COMPILE); final Module subModule = DataModelFactory.createModule("module11", "1.0.0-SNAPSHOT"); subModule.addDependency(dependency); module.addSubmodule(subModule); final List<Dependency> dependencies = ModuleUtils.getAllDependencies(module); assertNotNull(dependencies); assertEquals(1, dependencies.size()); assertEquals(dependency, dependencies.get(0)); }
@Test public void testGetAllDependenciesWithSubModulesAvoidingArtifactsOfTheModuleToBeInDependencies(){ final Module module = DataModelFactory.createModule("module1", "1.0.0-SNAPSHOT"); final Artifact artifact = DataModelFactory.createArtifact("com.my.company", "artifact1", "1.0.0-SNAPSHOT", null, "jar", "jar"); final Artifact artifact2 = DataModelFactory.createArtifact("com.my.company", "dependency1", "1.0.0-SNAPSHOT", null, "jar", "jar"); final Dependency dependency = DataModelFactory.createDependency(artifact, Scope.COMPILE); final Dependency dependency2 = DataModelFactory.createDependency(artifact2, Scope.COMPILE); final Module subModule = DataModelFactory.createModule("module11", "1.0.0-SNAPSHOT"); subModule.addDependency(dependency); subModule.addDependency(dependency2); module.addArtifact(artifact); module.addSubmodule(subModule); final List<Dependency> dependencies = ModuleUtils.getAllDependencies(module); assertNotNull(dependencies); assertEquals(1, dependencies.size()); assertEquals(dependency2, dependencies.get(0)); }
@Test public void testGetAllDependenciesWithSubModulesAvoidingArtifactsOfTheModuleToBeInDependenciesEvenForTrickSourcesJar(){ final Module module = DataModelFactory.createModule("module1", "1.0.0-SNAPSHOT"); final Artifact artifact = DataModelFactory.createArtifact("com.my.company", "artifact1", "1.0.0-SNAPSHOT", null, "jar", "jar"); final Artifact artifact2 = DataModelFactory.createArtifact("com.my.company", "artifact1", "1.0.0-SNAPSHOT", null, "source-jar", "jar"); final Dependency dependency = DataModelFactory.createDependency(artifact2, Scope.COMPILE); final Module subModule = DataModelFactory.createModule("module11", "1.0.0-SNAPSHOT"); subModule.addDependency(dependency); module.addArtifact(artifact); module.addSubmodule(subModule); final List<Dependency> dependencies = ModuleUtils.getAllDependencies(module); assertNotNull(dependencies); assertEquals(0, dependencies.size()); }
@Test public void testGetAllDependenciesAvoidDuplications(){ final Module module = DataModelFactory.createModule("module1", "1.0.0-SNAPSHOT"); final Artifact artifact = DataModelFactory.createArtifact("com.my.company", "dependency1", "1.0.0-SNAPSHOT", null, "jar", "jar"); final Dependency dependency = DataModelFactory.createDependency(artifact, Scope.COMPILE); final Module subModule = DataModelFactory.createModule("module11", "1.0.0-SNAPSHOT"); subModule.addDependency(dependency); module.addSubmodule(subModule); module.addDependency(dependency); final List<Dependency> dependencies = ModuleUtils.getAllDependencies(module); assertNotNull(dependencies); assertEquals(1, dependencies.size()); assertEquals(dependency, dependencies.get(0)); }
@Test public void testGetAllDependencies(){ final Module module = DataModelFactory.createModule("module1", "1.0.0-SNAPSHOT"); final Artifact artifact = DataModelFactory.createArtifact("com.my.company", "dependency1", "1.0.0-SNAPSHOT", null, "jar", "jar"); final Dependency dependency = DataModelFactory.createDependency(artifact, Scope.COMPILE); module.addDependency(dependency); final List<Dependency> dependencies = ModuleUtils.getAllDependencies(module); assertNotNull(dependencies); assertEquals(1, dependencies.size()); assertEquals(dependency, dependencies.get(0)); }