org.jboss.shrinkwrap.api.Archive Java Examples

The following examples show how to use org.jboss.shrinkwrap.api.Archive. 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: FurnaceDeployableContainer.java    From furnace with Eclipse Public License 1.0 6 votes vote down vote up
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 File: ConfigurableManagerTest.java    From thorntail with 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 File: AbstractLoggingTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * 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 #4
Source File: TomEEContainer.java    From tomee with 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 File: TaskanaWildflyTest.java    From taskana with 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 #6
Source File: InVMSimpleContainer.java    From ARCHIVE-wildfly-swarm with 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 #7
Source File: ShrinkWrapUtil.java    From furnace with 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 #8
Source File: MeteredConstructorBeanTest.java    From metrics-cdi with 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 #9
Source File: ExceptionMeteredConstructorBeanTest.java    From metrics-cdi with Apache License 2.0 5 votes vote down vote up
@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 #10
Source File: WildflyDeprecatedDeploymentArchiveProcessor.java    From keycloak with Apache License 2.0 5 votes vote down vote up
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 #11
Source File: DeploymentArchiveProcessor.java    From keycloak with 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 #12
Source File: ExceptionMeteredMethodBeanTest.java    From metrics-cdi with Apache License 2.0 5 votes vote down vote up
@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 #13
Source File: WildFlySwarmDeploymentAppender.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Override
protected Archive<?> buildArchive() {
    return ShrinkWrap.create(JavaArchive.class)
            .addPackages(
                    true,
                    "org.jboss.arquillian.container.test.spi",
                    "org.wildfly.swarm.arquillian.resources")
            .addClass(WildFlySwarmRemoteExtension.class)
            .addAsServiceProvider(RemoteLoadableExtension.class, WildFlySwarmRemoteExtension.class)
            .addAsServiceProvider(ExtensionLoader.class, RemoteExtensionLoader.class);
}
 
Example #14
Source File: FurnaceAuxiliaryArchiveProcessor.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
@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 #15
Source File: DefaultDeploymentFactory.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
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 #16
Source File: JAXRSTest.java    From ARCHIVE-wildfly-swarm with 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 #17
Source File: TraceResolverOnDeploymentTest.java    From thorntail with 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 #18
Source File: JoseCompactTest.java    From thorntail with 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 #19
Source File: TimeoutTest.java    From microprofile-rest-client with 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 #20
Source File: InheritedTimedMethodBeanTest.java    From metrics-cdi with 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 #21
Source File: ConnectorTest.java    From microprofile-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #22
Source File: JoseJwsCompactDetachedTest.java    From thorntail with 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 #23
Source File: ManagedSEDeployableContainer.java    From camel-spring-boot with Apache License 2.0 5 votes vote down vote up
private Properties getSystemProperties(final Archive<?> archive) throws DeploymentException {
    Node systemPropertiesNode = archive.get(ClassPath.SYSTEM_PROPERTIES_ARCHIVE_PATH);
    if (systemPropertiesNode != null) {
        try (InputStream in = systemPropertiesNode.getAsset().openStream()) {
            Properties systemProperties = new Properties();
            systemProperties.load(in);
            return systemProperties;
        } catch (IOException e) {
            throw new DeploymentException("Could not load system properties", e);
        }
    }
    return null;
}
 
Example #24
Source File: Deployments.java    From arquillian-suite-extension with Apache License 2.0 5 votes vote down vote up
@Deployment(name = "autogenerated_web", order = 1)
@TargetsContainer("app")
public static Archive<?> generateAutogeneratedWebDeployment() {
    EnterpriseArchive ear = EarGenericBuilder.getModuleDeployment(ModuleType.WAR, "test-war-module");
    ear.delete("lib/glassfish-embedded-all-3.1.2.2.jar");
    return ear;
}
 
Example #25
Source File: TestRepositoryDeploymentListener.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void preDeploy(Furnace furnace, Archive<?> archive) throws Exception
{
   previousUserSettings = System.setProperty(MavenContainer.ALT_USER_SETTINGS_XML_LOCATION,
            getAbsolutePath("profiles/settings.xml"));
   previousLocalRepository = System.setProperty(MavenContainer.ALT_LOCAL_REPOSITORY_LOCATION,
            "target/the-other-repository");
}
 
Example #26
Source File: QuestionnairResourceInServletTest.java    From gazpachoquest with GNU General Public License v3.0 5 votes vote down vote up
@Deployment
public static Archive<?> createTestArchive() {

    String beansDescriptor = Descriptors.create(BeansDescriptor.class).exportAsString();
    return ShrinkWrap
            .create(WebArchive.class, "test.war")
            .addClasses(ResourceProducer.class, GazpachoResource.class, QuestionnaireResource.class,
                    QuestionnairResourceTestServlet.class)
            .addAsWebInfResource(new StringAsset(beansDescriptor), "beans.xml");
}
 
Example #27
Source File: CachedGaugeMethodBeanTest.java    From metrics-cdi with Apache License 2.0 5 votes vote down vote up
@Deployment
public static Archive<?> createTestArchive() {
    return ShrinkWrap.create(JavaArchive.class)
        // Test bean
        .addClass(CachedGaugeMethodBean.class)
        // Metrics CDI extension
        .addPackage(MetricsExtension.class.getPackage())
        // Bean archive deployment descriptor
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}
 
Example #28
Source File: TomeeHibernateIntegrationTest.java    From flexy-pool with Apache License 2.0 5 votes vote down vote up
@Deployment
public static Archive<?> createDeployment() {
    System.setProperty(PropertyLoader.PROPERTIES_FILE_PATH, "hibernate-connection-provider/flexy-pool-hibernate.properties");
    return ShrinkWrap.create(JavaArchive.class)
            .addPackage(Book.class.getPackage())
            .addClass(DefaultDataSourceConfiguration.class)
            .addAsManifestResource("hibernate-connection-provider/test-persistence-hibernate.xml", "persistence.xml")
            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}
 
Example #29
Source File: HandledExceptionHandlerTest.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
@Deployment(name = "HandledExceptionHandlerTest")
public static Archive<?> createTestArchive()
{
    return ShrinkWrap
            .create(WebArchive.class, "handledExceptionHandler.war")
            .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreArchive())
            .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
            .addClasses(ExceptionHandledHandler.class);
}
 
Example #30
Source File: JoseJwsCompactUnencodedTest.java    From thorntail with 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.addAllDependencies();
    deployment.addAsResource("keystore.jks", "keystore-unencoded.jks");
    deployment.addAsResource("project-jws-compact-unencoded.yml", "project-defaults.yml");
    return deployment;
}