@Test public void testExecute() throws Exception { WebXmlPirasoModifier modifier = new WebXmlPirasoModifier(); MavenProject project = mock(MavenProject.class); doReturn(new Properties()).when(project).getProperties(); modifier.setProject(project); File webXml = new File(WebXmlPirasoModifier.class.getResource("/web.xml").getFile()); File parent = new File(webXml.getParentFile(), "new"); if(!parent.isDirectory()) { parent.mkdirs(); } modifier.setPirasoLoggingPath("/piraso/logging"); modifier.setWebXml(webXml); modifier.setOutputDirectory(parent); modifier.execute(); }
public void execute() throws MojoExecutionException, MojoFailureException { if(webXml == null || !webXml.isFile()) { throw new MojoExecutionException("'webXml' configuration is expected and should be a valid file."); } if(outputDirectory == null) { throw new MojoExecutionException("'outputDirectory' configuration is expected."); } parseDocument(webXml); Node root = document.getElementsByTagName("web-app").item(0); Node firstContextParam = document.getElementsByTagName("context-param").item(0); NodeList firstFilters = document.getElementsByTagName("filter"); Node firstFilterOrServlet; if(firstFilters != null && firstFilters.getLength() > 0) { firstFilterOrServlet = firstFilters.item(0); } else { firstFilterOrServlet = document.getElementsByTagName("servlet").item(0); } insertContextParam(root, firstContextParam, "parentContextKey", "piraso.context"); insertContextParam(root, firstContextParam, "contextClass", "org.piraso.server.spring.web.PirasoWebApplicationContext"); insertFilterAndServletElement(root, firstFilterOrServlet); try { File outputFile = new File(outputDirectory, webXml.getName()); writeDocument(outputFile); if(project != null) { project.getProperties().setProperty("maven.war.webxml", outputFile.getAbsolutePath()); } } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } }
WebXmlPirasoModifier extends AbstractXMLPirasoModifier { public void execute() throws MojoExecutionException, MojoFailureException { if(webXml == null || !webXml.isFile()) { throw new MojoExecutionException("'webXml' configuration is expected and should be a valid file."); } if(outputDirectory == null) { throw new MojoExecutionException("'outputDirectory' configuration is expected."); } parseDocument(webXml); Node root = document.getElementsByTagName("web-app").item(0); Node firstContextParam = document.getElementsByTagName("context-param").item(0); NodeList firstFilters = document.getElementsByTagName("filter"); Node firstFilterOrServlet; if(firstFilters != null && firstFilters.getLength() > 0) { firstFilterOrServlet = firstFilters.item(0); } else { firstFilterOrServlet = document.getElementsByTagName("servlet").item(0); } insertContextParam(root, firstContextParam, "parentContextKey", "piraso.context"); insertContextParam(root, firstContextParam, "contextClass", "org.piraso.server.spring.web.PirasoWebApplicationContext"); insertFilterAndServletElement(root, firstFilterOrServlet); try { File outputFile = new File(outputDirectory, webXml.getName()); writeDocument(outputFile); if(project != null) { project.getProperties().setProperty("maven.war.webxml", outputFile.getAbsolutePath()); } } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } } }
WebXmlPirasoModifier extends AbstractXMLPirasoModifier { public void execute() throws MojoExecutionException, MojoFailureException { if(webXml == null || !webXml.isFile()) { throw new MojoExecutionException("'webXml' configuration is expected and should be a valid file."); } if(outputDirectory == null) { throw new MojoExecutionException("'outputDirectory' configuration is expected."); } parseDocument(webXml); Node root = document.getElementsByTagName("web-app").item(0); Node firstContextParam = document.getElementsByTagName("context-param").item(0); NodeList firstFilters = document.getElementsByTagName("filter"); Node firstFilterOrServlet; if(firstFilters != null && firstFilters.getLength() > 0) { firstFilterOrServlet = firstFilters.item(0); } else { firstFilterOrServlet = document.getElementsByTagName("servlet").item(0); } insertContextParam(root, firstContextParam, "parentContextKey", "piraso.context"); insertContextParam(root, firstContextParam, "contextClass", "org.piraso.server.spring.web.PirasoWebApplicationContext"); insertFilterAndServletElement(root, firstFilterOrServlet); try { File outputFile = new File(outputDirectory, webXml.getName()); writeDocument(outputFile); if(project != null) { project.getProperties().setProperty("maven.war.webxml", outputFile.getAbsolutePath()); } } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } }  }
WebXmlPirasoModifier extends AbstractXMLPirasoModifier { public void execute() throws MojoExecutionException, MojoFailureException { if(webXml == null || !webXml.isFile()) { throw new MojoExecutionException("'webXml' configuration is expected and should be a valid file."); } if(outputDirectory == null) { throw new MojoExecutionException("'outputDirectory' configuration is expected."); } parseDocument(webXml); Node root = document.getElementsByTagName("web-app").item(0); Node firstContextParam = document.getElementsByTagName("context-param").item(0); NodeList firstFilters = document.getElementsByTagName("filter"); Node firstFilterOrServlet; if(firstFilters != null && firstFilters.getLength() > 0) { firstFilterOrServlet = firstFilters.item(0); } else { firstFilterOrServlet = document.getElementsByTagName("servlet").item(0); } insertContextParam(root, firstContextParam, "parentContextKey", "piraso.context"); insertContextParam(root, firstContextParam, "contextClass", "org.piraso.server.spring.web.PirasoWebApplicationContext"); insertFilterAndServletElement(root, firstFilterOrServlet); try { File outputFile = new File(outputDirectory, webXml.getName()); writeDocument(outputFile); if(project != null) { project.getProperties().setProperty("maven.war.webxml", outputFile.getAbsolutePath()); } } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } }  void setOutputDirectory(File outputDirectory); void setPirasoLoggingPath(String pirasoLoggingPath); void setWebXml(File webXml); void setProject(MavenProject project); void execute(); }
WebXmlPirasoModifier extends AbstractXMLPirasoModifier { public void execute() throws MojoExecutionException, MojoFailureException { if(webXml == null || !webXml.isFile()) { throw new MojoExecutionException("'webXml' configuration is expected and should be a valid file."); } if(outputDirectory == null) { throw new MojoExecutionException("'outputDirectory' configuration is expected."); } parseDocument(webXml); Node root = document.getElementsByTagName("web-app").item(0); Node firstContextParam = document.getElementsByTagName("context-param").item(0); NodeList firstFilters = document.getElementsByTagName("filter"); Node firstFilterOrServlet; if(firstFilters != null && firstFilters.getLength() > 0) { firstFilterOrServlet = firstFilters.item(0); } else { firstFilterOrServlet = document.getElementsByTagName("servlet").item(0); } insertContextParam(root, firstContextParam, "parentContextKey", "piraso.context"); insertContextParam(root, firstContextParam, "contextClass", "org.piraso.server.spring.web.PirasoWebApplicationContext"); insertFilterAndServletElement(root, firstFilterOrServlet); try { File outputFile = new File(outputDirectory, webXml.getName()); writeDocument(outputFile); if(project != null) { project.getProperties().setProperty("maven.war.webxml", outputFile.getAbsolutePath()); } } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } }  void setOutputDirectory(File outputDirectory); void setPirasoLoggingPath(String pirasoLoggingPath); void setWebXml(File webXml); void setProject(MavenProject project); void execute();  }