Search in sources :

Example 56 with ArchivePath

use of org.jboss.shrinkwrap.api.ArchivePath in project jbossws-cxf by jbossws.

the class DateTestCase method createDeployments.

@Deployment(testable = false)
public static WebArchive createDeployments() {
    WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxws-date.war");
    archive.addManifest().addPackages(false, new Filter<ArchivePath>() {

        @Override
        public boolean include(ArchivePath path) {
            return !path.get().contains("TestCase");
        }
    }, "org.jboss.test.ws.jaxws.date");
    return archive;
}
Also used : ArchivePath(org.jboss.shrinkwrap.api.ArchivePath) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) Deployment(org.jboss.arquillian.container.test.api.Deployment)

Example 57 with ArchivePath

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

the class ScannerTests method buildLargeJar.

protected File buildLargeJar() throws Exception {
    final String fileName = "large.jar";
    final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, fileName);
    // Build a large jar by adding a lorem ipsum file repeatedly.
    final Path loremipsumTxtFile = Paths.get(ScannerTests.class.getResource("/org/hibernate/jpa/test/packaging/loremipsum.txt").toURI());
    for (int i = 0; i < 100; i++) {
        ArchivePath path = ArchivePaths.create("META-INF/file" + i);
        archive.addAsResource(loremipsumTxtFile.toFile(), path);
    }
    File testPackage = new File(shrinkwrapArchiveDirectory, fileName);
    archive.as(ZipExporter.class).exportTo(testPackage, true);
    return testPackage;
}
Also used : ArchivePath(org.jboss.shrinkwrap.api.ArchivePath) Path(java.nio.file.Path) ArchivePath(org.jboss.shrinkwrap.api.ArchivePath) ZipExporter(org.jboss.shrinkwrap.api.exporter.ZipExporter) File(java.io.File) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive)

Example 58 with ArchivePath

use of org.jboss.shrinkwrap.api.ArchivePath in project tomee by apache.

the class OpenEJBArchiveProcessor method finderArchive.

private static org.apache.xbean.finder.archive.Archive finderArchive(final Node beansXml, final Archive<?> archive, final ClassLoader cl, final CompositeArchive libs, final Map<URL, List<String>> webAppClassesByUrl, final CompositeBeans compositeBeans) {
    final List<Class<?>> classes = new ArrayList<>();
    final Map<ArchivePath, Node> content = archive.getContent(new IncludeRegExpPaths(".*.class"));
    for (final Map.Entry<ArchivePath, Node> node : content.entrySet()) {
        final String classname = name(node.getKey().get());
        try {
            classes.add(cl.loadClass(classname));
        } catch (final ClassNotFoundException e) {
            LOGGER.fine("Can't load class " + classname);
            if (LOGGER.isLoggable(Level.FINEST)) {
                e.printStackTrace(System.err);
            }
        } catch (final NoClassDefFoundError ncdfe) {
        // no-op
        }
    }
    final List<org.apache.xbean.finder.archive.Archive> archives = new ArrayList<>();
    archives.add(new ClassesArchive(classes));
    if (beansXml != null) {
        try {
            // no host avoid host resolution in hashcode()
            final URL key = new URL("jar:file://!/WEB-INF/beans.xml");
            try {
                DeploymentLoader.doMerge(key, compositeBeans, ReadDescriptors.readBeans(beansXml.getAsset().openStream()));
            } catch (final OpenEJBException e) {
                throw new IllegalArgumentException(e);
            }
            final List<String> mainClasses = new ArrayList<>();
            for (final Class<?> clazz : classes) {
                mainClasses.add(clazz.getName());
            }
            webAppClassesByUrl.put(key, mainClasses);
        } catch (final MalformedURLException mue) {
        // no-op
        }
    }
    if (libs != null) {
        archives.add(libs);
    }
    return new SimpleWebappAggregatedArchive(cl, new CompositeArchive(archives), webAppClassesByUrl);
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) MalformedURLException(java.net.MalformedURLException) FilteredArchive(org.apache.xbean.finder.archive.FilteredArchive) ClassesArchive(org.apache.xbean.finder.archive.ClassesArchive) EnterpriseArchive(org.jboss.shrinkwrap.api.spec.EnterpriseArchive) WebappAggregatedArchive(org.apache.openejb.config.WebappAggregatedArchive) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) JarArchive(org.apache.xbean.finder.archive.JarArchive) Archive(org.jboss.shrinkwrap.api.Archive) CompositeArchive(org.apache.xbean.finder.archive.CompositeArchive) Node(org.jboss.shrinkwrap.api.Node) ArrayList(java.util.ArrayList) URL(java.net.URL) ArchivePath(org.jboss.shrinkwrap.api.ArchivePath) IncludeRegExpPaths(org.jboss.shrinkwrap.impl.base.filter.IncludeRegExpPaths) CompositeArchive(org.apache.xbean.finder.archive.CompositeArchive) ClassesArchive(org.apache.xbean.finder.archive.ClassesArchive) TestClass(org.jboss.arquillian.test.spi.TestClass) Map(java.util.Map) HashMap(java.util.HashMap)

Example 59 with ArchivePath

use of org.jboss.shrinkwrap.api.ArchivePath in project tomee by apache.

the class OpenEJBArchiveProcessor method analyzeLibs.

private static CompositeArchive analyzeLibs(final ClassLoader parent, final List<URL> additionalPaths, final Map<URL, List<String>> earMap, final List<Archive> earLibsArchives, final CompositeBeans earBeans, final Map<ArchivePath, Node> jars, final Map<String, Object> altDD) {
    final List<org.apache.xbean.finder.archive.Archive> archives = new ArrayList<>(jars.size());
    for (final Map.Entry<ArchivePath, Node> node : jars.entrySet()) {
        final Asset asset = node.getValue().getAsset();
        if (ArchiveAsset.class.isInstance(asset)) {
            final Archive<?> libArchive = ArchiveAsset.class.cast(asset).getArchive();
            if (!isExcluded(libArchive.getName())) {
                earLibsArchives.add(libArchive);
                final List<Class<?>> earClasses = new ArrayList<>();
                final List<String> earClassNames = new ArrayList<>();
                final Map<ArchivePath, Node> content = libArchive.getContent(new IncludeRegExpPaths(".*.class"));
                for (final Map.Entry<ArchivePath, Node> classNode : content.entrySet()) {
                    final String classname = name(classNode.getKey().get());
                    try {
                        earClasses.add(parent.loadClass(classname));
                        earClassNames.add(classname);
                    } catch (final ClassNotFoundException e) {
                        LOGGER.fine("Can't load class " + classname);
                    } catch (final NoClassDefFoundError ncdfe) {
                    // no-op
                    }
                }
                try {
                    // ends with !/META-INF/beans.xml to force it to be used as a cdi module *with bda*
                    final Node beansNode = libArchive.get(META_INF + BEANS_XML);
                    final URL arUrl = new URL("jar:file://!/lib/" + libArchive.getName() + (beansNode != null ? "!/META-INF/beans.xml" : ""));
                    if (beansNode != null) {
                        try {
                            DeploymentLoader.doMerge(arUrl, earBeans, ReadDescriptors.readBeans(beansNode.getAsset().openStream()));
                        } catch (final OpenEJBException e) {
                            throw new IllegalArgumentException(e);
                        }
                    }
                    earMap.put(arUrl, earClassNames);
                } catch (final MalformedURLException e) {
                // no-op
                }
                archives.add(new ClassesArchive(earClasses));
            }
            final Node ejbJarXml = libArchive.get(META_INF + EJB_JAR_XML);
            if (ejbJarXml != null) {
                // not super, we should merge them surely but ok for use cases we met until today
                altDD.put("ejb-jar.xml", new AssetSource(ejbJarXml.getAsset(), null));
            }
        }
        if (UrlAsset.class.isInstance(asset) || FileAsset.class.isInstance(asset)) {
            try {
                final URL url = UrlAsset.class.isInstance(asset) ? get(URL.class, "url", asset) : get(File.class, "file", asset).toURI().toURL();
                final List<String> classes = new ArrayList<String>();
                archives.add(new FilteredArchive(new JarArchive(parent, url), new WebappAggregatedArchive.ScanXmlSaverFilter(false, null, classes, null)));
                additionalPaths.add(url);
                final URLClassLoader loader = new URLClassLoader(new URL[] { url }, EMPTY_LOADER);
                for (final String beans : asList("META-INF/beans.xml", "/META-INF/beans.xml")) {
                    final URL u = loader.getResource(beans);
                    if (u != null) {
                        try {
                            DeploymentLoader.doMerge(u, earBeans, ReadDescriptors.readBeans(u.openStream()));
                        } catch (final OpenEJBException e) {
                            throw new IllegalArgumentException(e);
                        } catch (final IOException e) {
                        // no-op
                        }
                        earMap.put(u, classes);
                    }
                }
                try {
                    loader.close();
                } catch (final IOException e) {
                // no-op
                }
            } catch (final MalformedURLException e) {
                throw new IllegalArgumentException(e);
            }
        }
    }
    return new CompositeArchive(archives);
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) MalformedURLException(java.net.MalformedURLException) FilteredArchive(org.apache.xbean.finder.archive.FilteredArchive) ClassesArchive(org.apache.xbean.finder.archive.ClassesArchive) EnterpriseArchive(org.jboss.shrinkwrap.api.spec.EnterpriseArchive) WebappAggregatedArchive(org.apache.openejb.config.WebappAggregatedArchive) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) JarArchive(org.apache.xbean.finder.archive.JarArchive) Archive(org.jboss.shrinkwrap.api.Archive) CompositeArchive(org.apache.xbean.finder.archive.CompositeArchive) Node(org.jboss.shrinkwrap.api.Node) ArrayList(java.util.ArrayList) FilteredArchive(org.apache.xbean.finder.archive.FilteredArchive) URL(java.net.URL) ArchivePath(org.jboss.shrinkwrap.api.ArchivePath) JarArchive(org.apache.xbean.finder.archive.JarArchive) Asset(org.jboss.shrinkwrap.api.asset.Asset) FileAsset(org.jboss.shrinkwrap.api.asset.FileAsset) ClassLoaderAsset(org.jboss.shrinkwrap.api.asset.ClassLoaderAsset) ArchiveAsset(org.jboss.shrinkwrap.api.asset.ArchiveAsset) UrlAsset(org.jboss.shrinkwrap.api.asset.UrlAsset) IncludeRegExpPaths(org.jboss.shrinkwrap.impl.base.filter.IncludeRegExpPaths) FileAsset(org.jboss.shrinkwrap.api.asset.FileAsset) ArchiveAsset(org.jboss.shrinkwrap.api.asset.ArchiveAsset) IOException(java.io.IOException) CompositeArchive(org.apache.xbean.finder.archive.CompositeArchive) URLClassLoader(java.net.URLClassLoader) ClassesArchive(org.apache.xbean.finder.archive.ClassesArchive) TestClass(org.jboss.arquillian.test.spi.TestClass) Map(java.util.Map) HashMap(java.util.HashMap) File(java.io.File) UrlAsset(org.jboss.shrinkwrap.api.asset.UrlAsset)

Example 60 with ArchivePath

use of org.jboss.shrinkwrap.api.ArchivePath in project tomee by apache.

the class MicroProfileOpenTracingTCKDeploymentPackager method generateDeployment.

@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);
}
Also used : ArchivePath(org.jboss.shrinkwrap.api.ArchivePath) ThreadLocalScopeManager(io.opentracing.util.ThreadLocalScopeManager) TestDeployment(org.jboss.arquillian.container.test.spi.TestDeployment) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) Node(org.jboss.shrinkwrap.api.Node) MockTracer(io.opentracing.mock.MockTracer)

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