/** * Enable static content to be served from a given base in the classpath. * * @param base The path prefix to use for static content. * @return */ @SuppressWarnings("unchecked") default T staticContent(String base) { // as(WARArchive.class).addModule("org.wildfly.swarm.undertow", "runtime"); try { // Add all the static content from the current app to the archive Archive allResources = DefaultWarDeploymentFactory.archiveFromCurrentApp(); // Here we define static as basically anything that's not a // Java class file or under WEB-INF or META-INF mergeIgnoringDuplicates(allResources, base, Filters.exclude(".*\\.class$")); } catch (Exception ex) { log.log(Level.WARNING, "Error setting up static resources", ex); } Node node = get(EXTERNAL_MOUNT_PATH); UndertowExternalMountsAsset asset; if (node == null) { asset = new UndertowExternalMountsAsset(); add(asset, EXTERNAL_MOUNT_PATH); } else { Asset tempAsset = node.getAsset(); if (!(tempAsset instanceof UndertowExternalMountsAsset)) { asset = new UndertowExternalMountsAsset(tempAsset.openStream()); add(asset, EXTERNAL_MOUNT_PATH); } else { asset = (UndertowExternalMountsAsset) node.getAsset(); } } // Add external mounts for static content so changes are picked up // immediately during development Path webResources = Paths.get(System.getProperty("user.dir"), "src", "main", "webapp"); if (base != null) { webResources = webResources.resolve(base); } if (Files.exists(webResources)) { asset.externalMount(webResources.toString()); } webResources = Paths.get(System.getProperty("user.dir"), "src", "main", "resources"); if (base != null) { webResources = webResources.resolve(base); } if (Files.exists(webResources)) { asset.externalMount(webResources.toString()); } return (T) this; }
private Archive<?> handleArchive( WebArchive applicationArchive, Collection<Archive<?>> auxiliaryArchives, WebArchive protocol, Processor processor) { if (applicationArchive.contains(WEB_XML_PATH)) { WebAppDescriptor applicationWebXml = Descriptors.importAs(WebAppDescriptor.class) .from(applicationArchive.get(WEB_XML_PATH).getAsset().openStream()); // SHRINKWRAP-187, to eager on not allowing overrides, delete it first applicationArchive.delete(WEB_XML_PATH); applicationArchive.setWebXML( new StringAsset(WebUtils.mergeWithDescriptor(applicationWebXml).exportAsString())); applicationArchive.merge(protocol, Filters.exclude(".*web\\.xml.*")); } else { applicationArchive.merge(protocol); } applicationArchive.addAsLibraries(auxiliaryArchives.toArray(new Archive<?>[0])); processor.process(applicationArchive); return applicationArchive; }