You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2012/04/15 16:43:01 UTC

svn commit: r1326352 - in /openejb/trunk/openejb: container/openejb-loader/src/main/java/org/apache/openejb/loader/ProvisioningUtil.java tomee/tomee-loader/src/main/java/org/apache/tomee/loader/TomcatHook.java

Author: rmannibucau
Date: Sun Apr 15 14:43:00 2012
New Revision: 1326352

URL: http://svn.apache.org/viewvc?rev=1326352&view=rev
Log:
refactoring a bit management of provisioning.properties to be able to use it from standalone too

Modified:
    openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/ProvisioningUtil.java
    openejb/trunk/openejb/tomee/tomee-loader/src/main/java/org/apache/tomee/loader/TomcatHook.java

Modified: openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/ProvisioningUtil.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/ProvisioningUtil.java?rev=1326352&r1=1326351&r2=1326352&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/ProvisioningUtil.java (original)
+++ openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/ProvisioningUtil.java Sun Apr 15 14:43:00 2012
@@ -25,12 +25,23 @@ import java.net.ProxySelector;
 import java.net.URI;
 import java.net.URL;
 import java.net.URLConnection;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Properties;
 
 public class ProvisioningUtil {
     public static final String OPENEJB_DEPLOYER_CACHE_FOLDER = "openejb.deployer.cache.folder";
     public static final String HTTP_PREFIX = "http";
     private static final int CONNECT_TIMEOUT = 10000;
 
+    private static final String ADDITIONAL_LIB_CONFIG = "provisioning.properties";
+    private static final String ZIP_KEY = "zip";
+    private static final String DESTINATION_KEY = "destination";
+    private static final String JAR_KEY = "jar";
+    public static final String TEMP_DIR = "temp";
+
     private ProvisioningUtil() {
         // no-op
     }
@@ -67,7 +78,7 @@ public class ProvisioningUtil {
                 urlConnection.setConnectTimeout(CONNECT_TIMEOUT);
                 return new BufferedInputStream(urlConnection.getInputStream());
             } catch (IOException e) {
-                continue;
+                // ignored
             }
         }
         return null;
@@ -104,4 +115,90 @@ public class ProvisioningUtil {
             return rawLocation;
         }
     }
+
+    public static void addAdditionalLibraries() throws IOException {
+        final File conf = new File(SystemInstance.get().getBase().getDirectory("conf"), ADDITIONAL_LIB_CONFIG);
+        if (!conf.exists()) {
+            return;
+        }
+
+        final Properties additionalLibProperties = IO.readProperties(conf);
+
+        final List<String> libToCopy = new ArrayList<String>();
+        final String toCopy = additionalLibProperties.getProperty(JAR_KEY);
+        if (toCopy != null) {
+            for (String lib : toCopy.split(",")) {
+                libToCopy.add(realLocation(lib.trim()));
+            }
+        }
+        final String toExtract = additionalLibProperties.getProperty(ZIP_KEY);
+        if (toExtract != null) {
+            for (String zip : toExtract.split(",")) {
+                libToCopy.addAll(extract(realLocation(zip)));
+            }
+        }
+
+        File destination;
+        if (additionalLibProperties.containsKey(DESTINATION_KEY)) {
+            destination = new File(additionalLibProperties.getProperty(DESTINATION_KEY));
+        } else {
+            destination = new File(SystemInstance.get().getBase().getDirectory(), Embedder.ADDITIONAL_LIB_FOLDER);
+        }
+        if (!destination.exists()) {
+            Files.mkdirs(destination);
+        }
+
+        for (String lib : libToCopy) {
+            copy(new File(lib), destination);
+        }
+    }
+
+    private static void copy(final File file, final File lib) throws IOException {
+        final File dest = new File(lib, file.getName());
+        if (dest.exists()) {
+            return;
+        }
+        IO.copy(file, dest);
+    }
+
+    private static Collection<String> extract(final String zip) throws IOException {
+        final File tmp = new File(SystemInstance.get().getBase().getDirectory(), TEMP_DIR);
+        if (!tmp.exists()) {
+            try {
+                Files.mkdirs(tmp);
+            } catch (Files.FileRuntimeException fre) {
+                // ignored
+            }
+        }
+
+        final File zipFile = new File(realLocation(zip));
+        final File extracted = new File(tmp, zipFile.getName().replace(".zip", ""));
+        if (extracted.exists()) {
+            return list(extracted);
+        }
+
+        Zips.unzip(zipFile, extracted);
+        return list(extracted);
+    }
+
+    private static Collection<String> list(final File dir) {
+        if (dir == null) {
+            return Collections.emptyList();
+        }
+
+        final Collection<String> libs = new ArrayList<String>();
+        final File[] files = dir.listFiles();
+        if (files == null) {
+            return Collections.emptyList();
+        }
+
+        for (File file : files) {
+            if (file.isDirectory()) {
+                libs.addAll(list(file));
+            } else {
+                libs.add(file.getAbsolutePath());
+            }
+        }
+        return libs;
+    }
 }

Modified: openejb/trunk/openejb/tomee/tomee-loader/src/main/java/org/apache/tomee/loader/TomcatHook.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/tomee-loader/src/main/java/org/apache/tomee/loader/TomcatHook.java?rev=1326352&r1=1326351&r2=1326352&view=diff
==============================================================================
--- openejb/trunk/openejb/tomee/tomee-loader/src/main/java/org/apache/tomee/loader/TomcatHook.java (original)
+++ openejb/trunk/openejb/tomee/tomee-loader/src/main/java/org/apache/tomee/loader/TomcatHook.java Sun Apr 15 14:43:00 2012
@@ -17,19 +17,13 @@
  */
 package org.apache.tomee.loader;
 
-import org.apache.openejb.loader.Embedder;
-import org.apache.openejb.loader.IO;
-import org.apache.openejb.loader.SystemInstance;
-import org.apache.openejb.loader.Zips;
-
 import java.io.File;
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
 import java.util.Properties;
-
-import static org.apache.openejb.loader.ProvisioningUtil.realLocation;
+import org.apache.openejb.loader.Embedder;
+import org.apache.openejb.loader.IO;
+import org.apache.openejb.loader.ProvisioningUtil;
+import org.apache.openejb.loader.SystemInstance;
 
 /**
  * This class should only be loadded and used via reflection from TomcatEmbedder.
@@ -63,12 +57,6 @@ import static org.apache.openejb.loader.
  * See org.apache.tomee.catalina.TomcatLoader for the next part of the story
  */
 class TomcatHook {
-    static final String ADDITIONAL_LIB_CONFIG = "provisioning.properties";
-    static final String ZIP_KEY = "zip";
-    static final String DESTINATION_KEY = "destination";
-    static final String JAR_KEY = "jar";
-    public static final String TEMP_DIR = "temp";
-
     /**
      * Using tomee.war path, it sets several required
      * system properties and init {@link SystemInstance#init(Properties)}
@@ -164,7 +152,7 @@ class TomcatHook {
 
         // manage additional libraries
         try {
-            addAdditionalLibraries(SystemInstance.get().getBase().getDirectory("conf"), new File(SystemInstance.get().getBase().getDirectory(), ADDITIONAL_LIB_CONFIG));
+            ProvisioningUtil.addAdditionalLibraries();
         } catch (IOException e) {
             // ignored
         }
@@ -187,81 +175,4 @@ class TomcatHook {
             e.printStackTrace();
         }
     }
-
-    private static void addAdditionalLibraries(final File confDir, final File libDir) throws IOException {
-        final File conf = new File(confDir, ADDITIONAL_LIB_CONFIG);
-        if (!conf.exists()) {
-            return;
-        }
-
-        final Properties additionalLibProperties = IO.readProperties(conf);
-
-        final List<String> libToCopy = new ArrayList<String>();
-        final String toCopy = additionalLibProperties.getProperty(JAR_KEY);
-        if (toCopy != null) {
-            for (String lib : toCopy.split(",")) {
-                libToCopy.add(realLocation(lib.trim()));
-            }
-        }
-        final String toExtract = additionalLibProperties.getProperty(ZIP_KEY);
-        if (toExtract != null) {
-            for (String zip : toExtract.split(",")) {
-                libToCopy.addAll(extract(realLocation(zip)));
-            }
-        }
-
-        File destination;
-        if (additionalLibProperties.containsKey(DESTINATION_KEY)) {
-            destination = new File(additionalLibProperties.getProperty(DESTINATION_KEY));
-        } else {
-            destination = new File(SystemInstance.get().getBase().getDirectory(), Embedder.ADDITIONAL_LIB_FOLDER);
-        }
-        if (!destination.exists()) {
-            destination = libDir;
-        }
-
-        for (String lib : libToCopy) {
-            copy(new File(lib), destination);
-        }
-    }
-
-    private static void copy(final File file, final File lib) throws IOException {
-        final File dest = new File(lib, file.getName());
-        if (dest.exists()) {
-            return;
-        }
-        IO.copy(file, dest);
-    }
-
-    private static Collection<String> extract(final String zip) throws IOException {
-        final File tmp = new File(SystemInstance.get().getBase().getDirectory(), TEMP_DIR);
-        if (!tmp.exists()) {
-            tmp.mkdirs();
-        }
-
-        final File zipFile = new File(realLocation(zip));
-        final File extracted = new File(tmp, zipFile.getName().replace(".zip", ""));
-        if (extracted.exists()) {
-            return list(extracted);
-        }
-
-        unzip(zipFile, extracted);
-        return list(extracted);
-    }
-
-    private static Collection<String> list(File dir) {
-        final Collection<String> libs = new ArrayList<String>();
-        for (File file : dir.listFiles()) {
-            if (file.isDirectory()) {
-                libs.addAll(list(file));
-            } else {
-                libs.add(file.getAbsolutePath());
-            }
-        }
-        return libs;
-    }
-
-    public static void unzip(final File source, final File targetDirectory) throws IOException {
-        Zips.unzip(source, targetDirectory);
-    }
 }