@Test public void testExecute() throws Exception { SpringXmlPirasoModifier modifier = new SpringXmlPirasoModifier(); File springXML = new File(SpringXmlPirasoModifier.class.getResource("/spring.xml").getFile()); File parent = new File(springXML.getParentFile(), "new"); if(!parent.isDirectory()) { parent.mkdirs(); } modifier.setSpringXml(springXML); modifier.setOutputDirectory(parent); modifier.setClassReplacements(Arrays.asList( new ClassReplacement("com.test.core.spring.remoting.HttpInvokerRequestExecutorWithTimeout", "com.alvin.testing") )); modifier.execute(); }
public void execute() throws MojoExecutionException, MojoFailureException { if(springXml == null || !springXml.isFile()) { throw new MojoExecutionException("'springXml' configuration is expected and should be a valid file."); } if(outputDirectory == null) { throw new MojoExecutionException("'outputDirectory' configuration is expected."); } if(classReplacements == null || classReplacements.isEmpty()) { throw new MojoExecutionException("'classReplacements' configuration is expected and should not be empty."); } parseDocument(springXml); try { for(ClassReplacement replacement : classReplacements) { NodeList beanList = document.getElementsByTagName("bean"); for(int i = 0; i < beanList.getLength(); i++) { Element el = (Element) beanList.item(i); if(StringUtils.equals(replacement.getClassName(), el.getAttribute("class"))) { el.setAttribute("class", replacement.getReplacementClassName()); if(el.getAttribute("id") != null) { getLog().info(String.format("Replacing class '%s' for bean '%s' with '%s'", el.getAttribute("id"), replacement.getClassName(), replacement.getReplacementClassName())); } else { getLog().info(String.format("Replacing class '%s' with '%s'", replacement.getClassName(), replacement.getReplacementClassName())); } } } } writeDocument(outputDirectory, springXml.getName()); } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } }
SpringXmlPirasoModifier extends AbstractXMLPirasoModifier { public void execute() throws MojoExecutionException, MojoFailureException { if(springXml == null || !springXml.isFile()) { throw new MojoExecutionException("'springXml' configuration is expected and should be a valid file."); } if(outputDirectory == null) { throw new MojoExecutionException("'outputDirectory' configuration is expected."); } if(classReplacements == null || classReplacements.isEmpty()) { throw new MojoExecutionException("'classReplacements' configuration is expected and should not be empty."); } parseDocument(springXml); try { for(ClassReplacement replacement : classReplacements) { NodeList beanList = document.getElementsByTagName("bean"); for(int i = 0; i < beanList.getLength(); i++) { Element el = (Element) beanList.item(i); if(StringUtils.equals(replacement.getClassName(), el.getAttribute("class"))) { el.setAttribute("class", replacement.getReplacementClassName()); if(el.getAttribute("id") != null) { getLog().info(String.format("Replacing class '%s' for bean '%s' with '%s'", el.getAttribute("id"), replacement.getClassName(), replacement.getReplacementClassName())); } else { getLog().info(String.format("Replacing class '%s' with '%s'", replacement.getClassName(), replacement.getReplacementClassName())); } } } } writeDocument(outputDirectory, springXml.getName()); } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } } }
SpringXmlPirasoModifier extends AbstractXMLPirasoModifier { public void execute() throws MojoExecutionException, MojoFailureException { if(springXml == null || !springXml.isFile()) { throw new MojoExecutionException("'springXml' configuration is expected and should be a valid file."); } if(outputDirectory == null) { throw new MojoExecutionException("'outputDirectory' configuration is expected."); } if(classReplacements == null || classReplacements.isEmpty()) { throw new MojoExecutionException("'classReplacements' configuration is expected and should not be empty."); } parseDocument(springXml); try { for(ClassReplacement replacement : classReplacements) { NodeList beanList = document.getElementsByTagName("bean"); for(int i = 0; i < beanList.getLength(); i++) { Element el = (Element) beanList.item(i); if(StringUtils.equals(replacement.getClassName(), el.getAttribute("class"))) { el.setAttribute("class", replacement.getReplacementClassName()); if(el.getAttribute("id") != null) { getLog().info(String.format("Replacing class '%s' for bean '%s' with '%s'", el.getAttribute("id"), replacement.getClassName(), replacement.getReplacementClassName())); } else { getLog().info(String.format("Replacing class '%s' with '%s'", replacement.getClassName(), replacement.getReplacementClassName())); } } } } writeDocument(outputDirectory, springXml.getName()); } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } }  }
SpringXmlPirasoModifier extends AbstractXMLPirasoModifier { public void execute() throws MojoExecutionException, MojoFailureException { if(springXml == null || !springXml.isFile()) { throw new MojoExecutionException("'springXml' configuration is expected and should be a valid file."); } if(outputDirectory == null) { throw new MojoExecutionException("'outputDirectory' configuration is expected."); } if(classReplacements == null || classReplacements.isEmpty()) { throw new MojoExecutionException("'classReplacements' configuration is expected and should not be empty."); } parseDocument(springXml); try { for(ClassReplacement replacement : classReplacements) { NodeList beanList = document.getElementsByTagName("bean"); for(int i = 0; i < beanList.getLength(); i++) { Element el = (Element) beanList.item(i); if(StringUtils.equals(replacement.getClassName(), el.getAttribute("class"))) { el.setAttribute("class", replacement.getReplacementClassName()); if(el.getAttribute("id") != null) { getLog().info(String.format("Replacing class '%s' for bean '%s' with '%s'", el.getAttribute("id"), replacement.getClassName(), replacement.getReplacementClassName())); } else { getLog().info(String.format("Replacing class '%s' with '%s'", replacement.getClassName(), replacement.getReplacementClassName())); } } } } writeDocument(outputDirectory, springXml.getName()); } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } }  void setClassReplacements(List<ClassReplacement> classReplacements); void setOutputDirectory(File outputDirectory); void setSpringXml(File springXml); void execute(); }
SpringXmlPirasoModifier extends AbstractXMLPirasoModifier { public void execute() throws MojoExecutionException, MojoFailureException { if(springXml == null || !springXml.isFile()) { throw new MojoExecutionException("'springXml' configuration is expected and should be a valid file."); } if(outputDirectory == null) { throw new MojoExecutionException("'outputDirectory' configuration is expected."); } if(classReplacements == null || classReplacements.isEmpty()) { throw new MojoExecutionException("'classReplacements' configuration is expected and should not be empty."); } parseDocument(springXml); try { for(ClassReplacement replacement : classReplacements) { NodeList beanList = document.getElementsByTagName("bean"); for(int i = 0; i < beanList.getLength(); i++) { Element el = (Element) beanList.item(i); if(StringUtils.equals(replacement.getClassName(), el.getAttribute("class"))) { el.setAttribute("class", replacement.getReplacementClassName()); if(el.getAttribute("id") != null) { getLog().info(String.format("Replacing class '%s' for bean '%s' with '%s'", el.getAttribute("id"), replacement.getClassName(), replacement.getReplacementClassName())); } else { getLog().info(String.format("Replacing class '%s' with '%s'", replacement.getClassName(), replacement.getReplacementClassName())); } } } } writeDocument(outputDirectory, springXml.getName()); } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } }  void setClassReplacements(List<ClassReplacement> classReplacements); void setOutputDirectory(File outputDirectory); void setSpringXml(File springXml); void execute();  }