Search in sources :

Example 11 with Node

use of org.jboss.shrinkwrap.api.Node in project wildfly-swarm by wildfly-swarm.

the class JBossWebContainer method findJbossWebAsset.

/**
 * Locate and load, or create a {@code jboss-web.xml} asset for this archive.
 *
 * @return The existing or new {@code jboss-web.xml} asset.
 */
default JBossWebAsset findJbossWebAsset() {
    final Node jbossWeb = this.get(JBOSS_WEB_PATH);
    Asset asset;
    if (jbossWeb == null) {
        asset = new JBossWebAsset();
        this.add(asset, JBOSS_WEB_PATH);
    } else {
        asset = jbossWeb.getAsset();
        if (!(asset instanceof JBossWebAsset)) {
            asset = new JBossWebAsset(asset.openStream());
            this.add(asset, JBOSS_WEB_PATH);
        }
    }
    return (JBossWebAsset) asset;
}
Also used : Node(org.jboss.shrinkwrap.api.Node) Asset(org.jboss.shrinkwrap.api.asset.Asset)

Example 12 with Node

use of org.jboss.shrinkwrap.api.Node in project wildfly-swarm by wildfly-swarm.

the class WebXmlContainer method findWebXmlAsset.

/**
 * Locate or create a {@code web.xml} asset.
 *
 * @return The existing or new {@code web.xml}.
 */
default WebXmlAsset findWebXmlAsset() {
    final Node webXml = this.get(WebXmlAsset.NAME);
    NamedAsset asset;
    if (webXml == null) {
        asset = new WebXmlAsset();
        this.add(asset);
    } else {
        Asset tempAsset = webXml.getAsset();
        if (!(tempAsset instanceof WebXmlAsset)) {
            asset = new WebXmlAsset(tempAsset.openStream());
            this.add(asset);
        } else {
            asset = (NamedAsset) tempAsset;
        }
    }
    return (WebXmlAsset) asset;
}
Also used : NamedAsset(org.jboss.shrinkwrap.api.asset.NamedAsset) Node(org.jboss.shrinkwrap.api.Node) ByteArrayAsset(org.jboss.shrinkwrap.api.asset.ByteArrayAsset) NamedAsset(org.jboss.shrinkwrap.api.asset.NamedAsset) Asset(org.jboss.shrinkwrap.api.asset.Asset)

Example 13 with Node

use of org.jboss.shrinkwrap.api.Node in project wildfly-swarm by wildfly-swarm.

the class StaticContentContainer method staticContent.

/**
 * 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) {
    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;
}
Also used : ArchivePath(org.jboss.shrinkwrap.api.ArchivePath) Path(java.nio.file.Path) BasicPath(org.jboss.shrinkwrap.impl.base.path.BasicPath) Archive(org.jboss.shrinkwrap.api.Archive) UndertowExternalMountsAsset(org.wildfly.swarm.undertow.internal.UndertowExternalMountsAsset) Node(org.jboss.shrinkwrap.api.Node) Asset(org.jboss.shrinkwrap.api.asset.Asset) UndertowExternalMountsAsset(org.wildfly.swarm.undertow.internal.UndertowExternalMountsAsset)

Example 14 with Node

use of org.jboss.shrinkwrap.api.Node in project wildfly-swarm by wildfly-swarm.

the class AdvertisingMetadataProcessorTest method createIndex.

Index createIndex(Archive<?> archive) throws IOException {
    Indexer indexer = new Indexer();
    Map<ArchivePath, Node> c = archive.getContent();
    for (Map.Entry<ArchivePath, Node> each : c.entrySet()) {
        if (each.getKey().get().endsWith(".class")) {
            indexer.index(each.getValue().getAsset().openStream());
        }
    }
    return indexer.complete();
}
Also used : ArchivePath(org.jboss.shrinkwrap.api.ArchivePath) Indexer(org.jboss.jandex.Indexer) Node(org.jboss.shrinkwrap.api.Node) Map(java.util.Map)

Example 15 with Node

use of org.jboss.shrinkwrap.api.Node in project wildfly-swarm by wildfly-swarm.

the class ServiceActivatorArchiveImpl method prepareAsset.

protected void prepareAsset() {
    Node node = getArchive().get(path());
    if (node != null) {
        Asset maybeCorrect = node.getAsset();
        if (maybeCorrect instanceof ServiceActivatorAsset) {
            setAsset((ServiceActivatorAsset) maybeCorrect);
        } else {
            ServiceActivatorAsset read = new ServiceActivatorAsset(maybeCorrect.openStream());
            setAsset(read);
        }
    } else {
        setAsset(new ServiceActivatorAsset());
    }
}
Also used : Node(org.jboss.shrinkwrap.api.Node) Asset(org.jboss.shrinkwrap.api.asset.Asset)

Aggregations

Node (org.jboss.shrinkwrap.api.Node)66 Archive (org.jboss.shrinkwrap.api.Archive)20 ArchivePath (org.jboss.shrinkwrap.api.ArchivePath)20 IOException (java.io.IOException)19 Test (org.junit.Test)17 Asset (org.jboss.shrinkwrap.api.asset.Asset)16 WebArchive (org.jboss.shrinkwrap.api.spec.WebArchive)15 File (java.io.File)14 Map (java.util.Map)14 InputStream (java.io.InputStream)13 URL (java.net.URL)13 BufferedReader (java.io.BufferedReader)10 InputStreamReader (java.io.InputStreamReader)10 StringAsset (org.jboss.shrinkwrap.api.asset.StringAsset)8 JolokiaFraction (org.wildfly.swarm.jolokia.JolokiaFraction)8 ArrayList (java.util.ArrayList)7 ArchiveAsset (org.jboss.shrinkwrap.api.asset.ArchiveAsset)7 OpenEJBException (org.apache.openejb.OpenEJBException)6 ClassAsset (org.jboss.shrinkwrap.api.asset.ClassAsset)6 MalformedURLException (java.net.MalformedURLException)5