NormalizePlugins extends AbstractTransformer { @Override public void transform() { if (disabled) return; for (Element plugin : selectAllPlugins()) { if (DomUtil.getChild(plugin, "groupId") == null) { Element groupId = DomUtil.appendChildInheritNamespace(plugin, "groupId"); DomUtil.setText(groupId, "org.apache.maven.plugins"); } Utils.reconstruct(plugin, STANDARD_CHILDREN); } } NormalizePlugins(PomWrapper pom, CommandLine args);  NormalizePlugins(PomWrapper pom); @Override void transform();  }
@Test public void testBasicOperation() throws Exception { new NormalizePlugins(loadPom("cleaner/PluginNormalize1.xml")).transform(); Element plug1 = newXPath(" List<Element> children1 = DomUtil.getChildren(plug1); assertEquals("plugin #1, #/children", 3, children1.size()); assertEquals("plugin #1, child #1 name", "groupId", DomUtil.getLocalName(children1.get(0))); assertEquals("plugin #1, child #1 value", "org.apache.maven.plugins", DomUtil.getText(children1.get(0))); assertEquals("plugin #1, child #2 name", "artifactId", DomUtil.getLocalName(children1.get(1))); assertEquals("plugin #1, child #2 value", "maven-antrun-plugin", DomUtil.getText(children1.get(1))); assertEquals("plugin #1, child #3 name", "version", DomUtil.getLocalName(children1.get(2))); assertEquals("plugin #1, child #3 value", "1.3", DomUtil.getText(children1.get(2))); Element plug2 = newXPath(" List<Element> children2 = DomUtil.getChildren(plug2); assertEquals("plugin #2, #/children", 3, children2.size()); assertEquals("plugin #2, child #1 name", "groupId", DomUtil.getLocalName(children2.get(0))); assertEquals("plugin #2, child #1 value", "org.codehaus.mojo", DomUtil.getText(children2.get(0))); assertEquals("plugin #2, child #2 name", "artifactId", DomUtil.getLocalName(children2.get(1))); assertEquals("plugin #2, child #2 value", "cobertura-maven-plugin", DomUtil.getText(children2.get(1))); assertEquals("plugin #2, child #3 name", "configuration", DomUtil.getLocalName(children2.get(2))); Element plug3 = newXPath(" List<Element> children3 = DomUtil.getChildren(plug3); assertEquals("plugin #3, #/children", 3, children3.size()); assertEquals("plugin #3, child #1 name", "groupId", DomUtil.getLocalName(children3.get(0))); assertEquals("plugin #3, child #1 value", "org.apache.maven.plugins", DomUtil.getText(children3.get(0))); assertEquals("plugin #3, child #2 name", "artifactId", DomUtil.getLocalName(children3.get(1))); assertEquals("plugin #3, child #2 value", "maven-site-plugin", DomUtil.getText(children3.get(1))); assertEquals("plugin #3, child #3 name", "version", DomUtil.getLocalName(children3.get(2))); assertEquals("plugin #3, child #3 value", "2.0.1", DomUtil.getText(children3.get(2))); }
@Test public void testDisabled() throws Exception { CommandLine args = new CommandLine("--noPluginNormalize"); new NormalizePlugins(loadPom("cleaner/PluginNormalize1.xml"), args).transform(); Element plug1 = newXPath(" List<Element> children1 = DomUtil.getChildren(plug1); assertEquals("plugin #1, #/children", 2, children1.size()); assertEquals("plugin #1, child #1 name", "version", DomUtil.getLocalName(children1.get(0))); assertEquals("plugin #1, child #1 value", "1.3", DomUtil.getText(children1.get(0))); assertEquals("plugin #1, child #2 name", "artifactId", DomUtil.getLocalName(children1.get(1))); assertEquals("plugin #1, child #2 value", "maven-antrun-plugin", DomUtil.getText(children1.get(1))); }