[jboss-cvs] JBossAS SVN: r104032 - in projects/reloaded/trunk/vdf-bootstrap-minimal: src/main/java/org/jboss/reloaded and 7 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Apr 15 21:50:38 EDT 2010
Author: ALRubinger
Date: 2010-04-15 21:50:37 -0400 (Thu, 15 Apr 2010)
New Revision: 104032
Added:
projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/java/org/jboss/reloaded/api/ReloadedShrinkWrapDeployerDescriptors.java
projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/java/org/jboss/reloaded/shrinkwrap/
projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/java/org/jboss/reloaded/shrinkwrap/api/
projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/java/org/jboss/reloaded/shrinkwrap/api/ShrinkWrapDeployer.java
projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/java/org/jboss/reloaded/shrinkwrap/api/ShrinkWrapReloadedDescriptors.java
projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/java/org/jboss/reloaded/shrinkwrap/impl/
projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/java/org/jboss/reloaded/shrinkwrap/impl/ArchiveDeployment.java
projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/java/org/jboss/reloaded/shrinkwrap/impl/ShrinkWrapDeployerImpl.java
projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/resources/org.jboss.reloaded_ShrinkWrapDeployer.xml
projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/resources/org.jboss.reloaded_TempFileProvider.xml
projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/org/jboss/reloaded/api/CachingDeployer.java
projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/org/jboss/reloaded/api/LifecyclePojo.java
projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/org/jboss/reloaded/api/ReloadedMCServerTestBase.java
projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/org/jboss/reloaded/api/ShrinkWrapDeployerUnitTest.java
Modified:
projects/reloaded/trunk/vdf-bootstrap-minimal/pom.xml
projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/org/jboss/reloaded/api/MainDeployerViaBootstrapUnitTest.java
projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/resources/log4j.xml
Log:
[RELOADED-14] Provide a ShrinkWrapDeployer wrapper over MainDeployer
Modified: projects/reloaded/trunk/vdf-bootstrap-minimal/pom.xml
===================================================================
--- projects/reloaded/trunk/vdf-bootstrap-minimal/pom.xml 2010-04-16 01:33:11 UTC (rev 104031)
+++ projects/reloaded/trunk/vdf-bootstrap-minimal/pom.xml 2010-04-16 01:50:37 UTC (rev 104032)
@@ -25,7 +25,8 @@
<version.org.jboss_jbossxb>2.0.2.Beta2</version.org.jboss_jbossxb>
<version.org.jboss_jboss.common.core>2.2.17.GA</version.org.jboss_jboss.common.core>
<version.junit_junit>4.7</version.junit_junit>
- <version.org.jboss.shrinkwrap>1.0.0-alpha-6</version.org.jboss.shrinkwrap>
+ <version.org.jboss.shrinkwrap>1.0.0-alpha-7</version.org.jboss.shrinkwrap>
+ <version.org.jboss.threads>2.0.0.CR4</version.org.jboss.threads>
</properties>
<!-- SCM -->
@@ -167,6 +168,25 @@
<artifactId>jboss-common-core</artifactId>
<version>${version.org.jboss_jboss.common.core}</version>
</dependency>
+
+ <!-- org.jboss.shrinkwrap -->
+ <dependency>
+ <groupId>org.jboss.shrinkwrap</groupId>
+ <artifactId>shrinkwrap-api</artifactId>
+ <version>${version.org.jboss.shrinkwrap}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.shrinkwrap</groupId>
+ <artifactId>shrinkwrap-impl-base</artifactId>
+ <version>${version.org.jboss.shrinkwrap}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.shrinkwrap</groupId>
+ <artifactId>shrinkwrap-extension-vfs3</artifactId>
+ <version>${version.org.jboss.shrinkwrap}</version>
+ <scope>provided</scope>
+ </dependency>
<!-- Test Dependencies -->
<dependency>
@@ -175,10 +195,11 @@
<version>${version.junit_junit}</version>
<scope>test</scope>
</dependency>
+
<dependency>
- <groupId>org.jboss.shrinkwrap</groupId>
- <artifactId>shrinkwrap-impl-base</artifactId>
- <version>${version.org.jboss.shrinkwrap}</version>
+ <groupId>org.jboss.threads</groupId>
+ <artifactId>jboss-threads</artifactId>
+ <version>${version.org.jboss.threads}</version>
<scope>test</scope>
</dependency>
Added: projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/java/org/jboss/reloaded/api/ReloadedShrinkWrapDeployerDescriptors.java
===================================================================
--- projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/java/org/jboss/reloaded/api/ReloadedShrinkWrapDeployerDescriptors.java (rev 0)
+++ projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/java/org/jboss/reloaded/api/ReloadedShrinkWrapDeployerDescriptors.java 2010-04-16 01:50:37 UTC (rev 104032)
@@ -0,0 +1,138 @@
+package org.jboss.reloaded.api;
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+import org.jboss.bootstrap.api.descriptor.BootstrapDescriptor;
+import org.jboss.bootstrap.api.descriptor.ClassLoaderResourceBootstrapDescriptor;
+import org.jboss.bootstrap.api.mc.server.MCServer;
+import org.jboss.deployers.client.spi.main.MainDeployer;
+
+/**
+ * Contains convenience methods for obtaining {@link BootstrapDescriptor}s
+ * used in constructing a runtime equipped with the
+ * Virtual Deployment Framework from a plain {@link MCServer}. Typical
+ * usage is:
+ *
+ * <code>// Create a server
+ * final MCServer mcServer = MCServerFactory.createServer();
+ *
+ * // Add the required bootstrap descriptors
+ * final List<BootstrapDescriptor> descriptors = mcServer.getConfiguration().getBootstrapDescriptors();
+ * descriptors.add(ReloadedDescriptors.getClassLoadingDescriptor());
+ * descriptors.add(ReloadedDescriptors.getVdfDescriptor());
+ *
+ * // Start
+ * mcServer.start();</code>
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ */
+public final class ReloadedShrinkWrapDeployerDescriptors
+{
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Name of the resource containing a Microcontainer
+ * deployment descriptor capable of launching VDF elements
+ * required for {@link MainDeployer} support
+ */
+ private static String RESOURCE_NAME_VDF = "org.jboss.reloaded_vdf.xml";
+
+ /**
+ * Name of the resource containing a Microcontainer
+ * deployment descriptor capable of launching VFS-based
+ * ClassLoading
+ */
+ public static String RESOURCE_NAME_CLASSLOADING = "org.jboss.reloaded_classloading.xml";
+
+ //-------------------------------------------------------------------------------------||
+ // Functional Methods -----------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Obtains a {@link BootstrapDescriptor} containing components necessary
+ * for starting the Virtual Deployment Framework and {@link MainDeployer}.
+ * The descriptor will be found as a {@link ClassLoader} resource
+ * of name {@link ReloadedShrinkWrapDeployerDescriptors#RESOURCE_NAME_VDF} from the Thread
+ * Context ClassLoader
+ * @return
+ */
+ public static BootstrapDescriptor getVdfDescriptor()
+ {
+ // Return
+ return new ClassLoaderResourceBootstrapDescriptor(RESOURCE_NAME_VDF);
+ }
+
+ /**
+ * Obtains a {@link BootstrapDescriptor} containing components necessary
+ * for starting the Virtual Deployment Framework and {@link MainDeployer}.
+ * The descriptor will be found as a {@link ClassLoader} resource
+ * of name {@link ReloadedShrinkWrapDeployerDescriptors#RESOURCE_NAME_VDF} from the specified
+ * @return
+ * @param cl {@link ClassLoader} used to obtain the resource
+ * @throws IllegalArgumentException If the {@link ClassLoader} is not specified
+ */
+ public static BootstrapDescriptor getVdfDescriptor(final ClassLoader cl)
+ {
+ // Precondition check
+ if (cl == null)
+ {
+ throw new IllegalArgumentException("ClassLoader must be specified");
+ }
+
+ // Return
+ return new ClassLoaderResourceBootstrapDescriptor(RESOURCE_NAME_VDF, cl);
+ }
+
+ /**
+ * Obtains a {@link BootstrapDescriptor} containing components necessary
+ * for starting VFS-based ClassLoading Services
+ * @return
+ */
+ public static BootstrapDescriptor getClassLoadingDescriptor()
+ {
+ // Return
+ return new ClassLoaderResourceBootstrapDescriptor(RESOURCE_NAME_CLASSLOADING);
+ }
+
+ /**
+ * Obtains a {@link BootstrapDescriptor} containing components necessary
+ * for starting VFS-based ClassLoading Services.
+ * The descriptor will be found as a {@link ClassLoader} resource
+ * of name {@link ReloadedShrinkWrapDeployerDescriptors#RESOURCE_NAME_CLASSLOADING} from the specified
+ * @return
+ * @param cl {@link ClassLoader} used to obtain the resource
+ * @throws IllegalArgumentException If the {@link ClassLoader} is not specified
+ */
+ public static BootstrapDescriptor getClassLoadingDescriptor(final ClassLoader cl)
+ {
+ // Precondition check
+ if (cl == null)
+ {
+ throw new IllegalArgumentException("ClassLoader must be specified");
+ }
+
+ // Return
+ return new ClassLoaderResourceBootstrapDescriptor(RESOURCE_NAME_CLASSLOADING, cl);
+ }
+
+}
Added: projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/java/org/jboss/reloaded/shrinkwrap/api/ShrinkWrapDeployer.java
===================================================================
--- projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/java/org/jboss/reloaded/shrinkwrap/api/ShrinkWrapDeployer.java (rev 0)
+++ projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/java/org/jboss/reloaded/shrinkwrap/api/ShrinkWrapDeployer.java 2010-04-16 01:50:37 UTC (rev 104032)
@@ -0,0 +1,62 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.reloaded.shrinkwrap.api;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.shrinkwrap.api.Archive;
+
+/**
+ * Deployer for ShrinkWrap {@link Archive} types. End-user
+ * view to adapt archives directly into the Virtual Deployment
+ * Framework.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface ShrinkWrapDeployer
+{
+ //-------------------------------------------------------------------------------------||
+ // Contracts --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Deploys the specified archives into the Virtual Deployment Framework
+ * as an atomic operation.
+ *
+ * @param archives The archives to deploy
+ * @throws IllegalArgumentException If the archives are not specified (null)
+ * @throws DeploymentException If an error occurred in deployment
+ */
+ void deploy(Archive<?>... archives) throws IllegalArgumentException, DeploymentException;
+
+ /**
+ * Undeploys the specified archives from the Virtual Deployment Framework. Each
+ * archive must have been previously deployed in via this {@link ShrinkWrapDeployer}
+ * instance, else it will be ignored and logged as a warning.
+ *
+ * @param archives The archives to undeploy
+ * @throws IllegalArgumentException If the archives are not specified
+ * @throws DeploymentException If an error occurred during undeployment
+ */
+ void undeploy(Archive<?>... archives) throws IllegalArgumentException, DeploymentException;
+
+}
Added: projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/java/org/jboss/reloaded/shrinkwrap/api/ShrinkWrapReloadedDescriptors.java
===================================================================
--- projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/java/org/jboss/reloaded/shrinkwrap/api/ShrinkWrapReloadedDescriptors.java (rev 0)
+++ projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/java/org/jboss/reloaded/shrinkwrap/api/ShrinkWrapReloadedDescriptors.java 2010-04-16 01:50:37 UTC (rev 104032)
@@ -0,0 +1,129 @@
+package org.jboss.reloaded.shrinkwrap.api;
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+import org.jboss.bootstrap.api.descriptor.BootstrapDescriptor;
+import org.jboss.bootstrap.api.descriptor.ClassLoaderResourceBootstrapDescriptor;
+import org.jboss.deployers.client.spi.main.MainDeployer;
+import org.jboss.vfs.TempFileProvider;
+
+/**
+ * TODO
+ *
+ * Proof-of-concept for ShrinkWrap/Reloaded Integration
+ * with {@link MainDeployer}
+ *
+ * Expand docs if this prototype works.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ */
+public final class ShrinkWrapReloadedDescriptors
+{
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Name of the resource containing a Microcontainer
+ * deployment descriptor capable of installing the
+ * {@link ShrinkWrapDeployer} implementation
+ */
+ private static String RESOURCE_NAME_SHRINKWRAP_DEPLOYER = "org.jboss.reloaded_ShrinkWrapDeployer.xml";
+
+ /**
+ * Name of the resource containing a Microcontainer
+ * deployment descriptor capable of installing the {@link TempFileProvider}
+ * used by the {@link ShrinkWrapDeployer}
+ */
+ public static String RESOURCE_NAME_TEMP_FILE_PROVIDER = "org.jboss.reloaded_TempFileProvider.xml";
+
+ //-------------------------------------------------------------------------------------||
+ // Functional Methods -----------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Obtains a {@link BootstrapDescriptor} containing components necessary
+ * for installing the {@link ShrinkWrapDeployer}.
+ * The descriptor will be found as a {@link ClassLoader} resource
+ * of name {@link ShrinkWrapReloadedDescriptors#RESOURCE_NAME_SHRINKWRAP_DEPLOYER} from the Thread
+ * Context ClassLoader
+ * @return
+ */
+ public static BootstrapDescriptor getShrinkWrapDeployerDescriptor()
+ {
+ // Return
+ return new ClassLoaderResourceBootstrapDescriptor(RESOURCE_NAME_SHRINKWRAP_DEPLOYER);
+ }
+
+ /**
+ * Obtains a {@link BootstrapDescriptor} containing components necessary
+ * for installing the {@link ShrinkWrapDeployer}.
+ * The descriptor will be found as a {@link ClassLoader} resource
+ * of name {@link ShrinkWrapReloadedDescriptors#RESOURCE_NAME_SHRINKWRAP_DEPLOYER} from the specified
+ * @return
+ * @param cl {@link ClassLoader} used to obtain the resource
+ * @throws IllegalArgumentException If the {@link ClassLoader} is not specified
+ */
+ public static BootstrapDescriptor getShrinkWrapDeployerDescriptor(final ClassLoader cl)
+ {
+ // Precondition check
+ if (cl == null)
+ {
+ throw new IllegalArgumentException("ClassLoader must be specified");
+ }
+
+ // Return
+ return new ClassLoaderResourceBootstrapDescriptor(RESOURCE_NAME_SHRINKWRAP_DEPLOYER, cl);
+ }
+
+ /**
+ * Obtains a {@link BootstrapDescriptor} containing components necessary
+ * for starting a {@link TempFileProvider} to be used by the {@link ShrinkWrapDeployer}
+ * @return
+ */
+ public static BootstrapDescriptor getTempFileProviderDescriptor()
+ {
+ // Return
+ return new ClassLoaderResourceBootstrapDescriptor(RESOURCE_NAME_TEMP_FILE_PROVIDER);
+ }
+
+ /**
+ * Obtains a {@link BootstrapDescriptor} containing components necessary
+ * for starting a {@link TempFileProvider} to be used by the {@link ShrinkWrapDeployer}
+ * The descriptor will be found as a {@link ClassLoader} resource
+ * of name {@link ShrinkWrapReloadedDescriptors#RESOURCE_NAME_TEMP_FILE_PROVIDER} from the specified
+ * @return
+ * @param cl {@link ClassLoader} used to obtain the resource
+ * @throws IllegalArgumentException If the {@link ClassLoader} is not specified
+ */
+ public static BootstrapDescriptor getTempFileProviderDescriptor(final ClassLoader cl)
+ {
+ // Precondition check
+ if (cl == null)
+ {
+ throw new IllegalArgumentException("ClassLoader must be specified");
+ }
+
+ // Return
+ return new ClassLoaderResourceBootstrapDescriptor(RESOURCE_NAME_TEMP_FILE_PROVIDER, cl);
+ }
+
+}
Added: projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/java/org/jboss/reloaded/shrinkwrap/impl/ArchiveDeployment.java
===================================================================
--- projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/java/org/jboss/reloaded/shrinkwrap/impl/ArchiveDeployment.java (rev 0)
+++ projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/java/org/jboss/reloaded/shrinkwrap/impl/ArchiveDeployment.java 2010-04-16 01:50:37 UTC (rev 104032)
@@ -0,0 +1,249 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.reloaded.shrinkwrap.impl;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.Set;
+import java.util.UUID;
+
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.client.spi.main.MainDeployer;
+import org.jboss.deployers.spi.attachments.Attachments;
+import org.jboss.deployers.vfs.spi.client.VFSDeployment;
+import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.vfs3.ArchiveFileSystem;
+import org.jboss.vfs.TempDir;
+import org.jboss.vfs.TempFileProvider;
+import org.jboss.vfs.VFS;
+import org.jboss.vfs.VirtualFile;
+
+/**
+ * {@link Deployment} implementation allowing an {@link Archive}
+ * to be handed off directly to the Virtual Deployment Framework.
+ * Clients are responsible, after undeployment has completed, to call
+ * {@link Closeable#close()} upon the return value of
+ * {@link ArchiveDeployment#getHandle()}.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+class ArchiveDeployment implements VFSDeployment
+{
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * serialVersionUID
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * The archive to be deployed
+ */
+ private final Archive<?> archive;
+
+ /**
+ * The VDF deployment view to be passed to {@link MainDeployer}
+ */
+ private final Deployment deployment;
+
+ /**
+ * The VFS handle which may be closed on undeployment
+ */
+ private final Closeable handle;
+
+ /**
+ * VFS view of the {@link Archive}
+ */
+ private final VirtualFile file;
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Creates a new {@link ArchiveDeployment} by mounting the specified {@link Archive} into
+ * an {@link ArchiveFileSystem} backed by the specified {@link TempFileProvider}
+ * @param archive The archive to be represented as a {@link Deployment}
+ * @param tempFileProvider The backing temp file provider for the archive to be flushed
+ * to real disk if necessary
+ */
+ ArchiveDeployment(final Archive<?> archive, final TempFileProvider tempFileProvider)
+ {
+ // Precondition checks
+ assert archive != null : "archive must be specified";
+ assert tempFileProvider != null : "provider must be specified";
+
+ // Create a VFS VirtualFile and mount it
+ final String archiveName = archive.getName();
+ final TempDir tempDir;
+ try
+ {
+ tempDir = tempFileProvider.createTempDir(archiveName);
+ }
+ catch (final IOException ioe)
+ {
+ throw new RuntimeException("Could not create temp directory to back " + archive.toString(), ioe);
+ }
+ final VirtualFile virtualFile = VFS.getChild(UUID.randomUUID().toString()).getChild(archiveName);
+
+ // Set
+ this.file = virtualFile;
+ this.archive = archive;
+ try
+ {
+ this.handle = VFS.mount(virtualFile, new ArchiveFileSystem(archive, tempDir));
+ }
+ catch (final IOException ioe)
+ {
+ throw new RuntimeException("Could not mount for deployment: " + archive.toString(), ioe);
+ }
+ this.deployment = VFSDeploymentFactory.getInstance().createVFSDeployment(virtualFile);
+
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Accessors --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * @return the archive
+ */
+ Archive<?> getArchive()
+ {
+ return archive;
+ }
+
+ /**
+ * @return the deployment
+ */
+ Deployment getDeployment()
+ {
+ return deployment;
+ }
+
+ /**
+ * @return the handle
+ */
+ Closeable getHandle()
+ {
+ return handle;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /*
+ * Everything below this line delegates to the real deployment
+ */
+
+ /**
+ * {@inheritDoc}
+ * @see org.jboss.deployers.client.spi.Deployment#getSimpleName()
+ */
+ @Override
+ public String getSimpleName()
+ {
+ return this.getDeployment().getSimpleName();
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.jboss.deployers.client.spi.Deployment#getName()
+ */
+ @Override
+ public String getName()
+ {
+ return this.getDeployment().getName();
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.jboss.deployers.client.spi.Deployment#getTypes()
+ */
+ @Override
+ @SuppressWarnings("deprecation")
+ public Set<String> getTypes()
+ {
+ return this.getDeployment().getTypes();
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.jboss.deployers.client.spi.Deployment#setTypes(java.util.Set)
+ */
+ @Override
+ @SuppressWarnings("deprecation")
+ public void setTypes(final Set<String> types)
+ {
+ this.getDeployment().setTypes(types);
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.jboss.deployers.spi.attachments.PredeterminedManagedObjectAttachments#getPredeterminedManagedObjects()
+ */
+ @Override
+ public Attachments getPredeterminedManagedObjects()
+ {
+ return this.getDeployment().getPredeterminedManagedObjects();
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.jboss.deployers.spi.attachments.PredeterminedManagedObjectAttachments#setPredeterminedManagedObjects(org.jboss.deployers.spi.attachments.Attachments)
+ */
+ @Override
+ public void setPredeterminedManagedObjects(final Attachments predetermined)
+ {
+ this.getDeployment().setPredeterminedManagedObjects(predetermined);
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.jboss.deployers.vfs.spi.client.VFSDeployment#getRoot()
+ */
+ @Override
+ public VirtualFile getRoot()
+ {
+ return file;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Overridden Implementations ---------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * {@inheritDoc}
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString()
+ {
+ return "ArchiveDeployment [archive=" + archive + ", " + VirtualFile.class.getSimpleName() + "=" + file.toString()
+ + "]";
+ }
+}
Added: projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/java/org/jboss/reloaded/shrinkwrap/impl/ShrinkWrapDeployerImpl.java
===================================================================
--- projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/java/org/jboss/reloaded/shrinkwrap/impl/ShrinkWrapDeployerImpl.java (rev 0)
+++ projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/java/org/jboss/reloaded/shrinkwrap/impl/ShrinkWrapDeployerImpl.java 2010-04-16 01:50:37 UTC (rev 104032)
@@ -0,0 +1,332 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.reloaded.shrinkwrap.impl;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.beans.metadata.api.annotations.Inject;
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.client.spi.main.MainDeployer;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.vfs.spi.client.VFSDeployment;
+import org.jboss.logging.Logger;
+import org.jboss.reloaded.shrinkwrap.api.ShrinkWrapDeployer;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.vfs3.ArchiveFileSystem;
+import org.jboss.vfs.TempFileProvider;
+
+/**
+ * Base implementation of a {@link ShrinkWrapDeployer}. Handles
+ * mounting/unmounting of {@link Archive}s into VFS using
+ * the {@link ArchiveFileSystem}. {@link Archive}s are then represented
+ * as {@link VFSDeployment}s and passed into the {@link MainDeployer}.
+ * Thread-safe; deploy and undeploy will block and service one client at a time.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public final class ShrinkWrapDeployerImpl implements ShrinkWrapDeployer
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Logger
+ */
+ private static final Logger log = Logger.getLogger(ShrinkWrapDeployerImpl.class);
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Delegate to handle the real deployment.
+ */
+ private final MainDeployer deployer;
+
+ /**
+ * Temporary file provider with which archives will be mounted
+ * before deployment
+ */
+ private final TempFileProvider tempFileProvider;
+
+ /**
+ * Mapping of all archives deployed via this {@link ShrinkWrapDeployer} instance. Must
+ * be guarded by "this" alongside deploy/undeploy operations.
+ */
+ private final Map<Archive<?>, ArchiveDeployment> deployments = new HashMap<Archive<?>, ArchiveDeployment>();
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Creates a new {@link ShrinkWrapDeployerImpl} instance.
+ *
+ * @param deployer The delegate deployer to handle
+ */
+ public ShrinkWrapDeployerImpl(@Inject final MainDeployer deployer, @Inject final TempFileProvider tempFileProvider)
+ {
+ // Precondition checks
+ if (deployer == null)
+ {
+ throw new IllegalArgumentException("deployer must be specified");
+ }
+ if (tempFileProvider == null)
+ {
+ throw new IllegalArgumentException("tempFileProvider must be specified");
+ }
+
+ // Set
+ this.deployer = deployer;
+ this.tempFileProvider = tempFileProvider;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * {@inheritDoc}
+ * @see org.jboss.reloaded.api.ShrinkWrapDeployer#deploy(org.jboss.shrinkwrap.api.Archive<?>[])
+ */
+ @Override
+ public void deploy(final Archive<?>... archives) throws IllegalArgumentException, DeploymentException
+ {
+ // Precondition checks
+ if (archives == null)
+ {
+ throw new IllegalArgumentException("Archives must be specified (even if empty)");
+ }
+
+ // Create ArchiveDeployments from the Archives
+ final Collection<ArchiveDeployment> newDeployments = new ArrayList<ArchiveDeployment>();
+ for (final Archive<?> archive : archives)
+ {
+ newDeployments.add(new ArchiveDeployment(archive, tempFileProvider));
+ }
+
+ // Deployment must be atomic
+ synchronized (this)
+ {
+ // Get the MainDeployer
+ final MainDeployer deployer = this.deployer;
+
+ // Init the deployments to add
+ final Collection<ArchiveDeployment> deploymentsToAdd = new ArrayList<ArchiveDeployment>(archives.length);
+
+ // For all new deployments
+ for (final ArchiveDeployment deployment : newDeployments)
+ {
+ // Check that we haven't deployed this archive already
+ final Archive<?> currentArchive = deployment.getArchive();
+ if (deployments.containsKey(currentArchive))
+ {
+ // Log a warning and unmount this sucker
+ log.warnf("Ignoring request to deploy already-deployed archive: %s", currentArchive);
+ try
+ {
+ deployment.getHandle().close();
+ }
+ catch (final IOException e)
+ {
+ log.warnf(e, "Could not close handle for mounted archive %s", currentArchive);
+ }
+ }
+
+ // Add to the MainDeployer
+ try
+ {
+ deployer.addDeployment(deployment);
+ }
+ catch (final DeploymentException de)
+ {
+ // Some error occurred while adding; revert out all the previously-processed deployments and report the error
+ log.warnf(de, "Error in adding deployment for archive %s; reverting out the previous deployments",
+ currentArchive);
+ removeDeployments(deploymentsToAdd);
+ throw de;
+ }
+ if(log.isTraceEnabled())
+ {
+ log.tracef("Adding archive for deployment: %s", currentArchive);
+ }
+ deploymentsToAdd.add(deployment);
+
+ }
+
+ // Process and check the MainDeployer
+ deployer.process();
+ try
+ {
+ deployer.checkComplete();
+ }
+ catch (final DeploymentException de)
+ {
+ // Some error occurred while processing and checking; revert out all the previously-processed deployments and report the error
+ log.warn("Error in processing deployments; reverting all archives requested for deployment", de);
+ removeDeployments(deploymentsToAdd);
+ throw de;
+ }
+
+ // Success; now formally mark all deployments as deployed
+ for (final ArchiveDeployment deploymentAdded : deploymentsToAdd)
+ {
+ this.deployments.put(deploymentAdded.getArchive(), deploymentAdded);
+ }
+ if (log.isDebugEnabled())
+ {
+ log.debugf("Deployed: %s", deploymentsToAdd);
+ }
+ }
+
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.jboss.reloaded.api.ShrinkWrapDeployer#undeploy(org.jboss.shrinkwrap.api.Archive<?>[])
+ */
+ @Override
+ public void undeploy(final Archive<?>... archives) throws IllegalArgumentException, DeploymentException
+ {
+ // Precondition checks
+ if (archives == null)
+ {
+ throw new IllegalArgumentException("Archives must be specified (even if empty)");
+ }
+
+ // Undeployment must be atomic
+ synchronized (this)
+ {
+ // Init a Collection of deployments to remove
+ final Collection<ArchiveDeployment> deploymentsToRemove = new ArrayList<ArchiveDeployment>(archives.length);
+
+ // Get the underlying deployments as keys from the archive
+ for (final Archive<?> archive : archives)
+ {
+
+ final ArchiveDeployment deployment = this.deployments.get(archive);
+ if (deployment == null)
+ {
+ log.warnf("No deployment has been made for archive %s; ignoring", archive.toString());
+ }
+ else
+ {
+ deploymentsToRemove.add(deployment);
+ }
+ }
+
+ // Remove all
+ this.removeDeployments(deploymentsToRemove);
+ }
+
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Internal Helper Methods -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Makes a best-effort at removing all specified {@link Deployment}s from
+ * the {@link MainDeployer}, throwing a {@link DeploymentException} if one is
+ * encountered during final check of the deployer. Unconditionally attempts to
+ * close all associated {@link ArchiveDeployment#getHandle()}s. MUST be called from within
+ * a synchronized block using "this" as monitor.
+ * @param deployments
+ */
+ private void removeDeployments(final Collection<ArchiveDeployment> deployments) throws DeploymentException
+ {
+ // Precondition checks
+ assert deployments != null : "deployments must not be null";
+
+ // Get the MainDeployer
+ final MainDeployer deployer = this.deployer;
+
+ // For all deployments
+ for (final ArchiveDeployment deployment : deployments)
+ {
+ try
+ {
+ // Remove from the deployer
+ deployer.removeDeployment(deployment);
+ }
+ catch (final DeploymentException de)
+ {
+ // Just log this removal failure
+ log.warnf(de, "Could not remove deployment %s", deployment);
+ }
+ }
+
+ // Mark a reference to cache an exception if we get one (to be rethrown)
+ DeploymentException cachedException = null;
+
+ // Process and check the deployer
+ deployer.process();
+ try
+ {
+ deployer.checkComplete();
+ }
+ catch (final DeploymentException de)
+ {
+
+ log.warn("Problem in Main Deployer while removing pending deployments", de);
+ // We can overwrite the exception cached above because this
+ // is likely to be more important
+ cachedException = de;
+ }
+
+ // For all deployments
+ for (final ArchiveDeployment deployment : deployments)
+ {
+ try
+ {
+ // Close up
+ deployment.getHandle().close();
+ }
+ catch (final IOException e)
+ {
+ // Don't bother WARNing this, but make a record in DEBUG
+ if (log.isDebugEnabled())
+ {
+ log.debugf(e, "Could not close the mounted %s", deployment.getArchive());
+ }
+ }
+
+ // Mark removed
+ this.deployments.remove(deployment.getArchive());
+ }
+
+ // Throw a DeploymentException if we got one
+ if (cachedException != null)
+ {
+ throw cachedException;
+ }
+
+ }
+
+}
Added: projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/resources/org.jboss.reloaded_ShrinkWrapDeployer.xml
===================================================================
--- projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/resources/org.jboss.reloaded_ShrinkWrapDeployer.xml (rev 0)
+++ projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/resources/org.jboss.reloaded_ShrinkWrapDeployer.xml 2010-04-16 01:50:37 UTC (rev 104032)
@@ -0,0 +1,18 @@
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <!--
+ Creates the ShrinkWrap Deployer, which delegates to the specified
+ MainDeployer and uses a supplied TempFileProvder
+ -->
+ <bean name="ShrinkWrapDeployer" class="org.jboss.reloaded.shrinkwrap.impl.ShrinkWrapDeployerImpl">
+ <constructor>
+ <parameter name="deployer">
+ <inject />
+ </parameter>
+ <parameter name="tempFileProvider">
+ <inject />
+ </parameter>
+ </constructor>
+ </bean>
+
+</deployment>
\ No newline at end of file
Added: projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/resources/org.jboss.reloaded_TempFileProvider.xml
===================================================================
--- projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/resources/org.jboss.reloaded_TempFileProvider.xml (rev 0)
+++ projects/reloaded/trunk/vdf-bootstrap-minimal/src/main/resources/org.jboss.reloaded_TempFileProvider.xml 2010-04-16 01:50:37 UTC (rev 104032)
@@ -0,0 +1,42 @@
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <!-- Deployment configuration for a VFS TempFileProvider -->
+
+
+ <!--
+
+ JBossXB isn't liking the inclusion of this namespace: TODO: Why?
+ <threads xmlns="urn:jboss:threads:2.0">
+
+ [Comment] This will execute
+ in the calling Thread. Probably better to use another,
+ Single-threaded executor type, but this is fine for now [/Comment]
+
+ <direct-executor name="org.jboss.reloaded.TempFileExecutorService"/>
+
+ </threads>
+ -->
+
+ <!--
+ Define the Executor, but this should really be done in threads.xsd
+ format above
+ -->
+ <bean name="org.jboss.reloaded.TempFileExecutorService" class="org.jboss.threads.JBossScheduledThreadPoolExecutor">
+ <constructor>
+ <parameter>1</parameter>
+ </constructor>
+ </bean>
+
+ <bean name="org.jboss.reloaded.TempFileProvider" class="org.jboss.vfs.TempFileProvider">
+ <constructor factoryClass="org.jboss.vfs.TempFileProvider"
+ factoryMethod="create">
+ <parameter>shrinkwrap-</parameter>
+ <parameter>
+ <inject bean="org.jboss.reloaded.TempFileExecutorService" />
+ </parameter>
+ </constructor>
+ </bean>
+
+
+
+</deployment>
\ No newline at end of file
Added: projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/org/jboss/reloaded/api/CachingDeployer.java
===================================================================
--- projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/org/jboss/reloaded/api/CachingDeployer.java (rev 0)
+++ projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/org/jboss/reloaded/api/CachingDeployer.java 2010-04-16 01:50:37 UTC (rev 104032)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.reloaded.api;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.Deployer;
+import org.jboss.deployers.spi.deployer.helpers.AbstractDeployer;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * Simple test {@link Deployer} which caches the last {@link DeploymentUnit}
+ * processed. Safe for use only in single-threaded environments.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+class CachingDeployer extends AbstractDeployer
+{
+
+ /**
+ * The last unit deployed
+ */
+ DeploymentUnit lastDeployed;
+
+ /**
+ * {@inheritDoc}
+ * @see org.jboss.deployers.spi.deployer.Deployer#deploy(org.jboss.deployers.structure.spi.DeploymentUnit)
+ */
+ @Override
+ public void deploy(DeploymentUnit unit) throws DeploymentException
+ {
+ log.info("Deploying: " + unit);
+
+ // Cache
+ lastDeployed = unit;
+ }
+
+}
Added: projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/org/jboss/reloaded/api/LifecyclePojo.java
===================================================================
--- projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/org/jboss/reloaded/api/LifecyclePojo.java (rev 0)
+++ projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/org/jboss/reloaded/api/LifecyclePojo.java 2010-04-16 01:50:37 UTC (rev 104032)
@@ -0,0 +1,76 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.reloaded.api;
+
+import org.jboss.beans.metadata.api.annotations.Start;
+import org.jboss.beans.metadata.api.annotations.Stop;
+
+/**
+ * Simple POJO with lifecycle operations to set state
+ * in globally-accessible fashion for testing
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class LifecyclePojo
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Notes the state of this POJO
+ */
+ enum State {
+ STARTED, STOPPED;
+ }
+
+ /**
+ * State flag so the test can see that we've been deployed
+ */
+ static State state = State.STOPPED;
+
+ //-------------------------------------------------------------------------------------||
+ // Lifecycle Methods ------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Lifecycle start callback
+ * @throws Exception
+ */
+ @Start
+ public void start() throws Exception
+ {
+ state = State.STARTED;
+ }
+
+ /**
+ * Lifecycle stop callback
+ * @throws Exception
+ */
+ @Stop
+ public void stop() throws Exception
+ {
+ state = State.STOPPED;
+ }
+}
Modified: projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/org/jboss/reloaded/api/MainDeployerViaBootstrapUnitTest.java
===================================================================
--- projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/org/jboss/reloaded/api/MainDeployerViaBootstrapUnitTest.java 2010-04-16 01:33:11 UTC (rev 104031)
+++ projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/org/jboss/reloaded/api/MainDeployerViaBootstrapUnitTest.java 2010-04-16 01:50:37 UTC (rev 104032)
@@ -1,22 +1,14 @@
package org.jboss.reloaded.api;
import java.io.File;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
import java.util.List;
import junit.framework.TestCase;
import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
import org.jboss.bootstrap.api.descriptor.BootstrapDescriptor;
-import org.jboss.bootstrap.api.lifecycle.LifecycleState;
import org.jboss.bootstrap.api.mc.server.MCServer;
-import org.jboss.bootstrap.api.mc.server.MCServerFactory;
-import org.jboss.deployers.client.spi.Deployment;
import org.jboss.deployers.client.spi.main.MainDeployer;
-import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.deployers.spi.deployer.Deployer;
-import org.jboss.deployers.spi.deployer.helpers.AbstractDeployer;
import org.jboss.deployers.structure.spi.DeploymentUnit;
import org.jboss.deployers.vfs.spi.client.VFSDeployment;
import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
@@ -27,9 +19,6 @@
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.vfs.VFS;
import org.jboss.vfs.VirtualFile;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.Test;
/**
@@ -41,7 +30,7 @@
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
* @version $Revision: $
*/
-public class MainDeployerViaBootstrapUnitTest
+public class MainDeployerViaBootstrapUnitTest extends ReloadedMCServerTestBase
{
//-------------------------------------------------------------------------------------||
@@ -54,21 +43,6 @@
private static final Logger log = Logger.getLogger(MainDeployerViaBootstrapUnitTest.class);
/**
- * The Server
- */
- private static MCServer server;
-
- /**
- * Name of the system property signaling JBossXB to ignore order
- */
- private static final String NAME_SYSPROP_JBOSSXB_IGNORE_ORDER = "xb.builder.useUnorderedSequence";
-
- /**
- * Value to set for JBossXB ordering
- */
- private static final String VALUE_SYSPROP_JBOSSXB_IGNORE_ORDER = "true";
-
- /**
* Name of the archive we'll deploy
*/
private static final String NAME_ARCHIVE = "testDeployment.jar";
@@ -88,71 +62,18 @@
//-------------------------------------------------------------------------------------||
/**
- * Setup JBossXB
- * TODO @see comments below so that this step is not necessary
+ * {@inheritDoc}
+ * @see org.jboss.reloaded.api.ReloadedMCServerTestBase#configureServer(org.jboss.bootstrap.api.mc.server.MCServer)
*/
- @BeforeClass
- public static void setupJBossXb()
+ @Override
+ protected void configureServer(final MCServer server)
{
- AccessController.doPrivileged(new PrivilegedAction<Void>()
- {
- public Void run()
- {
- // Must use unordered sequence else JBossXB will explode
- //TODO Define a proper vfs.xml which is properly ordered
- System.setProperty(NAME_SYSPROP_JBOSSXB_IGNORE_ORDER, VALUE_SYSPROP_JBOSSXB_IGNORE_ORDER);
- return null;
- }
- });
- }
-
- /**
- * Creates the server
- */
- @BeforeClass
- public static void createAndConfigureServer()
- {
- // Create a server
- final MCServer mcServer = MCServerFactory.createServer();
-
// Add the required bootstrap descriptors
- final List<BootstrapDescriptor> descriptors = mcServer.getConfiguration().getBootstrapDescriptors();
+ final List<BootstrapDescriptor> descriptors = server.getConfiguration().getBootstrapDescriptors();
descriptors.add(ReloadedDescriptors.getClassLoadingDescriptor());
descriptors.add(ReloadedDescriptors.getVdfDescriptor());
-
- log.info("Using bootstrap descriptors:" + descriptors);
-
- // Set
- server = mcServer;
}
- /**
- * Starts the server before each test
- * @throws Exception
- */
- @Before
- public void startServer() throws Exception
- {
- long before = System.currentTimeMillis();
- server.start();
- long after = System.currentTimeMillis();
- long total = after - before;
- log.info("Boot took: " + total + "ms");
- }
-
- /**
- * Stops the server after each test
- * @throws Exception
- */
- @After
- public void stopServer() throws Exception
- {
- if (server != null && server.getState().equals(LifecycleState.STARTED))
- {
- server.stop();
- }
- }
-
//-------------------------------------------------------------------------------------||
// Tests ------------------------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
@@ -206,31 +127,4 @@
mainDeployer.checkComplete();
}
- //-------------------------------------------------------------------------------------||
- // Inner Classes ----------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Simple {@link Deployer} to cache and make accessible the last-deployed
- * {@link DeploymentUnit}. Used to ensure that we can install deployers
- * into the chain and that they'll process new {@link Deployment}s.
- */
- protected static class CachingDeployer extends AbstractDeployer
- {
-
- /**
- * The last unit deployed
- */
- DeploymentUnit lastDeployed;
-
- public void deploy(final DeploymentUnit unit) throws DeploymentException
- {
- log.info("Deploying: " + unit);
- // Hack into internals to get the underlying context
-
- // Cache the real underlying deployemt if you have access to it.
- lastDeployed = unit;
- }
-
- }
}
Added: projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/org/jboss/reloaded/api/ReloadedMCServerTestBase.java
===================================================================
--- projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/org/jboss/reloaded/api/ReloadedMCServerTestBase.java (rev 0)
+++ projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/org/jboss/reloaded/api/ReloadedMCServerTestBase.java 2010-04-16 01:50:37 UTC (rev 104032)
@@ -0,0 +1,152 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.reloaded.api;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
+import org.jboss.bootstrap.api.lifecycle.LifecycleState;
+import org.jboss.bootstrap.api.mc.server.MCServer;
+import org.jboss.bootstrap.api.mc.server.MCServerFactory;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.logging.Logger;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+
+/**
+ * Base support for Reloaded test cases using {@link MCServer}
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public abstract class ReloadedMCServerTestBase
+{
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Logger
+ */
+ private static final Logger log = Logger.getLogger(ReloadedMCServerTestBase.class);
+
+ /**
+ * Name of the system property signaling JBossXB to ignore order
+ */
+ private static final String NAME_SYSPROP_JBOSSXB_IGNORE_ORDER = "xb.builder.useUnorderedSequence";
+
+ /**
+ * Value to set for JBossXB ordering
+ */
+ private static final String VALUE_SYSPROP_JBOSSXB_IGNORE_ORDER = "true";
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * The Server
+ */
+ MCServer server;
+
+ /**
+ * Deployer to cache the last {@link DeploymentUnit} processed
+ */
+ CachingDeployer cachingDeployer;
+
+ //-------------------------------------------------------------------------------------||
+ // Lifecycle --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Setup JBossXB
+ * TODO @see comments below so that this step is not necessary
+ */
+ @BeforeClass
+ public static void setupJBossXb()
+ {
+ AccessController.doPrivileged(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ // Must use unordered sequence else JBossXB will explode
+ //TODO Define a proper vfs.xml which is properly ordered
+ System.setProperty(NAME_SYSPROP_JBOSSXB_IGNORE_ORDER, VALUE_SYSPROP_JBOSSXB_IGNORE_ORDER);
+ return null;
+ }
+ });
+ }
+
+ /**
+ * Starts the server before each test
+ * @throws Exception
+ */
+ @Before
+ public void startServerAndInstallCachingDeployer() throws Throwable
+ {
+ // Create a server
+ final MCServer mcServer = MCServerFactory.createServer();
+ this.server = mcServer;
+
+ // Configure it
+ this.configureServer(mcServer);
+
+ // Start
+ long before = System.currentTimeMillis();
+ server.start();
+ long after = System.currentTimeMillis();
+ long total = after - before;
+ log.info("Boot took: " + total + "ms");
+
+ // Get the KernelController
+ final KernelController controller = server.getKernel().getController();
+
+ // Install a caching deployer which will remember the last deployment
+ final CachingDeployer deployer = new CachingDeployer();
+ cachingDeployer = deployer;
+ final String deployerName = deployer.getClass().getSimpleName();
+ final BeanMetaDataBuilder bmdb = BeanMetaDataBuilder.createBuilder(deployerName, deployer.getClass().getName());
+ controller.install(bmdb.getBeanMetaData(), deployer);
+ }
+
+ /**
+ * Configures the server before it's initialized/started
+ * @param server
+ */
+ protected abstract void configureServer(final MCServer server);
+
+ /**
+ * Stops the server after each test
+ * @throws Exception
+ */
+ @After
+ public void stopServer() throws Exception
+ {
+ if (server != null && server.getState().equals(LifecycleState.STARTED))
+ {
+ server.stop();
+ }
+ }
+}
Added: projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/org/jboss/reloaded/api/ShrinkWrapDeployerUnitTest.java
===================================================================
--- projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/org/jboss/reloaded/api/ShrinkWrapDeployerUnitTest.java (rev 0)
+++ projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/java/org/jboss/reloaded/api/ShrinkWrapDeployerUnitTest.java 2010-04-16 01:50:37 UTC (rev 104032)
@@ -0,0 +1,130 @@
+package org.jboss.reloaded.api;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.List;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.jboss.bootstrap.api.descriptor.BootstrapDescriptor;
+import org.jboss.bootstrap.api.mc.server.MCServer;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.logging.Logger;
+import org.jboss.reloaded.shrinkwrap.api.ShrinkWrapDeployer;
+import org.jboss.reloaded.shrinkwrap.api.ShrinkWrapReloadedDescriptors;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.Archives;
+import org.jboss.shrinkwrap.api.Asset;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.Test;
+
+/**
+ * Ensures that the {@link ShrinkWrapDeployer} supports deployment
+ * and undeployment of ShrinkWrap {@link Archive}s.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class ShrinkWrapDeployerUnitTest extends ReloadedMCServerTestBase
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Logger
+ */
+ private static final Logger log = Logger.getLogger(ShrinkWrapDeployerUnitTest.class);
+
+ /**
+ * MC bean name of the {@link ShrinkWrapDeployer}
+ */
+ protected static final String NAME_MC_SHRINKWRAP_DEPLOYER = "ShrinkWrapDeployer";
+
+ /**
+ * Name of a ShrinkWrap {@link Archive} we'll deploy
+ */
+ private static final String NAME_ARCHIVE = "testDeployment.jar";
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * {@inheritDoc}
+ * @see org.jboss.reloaded.api.ReloadedMCServerTestBase#configureServer(org.jboss.bootstrap.api.mc.server.MCServer)
+ */
+ @Override
+ protected void configureServer(final MCServer server)
+ {
+ // Add the required bootstrap descriptors
+ final List<BootstrapDescriptor> descriptors = server.getConfiguration().getBootstrapDescriptors();
+ descriptors.add(ReloadedDescriptors.getClassLoadingDescriptor());
+ descriptors.add(ReloadedDescriptors.getVdfDescriptor());
+ descriptors.add(ShrinkWrapReloadedDescriptors.getTempFileProviderDescriptor());
+ descriptors.add(ShrinkWrapReloadedDescriptors.getShrinkWrapDeployerDescriptor());
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Tests ------------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Ensures that a ShrinkWrap {@link Archive} may be directly deployed into
+ * the {@link ShrinkWrapDeployer}
+ */
+ @Test
+ public void testShrinkWrapDeployment() throws Throwable
+ {
+ // Get the KernelController
+ final KernelController controller = server.getKernel().getController();
+
+ // Get the MainDeployer (should have been installed via the lifecycle)
+ final ShrinkWrapDeployer shrinkwrapDeployer = (ShrinkWrapDeployer) controller.getInstalledContext(
+ NAME_MC_SHRINKWRAP_DEPLOYER).getTarget();
+ TestCase.assertNotNull(ShrinkWrapDeployer.class.getName() + " instance was not installed into MC",
+ shrinkwrapDeployer);
+
+ // Ensure preconditions (state STOPPED)
+ LifecyclePojo.State currentState = LifecyclePojo.state;
+ log.info("Current State of Lifecycle POJO: " + currentState);
+ Assert.assertEquals("Lifecycle POJO state should be stopped before deployment", LifecyclePojo.State.STOPPED,
+ currentState);
+
+ // Construct a test JAR to install the Lifecycle POJO
+ final Asset deploymentXmlAsset = new Asset()
+ {
+
+ @Override
+ public InputStream openStream()
+ {
+ return new ByteArrayInputStream(new String(
+ "<deployment xmlns=\"urn:jboss:bean-deployer:2.0\"><bean name=\"LifecyclePojo\" class=\""
+ + LifecyclePojo.class.getName() + "\" /></deployment>").getBytes());
+ }
+ };
+ final JavaArchive testJar = Archives.create(NAME_ARCHIVE, JavaArchive.class).addClass(LifecyclePojo.class).add(
+ deploymentXmlAsset, ArchivePaths.create("pojo-jboss-beans.xml"));
+
+ // Deploy the test JAR
+ shrinkwrapDeployer.deploy(testJar);
+
+ // Ensure deployed
+ currentState = LifecyclePojo.state;
+ log.info("Current State of Lifecycle POJO: " + currentState);
+ Assert.assertEquals("Lifecycle POJO state should be started after deployment", LifecyclePojo.State.STARTED,
+ currentState);
+
+ // Undeploy
+ shrinkwrapDeployer.undeploy(testJar);
+
+ // Ensure undeployed
+ currentState = LifecyclePojo.state;
+ log.info("Current State of Lifecycle POJO: " + currentState);
+ Assert.assertEquals("Lifecycle POJO state should be stopped after undeployment", LifecyclePojo.State.STOPPED,
+ LifecyclePojo.state);
+ }
+}
Modified: projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/resources/log4j.xml
===================================================================
--- projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/resources/log4j.xml 2010-04-16 01:33:11 UTC (rev 104031)
+++ projects/reloaded/trunk/vdf-bootstrap-minimal/src/test/resources/log4j.xml 2010-04-16 01:50:37 UTC (rev 104032)
@@ -59,6 +59,9 @@
<category name="org.jboss.bootstrap">
<priority value="DEBUG"/>
</category>
+ <category name="org.jboss.reloaded">
+ <priority value="ALL"/>
+ </category>
<!-- ======================= -->
<!-- Setup the Root category -->
More information about the jboss-cvs-commits
mailing list