Java Code Examples for org.jboss.shrinkwrap.api.Archive

The following examples show how to use org.jboss.shrinkwrap.api.Archive. These examples are extracted from open source projects. 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
private void deployToRepository(Archive<?> archive, MutableAddonRepository repository, final AddonId addonToDeploy)
{
   File destDir = repository.getAddonBaseDir(addonToDeploy);
   destDir.mkdirs();
   ShrinkWrapUtil.toFile(new File(destDir.getAbsolutePath(), archive.getName()), archive);
   ShrinkWrapUtil.unzip(destDir, archive);
   System.out.println("Furnace test harness is deploying [" + addonToDeploy + "] to repository [" + repository
            + "] ...");

   if (archive instanceof AddonDependencyAware)
   {
      repository.deploy(addonToDeploy,
               ((AddonDependencyAware<?>) archive).getAddonDependencies(),
               Collections.<File> emptyList());
   }
   else
   {
      repository.deploy(addonToDeploy,
               Collections.<AddonDependencyEntry> emptyList(),
               Collections.<File> emptyList());
   }

   repository.enable(addonToDeploy);
}
 
Example 2
Source Project: thorntail   Source File: ConfigurableManagerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testDeploymentConfigurableUsingAliasBackwardCompatibility() throws Exception {
    Properties props = new Properties();
    Map<String, String> env = new HashMap<>();
    ConfigViewFactory factory = new ConfigViewFactory(props, env);
    factory.withProperty("swarm.http.context", "/myapp");
    ConfigView configView = factory.get(true);
    DeploymentContext context = new DeploymentContextImpl();
    ConfigurableManager manager = new ConfigurableManager(configView, context);

    Archive archive = ShrinkWrap.create(JavaArchive.class, "myapp.war");
    try {
        context.activate(archive, archive.getName(), false);
        BackwardCompatibleComponent component = new BackwardCompatibleComponent();
        manager.scan(component);
        assertThat(component.context.get()).isEqualTo("/myapp");

    } finally {
        context.deactivate();
    }
}
 
Example 3
Source Project: taskana   Source File: TaskanaWildflyTest.java    License: Apache License 2.0 6 votes vote down vote up
@Deployment(testable = false)
public static Archive<?> createTestArchive() {

  File[] files =
      Maven.resolver()
          .loadPomFromFile("pom.xml")
          .importRuntimeDependencies()
          .resolve()
          .withTransitivity()
          .asFile();

  return ShrinkWrap.create(WebArchive.class, "taskana.war")
      .addPackages(true, "pro.taskana")
      .addAsResource("taskana.properties")
      .addAsResource("application.properties")
      .addAsResource("project-defaults.yml")
      .addAsLibraries(files);
}
 
Example 4
Source Project: tomee   Source File: TomEEContainer.java    License: Apache License 2.0 6 votes vote down vote up
protected AppInfo doDeploy(final Archive<?> archive, final File file) throws OpenEJBException, NamingException, IOException {
    AppInfo appInfo;
    final Properties deployerProperties = getDeployerProperties();
    if (deployerProperties == null) {
        appInfo = deployer().deploy(file.getAbsolutePath());
    } else {
        final Properties props = new Properties();
        props.putAll(deployerProperties);

        if ("true".equalsIgnoreCase(deployerProperties.getProperty(DeployerEjb.OPENEJB_USE_BINARIES, "false"))) {
            final byte[] slurpBinaries = IO.slurpBytes(file);
            props.put(DeployerEjb.OPENEJB_VALUE_BINARIES, slurpBinaries);
            props.put(DeployerEjb.OPENEJB_PATH_BINARIES, archive.getName());
        }

        appInfo = deployer().deploy(file.getAbsolutePath(), props);
    }
    return appInfo;
}
 
Example 5
Source Project: ARCHIVE-wildfly-swarm   Source File: InVMSimpleContainer.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void start(Archive<?> archive) throws Exception {
    archive.as(ServiceActivatorArchive.class)
            .addServiceActivator(DaemonServiceActivator.class)
            .as(JARArchive.class)
            .addModule("org.wildfly.swarm.arquillian.daemon");

    System.setProperty(BootstrapProperties.APP_ARTIFACT, archive.getName());

    if (isContainerFactory(this.testClass)) {
        archive.as(JARArchive.class)
                .addModule("org.wildfly.swarm.container")
                .addModule("org.wildfly.swarm.configuration");
        Object factory = this.testClass.newInstance();
        this.container = ((ContainerFactory) factory).newContainer();
    } else {
        this.container = new Container();
    }
    this.container.start().deploy(archive);
}
 
Example 6
Source Project: furnace   Source File: ShrinkWrapUtil.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates a tmp folder and exports the file. Returns the URL for that file location.
 * 
 * @param archive Archive to export
 * @return
 */
public static URL toURL(final Archive<?> archive)
{
   // create a random named temp file, then delete and use it as a directory
   try
   {
      File root = File.createTempFile("arquillian", archive.getName());
      root.delete();
      root.mkdirs();

      File deployment = new File(root, archive.getName());
      deployment.deleteOnExit();
      archive.as(ZipExporter.class).exportTo(deployment, true);
      return deployment.toURI().toURL();
   }
   catch (Exception e)
   {
      throw new RuntimeException("Could not export deployment to temp", e);
   }
}
 
Example 7
/**
 * Deploys the archive to the running server.
 *
 * @param archive     the archive to deploy
 * @param runtimeName the runtime name for the deployment
 *
 * @throws IOException if an error occurs deploying the archive
 */
public static void deploy(final Archive<?> archive, final String runtimeName) throws IOException {
    // Use an operation to allow overriding the runtime name
    final ModelNode address = Operations.createAddress(DEPLOYMENT, archive.getName());
    final ModelNode addOp = createAddOperation(address);
    if (runtimeName != null && !archive.getName().equals(runtimeName)) {
        addOp.get(RUNTIME_NAME).set(runtimeName);
    }
    addOp.get("enabled").set(true);
    // Create the content for the add operation
    final ModelNode contentNode = addOp.get(CONTENT);
    final ModelNode contentItem = contentNode.get(0);
    contentItem.get(ClientConstants.INPUT_STREAM_INDEX).set(0);

    // Create an operation and add the input archive
    final OperationBuilder builder = OperationBuilder.create(addOp);
    builder.addInputStream(archive.as(ZipExporter.class).exportAsInputStream());

    // Deploy the content and check the results
    final ModelNode result = client.getControllerClient().execute(builder.build());
    if (!Operations.isSuccessfulOutcome(result)) {
        Assert.fail(String.format("Failed to deploy %s: %s", archive, Operations.getFailureDescription(result).asString()));
    }
}
 
Example 8
Source Project: tomee   Source File: PreloadableWar.java    License: Apache License 2.0 5 votes vote down vote up
public static Archive<?> war() {
    try {
        return war.get();
    } catch (final Exception e) {
        throw new IllegalStateException(e);
    }
}
 
Example 9
Source Project: thorntail   Source File: JoseJwsCompactDetachedTest.java    License: Apache License 2.0 5 votes vote down vote up
@Deployment
public static Archive<?> createDeployment() throws Exception {
    JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class);
    deployment.addResource(MyResource.class);
    deployment.addResource(SecuredApplication.class);
    deployment.addResource(Jose4jJoseFactory.class);
    deployment.addResource(Jose4jJoseImpl.class);  
    deployment.addAllDependencies();
    deployment.addAsResource("jwk.keys");
    deployment.addAsResource("project-jws-compact-detached.yml", "project-defaults.yml");
    deployment.addAsServiceProvider(JoseFactory.class, Jose4jJoseFactory.class);
    return deployment;
}
 
Example 10
Source Project: keycloak   Source File: UndertowDeployerHelper.java    License: 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 11
@Deployment
public static Archive<?> createTestArchive() {
    return ShrinkWrap.create(WebArchive.class)
            .addPackage(SeatType.class.getPackage())
            .addPackage(TicketService.class.getPackage())
            .addPackage(LoggerProducer.class.getPackage())
            .addAsResource("META-INF/persistence.xml")
            .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
}
 
Example 12
/**
 * Dodaje główny moduł do archiwum EAR.
 *
 * @param ear archiwum EAR
 * @param type typ głównego modułu
 * @param module główny moduł
 * @param descriptorBuilder deskreptor builder dla EAR'a
 */
private static void addMainModule(EnterpriseArchive ear, ModuleType type, Archive<?> module, EarDescriptorBuilder descriptorBuilder) {
    if (type.isModule()) {
        ear.addAsModule(module);
        if (type == ModuleType.EJB) {
            descriptorBuilder.addEjb(module.getName());
        }
        if (type == ModuleType.WAR) {
            descriptorBuilder.addWeb(module.getName());
        }
    } else {
        ear.addAsLibrary(module);
    }
}
 
Example 13
Source Project: ARCHIVE-wildfly-swarm   Source File: JAXRSTest.java    License: Apache License 2.0 5 votes vote down vote up
@Deployment
public static Archive createDeployment() throws Exception {
    JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class);
    deployment.addResource(MyResource.class);
    deployment.addAllDependencies();
    deployment.staticContent();
    return deployment;
}
 
Example 14
Source Project: thorntail   Source File: JoseCompactTest.java    License: Apache License 2.0 5 votes vote down vote up
@Deployment
public static Archive<?> createDeployment() throws Exception {
    JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class);
    deployment.addResource(MyResource.class);
    deployment.addResource(SecuredApplication.class);
    deployment.addResource(JoseExceptionMapper.class);
    deployment.addResource(Jose4jJoseFactory.class);
    deployment.addResource(Jose4jJoseImpl.class);  
    deployment.addAllDependencies();
    deployment.addAsResource("keystore.jks");
    deployment.addAsResource("project-jose-compact.yml", "project-defaults.yml");
    deployment.addAsServiceProvider(JoseFactory.class, Jose4jJoseFactory.class);
    return deployment;
}
 
Example 15
Source Project: thorntail   Source File: TraceResolverOnDeploymentTest.java    License: Apache License 2.0 5 votes vote down vote up
@Deployment
public static Archive createDeployment() throws Exception {
    WARArchive deployment = ShrinkWrap.create(WARArchive.class);

    // on real world deployments, these parts would come from a dependency of the target application
    deployment.addClass(MockTracerResolver.class);
    deployment.addPackage(MockTracer.class.getPackage());
    deployment.addAsServiceProvider(TracerResolver.class, MockTracerResolver.class);

    // this is a simple servlet, that we can hit with our tests
    deployment.addClass(SimpleServlet.class);
    deployment.addClass(AsyncServlet.class);

    return deployment;
}
 
Example 16
Source Project: metrics-cdi   Source File: InheritedGaugeMethodBeanTest.java    License: Apache License 2.0 5 votes vote down vote up
@Deployment
public static Archive<?> createTestArchive() {
    return ShrinkWrap.create(JavaArchive.class)
        // Test beans
        .addClass(GaugeMethodBean.class)
        .addClass(InheritedGaugeMethodBean.class)
        // Metrics CDI extension
        .addPackage(MetricsExtension.class.getPackage())
        // Bean archive deployment descriptor
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}
 
Example 17
Source Project: microprofile-config   Source File: CDIPlainInjectionTest.java    License: Apache License 2.0 5 votes vote down vote up
@Deployment
public static Archive deployment() {
    return ShrinkWrap.create(WebArchive.class)
            .addClasses(CDIPlainInjectionTest.class, SimpleValuesBean.class, DynamicValuesBean.class,
                    AdditionalMatchers.class, TestConfigSource.class, DefaultPropertyBean.class)
            .addAsServiceProvider(ConfigSource.class, TestConfigSource.class)
            .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
}
 
Example 18
Source Project: thorntail   Source File: WildFlySwarmContainer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public synchronized ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException {
    BootstrapUtil.convertSwarmSystemPropertiesToThorntail();

    StartupTimeout startupTimeout = this.testClass.getAnnotation(StartupTimeout.class);
    if (startupTimeout != null) {
        setTimeout(startupTimeout.value());
    }

    this.delegateContainer = new UberjarSimpleContainer(this.containerContext.get(), this.deploymentContext.get(), this.testClass);

    try {
        this.delegateContainer
                .setJavaVmArguments(this.getJavaVmArguments())
                .requestedMavenArtifacts(this.requestedMavenArtifacts)
                .start(archive);
        // start wants to connect to the remote container, which isn't up until now, so
        // we override start above and call it here instead
        super.start();

        ProtocolMetaData metaData = new ProtocolMetaData();
        metaData.addContext(createDeploymentContext(archive.getId()));

        return metaData;
    } catch (Throwable e) {
        if (e instanceof LifecycleException) {
            e = e.getCause();
        }
        throw new DeploymentException(e.getMessage(), e);
    }
}
 
Example 19
public static void deploy(Archive archive, ContainerInfo containerInfo) throws CommandFailedException, IOException {
    ManagementClient.online(OnlineOptions
            .standalone()
            .hostAndPort("localhost", containerInfo.getContextRoot().getPort() + 1547)
            .build())
            .apply(new Deploy.Builder(
                    archive.as(ZipExporter.class).exportAsInputStream(),
                    archive.getName(),
                    true).build());
}
 
Example 20
@Deployment
static Archive<?> createTestArchive() {
    return ShrinkWrap.create(WebArchive.class)
        // Test bean
        .addClass(TimedConstructorBean.class)
        // Bean archive deployment descriptor
        .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
}
 
Example 21
protected boolean setupUsingAppArtifact(Archive<?> archive) throws IOException {
    final String appArtifact = System.getProperty(BootstrapProperties.APP_ARTIFACT);

    if (appArtifact != null) {
        try (InputStream in = ClassLoader.getSystemClassLoader().getResourceAsStream("_bootstrap/" + appArtifact)) {
            archive.as(ZipImporter.class)
                    .importFrom(in);
        }
        return true;
    }

    return false;
}
 
Example 22
@Override
public void process(Archive<?> archive)
{
   if ("arquillian-core.jar".equals(archive.getName()))
   {
      Node node = archive.get("org/jboss/shrinkwrap/descriptor");
      if (node != null)
         archive.delete(node.getPath());
   }
}
 
Example 23
Source Project: metrics-cdi   Source File: MeteredConstructorBeanTest.java    License: Apache License 2.0 5 votes vote down vote up
@Deployment
static Archive<?> createTestArchive() {
    return ShrinkWrap.create(JavaArchive.class)
        // Test bean
        .addClass(MeteredConstructorBean.class)
        // Metrics CDI extension
        .addPackage(MetricsExtension.class.getPackage())
        // Bean archive deployment descriptor
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}
 
Example 24
@Deployment
public static Archive<?> createTestArchive() {
    return ShrinkWrap.create(JavaArchive.class)
        // Test bean
        .addClass(ExceptionMeteredMethodBean.class)
        // Metrics CDI extension
        .addPackage(MetricsExtension.class.getPackage())
        // Bean archive deployment descriptor
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}
 
Example 25
Source Project: keycloak   Source File: DeploymentArchiveProcessor.java    License: Apache License 2.0 5 votes vote down vote up
protected void modifyAdapterConfigs(Archive<?> archive, TestClass testClass) {
    boolean relative = isRelative();
    modifyAdapterConfig(archive, ADAPTER_CONFIG_PATH, relative);
    modifyAdapterConfig(archive, ADAPTER_CONFIG_PATH_TENANT1, relative);
    modifyAdapterConfig(archive, ADAPTER_CONFIG_PATH_TENANT2, relative);
    modifyAdapterConfig(archive, ADAPTER_CONFIG_PATH_JS, relative);
    modifyAdapterConfig(archive, SAML_ADAPTER_CONFIG_PATH, relative);
    modifyAdapterConfig(archive, SAML_ADAPTER_CONFIG_PATH_TENANT1, relative);
    modifyAdapterConfig(archive, SAML_ADAPTER_CONFIG_PATH_TENANT2, relative);
}
 
Example 26
private void modifyWebXML(Archive<?> archive, TestClass testClass) {
    if (!archive.contains(DeploymentArchiveProcessorUtils.WEBXML_PATH)) return;
    if (!testClass.getJavaClass().isAnnotationPresent(UseServletFilter.class)) return;
    if (!archive.contains(DeploymentArchiveProcessorUtils.JBOSS_DEPLOYMENT_XML_PATH)) return;
    
    log.debug("Modifying WEB.XML in " + archive.getName() + " for Servlet Filter.");
    DeploymentArchiveProcessorUtils.modifyWebXMLForServletFilter(archive, testClass);
    DeploymentArchiveProcessorUtils.addFilterDependencies(archive, testClass);
}
 
Example 27
@Deployment
static Archive<?> createTestArchive() {
    return ShrinkWrap.create(JavaArchive.class)
        // Test bean
        .addClass(ExceptionMeteredConstructorBean.class)
        // Metrics CDI extension
        .addPackage(MetricsExtension.class.getPackage())
        // Bean archive deployment descriptor
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}
 
Example 28
Source Project: microprofile-rest-client   Source File: TimeoutTest.java    License: Apache License 2.0 5 votes vote down vote up
@Deployment
public static Archive<?> createDeployment() {
    String simpleName = TimeoutTest.class.getSimpleName();
    return ShrinkWrap.create(WebArchive.class, simpleName + ".war")
                     .addClasses(WiremockArquillianTest.class,
                                 TimeoutTestBase.class,
                                 SimpleGetApi.class);
}
 
Example 29
Source Project: metrics-cdi   Source File: InheritedTimedMethodBeanTest.java    License: Apache License 2.0 5 votes vote down vote up
@Deployment
static Archive<?> createTestArchive() {
    return ShrinkWrap.create(JavaArchive.class)
        // Test bean
        .addClass(VisibilityTimedMethodBean.class)
        .addClass(InheritedTimedMethodBean.class)
        // Metrics CDI extension
        .addPackage(MetricsExtension.class.getPackage())
        // Bean archive deployment descriptor
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}
 
Example 30
@Deployment
public static Archive<JavaArchive> deployment() {
    JavaArchive archive = ShrinkWrap.create(JavaArchive.class)
        .addClasses(DummyConnector.class, MyProcessor.class, ArchiveExtender.class)
        .addAsManifestResource(MissingConnectorTest.class.getResource("connector-config.properties"), "microprofile-config.properties")
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");

    ServiceLoader.load(ArchiveExtender.class).iterator().forEachRemaining(ext -> ext.extend(archive));
    return archive;
}