[jboss-cvs] JBossAS SVN: r91047 - in projects/embedded/trunk: core/src/main/java/org/jboss/embedded/core and 9 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Jul 10 00:39:08 EDT 2009
Author: ALRubinger
Date: 2009-07-10 00:39:07 -0400 (Fri, 10 Jul 2009)
New Revision: 91047
Added:
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/SecurityActions.java
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/impl/
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/impl/base/
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/impl/base/AbstractVirtualArchive.java
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/impl/base/ResourceNotFoundException.java
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/impl/base/SecurityActions.java
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/impl/vfs/
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/impl/vfs/SecurityActions.java
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/impl/vfs/VirtualVfsArchiveImpl.java
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/spi/
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/spi/ExtensibleVirtualArchive.java
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/spi/vfs/
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/spi/vfs/ExtensibleVirtualVfsArchive.java
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/spi/vfs/VirtualVfsArchive.java
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/tempdev/
Removed:
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/deployment/
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/tempdev/AbstractVirtualDeployment.java
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/tempdev/ExtensibleVirtualDeployment.java
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/tempdev/ResourceNotFoundException.java
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/tempdev/SecurityActions.java
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/tempdev/VirtualDeployment.java
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/tempdev/VirtualDeploymentImpl.java
Modified:
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/JBossASEmbeddedServer.java
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/JBossASEmbeddedServerImpl.java
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/tempdev/VirtualDeploymentFactory.java
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/tempdev/VirtualDeploymentGroup.java
projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/tempdev/VirtualDeploymentGroupImpl.java
projects/embedded/trunk/pom.xml
projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/ServerTestCase.java
projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/TempDevelopmentOnlyTestCase.java
Log:
[EMB-32] Some more API work for VirtualArchive, cleanup of some impls, better separation
Modified: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/JBossASEmbeddedServer.java
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/JBossASEmbeddedServer.java 2009-07-10 04:17:47 UTC (rev 91046)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/JBossASEmbeddedServer.java 2009-07-10 04:39:07 UTC (rev 91047)
@@ -24,7 +24,7 @@
import org.jboss.bootstrap.spi.as.server.JBossASServer;
import org.jboss.deployers.client.spi.Deployment;
import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.embedded.core.deployment.VirtualDeployment;
+import org.jboss.embedded.core.virtual.spi.vfs.VirtualVfsArchive;
/**
* JBossASEmbeddedServer
@@ -62,5 +62,5 @@
* @throws DeploymentException
* @throws IllegalArgumentException If the deployment was not specified
*/
- void deploy(VirtualDeployment deployment) throws DeploymentException, IllegalArgumentException;
+ void deploy(VirtualVfsArchive deployment) throws DeploymentException, IllegalArgumentException;
}
Modified: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/JBossASEmbeddedServerImpl.java
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/JBossASEmbeddedServerImpl.java 2009-07-10 04:17:47 UTC (rev 91046)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/JBossASEmbeddedServerImpl.java 2009-07-10 04:39:07 UTC (rev 91047)
@@ -30,10 +30,10 @@
import org.jboss.deployers.client.spi.main.MainDeployer;
import org.jboss.deployers.spi.DeploymentException;
import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
-import org.jboss.embedded.core.deployment.VirtualDeployment;
import org.jboss.embedded.core.lifecycle.IgnoreXbUnorderedSequenceLifecycleEventHandler;
import org.jboss.embedded.core.lifecycle.InitLoggingManagerLifecycleEventHandler;
import org.jboss.embedded.core.lifecycle.SetRmiHostnameLifecycleEventHandler;
+import org.jboss.embedded.core.virtual.spi.vfs.VirtualVfsArchive;
import org.jboss.kernel.Kernel;
import org.jboss.kernel.spi.dependency.KernelController;
import org.jboss.logging.Logger;
@@ -60,6 +60,21 @@
*/
private static final Logger log = Logger.getLogger(JBossASEmbeddedServerImpl.class);
+ /**
+ * Environment Variable name for JBOSS_HOME
+ */
+ public static final String ENV_VAR_JBOSS_HOME = "JBOSS_HOME";
+
+ /**
+ * System property name for JBOSS_HOME
+ */
+ public static final String SYS_PROP_JBOSS_HOME = "jboss.home";
+
+ /**
+ * Name under which the MainDeployer is registered with MC
+ */
+ private static final String MC_NAME_MAIN_DEPLOYER = "MainDeployer";
+
//-------------------------------------------------------------------------------------||
// Constructor ------------------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
@@ -67,13 +82,39 @@
/**
* Constructor
*
+ * Creates a new instance, finding JBOSS_HOME from either:
*
+ * 1) Environment variable "JBOSS_HOME"
+ * 2) System property "jboss.home"
*
+ * ...with preference to the system property
+ *
* @throws IllegalStateException
*/
public JBossASEmbeddedServerImpl() throws IllegalStateException
{
+ // Call Super
+ super();
+ // Get JBOSS_HOME
+ String jbossHome = SecurityActions.getSystemProperty(SYS_PROP_JBOSS_HOME);
+ if (jbossHome == null)
+ {
+ jbossHome = SecurityActions.getEnvironmentVariable(ENV_VAR_JBOSS_HOME);
+ log.info("Using " + ENV_VAR_JBOSS_HOME + " Environment Variable: " + jbossHome);
+ }
+ else
+ {
+ log.info("Using " + SYS_PROP_JBOSS_HOME + " System Property: " + jbossHome);
+ }
+ if (jbossHome == null)
+ {
+ throw new IllegalStateException("JBOSS_HOME must be specified, either via environment variable \""
+ + ENV_VAR_JBOSS_HOME + "\" or system property \"" + SYS_PROP_JBOSS_HOME + "\".");
+ }
+
+ // Init
+ this.initialize(jbossHome);
}
/**
@@ -87,7 +128,75 @@
// Call the super implementation
super();
+ // Init
+ this.initialize(jbossHome);
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /* (non-Javadoc)
+ * @see org.jboss.embedded.core.server.JBossASEmbeddedServer#deploy(org.jboss.deployers.client.spi.Deployment)
+ */
+ @Override
+ public void deploy(final Deployment deployment) throws DeploymentException, IllegalArgumentException
+ {
// Precondition check
+ if (deployment == null)
+ {
+ throw new IllegalArgumentException("deployment must be specified");
+ }
+
+ // Get the MainDeployer
+ final Kernel kernel = this.getKernel();
+ final KernelController controller = kernel.getController();
+ final ControllerContext context = controller.getContext(MC_NAME_MAIN_DEPLOYER, ControllerState.INSTALLED);
+ if (context == null)
+ {
+ throw new IllegalStateException("Main deployer could not be found");
+ }
+ final Object target = context.getTarget();
+ final MainDeployer mainDeployer = MainDeployer.class.cast(target);
+
+ // Deploy and check all's OK
+ mainDeployer.deploy(deployment);
+ mainDeployer.checkComplete();
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.embedded.core.server.JBossASEmbeddedServer#deploy(org.jboss.embedded.core.deployment.VirtualDeployment)
+ */
+ @Override
+ public void deploy(final VirtualVfsArchive deployment) throws DeploymentException, IllegalArgumentException
+ {
+ // Precondition check
+ if (deployment == null)
+ {
+ throw new IllegalArgumentException("deployment must be specified");
+ }
+
+ // Make a VFS Deployment
+ final VirtualFile root = deployment.getRoot();
+ final Deployment d = VFSDeploymentFactory.getInstance().createVFSDeployment(root);
+
+ // Deploy
+ this.deploy(d);
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Internal Helper Methods ------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Centralizes initialization for the constructors
+ *
+ * @param jbossHome
+ * @throws IllegalArgumentException If JBOSS_HOME is not specified
+ */
+ private void initialize(final String jbossHome) throws IllegalArgumentException
+ {
+ // Precondition check
if (jbossHome == null || jbossHome.length() == 0)
{
throw new IllegalArgumentException("JBOSS_HOME is required but was not specified");
@@ -142,52 +251,4 @@
// }
}
- //-------------------------------------------------------------------------------------||
- // Required Implementations -----------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /* (non-Javadoc)
- * @see org.jboss.embedded.core.server.JBossASEmbeddedServer#deploy(org.jboss.deployers.client.spi.Deployment)
- */
- @Override
- public void deploy(final Deployment deployment) throws DeploymentException, IllegalArgumentException
- {
- // Precondition check
- if (deployment == null)
- {
- throw new IllegalArgumentException("deployment must be specified");
- }
-
- // TODO Auto-generated method stub
- final Kernel kernel = this.getKernel();
- final KernelController controller = kernel.getController();
- final ControllerContext context = controller.getContext("MainDeployer", ControllerState.INSTALLED);
- if (context == null)
- {
- throw new IllegalStateException("Main deployer could not be found");
- }
- final Object target = context.getTarget();
- final MainDeployer mainDeployer = MainDeployer.class.cast(target);
- mainDeployer.deploy(deployment);
- mainDeployer.checkComplete();
- }
-
- /* (non-Javadoc)
- * @see org.jboss.embedded.core.server.JBossASEmbeddedServer#deploy(org.jboss.embedded.core.deployment.VirtualDeployment)
- */
- @Override
- public void deploy(final VirtualDeployment deployment) throws DeploymentException, IllegalArgumentException
- {
- // Precondition check
- if (deployment == null)
- {
- throw new IllegalArgumentException("deployment must be specified");
- }
-
- // Make a VFS Deployment
- final VirtualFile root = deployment.getRoot();
- final Deployment d = VFSDeploymentFactory.getInstance().createVFSDeployment(root);
- this.deploy(d);
- }
-
}
Added: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/SecurityActions.java
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/SecurityActions.java (rev 0)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/SecurityActions.java 2009-07-10 04:39:07 UTC (rev 91047)
@@ -0,0 +1,83 @@
+package org.jboss.embedded.core.server;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * SecurityActions
+ *
+ * A set of privileged actions that are not to leak out
+ * of this package
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+class SecurityActions
+{
+
+ //-------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------||
+
+ /**
+ * No external instanciation
+ */
+ private SecurityActions()
+ {
+
+ }
+
+ //-------------------------------------------------------------------------------||
+ // Utility Methods --------------------------------------------------------------||
+ //-------------------------------------------------------------------------------||
+
+ /**
+ * Obtains the system property with the specified key
+ *
+ * @param key
+ * @return
+ * @throws IllegalArgumentException If the key is null
+ */
+ static String getSystemProperty(final String key) throws IllegalArgumentException
+ {
+ // Precondition check
+ if (key == null)
+ {
+ throw new IllegalArgumentException("key was null");
+ }
+
+ // Get sysprop
+ return AccessController.doPrivileged(new PrivilegedAction<String>()
+ {
+ public String run()
+ {
+ return System.getProperty(key);
+ }
+ });
+ }
+
+ /**
+ * Obtains the environment variable with the specified key
+ *
+ * @param key
+ * @return
+ * @throws IllegalArgumentException If the key is null
+ */
+ static String getEnvironmentVariable(final String key) throws IllegalArgumentException
+ {
+ // Precondition check
+ if (key == null)
+ {
+ throw new IllegalArgumentException("key was null");
+ }
+
+ // Get envvar
+ return AccessController.doPrivileged(new PrivilegedAction<String>()
+ {
+ public String run()
+ {
+ return System.getenv(key);
+ }
+ });
+ }
+}
Property changes on: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/SecurityActions.java
___________________________________________________________________
Name: svn:executable
+ *
Copied: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/impl/base/AbstractVirtualArchive.java (from rev 91029, projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/deployment/AbstractVirtualDeployment.java)
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/impl/base/AbstractVirtualArchive.java (rev 0)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/impl/base/AbstractVirtualArchive.java 2009-07-10 04:39:07 UTC (rev 91047)
@@ -0,0 +1,274 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.embedded.core.virtual.impl.base;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.jboss.embedded.core.virtual.spi.ExtensibleVirtualArchive;
+import org.jboss.logging.Logger;
+
+/**
+ * AbstractVirtualDeployment
+ *
+ * Base implementation of {@link ExtensibleVirtualArchive}
+ *
+ * @see {@link ExtensibleVirtualArchive}
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public abstract class AbstractVirtualArchive<T extends ExtensibleVirtualArchive<T>>
+ implements
+ ExtensibleVirtualArchive<T>
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Logger
+ */
+ private static final Logger log = Logger.getLogger(AbstractVirtualArchive.class);
+
+ /**
+ * Extension for Java Archives
+ */
+ public static final String EXTENSION_JAR = ".jar";
+
+ /**
+ * Delimiter for paths while looking for resources
+ */
+ private static final char DELIMITER_RESOURCE_PATH = '/';
+
+ /**
+ * Delimiter for paths in fully-qualified class names
+ */
+ private static final char DELIMITER_CLASS_NAME_PATH = '.';
+
+ /**
+ * The filename extension appended to classes
+ */
+ private static final String EXTENSION_CLASS = ".class";
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * The ClassLoader used in loading resources and classes into the virtual deployment
+ */
+ private final ClassLoader classLoader;
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Constructor
+ *
+ * Creates a new {@link AbstractVirtualArchive} using the Thread Context
+ * ClassLoader.
+ *
+ * @param name Unique name for the deployment
+ * @throws IllegalArgumentException If the name was not specified
+ */
+ public AbstractVirtualArchive(final String name) throws IllegalArgumentException
+ {
+ this(name, SecurityActions.getThreadContextClassLoader());
+ }
+
+ /**
+ * Constructor
+ *
+ * @param name Unique name for the deployment
+ * @param cl ClassLoader to be used in loading resources and classes
+ * @throws IllegalArgumentException If the name, actual class or ClassLoader was not specified
+ */
+ public AbstractVirtualArchive(final String name, final ClassLoader cl) throws IllegalArgumentException
+ {
+ // Precondition check
+ if (name == null || name.length() == 0)
+ {
+ throw new IllegalArgumentException("name must be specified");
+ }
+ if (cl == null)
+ {
+ throw new IllegalArgumentException("ClassLoader must be specified");
+ }
+
+ // Set the CL
+ this.classLoader = cl;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.embedded.core.deployment.VirtualDeployment#addClass(java.lang.Class)
+ */
+ @Override
+ public T addClass(final Class<?> clazz) throws IllegalArgumentException
+ {
+ // Precondition check
+ if (clazz == null)
+ {
+ throw new IllegalArgumentException("Class must be specified");
+ }
+
+ // Get the resource name of the class
+ final String name = this.getResourceNameOfClass(clazz);
+
+ // Add it as a resource
+ if (log.isTraceEnabled())
+ {
+ log.trace("Adding class as resource: " + clazz);
+ }
+ return this.addResource(name);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.embedded.core.deployment.VirtualDeployment#addClasses(java.lang.Class<?>[])
+ */
+ @Override
+ public T addClasses(final Class<?>... classes) throws IllegalArgumentException
+ {
+ // Precondition check
+ if (classes == null || classes.length == 0)
+ {
+ throw new IllegalArgumentException("At least one class must be specified");
+ }
+
+ // For each class
+ for (final Class<?> clazz : classes)
+ {
+ this.addClass(clazz);
+ }
+
+ // Return
+ return this.covarientReturn();
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Contracts --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Obtains the actual class (type) of this instance, used
+ * in covarient return (casting)
+ *
+ * @return the actualClass
+ */
+ protected abstract Class<T> getActualClass();
+
+ //-------------------------------------------------------------------------------------||
+ // Internal Helper Methods ------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Returns the name of the class such that it may be accessed via ClassLoader.getResource()
+ *
+ * @param clazz The class
+ * @throws IllegalArgumentException If the class was not specified
+ */
+ private String getResourceNameOfClass(final Class<?> clazz) throws IllegalArgumentException
+ {
+ // Precondition check
+ if (clazz == null)
+ {
+ throw new IllegalArgumentException("Class must be specified");
+ }
+
+ // Build the name
+ final String fqn = clazz.getName();
+ final String nameAsResourcePath = fqn.replace(DELIMITER_CLASS_NAME_PATH, DELIMITER_RESOURCE_PATH);
+ final String resourceName = nameAsResourcePath + EXTENSION_CLASS;
+
+ // Return
+ return resourceName;
+ }
+
+ /**
+ * Returns this instance as a typed server (as specified by K),
+ * throwing a descriptive error message in case the server is not assignable
+ */
+ protected final T covarientReturn()
+ {
+ // Get the actual class
+ final Class<T> actualClass = this.getActualClass();
+
+ // Cast
+ try
+ {
+ return actualClass.cast(this);
+ }
+ catch (ClassCastException cce)
+ {
+ throw new RuntimeException("Actual class is incorrect and " + actualClass
+ + " was not assignable to this instance: " + this, cce);
+ }
+ }
+
+ /**
+ * Copies and returns the specified URL. Used
+ * to ensure we don't export mutable URLs
+ *
+ * @param url
+ * @return
+ */
+ protected final URL copyURL(final URL url)
+ {
+ // If null, return
+ if (url == null)
+ {
+ return url;
+ }
+
+ try
+ {
+ // Copy
+ return new URL(url.toExternalForm());
+ }
+ catch (MalformedURLException e)
+ {
+ throw new RuntimeException("Error in copying URL", e);
+ }
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Accessors / Mutators ---------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Returns the ClassLoader used to load classes
+ * and resources into this virtual deployment
+ *
+ * @return
+ */
+ protected final ClassLoader getClassLoader()
+ {
+ return this.classLoader;
+ }
+}
Copied: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/impl/base/ResourceNotFoundException.java (from rev 91029, projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/deployment/ResourceNotFoundException.java)
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/impl/base/ResourceNotFoundException.java (rev 0)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/impl/base/ResourceNotFoundException.java 2009-07-10 04:39:07 UTC (rev 91047)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.embedded.core.virtual.impl.base;
+
+/**
+ * ResourceNotFoundException
+ *
+ * Thrown when a resource is requested, but could not be found
+ * within the context of the given ClassLoader
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class ResourceNotFoundException extends IllegalArgumentException
+{
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * serialVersionUID
+ */
+ private static final long serialVersionUID = 1L;
+
+ //-------------------------------------------------------------------------------------||
+ // Constructors -----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ public ResourceNotFoundException()
+ {
+ super();
+ }
+
+ public ResourceNotFoundException(final String message, final Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ public ResourceNotFoundException(final String s)
+ {
+ super(s);
+ }
+
+ public ResourceNotFoundException(final Throwable cause)
+ {
+ super(cause);
+ }
+
+}
Added: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/impl/base/SecurityActions.java
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/impl/base/SecurityActions.java (rev 0)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/impl/base/SecurityActions.java 2009-07-10 04:39:07 UTC (rev 91047)
@@ -0,0 +1,47 @@
+package org.jboss.embedded.core.virtual.impl.base;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * SecurityActions
+ *
+ * A set of privileged actions that are not to leak out
+ * of this package
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+class SecurityActions
+{
+
+ //-------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------||
+
+ /**
+ * No external instanciation
+ */
+ private SecurityActions()
+ {
+
+ }
+
+ //-------------------------------------------------------------------------------||
+ // Utility Methods --------------------------------------------------------------||
+ //-------------------------------------------------------------------------------||
+
+ /**
+ * Obtains the Thread Context ClassLoader
+ */
+ static ClassLoader getThreadContextClassLoader()
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
+ public ClassLoader run()
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ }
+}
Property changes on: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/impl/base/SecurityActions.java
___________________________________________________________________
Name: svn:executable
+ *
Added: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/impl/vfs/SecurityActions.java
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/impl/vfs/SecurityActions.java (rev 0)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/impl/vfs/SecurityActions.java 2009-07-10 04:39:07 UTC (rev 91047)
@@ -0,0 +1,47 @@
+package org.jboss.embedded.core.virtual.impl.vfs;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * SecurityActions
+ *
+ * A set of privileged actions that are not to leak out
+ * of this package
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+class SecurityActions
+{
+
+ //-------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------||
+
+ /**
+ * No external instanciation
+ */
+ private SecurityActions()
+ {
+
+ }
+
+ //-------------------------------------------------------------------------------||
+ // Utility Methods --------------------------------------------------------------||
+ //-------------------------------------------------------------------------------||
+
+ /**
+ * Obtains the Thread Context ClassLoader
+ */
+ static ClassLoader getThreadContextClassLoader()
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
+ public ClassLoader run()
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ }
+}
Property changes on: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/impl/vfs/SecurityActions.java
___________________________________________________________________
Name: svn:executable
+ *
Copied: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/impl/vfs/VirtualVfsArchiveImpl.java (from rev 91029, projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/deployment/VirtualDeploymentImpl.java)
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/impl/vfs/VirtualVfsArchiveImpl.java (rev 0)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/impl/vfs/VirtualVfsArchiveImpl.java 2009-07-10 04:39:07 UTC (rev 91047)
@@ -0,0 +1,420 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.embedded.core.virtual.impl.vfs;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.List;
+
+import org.jboss.embedded.core.virtual.impl.base.AbstractVirtualArchive;
+import org.jboss.embedded.core.virtual.impl.base.ResourceNotFoundException;
+import org.jboss.embedded.core.virtual.spi.vfs.VirtualVfsArchive;
+import org.jboss.logging.Logger;
+import org.jboss.virtual.MemoryFileFactory;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * VirtualVfsArchiveImpl
+ *
+ * Concrete implementation of a VFS-backed virtual deployment
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class VirtualVfsArchiveImpl extends AbstractVirtualArchive<VirtualVfsArchive> implements VirtualVfsArchive
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Logger
+ */
+ private static final Logger log = Logger.getLogger(VirtualVfsArchiveImpl.class);
+
+ /**
+ * Protocol of VFS in-memory
+ */
+ private static final String PROTOCOL_VFS_MEMORY = "vfsmemory";
+
+ /**
+ * Newline character
+ */
+ private static final char NEWLINE = '\n';
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * The root of the deployment
+ */
+ private final VirtualFile root;
+
+ /**
+ * The URL to the root deployment
+ */
+ private final URL rootUrl;
+
+ //-------------------------------------------------------------------------------------||
+ // Constructors -----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Constructor
+ *
+ * Creates a new instance using the Thread Context
+ * ClassLoader.
+ *
+ * @param name Unique name for the deployment
+ * @throws IllegalArgumentException If the name was not specified
+ */
+ public VirtualVfsArchiveImpl(final String name) throws IllegalArgumentException
+ {
+ this(name, SecurityActions.getThreadContextClassLoader());
+ }
+
+ /**
+ * Constructor
+ *
+ * @param name Unique name for the deployment
+ * @param cl ClassLoader to be used in loading resources and classes
+ * @throws IllegalArgumentException If the name, actual class or ClassLoader was not specified
+ */
+ public VirtualVfsArchiveImpl(final String name, final ClassLoader cl) throws IllegalArgumentException
+ {
+ // Invoke super
+ super(name, cl);
+
+ // Create the root for the deployment
+ VirtualFile file = null;
+ URL url = null;
+ try
+ {
+ final URL memoryRootUrl = new URL(PROTOCOL_VFS_MEMORY, name, "");
+ MemoryFileFactory.createRoot(memoryRootUrl);
+ url = memoryRootUrl;
+ file = VFS.getRoot(memoryRootUrl);
+ }
+ catch (final IOException ioe)
+ {
+ throw new RuntimeException("Error in creating the root for virtual deployment \"" + name + "\"", ioe);
+ }
+
+ // Set properties for the root
+ this.root = file;
+ this.rootUrl = url;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.embedded.core.deployment.AbstractVirtualDeployment#getActualClass()
+ */
+ @Override
+ protected Class<VirtualVfsArchive> getActualClass()
+ {
+ return VirtualVfsArchive.class;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.embedded.core.deployment.ExtensibleVirtualVfsArchive#getRoot()
+ */
+ @Override
+ public VirtualFile getRoot()
+ {
+ return this.root;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.embedded.core.deployment.VirtualDeployment#addResource(java.lang.String)
+ */
+ @Override
+ public VirtualVfsArchive addResource(final String name) throws IllegalArgumentException
+ {
+ // Precondition check
+ if (name == null || name.length() == 0)
+ {
+ throw new IllegalArgumentException("name must be specified");
+ }
+
+ // Get the content of the resource
+ byte[] content = null;
+ try
+ {
+ content = this.getBytesOfResource(name);
+ }
+ catch (final IOException ioe)
+ {
+ throw new RuntimeException("Could not add resource \"" + name + "\" to " + this, ioe);
+ }
+
+ // Get the root URL of the memory file
+ final URL rootUrl = this.getRootUrl();
+
+ // Construct a new URL for this new memoryfile
+ URL newUrl = null;
+ try
+ {
+ newUrl = new URL(rootUrl, name);
+ }
+ catch (final MalformedURLException murle)
+ {
+ throw new RuntimeException("Could not form URL for new resource \"" + name + "\" in " + this, murle);
+ }
+
+ // Put the new memory file in place
+ MemoryFileFactory.putFile(newUrl, content);
+ log.debug("Added \"" + name + "\": " + newUrl);
+
+ // Return
+ return this.covarientReturn();
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.embedded.core.deployment.ExtensibleVirtualDeployment#toString(boolean)
+ */
+ @Override
+ public String toString(final boolean verbose)
+ {
+ // If we want verbose output
+ if (verbose)
+ {
+ // Describe the root
+ return this.describe(this.getRoot());
+ }
+
+ // Fall back on toString
+ return this.toString();
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Internal Helper Methods ------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Obtains the contents (bytes) of the specified resource
+ *
+ * @param name
+ * @return
+ * @throws IOException
+ * @throws IllegalArgumentException If the name is not specified
+ */
+ private byte[] getBytesOfResource(final String name) throws IOException, IllegalArgumentException
+ {
+ // Precondition check
+ if (name == null || name.length() == 0)
+ {
+ throw new IllegalArgumentException("name must be specified");
+ }
+
+ // Get the URL
+ final URL resourceUrl = this.getResourceUrl(name);
+
+ // Open a connection and read in all the bytes
+ final URLConnection connection = resourceUrl.openConnection();
+ final int length = connection.getContentLength();
+ assert length > -1 : "Content length is not known";
+ byte contents[] = new byte[length];
+ final InputStream in = connection.getInputStream();
+ int read = 0;
+ int currentLocation = 0;
+ int bytesToRead = 1024;
+ // Avoid ArrayIndexOutOfBounds by adjusting back the bytes we read in
+ if (bytesToRead + currentLocation > length)
+ {
+ bytesToRead = length;
+ }
+
+ // Read into the byte array
+ while ((read = (in.read(contents, currentLocation, bytesToRead))) > 0)
+ {
+ // Mark our new offset
+ currentLocation += read;
+
+ // Avoid ArrayIndexOutOfBounds
+ if (bytesToRead + currentLocation > length)
+ {
+ bytesToRead = length - currentLocation;
+ }
+ }
+
+ // Close up the stream
+ in.close();
+
+ // Return the byte array
+ if (log.isTraceEnabled())
+ {
+ log.trace("Read " + contents.length + " bytes for: " + name);
+ }
+ return contents;
+ }
+
+ /**
+ * Describes this file in form:
+ *
+ * "/path/resource.ext - x bytes"
+ *
+ * In addition to all children of the given file root.
+ *
+ * @param file The root to describe
+ * @return
+ * @throws IllegalArgumentException If either the file or builder are not specified
+ */
+ private String describe(final VirtualFile file)
+ {
+ // Precondition checks
+ if (file == null)
+ {
+ throw new IllegalArgumentException("file must be specified");
+ }
+
+ // Make a StringBuilder
+ final StringBuilder sb = new StringBuilder();
+
+ // Start the output
+ sb.append(file);
+ sb.append(NEWLINE);
+
+ // Describe in depth
+ return this.describe(file, sb);
+ }
+
+ /**
+ * Describes this file in form:
+ *
+ * "/path/resource.ext - x bytes"
+ *
+ * In addition to all children of the given file root.
+ *
+ * @param file The root to describe
+ * @param sb The builder to which the description will be appended
+ * @return
+ * @throws IllegalArgumentException If either the file or builder are not specified
+ */
+ private String describe(final VirtualFile file, final StringBuilder sb) throws IllegalArgumentException
+ {
+ // Precondition checks
+ if (file == null)
+ {
+ throw new IllegalArgumentException("file must be specified");
+ }
+ if (sb == null)
+ {
+ throw new IllegalArgumentException("builder must be specified");
+ }
+
+ // Get information for this root
+ final String path = file.getPathName();
+ final long size;
+ try
+ {
+ size = file.getSize();
+ }
+ catch (final IOException ioe)
+ {
+ throw new RuntimeException("Could not get size for: " + file, ioe);
+ }
+
+ // Append this information
+ sb.append(path);
+ sb.append(" - ");
+ sb.append(size);
+ sb.append(" bytes");
+ sb.append(NEWLINE);
+
+ // Recurse into any children
+ final List<VirtualFile> children;
+ try
+ {
+ children = file.getChildren();
+ }
+ catch (final IOException ioe)
+ {
+ throw new RuntimeException("Could not obtain children for: " + file, ioe);
+ }
+ if (children != null && children.size() > 0)
+ {
+ for (final VirtualFile child : children)
+ {
+ this.describe(child, sb);
+ }
+ }
+
+ // Return
+ return sb.toString();
+ }
+
+ /**
+ * Obtains the URL of the resource with the requested name.
+ * The search order is described by {@link ClassLoader#getResource(String)}
+ *
+ * @param name
+ * @return
+ * @throws IllegalArgumentException If name is not specified or could not
+ */
+ private URL getResourceUrl(final String name) throws IllegalArgumentException
+ {
+ // Precondition check
+ if (name == null || name.length() == 0)
+ {
+ throw new IllegalArgumentException("name must be specified");
+ }
+
+ // Find
+ final ClassLoader cl = this.getClassLoader();
+ final URL url = cl.getResource(name);
+
+ // Ensure found
+ if (url == null)
+ {
+ throw new ResourceNotFoundException("Could not find resource with name \"" + name + "\" in: " + cl);
+ }
+
+ // Return
+ return url;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Accessors / Mutators ---------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Returns a copy of this root's URL (not the
+ * actual reference as we want to protect internal
+ * state from mutation)
+ * @return
+ */
+ protected final URL getRootUrl()
+ {
+ return this.copyURL(this.rootUrl);
+ }
+}
Copied: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/spi/ExtensibleVirtualArchive.java (from rev 91029, projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/deployment/ExtensibleVirtualDeployment.java)
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/spi/ExtensibleVirtualArchive.java (rev 0)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/spi/ExtensibleVirtualArchive.java 2009-07-10 04:39:07 UTC (rev 91047)
@@ -0,0 +1,82 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.embedded.core.virtual.spi;
+
+import org.jboss.embedded.core.virtual.tempdev.VirtualDeploymentGroup;
+
+/**
+ * ExtensibleVirtualArchive
+ *
+ * Represents a single in-memory collection of resources which may
+ * be constructed declaratively / programmatically.
+ *
+ * @see {@link VirtualDeploymentGroup}
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @author <a href="bill at jboss.com">Bill Burke</a>
+ * @author adrian at jboss.org
+ * @version $Revision: $
+ */
+public interface ExtensibleVirtualArchive<T extends ExtensibleVirtualArchive<T>>
+{
+ //-------------------------------------------------------------------------------------||
+ // Contracts --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Adds the specified Class to the deployment
+ *
+ * @param The class to add
+ * @return This virtual deployment
+ * @throws IllegalArgumentException If no class was specified
+ */
+ T addClass(Class<?> clazz) throws IllegalArgumentException;
+
+ /**
+ * Adds the specified Classes to the deployment.
+ *
+ * @param classes
+ * @return This virtual deployment
+ * @throws IllegalArgumentException If no classes were specified
+ */
+ T addClasses(Class<?>... classes) throws IllegalArgumentException;
+
+ /**
+ * Adds the resource with the specified name to the
+ * deployment. The resource name must be visible to the ClassLoader
+ * of the deployment
+ *
+ * @param name
+ * @return
+ * @throws IllegalArgumentException If the name was not specified
+ */
+ T addResource(String name) throws IllegalArgumentException;
+
+ /**
+ * Returns a multiline "ls -l"-equse output of the contents of
+ * this deployment and (recursively) its children if the verbosity
+ * flag is set to "true". Otherwise the no-arg version is invoked
+ *
+ * @return
+ */
+ String toString(boolean verbose);
+
+}
Added: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/spi/vfs/ExtensibleVirtualVfsArchive.java
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/spi/vfs/ExtensibleVirtualVfsArchive.java (rev 0)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/spi/vfs/ExtensibleVirtualVfsArchive.java 2009-07-10 04:39:07 UTC (rev 91047)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.embedded.core.virtual.spi.vfs;
+
+import org.jboss.embedded.core.virtual.spi.ExtensibleVirtualArchive;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * ExtensibleVirtualVfsArchive
+ *
+ * An in-memory collection of resources backed by
+ * JBoss VFS (Virtual File System) which may be extended
+ * to provide true typesafe covarient return in method chaining
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface ExtensibleVirtualVfsArchive<T extends ExtensibleVirtualVfsArchive<T>>
+ extends
+ ExtensibleVirtualArchive<T>
+{
+ //-------------------------------------------------------------------------------------||
+ // Contracts --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Obtains the VFS file which is the root level
+ * of this deployment
+ *
+ * @return
+ */
+ VirtualFile getRoot();
+}
Copied: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/spi/vfs/VirtualVfsArchive.java (from rev 91029, projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/deployment/VirtualDeployment.java)
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/spi/vfs/VirtualVfsArchive.java (rev 0)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/spi/vfs/VirtualVfsArchive.java 2009-07-10 04:39:07 UTC (rev 91047)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.embedded.core.virtual.spi.vfs;
+
+
+/**
+ * VirtualVfsArchive
+ *
+ * Represents a single in-memory collectdeploymention
+ * of resources which may
+ * be constructed declaratively / programmatically.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface VirtualVfsArchive extends ExtensibleVirtualVfsArchive<VirtualVfsArchive>
+{
+ /*
+ * API inherited; this type in
+ * place to define generics
+ */
+}
Copied: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/tempdev (from rev 91029, projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/deployment)
Deleted: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/tempdev/AbstractVirtualDeployment.java
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/deployment/AbstractVirtualDeployment.java 2009-07-09 22:37:28 UTC (rev 91029)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/tempdev/AbstractVirtualDeployment.java 2009-07-10 04:39:07 UTC (rev 91047)
@@ -1,580 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, 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.embedded.core.deployment;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLConnection;
-import java.util.List;
-
-import org.jboss.logging.Logger;
-import org.jboss.virtual.MemoryFileFactory;
-import org.jboss.virtual.VFS;
-import org.jboss.virtual.VirtualFile;
-
-/**
- * AbstractVirtualDeployment
- *
- * Base implementation of {@link ExtensibleVirtualDeployment}
- *
- * @see {@link ExtensibleVirtualDeployment}
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-public abstract class AbstractVirtualDeployment<T extends ExtensibleVirtualDeployment<T>>
- implements
- ExtensibleVirtualDeployment<T>
-{
-
- //-------------------------------------------------------------------------------------||
- // Class Members ----------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Logger
- */
- private static final Logger log = Logger.getLogger(AbstractVirtualDeployment.class);
-
- /**
- * Protocol of VFS in-memory
- */
- private static final String PROTOCOL_VFS_MEMORY = "vfsmemory";
-
- /**
- * Extension for Java Archives
- */
- public static final String EXTENSION_JAR = ".jar";
-
- /**
- * Delimiter for paths while looking for resources
- */
- private static final char DELIMITER_RESOURCE_PATH = '/';
-
- /**
- * Delimiter for paths in fully-qualified class names
- */
- private static final char DELIMITER_CLASS_NAME_PATH = '.';
-
- /**
- * The filename extension appended to classes
- */
- private static final String EXTENSION_CLASS = ".class";
-
- /**
- * Newline character
- */
- private static final char NEWLINE = '\n';
-
- //-------------------------------------------------------------------------------------||
- // Instance Members -------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * The root of the deployment
- */
- private final VirtualFile root;
-
- /**
- * The URL to the root deployment
- */
- private final URL rootUrl;
-
- /**
- * The ClassLoader used in loading resources and classes into the virtual deployment
- */
- private final ClassLoader classLoader;
-
- //-------------------------------------------------------------------------------------||
- // Constructor ------------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Constructor
- *
- * Creates a new {@link AbstractVirtualDeployment} using the Thread Context
- * ClassLoader.
- *
- * @param name Unique name for the deployment
- * @throws IllegalArgumentException If the name was not specified
- */
- public AbstractVirtualDeployment(final String name) throws IllegalArgumentException
- {
- this(name, SecurityActions.getThreadContextClassLoader());
- }
-
- /**
- * Constructor
- *
- * @param name Unique name for the deployment
- * @param cl ClassLoader to be used in loading resources and classes
- * @throws IllegalArgumentException If the name, actual class or ClassLoader was not specified
- */
- public AbstractVirtualDeployment(final String name, final ClassLoader cl) throws IllegalArgumentException
- {
- // Precondition check
- if (name == null || name.length() == 0)
- {
- throw new IllegalArgumentException("name must be specified");
- }
- if (cl == null)
- {
- throw new IllegalArgumentException("ClassLoader must be specified");
- }
-
- // Create the root for the deployment
- VirtualFile file = null;
- URL url = null;
- try
- {
- final URL memoryRootUrl = new URL(PROTOCOL_VFS_MEMORY, name, "");
- MemoryFileFactory.createRoot(memoryRootUrl);
- url = memoryRootUrl;
- file = VFS.getRoot(memoryRootUrl);
- }
- catch (final IOException ioe)
- {
- throw new RuntimeException("Error in creating the root for virtual deployment \"" + name + "\"", ioe);
- }
-
- // Set properties for the root
- this.root = file;
- this.rootUrl = url;
-
- // Set the CL
- this.classLoader = cl;
- }
-
- //-------------------------------------------------------------------------------------||
- // Required Implementations -----------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /*
- * (non-Javadoc)
- * @see org.jboss.embedded.core.deployment.VirtualDeployment#addClass(java.lang.Class)
- */
- @Override
- public T addClass(final Class<?> clazz) throws IllegalArgumentException
- {
- // Precondition check
- if (clazz == null)
- {
- throw new IllegalArgumentException("Class must be specified");
- }
-
- // Get the resource name of the class
- final String name = this.getResourceNameOfClass(clazz);
-
- // Add it as a resource
- return this.addResource(name);
- }
-
- /*
- * (non-Javadoc)
- * @see org.jboss.embedded.core.deployment.VirtualDeployment#addClasses(java.lang.Class<?>[])
- */
- @Override
- public T addClasses(final Class<?>... classes) throws IllegalArgumentException
- {
- // Precondition check
- if (classes == null || classes.length == 0)
- {
- throw new IllegalArgumentException("At least one class must be specified");
- }
-
- // For each class
- for (final Class<?> clazz : classes)
- {
- this.addClass(clazz);
- }
-
- // Return
- return this.covarientReturn();
- }
-
- /* (non-Javadoc)
- * @see org.jboss.embedded.core.deployment.VirtualDeployment#addResource(java.lang.String)
- */
- @Override
- public T addResource(final String name) throws IllegalArgumentException
- {
- // Precondition check
- if (name == null || name.length() == 0)
- {
- throw new IllegalArgumentException("name must be specified");
- }
-
- // Get the content of the resource
- byte[] content = null;
- try
- {
- content = this.getBytesOfResource(name);
- }
- catch (final IOException ioe)
- {
- throw new RuntimeException("Could not add resource \"" + name + "\" to " + this, ioe);
- }
-
- // Get the root URL of the memory file
- final URL rootUrl = this.getRootUrl();
-
- // Construct a new URL for this new memoryfile
- URL newUrl = null;
- try
- {
- newUrl = new URL(rootUrl, name);
- }
- catch (final MalformedURLException murle)
- {
- throw new RuntimeException("Could not form URL for new resource \"" + name + "\" in " + this, murle);
- }
-
- // Put the new memory file in place
- MemoryFileFactory.putFile(newUrl, content);
- log.debug("Added \"" + name + "\": " + newUrl);
-
- // Return
- return this.covarientReturn();
- }
-
- /* (non-Javadoc)
- * @see org.jboss.embedded.core.deployment.ExtensibleVirtualDeployment#toString(boolean)
- */
- @Override
- public String toString(final boolean verbose)
- {
- // If we want verbose output
- if (verbose)
- {
- // Describe the root
- return this.describe(this.getRoot());
- }
-
- // Fall back on toString
- return this.toString();
- }
-
- /* (non-Javadoc)
- * @see org.jboss.embedded.core.deployment.ExtensibleVirtualDeployment#getRoot()
- */
- @Override
- public VirtualFile getRoot()
- {
- return this.root;
- }
-
- //-------------------------------------------------------------------------------------||
- // Contracts --------------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Obtains the actual class (type) of this instance, used
- * in covarient return (casting)
- *
- * @return the actualClass
- */
- protected abstract Class<T> getActualClass();
-
- //-------------------------------------------------------------------------------------||
- // Internal Helper Methods ------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Returns the name of the class such that it may be accessed via ClassLoader.getResource()
- *
- * @param clazz The class
- * @throws IllegalArgumentException If the class was not specified
- */
- private String getResourceNameOfClass(final Class<?> clazz) throws IllegalArgumentException
- {
- // Precondition check
- if (clazz == null)
- {
- throw new IllegalArgumentException("Class must be specified");
- }
-
- // Build the name
- final String fqn = clazz.getName();
- final String nameAsResourcePath = fqn.replace(DELIMITER_CLASS_NAME_PATH, DELIMITER_RESOURCE_PATH);
- final String resourceName = nameAsResourcePath + EXTENSION_CLASS;
-
- // Return
- return resourceName;
- }
-
- /**
- * Obtains the URL of the resource with the requested name.
- * The search order is described by {@link ClassLoader#getResource(String)}
- *
- * @param name
- * @return
- * @throws IllegalArgumentException If name is not specified or could not
- */
- private URL getResourceUrl(final String name) throws IllegalArgumentException
- {
- // Precondition check
- if (name == null || name.length() == 0)
- {
- throw new IllegalArgumentException("name must be specified");
- }
-
- // Find
- final ClassLoader cl = this.getClassLoader();
- final URL url = cl.getResource(name);
-
- // Ensure found
- if (url == null)
- {
- throw new ResourceNotFoundException("Could not find resource with name \"" + name + "\" in: " + cl);
- }
-
- // Return
- return url;
- }
-
- /**
- * Obtains the contents (bytes) of the specified resource
- *
- * @param name
- * @return
- * @throws IOException
- * @throws IllegalArgumentException If the name is not specified
- */
- private byte[] getBytesOfResource(final String name) throws IOException, IllegalArgumentException
- {
- // Precondition check
- if (name == null || name.length() == 0)
- {
- throw new IllegalArgumentException("name must be specified");
- }
-
- // Get the URL
- final URL resourceUrl = this.getResourceUrl(name);
-
- // Open a connection and read in all the bytes
- final URLConnection connection = resourceUrl.openConnection();
- final int length = connection.getContentLength();
- assert length > -1 : "Content length is not known";
- byte contents[] = new byte[length];
- final InputStream in = connection.getInputStream();
- int read = 0;
- int currentLocation = 0;
- int bytesToRead = 1024;
- // Avoid ArrayIndexOutOfBounds by adjusting back the bytes we read in
- if (bytesToRead + currentLocation > length)
- {
- bytesToRead = length;
- }
-
- // Read into the byte array
- while ((read = (in.read(contents, currentLocation, bytesToRead))) > 0)
- {
- // Mark our new offset
- currentLocation += read;
-
- // Avoid ArrayIndexOutOfBounds
- if (bytesToRead + currentLocation > length)
- {
- bytesToRead = length - currentLocation;
- }
- }
-
- // Close up the stream
- in.close();
-
- // Return the byte array
- if (log.isTraceEnabled())
- {
- log.trace("Read " + contents.length + " bytes for: " + name);
- }
- return contents;
- }
-
- /**
- * Returns this instance as a typed server (as specified by K),
- * throwing a descriptive error message in case the server is not assignable
- */
- protected final T covarientReturn()
- {
- // Get the actual class
- final Class<T> actualClass = this.getActualClass();
-
- // Cast
- try
- {
- return actualClass.cast(this);
- }
- catch (ClassCastException cce)
- {
- throw new RuntimeException("Actual class is incorrect and " + actualClass
- + " was not assignable to this instance: " + this, cce);
- }
- }
-
- /**
- * Describes this file in form:
- *
- * "/path/resource.ext - x bytes"
- *
- * In addition to all children of the given file root.
- *
- * @param file The root to describe
- * @return
- * @throws IllegalArgumentException If either the file or builder are not specified
- */
- private String describe(final VirtualFile file)
- {
- // Precondition checks
- if (file == null)
- {
- throw new IllegalArgumentException("file must be specified");
- }
-
- // Make a StringBuilder
- final StringBuilder sb = new StringBuilder();
-
- // Start the output
- sb.append(file);
- sb.append(NEWLINE);
-
- // Describe in depth
- return this.describe(file, sb);
- }
-
- /**
- * Describes this file in form:
- *
- * "/path/resource.ext - x bytes"
- *
- * In addition to all children of the given file root.
- *
- * @param file The root to describe
- * @param sb The builder to which the description will be appended
- * @return
- * @throws IllegalArgumentException If either the file or builder are not specified
- */
- private String describe(final VirtualFile file, final StringBuilder sb) throws IllegalArgumentException
- {
- // Precondition checks
- if (file == null)
- {
- throw new IllegalArgumentException("file must be specified");
- }
- if (sb == null)
- {
- throw new IllegalArgumentException("builder must be specified");
- }
-
- // Get information for this root
- final String path = file.getPathName();
- final long size;
- try
- {
- size = file.getSize();
- }
- catch (final IOException ioe)
- {
- throw new RuntimeException("Could not get size for: " + file, ioe);
- }
-
- // Append this information
- sb.append(path);
- sb.append(" - ");
- sb.append(size);
- sb.append(" bytes");
- sb.append(NEWLINE);
-
- // Recurse into any children
- final List<VirtualFile> children;
- try
- {
- children = file.getChildren();
- }
- catch (final IOException ioe)
- {
- throw new RuntimeException("Could not obtain children for: " + file, ioe);
- }
- if (children != null && children.size() > 0)
- {
- for (final VirtualFile child : children)
- {
- this.describe(child, sb);
- }
- }
-
- // Return
- return sb.toString();
- }
-
- /**
- * Copies and returns the specified URL. Used
- * to ensure we don't export mutable URLs
- *
- * @param url
- * @return
- */
- protected final URL copyURL(final URL url)
- {
- // If null, return
- if (url == null)
- {
- return url;
- }
-
- try
- {
- // Copy
- return new URL(url.toExternalForm());
- }
- catch (MalformedURLException e)
- {
- throw new RuntimeException("Error in copying URL", e);
- }
- }
-
- //-------------------------------------------------------------------------------------||
- // Accessors / Mutators ---------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Returns the ClassLoader used to load classes
- * and resources into this virtual deployment
- *
- * @return
- */
- protected final ClassLoader getClassLoader()
- {
- return this.classLoader;
- }
-
- /**
- * Returns a copy of this root's URL (not the
- * actual reference as we want to protect internal
- * state from mutation)
- * @return
- */
- protected final URL getRootUrl()
- {
- return this.copyURL(this.rootUrl);
- }
-}
Deleted: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/tempdev/ExtensibleVirtualDeployment.java
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/deployment/ExtensibleVirtualDeployment.java 2009-07-09 22:37:28 UTC (rev 91029)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/tempdev/ExtensibleVirtualDeployment.java 2009-07-10 04:39:07 UTC (rev 91047)
@@ -1,90 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, 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.embedded.core.deployment;
-
-import org.jboss.virtual.VirtualFile;
-
-/**
- * ExtensibleVirtualDeployment
- *
- * Represents a single in-memory deployment which may
- * be constructed declaratively / programmatically.
- *
- * @see {@link VirtualDeploymentGroup}
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @author <a href="bill at jboss.com">Bill Burke</a>
- * @author adrian at jboss.org
- * @version $Revision: $
- */
-public interface ExtensibleVirtualDeployment<T extends ExtensibleVirtualDeployment<?>>
-{
- //-------------------------------------------------------------------------------------||
- // Contracts --------------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Adds the specified Class to the deployment
- *
- * @param The class to add
- * @return This virtual deployment
- * @throws IllegalArgumentException If no class was specified
- */
- T addClass(Class<?> clazz) throws IllegalArgumentException;
-
- /**
- * Adds the specified Classes to the deployment.
- *
- * @param classes
- * @return This virtual deployment
- * @throws IllegalArgumentException If no classes were specified
- */
- T addClasses(Class<?>... classes) throws IllegalArgumentException;
-
- /**
- * Adds the resource with the specified name to the
- * deployment. The resource name must be visible to the ClassLoader
- * of the deployment
- *
- * @param name
- * @return
- * @throws IllegalArgumentException If the name was not specified
- */
- T addResource(String name) throws IllegalArgumentException;
-
- /**
- * Returns a multiline "ls -l"-equse output of the contents of
- * this deployment and (recursively) its children if the verbosity
- * flag is set to "true". Otherwise the no-arg version is invoked
- *
- * @return
- */
- String toString(boolean verbose);
-
- /**
- * Obtains the VFS file which is the root level
- * of this deployment
- *
- * @return
- */
- VirtualFile getRoot();
-
-}
Deleted: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/tempdev/ResourceNotFoundException.java
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/deployment/ResourceNotFoundException.java 2009-07-09 22:37:28 UTC (rev 91029)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/tempdev/ResourceNotFoundException.java 2009-07-10 04:39:07 UTC (rev 91047)
@@ -1,68 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, 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.embedded.core.deployment;
-
-/**
- * ResourceNotFoundException
- *
- * Thrown when a resource is requested, but could not be found
- * within the context of the given ClassLoader
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-public class ResourceNotFoundException extends IllegalArgumentException
-{
- //-------------------------------------------------------------------------------------||
- // Class Members ----------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * serialVersionUID
- */
- private static final long serialVersionUID = 1L;
-
- //-------------------------------------------------------------------------------------||
- // Constructors -----------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- public ResourceNotFoundException()
- {
- super();
- }
-
- public ResourceNotFoundException(final String message, final Throwable cause)
- {
- super(message, cause);
- }
-
- public ResourceNotFoundException(final String s)
- {
- super(s);
- }
-
- public ResourceNotFoundException(final Throwable cause)
- {
- super(cause);
- }
-
-}
Deleted: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/tempdev/SecurityActions.java
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/deployment/SecurityActions.java 2009-07-09 22:37:28 UTC (rev 91029)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/tempdev/SecurityActions.java 2009-07-10 04:39:07 UTC (rev 91047)
@@ -1,47 +0,0 @@
-package org.jboss.embedded.core.deployment;
-
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-
-/**
- * SecurityActions
- *
- * A set of privileged actions that are not to leak out
- * of this package
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-class SecurityActions
-{
-
- //-------------------------------------------------------------------------------||
- // Constructor ------------------------------------------------------------------||
- //-------------------------------------------------------------------------------||
-
- /**
- * No external instanciation
- */
- private SecurityActions()
- {
-
- }
-
- //-------------------------------------------------------------------------------||
- // Utility Methods --------------------------------------------------------------||
- //-------------------------------------------------------------------------------||
-
- /**
- * Obtains the Thread Context ClassLoader
- */
- static ClassLoader getThreadContextClassLoader()
- {
- return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
- {
- public ClassLoader run()
- {
- return Thread.currentThread().getContextClassLoader();
- }
- });
- }
-}
Deleted: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/tempdev/VirtualDeployment.java
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/deployment/VirtualDeployment.java 2009-07-09 22:37:28 UTC (rev 91029)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/tempdev/VirtualDeployment.java 2009-07-10 04:39:07 UTC (rev 91047)
@@ -1,39 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, 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.embedded.core.deployment;
-
-/**
- * VirtualDeployment
- *
- * Represents a single in-memory deployment which may
- * be constructed declaratively / programmatically.
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-public interface VirtualDeployment extends ExtensibleVirtualDeployment<VirtualDeployment>
-{
- /*
- * API inherited from {@link ExtensibleVirtualDeployment}; this type in
- * place to define generics
- */
-}
Modified: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/tempdev/VirtualDeploymentFactory.java
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/deployment/VirtualDeploymentFactory.java 2009-07-09 22:37:28 UTC (rev 91029)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/tempdev/VirtualDeploymentFactory.java 2009-07-10 04:39:07 UTC (rev 91047)
@@ -19,7 +19,7 @@
* 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.embedded.core.deployment;
+package org.jboss.embedded.core.virtual.tempdev;
import java.io.IOException;
import java.net.URL;
Modified: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/tempdev/VirtualDeploymentGroup.java
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/deployment/VirtualDeploymentGroup.java 2009-07-09 22:37:28 UTC (rev 91029)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/tempdev/VirtualDeploymentGroup.java 2009-07-10 04:39:07 UTC (rev 91047)
@@ -19,11 +19,12 @@
* 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.embedded.core.deployment;
+package org.jboss.embedded.core.virtual.tempdev;
import java.util.Collection;
import org.jboss.deployers.vfs.spi.client.VFSDeployment;
+import org.jboss.embedded.core.virtual.spi.ExtensibleVirtualArchive;
/**
* VirtualDeploymentGroup
@@ -34,7 +35,7 @@
* classes or resources in arbitrary locations available
* either from a ClassLoader or Class Path.
*
- * @see {@link ExtensibleVirtualDeployment}
+ * @see {@link ExtensibleVirtualArchive}
* @author <a href="bill at jboss.com">Bill Burke</a>
* @author adrian at jboss.org
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
Modified: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/tempdev/VirtualDeploymentGroupImpl.java
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/deployment/VirtualDeploymentGroupImpl.java 2009-07-09 22:37:28 UTC (rev 91029)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/tempdev/VirtualDeploymentGroupImpl.java 2009-07-10 04:39:07 UTC (rev 91047)
@@ -19,7 +19,7 @@
* 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.embedded.core.deployment;
+package org.jboss.embedded.core.virtual.tempdev;
import java.util.Collection;
import java.util.Collections;
Deleted: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/tempdev/VirtualDeploymentImpl.java
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/deployment/VirtualDeploymentImpl.java 2009-07-09 22:37:28 UTC (rev 91029)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/tempdev/VirtualDeploymentImpl.java 2009-07-10 04:39:07 UTC (rev 91047)
@@ -1,77 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, 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.embedded.core.deployment;
-
-/**
- * VirtualDeploymentImpl
- *
- * Concrete implementation of a virtual deployment
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-public class VirtualDeploymentImpl extends AbstractVirtualDeployment<VirtualDeployment> implements VirtualDeployment
-{
- //-------------------------------------------------------------------------------------||
- // Constructors -----------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Constructor
- *
- * Creates a new {@link AbstractVirtualDeployment} using the Thread Context
- * ClassLoader.
- *
- * @param name Unique name for the deployment
- * @throws IllegalArgumentException If the name was not specified
- */
- public VirtualDeploymentImpl(final String name) throws IllegalArgumentException
- {
- super(name);
- }
-
- /**
- * Constructor
- *
- * @param name Unique name for the deployment
- * @param cl ClassLoader to be used in loading resources and classes
- * @throws IllegalArgumentException If the name, actual class or ClassLoader was not specified
- */
- public VirtualDeploymentImpl(final String name, final ClassLoader cl) throws IllegalArgumentException
- {
- super(name, cl);
- }
-
- //-------------------------------------------------------------------------------------||
- // Required Implementations -----------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /*
- * (non-Javadoc)
- * @see org.jboss.embedded.core.deployment.AbstractVirtualDeployment#getActualClass()
- */
- @Override
- protected Class<VirtualDeployment> getActualClass()
- {
- return VirtualDeployment.class;
- }
-}
Modified: projects/embedded/trunk/pom.xml
===================================================================
--- projects/embedded/trunk/pom.xml 2009-07-10 04:17:47 UTC (rev 91046)
+++ projects/embedded/trunk/pom.xml 2009-07-10 04:39:07 UTC (rev 91047)
@@ -34,7 +34,8 @@
<module>assembly</module>
<module>build</module>
<module>core</module>
- <module>testsuite</module>
+ <!-- <module>testsuite</module>
+ <module>testsuite-fulldep Leave these out for the time being -->
</modules>
</project>
Modified: projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/ServerTestCase.java
===================================================================
--- projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/ServerTestCase.java 2009-07-10 04:17:47 UTC (rev 91046)
+++ projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/ServerTestCase.java 2009-07-10 04:39:07 UTC (rev 91047)
@@ -22,11 +22,17 @@
//FIXME We have to be in org.jboss due to JMX getPackage in AS
package org.jboss;
-import junit.framework.TestCase;
+import javax.naming.InitialContext;
-import org.jboss.bootstrap.spi.as.server.JBossASServer;
+import junit.framework.Assert;
+
import org.jboss.bootstrap.spi.lifecycle.LifecycleState;
+import org.jboss.embedded.core.server.JBossASEmbeddedServer;
import org.jboss.embedded.core.server.JBossASEmbeddedServerImpl;
+import org.jboss.embedded.core.virtual.impl.vfs.VirtualVfsArchiveImpl;
+import org.jboss.embedded.core.virtual.spi.vfs.VirtualVfsArchive;
+import org.jboss.embedded.testsuite.fulldep.ejb3.slsb.OutputBean;
+import org.jboss.embedded.testsuite.fulldep.ejb3.slsb.OutputLocalBusiness;
import org.jboss.logging.Logger;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -66,23 +72,16 @@
// Class Members ----------------------------------------------------------------||
//-------------------------------------------------------------------------------||
+ /**
+ * Logger
+ */
private static final Logger log = Logger.getLogger(ServerTestCase.class);
/**
* The server instance
*/
- private static JBossASServer server;
+ private static JBossASEmbeddedServer server;
- /**
- * Environment Variable name for JBOSS_HOME
- */
- private static final String ENV_VAR_JBOSS_HOME = "JBOSS_HOME";
-
- /**
- * System property name for JBOSS_HOME
- */
- private static final String SYS_PROP_JBOSS_HOME = "jboss.home";
-
//-------------------------------------------------------------------------------||
// Lifecycle --------------------------------------------------------------------||
//-------------------------------------------------------------------------------||
@@ -95,23 +94,10 @@
@BeforeClass
public static void startEmbedddedAS() throws Exception
{
- // Get JBOSS_HOME
- String jbossHome = SecurityActions.getSystemProperty(SYS_PROP_JBOSS_HOME);
- if (jbossHome == null)
- {
- jbossHome = SecurityActions.getEnvironmentVariable(ENV_VAR_JBOSS_HOME);
- }
- if (jbossHome == null)
- {
- throw new IllegalStateException(
- "JBOSS_HOME must be specified for this test, either via environment variable \"" + ENV_VAR_JBOSS_HOME
- + "\" or system property \"" + SYS_PROP_JBOSS_HOME + "\".");
- }
+ // Make Server (will pull JBOSS_HOME from env var or sys prop)
+ server = new JBossASEmbeddedServerImpl();
+ log.info("Created: " + server);
- // Make Server
- log.info("Using JBOSS_HOME: " + jbossHome);
- server = new JBossASEmbeddedServerImpl(jbossHome);
-
// Start
log.info("Starting Server: " + server);
server.start();
@@ -139,14 +125,32 @@
//-------------------------------------------------------------------------------||
/**
- * Ensures that the server reports as running
+ * Tests virtual deployment by constructing an in-memory unit
+ * and deploying into the server. Invokes the EJB3 through a
+ * local business interface.
*/
@Test
- public void testServerStart() throws Exception
+ public void testVirtualEjb3Deployment() throws Exception
{
- log.info("testServerStart");
- final LifecycleState state = server.getState();
- final LifecycleState expected = LifecycleState.STARTED;
- TestCase.assertEquals("The server is not reporting as started", expected, state);
+ // Log
+ log.info("testVirtualEjb3Deployment");
+
+ // Make a deployment
+ final String name = "testDeployment.jar";
+ final VirtualVfsArchive deployment = new VirtualVfsArchiveImpl(name).addClasses(OutputBean.class,
+ OutputLocalBusiness.class);
+ log.info(deployment.toString(true));
+
+ // Deploy
+ server.deploy(deployment);
+
+ // Test
+ final OutputLocalBusiness bean = (OutputLocalBusiness) new InitialContext().lookup(OutputBean.class
+ .getSimpleName()
+ + "/local");;
+ final String output = bean.getOutput();
+ log.info("Got output: " + output);
+ Assert.assertEquals(OutputLocalBusiness.OUTPUT, output);
+
}
}
Modified: projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/TempDevelopmentOnlyTestCase.java
===================================================================
--- projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/TempDevelopmentOnlyTestCase.java 2009-07-10 04:17:47 UTC (rev 91046)
+++ projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/TempDevelopmentOnlyTestCase.java 2009-07-10 04:39:07 UTC (rev 91047)
@@ -22,17 +22,9 @@
//FIXME We have to be in org.jboss due to JMX getPackage in AS
package org.jboss;
-import javax.naming.InitialContext;
-
-import junit.framework.Assert;
-
import org.jboss.bootstrap.spi.lifecycle.LifecycleState;
-import org.jboss.embedded.core.deployment.VirtualDeployment;
-import org.jboss.embedded.core.deployment.VirtualDeploymentImpl;
import org.jboss.embedded.core.server.JBossASEmbeddedServer;
import org.jboss.embedded.core.server.JBossASEmbeddedServerImpl;
-import org.jboss.embedded.testsuite.fulldep.ejb3.slsb.OutputBean;
-import org.jboss.embedded.testsuite.fulldep.ejb3.slsb.OutputLocalBusiness;
import org.jboss.logging.Logger;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -73,8 +65,7 @@
@BeforeClass
public static void startEmbedddedAS() throws Exception
{
- // Get JBOSS_HOME
- //TODO From sysprop or envvar
+ //TODO Hack, this is a hardcoded JBOSS_HOME
String jbossHome = "/home/alrubinger/business/jboss/wc/jbossas/branches/Branch_5_x/build/output/jboss-5.2.0.Beta";
// Make Server
log.info("Using JBOSS_HOME: " + jbossHome);
@@ -106,31 +97,12 @@
//-------------------------------------------------------------------------------||
/**
- * Tests virtual deployment by constructing an in-memory unit and deploying into the server
+ * Empty marker for now, may be used for dev later
*/
@Test
- public void testVirtualDeployment() throws Exception
+ public void testSomething() throws Exception
{
- // Log
- log.info("testVirtualDeployment");
- // Make a deployment
- final String name = "testDeployment.jar";
- final VirtualDeployment deployment = new VirtualDeploymentImpl(name).addClasses(OutputBean.class,
- OutputLocalBusiness.class);
- log.info(deployment.toString(true));
-
- // Deploy
- server.deploy(deployment);
-
- // Test
- final OutputLocalBusiness bean = (OutputLocalBusiness) new InitialContext().lookup(OutputBean.class
- .getSimpleName()
- + "/local");;
- final String output = bean.getOutput();
- log.info("Got output: " + output);
- Assert.assertEquals(OutputLocalBusiness.OUTPUT, output);
-
}
}
More information about the jboss-cvs-commits
mailing list