org.jboss.shrinkwrap.api.ArchivePath Java Examples

The following examples show how to use org.jboss.shrinkwrap.api.ArchivePath. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServiceFileCombinationImpl.java    From vertx-maven-plugin with Apache License 2.0 6 votes vote down vote up
private static Map<String, List<List<String>>> findDescriptorsFromDependencies(List<File> deps, List<String> patterns) {
    Map<String, List<List<String>>> map = new LinkedHashMap<>();

    for (File file : deps) {
        JavaArchive archive = ShrinkWrap.createFromZipFile(JavaArchive.class, file);
        Map<ArchivePath, Node> content = getMatchingFilesFromJar(patterns, archive);

        for (Map.Entry<ArchivePath, Node> entry : content.entrySet()) {
            Asset asset = entry.getValue().getAsset();
            if (asset != null) {
                List<String> lines;
                String path = entry.getKey().get();
                lines = read(asset, path);

                List<List<String>> items = map.computeIfAbsent(path, k -> new ArrayList<>());
                items.add(lines);
                map.put(path, items);
            }
        }
    }
    return map;
}
 
Example #2
Source File: DefaultApplicationDeploymentProcessor.java    From thorntail with Apache License 2.0 6 votes vote down vote up
static boolean hasApplicationPathAnnotation(ArchivePath path, Asset asset) {
    if (asset == null) {
        return false;
    }

    if (asset instanceof ArchiveAsset) {
        return hasApplicationPathAnnotation(((ArchiveAsset) asset).getArchive());
    }

    if (!path.get().endsWith(".class")) {
        return false;
    }

    try (InputStream in = asset.openStream()) {
        ClassReader reader = new ClassReader(in);
        ApplicationPathAnnotationSeekingClassVisitor visitor = new ApplicationPathAnnotationSeekingClassVisitor();
        reader.accept(visitor, 0);
        return visitor.isFound();
    } catch (IOException ignored) {
    }

    return false;
}
 
Example #3
Source File: ArchiveResourceIteratorFactory.java    From tomee with Apache License 2.0 6 votes vote down vote up
private Collection<Resource> findResources(final String path, final String suffix) {
    final ClassLoader loader = Thread.currentThread().getContextClassLoader();
    final Collection<Resource> resources = new ArrayList<Resource>();
    if (SWClassLoader.class.isInstance(loader)) {
        final Collection<Archive<?>> archives = SWClassLoader.class.cast(loader).getArchives();
        final ClassLoader parent = loader.getParent();
        for (final Archive<?> archive : archives) {
            final Map<ArchivePath, Node> content = archive.getContent(new Filter<ArchivePath>() {
                @Override
                public boolean include(final ArchivePath object) {
                    final String currentPath = classloaderPath(object);

                    return !(parent != null && parent.getResource(currentPath) != null)
                            && currentPath.startsWith('/' + path) && currentPath.endsWith(suffix);

                }
            });

            for (final Map.Entry<ArchivePath, Node> entry : content.entrySet()) {
                resources.add(new SWResource(entry.getKey(), entry.getValue()));
            }
        }
    }
    return resources;
}
 
Example #4
Source File: DependencyManagerTest.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 6 votes vote down vote up
@Test
public void populateUberJarMavenRepository() throws Exception {
    manager.addDependency(BOOTSTRAP_JAR);
    manager.addDependency(BOOTSTRAP_CONF);
    manager.addDependency(MODULES_EMPTY_A);
    manager.addDependency(MODULES_A);
    manager.analyzeDependencies(false);

    Archive archive = ShrinkWrap.create(JavaArchive.class);

    manager.populateUberJarMavenRepository(archive);

    Map<ArchivePath, Node> content = archive.getContent();

    List<String> jars = content.keySet().stream().map(ArchivePath::get).filter((e) -> e.endsWith(".jar")).collect(Collectors.toList());

    assertThat(jars).hasSize(5);
    assertThat(jars).contains("/m2repo/" + MODULES_EMPTY_A.repoPath(true));
    assertThat(jars).contains("/m2repo/" + BOOTSTRAP_CONF.repoPath(true));
    assertThat(jars).contains("/m2repo/" + MODULES_A.repoPath(true));
    assertThat(jars).contains("/m2repo/" + CXF.repoPath(true));
    assertThat(jars).contains("/m2repo/" + WS_INTEGRATION.repoPath(true));
}
 
Example #5
Source File: MicroProfileOpenAPITCKDeploymentPackager.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Override
public Archive<?> generateDeployment(final TestDeployment testDeployment,
                                     final Collection<ProtocolArchiveProcessor> processors) {
    final WebArchive webArchive = ShrinkWrap.create(WebArchive.class, "microprofile-openapi.war")
                                            .merge(testDeployment.getApplicationArchive())
                                            // TODO - This doesn't seem right. This is for the JAX-RS endpoints to be CDI scanned.
                                            // This is to use CDI events to filter endpoints with configuration.
                                            // Check org.apache.geronimo.microprofile.openapi.cdi.GeronimoOpenAPIExtension.findEndpointsAndApplication()
                                            // A beans.xml should not be required.
                                            .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
            ;

    // MP Config in wrong place - See https://github.com/eclipse/microprofile/issues/46.
    if (testDeployment.getApplicationArchive() instanceof WebArchive) {
        final Map<ArchivePath, Node> content =
                testDeployment.getApplicationArchive().getContent(
                        object -> object.get().matches(".*META-INF/.*"));
        content.forEach((archivePath, node) -> webArchive.addAsResource(node.getAsset(), node.getPath()));
    }

    return super.generateDeployment(
            new TestDeployment(null, webArchive, testDeployment.getAuxiliaryArchives()), processors);
}
 
Example #6
Source File: CustomVaultInModuleTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static void createTestModule() throws Exception {
    File moduleXml = new File(CustomSecurityVault.class.getResource(CustomVaultInModuleTestCase.class.getSimpleName() + "-module.xml").toURI());
    testModule = new TestModule(MODULE_NAME, moduleXml);

    JavaArchive archive = testModule.addResource("test-custom-vault-in-module.jar")
            .addClass(CustomSecurityVault.class)
            .addClass(TestVaultExtension.class)
            .addClass(TestVaultParser.class)
            .addClass(TestVaultRemoveHandler.class)
            .addClass(TestVaultResolveExpressionHandler.class)
            .addClass(TestVaultSubsystemResourceDescription.class);

    ArchivePath path = ArchivePaths.create("/");
    path = ArchivePaths.create(path, "services");
    path = ArchivePaths.create(path, Extension.class.getName());
    archive.addAsManifestResource(CustomSecurityVault.class.getPackage(), Extension.class.getName(), path);
    testModule.create(true);
}
 
Example #7
Source File: MicroProfileOpenTracingTCKDeploymentPackager.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Override
public Archive<?> generateDeployment(final TestDeployment testDeployment,
                                     final Collection<ProtocolArchiveProcessor> processors) {

    final WebArchive webArchive = ShrinkWrap.create(WebArchive.class, "microprofile-opentracing.war")
                                            .merge(testDeployment.getApplicationArchive());

    // opentracing-api jar added by Geronimo Impl. Also added by TCK causes issues with same classes in different Classloaders
    final Map<ArchivePath, Node> content = webArchive.getContent(object -> object.get().matches(".*opentracing-api.*jar.*"));
    content.forEach((archivePath, node) -> webArchive.delete(archivePath));

    // TCK expects a MockTracer. Check org/eclipse/microprofile/opentracing/tck/application/TracerWebService.java:133
    webArchive.addAsLibrary(jarLocation(MockTracer.class));
    webArchive.addAsLibrary(jarLocation(ThreadLocalScopeManager.class));
    webArchive.addAsWebInfResource("META-INF/beans.xml");
    webArchive.addClass(MicroProfileOpenTracingTCKTracer.class);

    System.out.println(webArchive.toString(true));

    return super.generateDeployment(
            new TestDeployment(null, webArchive, testDeployment.getAuxiliaryArchives()), processors);
}
 
Example #8
Source File: DuplicateExtCommandTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static void createTestModule() throws Exception {
    final File moduleXml = new File(DuplicateExtCommandTestCase.class.getResource(DuplicateExtCommandTestCase.class.getSimpleName() + "-module.xml").toURI());
    testModule = new TestModule(MODULE_NAME, moduleXml);

    final JavaArchive archive = testModule.addResource("test-cli-duplicate-commands-module.jar")
            .addClass(DuplicateExtCommandHandler.class)
            .addClass(DuplicateExtCommandHandlerProvider.class)
            .addClass(DuplicateExtCommandsExtension.class)
            .addClass(CliExtCommandsParser.class)
            .addClass(DuplicateExtCommand.class)
            .addClass(DuplicateExtCommandSubsystemResourceDescription.class);

    ArchivePath services = ArchivePaths.create("/");
    services = ArchivePaths.create(services, "services");

    final ArchivePath extService = ArchivePaths.create(services, Extension.class.getName());
    archive.addAsManifestResource(getResource(DuplicateExtCommandsExtension.class), extService);

    final ArchivePath cliCmdService = ArchivePaths.create(services, CommandHandlerProvider.class.getName());
    archive.addAsManifestResource(getResource(DuplicateExtCommandHandlerProvider.class), cliCmdService);

    final ArchivePath cliAeshCmdService = ArchivePaths.create(services, Command.class.getName());
    archive.addAsManifestResource(getResource(DuplicateExtCommand.class), cliAeshCmdService);
    testModule.create(true);
}
 
Example #9
Source File: JAXRSArchiveImpl.java    From thorntail with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #10
Source File: WebInfLibFilteringArchive.java    From thorntail with Apache License 2.0 5 votes vote down vote up
protected void filter(Set<ArchivePath> remove, Node node, ResolvedDependencies resolvedDependencies) {
    String path = node.getPath().get();
    if (path.startsWith("/WEB-INF/lib") && path.endsWith(".jar")) {
        if (path.contains("thorntail-runner")) {
            remove.add(node.getPath());
        }
        if (resolvedDependencies.isRemovable(node)) {
            remove.add(node.getPath());
        }
    }

    for (Node each : node.getChildren()) {
        filter(remove, each, resolvedDependencies);
    }
}
 
Example #11
Source File: NotificationFilter.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
public boolean include(ArchivePath path) {
    Node node = uber.get(path);
    if (node != null && isAllowedDuplicate(node) == false) {
        Asset asset = node.getAsset();
        if (asset != null) {
            Asset other = archive.get(path).getAsset();
            validate(path, equal(asset, other));
        }
        return false;
    }
    return true;
}
 
Example #12
Source File: WebInfLibFilteringArchive.java    From thorntail with Apache License 2.0 5 votes vote down vote up
protected void filter(ResolvedDependencies resolvedDependencies) {
    Set<ArchivePath> remove = new HashSet<>();
    filter(remove, getArchive().get(ArchivePaths.root()), resolvedDependencies);

    for (ArchivePath each : remove) {
        getArchive().delete(each);
    }
}
 
Example #13
Source File: ArchiveUtil.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
/**
 * Indexes the given archive.
 * 
 * @param config
 * @param indexer
 * @param archive
 */
private static void indexArchive(OpenApiConfig config, Indexer indexer, Archive<?> archive) {
    FilteredIndexView filter = new FilteredIndexView(null, config);
    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(filter, archivePath.get())) {
                try (InputStream contentStream = each.getValue().getAsset().openStream()) {
                    TckLogging.log.indexing(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()) {
                    JavaArchive jarArchive = ShrinkWrap.create(JavaArchive.class, archivePath.get())
                            .as(ZipImporter.class).importFrom(contentStream).as(JavaArchive.class);
                    indexArchive(config, indexer, jarArchive);
                }
                continue;
            }
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example #14
Source File: UndertowDeployerHelper.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private void addAnnotatedServlets(DeploymentInfo di, Archive<?> archive) {
    Map<ArchivePath, Node> classNodes = archive.getContent((ArchivePath path) -> {

        String stringPath = path.get();
        return (stringPath.startsWith("/WEB-INF/classes") && stringPath.endsWith("class"));

    });

    for (Map.Entry<ArchivePath, Node> entry : classNodes.entrySet()) {
        Node n = entry.getValue();
        if (n.getAsset() instanceof ClassAsset) {
            ClassAsset classAsset = (ClassAsset) n.getAsset();
            Class<?> clazz = classAsset.getSource();

            WebServlet annotation = clazz.getAnnotation(WebServlet.class);
            if (annotation != null) {
                ServletInfo undertowServlet = new ServletInfo(clazz.getSimpleName(), (Class<? extends Servlet>) clazz);

                String[] mappings = annotation.value();
                if (mappings != null) {
                    for (String urlPattern : mappings) {
                        undertowServlet.addMapping(urlPattern);
                    }
                }

                di.addServlet(undertowServlet);
            }
        }
    }

}
 
Example #15
Source File: Mvn.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public boolean include(final ArchivePath archivePath) {
    if (!delegate.include(archivePath)) {
        return false;
    }
    if (archivePath.get().contains("shiro.ini")) {
        paths.put(archivePath, addArquillianServletInUrls(archivePath));
        return false;
    }
    return true;
}
 
Example #16
Source File: DefaultApplicationDeploymentProcessor.java    From thorntail with Apache License 2.0 5 votes vote down vote up
private static boolean hasApplicationPathAnnotation(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 (hasApplicationPathAnnotation(node.getPath(), asset)) {
            return true;
        }
    }

    return false;
}
 
Example #17
Source File: Mvn.java    From tomee with Apache License 2.0 5 votes vote down vote up
public KnownResourcesFilter(final File base, final String prefix, final Filter<ArchivePath> filter) {
    this.base = base;
    this.delegate = filter;

    if (prefix.startsWith("/")) {
        this.prefix = prefix.substring(1);
    } else {
        this.prefix = prefix;
    }
}
 
Example #18
Source File: DependencyManagerTest.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Test
public void populateUberJarMavenRepositoryAvoidingProvided() throws Exception {
    manager.addDependency(BOOTSTRAP_JAR);
    manager.addDependency(BOOTSTRAP_CONF);
    manager.addDependency(MODULES_EMPTY_A);
    manager.addDependency(MODULES_A);
    manager.addDependency(PROVIDED_A);
    manager.addDependency(COM_SUN_MAIL);
    manager.analyzeDependencies(false);

    assertThat(manager.getProvidedGAVs()).contains("com.sun.mail:javax.mail");

    Archive archive = ShrinkWrap.create(JavaArchive.class);

    manager.populateUberJarMavenRepository(archive);

    Map<ArchivePath, Node> content = archive.getContent();

    List<String> jars = content.keySet().stream().map(ArchivePath::get).filter((e) -> e.endsWith(".jar")).collect(Collectors.toList());

    assertThat(jars).hasSize(6);
    assertThat(jars).contains("/m2repo/" + MODULES_EMPTY_A.repoPath(true));
    assertThat(jars).contains("/m2repo/" + BOOTSTRAP_CONF.repoPath(true));
    assertThat(jars).contains("/m2repo/" + MODULES_A.repoPath(true));
    assertThat(jars).contains("/m2repo/" + CXF.repoPath(true));
    assertThat(jars).contains("/m2repo/" + WS_INTEGRATION.repoPath(true));
    assertThat(jars).contains("/m2repo/" + PROVIDED_A.repoPath(true));
}
 
Example #19
Source File: JAXRSArchiveImpl.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
protected void addGeneratedApplication() {

        Map<ArchivePath, Node> content = getArchive().getContent();

        boolean applicationFound = false;

        for (Map.Entry<ArchivePath, Node> entry : content.entrySet()) {
            Node node = entry.getValue();
            Asset asset = node.getAsset();
            if (hasApplicationPathAnnotation(node.getPath(), asset)) {
                applicationFound = true;
                break;
            }
        }

        if (!applicationFound) {
            String name = "org.wildfly.swarm.generated.WildFlySwarmDefaultJAXRSApplication";
            String path = "WEB-INF/classes/" + name.replace('.', '/') + ".class";

            byte[] generatedApp = new byte[0];
            try {
                generatedApp = ApplicationFactory2.create(name, "/");
                add(new ByteArrayAsset(generatedApp), path);
                addHandlers(new ApplicationHandler(this, path));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
 
Example #20
Source File: AbstractApplicationArchiveProcessor.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
public void process(Archive<?> archive, TestClass testClass) {
    if (archive instanceof EnterpriseArchive) {
        final EnterpriseArchive ear = (EnterpriseArchive) archive;

        Map<ArchivePath, Node> wars = ear.getContent(Filters.include(".*\\.war"));
        for (Map.Entry<ArchivePath, Node> war : wars.entrySet()) {
            handleWebArchive(ear.getAsType(WebArchive.class, war.getKey()));
        }
    } else if (archive instanceof WebArchive) {
        handleWebArchive((WebArchive) archive);
    } else {
        throw new IllegalArgumentException("Can only handle .ear or .war deployments: " + archive);
    }
}
 
Example #21
Source File: RARArchiveImpl.java    From thorntail with Apache License 2.0 4 votes vote down vote up
@Override
public ArchivePath getLibraryPath() {
    return PATH_LIBRARY;
}
 
Example #22
Source File: RARArchiveImpl.java    From thorntail with Apache License 2.0 4 votes vote down vote up
@Override
protected ArchivePath getResourcePath() {
    return PATH_RESOURCE;
}
 
Example #23
Source File: ScanMultiProvider.java    From appengine-tck with Apache License 2.0 4 votes vote down vote up
protected void merge(MultiContext context, WebArchive war) throws Exception {
    WebArchive uber = context.getWar();
    Filter<ArchivePath> filter = createFilter(uber, war);
    uber.merge(war, filter);
}
 
Example #24
Source File: Mvn.java    From tomee with Apache License 2.0 4 votes vote down vote up
public void update(final Archive<?> archive) {
    for (final Map.Entry<ArchivePath, Asset> r : paths.entrySet()) {
        archive.add(r.getValue(), prefix + r.getKey().get());
    }
}
 
Example #25
Source File: SpringBootZipExporterDelegate.java    From camel-spring-boot with Apache License 2.0 4 votes vote down vote up
@Override
protected void processNode(final ArchivePath path, final Node node) {
    // do nothing
}
 
Example #26
Source File: SwaggerConfiguration.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 4 votes vote down vote up
@Override
public void prepareArchive(Archive<?> a) {
    try {
        // Create a JAX-RS deployment archive
        JAXRSArchive deployment = a.as(JAXRSArchive.class).addModule("io.swagger");

        // Make the deployment a swagger archive
        SwaggerArchive swaggerArchive = deployment.as(SwaggerArchive.class);

        // Get the context root from the deployment and tell swagger about it
        swaggerArchive.setContextRoot(deployment.getContextRoot());

        // If the archive has not been configured with packages for swagger to scan
        // try to be smart about it, and find the topmost package that's not in the
        // org.wildfly.swarm package space
        if (!swaggerArchive.hasResourcePackages()) {
            String packageName = null;
            for (Map.Entry<ArchivePath, Node> entry : deployment.getContent().entrySet()) {
                final ArchivePath key = entry.getKey();
                if (key.get().endsWith(".class")) {
                    String parentPath = key.getParent().get();
                    parentPath = parentPath.replaceFirst("/", "");

                    String parentPackage = parentPath.replaceFirst(".*/classes/", "");
                    parentPackage = parentPackage.replaceAll("/", ".");

                    if (parentPackage.startsWith("org.wildfly.swarm")) {
                        System.out.println("[Swagger] Ignoring swarm package " + parentPackage);
                    } else {
                        packageName = parentPackage;
                        break;
                    }
                }
            }
            if (packageName == null) {
                System.err.println("[Swagger] No eligible packages for Swagger to scan.");
            } else {
                System.out.println("[Swagger] Configuring Swagger with " + packageName);
                swaggerArchive.setResourcePackages(packageName);
            }
        }

        // Now add the swagger resources to our deployment
        deployment.addResource(io.swagger.jaxrs.listing.ApiListingResource.class);
        deployment.addResource(io.swagger.jaxrs.listing.SwaggerSerializers.class);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #27
Source File: DeploymentProducer.java    From thorntail with Apache License 2.0 4 votes vote down vote up
private boolean isClass(ArchivePath a) {
    String path = a.get();
    return path.endsWith(CLASS_SUFFIX) && !path.endsWith("module-info.class");
}
 
Example #28
Source File: AddonArchiveImpl.java    From furnace with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * @see org.jboss.shrinkwrap.impl.base.container.ContainerBase#getManifestPath()
 */
@Override
protected ArchivePath getManifestPath()
{
   return PATH_MANIFEST;
}
 
Example #29
Source File: AddonArchiveImpl.java    From furnace with Eclipse Public License 1.0 4 votes vote down vote up
protected ArchivePath getForgeXMLPath()
{
   return PATH_FORGE_XML;
}
 
Example #30
Source File: AddonArchiveImpl.java    From furnace with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * @see org.jboss.shrinkwrap.impl.base.container.ContainerBase#getClassesPath()
 */
@Override
protected ArchivePath getClassesPath()
{
   return PATH_CLASSES;
}