[jboss-cvs] JBossAS SVN: r63971 - trunk/system/src/main/org/jboss/aop/deployers/temp.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jul 11 10:14:21 EDT 2007
Author: kabir.khan at jboss.com
Date: 2007-07-11 10:14:21 -0400 (Wed, 11 Jul 2007)
New Revision: 63971
Modified:
trunk/system/src/main/org/jboss/aop/deployers/temp/AspectDeployer.java
Log:
[JBAS-4537] Make sure that errors on undeployment are logged and do not throw exceptions, and that partial deploys are unwound
Modified: trunk/system/src/main/org/jboss/aop/deployers/temp/AspectDeployer.java
===================================================================
--- trunk/system/src/main/org/jboss/aop/deployers/temp/AspectDeployer.java 2007-07-11 13:45:16 UTC (rev 63970)
+++ trunk/system/src/main/org/jboss/aop/deployers/temp/AspectDeployer.java 2007-07-11 14:14:21 UTC (rev 63971)
@@ -25,6 +25,7 @@
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.util.ArrayList;
import java.util.List;
import javassist.bytecode.ClassFile;
@@ -136,8 +137,10 @@
log.info("AOP deployment is scoped using classloader " + scl);
}
+ ArrayList<VirtualFile> deployedFiles = new ArrayList<VirtualFile>(files.size());
for (VirtualFile vf : files)
{
+ deployedFiles.add(vf);
try
{
log.debug("deploying: " + vf.toURL());
@@ -165,6 +168,12 @@
}
catch (Exception e)
{
+ //Unwind things already installed, in the reverse order
+ for (int i = deployedFiles.size() - 1 ; i >= 0 ; i--)
+ {
+ undeployXml(scl, deployedFiles.get(i));
+ }
+
throw DeploymentException.rethrowAsDeploymentException("Error deploying xml " + vf.getName(), e);
}
}
@@ -176,32 +185,43 @@
for (VirtualFile vf : files)
{
+ undeployXml(scl, vf);
+ }
+
+ aspectManager.unregisterClassLoader(unit.getClassLoader());
+ }
+
+ private void undeployXml(ClassLoader scl, VirtualFile vf)
+ {
+ try
+ {
+ log.debug("undeploying: " + vf.toURL());
+ InputStream is = vf.openStream();
try
{
- log.debug("undeploying: " + vf.toURL());
- InputStream is = vf.openStream();
+ Document doc = AspectXmlLoader.loadDocument(is);
+ AspectXmlLoader loader = new AspectXmlLoader();
+
+ AspectManager manager = (scl != null) ? AspectManager.instance(scl) : aspectManager;
+
+ loader.setManager(manager);
+ loader.undeployXML(doc, vf.toURL());
+ }
+ finally
+ {
try
{
- Document doc = AspectXmlLoader.loadDocument(is);
- AspectXmlLoader loader = new AspectXmlLoader();
-
- AspectManager manager = (scl != null) ? AspectManager.instance(scl) : aspectManager;
-
- loader.setManager(manager);
- loader.undeployXML(doc, vf.toURL());
+ is.close();
}
- finally
+ catch(IOException ignore)
{
- is.close();
}
}
- catch (Exception e)
- {
- log.warn("Error undeploying xml " + vf.getName(), e);
- }
}
-
- aspectManager.unregisterClassLoader(unit.getClassLoader());
+ catch (Exception e)
+ {
+ log.warn("Error undeploying xml " + vf.getName(), e);
+ }
}
private void deployAnnotations(VFSDeploymentUnit unit) throws DeploymentException
@@ -215,17 +235,22 @@
AspectAnnotationLoader loader = getAnnotationLoader(scl);
List<VirtualFile> files = getClasses(unit);
+ ArrayList<VirtualFile> deployedFiles = new ArrayList<VirtualFile>(files.size());
for(VirtualFile file : files)
{
- ClassFile cf = loadClassFile(file);
-
try
{
+ ClassFile cf = loadClassFile(file);
log.debug("Deploying possibly annotated class " + cf.getName());
loader.deployClassFile(cf);
}
catch (Exception e)
{
+ //Unwind things already installed, in the reverse order
+ for (int i = deployedFiles.size() ; i >= 0 ; i-- )
+ {
+ undeployAnnotation(loader, deployedFiles.get(i));
+ }
throw new DeploymentException("Error reading annotations for " + file, e);
}
}
@@ -238,20 +263,24 @@
List<VirtualFile> files = getClasses(unit);
for(VirtualFile file : files)
{
+ undeployAnnotation(loader, file);
+ }
+ }
+
+ private void undeployAnnotation(AspectAnnotationLoader loader, VirtualFile file)
+ {
+ try
+ {
ClassFile cf = loadClassFile(file);
-
- try
- {
- log.debug("Undeploying possibly annotated class " + cf.getName());
- loader.undeployClassFile(cf);
- }
- catch (Exception e)
- {
- log.warn("Error reading annotations for " + file, e);
- }
+ log.debug("Undeploying possibly annotated class " + cf.getName());
+ loader.undeployClassFile(cf);
}
+ catch (Exception e)
+ {
+ log.warn("Error reading annotations for " + file, e);
+ }
}
-
+
private AspectAnnotationLoader getAnnotationLoader(ClassLoader scl)
{
AspectManager manager = (scl != null) ? AspectManager.instance(scl) : AspectManager.instance();
More information about the jboss-cvs-commits
mailing list