Return-Path: X-Original-To: apmail-openejb-commits-archive@www.apache.org Delivered-To: apmail-openejb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B0C94911E for ; Wed, 1 Feb 2012 08:55:58 +0000 (UTC) Received: (qmail 20003 invoked by uid 500); 1 Feb 2012 08:55:58 -0000 Delivered-To: apmail-openejb-commits-archive@openejb.apache.org Received: (qmail 19945 invoked by uid 500); 1 Feb 2012 08:55:57 -0000 Mailing-List: contact commits-help@openejb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@openejb.apache.org Delivered-To: mailing list commits@openejb.apache.org Received: (qmail 19937 invoked by uid 99); 1 Feb 2012 08:55:56 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 Feb 2012 08:55:56 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 Feb 2012 08:55:51 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id DAAD12388A29 for ; Wed, 1 Feb 2012 08:55:29 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1239012 - /openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java Date: Wed, 01 Feb 2012 08:55:29 -0000 To: commits@openejb.apache.org From: andygumbrecht@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120201085529.DAAD12388A29@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: andygumbrecht Date: Wed Feb 1 08:55:29 2012 New Revision: 1239012 URL: http://svn.apache.org/viewvc?rev=1239012&view=rev Log: Apply final where applicable. Provided List jarList was being checked for contains(String) rather than contains(URL). Filter out duplicate URLs due to case sensitivity in loadFromClasspath <-- The fact that we actually get duplicate URLs is still an issue. Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java 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=1239012&r1=1239011&r2=1239012&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 Wed Feb 1 08:55:29 2012 @@ -46,7 +46,7 @@ public class DeploymentsResolver impleme private static final Logger logger = DeploymentLoader.logger; - public static void loadFrom(Deployments dep, FileUtils path, List jarList) { + public static void loadFrom(final Deployments dep, final FileUtils path, final List jarList) { //////////////////////////////// // @@ -55,9 +55,10 @@ public class DeploymentsResolver impleme //////////////////////////////// if (dep.getDir() == null && dep.getJar() != null) { try { - File jar = path.getFile(dep.getJar(), false); - if (!jarList.contains(jar.getAbsolutePath())) { - jarList.add(jar.toURI().toURL()); + final File jar = path.getFile(dep.getJar(), false); + final URL url = jar.toURI().toURL(); + if (!jarList.contains(url)) { + jarList.add(url); } } catch (Exception ignored) { } @@ -77,33 +78,36 @@ public class DeploymentsResolver impleme // Unpacked "Jar" directory with descriptor // //////////////////////////////// - File ejbJarXml = new File(dir, "META-INF" + File.separator + "ejb-jar.xml"); + final File ejbJarXml = new File(dir, "META-INF" + File.separator + "ejb-jar.xml"); if (ejbJarXml.exists()) { try { - if (!jarList.contains(dir.getAbsolutePath())) { - jarList.add(dir.toURI().toURL()); + final URL url = dir.toURI().toURL(); + if (!jarList.contains(url)) { + jarList.add(url); } } catch (MalformedURLException ignore) { } return; } - File appXml = new File(dir, "META-INF" + File.separator + "application.xml"); + final File appXml = new File(dir, "META-INF" + File.separator + "application.xml"); if (appXml.exists()) { try { - if (!jarList.contains(dir.getAbsolutePath())) { - jarList.add(dir.toURI().toURL()); + final URL url = dir.toURI().toURL(); + if (!jarList.contains(url)) { + jarList.add(url); } } catch (MalformedURLException ignore) { } return; } - File raXml = new File(dir, "META-INF" + File.separator + "ra.xml"); + final File raXml = new File(dir, "META-INF" + File.separator + "ra.xml"); if (raXml.exists()) { try { - if (!jarList.contains(dir.getAbsolutePath())) { - jarList.add(dir.toURI().toURL()); + final URL url = dir.toURI().toURL(); + if (!jarList.contains(url)) { + jarList.add(url); } } catch (MalformedURLException ignore) { } @@ -116,20 +120,24 @@ public class DeploymentsResolver impleme // //////////////////////////////// boolean hasNestedArchives = false; - for (File file : dir.listFiles()) { + for (final File file : dir.listFiles()) { try { - if (file.getName().endsWith(".jar") || file.getName().endsWith(".war")|| file.getName().endsWith(".rar")|| file.getName().endsWith(".ear")) { - if (jarList.contains(file.getAbsolutePath())) continue; - jarList.add(file.toURI().toURL()); + + final URL url = file.toURI().toURL(); + if (jarList.contains(url)) continue; + + if (file.getName().endsWith(".jar") || file.getName().endsWith(".war") || file.getName().endsWith(".rar") || file.getName().endsWith(".ear")) { + jarList.add(url); hasNestedArchives = true; - } else if (new File(file, "META-INF").exists()){ // Unpacked ear or jar - jarList.add(file.toURI().toURL()); + } else if (new File(file, "META-INF").exists()) { // Unpacked ear or jar + jarList.add(url); hasNestedArchives = true; - } else if (new File(file, "WEB-INF").exists()){ // Unpacked webapp - jarList.add(file.toURI().toURL()); + } else if (new File(file, "WEB-INF").exists()) { // Unpacked webapp + jarList.add(url); hasNestedArchives = true; } - } catch (Exception ignore) { + } catch (Exception e) { + logger.debug("loadFrom", e); } } @@ -139,13 +147,14 @@ public class DeploymentsResolver impleme // //////////////////////////////// if (!hasNestedArchives) { - HashMap files = new HashMap(); + final HashMap files = new HashMap(); DeploymentLoader.scanDir(dir, files, ""); - for (String fileName : files.keySet()) { + for (final String fileName : files.keySet()) { if (fileName.endsWith(".class")) { try { - if (!jarList.contains(dir.getAbsolutePath())) { - jarList.add(dir.toURI().toURL()); + final URL url = dir.toURI().toURL(); + if (!jarList.contains(url)) { + jarList.add(url); } } catch (MalformedURLException ignore) { } @@ -171,17 +180,19 @@ public class DeploymentsResolver impleme * 2- Loading the resource is the default behaviour in case of not defining a value for any class-path pattern * This appears in step 3 of the above algorithm. */ - public static void loadFromClasspath(FileUtils base, List jarList, ClassLoader classLoader) { - Options options = SystemInstance.get().getOptions(); - String include = options.get(CLASSPATH_INCLUDE, ".*"); - String exclude = options.get(CLASSPATH_EXCLUDE, ""); - Set requireDescriptors = options.getAll(CLASSPATH_REQUIRE_DESCRIPTOR, RequireDescriptors.CLIENT); - boolean filterDescriptors = options.get(CLASSPATH_FILTER_DESCRIPTORS, false); - boolean filterSystemApps = options.get(CLASSPATH_FILTER_SYSTEMAPPS, true); + public static void loadFromClasspath(final FileUtils base, final List jarList, final ClassLoader classLoader) { + final Options options = SystemInstance.get().getOptions(); + final String include = options.get(CLASSPATH_INCLUDE, ".*"); + final String exclude = options.get(CLASSPATH_EXCLUDE, ""); + final Set requireDescriptors = options.getAll(CLASSPATH_REQUIRE_DESCRIPTOR, RequireDescriptors.CLIENT); + final boolean filterDescriptors = options.get(CLASSPATH_FILTER_DESCRIPTORS, false); + final boolean filterSystemApps = options.get(CLASSPATH_FILTER_SYSTEMAPPS, true); try { UrlSet urlSet = new UrlSet(classLoader); - UrlSet includes = urlSet.matching(include); + + //final UrlSet includes = urlSet.matching(include); + urlSet = urlSet.exclude(ClassLoader.getSystemClassLoader().getParent()); urlSet = urlSet.excludeJavaExtDirs(); urlSet = urlSet.excludeJavaEndorsedDirs(); @@ -191,7 +202,7 @@ public class DeploymentsResolver impleme // save the prefiltered list of jars before excluding system apps // so that we can choose not to filter modules with descriptors on the full list - UrlSet prefiltered = urlSet; + final UrlSet prefiltered = urlSet; // we should exclude system apps before and apply user properties after @@ -202,14 +213,23 @@ public class DeploymentsResolver impleme if (prefiltered.size() == urlSet.size()) { urlSet = NewLoaderLogic.applyBuiltinExcludes(urlSet); - if (filterSystemApps){ + if (filterSystemApps) { urlSet = urlSet.exclude(".*/openejb-[^/]+(.(jar|ear|war)(!/)?|/target/(test-)?classes/?)"); } } + final List urls = new ArrayList(); + final boolean isWindows = System.getProperty("os.name", "unknown").toLowerCase().startsWith("windows"); - List urls = urlSet.getUrls(); - int size = urls.size(); + for (final URL url : urlSet.getUrls()) { + final String ef = (isWindows ? url.toExternalForm().toLowerCase() : url.toExternalForm()); + final URL u = new URL(ef); + if (!urls.contains(u)) { + urls.add(u); + } + } + + final int size = urls.size(); if (size == 0 && include.length() > 0) { logger.warning("No classpath URLs matched. Current settings: " + CLASSPATH_EXCLUDE + "='" + exclude + "', " + CLASSPATH_INCLUDE + "='" + include + "'"); return; @@ -219,7 +239,7 @@ public class DeploymentsResolver impleme logger.debug("Inspecting classpath for applications: " + urls.size() + " urls."); } else { // Has the user allowed some module types to be discoverable via scraping? - boolean willScrape = requireDescriptors.size() < RequireDescriptors.values().length; + final boolean willScrape = requireDescriptors.size() < RequireDescriptors.values().length; if (size < 50 && willScrape) { logger.info("Inspecting classpath for applications: " + urls.size() + " urls. Consider adjusting your exclude/include. Current settings: " + CLASSPATH_EXCLUDE + "='" + exclude + "', " + CLASSPATH_INCLUDE + "='" + include + "'"); @@ -229,27 +249,27 @@ public class DeploymentsResolver impleme } } - long begin = System.currentTimeMillis(); + final long begin = System.currentTimeMillis(); processUrls(urls, classLoader, requireDescriptors, base, jarList); - long end = System.currentTimeMillis(); - long time = end - begin; + final long end = System.currentTimeMillis(); + final long time = end - begin; UrlSet unchecked = new UrlSet(); - if (!filterDescriptors){ + if (!filterDescriptors) { unchecked = prefiltered.exclude(urlSet); - if (filterSystemApps){ + if (filterSystemApps) { unchecked = unchecked.exclude(".*/openejb-[^/]+(.(jar|ear|war)(./)?|/target/classes/?)"); } processUrls(unchecked.getUrls(), classLoader, EnumSet.allOf(RequireDescriptors.class), base, jarList); } if (logger.isDebugEnabled()) { - int urlCount = urlSet.getUrls().size() + unchecked.getUrls().size(); - logger.debug("URLs after filtering: "+ urlCount); - for (URL url : urlSet.getUrls()) { + final int urlCount = urlSet.getUrls().size() + unchecked.getUrls().size(); + logger.debug("URLs after filtering: " + urlCount); + for (final URL url : urlSet.getUrls()) { logger.debug("Annotations path: " + url); } - for (URL url : unchecked.getUrls()) { + for (final URL url : unchecked.getUrls()) { logger.debug("Descriptors path: " + url); } } @@ -266,12 +286,12 @@ public class DeploymentsResolver impleme } else { logger.fatal("Searched " + urls.size() + " classpath urls in " + time + " milliseconds. Average " + (time / urls.size()) + " milliseconds per url. TOO LONG!"); logger.fatal("ADJUST THE EXCLUDE/INCLUDE!!!. Current settings: " + CLASSPATH_EXCLUDE + "='" + exclude + "', " + CLASSPATH_INCLUDE + "='" + include + "'"); - List list = new ArrayList(); - for (URL url : urls) { + final List list = new ArrayList(); + for (final URL url : urls) { list.add(url.toExternalForm()); } Collections.sort(list); - for (String url : list) { + for (final String url : list) { logger.info("Matched: " + url); } } @@ -292,9 +312,9 @@ public class DeploymentsResolver impleme * @param requireDescriptors * @return */ - private static boolean shouldFilter(String include, String exclude, Set requireDescriptors) { - boolean includeNothing = include.equals(""); - boolean excludeEverything = exclude.equals(".*"); + private static boolean shouldFilter(final String include, final String exclude, final Set requireDescriptors) { + final boolean includeNothing = include.equals(""); + final boolean excludeEverything = exclude.equals(".*"); // If we are going to eliminate the entire classpath from // scanning anyway, no sense in taking the time to do it @@ -304,13 +324,11 @@ public class DeploymentsResolver impleme // If we are forcably requiring descriptors for all possible file types // then there is also no scanning and no point in filtering the // classpath down bit by bit. Return false - if (requireDescriptors.size() == RequireDescriptors.values().length) return false; - - return true; + return requireDescriptors.size() != RequireDescriptors.values().length; } private static UrlSet applyBuiltinExcludes(UrlSet urlSet) throws MalformedURLException { - + urlSet = urlSet.exclude(".*/activation(-[\\d.]+)?.jar(!/)?"); urlSet = urlSet.exclude(".*/activeio-core(-[\\d.]+)?(-incubator)?.jar(!/)?"); urlSet = urlSet.exclude(".*/activemq-(core|ra)(-[\\d.]+)?.jar(!/)?"); @@ -376,42 +394,46 @@ public class DeploymentsResolver impleme return urlSet; } - public static void processUrls(List urls, ClassLoader classLoader, Set requireDescriptors, FileUtils base, List jarList) { + public static void processUrls(final List urls, final ClassLoader classLoader, final Set requireDescriptors, final FileUtils base, final List jarList) { for (URL url : urls) { - String urlProtocol = url.getProtocol(); + final String urlProtocol = url.getProtocol(); //Currently, we only support jar and file protocol - boolean isValidURL = urlProtocol.equals("jar") || urlProtocol.equals("file"); + final boolean isValidURL = urlProtocol.equals("jar") || urlProtocol.equals("file"); if (!isValidURL) { logger.warning("Unknown protocol " + urlProtocol); continue; } - Deployments deployment; + final Deployments deployment; String path = ""; try { - - DeploymentLoader deploymentLoader = new DeploymentLoader(); - - Class moduleType = deploymentLoader.discoverModuleType(url, classLoader, requireDescriptors); + + final DeploymentLoader deploymentLoader = new DeploymentLoader(); + + final Class moduleType = deploymentLoader.discoverModuleType(url, classLoader, requireDescriptors); if (AppModule.class.isAssignableFrom(moduleType) || EjbModule.class.isAssignableFrom(moduleType) || PersistenceModule.class.isAssignableFrom(moduleType) || ConnectorModule.class.isAssignableFrom(moduleType) || ClientModule.class.isAssignableFrom(moduleType)) { - deployment = JaxbOpenejb.createDeployments(); - if (urlProtocol.equals("jar")) { - url = new URL(url.getFile().replaceFirst("!.*$", "")); - File file = toFile(url); - path = file.getAbsolutePath(); - deployment.setJar(path); - } else if (urlProtocol.equals("file")) { - File file = toFile(url); - path = file.getAbsolutePath(); - deployment.setDir(path); - } - logger.info("Found " + moduleType.getSimpleName() + " in classpath: " + path); if (AppModule.class.isAssignableFrom(moduleType) || ConnectorModule.class.isAssignableFrom(moduleType)) { + + deployment = JaxbOpenejb.createDeployments(); + + if (urlProtocol.equals("jar")) { + url = new URL(url.getFile().replaceFirst("!.*$", "")); + final File file = toFile(url); + path = file.getAbsolutePath(); + deployment.setJar(path); + } else if (urlProtocol.equals("file")) { + final File file = toFile(url); + path = file.getAbsolutePath(); + deployment.setDir(path); + } + + logger.info("Found " + moduleType.getSimpleName() + " in classpath: " + path); + loadFrom(deployment, base, jarList); } else { - if (!jarList.contains(path)){ + if (!jarList.contains(url)) { jarList.add(url); } }