SortDependencies extends AbstractTransformer { @Override public void transform() { if (disabled) return; logger.info("sorting dependencies"); processGroup(PomPaths.PROJECT_DEPENDENCIES); processGroup(PomPaths.MANAGED_DEPENDENCIES); } SortDependencies(PomWrapper pom, CommandLine args);  SortDependencies(PomWrapper pom); @Override void transform();  }
@Test public void testBasicOperation() throws Exception { new SortDependencies(loadPom("cleaner/DependencySort1.xml")).transform(); List<Element> dependencies = newXPath("/mvn:project/mvn:dependencies/*").evaluate(dom(), Element.class); assertEquals("number of dependencies in <dependencies>", 3, dependencies.size()); assertDependencySpec("dependencies(0)", dependencies.get(0), "commons-io", "commons-io", "2.4"); assertDependencySpec("dependencies(1)", dependencies.get(1), "commons-logging", "commons-logging", "1.1"); assertDependencySpec("dependencies(2)", dependencies.get(2), "junit", "junit", "4.10"); List<Element> dependencyMgmt = newXPath("/mvn:project/mvn:dependencyManagement/mvn:dependencies/*").evaluate(dom(), Element.class); assertEquals("number of dependencies in <dependencyManagement>", 4, dependencyMgmt.size()); assertDependencySpec("dependencyMgmt(0)", dependencyMgmt.get(0), "org.springframework", "spring-context", "3.1.2.RELEASE"); assertDependencySpec("dependencyMgmt(1)", dependencyMgmt.get(1), "org.springframework", "spring-core", "3.1.2.RELEASE"); assertDependencySpec("dependencyMgmt(2)", dependencyMgmt.get(2), "org.springframework", "spring-orm", "3.1.2.RELEASE"); assertDependencySpec("dependencyMgmt(3)", dependencyMgmt.get(3), "org.springframework", "spring-tx", "3.1.2.RELEASE"); }
@Test public void testGroupByScope() throws Exception { CommandLine args = new CommandLine("--groupDependenciesByScope"); new SortDependencies(loadPom("cleaner/DependencySort2.xml"), args).transform(); List<Element> dependencies = newXPath("/mvn:project/mvn:dependencies/*").evaluate(dom(), Element.class); assertEquals("number of dependencies in <dependencies>", 6, dependencies.size()); assertDependencySpec("dependencies(0)", dependencies.get(0), "commons-io", "commons-io", "2.4"); assertDependencySpec("dependencies(1)", dependencies.get(1), "commons-lang", "commons-lang", "2.3"); assertDependencySpec("dependencies(2)", dependencies.get(2), "org.slf4j", "slf4j-log4j12", "1.6.6"); assertDependencySpec("dependencies(3)", dependencies.get(3), "junit", "junit", "4.10"); assertDependencySpec("dependencies(4)", dependencies.get(4), "javax.sql", "jdbc-stdext", "2.0"); assertDependencySpec("dependencies(5)", dependencies.get(5), "commons-logging", "commons-logging", "1.1"); }
@Test public void testDisabled() throws Exception { CommandLine args = new CommandLine("--noDependencySort"); new SortDependencies(loadPom("cleaner/DependencySort1.xml"), args).transform(); List<Element> dependencies = newXPath("/mvn:project/mvn:dependencies/*").evaluate(dom(), Element.class); assertEquals("number of dependencies in <dependencies>", 3, dependencies.size()); assertDependencySpec("dependencies(0)", dependencies.get(0), "commons-logging", "commons-logging", "1.1"); assertDependencySpec("dependencies(1)", dependencies.get(1), "junit", "junit", "4.10"); assertDependencySpec("dependencies(2)", dependencies.get(2), "commons-io", "commons-io", "2.4"); List<Element> dependencyMgmt = newXPath("/mvn:project/mvn:dependencyManagement/mvn:dependencies/*").evaluate(dom(), Element.class); assertEquals("number of dependencies in <dependencyManagement>", 4, dependencyMgmt.size()); assertDependencySpec("dependencyMgmt(0)", dependencyMgmt.get(0), "org.springframework", "spring-tx", "3.1.2.RELEASE"); assertDependencySpec("dependencyMgmt(1)", dependencyMgmt.get(1), "org.springframework", "spring-core", "3.1.2.RELEASE"); assertDependencySpec("dependencyMgmt(2)", dependencyMgmt.get(2), "org.springframework", "spring-context", "3.1.2.RELEASE"); assertDependencySpec("dependencyMgmt(3)", dependencyMgmt.get(3), "org.springframework", "spring-orm", "3.1.2.RELEASE"); }