Search in sources :

Example 1 with Node

use of org.jboss.shrinkwrap.api.Node in project camel by apache.

the class ManagedSEDeployableContainer method getSystemProperties.

private Properties getSystemProperties(final Archive<?> archive) throws DeploymentException {
    Node systemPropertiesNode = archive.get(ClassPath.SYSTEM_PROPERTIES_ARCHIVE_PATH);
    if (systemPropertiesNode != null) {
        try (InputStream in = systemPropertiesNode.getAsset().openStream()) {
            Properties systemProperties = new Properties();
            systemProperties.load(in);
            return systemProperties;
        } catch (IOException e) {
            throw new DeploymentException("Could not load system properties", e);
        }
    }
    return null;
}
Also used : InputStream(java.io.InputStream) Node(org.jboss.shrinkwrap.api.Node) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException) IOException(java.io.IOException) Properties(java.util.Properties)

Example 2 with Node

use of org.jboss.shrinkwrap.api.Node in project camel by apache.

the class FileDeploymentUtils method materializeSubdirectories.

public static void materializeSubdirectories(File entryDirectory, Node node) throws DeploymentException, IOException {
    for (Node child : node.getChildren()) {
        if (child.getAsset() == null) {
            materializeSubdirectories(entryDirectory, child);
        } else {
            if (ClassPathDirectory.isMarkerFileArchivePath(child.getPath())) {
                // Do not materialize the marker file
                continue;
            }
            // E.g. META-INF/my-super-descriptor.xml
            File resourceFile = new File(entryDirectory, child.getPath().get().replace(DELIMITER_RESOURCE_PATH, File.separatorChar));
            File resoureDirectory = resourceFile.getParentFile();
            if (!resoureDirectory.exists() && !resoureDirectory.mkdirs()) {
                throw new DeploymentException("Could not create class path directory: " + entryDirectory);
            }
            resourceFile.createNewFile();
            try (InputStream in = child.getAsset().openStream();
                OutputStream out = new FileOutputStream(resourceFile)) {
                copy(in, out);
            }
            child.getPath().get();
        }
    }
}
Also used : InputStream(java.io.InputStream) Node(org.jboss.shrinkwrap.api.Node) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException) File(java.io.File)

Example 3 with Node

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

the class ContextPathArchivePreparerTest method testExternalMount.

@SuppressWarnings("unchecked")
@Test
public void testExternalMount() throws Exception {
    WARArchive archive = DefaultWarDeploymentFactory.archiveFromCurrentApp();
    assertThat(archive.getContextRoot()).isNull();
    URL url = getClass().getClassLoader().getResource("mounts.yml");
    ConfigViewFactory factory = new ConfigViewFactory(new Properties());
    factory.load("test", url);
    factory.withProfile("test");
    ConfigViewImpl view = factory.get(true);
    List<String> mounts = view.resolve("swarm.context.mounts").as(List.class).getValue();
    ContextPathArchivePreparer preparer = new ContextPathArchivePreparer(archive);
    preparer.mounts = mounts;
    preparer.process();
    Node externalMount = archive.get(WARArchive.EXTERNAL_MOUNT_PATH);
    assertThat(externalMount).isNotNull();
    assertThat(externalMount.getAsset()).isInstanceOf(UndertowExternalMountsAsset.class);
    UndertowExternalMountsAsset externalMountAsset = (UndertowExternalMountsAsset) externalMount.getAsset();
    try (BufferedReader reader = new BufferedReader(new InputStreamReader(externalMountAsset.openStream()))) {
        assertThat(reader.readLine()).endsWith("external1");
        assertThat(reader.readLine()).endsWith("external2");
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) Node(org.jboss.shrinkwrap.api.Node) Properties(java.util.Properties) WARArchive(org.wildfly.swarm.undertow.WARArchive) URL(java.net.URL) ConfigViewImpl(org.wildfly.swarm.container.config.ConfigViewImpl) UndertowExternalMountsAsset(org.wildfly.swarm.undertow.internal.UndertowExternalMountsAsset) ConfigViewFactory(org.wildfly.swarm.container.config.ConfigViewFactory) BufferedReader(java.io.BufferedReader) List(java.util.List) Test(org.junit.Test)

Example 4 with Node

use of org.jboss.shrinkwrap.api.Node 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 5 with Node

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

the class SecuredTest method testExistingWebXml.

@Test
public void testExistingWebXml() {
    WARArchive archive = ShrinkWrap.create(WARArchive.class);
    ClassLoaderAsset asset = new ClassLoaderAsset("test-web.xml");
    archive.addAsWebInfResource(asset, "web.xml");
    archive.as(Secured.class).protect("/cheddar");
    Node webXml = archive.get("WEB-INF/web.xml");
    Asset newAsset = webXml.getAsset();
    InputStream in = newAsset.openStream();
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    List<String> lines = reader.lines().map(String::trim).collect(Collectors.toList());
    assertThat(lines).contains("<servlet-name>comingsoon</servlet-name>");
    assertThat(lines).contains("<url-pattern>/cheddar</url-pattern>");
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Node(org.jboss.shrinkwrap.api.Node) BufferedReader(java.io.BufferedReader) ClassLoaderAsset(org.jboss.shrinkwrap.api.asset.ClassLoaderAsset) Asset(org.jboss.shrinkwrap.api.asset.Asset) ClassLoaderAsset(org.jboss.shrinkwrap.api.asset.ClassLoaderAsset) WARArchive(org.wildfly.swarm.undertow.WARArchive) Test(org.junit.Test)

Aggregations

Node (org.jboss.shrinkwrap.api.Node)59 ArchivePath (org.jboss.shrinkwrap.api.ArchivePath)19 Archive (org.jboss.shrinkwrap.api.Archive)17 Test (org.junit.Test)17 Asset (org.jboss.shrinkwrap.api.asset.Asset)16 IOException (java.io.IOException)15 URL (java.net.URL)12 Map (java.util.Map)12 File (java.io.File)11 WebArchive (org.jboss.shrinkwrap.api.spec.WebArchive)11 BufferedReader (java.io.BufferedReader)10 InputStream (java.io.InputStream)10 InputStreamReader (java.io.InputStreamReader)10 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 AnnotationNode (org.objectweb.asm.tree.AnnotationNode)6 ClassNode (org.objectweb.asm.tree.ClassNode)6 JAXRSArchive (org.wildfly.swarm.jaxrs.JAXRSArchive)6