tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r613045 - in /openejb/trunk/openejb3/container: openejb-core/src/main/java/org/apache/openejb/assembler/ openejb-core/src/main/java/org/apache/openejb/assembler/classic/ openejb-core/src/main/java/org/apache/openejb/cli/ openejb-core/src/ma...
Date Fri, 18 Jan 2008 02:51:41 GMT
Author: dain
Date: Thu Jan 17 18:51:36 2008
New Revision: 613045

URL: http://svn.apache.org/viewvc?rev=613045&view=rev
Log:
The application id should be the canonical file path not a relative path
Undeploy command can now take the file name of an application deployed in the server

Modified:
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cli/Bootstrap.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/Deploy.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/JarExtractor.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/Undeploy.java
    openejb/trunk/openejb3/container/openejb-loader/src/main/java/org/apache/openejb/loader/FileUtils.java

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java?rev=613045&r1=613044&r2=613045&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java
Thu Jan 17 18:51:36 2008
@@ -46,8 +46,8 @@
     static {
         String uniqueName = "OpenEJB-" + new BigInteger(128, new SecureRandom()).toString(Character.MAX_RADIX);
         String tempDir = System.getProperty("java.io.tmpdir");
-        uniqueFile = new File(tempDir, uniqueName);
         try {
+            uniqueFile = new File(tempDir, uniqueName).getCanonicalFile();
             uniqueFile.createNewFile();
         } catch (IOException e) {
             throw new RuntimeException(e);

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java?rev=613045&r1=613044&r2=613045&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
Thu Jan 17 18:51:36 2008
@@ -97,7 +97,7 @@
 
     private final CoreContainerSystem containerSystem;
     private final PersistenceClassLoaderHandler persistenceClassLoaderHandler;
-    private final ClassLoaderRegistry classLoaderRegistry;;
+    private final ClassLoaderRegistry classLoaderRegistry;
     private final JndiBuilder jndiBuilder;
     private TransactionManager transactionManager;
     private SecurityService securityService;

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cli/Bootstrap.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cli/Bootstrap.java?rev=613045&r1=613044&r2=613045&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cli/Bootstrap.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cli/Bootstrap.java
Thu Jan 17 18:51:36 2008
@@ -62,7 +62,7 @@
 
                 if (jarFile.getName().indexOf("openejb-core") > -1) {
                     File lib = jarFile.getParentFile();
-                    File home = lib.getParentFile();
+                    File home = lib.getParentFile().getCanonicalFile();
 
                     System.setProperty(OPENEJB_HOME_PROPERTY_NAME, home.getAbsolutePath());
                 }

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java?rev=613045&r1=613044&r2=613045&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java
Thu Jan 17 18:51:36 2008
@@ -66,6 +66,7 @@
 import java.util.ArrayList;
 import java.net.URL;
 import java.io.File;
+import java.io.IOException;
 
 /**
  * @version $Rev$ $Date$
@@ -179,7 +180,11 @@
         List<URL> additionalLibraries = appModule.getAdditionalLibraries();
         for (URL url : additionalLibraries) {
             File file = new File(url.getPath());
-            appInfo.libs.add(file.getAbsolutePath());
+            try {
+                appInfo.libs.add(file.getCanonicalPath());
+            } catch (IOException e) {
+                throw new OpenEJBException("Invalid application lib path " + file.getAbsolutePath());
+            }
         }
 
         if (appModule.getCmpMappings() != null) {
@@ -263,7 +268,11 @@
             List<URL> libraries = connectorModule.getLibraries();
             for (URL url : libraries) {
                 File file = new File(url.getPath());
-                connectorInfo.libs.add(file.getAbsolutePath());
+                try {
+                    connectorInfo.libs.add(file.getCanonicalPath());
+                } catch (IOException e) {
+                    throw new IllegalArgumentException("Invalid application lib path " +
file.getAbsolutePath());                    
+                }
             }
 
             ResourceAdapter resourceAdapter = connector.getResourceAdapter();

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/Deploy.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/Deploy.java?rev=613045&r1=613044&r2=613045&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/Deploy.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/Deploy.java
Thu Jan 17 18:51:36 2008
@@ -16,6 +16,19 @@
  */
 package org.apache.openejb.config;
 
+import java.io.Closeable;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.List;
+import java.util.Properties;
+import java.util.jar.JarFile;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.CommandLineParser;
 import org.apache.commons.cli.HelpFormatter;
@@ -25,32 +38,20 @@
 import org.apache.commons.cli.ParseException;
 import org.apache.commons.cli.PosixParser;
 import org.apache.openejb.OpenEJBException;
-import org.apache.openejb.cli.SystemExitException;
-import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.assembler.Deployer;
 import org.apache.openejb.assembler.classic.AppInfo;
+import org.apache.openejb.assembler.classic.ClientInfo;
+import org.apache.openejb.assembler.classic.ConnectorInfo;
 import org.apache.openejb.assembler.classic.EjbJarInfo;
 import org.apache.openejb.assembler.classic.EnterpriseBeanInfo;
 import org.apache.openejb.assembler.classic.InterceptorInfo;
-import org.apache.openejb.assembler.classic.ClientInfo;
 import org.apache.openejb.assembler.classic.PersistenceUnitInfo;
-import org.apache.openejb.assembler.classic.ConnectorInfo;
 import org.apache.openejb.assembler.classic.WebAppInfo;
+import org.apache.openejb.cli.SystemExitException;
+import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.util.Messages;
 import org.apache.openejb.util.OpenEjbVersion;
 
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import java.io.File;
-import java.io.OutputStream;
-import java.io.InputStream;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.Closeable;
-import java.util.List;
-import java.util.Properties;
-
 /**
  * Deploy EJB beans
  */
@@ -76,7 +77,7 @@
         options.addOption(option("q", "quiet", "cmd.deploy.opt.quiet"));
         options.addOption(option(null, "dir", "cmd.deploy.opt.dir"));
 
-        CommandLine line = null;
+        CommandLine line;
         try {
             // parse the command line arguments
             line = parser.parse(options, args);
@@ -115,7 +116,7 @@
 
         boolean offline = line.hasOption("offline");
 
-        File apps = null;
+        File apps;
         try {
             String dir = line.getOptionValue("dir", "apps");
             apps = SystemInstance.get().getBase().getDirectory(dir);
@@ -161,16 +162,26 @@
 
                 File destFile = new File(apps, file.getName());
 
-                checkDest(destFile, file);
 
-                copyFile(file, destFile);
+                if (shouldUnpack(file)) {
+                    destFile = unpack(file, apps);
+                } else {
+                    checkDest(destFile, file);
+                    copyFile(file, destFile);
+                }
 
                 if (offline) {
                     System.out.println(messages.format("cmd.deploy.offline", path, apps.getAbsolutePath()));
                     continue;
                 }
 
-                AppInfo appInfo = deployer.deploy(file.getAbsolutePath());
+                String location;
+                try {
+                    location = destFile.getCanonicalPath();
+                } catch (IOException e) {
+                    throw new OpenEJBException(messages.format("cmd.deploy.fileNotFound",
path));
+                }
+                AppInfo appInfo = deployer.deploy(location);
 
                 System.out.println(messages.format("cmd.deploy.successful", path, appInfo.jarPath));
 
@@ -266,6 +277,62 @@
             close(out);
         }
     }
+
+    private static boolean shouldUnpack(File file) {
+        String name = file.getName();
+        if (name.endsWith(".ear") || name.endsWith(".rar") || name.endsWith(".rar")) {
+            return true;
+        }
+
+        JarFile jarFile = null;
+        try {
+            jarFile = new JarFile(file);
+
+            if (jarFile.getEntry("META-INF/application.xml") != null) {
+                return true;
+            }
+            if (jarFile.getEntry("META-INF/ra.xml") != null) {
+                return true;
+            }
+            if (jarFile.getEntry("WEB-INF/web.xml") != null) {
+                return true;
+            }
+        } catch (IOException e) {
+        } finally {
+            if (jarFile != null) {
+                try {
+                    jarFile.close();
+                } catch (IOException ignored) {
+                }
+            }
+        }
+
+        return false;
+    }
+        
+    private static File unpack(File jarFile, File destDir) throws OpenEJBException, DeploymentTerminatedException
{
+        if (jarFile.isDirectory()) {
+            return jarFile;
+        }
+
+        String name = jarFile.getName();
+        if (name.endsWith(".jar") || name.endsWith(".ear") || name.endsWith(".zip") || name.endsWith(".war")
|| name.endsWith(".rar")) {
+            name = name.replaceFirst("....$", "");
+        } else {
+            name += ".unpacked";
+        }
+
+
+        try {
+            File destinationDir = new File(destDir, name);
+            checkDest(destinationDir, jarFile);
+            JarExtractor.extract(jarFile, destinationDir);
+            return destinationDir;
+        } catch (IOException e) {
+            throw new OpenEJBException("Unable to extract jar. " + e.getMessage(), e);
+        }
+    }
+
 
     private static void close(Closeable in) {
         if (in != null) {

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java?rev=613045&r1=613044&r2=613045&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
Thu Jan 17 18:51:36 2008
@@ -87,9 +87,21 @@
             throw new UnknownModuleTypeException("Unable to determine module type for jar:
" + baseUrl.toExternalForm(), e);
         }
 
+        String jarPath;
+        try {
+            jarPath = jarFile.getCanonicalPath();
+        } catch (IOException e) {
+            throw new OpenEJBException("Invalid application file path " + jarFile);
+        }
+
         if (AppModule.class.equals(moduleClass)) {
 
             File appDir = unpack(jarFile);
+            try {
+                appDir = appDir.getCanonicalFile();
+            } catch (IOException e) {
+                throw new OpenEJBException("Invalid application directory " + appDir.getAbsolutePath());
+            }
 
             URL appUrl = getFileUrl(appDir);
 
@@ -342,7 +354,7 @@
                 return appModule;
 
             } catch (OpenEJBException e) {
-                logger.error("Unable to load EAR: " + jarFile.getAbsolutePath(), e);
+                logger.error("Unable to load EAR: " + jarPath, e);
                 throw e;
             }
 
@@ -356,9 +368,9 @@
             }
 
             // create the EJB Module
-            EjbModule ejbModule = new EjbModule(classLoader, jarFile.getAbsolutePath(), ejbJar,
null);
+            EjbModule ejbModule = new EjbModule(classLoader, jarPath, ejbJar, null);
             ejbModule.getAltDDs().putAll(descriptors);
-            ejbModule.getWatchedResources().add(jarFile.getAbsolutePath());
+            ejbModule.getWatchedResources().add(jarPath);
             if (ejbJarXmlUrl != null && "file".equals(ejbJarXmlUrl.getProtocol()))
{
                 ejbModule.getWatchedResources().add(ejbJarXmlUrl.getPath());
             }

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/JarExtractor.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/JarExtractor.java?rev=613045&r1=613044&r2=613045&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/JarExtractor.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/JarExtractor.java
Thu Jan 17 18:51:36 2008
@@ -33,9 +33,8 @@
 public class JarExtractor {
 
     /**
-     * Extract the Jar file into an unpacked
-     * directory structure, and return the absolute pathname to the extracted
-     * directory.
+     * Extract the Jar file into an unpacked directory structure, and
+     * return the absolute pathname to the extracted directory.
      *
      * @param file Jar file to unpack
      * @param pathname Context path name for web application
@@ -43,19 +42,30 @@
      * @throws java.io.IOException              if an input/output error was encountered
      *                                  during expansion
      */
-    public static File extract(File file, String pathname)
-            throws IOException {
-
+    public static File extract(File file, String pathname) throws IOException {
         File docBase = new File(file.getParentFile(), pathname);
-        if (docBase.exists()) {
+        extract(file, docBase);
+        return docBase;
+    }
+
+    /**
+     * Extract the jar file into the specifiec destination directory.  If the destination
directory
+     * already exists, the jar will not be unpacked.
+     *
+     * @param file jar file to unpack
+     * @param destinationDir the directory in which the jar will be unpacked; must not exist
+     * @throws java.io.IOException if an input/output error was encountered during expansion
+     */
+    public static void extract(File file, File destinationDir) throws IOException {
+        if (destinationDir.exists()) {
             // Ear file is already installed
-            return docBase;
+            return;
         }
 
         DeploymentLoader.logger.info("Extracting jar: " + file.getAbsolutePath());
 
         // Create the new document base directory
-        docBase.mkdir();
+        destinationDir.mkdirs();
 
         // Extract the JAR into the new directory
         JarFile jarFile = null;
@@ -68,7 +78,7 @@
                 String name = jarEntry.getName();
                 int last = name.lastIndexOf('/');
                 if (last >= 0) {
-                    File parent = new File(docBase,
+                    File parent = new File(destinationDir,
                             name.substring(0, last));
                     parent.mkdirs();
                 }
@@ -77,7 +87,7 @@
                 }
                 input = jarFile.getInputStream(jarEntry);
 
-                File extractedFile = extract(input, docBase, name);
+                File extractedFile = extract(input, destinationDir, name);
                 long lastModified = jarEntry.getTime();
                 if ((lastModified != -1) && (lastModified != 0) && (extractedFile
!= null)) {
                     extractedFile.setLastModified(lastModified);
@@ -89,7 +99,7 @@
         } catch (IOException e) {
             // If something went wrong, delete extracted dir to keep things
             // clean
-            deleteDir(docBase);
+            deleteDir(destinationDir);
             throw e;
         } finally {
             if (input != null) {
@@ -97,22 +107,17 @@
                     input.close();
                 } catch (Throwable t) {
                 }
-                input = null;
             }
             if (jarFile != null) {
                 try {
                     jarFile.close();
                 } catch (Throwable t) {
                 }
-                jarFile = null;
             }
         }
 
         // Return the absolute path to our new document base directory
-        DeploymentLoader.logger.info("Extracted path: " + docBase.getAbsolutePath());
-
-        return docBase;
-
+        DeploymentLoader.logger.info("Extracted path: " + destinationDir.getAbsolutePath());
     }
 
 
@@ -126,7 +131,7 @@
 
         boolean result = true;
 
-        String files[] = null;
+        String files[];
         if (src.isDirectory()) {
             files = src.list();
             result = dest.mkdir();
@@ -196,12 +201,12 @@
      */
     public static boolean deleteDir(File dir) {
 
-        String files[] = dir.list();
-        if (files == null) {
-            files = new String[0];
+        String fileNames[] = dir.list();
+        if (fileNames == null) {
+            fileNames = new String[0];
         }
-        for (int i = 0; i < files.length; i++) {
-            File file = new File(dir, files[i]);
+        for (String fileName : fileNames) {
+            File file = new File(dir, fileName);
             if (file.isDirectory()) {
                 deleteDir(file);
             } else {

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/Undeploy.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/Undeploy.java?rev=613045&r1=613044&r2=613045&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/Undeploy.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/Undeploy.java
Thu Jan 17 18:51:36 2008
@@ -17,6 +17,8 @@
 package org.apache.openejb.config;
 
 import java.util.Properties;
+import java.io.File;
+import java.io.IOException;
 
 import javax.naming.Context;
 import javax.naming.InitialContext;
@@ -105,7 +107,26 @@
             String moduleId = (String) obj;
 
             try {
-                deployer.undeploy(moduleId);
+                boolean undeployed = false;
+
+                // Treat moduleId as a file path, and see if there is a matching app to undeploy
+                String path = null;
+                try {
+                    path = new File(moduleId).getCanonicalPath();
+                } catch (IOException e) {
+                }
+                if (path != null) {
+                    try {
+                        deployer.undeploy(path);
+                        undeployed = true;
+                    } catch (NoSuchApplicationException e) {
+                    }
+                }
+
+                // If that didn't work, undeploy using just the moduleId
+                if (!undeployed) {
+                    deployer.undeploy(moduleId);
+                }
 
                 // TODO make this message
                 System.out.println(messages.format("cmd.undeploy.successful", moduleId));

Modified: openejb/trunk/openejb3/container/openejb-loader/src/main/java/org/apache/openejb/loader/FileUtils.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-loader/src/main/java/org/apache/openejb/loader/FileUtils.java?rev=613045&r1=613044&r2=613045&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-loader/src/main/java/org/apache/openejb/loader/FileUtils.java
(original)
+++ openejb/trunk/openejb3/container/openejb-loader/src/main/java/org/apache/openejb/loader/FileUtils.java
Thu Jan 17 18:51:36 2008
@@ -51,7 +51,12 @@
                 home = new File(homePath);
             }
 
-            home = home.getAbsoluteFile();
+            try {
+                home = home.getCanonicalFile();
+            } catch (IOException e) {
+                // this shouldn't happen, but let's get absolute file
+                home = home.getAbsoluteFile();
+            }
         } catch (SecurityException e) {
 
         }



Mime
View raw message