Author: dblevins
Date: Mon Dec  3 03:50:07 2012
New Revision: 1416343

URL: http://svn.apache.org/viewvc?rev=1416343&view=rev
Log:
Improvements in <Deployments> aimed to make properly implementing TOMEE-620 
easier
Cuts the messy part out where we turn Files into URLs then to Strings then to 
URLs then back into Files again
No more URLs, no Strings, just Files

Modified:
    
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
    
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java
    
openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/Files.java

Modified: 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java?rev=1416343&r1=1416342&r2=1416343&view=diff
==============================================================================
--- 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
 (original)
+++ 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
 Mon Dec  3 03:50:07 2012
@@ -465,24 +465,14 @@ public class ConfigurationFactory implem
         }
 
 
-        final List<String> declaredApps = getDeclaredApps();
+        final List<File> declaredApps = getDeclaredApps();
 
-        for (final String pathname : declaredApps) {
+        for (final File jarFile : declaredApps) {
             try {
-                try {
-                    final File jarFile;
-                    if (pathname.startsWith("file:/")) {
-                        jarFile = new File(new URI(pathname));
-                    } else {
-                        jarFile = new File(pathname);
-                    }
 
-                    final AppInfo appInfo = configureApplication(jarFile);
-                    sys.containerSystem.applications.add(appInfo);
+                final AppInfo appInfo = configureApplication(jarFile);
+                sys.containerSystem.applications.add(appInfo);
 
-                } catch (URISyntaxException e) {
-                    logger.error("Invalid declaredApp URI '" + pathname + "'", 
e);
-                }
             } catch (OpenEJBException alreadyHandled) {
                 final DeploymentExceptionManager exceptionManager = 
SystemInstance.get().getComponent(DeploymentExceptionManager.class);
                 exceptionManager.pushDelpoymentException(alreadyHandled);
@@ -543,71 +533,62 @@ public class ConfigurationFactory implem
         return finished;
     }
 
-    private List<String> getDeclaredApps() {
+    private List<File> getDeclaredApps() {
         // make a copy of the list because we update it
         final List<Deployments> deployments = new ArrayList<Deployments>();
+
         if (openejb != null) {
             deployments.addAll(openejb.getDeployments());
         }
-        File additionalDeploymentFile;
+
         try {
-            additionalDeploymentFile = 
SystemInstance.get().getBase().getFile(ADDITIONAL_DEPLOYMENTS, false);
-        } catch (IOException e) {
-            additionalDeploymentFile = null;
-        }
-        if (additionalDeploymentFile.exists()) {
-            InputStream fis = null;
-            try {
-                fis = IO.read(additionalDeploymentFile);
-                final AdditionalDeployments additionalDeployments = 
JaxbOpenejb.unmarshal(AdditionalDeployments.class, fis);
-                deployments.addAll(additionalDeployments.getDeployments());
-            } catch (Exception e) {
-                logger.error("can't read " + ADDITIONAL_DEPLOYMENTS, e);
-            } finally {
-                IO.close(fis);
+            final File additionalDeploymentFile = 
SystemInstance.get().getBase().getFile(ADDITIONAL_DEPLOYMENTS, false);
+
+            if (additionalDeploymentFile.exists()) {
+                InputStream fis = null;
+                try {
+                    fis = IO.read(additionalDeploymentFile);
+                    final AdditionalDeployments additionalDeployments = 
JaxbOpenejb.unmarshal(AdditionalDeployments.class, fis);
+                    deployments.addAll(additionalDeployments.getDeployments());
+                } catch (Exception e) {
+                    logger.error("can't read " + ADDITIONAL_DEPLOYMENTS, e);
+                } finally {
+                    IO.close(fis);
+                }
             }
+        } catch (IOException e) {
         }
 
         // resolve jar locations //////////////////////////////////////  BEGIN 
 ///////
 
         final FileUtils base = SystemInstance.get().getBase();
 
-        final List<URL> declaredAppsUrls = new ArrayList<URL>();
+        final List<File> declaredAppsUrls = new ArrayList<File>();
         try {
             for (final Deployments deployment : deployments) {
                 DeploymentsResolver.loadFrom(deployment, base, 
declaredAppsUrls);
             }
         } catch (SecurityException ignored) {
         }
-        return toString(declaredAppsUrls);
+
+        return declaredAppsUrls;
     }
 
-    public ArrayList<File> getModulesFromClassPath(List<String> declaredApps, 
final ClassLoader classLoader) {
+    public ArrayList<File> getModulesFromClassPath(List<File> declaredApps, 
final ClassLoader classLoader) {
         final FileUtils base = SystemInstance.get().getBase();
-        if (declaredApps == null) {
-            declaredApps = getDeclaredApps();
-        }
+
         final List<URL> classpathAppsUrls = new ArrayList<URL>();
         DeploymentsResolver.loadFromClasspath(base, classpathAppsUrls, 
classLoader);
 
         final ArrayList<File> jarFiles = new ArrayList<File>();
         for (final URL path : classpathAppsUrls) {
-            if (declaredApps.contains(URLs.toFilePath(path))) continue;
+            final File file = URLs.toFile(path);
 
-            jarFiles.add(new File(URLs.toFilePath(path)));
-        }
-        return jarFiles;
-    }
+            if (declaredApps != null && declaredApps.contains(file)) continue;
 
-    private List<String> toString(final List<URL> urls) {
-        final List<String> toReturn = new ArrayList<String>(urls.size());
-        for (final URL url : urls) {
-            try {
-                toReturn.add(url.toString());
-            } catch (Exception ignore) {
-            }
+            jarFiles.add(file);
         }
-        return toReturn;
+        return jarFiles;
     }
 
     public ContainerInfo createContainerInfo(final Container container) throws 
OpenEJBException {

Modified: 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java?rev=1416343&r1=1416342&r2=1416343&view=diff
==============================================================================
--- 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java
 (original)
+++ 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java
 Mon Dec  3 03:50:07 2012
@@ -54,7 +54,7 @@ public class DeploymentsResolver impleme
 
     private static final Logger logger = DeploymentLoader.logger;
 
-    public static void loadFrom(final Deployments dep, final FileUtils path, 
final List<URL> jarList) {
+    public static void loadFrom(final Deployments dep, final FileUtils path, 
final List<File> jarList) {
 
         if (dep.getDir() != null) {
 
@@ -93,24 +93,19 @@ public class DeploymentsResolver impleme
         }
     }
 
-    private static void loadFromFile(Deployments dep, FileUtils path, 
List<URL> jarList) {
+    private static void loadFromFile(Deployments dep, FileUtils path, 
List<File> jarList) {
         final File file = Files.path(path.getDirectory(), dep.getFile());
 
         Files.exists(file);
         Files.readable(file);
         Files.file(file);
 
-        try {
-            final URL url = file.toURI().toURL();
-            if (!jarList.contains(url)) {
-                jarList.add(url);
-            }
-        } catch (MalformedURLException e) {
-            throw new RuntimeException("Cannot convert file to URL: 
file="+file.getAbsolutePath(), e);
+        if (!jarList.contains(file)) {
+            jarList.add(file);
         }
     }
 
-    private static void loadFromDir(Deployments dep, FileUtils path, List<URL> 
jarList) {
+    private static void loadFromDir(Deployments dep, FileUtils path, 
List<File> jarList) {
         final File dir = Files.path(path.getDirectory(), dep.getDir());
 
         Files.exists(dir);
@@ -130,14 +125,8 @@ public class DeploymentsResolver impleme
         }
 
         for (File file : files.values()) {
-            try {
-                final URL url = file.toURI().toURL();
-
-                if (!jarList.contains(url)) {
-                    jarList.add(url);
-                }
-            } catch (MalformedURLException e) {
-                throw new RuntimeException("Cannot convert file to URL: 
file="+file.getAbsolutePath(), e);
+            if (!jarList.contains(file)) {
+                jarList.add(file);
             }
         }
     }

Modified: 
openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/Files.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/Files.java?rev=1416343&r1=1416342&r2=1416343&view=diff
==============================================================================
--- 
openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/Files.java
 (original)
+++ 
openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/Files.java
 Mon Dec  3 03:50:07 2012
@@ -39,7 +39,7 @@ public class Files {
             }
         }
 
-        return dir;
+        return dir.getAbsoluteFile();
     }
 
     public static File path(File dir, String... parts) {
@@ -57,7 +57,7 @@ public class Files {
             base = new File(base, parts[i]);
         }
 
-        return base;
+        return base.getAbsoluteFile();
     }
 
     public static List<File> collect(final File dir, final String regex) {


Reply via email to