geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gdam...@apache.org
Subject svn commit: r322461 - in /geronimo/trunk/modules: common/src/java/org/apache/geronimo/common/DeploymentException.java common/src/test/org/apache/geronimo/common/DeploymentExceptionTest.java deployment/src/java/org/apache/geronimo/deployment/Deployer.java
Date Sun, 16 Oct 2005 08:53:38 GMT
Author: gdamour
Date: Sun Oct 16 01:53:27 2005
New Revision: 322461

URL: http://svn.apache.org/viewcvs?rev=322461&view=rev
Log:
GERONIMO-1077 DeploymentException propagated to deployer are incomplete 
(stack + nested exceptions)


GERONIMO-1072 Better error for bad EJB QL

Propagate stack and nested exceptions to deployer. To some extent, 
GERONIMO-1072 was not valid.

Added:
    geronimo/trunk/modules/common/src/test/org/apache/geronimo/common/DeploymentExceptionTest.java
Modified:
    geronimo/trunk/modules/common/src/java/org/apache/geronimo/common/DeploymentException.java
    geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/Deployer.java

Modified: geronimo/trunk/modules/common/src/java/org/apache/geronimo/common/DeploymentException.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/common/src/java/org/apache/geronimo/common/DeploymentException.java?rev=322461&r1=322460&r2=322461&view=diff
==============================================================================
--- geronimo/trunk/modules/common/src/java/org/apache/geronimo/common/DeploymentException.java
(original)
+++ geronimo/trunk/modules/common/src/java/org/apache/geronimo/common/DeploymentException.java
Sun Oct 16 01:53:27 2005
@@ -23,7 +23,6 @@
  */
 public class DeploymentException extends Exception {
 
-
     public DeploymentException() {
     }
 
@@ -38,5 +37,41 @@
     public DeploymentException(String message, Throwable cause) {
         super(message, cause);
     }
+    
+    public DeploymentException cleanse() {
+        if(null != getCause()) {
+            Throwable root = this;
+            CleanseException previousEx = null;
+            CleanseException rootEx = null;
+            while (null != root) {
+                Throwable e = root.getCause();
+                CleanseException exception = new CleanseException(root.getMessage(), root.toString());
+                if (null == rootEx) {
+                    rootEx = exception;
+                }
+                exception.setStackTrace(root.getStackTrace());
+                if (null != previousEx) {
+                    previousEx.initCause(exception);
+                }
+                previousEx = exception;
+                root = e;
+            }
+            return rootEx;
+        }
 
+        return this;
+    }
+    
+    private static class CleanseException extends DeploymentException {
+        private final String toString;
+        
+        public CleanseException(String message, String toString) {
+            super(message);
+            this.toString = toString;
+        }
+        
+        public String toString() {
+            return toString;
+        }
+    }
 }

Added: geronimo/trunk/modules/common/src/test/org/apache/geronimo/common/DeploymentExceptionTest.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/common/src/test/org/apache/geronimo/common/DeploymentExceptionTest.java?rev=322461&view=auto
==============================================================================
--- geronimo/trunk/modules/common/src/test/org/apache/geronimo/common/DeploymentExceptionTest.java
(added)
+++ geronimo/trunk/modules/common/src/test/org/apache/geronimo/common/DeploymentExceptionTest.java
Sun Oct 16 01:53:27 2005
@@ -0,0 +1,50 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.common;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev: 109898 $ $Date: 2004-12-06 05:21:47 +1100 (Mon, 06 Dec 2004) $
+ */
+public class DeploymentExceptionTest extends TestCase {
+    
+    public void testCleanse() throws Exception {
+        DeploymentException exception = new DeploymentException("message");
+        IllegalArgumentException nested1 = new IllegalArgumentException("nested1");
+        exception.initCause(nested1);
+        IllegalStateException nested2 = new IllegalStateException("nested2");
+        nested1.initCause(nested2);
+        
+        ByteArrayOutputStream expected = new ByteArrayOutputStream();
+        exception.printStackTrace(new PrintStream(expected));
+
+        ByteArrayOutputStream result = new ByteArrayOutputStream();
+        DeploymentException newEx = exception.cleanse();
+        newEx.printStackTrace(new PrintStream(result));
+
+        byte[] expectedBytes = expected.toByteArray();
+        byte[] resultBytes = result.toByteArray();
+        assertEquals(expectedBytes.length, resultBytes.length);
+        for (int i = 0; i < expectedBytes.length; i++) {
+            assertEquals(expectedBytes[i], resultBytes[i]);
+        }
+    }
+}

Modified: geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/Deployer.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/Deployer.java?rev=322461&r1=322460&r2=322461&view=diff
==============================================================================
--- geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/Deployer.java
(original)
+++ geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/Deployer.java
Sun Oct 16 01:53:27 2005
@@ -19,6 +19,7 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.net.URI;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -27,7 +28,6 @@
 import java.util.jar.Attributes;
 import java.util.jar.JarFile;
 import java.util.jar.Manifest;
-import java.net.URI;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -35,16 +35,14 @@
 import org.apache.geronimo.deployment.util.DeploymentUtil;
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
+import org.apache.geronimo.kernel.GBeanNotFoundException;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.config.Configuration;
 import org.apache.geronimo.kernel.config.ConfigurationData;
 import org.apache.geronimo.kernel.config.ConfigurationStore;
 import org.apache.geronimo.kernel.config.InvalidConfigException;
-import org.apache.geronimo.kernel.config.Configuration;
-import org.apache.geronimo.kernel.Kernel;
-import org.apache.geronimo.kernel.GBeanNotFoundException;
-import org.apache.geronimo.system.main.CommandLineManifest;
 import org.apache.geronimo.system.configuration.ExecutableConfigurationUtil;
-
-import javax.management.MalformedObjectNameException;
+import org.apache.geronimo.system.main.CommandLineManifest;
 
 /**
  * GBean that knows how to deploy modules (by consulting available module builders)
@@ -87,21 +85,11 @@
             return deploy(planFile, moduleFile, null, true, null, null, null, null);
         } catch (DeploymentException e) {
             log.debug("Deployment failed: plan=" + planFile +", module=" + originalModuleFile,
e);
-            throw cleanseDeploymentException(e);
+            throw e.cleanse();
         } finally {
             if (tmpDir != null) {
                 DeploymentUtil.recursiveDelete(tmpDir);
             }
-        }
-    }
-
-    private DeploymentException cleanseDeploymentException(DeploymentException source) {
-        if(source.getCause() != null) {
-            Throwable e = source.getCause();
-            DeploymentException newx = new DeploymentException(source.getMessage()+" caused
by "+e.getMessage(), null);
-            return newx;
-        } else {
-            return source;
         }
     }
 



Mime
View raw message