Search in sources :

Example 51 with ArchivePath

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

the class SwaggerArchivePreparer method process.

@Override
public void process() {
    if (this.deploymentContext != null && this.deploymentContext.isImplicit()) {
        return;
    }
    if (archive.getName().endsWith(".war")) {
        // Create a JAX-RS deployment archive
        WARArchive deployment = archive.as(WARArchive.class);
        deployment.addModule("io.swagger");
        // Make the deployment a swagger archive
        SwaggerArchive swaggerArchive = deployment.as(SwaggerArchive.class);
        // SWARM-1667: Add the custom CDI extension to the deployment to provide a workaround solution.
        deployment.addModule("org.wildfly.swarm.swagger", "deployment");
        deployment.addAsServiceProvider(Extension.class.getName(), "org.wildfly.swarm.swagger.deployment.SwaggerExtension");
        if (this.title != null) {
            swaggerArchive.setTitle(this.title);
        }
        if (this.description != null) {
            swaggerArchive.setDescription(this.description);
        }
        if (this.packages != null && !this.packages.isEmpty()) {
            swaggerArchive.setResourcePackages(this.packages.toArray(new String[this.packages.size()]));
        }
        if (this.tosUrl != null) {
            swaggerArchive.setTermsOfServiceUrl(this.tosUrl);
        }
        if (this.license != null) {
            swaggerArchive.setLicense(this.license);
        }
        if (this.licenseUrl != null) {
            swaggerArchive.setLicenseUrl(this.licenseUrl);
        }
        if (this.version != null) {
            swaggerArchive.setVersion(this.version);
        }
        if (this.schemes != null && !this.schemes.isEmpty()) {
            swaggerArchive.setSchemes(this.schemes.toArray(new String[this.schemes.size()]));
        }
        if (this.host != null) {
            swaggerArchive.setHost(this.host);
        }
        // get the context root from the deployment and tell swagger about it
        if (this.root != null) {
            swaggerArchive.setContextRoot(this.root);
        } else {
            if (!swaggerArchive.hasContextRoot()) {
                if (deployment.getContextRoot() != null) {
                    swaggerArchive.setContextRoot(deployment.getContextRoot());
                } else {
                    swaggerArchive.setContextRoot(contextPath.get());
                }
            }
        }
        // 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")) {
                        SwaggerMessages.MESSAGES.ignoringPackage(parentPackage);
                    } else {
                        packageName = parentPackage;
                        break;
                    }
                }
            }
            if (packageName == null) {
                SwaggerMessages.MESSAGES.noEligiblePackages(archive.getName());
            } else {
                SwaggerMessages.MESSAGES.configureSwaggerForPackage(archive.getName(), packageName);
                swaggerArchive.setResourcePackages(packageName);
            }
        } else {
            SwaggerMessages.MESSAGES.configureSwaggerForSeveralPackages(archive.getName(), Arrays.asList(swaggerArchive.getResourcePackages()));
        }
        // Now add the swagger resources to our deployment
        deployment.addClass(io.swagger.jaxrs.listing.ApiListingResource.class);
        deployment.addClass(io.swagger.jaxrs.listing.SwaggerSerializers.class);
    }
}
Also used : Extension(javax.enterprise.inject.spi.Extension) ArchivePath(org.jboss.shrinkwrap.api.ArchivePath) Node(org.jboss.shrinkwrap.api.Node) WARArchive(org.wildfly.swarm.undertow.WARArchive) Map(java.util.Map) SwaggerArchive(org.wildfly.swarm.swagger.SwaggerArchive)

Example 52 with ArchivePath

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

the class Swarm method initializeConfigFiltersClassPath.

private void initializeConfigFiltersClassPath() throws IOException, ClassNotFoundException {
    String classpath = System.getProperty("java.class.path");
    String[] locations = classpath.split(System.getProperty("path.separator"));
    Indexer indexer = new Indexer();
    for (String location : locations) {
        File file = new File(location);
        JavaArchive archive = null;
        if (file.exists()) {
            if (file.isDirectory()) {
                archive = ShrinkWrap.create(ExplodedImporter.class).importDirectory(file).as(JavaArchive.class);
            } else {
                archive = ShrinkWrap.create(ZipImporter.class).importFrom(file).as(JavaArchive.class);
            }
            Map<ArchivePath, Node> content = archive.getContent();
            for (ArchivePath path : content.keySet()) {
                if (path.get().endsWith(".class") && !path.get().endsWith("module-info.class")) {
                    Node node = content.get(path);
                    try {
                        indexer.index(node.getAsset().openStream());
                    } catch (IOException e) {
                    // ignore
                    }
                }
            }
        }
    }
    Index index = indexer.complete();
    Set<ClassInfo> impls = index.getAllKnownImplementors(DotName.createSimple(ConfigurationFilter.class.getName()));
    for (ClassInfo each : impls) {
        String name = each.name().toString();
        Class<? extends ConfigurationFilter> cls = (Class<? extends ConfigurationFilter>) Class.forName(name);
        try {
            ConfigurationFilter filter = cls.newInstance();
            this.configView.withFilter(filter);
        } catch (InstantiationException | IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}
Also used : ConfigurationFilter(org.wildfly.swarm.spi.api.ConfigurationFilter) Node(org.jboss.shrinkwrap.api.Node) Index(org.jboss.jandex.Index) IOException(java.io.IOException) ExplodedImporter(org.jboss.shrinkwrap.api.importer.ExplodedImporter) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) ArchivePath(org.jboss.shrinkwrap.api.ArchivePath) Indexer(org.jboss.jandex.Indexer) ZipImporter(org.jboss.shrinkwrap.api.importer.ZipImporter) JarFile(java.util.jar.JarFile) File(java.io.File) ClassInfo(org.jboss.jandex.ClassInfo)

Example 53 with ArchivePath

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

the class JBWS3516TestCase method createDeployment.

@Deployment(testable = false)
public static WebArchive createDeployment() {
    WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxws-cxf-jbws3516.war");
    archive.setManifest(new StringAsset("Manifest-Version: 1.0\n" + "Dependencies: org.apache.cxf.impl\n")).addPackages(false, new Filter<ArchivePath>() {

        @Override
        public boolean include(ArchivePath object) {
            return !object.get().contains("TestCase");
        }
    }, "org.jboss.test.ws.jaxws.cxf.jbws3516").addAsWebInfResource(new File(JBossWSTestHelper.getTestResourcesDir() + "/jaxws/cxf/jbws3516/WEB-INF/wsdl/hello_world.wsdl"), "wsdl/hello_world.wsdl").setWebXML(new File(JBossWSTestHelper.getTestResourcesDir() + "/jaxws/cxf/jbws3516/WEB-INF/web.xml"));
    return archive;
}
Also used : ArchivePath(org.jboss.shrinkwrap.api.ArchivePath) StringAsset(org.jboss.shrinkwrap.api.asset.StringAsset) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) File(java.io.File) Deployment(org.jboss.arquillian.container.test.api.Deployment)

Example 54 with ArchivePath

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

the class JBWS2278TestCase method createDeployments.

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

        @Override
        public boolean include(ArchivePath path) {
            return !path.get().contains("TestCase");
        }
    }, "org.jboss.test.ws.jaxws.jbws2278").addAsWebInfResource(new File(JBossWSTestHelper.getTestResourcesDir() + "/jaxws/jbws2278/WEB-INF/jboss-web.xml"), "jboss-web.xml").addAsWebInfResource(new File(JBossWSTestHelper.getTestResourcesDir() + "/jaxws/jbws2278/WEB-INF/wsdl/Test.wsdl"), "wsdl/Test.wsdl").setWebXML(new File(JBossWSTestHelper.getTestResourcesDir() + "/jaxws/jbws2278/WEB-INF/web.xml"));
    return archive;
}
Also used : ArchivePath(org.jboss.shrinkwrap.api.ArchivePath) Filter(org.jboss.shrinkwrap.api.Filter) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) File(java.io.File) Deployment(org.jboss.arquillian.container.test.api.Deployment)

Example 55 with ArchivePath

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

the class ComplexTestCase method createDeployments.

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

        @Override
        public boolean include(ArchivePath path) {
            return !path.get().contains("TestCase");
        }
    }, "org.jboss.test.ws.jaxws.complex").setWebXML(new File(JBossWSTestHelper.getTestResourcesDir() + "/jaxws/complex/WEB-INF/web.xml"));
    return archive;
}
Also used : ArchivePath(org.jboss.shrinkwrap.api.ArchivePath) Filter(org.jboss.shrinkwrap.api.Filter) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) File(java.io.File) Deployment(org.jboss.arquillian.container.test.api.Deployment)

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