tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andygumbre...@apache.org
Subject svn commit: r1239091 - in /openejb/trunk/openejb/container: openejb-core/src/main/java/org/apache/openejb/cli/ openejb-core/src/main/java/org/apache/openejb/util/ openejb-loader/src/main/java/org/apache/openejb/loader/
Date Wed, 01 Feb 2012 11:45:31 GMT
Author: andygumbrecht
Date: Wed Feb  1 11:45:31 2012
New Revision: 1239091

URL: http://svn.apache.org/viewvc?rev=1239091&view=rev
Log:
Fix classloader issue due to BasicURLClassPath filenames:

Now using following which should be rock solid:

try {
	jars[j] = new URL(new File(dir, name).getCanonicalFile().getAbsoluteFile().toURI().toURL().toExternalForm());
} catch (IOException e) {
	jars[j] = new URL(new File(dir, name).getAbsoluteFile().toURI().toURL().toExternalForm());
}


Modified:
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/cli/Bootstrap.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/UrlCache.java
    openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/BasicURLClassPath.java
    openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/SystemClassPath.java

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/cli/Bootstrap.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/cli/Bootstrap.java?rev=1239091&r1=1239090&r2=1239091&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/cli/Bootstrap.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/cli/Bootstrap.java
Wed Feb  1 11:45:31 2012
@@ -21,7 +21,6 @@ import org.apache.openejb.loader.SystemC
 import java.io.File;
 import java.net.URI;
 import java.net.URL;
-import java.net.URLDecoder;
 
 /**
  * @version $Rev$ $Date$
@@ -33,37 +32,37 @@ public class Bootstrap {
     private final static String OPENEJB_BASE_PROPERTY_NAME = "openejb.base";
     private final static String OPENEJB_CLI_MAIN_CLASS_NAME = "org.apache.openejb.cli.MainImpl";
 
-    private static void setupHome(String[] args) {
-        for (String arg : args) {
-            if (arg.startsWith("-D" + OPENEJB_HOME_PROPERTY_NAME)){
+    private static void setupHome(final String[] args) {
+        for (final String arg : args) {
+            if (arg.startsWith("-D" + OPENEJB_HOME_PROPERTY_NAME)) {
                 addProperty(arg);
-            } else if (arg.startsWith("-D" + OPENEJB_BASE_PROPERTY_NAME)){
+            } else if (arg.startsWith("-D" + OPENEJB_BASE_PROPERTY_NAME)) {
                 addProperty(arg);
             }
         }
 
-        String homeProperty = System.getProperty(OPENEJB_HOME_PROPERTY_NAME);
-        if (homeProperty != null){
-            if (new File(homeProperty).exists()){
+        final String homeProperty = System.getProperty(OPENEJB_HOME_PROPERTY_NAME);
+        if (homeProperty != null) {
+            if (new File(homeProperty).exists()) {
                 return;
             }
         }
 
         try {
-            URL classURL = Thread.currentThread().getContextClassLoader().getResource(OPENEJB_VERSION_PROPERTIES_FILE_NAME);
+            final URL classURL = Thread.currentThread().getContextClassLoader().getResource(OPENEJB_VERSION_PROPERTIES_FILE_NAME);
 
             if (classURL != null) {
                 String propsString = classURL.getFile();
 
                 propsString = propsString.substring(0, propsString.indexOf("!"));
 
-                URI uri = new URI(propsString);
+                final URI uri = new URI(propsString);
 
-                File jarFile = new File(uri.getSchemeSpecificPart());
+                final File jarFile = new File(uri.getSchemeSpecificPart());
 
-                if (jarFile.getName().indexOf("openejb-core") > -1) {
-                    File lib = jarFile.getParentFile();
-                    File home = lib.getParentFile().getCanonicalFile();
+                if (jarFile.getName().contains("openejb-core")) {
+                    final File lib = jarFile.getParentFile();
+                    final File home = lib.getParentFile().getCanonicalFile();
 
                     System.setProperty(OPENEJB_HOME_PROPERTY_NAME, home.getAbsolutePath());
                 }
@@ -73,17 +72,17 @@ public class Bootstrap {
         }
     }
 
-    private static void addProperty(String arg) {
-        String prop = arg.substring(arg.indexOf("-D") + 2, arg.indexOf("="));
-        String val = arg.substring(arg.indexOf("=") + 1);
+    private static void addProperty(final String arg) {
+        final String prop = arg.substring(arg.indexOf("-D") + 2, arg.indexOf("="));
+        final String val = arg.substring(arg.indexOf("=") + 1);
 
         System.setProperty(prop, val);
     }
 
     private static void setupClasspath() {
         try {
-            File lib = new File(System.getProperty(OPENEJB_HOME_PROPERTY_NAME) + File.separator
+ "lib");
-            SystemClassPath systemCP = new SystemClassPath();
+            final File lib = new File(System.getProperty(OPENEJB_HOME_PROPERTY_NAME) + File.separator
+ "lib");
+            final SystemClassPath systemCP = new SystemClassPath();
             systemCP.addJarsToPath(lib);
         } catch (Exception e) {
             System.err.println("Error setting up the classpath: " + e.getClass() + ": " +
e.getMessage());
@@ -94,12 +93,12 @@ public class Bootstrap {
     /**
      * Read commands from BASE_PATH (using XBean's ResourceFinder) and execute the one specified
on the command line
      */
-    public static void main(String[] args) throws Exception {
+    public static void main(final String[] args) throws Exception {
         setupHome(args);
         setupClasspath();
 
-        Class<?> clazz = Bootstrap.class.getClassLoader().loadClass(OPENEJB_CLI_MAIN_CLASS_NAME);
-        Main main = (Main) clazz.newInstance();
+        final Class<?> clazz = Bootstrap.class.getClassLoader().loadClass(OPENEJB_CLI_MAIN_CLASS_NAME);
+        final Main main = (Main) clazz.newInstance();
         try {
             main.main(args);
         } catch (SystemExitException e) {

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/UrlCache.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/UrlCache.java?rev=1239091&r1=1239090&r2=1239091&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/UrlCache.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/UrlCache.java
Wed Feb  1 11:45:31 2012
@@ -58,13 +58,7 @@ public class UrlCache {
         if (value != null) {
             antiJarLocking = Boolean.valueOf(value);
         } else {
-            boolean embedded = false;
-            try {
-                FileUtils openejbBase = SystemInstance.get().getBase();
-                embedded = !openejbBase.getDirectory("conf").exists();
-            } catch (IOException e) {
-            }
-
+            final boolean embedded = Boolean.parseBoolean( SystemInstance.get().getProperty("openejb.embedded",
"false"));
             // antiJarLocking is on by default when we are not embedded and running on windows
             antiJarLocking = !embedded && System.getProperty("os.name", "unknown").toLowerCase().startsWith("windows");
         }

Modified: openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/BasicURLClassPath.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/BasicURLClassPath.java?rev=1239091&r1=1239090&r2=1239091&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/BasicURLClassPath.java
(original)
+++ openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/BasicURLClassPath.java
Wed Feb  1 11:45:31 2012
@@ -17,6 +17,7 @@
 package org.apache.openejb.loader;
 
 import java.io.File;
+import java.io.IOException;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.net.URL;
@@ -27,6 +28,7 @@ import java.security.PrivilegedAction;
 public abstract class BasicURLClassPath implements ClassPath {
     public static ClassLoader getContextClassLoader() {
         return java.security.AccessController.doPrivileged(new java.security.PrivilegedAction<ClassLoader>()
{
+            @Override
             public ClassLoader run() {
                 return Thread.currentThread().getContextClassLoader();
             }
@@ -36,18 +38,19 @@ public abstract class BasicURLClassPath 
     private java.lang.reflect.Field ucpField;
 
     protected void addJarToPath(final URL jar, final URLClassLoader loader) throws Exception
{
-        Object cp = getURLClassPath(loader);
-        Method addURLMethod = getAddURLMethod(loader);
-        addURLMethod.invoke(cp, new URL[] { jar });
+        final Object cp = getURLClassPath(loader);
+        final Method addURLMethod = getAddURLMethod(loader);
+        addURLMethod.invoke(cp, new URL[]{jar});
     }
 
     private Method getAddURLMethod(final URLClassLoader loader) {
         return AccessController.doPrivileged(new PrivilegedAction<Method>() {
+            @Override
             public Method run() {
-                Object cp;
+                final Object cp;
                 try {
                     cp = getURLClassPath(loader);
-                    Class<?> clazz = cp.getClass();
+                    final Class<?> clazz = cp.getClass();
                     return clazz.getDeclaredMethod("addURL", URL.class);
                 } catch (Exception e) {
                     e.printStackTrace();
@@ -62,32 +65,41 @@ public abstract class BasicURLClassPath 
     protected void addJarsToPath(final File dir, final URLClassLoader loader) throws Exception
{
         if (dir == null || !dir.exists()) return;
 
-        String[] jarNames = dir.list(new java.io.FilenameFilter() {
-            public boolean accept(File dir, String name) {
-
-                return (name.endsWith(".jar") || name.endsWith(".zip"));
+        final String[] jarNames = dir.list(new java.io.FilenameFilter() {
+            @Override
+            public boolean accept(final File dir, String name) {
+                name = name.toLowerCase();
+                return name.endsWith(".jar") || name.endsWith(".zip");
             }
         });
 
         final URL[] jars = new URL[jarNames.length];
+        final boolean isWindows = System.getProperty("os.name", "unknown").toLowerCase().startsWith("windows");
+
         for (int j = 0; j < jarNames.length; j++) {
-            jars[j] = new File(dir, jarNames[j]).toURI().toURL();
+            final String name = isWindows ? jarNames[j].toLowerCase() : jarNames[j];
+            try {
+                jars[j] = new URL(new File(dir, name).getCanonicalFile().getAbsoluteFile().toURI().toURL().toExternalForm());
+            } catch (IOException e) {
+                jars[j] = new URL(new File(dir, name).getAbsoluteFile().toURI().toURL().toExternalForm());
+            }
         }
 
-        Object cp = getURLClassPath(loader);
-        Method addURLMethod = getAddURLMethod(loader);
-        for (URL jar : jars) {
-            addURLMethod.invoke(cp, new URL[] { jar });
+        final Object cp = getURLClassPath(loader);
+        final Method addURLMethod = getAddURLMethod(loader);
+        for (final URL jar : jars) {
+            addURLMethod.invoke(cp, new URL[]{jar});
         }
     }
 
-    protected Object getURLClassPath(URLClassLoader loader) throws Exception {
+    protected Object getURLClassPath(final URLClassLoader loader) throws Exception {
         return getUcpField().get(loader);
     }
 
     private java.lang.reflect.Field getUcpField() throws Exception {
         if (ucpField == null) {
             ucpField = AccessController.doPrivileged(new PrivilegedAction<Field>()
{
+                @Override
                 public Field run() {
                     java.lang.reflect.Field ucp = null;
                     try {

Modified: openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/SystemClassPath.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/SystemClassPath.java?rev=1239091&r1=1239090&r2=1239091&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/SystemClassPath.java
(original)
+++ openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/SystemClassPath.java
Wed Feb  1 11:45:31 2012
@@ -32,17 +32,20 @@ public class SystemClassPath extends Bas
 
     private URLClassLoader sysLoader;
 
-    public void addJarsToPath(File dir) throws Exception {
+    @Override
+    public void addJarsToPath(final File dir) throws Exception {
         this.addJarsToPath(dir, getSystemLoader());
         this.rebuildJavaClassPathVariable();
     }
 
-    public void addJarToPath(URL jar) throws Exception {
+    @Override
+    public void addJarToPath(final URL jar) throws Exception {
 
         this.addJarToPath(jar, getSystemLoader());
         this.rebuildJavaClassPathVariable();
     }
 
+    @Override
     public ClassLoader getClassLoader() {
         try {
             return getSystemLoader();
@@ -59,15 +62,15 @@ public class SystemClassPath extends Bas
     }
 
     private void rebuildJavaClassPathVariable() throws Exception {
-        URLClassLoader loader = getSystemLoader();
-        Object cp = getURLClassPath(loader);
-        Method getURLsMethod = getGetURLsMethod();
-        URL[] urls = (URL[]) getURLsMethod.invoke(cp);
+        final URLClassLoader loader = getSystemLoader();
+        final Object cp = getURLClassPath(loader);
+        final Method getURLsMethod = getGetURLsMethod();
+        final URL[] urls = (URL[]) getURLsMethod.invoke(cp);
 
         if (urls.length < 1)
             return;
 
-        StringBuilder path = new StringBuilder(urls.length * 32);
+        final StringBuilder path = new StringBuilder(urls.length * 32);
 
         File s = new File(URLDecoder.decode(urls[0].getFile(), "UTF-8"));
         path.append(s.getPath());
@@ -88,11 +91,12 @@ public class SystemClassPath extends Bas
 
     private Method getGetURLsMethod() {
         return AccessController.doPrivileged(new PrivilegedAction<Method>() {
+            @Override
             public Method run() {
                 try {
-                    URLClassLoader loader = getSystemLoader();
-                    Object cp = getURLClassPath(loader);
-                    Class<?> clazz = cp.getClass();
+                    final URLClassLoader loader = getSystemLoader();
+                    final Object cp = getURLClassPath(loader);
+                    final Class<?> clazz = cp.getClass();
 
                      try {
                          return clazz.getDeclaredMethod("getURLs", URL.class);



Mime
View raw message