test_class.file: webapp/webxml/src/test/java/cloud/piranha/webapp/webxml/WebXmlInitializerTest.java
test_class.identifier: WebXmlInitializerTest
test_case.body: @Test
      void testOnStartup() throws Exception {
          DefaultWebApplication webApplication = new DefaultWebApplication();
          webApplication.addResource(new DirectoryResource(new File("src/test/webxml/init")));
          webApplication.addInitializer(new WebXmlInitializer());
          webApplication.initialize();
          ServletRegistration registration = webApplication.getServletRegistration("Test Servlet");
          assertNotNull(registration);
          assertFalse(registration.getMappings().isEmpty());
          assertEquals("*.html", registration.getMappings().iterator().next());
          assertEquals("application/x-java-class", webApplication.getMimeType("my.class"));
          assertEquals("myvalue", webApplication.getInitParameter("myname"));
          assertEquals("myservletcontext", webApplication.getServletContextName());
      }
test_case.class_method_signature: WebXmlInitializerTest.testOnStartup()
test_case.full_signature: @Test void testOnStartup()
test_case.identifier: testOnStartup
test_case.invocations: addResource addInitializer initialize getServletRegistration assertNotNull assertFalse isEmpty getMappings assertEquals next iterator getMappings assertEquals getMimeType assertEquals getInitParameter assertEquals getServletContextName
test_case.modifiers: @Test
test_case.parameters: ()
test_case.return: void
test_case.signature: void testOnStartup()
focal_class.declarator: LOGGER = Logger.getLogger(WebXmlInitializer.class.getName())
focal_class.modifier: private static final
focal_class.original_string: private static final Logger LOGGER = Logger.getLogger(WebXmlInitializer.class.getName());
focal_class.type: Logger
focal_class.var_name: LOGGER
focal_class.file: webapp/webxml/src/main/java/cloud/piranha/webapp/webxml/WebXmlInitializer.java
focal_class.identifier: WebXmlInitializer
focal_class.interfaces: implements ServletContainerInitializer
focal_class.class_method_signature: WebXmlInitializer.onStartup(Set<Class<?>> classes, ServletContext servletContext)
focal_class.full_signature: @Override public void onStartup(Set<Class<?>> classes, ServletContext servletContext)
focal_class.identifier: onStartup
focal_class.modifiers: @Override public
focal_class.parameters: (Set<Class<?>> classes, ServletContext servletContext)
focal_class.return: void
focal_class.signature: void onStartup(Set<Class<?>> classes, ServletContext servletContext)
focal_method.body: @Override
      public void onStartup(Set<Class<?>> classes, ServletContext servletContext) throws ServletException {
          LOGGER.log(FINE, () -> "Entering WebXmlInitializer.onStartup");
  
          try {
              WebXmlParser parser = new WebXmlParser();
              WebXmlManager manager = new WebXmlManager();
              servletContext.setAttribute(WebXmlManager.KEY, manager);
  
              WebApplication webApp = (WebApplication) servletContext;
              InputStream inputStream = servletContext.getResourceAsStream("WEB-INF/web.xml");
              if (inputStream != null) {
                  WebXml webXml = parser.parse(servletContext.getResourceAsStream("WEB-INF/web.xml"));
                  manager.setWebXml(webXml);
                  manager.setInitialWebXml(webXml);
              }
  
              ArrayList<WebXml> webFragments = new ArrayList<>();
              List<URL> webFragmentUrls = Collections.list(servletContext.getClassLoader().getResources("META-INF/web-fragment.xml"));
              for (URL url : webFragmentUrls) {
                  try (InputStream stream = url.openStream()) {
                      WebXml webFragment = parser.parse(stream);
                      webFragment.setFragment(true);
                      webFragments.add(webFragment);
                  }
              }
              if (!webFragments.isEmpty()) {
                  manager.setWebFragments(webFragments);
              }
  
              if (manager.getWebXml() == null) {
                  manager.setWebXml(new WebXml());
              }
  
              if (manager.getWebXml() != null) {
                  WebXml webXml = manager.getWebXml();
                  WebXmlProcessor processor = new WebXmlProcessor();
  
                  processor.process(webXml, webApp);
  
                  if (webXml.getMetadataComplete()) {
                      return;
                  }
  
                  manager.getOrderedFragments().forEach(fragment -> processor.process(fragment, webApp));
              } else {
                  LOGGER.fine("No web.xml found!");
              }
          } catch (IOException e) {
              LOGGER.log(WARNING, "Unable to parse web.xml", e);
          }
  
          LOGGER.log(FINE, () -> "Exiting WebXmlInitializer.onStartup");
      }
focal_method.class_method_signature: WebXmlInitializer.onStartup(Set<Class<?>> classes, ServletContext servletContext)
focal_method.full_signature: @Override public void onStartup(Set<Class<?>> classes, ServletContext servletContext)
focal_method.identifier: onStartup
focal_method.invocations: log setAttribute getResourceAsStream parse getResourceAsStream setWebXml setInitialWebXml list getResources getClassLoader openStream parse setFragment add isEmpty setWebFragments getWebXml setWebXml getWebXml getWebXml process getMetadataComplete forEach getOrderedFragments process fine log log
focal_method.modifiers: @Override public
focal_method.parameters: (Set<Class<?>> classes, ServletContext servletContext)
focal_method.return: void
focal_method.signature: void onStartup(Set<Class<?>> classes, ServletContext servletContext)