[jboss-cvs] JBossAS SVN: r58324 - in projects/microcontainer/trunk/deployers/src: main/org/jboss/deployers/plugins/deployer main/org/jboss/deployers/spi/deployer tests/org/jboss/test/deployers/structure/ear/test
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Nov 13 20:48:50 EST 2006
Author: scott.stark at jboss.org
Date: 2006-11-13 20:48:46 -0500 (Mon, 13 Nov 2006)
New Revision: 58324
Modified:
projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployer/AbstractDeploymentUnit.java
projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/deployer/DeploymentUnit.java
projects/microcontainer/trunk/deployers/src/tests/org/jboss/test/deployers/structure/ear/test/EARStructureUnitTestCase.java
Log:
Add a DeploymentUnit.getFile to avoid having to retrieve the root from the DeploymentContext
Modified: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployer/AbstractDeploymentUnit.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployer/AbstractDeploymentUnit.java 2006-11-14 00:42:17 UTC (rev 58323)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployer/AbstractDeploymentUnit.java 2006-11-14 01:48:46 UTC (rev 58324)
@@ -36,6 +36,7 @@
import org.jboss.deployers.spi.classloader.ClassLoaderFactory;
import org.jboss.deployers.spi.deployer.DeploymentUnit;
import org.jboss.deployers.spi.structure.DeploymentContext;
+import org.jboss.logging.Logger;
import org.jboss.virtual.VirtualFile;
/**
@@ -51,6 +52,7 @@
public class AbstractDeploymentUnit extends AbstractAttachments
implements DeploymentUnit, Serializable
{
+ private static final Logger log = Logger.getLogger(AbstractDeploymentUnit.class);
private static final long serialVersionUID = 1;
/** The deployment context */
@@ -89,6 +91,27 @@
return deploymentContext.getRelativePath();
}
+ /**
+ * Find a child of the deployment root.
+ * @param name - relative path of the file to find
+ * @return the file if found, null otherwise.
+ */
+ public VirtualFile getFile(String name)
+ {
+ VirtualFile root = deploymentContext.getRoot();
+ VirtualFile file = null;
+ try
+ {
+ file = root.findChild(name);
+ }
+ catch(Exception e)
+ {
+ if( log.isTraceEnabled() )
+ log.trace("Failed to find: "+name, e);
+ }
+ return file;
+ }
+
public ClassLoader getClassLoader()
{
ClassLoader cl = deploymentContext.getClassLoader();
Modified: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/deployer/DeploymentUnit.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/deployer/DeploymentUnit.java 2006-11-14 00:42:17 UTC (rev 58323)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/deployer/DeploymentUnit.java 2006-11-14 01:48:46 UTC (rev 58324)
@@ -37,6 +37,7 @@
* that deployers work with.
*
* @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author Scott.Stark at jboss.org
* @version $Revision: 1.1 $
*/
public interface DeploymentUnit extends Attachments
@@ -78,7 +79,8 @@
public String getRelativePath();
/**
- * Gets a metadata file
+ * Gets a metadata file. This is a file located under the deployment metadata
+ * context(s).
*
* @param name the name to exactly match
* @return the virtual file or null if not found
@@ -95,8 +97,17 @@
* @throws IllegalArgumentException if both the name and suffix are null
*/
List<VirtualFile> getMetaDataFiles(String name, String suffix);
-
+
/**
+ * Get a file in the deployment. To get the deployment root use "" as the file
+ * name.
+ *
+ * @param name - the path name of the file relative to the deployment root.
+ * @return the file if found, null otherwise.
+ */
+ VirtualFile getFile(String name);
+
+ /**
* Gets the classloader for this deployment unit
*
* @return the classloader
Modified: projects/microcontainer/trunk/deployers/src/tests/org/jboss/test/deployers/structure/ear/test/EARStructureUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/tests/org/jboss/test/deployers/structure/ear/test/EARStructureUnitTestCase.java 2006-11-14 00:42:17 UTC (rev 58323)
+++ projects/microcontainer/trunk/deployers/src/tests/org/jboss/test/deployers/structure/ear/test/EARStructureUnitTestCase.java 2006-11-14 01:48:46 UTC (rev 58324)
@@ -30,10 +30,12 @@
import junit.framework.Test;
import junit.framework.TestSuite;
+import org.jboss.deployers.plugins.deployer.AbstractDeploymentUnit;
import org.jboss.deployers.plugins.structure.BasicStructuredDeployers;
import org.jboss.deployers.plugins.structure.vfs.file.FileStructure;
import org.jboss.deployers.plugins.structure.vfs.jar.JARStructure;
import org.jboss.deployers.plugins.structure.vfs.war.WARStructure;
+import org.jboss.deployers.spi.deployer.DeploymentUnit;
import org.jboss.deployers.spi.structure.DeploymentContext;
import org.jboss.deployers.spi.structure.vfs.StructureDeployer;
import org.jboss.deployers.spi.structure.vfs.StructuredDeployers;
@@ -221,5 +223,28 @@
assertEquals("submbean2-service.xml", "submbean2-service.xml", submbean2.getSimpleName());
}
-
+
+ /**
+ * Basic getMetaDataFile/getFile tests.
+ *
+ * @throws Exception
+ */
+ public void testComplexWithAppFinds()
+ throws Exception
+ {
+ DeploymentContext ear = assertValidContext("/structure/", "ear/complexwithappxml.ear");
+ AbstractDeploymentUnit earUnit = new AbstractDeploymentUnit(ear);
+
+ // META-INF/application.properties
+ VirtualFile appProps = earUnit.getMetaDataFile("application.properties");
+ assertNotNull("META-INF/application.properties", appProps);
+ VirtualFile xappProps = earUnit.getFile("application.properties");
+ assertNull("application.properties", xappProps);
+
+ // lib/lib0.jar
+ VirtualFile xlib0Jar = earUnit.getMetaDataFile("lib/lib0.jar");
+ assertNull("lib/lib0.jar", xlib0Jar);
+ VirtualFile lib0Jar = earUnit.getFile("lib/lib0.jar");
+ assertNotNull("lib/lib0.jar", lib0Jar);
+ }
}
More information about the jboss-cvs-commits
mailing list