[jboss-cvs] JBossAS SVN: r75837 - in projects/jboss-deployers/trunk: deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jul 15 06:42:09 EDT 2008
Author: alesj
Date: 2008-07-15 06:42:08 -0400 (Tue, 15 Jul 2008)
New Revision: 75837
Modified:
projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/AbstractVFSParsingDeployer.java
projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/MultipleVFSParsingDeployer.java
projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/validate/test/DeployersValidateInputTestCase.java
Log:
[JBDEPLOY-58]; initial work on handling altDD in multiple file deployers.
Modified: projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/validate/test/DeployersValidateInputTestCase.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/validate/test/DeployersValidateInputTestCase.java 2008-07-15 09:38:17 UTC (rev 75836)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/validate/test/DeployersValidateInputTestCase.java 2008-07-15 10:42:08 UTC (rev 75837)
@@ -59,7 +59,7 @@
// this one needs to be created first
TestXmlDeployer xmlDeployer = new TestXmlDeployer();
xmlDeployer.create();
-
+
AbstractVFSParsingDeployer<?>[] deployers = new AbstractVFSParsingDeployer<?>[]
{
new Properties2BeansDeployer(),
@@ -75,10 +75,12 @@
for(AbstractVFSParsingDeployer<?> deployer : deployers)
{
+ // set name to "" to match in deployment
+ deployer.setName("");
try
{
deployer.deploy(unit);
- fail("Should not be here.");
+ fail("Should not be here: " + deployer);
}
catch(Exception e)
{
Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/AbstractVFSParsingDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/AbstractVFSParsingDeployer.java 2008-07-15 09:38:17 UTC (rev 75836)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/AbstractVFSParsingDeployer.java 2008-07-15 10:42:08 UTC (rev 75837)
@@ -111,24 +111,64 @@
return inputStream;
}
+ /**
+ * Get metadata file.
+ * First try altDD, then fallback to original name.
+ *
+ * @param unit the vfs deployment unit
+ * @param altPrefix altDD prefix
+ * @param originalName the original file name
+ * @return metadata file or null if it doesn't exist
+ */
+ protected VirtualFile getMetadataFile(VFSDeploymentUnit unit, String altPrefix, String originalName)
+ {
+ VirtualFile file = unit.getAttachment(altPrefix + ".altDD", VirtualFile.class);
+ if(file == null && originalName != null)
+ file = unit.getMetaDataFile(originalName);
+
+ return file;
+ }
+
+ /**
+ * Match file name to metadata class.
+ *
+ * @param fileName the file name
+ * @return matching metadata class
+ */
+ protected Class<?> matchFileToClass(String fileName)
+ {
+ return null;
+ }
+
+ /**
+ * Get altDD prefix from file name.
+ *
+ * First look into matching metadata classes.
+ * If no match found, fall back to file name.
+ *
+ * @param fileName the file name
+ * @return altDD prefix
+ */
+ protected String getAltDDPrefix(String fileName)
+ {
+ Class<?> expectedClass = matchFileToClass(fileName);
+ if (expectedClass != null)
+ return expectedClass.getName();
+ else
+ return fileName;
+ }
+
@Override
protected T parse(DeploymentUnit unit, String name, T root) throws Exception
{
// Try to find the metadata
VFSDeploymentUnit vfsDeploymentUnit = (VFSDeploymentUnit) unit;
- VirtualFile file = (VirtualFile) unit.getAttachment(getOutput().getName() + ".altDD");
+ VirtualFile file = getMetadataFile(vfsDeploymentUnit, getOutput().getName(), name);
if(file == null)
- {
- file = vfsDeploymentUnit.getMetaDataFile(name);
- if (file == null)
return null;
- }
-
- T result = parse(vfsDeploymentUnit, file, root);
- if (result != null)
- init(vfsDeploymentUnit, result, file);
- return result;
+
+ return parseAndInit(vfsDeploymentUnit, file, root);
}
protected T parse(DeploymentUnit unit, Set<String> names, T root) throws Exception
@@ -143,7 +183,7 @@
for (String name : names)
{
- VirtualFile file = vfsDeploymentUnit.getMetaDataFile(name);
+ VirtualFile file = getMetadataFile(vfsDeploymentUnit, getAltDDPrefix(name), name);
if (file != null)
files.add(file);
else
@@ -166,27 +206,40 @@
// Try to find the metadata
VFSDeploymentUnit vfsDeploymentUnit = (VFSDeploymentUnit) unit;
+
+ // let's check altDD first
+ VirtualFile file = getMetadataFile(vfsDeploymentUnit, getOutput().getName(), null);
+ if (file != null)
+ return parseAndInit(vfsDeploymentUnit, file, root);
+
+ // try all name+suffix matches
List<VirtualFile> files = vfsDeploymentUnit.getMetaDataFiles(name, suffix);
-
- if (files.size() == 0)
+ switch (files.size())
{
- return null;
+ case 0 :
+ return null;
+ case 1 :
+ return parseAndInit(vfsDeploymentUnit, files.get(0), root);
+ default :
+ return handleMultipleFiles(vfsDeploymentUnit, root, files);
}
- else if (files.size() > 1)
- {
- return handleMultipleFiles(vfsDeploymentUnit, root, files);
- }
- else
- {
- VirtualFile file = (VirtualFile) unit.getAttachment(getOutput().getName() + ".altDD");
- if(file == null)
- file = files.get(0);
+ }
- T result = parse(vfsDeploymentUnit, file, root);
- if (result != null)
- init(vfsDeploymentUnit, result, file);
- return result;
- }
+ /**
+ * Parse the file, initialize the result if exists.
+ *
+ * @param unit the deployment unit
+ * @param file the file
+ * @param root the root
+ * @return parsed result
+ * @throws Exception for any error
+ */
+ protected T parseAndInit(VFSDeploymentUnit unit, VirtualFile file, T root) throws Exception
+ {
+ T result = parse(unit, file, root);
+ if (result != null)
+ init(unit, result, file);
+ return result;
}
protected T parse(DeploymentUnit unit, Set<String> names, String suffix, T root) throws Exception
@@ -201,11 +254,20 @@
for (String name : names)
{
- List<VirtualFile> matched = vfsDeploymentUnit.getMetaDataFiles(name, suffix);
- if (matched != null && matched.isEmpty() == false)
- files.addAll(matched);
+ // try finding altDD file
+ VirtualFile file = getMetadataFile(vfsDeploymentUnit, getAltDDPrefix(name), null);
+ if (file == null)
+ {
+ List<VirtualFile> matched = vfsDeploymentUnit.getMetaDataFiles(name, suffix);
+ if (matched != null && matched.isEmpty() == false)
+ files.addAll(matched);
+ else
+ missingFiles.add(name);
+ }
else
- missingFiles.add(name);
+ {
+ files.add(file);
+ }
}
if (missingFiles.size() == names.size())
Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/MultipleVFSParsingDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/MultipleVFSParsingDeployer.java 2008-07-15 09:38:17 UTC (rev 75836)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/MultipleVFSParsingDeployer.java 2008-07-15 10:42:08 UTC (rev 75837)
@@ -67,7 +67,26 @@
*/
protected Class<?> matchFileToClass(VirtualFile file)
{
- String fileName = file.getName();
+ if (file == null)
+ throw new IllegalArgumentException("Null file");
+
+ return matchFileToClass(file.getName(), true);
+ }
+
+ protected Class<?> matchFileToClass(String fileName)
+ {
+ return matchFileToClass(fileName, false);
+ }
+
+ /**
+ * Match file name mappings.
+ *
+ * @param fileName the file name
+ * @param throwException should we throw an exception if no match found
+ * @return match or null or IllegalArgumentException
+ */
+ protected Class<?> matchFileToClass(String fileName, boolean throwException)
+ {
Class<?> result = mappings.get(fileName);
if (result == null)
{
@@ -75,9 +94,9 @@
result = suffixClass;
}
- if (result == null)
+ if (result == null && throwException)
throw new IllegalArgumentException(
- "Should not be here, file '" + file +
+ "Should not be here, file name '" + fileName +
"' must macth some mapping " + mappings + " or suffix " + getSuffix()
);
More information about the jboss-cvs-commits
mailing list