Search in sources :

Example 46 with ArchivePath

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

the class OpenApiAnnotationScanner method indexArchive.

/**
 * Indexes the given archive.
 * @param config
 * @param indexer
 * @param archive
 */
@SuppressWarnings("unchecked")
private static void indexArchive(OpenApiConfig config, Indexer indexer, Archive archive) {
    Map<ArchivePath, Node> c = archive.getContent();
    try {
        for (Map.Entry<ArchivePath, Node> each : c.entrySet()) {
            ArchivePath archivePath = each.getKey();
            if (archivePath.get().endsWith(OpenApiConstants.CLASS_SUFFIX) && acceptClassForScanning(config, archivePath.get())) {
                try (InputStream contentStream = each.getValue().getAsset().openStream()) {
                    LOG.debugv("Indexing asset: {0} from archive: {1}", archivePath.get(), archive.getName());
                    indexer.index(contentStream);
                }
                continue;
            }
            if (archivePath.get().endsWith(OpenApiConstants.JAR_SUFFIX) && acceptJarForScanning(config, archivePath.get())) {
                try (InputStream contentStream = each.getValue().getAsset().openStream()) {
                    JARArchive jarArchive = ShrinkWrap.create(JARArchive.class, archivePath.get()).as(ZipImporter.class).importFrom(contentStream).as(JARArchive.class);
                    indexArchive(config, indexer, jarArchive);
                }
                continue;
            }
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : ArchivePath(org.jboss.shrinkwrap.api.ArchivePath) InputStream(java.io.InputStream) Node(org.jboss.shrinkwrap.api.Node) JARArchive(org.wildfly.swarm.spi.api.JARArchive) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap)

Example 47 with ArchivePath

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

the class WebInfLibFilteringArchive method filter.

protected void filter(ResolvedDependencies resolvedDependencies) {
    Set<ArchivePath> remove = new HashSet<>();
    filter(remove, getArchive().get(ArchivePaths.root()), resolvedDependencies);
    for (ArchivePath each : remove) {
        getArchive().delete(each);
    }
}
Also used : ArchivePath(org.jboss.shrinkwrap.api.ArchivePath) HashSet(java.util.HashSet)

Example 48 with ArchivePath

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

the class StaticContentContainer method mergeIgnoringDuplicates.

@SuppressWarnings("unchecked")
default T mergeIgnoringDuplicates(Archive<?> source, String base, Filter<ArchivePath> filter) {
    if (!base.startsWith("/")) {
        base = "/" + base;
    }
    // Get existing contents from source archive
    final Map<ArchivePath, Node> sourceContent = source.getContent();
    // Add each asset from the source archive
    for (final Map.Entry<ArchivePath, Node> contentEntry : sourceContent.entrySet()) {
        final Node node = contentEntry.getValue();
        ArchivePath nodePath = contentEntry.getKey();
        if (!nodePath.get().startsWith(base)) {
            continue;
        }
        if (!filter.include(nodePath)) {
            continue;
        }
        if (contains(nodePath)) {
            continue;
        }
        nodePath = new BasicPath(nodePath.get().replaceFirst(base, ""));
        // Delegate
        if (node.getAsset() == null) {
            addAsDirectory(nodePath);
        } else {
            add(node.getAsset(), nodePath);
        }
    }
    return (T) this;
}
Also used : ArchivePath(org.jboss.shrinkwrap.api.ArchivePath) Node(org.jboss.shrinkwrap.api.Node) BasicPath(org.jboss.shrinkwrap.impl.base.path.BasicPath) Map(java.util.Map)

Example 49 with ArchivePath

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

the class JAXRSArchiveImpl method isJAXRS.

public static boolean isJAXRS(Archive<?> archive) {
    Map<ArchivePath, Node> content = archive.getContent();
    for (Map.Entry<ArchivePath, Node> entry : content.entrySet()) {
        Node node = entry.getValue();
        Asset asset = node.getAsset();
        if (isJAXRS(node.getPath(), asset)) {
            return true;
        }
    }
    return false;
}
Also used : ArchivePath(org.jboss.shrinkwrap.api.ArchivePath) Node(org.jboss.shrinkwrap.api.Node) Asset(org.jboss.shrinkwrap.api.asset.Asset) ArchiveAsset(org.jboss.shrinkwrap.api.asset.ArchiveAsset) Map(java.util.Map)

Example 50 with ArchivePath

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

the class RuntimeDeployer method deploy.

public void deploy(Archive<?> deployment, String asName) throws DeploymentException {
    if (deployment.getName().endsWith(".rar")) {
        // Track any .rar deployments
        this.rarDeploymentNames.add(deployment.getName());
    } else if (!this.rarDeploymentNames.isEmpty()) {
        // Add any previous .rar deployments as dependencies
        // of any non-.rar deployments.
        JARArchive mutable = deployment.as(JARArchive.class);
        this.rarDeploymentNames.forEach(e -> {
            mutable.addModule("deployment." + e);
        });
    }
    try (AutoCloseable deploymentTimer = Performance.time("deployment: " + deployment.getName())) {
        // see DependenciesContainer#addAllDependencies()
        if (deployment instanceof DependenciesContainer) {
            DependenciesContainer<?> depContainer = (DependenciesContainer) deployment;
            if (depContainer.hasMarker(DependenciesContainer.ALL_DEPENDENCIES_MARKER)) {
                if (!depContainer.hasMarker(ALL_DEPENDENCIES_ADDED_MARKER)) {
                    ApplicationEnvironment appEnv = ApplicationEnvironment.get();
                    if (ApplicationEnvironment.Mode.UBERJAR == appEnv.getMode()) {
                        ArtifactLookup artifactLookup = ArtifactLookup.get();
                        for (String gav : appEnv.getDependencies()) {
                            depContainer.addAsLibrary(artifactLookup.artifact(gav));
                        }
                    } else {
                        Set<String> paths = appEnv.resolveDependencies(Collections.emptyList());
                        for (String path : paths) {
                            final File pathFile = new File(path);
                            if (path.endsWith(".jar")) {
                                depContainer.addAsLibrary(pathFile);
                            } else if (pathFile.isDirectory()) {
                                depContainer.merge(ShrinkWrap.create(GenericArchive.class).as(ExplodedImporter.class).importDirectory(pathFile).as(GenericArchive.class), "/WEB-INF/classes", Filters.includeAll());
                            }
                        }
                    }
                    depContainer.addMarker(ALL_DEPENDENCIES_ADDED_MARKER);
                }
            }
        }
        this.deploymentContext.activate(deployment, asName, !this.implicitDeploymentsComplete);
        // 2. give fractions a chance to handle the deployment
        for (DeploymentProcessor processor : this.deploymentProcessors) {
            processor.process();
        }
        this.deploymentContext.deactivate();
        if (DeployerMessages.MESSAGES.isDebugEnabled()) {
            DeployerMessages.MESSAGES.deploying(deployment.getName());
            Map<ArchivePath, Node> ctx = deployment.getContent();
            for (Map.Entry<ArchivePath, Node> each : ctx.entrySet()) {
                DeployerMessages.MESSAGES.deploymentContent(each.getKey().toString());
            }
        }
        if (BootstrapProperties.flagIsSet(SwarmProperties.EXPORT_DEPLOYMENT)) {
            String exportLocation = System.getProperty(SwarmProperties.EXPORT_DEPLOYMENT);
            if (exportLocation != null) {
                Path archivePath = null;
                if (exportLocation.toLowerCase().equals("true")) {
                    archivePath = Paths.get(deployment.getName());
                } else {
                    Path exportDir = Paths.get(exportLocation);
                    Files.createDirectories(exportDir);
                    archivePath = exportDir.resolve(deployment.getName());
                }
                final File out = archivePath.toFile();
                DeployerMessages.MESSAGES.exportingDeployment(out.getAbsolutePath());
                deployment.as(ZipExporter.class).exportTo(out, true);
            }
        }
        byte[] hash = this.contentRepository.addContent(deployment);
        final ModelNode deploymentAdd = new ModelNode();
        deploymentAdd.get(OP).set(ADD);
        deploymentAdd.get(OP_ADDR).set("deployment", deployment.getName());
        deploymentAdd.get(RUNTIME_NAME).set(deployment.getName());
        deploymentAdd.get(ENABLED).set(true);
        deploymentAdd.get(PERSISTENT).set(true);
        ModelNode content = deploymentAdd.get(CONTENT).add();
        content.get(HASH).set(hash);
        int deploymentTimeout = Integer.getInteger(SwarmProperties.DEPLOYMENT_TIMEOUT, 300);
        final ModelNode opHeaders = new ModelNode();
        opHeaders.get(BLOCKING_TIMEOUT).set(deploymentTimeout);
        deploymentAdd.get(OPERATION_HEADERS).set(opHeaders);
        BootstrapLogger.logger("org.wildfly.swarm.runtime.deployer").info("deploying " + deployment.getName());
        System.setProperty(SwarmInternalProperties.CURRENT_DEPLOYMENT, deployment.getName());
        try {
            ModelNode result = client.execute(deploymentAdd);
            ModelNode outcome = result.get("outcome");
            if (outcome.asString().equals("success")) {
                return;
            }
            ModelNode description = result.get("failure-description");
            throw new DeploymentException(deployment, SwarmMessages.MESSAGES.deploymentFailed(description.asString()));
        } catch (IOException e) {
            throw SwarmMessages.MESSAGES.deploymentFailed(e, deployment);
        }
    } catch (Exception e) {
        throw new DeploymentException(deployment, e);
    }
}
Also used : ApplicationEnvironment(org.wildfly.swarm.bootstrap.env.ApplicationEnvironment) ADD(org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD) DefaultDeploymentCreator(org.wildfly.swarm.container.runtime.deployments.DefaultDeploymentCreator) DependenciesContainer(org.wildfly.swarm.spi.api.DependenciesContainer) Node(org.jboss.shrinkwrap.api.Node) PreDestroy(javax.annotation.PreDestroy) BLOCKING_TIMEOUT(org.jboss.as.controller.descriptions.ModelDescriptionConstants.BLOCKING_TIMEOUT) Map(java.util.Map) BootstrapLogger(org.wildfly.swarm.bootstrap.logging.BootstrapLogger) ENABLED(org.jboss.as.controller.descriptions.ModelDescriptionConstants.ENABLED) Any(javax.enterprise.inject.Any) Path(java.nio.file.Path) DeploymentContext(org.wildfly.swarm.container.runtime.cdi.DeploymentContext) Instance(javax.enterprise.inject.Instance) ZipImporter(org.jboss.shrinkwrap.api.importer.ZipImporter) Collection(java.util.Collection) SwarmInternalProperties(org.wildfly.swarm.spi.api.internal.SwarmInternalProperties) Set(java.util.Set) JARArchive(org.wildfly.swarm.spi.api.JARArchive) GenericArchive(org.jboss.shrinkwrap.api.GenericArchive) DeploymentException(org.wildfly.swarm.container.DeploymentException) FileSystemLayout(org.wildfly.swarm.internal.FileSystemLayout) List(java.util.List) OP(org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP) Stream(java.util.stream.Stream) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) CONTENT(org.jboss.as.controller.descriptions.ModelDescriptionConstants.CONTENT) ApplicationScoped(javax.enterprise.context.ApplicationScoped) ModelNode(org.jboss.dmr.ModelNode) SwarmProperties(org.wildfly.swarm.spi.api.SwarmProperties) RUNTIME_NAME(org.jboss.as.controller.descriptions.ModelDescriptionConstants.RUNTIME_NAME) DeploymentProcessor(org.wildfly.swarm.spi.api.DeploymentProcessor) TempFileProvider(org.jboss.vfs.TempFileProvider) Performance(org.wildfly.swarm.bootstrap.performance.Performance) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Deployer(org.wildfly.swarm.container.internal.Deployer) ArchivePath(org.jboss.shrinkwrap.api.ArchivePath) DeployerMessages(org.wildfly.swarm.internal.DeployerMessages) ArtifactLookup(org.wildfly.swarm.spi.api.ArtifactLookup) ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) OPERATION_HEADERS(org.jboss.as.controller.descriptions.ModelDescriptionConstants.OPERATION_HEADERS) OP_ADDR(org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR) PERSISTENT(org.jboss.as.controller.descriptions.ModelDescriptionConstants.PERSISTENT) ShrinkWrap(org.jboss.shrinkwrap.api.ShrinkWrap) Files(java.nio.file.Files) BootstrapProperties(org.wildfly.swarm.bootstrap.util.BootstrapProperties) ExplodedImporter(org.jboss.shrinkwrap.api.importer.ExplodedImporter) SwarmMessages(org.wildfly.swarm.internal.SwarmMessages) IOException(java.io.IOException) Filters(org.jboss.shrinkwrap.api.Filters) Archive(org.jboss.shrinkwrap.api.Archive) SwarmContentRepository(org.wildfly.swarm.container.runtime.wildfly.SwarmContentRepository) ZipExporter(org.jboss.shrinkwrap.api.exporter.ZipExporter) File(java.io.File) HASH(org.jboss.as.controller.descriptions.ModelDescriptionConstants.HASH) Paths(java.nio.file.Paths) Collections(java.util.Collections) ArtifactLookup(org.wildfly.swarm.spi.api.ArtifactLookup) ZipExporter(org.jboss.shrinkwrap.api.exporter.ZipExporter) Node(org.jboss.shrinkwrap.api.Node) ModelNode(org.jboss.dmr.ModelNode) ArchivePath(org.jboss.shrinkwrap.api.ArchivePath) DeploymentProcessor(org.wildfly.swarm.spi.api.DeploymentProcessor) JARArchive(org.wildfly.swarm.spi.api.JARArchive) Path(java.nio.file.Path) ArchivePath(org.jboss.shrinkwrap.api.ArchivePath) DependenciesContainer(org.wildfly.swarm.spi.api.DependenciesContainer) IOException(java.io.IOException) ApplicationEnvironment(org.wildfly.swarm.bootstrap.env.ApplicationEnvironment) DeploymentException(org.wildfly.swarm.container.DeploymentException) IOException(java.io.IOException) GenericArchive(org.jboss.shrinkwrap.api.GenericArchive) DeploymentException(org.wildfly.swarm.container.DeploymentException) ModelNode(org.jboss.dmr.ModelNode) File(java.io.File) Map(java.util.Map)

Aggregations

ArchivePath (org.jboss.shrinkwrap.api.ArchivePath)60 File (java.io.File)39 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)33 ZipExporter (org.jboss.shrinkwrap.api.exporter.ZipExporter)31 Node (org.jboss.shrinkwrap.api.Node)18 WebArchive (org.jboss.shrinkwrap.api.spec.WebArchive)17 Map (java.util.Map)12 VirtualFile (org.jboss.vfs.VirtualFile)10 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)7 Archive (org.jboss.shrinkwrap.api.Archive)7 Deployment (org.jboss.arquillian.container.test.api.Deployment)6 Asset (org.jboss.shrinkwrap.api.asset.Asset)6 URL (java.net.URL)5 ArchiveAsset (org.jboss.shrinkwrap.api.asset.ArchiveAsset)5 JARArchive (org.wildfly.swarm.spi.api.JARArchive)5 Path (java.nio.file.Path)4 ZipImporter (org.jboss.shrinkwrap.api.importer.ZipImporter)4 MalformedURLException (java.net.MalformedURLException)3 HashMap (java.util.HashMap)3