Author: rmannibucau
Date: Thu Mar  7 15:16:47 2013
New Revision: 1453913

URL: http://svn.apache.org/r1453913
Log:
TOMEE-787 provisioning classloader enricher

Added:
    
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/classloader/FalseFilter.java
    
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/classloader/ProvisioningClassLoaderConfigurer.java
      - copied, changed from r1453768, 
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/classloader/DefaultClassLoaderConfigurer.java
Modified:
    
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/classloader/DefaultClassLoaderConfigurer.java

Modified: 
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/classloader/DefaultClassLoaderConfigurer.java
URL: 
http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/classloader/DefaultClassLoaderConfigurer.java?rev=1453913&r1=1453912&r2=1453913&view=diff
==============================================================================
--- 
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/classloader/DefaultClassLoaderConfigurer.java
 (original)
+++ 
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/classloader/DefaultClassLoaderConfigurer.java
 Thu Mar  7 15:16:47 2013
@@ -18,6 +18,7 @@ package org.apache.openejb.classloader;
 
 import org.apache.openejb.config.NewLoaderLogic;
 import org.apache.openejb.loader.IO;
+import org.apache.openejb.util.JarExtractor;
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
 import org.apache.openejb.util.URLs;
@@ -27,6 +28,7 @@ import org.apache.xbean.finder.filter.Fi
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
+import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
@@ -59,14 +61,24 @@ public class DefaultClassLoaderConfigure
         if (addedFolder != null) {
             final File parent = new File(addedFolder);
             if (parent.exists()) {
-                final File[] files = parent.listFiles();
-                if (files != null) {
-                    for (final File f : files) {
-                        final String name = f.getName();
-                        if (f.isDirectory() || name.endsWith(".zip") || 
name.endsWith(".jar")) {
-                            addedList.add(f.getAbsolutePath());
+                if (parent.isDirectory()) {
+                    final File[] files = parent.listFiles();
+                    if (files != null) {
+                        for (final File f : files) {
+                            final String name = f.getName();
+                            if (f.isDirectory() || name.endsWith(".zip") || 
name.endsWith(".jar")) {
+                                addedList.add(f.getAbsolutePath());
+                            }
                         }
                     }
+                } else if (addedFolder.endsWith(".zip")) {
+                    try {
+                        setAddedFolder(JarExtractor.extract(parent, 
parent.getName()).getAbsolutePath());
+                    } catch (IOException e) {
+                        LOGGER.error("Can't unpack " + parent.getPath());
+                    }
+                } else {
+                    LOGGER.warning("Ignoring " + addedFolder + " because 
that's not a folder or a zip");
                 }
             }
         }
@@ -114,13 +126,4 @@ public class DefaultClassLoaderConfigure
             return true;
         }
     }
-
-    private static class FalseFilter implements Filter {
-        public static final FalseFilter INSTANCE = new FalseFilter();
-
-        @Override
-        public boolean accept(final String name) {
-            return true;
-        }
-    }
 }

Added: 
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/classloader/FalseFilter.java
URL: 
http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/classloader/FalseFilter.java?rev=1453913&view=auto
==============================================================================
--- 
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/classloader/FalseFilter.java
 (added)
+++ 
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/classloader/FalseFilter.java
 Thu Mar  7 15:16:47 2013
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.classloader;
+
+import org.apache.xbean.finder.filter.Filter;
+
+public class FalseFilter  implements Filter {
+    public static final FalseFilter INSTANCE = new FalseFilter();
+
+    @Override
+    public boolean accept(final String name) {
+        return true;
+    }
+}

Copied: 
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/classloader/ProvisioningClassLoaderConfigurer.java
 (from r1453768, 
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/classloader/DefaultClassLoaderConfigurer.java)
URL: 
http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/classloader/ProvisioningClassLoaderConfigurer.java?p2=tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/classloader/ProvisioningClassLoaderConfigurer.java&p1=tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/classloader/DefaultClassLoaderConfigurer.java&r1=1453768&r2=1453913&rev=1453913&view=diff
==============================================================================
--- 
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/classloader/DefaultClassLoaderConfigurer.java
 (original)
+++ 
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/classloader/ProvisioningClassLoaderConfigurer.java
 Thu Mar  7 15:16:47 2013
@@ -16,24 +16,37 @@
  */
 package org.apache.openejb.classloader;
 
-import org.apache.openejb.config.NewLoaderLogic;
 import org.apache.openejb.loader.IO;
+import org.apache.openejb.loader.ProvisioningUtil;
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
 import org.apache.openejb.util.URLs;
 import org.apache.xbean.finder.filter.Filter;
 import org.apache.xbean.finder.filter.Filters;
 
+import java.io.BufferedReader;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
+import java.io.FileReader;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
 
-public class DefaultClassLoaderConfigurer implements ClassLoaderConfigurer {
-    private static final Logger LOGGER = 
Logger.getInstance(LogCategory.OPENEJB, DefaultClassLoaderConfigurer.class);
+/**
+ * Configuration
+ * <configurer prefix>.configuration = /foo/bar/config.txt
+ *
+ * Handled file format:
+ * -xbean
+ * +http://..../camel-core.jar
+ * +org.foo:bar:1.0
+ *
+ * The maven like urls needs the openejb-provisinning module
+ *
+ * Note: if a line doesn't start with '+' it is considered as an addition
+ */
+public class ProvisioningClassLoaderConfigurer implements 
ClassLoaderConfigurer {
+    private static final Logger LOGGER = 
Logger.getInstance(LogCategory.OPENEJB, 
ProvisioningClassLoaderConfigurer.class);
 
     // just some default if one is not set
     private URL[] added = new URL[0];
@@ -54,73 +67,49 @@ public class DefaultClassLoaderConfigure
         }
     }
 
-    public void setAddedFolder(final String addedFolder) {
-        final Collection<String> addedList = new ArrayList<String>();
-        if (addedFolder != null) {
-            final File parent = new File(addedFolder);
-            if (parent.exists()) {
-                final File[] files = parent.listFiles();
-                if (files != null) {
-                    for (final File f : files) {
-                        final String name = f.getName();
-                        if (f.isDirectory() || name.endsWith(".zip") || 
name.endsWith(".jar")) {
-                            addedList.add(f.getAbsolutePath());
-                        }
+    public void setConfiguration(final String configFile) {
+        final Collection<String> toAdd = new ArrayList<String>();
+        final Collection<String> toExclude = new ArrayList<String>();
+
+        BufferedReader reader = null;
+        try {
+            reader = new BufferedReader(new FileReader(configFile));
+
+            String line;
+            while ((line = reader.readLine()) != null) {
+                line = line.trim();
+                if (line.startsWith("#")) {
+                    continue;
+                }
+
+                if (line.startsWith("-")) {
+                    toExclude.add(line);
+                } else {
+                    if (line.startsWith("+")) {
+                        line = line.substring(1);
                     }
+                    toAdd.add(ProvisioningUtil.realLocation(line));
                 }
             }
+
+        } catch (final Exception e) {
+            LOGGER.error("Can't read " + configFile, e);
+        } finally {
+            IO.close(reader);
         }
 
-        added = new URL[addedList.size()];
+        added = new URL[toAdd.size()];
         int i = 0;
-        for (final String path : addedList) {
+        for (final String path : toAdd) {
             try {
                 added[i++] = new File(path).toURI().toURL();
             } catch (MalformedURLException e) {
                 LOGGER.warning("Can't add file " + path, e);
             }
         }
-    }
-
-    public void setExcludedListFile(final String excludedListFile) {
-        String[] excludedPrefixes = null;
-        if (excludedListFile != null) {
-            final File excludedFile = new File(excludedListFile);
-            if (excludedFile.exists()) {
-                FileInputStream is = null;
-                try {
-                    is = new FileInputStream(excludedFile);
-                    excludedPrefixes = NewLoaderLogic.readInputStreamList(is);
-                } catch (FileNotFoundException e) {
-                    LOGGER.error("can't read " + excludedListFile);
-                } finally {
-                    IO.close(is);
-                }
-            }
-        }
-
-        if (excludedPrefixes == null || excludedPrefixes.length == 0) {
-            excluded = TrueFilter.INSTANCE;
-        } else {
-            excluded = Filters.prefixes(excludedPrefixes);
-        }
-    }
-
-    private static class TrueFilter implements Filter {
-        public static final TrueFilter INSTANCE = new TrueFilter();
 
-        @Override
-        public boolean accept(final String name) {
-            return true;
-        }
-    }
-
-    private static class FalseFilter implements Filter {
-        public static final FalseFilter INSTANCE = new FalseFilter();
-
-        @Override
-        public boolean accept(final String name) {
-            return true;
+        if (toExclude.size() > 0) {
+            excluded = Filters.prefixes(toExclude.toArray(new 
String[toExclude.size()]));
         }
     }
 }


Reply via email to