ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From SBowman <SBow...@webb.net>
Subject [PATCH] DDCreatorHelper.java bug fix
Date Tue, 13 Mar 2001 18:47:16 GMT
I ran across a problem with WebLogic 4.5.1 EJB creation under Ant, so I'm
submitting a patch for anyone who's still using WebLogic 4.5.1.

Problem:  If you modify an EJB, e.g. remove a method to a session bean and
its remote interface, and the deployment descriptor text file does not
change, the serialized descriptor file will no longer match the EJB class
files, and the build will fail.

Solution:  Right now, the DDCreatorHelper class only checks to see if the
descriptor file is newer than the serialized file; it doesn't bother to
check if the serialized file can load the EJB classes correctly.  I've added
the code to try loading the EJB classes through the serialized file.  If
that fails, the serialized file is regenerated (it assumes that the EJB
classes have changed, even though the descriptor has not).

Thanks,
Sean Bowman
Senior Software Engineer
Webb Interactive, Inc.
http://www.webb.net
sbowman@webb.net

P.S. I apologize if I have missed some step in the patch submission process.
This is the first time I have submitted a patch to the Jakarta group), but
it seemed like something others might find useful.

--------

Index: DDCreatorHelper.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/
ejb/DDCreatorHelper.java,v
retrieving revision 1.4
diff -u -r1.4 DDCreatorHelper.java
--- DDCreatorHelper.java	2001/01/03 14:18:39	1.4
+++ DDCreatorHelper.java	2001/03/13 18:32:06
@@ -54,7 +54,11 @@
 package org.apache.tools.ant.taskdefs.optional.ejb;
 
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.ObjectInputStream;
 
+import javax.ejb.deployment.DeploymentDescriptor;
+
 /**
  * A helper class which performs the actual work of the ddcreator task.
  *
@@ -128,7 +132,8 @@
             File serFile = new File(generatedFilesDirectory, serName);
                 
             // do we need to regenerate the file
-            if (!serFile.exists() || serFile.lastModified() <
descriptorFile.lastModified()) {
+            if (!serFile.exists() || serFile.lastModified() <
descriptorFile.lastModified()
+                || regenerateSerializedFile(serFile)) {
                 
                 String[] args = {"-noexit", 
                                  "-d", serFile.getParent(),
@@ -145,6 +150,32 @@
                     weblogic.ejb.utils.DDCreator.main(newArgs);
                 }
             }
+        }
+    }
+
+    /**
+     * EJBC will fail if the serialized descriptor file does not match the
bean classes.
+     * You can test for this by trying to load the deployment descriptor.
If it fails,
+     * the serialized file needs to be regenerated because the associated
class files
+     * don't match.
+     */
+    private boolean regenerateSerializedFile(File serFile) {
+        try {
+
+            FileInputStream fis = new FileInputStream(serFile);
+            ObjectInputStream ois = new ObjectInputStream(fis);
+            DeploymentDescriptor dd = (DeploymentDescriptor)
ois.readObject();
+            fis.close();
+
+            // Since the descriptor read properly, everything should be
o.k.
+            return false;
+
+        } catch (Exception e) {
+            
+            // Weblogic will throw an error if the deployment descriptor
does 
+            // not match the class files.
+            return true;
+
         }
     }
 }

--------


Mime
View raw message