Search in sources :

Example 1 with Archive

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

the class SecuredArchivePreparer method getKeycloakJson.

private InputStream getKeycloakJson() {
    InputStream keycloakJson = Thread.currentThread().getContextClassLoader().getResourceAsStream("keycloak.json");
    if (keycloakJson == null) {
        String appArtifact = System.getProperty(BootstrapProperties.APP_ARTIFACT);
        if (appArtifact != null) {
            try (InputStream in = ClassLoader.getSystemClassLoader().getResourceAsStream("_bootstrap/" + appArtifact)) {
                Archive tmpArchive = ShrinkWrap.create(JARArchive.class);
                tmpArchive.as(ZipImporter.class).importFrom(in);
                Node jsonNode = tmpArchive.get("keycloak.json");
                if (jsonNode == null) {
                    jsonNode = tmpArchive.get("WEB-INF/keycloak.json");
                }
                if (jsonNode != null && jsonNode.getAsset() != null) {
                    keycloakJson = jsonNode.getAsset().openStream();
                }
            } catch (IOException e) {
            // ignore
            }
        }
    }
    return keycloakJson;
}
Also used : JARArchive(org.wildfly.swarm.spi.api.JARArchive) Archive(org.jboss.shrinkwrap.api.Archive) InputStream(java.io.InputStream) ZipImporter(org.jboss.shrinkwrap.api.importer.ZipImporter) Node(org.jboss.shrinkwrap.api.Node) IOException(java.io.IOException)

Example 2 with Archive

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

the class JolokiaWarDeploymentProducerTest method testPreferConfigValueURL_vs_API.

@Test
public void testPreferConfigValueURL_vs_API() throws Exception {
    URL resource = getClass().getClassLoader().getResource("my-jolokia-access2.xml");
    JolokiaWarDeploymentProducer producer = new JolokiaWarDeploymentProducer();
    producer.fraction = new JolokiaFraction().prepareJolokiaWar(JolokiaFraction.jolokiaAccess(access -> {
        access.host("1.1.1.1");
    }));
    producer.lookup = new MockArtifactLookup();
    producer.jolokiaAccessXML = resource.toExternalForm();
    Archive war = producer.jolokiaWar();
    Node xml = war.get("WEB-INF/classes/jolokia-access.xml");
    assertThat(xml).isNotNull();
    try (BufferedReader reader = new BufferedReader(new InputStreamReader(xml.getAsset().openStream()))) {
        List<String> lines = reader.lines().collect(Collectors.toList());
        assertThat(lines).isNotEmpty();
        assertThat(lines.get(0)).contains("This is my-jolokia-access2.xml");
    }
}
Also used : Archive(org.jboss.shrinkwrap.api.Archive) InputStreamReader(java.io.InputStreamReader) Node(org.jboss.shrinkwrap.api.Node) BufferedReader(java.io.BufferedReader) JolokiaFraction(org.wildfly.swarm.jolokia.JolokiaFraction) URL(java.net.URL) Test(org.junit.Test)

Example 3 with Archive

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

the class JolokiaWarDeploymentProducerTest method testNoJolokiaAccessAtAll.

@Test
public void testNoJolokiaAccessAtAll() throws Exception {
    JolokiaWarDeploymentProducer producer = new JolokiaWarDeploymentProducer();
    producer.fraction = new JolokiaFraction();
    producer.lookup = new MockArtifactLookup();
    Archive war = producer.jolokiaWar();
    Node xml = war.get("WEB-INF/classes/jolokia-access.xml");
    assertThat(xml).isNull();
}
Also used : Archive(org.jboss.shrinkwrap.api.Archive) Node(org.jboss.shrinkwrap.api.Node) JolokiaFraction(org.wildfly.swarm.jolokia.JolokiaFraction) Test(org.junit.Test)

Example 4 with Archive

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

the class JolokiaWarDeploymentProducerTest method testJolokiaAccessViaUrlOnFraction.

@Test
public void testJolokiaAccessViaUrlOnFraction() throws Exception {
    URL resource = getClass().getClassLoader().getResource("my-jolokia-access.xml");
    JolokiaWarDeploymentProducer producer = new JolokiaWarDeploymentProducer();
    producer.fraction = new JolokiaFraction().prepareJolokiaWar(JolokiaFraction.jolokiaAccessXml(resource));
    producer.lookup = new MockArtifactLookup();
    Archive war = producer.jolokiaWar();
    Node xml = war.get("WEB-INF/classes/jolokia-access.xml");
    assertThat(xml).isNotNull();
    try (BufferedReader reader = new BufferedReader(new InputStreamReader(xml.getAsset().openStream()))) {
        List<String> lines = reader.lines().collect(Collectors.toList());
        assertThat(lines).isNotEmpty();
        assertThat(lines.get(0)).contains("This is my-jolokia-access.xml");
    }
}
Also used : Archive(org.jboss.shrinkwrap.api.Archive) InputStreamReader(java.io.InputStreamReader) Node(org.jboss.shrinkwrap.api.Node) BufferedReader(java.io.BufferedReader) JolokiaFraction(org.wildfly.swarm.jolokia.JolokiaFraction) URL(java.net.URL) Test(org.junit.Test)

Example 5 with Archive

use of org.jboss.shrinkwrap.api.Archive 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)

Aggregations

Archive (org.jboss.shrinkwrap.api.Archive)37 Node (org.jboss.shrinkwrap.api.Node)17 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)12 Test (org.junit.Test)12 File (java.io.File)11 URL (java.net.URL)10 ArrayList (java.util.ArrayList)9 ArchivePath (org.jboss.shrinkwrap.api.ArchivePath)8 JolokiaFraction (org.wildfly.swarm.jolokia.JolokiaFraction)8 BufferedReader (java.io.BufferedReader)7 IOException (java.io.IOException)7 InputStreamReader (java.io.InputStreamReader)7 Map (java.util.Map)7 HashMap (java.util.HashMap)6 WebArchive (org.jboss.shrinkwrap.api.spec.WebArchive)6 List (java.util.List)5 ZipImporter (org.jboss.shrinkwrap.api.importer.ZipImporter)5 DeploymentContext (org.wildfly.swarm.container.runtime.cdi.DeploymentContext)5 JARArchive (org.wildfly.swarm.spi.api.JARArchive)5 Path (java.nio.file.Path)4