/me is checking, thanks!
Romain Manni-Bucau @rmannibucau http://www.tomitribe.com http://rmannibucau.wordpress.com https://github.com/rmannibucau 2014-10-20 13:19 GMT+02:00 Thiago Veronezi <[email protected]>: > Hi Romain, > > I think there is a file missing in this commit. It breaks > "CheckDescriptorLocationTest.java". > > []s, > Thiago. > > > On Mon, Oct 20, 2014 at 4:24 AM, <[email protected]> wrote: > >> Repository: tomee >> Updated Branches: >> refs/heads/develop 0937a91bd -> 71a997360 >> >> >> TOMEE-1418 support tomcat classloader config in openejb (temp) loaders >> >> >> Project: http://git-wip-us.apache.org/repos/asf/tomee/repo >> Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/71a99736 >> Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/71a99736 >> Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/71a99736 >> >> Branch: refs/heads/develop >> Commit: 71a997360230c72fbb208f9b2f3fedf63c4dbf97 >> Parents: 0937a91 >> Author: Romain Manni-Bucau <[email protected]> >> Authored: Mon Oct 20 10:24:08 2014 +0200 >> Committer: Romain Manni-Bucau <[email protected]> >> Committed: Mon Oct 20 10:24:08 2014 +0200 >> >> ---------------------------------------------------------------------- >> .../apache/openejb/assembler/DeployerEjb.java | 2 +- >> .../org/apache/openejb/config/AppValidator.java | 2 +- >> .../openejb/config/ConfigurationFactory.java | 4 +- >> .../apache/openejb/config/DeploymentLoader.java | 45 +++++++--- >> .../openejb/config/QuickContextXmlParser.java | 94 -------------------- >> .../tomee/catalina/TomcatWebAppBuilder.java | 68 +++++++++++++- >> 6 files changed, 105 insertions(+), 110 deletions(-) >> ---------------------------------------------------------------------- >> >> >> >> http://git-wip-us.apache.org/repos/asf/tomee/blob/71a99736/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java >> ---------------------------------------------------------------------- >> diff --git >> a/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java >> b/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java >> index 871bd06..2939214 100644 >> --- >> a/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java >> +++ >> b/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java >> @@ -184,7 +184,7 @@ public class DeployerEjb implements Deployer { >> AppInfo appInfo = null; >> >> try { >> - appModule = deploymentLoader.load(file); >> + appModule = deploymentLoader.load(file, null); >> >> // Add any alternate deployment descriptors to the modules >> final Map<String, DeploymentModule> modules = new TreeMap<>(); >> >> >> http://git-wip-us.apache.org/repos/asf/tomee/blob/71a99736/container/openejb-core/src/main/java/org/apache/openejb/config/AppValidator.java >> ---------------------------------------------------------------------- >> diff --git >> a/container/openejb-core/src/main/java/org/apache/openejb/config/AppValidator.java >> b/container/openejb-core/src/main/java/org/apache/openejb/config/AppValidator.java >> index 9f3f552..6cbcd3b 100644 >> --- >> a/container/openejb-core/src/main/java/org/apache/openejb/config/AppValidator.java >> +++ >> b/container/openejb-core/src/main/java/org/apache/openejb/config/AppValidator.java >> @@ -288,7 +288,7 @@ public class AppValidator { >> for (final Object obj : line.getArgList()) { >> final String module = (String) obj; >> final File file = new File(module); >> - final AppModule appModule = deploymentLoader.load(file); >> + final AppModule appModule = deploymentLoader.load(file, >> null); >> validator.validate(appModule); >> } >> } catch (final Exception e) { >> >> >> http://git-wip-us.apache.org/repos/asf/tomee/blob/71a99736/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java >> ---------------------------------------------------------------------- >> diff --git >> a/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java >> b/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java >> index fe0287e..7544c15 100644 >> --- >> a/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java >> +++ >> b/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java >> @@ -808,7 +808,7 @@ public class ConfigurationFactory implements >> OpenEjbConfigurationFactory { >> logger.debug("Beginning load: " + jarFile.getAbsolutePath()); >> >> try { >> - final AppModule appModule = deploymentLoader.load(jarFile); >> + final AppModule appModule = deploymentLoader.load(jarFile, >> null); >> final AppInfo appInfo = configureApplication(appModule); >> >> // TODO This is temporary -- we need to do this in >> AppInfoBuilder >> @@ -869,7 +869,7 @@ public class ConfigurationFactory implements >> OpenEjbConfigurationFactory { >> logger.info("Beginning load: " + jarFile.getAbsolutePath()); >> >> try { >> - final AppModule module = deploymentLoader.load(jarFile); >> + final AppModule module = deploymentLoader.load(jarFile, >> null); >> >> >> collection.getAdditionalLibraries().addAll(module.getAdditionalLibraries()); >> >> collection.getClientModules().addAll(module.getClientModules()); >> >> >> http://git-wip-us.apache.org/repos/asf/tomee/blob/71a99736/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java >> ---------------------------------------------------------------------- >> diff --git >> a/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java >> b/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java >> index a9a7d9f..7b1f995 100644 >> --- >> a/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java >> +++ >> b/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java >> @@ -111,7 +111,12 @@ public class DeploymentLoader implements >> DeploymentFilterable { >> private static String ALTDD = >> SystemInstance.get().getOptions().get(OPENEJB_ALTDD_PREFIX, (String) null); >> private volatile List<URL> containerUrls = null; >> >> - public AppModule load(final File jarFile) throws OpenEJBException { >> + /** >> + * @param jarFile the app file (war, jar, ear) >> + * @param additionalAppDescriptors potentially some more desriptor, >> used *only* today for context.xml of tomcat >> + * @return the loaded module >> + */ >> + public AppModule load(final File jarFile, final ExternalConfiguration >> config) throws OpenEJBException { >> // verify we have a valid file >> final String jarPath; >> try { >> @@ -211,7 +216,7 @@ public class DeploymentLoader implements >> DeploymentFilterable { >> final File file = URLs.toFile(baseUrl); >> >> // Standalone Web Module >> - final WebModule webModule = >> createWebModule(file.getAbsolutePath(), baseUrl, getOpenEJBClassLoader(), >> getContextRoot(), getModuleName()); >> + final WebModule webModule = >> createWebModule(file.getAbsolutePath(), baseUrl, getOpenEJBClassLoader(), >> getContextRoot(), getModuleName(), config); >> // important to use the webapp classloader here otherwise >> each time we'll check something using loadclass it will fail (=== empty >> classloader) >> final AppModule appModule = new >> AppModule(webModule.getClassLoader(), file.getAbsolutePath(), new >> Application(), true); >> addWebModule(webModule, appModule); >> @@ -775,12 +780,12 @@ public class DeploymentLoader implements >> DeploymentFilterable { >> return ejbModule; >> } >> >> - private WebModule createWebModule(final String jar, final URL warUrl, >> final ClassLoader parentClassLoader, final String contextRoot, final String >> moduleName) throws OpenEJBException { >> - return createWebModule(jar, URLs.toFilePath(warUrl), >> parentClassLoader, contextRoot, moduleName); >> + private WebModule createWebModule(final String jar, final URL warUrl, >> final ClassLoader parentClassLoader, final String contextRoot, final String >> moduleName, final ExternalConfiguration config) throws OpenEJBException { >> + return createWebModule(jar, URLs.toFilePath(warUrl), >> parentClassLoader, contextRoot, moduleName, config); >> } >> >> public void addWebModule(final AppModule appModule, final URL warUrl, >> final ClassLoader parentClassLoader, final String contextRoot, final String >> moduleName) throws OpenEJBException { >> - final WebModule webModule = >> createWebModule(appModule.getJarLocation(), URLs.toFilePath(warUrl), >> parentClassLoader, contextRoot, moduleName); >> + final WebModule webModule = >> createWebModule(appModule.getJarLocation(), URLs.toFilePath(warUrl), >> parentClassLoader, contextRoot, moduleName, null); >> addWebModule(webModule, appModule); >> } >> >> @@ -894,7 +899,7 @@ public class DeploymentLoader implements >> DeploymentFilterable { >> >> } >> >> - public WebModule createWebModule(final String appId, final String >> warPath, final ClassLoader parentClassLoader, final String contextRoot, >> final String moduleName) throws OpenEJBException { >> + public WebModule createWebModule(final String appId, final String >> warPath, final ClassLoader parentClassLoader, final String contextRoot, >> final String moduleName, final ExternalConfiguration config) throws >> OpenEJBException { >> File warFile = new File(warPath); >> if (!warFile.isDirectory()) { >> warFile = unpack(warFile); >> @@ -989,10 +994,18 @@ public class DeploymentLoader implements >> DeploymentFilterable { >> webUrls.addAll(addedUrls); >> >> // context.xml can define some additional libraries >> - final File contextXml = new File(warFile, "META-INF/context.xml"); >> - if (contextXml.exists()) { >> - final QuickContextXmlParser parser = >> QuickContextXmlParser.parse(contextXml); >> - webUrls.addAll(parser.getAdditionalURLs()); >> + if (config != null) { // we don't test all !=null inline to show >> that config will get extra params in the future and that it is hierarchic >> + if (config.getClasspath() != null) { >> + final Set<URL> contextXmlUrls = new LinkedHashSet<>(); >> + for (final String location : config.getClasspath()) { >> + try { >> + webUrls.add(new File(location).toURI().toURL()); >> + } catch (final MalformedURLException e) { >> + throw new IllegalArgumentException(e); >> + } >> + } >> + webUrls.addAll(contextXmlUrls); >> + } >> } >> >> final ClassLoaderConfigurer configurer = >> QuickJarsTxtParser.parse(new File(warFile, "WEB-INF/" + >> QuickJarsTxtParser.FILE_NAME)); >> @@ -2050,4 +2063,16 @@ public class DeploymentLoader implements >> DeploymentFilterable { >> public static void reloadAltDD() { >> ALTDD = >> SystemInstance.get().getOptions().get(OPENEJB_ALTDD_PREFIX, (String) null); >> } >> + >> + public static class ExternalConfiguration { >> + private final String[] classpath; >> + >> + public ExternalConfiguration(final String[] classpath) { >> + this.classpath = classpath; >> + } >> + >> + public String[] getClasspath() { >> + return classpath; >> + } >> + } >> } >> >> >> http://git-wip-us.apache.org/repos/asf/tomee/blob/71a99736/container/openejb-core/src/main/java/org/apache/openejb/config/QuickContextXmlParser.java >> ---------------------------------------------------------------------- >> diff --git >> a/container/openejb-core/src/main/java/org/apache/openejb/config/QuickContextXmlParser.java >> b/container/openejb-core/src/main/java/org/apache/openejb/config/QuickContextXmlParser.java >> deleted file mode 100644 >> index 92481f7..0000000 >> --- >> a/container/openejb-core/src/main/java/org/apache/openejb/config/QuickContextXmlParser.java >> +++ /dev/null >> @@ -1,94 +0,0 @@ >> -/* >> - * 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.config; >> - >> -import org.apache.openejb.loader.ProvisioningUtil; >> -import org.apache.openejb.util.PropertyPlaceHolderHelper; >> -import org.xml.sax.Attributes; >> -import org.xml.sax.SAXException; >> -import org.xml.sax.helpers.DefaultHandler; >> - >> -import javax.xml.parsers.SAXParser; >> -import javax.xml.parsers.SAXParserFactory; >> -import java.io.File; >> -import java.net.MalformedURLException; >> -import java.net.URL; >> -import java.util.Collection; >> -import java.util.LinkedHashSet; >> -import java.util.Set; >> -import java.util.StringTokenizer; >> - >> -public class QuickContextXmlParser extends DefaultHandler { >> - private static final SAXParserFactory FACTORY = >> SAXParserFactory.newInstance(); >> - >> - static { >> - FACTORY.setNamespaceAware(true); >> - FACTORY.setValidating(false); >> - } >> - >> - private String virtualClasspath = ""; >> - >> - @Override >> - public void startElement(final String uri, final String localName, >> final String qName, final Attributes attributes) throws SAXException { >> - if ("Loader".equalsIgnoreCase(localName)) { >> - final String className = attributes.getValue("className"); >> - if (className != null) { >> - if >> ("org.apache.catalina.loader.VirtualWebappLoader".equals(className) >> - || >> "org.apache.tomee.catalina.ProvisioningWebappLoader".equals(className)) { >> - virtualClasspath = >> attributes.getValue("virtualClasspath"); >> - } >> - } >> - } >> - } >> - >> - public Collection<URL> getAdditionalURLs() { >> - final Set<URL> set = new LinkedHashSet<>(); >> - >> - if (virtualClasspath != null) { >> - final StringTokenizer tkn = new >> StringTokenizer(virtualClasspath, ";"); >> - while (tkn.hasMoreTokens()) { >> - final String token = tkn.nextToken().trim(); >> - if (token.isEmpty()) { >> - continue; >> - } >> - >> - final Set<String> locations = >> ProvisioningUtil.realLocation(PropertyPlaceHolderHelper.simpleValue(token)); >> - for (final String location : locations) { >> - try { >> - set.add(new File(location).toURI().toURL()); >> - } catch (final MalformedURLException e) { >> - throw new IllegalArgumentException(e); >> - } >> - } >> - } >> - } >> - >> - return set; >> - } >> - >> - public static QuickContextXmlParser parse(final File contextXml) { >> - final QuickContextXmlParser handler = new QuickContextXmlParser(); >> - try { >> - final SAXParser parser = FACTORY.newSAXParser(); >> - parser.parse(contextXml, handler); >> - } catch (final Exception e) { >> - // no-op: not parseable so ignoring >> - } >> - return handler; >> - } >> -} >> >> >> http://git-wip-us.apache.org/repos/asf/tomee/blob/71a99736/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java >> ---------------------------------------------------------------------- >> diff --git >> a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java >> b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java >> index 5fc5856..1f9273d 100644 >> --- >> a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java >> +++ >> b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java >> @@ -31,7 +31,9 @@ import org.apache.catalina.Realm; >> import org.apache.catalina.Service; >> import org.apache.catalina.UserDatabase; >> import org.apache.catalina.Valve; >> +import org.apache.catalina.WebResource; >> import org.apache.catalina.WebResourceRoot; >> +import org.apache.catalina.WebResourceSet; >> import org.apache.catalina.core.ContainerBase; >> import org.apache.catalina.core.NamingContextListener; >> import org.apache.catalina.core.StandardContext; >> @@ -94,6 +96,7 @@ import >> org.apache.openejb.core.ivm.naming.SystemComponentReference; >> import org.apache.openejb.jee.EnvEntry; >> import org.apache.openejb.jee.WebApp; >> import org.apache.openejb.loader.IO; >> +import org.apache.openejb.loader.ProvisioningUtil; >> import org.apache.openejb.loader.SystemInstance; >> import org.apache.openejb.server.httpd.BeginWebBeansListener; >> import org.apache.openejb.server.httpd.EndWebBeansListener; >> @@ -101,7 +104,9 @@ import org.apache.openejb.server.httpd.HttpSession; >> import org.apache.openejb.spi.ContainerSystem; >> import org.apache.openejb.util.LogCategory; >> import org.apache.openejb.util.Logger; >> +import org.apache.openejb.util.URLs; >> import org.apache.openejb.util.proxy.LocalBeanProxyFactory; >> +import org.apache.openejb.util.reflection.Reflections; >> import org.apache.tomcat.InstanceManager; >> import org.apache.tomcat.JarScanFilter; >> import org.apache.tomcat.util.descriptor.web.ApplicationParameter; >> @@ -155,6 +160,7 @@ import java.util.Collections; >> import java.util.HashMap; >> import java.util.HashSet; >> import java.util.Iterator; >> +import java.util.LinkedList; >> import java.util.List; >> import java.util.Map; >> import java.util.Properties; >> @@ -165,6 +171,7 @@ import java.util.concurrent.atomic.AtomicReference; >> import java.util.jar.JarEntry; >> import java.util.jar.JarFile; >> >> +import static java.util.Arrays.asList; >> import static org.apache.tomee.catalina.Contexts.warPath; >> >> /** >> @@ -1948,7 +1955,7 @@ public class TomcatWebAppBuilder implements >> WebAppBuilder, ContextListener, Pare >> final AppInfo appInfo; >> try { >> file = file.getCanonicalFile().getAbsoluteFile(); >> - final AppModule appModule = >> deploymentLoader.load(file); >> + final AppModule appModule = >> deploymentLoader.load(file, null); >> >> // Ignore any standalone web modules - this >> happens when the app is unpaked and doesn't have a WEB-INF dir >> if (appModule.getDeploymentModule().size() == 1 >> && appModule.getWebModules().size() == 1) { >> @@ -2056,7 +2063,7 @@ public class TomcatWebAppBuilder implements >> WebAppBuilder, ContextListener, Pare >> final TomcatDeploymentLoader tomcatDeploymentLoader = new >> TomcatDeploymentLoader(standardContext, id); >> final AppModule appModule; >> try { >> - appModule = >> tomcatDeploymentLoader.load(Contexts.warPath(standardContext)); >> + appModule = >> tomcatDeploymentLoader.load(Contexts.warPath(standardContext), >> configuredClasspath(standardContext)); >> } catch (final OpenEJBException e) { >> throw new TomEERuntimeException(e); >> } >> @@ -2067,6 +2074,63 @@ public class TomcatWebAppBuilder implements >> WebAppBuilder, ContextListener, Pare >> return appModule; >> } >> >> + private static DeploymentLoader.ExternalConfiguration >> configuredClasspath(final StandardContext standardContext) { >> + final Loader loader = standardContext.getLoader(); >> + if (loader != null) { >> + final ClassLoader cl = >> standardContext.getLoader().getClassLoader(); >> + if (cl == null) { >> + return null; >> + } >> + >> + final Collection<String> cp = new LinkedList<>(); >> + >> + final String name = loader.getClass().getName(); >> + // no more in tomcat 8 but keep it while we maintain t7 >> integration >> + if >> ("org.apache.catalina.loader.VirtualWebappLoader".equals(name) >> + || >> "org.apache.tomee.catalina.ProvisioningWebappLoader".equals(name)) { >> + final Object virtualClasspath = Reflections.get(loader, >> "virtualClasspath"); >> + if (virtualClasspath != null) { >> + for (final String str : >> virtualClasspath.toString().split(";")) { >> + cp.addAll(ProvisioningUtil.realLocation(str)); >> + } >> + } >> + } else { >> + final WebResourceRoot webResources = >> standardContext.getResources(); >> + if (webResources != null) { // to enhance >> + for (final WebResourceSet[] sets : >> asList(webResources.getPreResources(), webResources.getPostResources(), >> webResources.getJarResources())) { >> + for (final WebResourceSet wr : sets) { >> + final URL base = wr.getBaseUrl(); >> + if (base != null) { >> + final File baseFile = URLs.toFile(base); >> + if (baseFile.isDirectory()) { >> + final String[] libs = >> wr.list("/WEB-INF/lib/"); >> + if (libs != null) { >> + for (final String resource : >> libs) { >> + cp.add(new File(baseFile, >> resource).getAbsolutePath()); >> + } >> + } >> + >> + final WebResource classes = >> wr.getResource("/WEB-INF/classes/"); >> + if (classes != null) { >> + final String path = >> classes.getCanonicalPath(); >> + if (path != null) { >> + cp.add(path); >> + } >> + } >> + } >> + } >> + } >> + } >> + } >> + } >> + >> + if (!cp.isEmpty()) { >> + return new >> DeploymentLoader.ExternalConfiguration(cp.toArray(new String[cp.size()])); >> + } >> + } >> + return null; >> + } >> + >> /** >> * Creates a new {@link WebModule} instance from given >> * tomcat context instance. >> >>
