[jboss-cvs] JBossAS SVN: r69938 - in projects/microcontainer/trunk: deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Feb 19 11:36:34 EST 2008
Author: adrian at jboss.org
Date: 2008-02-19 11:36:34 -0500 (Tue, 19 Feb 2008)
New Revision: 69938
Added:
projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/classloader/InMemoryClassesDeployer.java
Modified:
projects/microcontainer/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/VFSDeploymentContext.java
projects/microcontainer/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/VFSDeploymentUnit.java
projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/AbstractVFSDeploymentContext.java
projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/AbstractVFSDeploymentUnit.java
Log:
[JBMICROCONT-241] - Proper deployer for creating in memory classes virtual file - includes a couple of helper methods for adding things to the classpath
Added: projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/classloader/InMemoryClassesDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/classloader/InMemoryClassesDeployer.java (rev 0)
+++ projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/classloader/InMemoryClassesDeployer.java 2008-02-19 16:36:34 UTC (rev 69938)
@@ -0,0 +1,115 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.deployers.vfs.plugins.classloader;
+
+import java.net.URL;
+import java.util.List;
+
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.vfs.spi.deployer.AbstractVFSRealDeployer;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.util.id.GUID;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.plugins.context.memory.MemoryContextFactory;
+
+/**
+ * TempURLDeployer.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class InMemoryClassesDeployer extends AbstractVFSRealDeployer
+{
+ /** The name of the dynamic class root */
+ public static final String DYNAMIC_CLASS_URL_KEY = "DYNAMIC_CLASS_URL_KEY";
+
+ /** The name of the dynamic class root */
+ public static final String DYNAMIC_CLASS_KEY = "DYNAMIC_CLASS_KEY";
+
+ /** The memory context factory */
+ private MemoryContextFactory factory = MemoryContextFactory.getInstance();
+
+ /**
+ * Create a new TempURLDeployer.
+ */
+ public InMemoryClassesDeployer()
+ {
+ // Make it run before the classloader describe deployer
+ setStage(DeploymentStages.DESCRIBE);
+ setOutput(ClassLoadingMetaData.class);
+ setTopLevelOnly(true);
+ }
+
+ @Override
+ public void deploy(VFSDeploymentUnit unit) throws DeploymentException
+ {
+ try
+ {
+ URL dynamicClassRoot = new URL("vfsmemory://" + new GUID());
+ factory.createRoot(dynamicClassRoot);
+ URL classesURL = new URL(dynamicClassRoot, "classes");
+ VirtualFile classes = factory.createDirectory(classesURL).getVirtualFile();
+ unit.addAttachment(DYNAMIC_CLASS_URL_KEY, dynamicClassRoot);
+ unit.addAttachment(DYNAMIC_CLASS_KEY, classes);
+ unit.addClassPath(classes);
+ log.debug("Dynamic class root for " + unit.getName() + " is " + dynamicClassRoot);
+ }
+ catch (Exception e)
+ {
+ throw new DeploymentException("Error creating dynamic class root", e);
+ }
+ }
+
+ @Override
+ public void undeploy(VFSDeploymentUnit unit)
+ {
+ log.debug("Removing dynamic class root for " + unit.getName());
+ try
+ {
+ VirtualFile classes = unit.removeAttachment(DYNAMIC_CLASS_KEY, VirtualFile.class);
+ if (classes != null)
+ {
+ List<VirtualFile> classPath = unit.getClassPath();
+ if (classPath != null)
+ {
+ classPath.remove(classes);
+ unit.setClassPath(classPath);
+ }
+ }
+ }
+ finally
+ {
+ try
+ {
+ URL root = unit.removeAttachment(DYNAMIC_CLASS_URL_KEY, URL.class);
+ if (root != null)
+ factory.deleteRoot(root);
+ }
+ catch (Exception e)
+ {
+ log.warn("Error deleting dynamic class root for " + unit.getName(), e);
+ }
+ }
+ }
+}
Modified: projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/AbstractVFSDeploymentContext.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/AbstractVFSDeploymentContext.java 2008-02-19 16:10:48 UTC (rev 69937)
+++ projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/AbstractVFSDeploymentContext.java 2008-02-19 16:36:34 UTC (rev 69938)
@@ -287,6 +287,42 @@
log.trace("ClassPath for " + root.getPathName() + " is " + VFSUtils.getPathsString(paths));
}
+ public void addClassPath(List<VirtualFile> files)
+ {
+ if (files == null)
+ throw new IllegalArgumentException("Null files");
+
+ List<VirtualFile> classPath = getClassPath();
+ if (classPath == null)
+ classPath = new ArrayList<VirtualFile>();
+
+ for (VirtualFile file : files)
+ {
+ if (file == null)
+ throw new IllegalArgumentException("Null virtual file in " + files);
+ classPath.add(file);
+ }
+ setClassPath(classPath);
+ }
+
+ public void addClassPath(VirtualFile... files)
+ {
+ if (files == null)
+ throw new IllegalArgumentException("Null files");
+
+ List<VirtualFile> classPath = getClassPath();
+ if (classPath == null)
+ classPath = new ArrayList<VirtualFile>();
+
+ for (VirtualFile file : files)
+ {
+ if (file == null)
+ throw new IllegalArgumentException("Null virtual file in " + files);
+ classPath.add(file);
+ }
+ setClassPath(classPath);
+ }
+
@Override
public VFSDeploymentContext getTopLevel()
{
Modified: projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/AbstractVFSDeploymentUnit.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/AbstractVFSDeploymentUnit.java 2008-02-19 16:10:48 UTC (rev 69937)
+++ projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/AbstractVFSDeploymentUnit.java 2008-02-19 16:36:34 UTC (rev 69938)
@@ -94,6 +94,16 @@
getDeploymentContext().setClassPath(classPath);
}
+ public void addClassPath(List<VirtualFile> files)
+ {
+ getDeploymentContext().addClassPath(files);
+ }
+
+ public void addClassPath(VirtualFile... files)
+ {
+ getDeploymentContext().addClassPath(files);
+ }
+
@Override
public VFSDeploymentUnit getParent()
{
Modified: projects/microcontainer/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/VFSDeploymentContext.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/VFSDeploymentContext.java 2008-02-19 16:10:48 UTC (rev 69937)
+++ projects/microcontainer/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/VFSDeploymentContext.java 2008-02-19 16:36:34 UTC (rev 69938)
@@ -105,6 +105,20 @@
void setClassPath(List<VirtualFile> paths);
/**
+ * Add virtual files to the classpath
+ *
+ * @param files a virtual file
+ */
+ void addClassPath(VirtualFile... files);
+
+ /**
+ * Add virtual files to the classpath
+ *
+ * @param files a virtual file
+ */
+ void addClassPath(List<VirtualFile> files);
+
+ /**
* Get the top level deployment context
*
* @return the top level deployment context
Modified: projects/microcontainer/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/VFSDeploymentUnit.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/VFSDeploymentUnit.java 2008-02-19 16:10:48 UTC (rev 69937)
+++ projects/microcontainer/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/VFSDeploymentUnit.java 2008-02-19 16:36:34 UTC (rev 69938)
@@ -91,6 +91,20 @@
void setClassPath(List<VirtualFile> classPath);
/**
+ * Add virtual files to the classpath
+ *
+ * @param files a virtual file
+ */
+ void addClassPath(VirtualFile... files);
+
+ /**
+ * Add virtual files to the classpath
+ *
+ * @param files a virtual file
+ */
+ void addClassPath(List<VirtualFile> files);
+
+ /**
* Get the top leve deployment unit
*
* @return the top level deployment unit
More information about the jboss-cvs-commits
mailing list