org.jboss.shrinkwrap.api.container.ClassContainer Java Examples

The following examples show how to use org.jboss.shrinkwrap.api.container.ClassContainer. 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: FaultToleranceApplicationArchiveProcessor.java    From smallrye-fault-tolerance with Apache License 2.0 5 votes vote down vote up
@Override
public void process(Archive<?> applicationArchive, TestClass testClass) {
    if (!(applicationArchive instanceof ClassContainer)) {
        LOGGER.warning(
                "Unable to add additional classes - not a class/resource container: "
                        + applicationArchive);
        return;
    }
    ClassContainer<?> classContainer = (ClassContainer<?>) applicationArchive;

    if (applicationArchive instanceof LibraryContainer) {
        JavaArchive additionalBeanArchive = ShrinkWrap.create(JavaArchive.class);
        additionalBeanArchive.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
        ((LibraryContainer<?>) applicationArchive).addAsLibrary(additionalBeanArchive);
    } else {
        classContainer.addAsResource(EmptyAsset.INSTANCE, "META-INF/beans.xml");
    }

    if (!applicationArchive.contains("META-INF/beans.xml")) {
        applicationArchive.add(EmptyAsset.INSTANCE, "META-INF/beans.xml");
    }

    String config;
    if (!applicationArchive.contains(MP_CONFIG_PATH)) {
        config = MAX_THREADS_OVERRIDE;
    } else {
        ByteArrayOutputStream output = readCurrentConfig(applicationArchive);
        applicationArchive.delete(MP_CONFIG_PATH);
        config = output.toString() + "\n" + MAX_THREADS_OVERRIDE;
    }
    classContainer.addAsResource(new StringAsset(config), MP_CONFIG_PATH);

    LOGGER.info("Added additional resources to " + applicationArchive.toString(true));
}
 
Example #2
Source File: RestClientProcessor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Override
public void process(Archive<?> applicationArchive, TestClass testClass) {
    // Only apply the processor to SSL tests
    if (testClass.getName().contains("SslHostnameVerifierTest") ||
            testClass.getName().contains("SslMutualTest") ||
            testClass.getName().contains("SslTrustStoreTest") ||
            testClass.getName().contains("SslContextTest")) {

        if (!(applicationArchive instanceof WebArchive)) {
            return;
        }

        WebArchive war = applicationArchive.as(WebArchive.class);
        war.addAsResource(new StringAsset("quarkus.ssl.native=true"), "application.properties");
    }

    // Make sure the test class and all of its superclasses are added to the test deployment
    // This ensures that all the classes from the hierarchy are loaded by the RuntimeClassLoader
    if (ClassContainer.class.isInstance(applicationArchive) && testClass.getJavaClass().getSuperclass() != null) {
        ClassContainer<?> classContainer = ClassContainer.class.cast(applicationArchive);
        Class<?> clazz = testClass.getJavaClass().getSuperclass();
        while (clazz != Object.class && clazz != null) {
            classContainer.addClass(clazz);
            clazz = clazz.getSuperclass();
        }

    }
}
 
Example #3
Source File: Mvn.java    From tomee with Apache License 2.0 4 votes vote down vote up
public <T extends Archive<?>> T build(final Class<T> type) {
    initDefaults();

    final T webArchive = ShrinkWrap.create(type, name);

    if (basePackage != null) {
        if (ClassContainer.class.isInstance(webArchive)) {
            final ClassContainer<?> container = ClassContainer.class.cast(webArchive);
            if (filter != null) {
                container.addPackages(true, filter, basePackage);
            } else {
                container.addPackages(true, basePackage);
            }
        }
    }

    final String root;
    if (WebContainer.class.isInstance(webArchive)) {
        root = "/WEB-INF/classes";
    } else {
        root = "/";
    }

    add(webArchive, classes, root)
    .add(webArchive, resources, root)
    .add(webArchive, webapp, "/");
    for (final Map.Entry<File, String> additionalResource : additionalResources.entrySet()) {
        add(webArchive, additionalResource.getKey(), additionalResource.getValue());
    }

    if (LibraryContainer.class.isInstance(webArchive)) {
        try {
            final File[] deps = Maven.configureResolver().workOffline().loadPomFromFile(new File(basedir, "pom.xml"))
                .importDependencies(scopes).resolve().withTransitivity().asFile();
            if (deps.length > 0) {
                LibraryContainer.class.cast(webArchive).addAsLibraries(deps);
            }
        } catch (final Exception e) {
            // no-op: no deps
        }
    }

    return webArchive;
}