Author: rmannibucau Date: Thu Oct 2 19:24:53 2014 New Revision: 1629050 URL: http://svn.apache.org/r1629050 Log: TOMEE-1375 mvn tomee-embedded:run as jetty:run
Added: tomee/tomee/trunk/maven/tomee-embedded-maven-plugin/src/test/ tomee/tomee/trunk/maven/tomee-embedded-maven-plugin/src/test/java/ tomee/tomee/trunk/maven/tomee-embedded-maven-plugin/src/test/java/org/ tomee/tomee/trunk/maven/tomee-embedded-maven-plugin/src/test/java/org/apache/ tomee/tomee/trunk/maven/tomee-embedded-maven-plugin/src/test/java/org/apache/openejb/ tomee/tomee/trunk/maven/tomee-embedded-maven-plugin/src/test/java/org/apache/openejb/maven/ tomee/tomee/trunk/maven/tomee-embedded-maven-plugin/src/test/java/org/apache/openejb/maven/plugins/ tomee/tomee/trunk/maven/tomee-embedded-maven-plugin/src/test/java/org/apache/openejb/maven/plugins/TomEEEmbeddedMojoTest.java tomee/tomee/trunk/maven/tomee-embedded-maven-plugin/src/test/java/org/superbiz/ tomee/tomee/trunk/maven/tomee-embedded-maven-plugin/src/test/java/org/superbiz/Endpoint.java tomee/tomee/trunk/maven/tomee-embedded-maven-plugin/src/test/resources/ tomee/tomee/trunk/maven/tomee-embedded-maven-plugin/src/test/resources/META-INF/ tomee/tomee/trunk/maven/tomee-embedded-maven-plugin/src/test/resources/META-INF/beans.xml Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java tomee/tomee/trunk/examples/deltaspike-fullstack/pom.xml tomee/tomee/trunk/maven/tomee-embedded-maven-plugin/src/main/java/org/apache/openejb/maven/plugins/TomEEEmbeddedMojo.java tomee/tomee/trunk/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Container.java tomee/tomee/trunk/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Main.java tomee/tomee/trunk/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/internal/StandardContextCustomizer.java tomee/tomee/trunk/tomee/tomee-embedded/src/test/java/org/apache/tomee/embedded/ClasspathAsWebappTest.java Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java?rev=1629050&r1=1629049&r2=1629050&view=diff ============================================================================== --- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java (original) +++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java Thu Oct 2 19:24:53 2014 @@ -216,31 +216,8 @@ public class DeploymentLoader implements final AppModule appModule = new AppModule(webModule.getClassLoader(), file.getAbsolutePath(), new Application(), true); addWebModule(webModule, appModule); - final Map<String, Object> otherDD = new HashMap<String, Object>(); - final List<URL> urls = webModule.getScannableUrls(); - final ResourceFinder finder = new ResourceFinder("", urls.toArray(new URL[urls.size()])); - otherDD.putAll(getDescriptors(finder, false)); + addWebModuleDescriptors(baseUrl, webModule, appModule); - // "persistence.xml" is done separately since we manage a list of url and not s single url - try { - final List<URL> persistenceXmls = finder.findAll(ddDir + "persistence.xml"); - if (persistenceXmls.size() >= 1) { - final URL old = (URL) otherDD.get("persistence.xml"); - if (old != null && !persistenceXmls.contains(old)) { - persistenceXmls.add(old); - } - otherDD.put("persistence.xml", persistenceXmls); - } - } catch (final IOException e) { - // ignored - } - - addConnectorModules(appModule, webModule); - - addWebPersistenceDD("persistence.xml", otherDD, appModule); - addWebPersistenceDD("persistence-fragment.xml", otherDD, appModule); - addPersistenceUnits(appModule, baseUrl); - addWebFragments(webModule, urls); appModule.setStandloneWebModule(); appModule.setDelegateFirst(true); // force it for webapps return appModule; @@ -270,7 +247,35 @@ public class DeploymentLoader implements } } - private void addConnectorModules(final AppModule appModule, final WebModule webModule) throws OpenEJBException { + public static void addWebModuleDescriptors(final URL baseUrl, final WebModule webModule, final AppModule appModule) throws OpenEJBException { + final Map<String, Object> otherDD = new HashMap<String, Object>(); + final List<URL> urls = webModule.getScannableUrls(); + final ResourceFinder finder = new ResourceFinder("", urls.toArray(new URL[urls.size()])); + otherDD.putAll(getDescriptors(finder, false)); + + // "persistence.xml" is done separately since we manage a list of url and not s single url + try { + final List<URL> persistenceXmls = finder.findAll(ddDir + "persistence.xml"); + if (persistenceXmls.size() >= 1) { + final URL old = (URL) otherDD.get("persistence.xml"); + if (old != null && !persistenceXmls.contains(old)) { + persistenceXmls.add(old); + } + otherDD.put("persistence.xml", persistenceXmls); + } + } catch (final IOException e) { + // ignored + } + + addConnectorModules(appModule, webModule); + + addWebPersistenceDD("persistence.xml", otherDD, appModule); + addWebPersistenceDD("persistence-fragment.xml", otherDD, appModule); + addPersistenceUnits(appModule, baseUrl); + addWebFragments(webModule, urls); + } + + private static void addConnectorModules(final AppModule appModule, final WebModule webModule) throws OpenEJBException { // WEB-INF if (webModule.getAltDDs().containsKey("ra.xml")) { final String jarLocation = new File(webModule.getJarLocation(), "/WEB-INF/classes").getAbsolutePath(); @@ -325,7 +330,7 @@ public class DeploymentLoader implements } @SuppressWarnings("unchecked") - private void addWebPersistenceDD(final String name, final Map<String, Object> otherDD, final AppModule appModule) { + private static void addWebPersistenceDD(final String name, final Map<String, Object> otherDD, final AppModule appModule) { if (otherDD.containsKey(name)) { List<URL> persistenceUrls = (List<URL>) appModule.getAltDDs().get(name); if (persistenceUrls == null) { Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java?rev=1629050&r1=1629049&r2=1629050&view=diff ============================================================================== --- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java (original) +++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java Thu Oct 2 19:24:53 2014 @@ -258,14 +258,18 @@ public class DeploymentsResolver impleme } } - final List<URL> urls = new ArrayList<URL>(); final boolean isWindows = System.getProperty("os.name", "unknown").toLowerCase().startsWith("windows"); - - 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 List<URL> urls; + if (!isWindows) { + urls = urlSet.getUrls(); + } else { + urls = new ArrayList<URL>(); + for (final URL url : urlSet.getUrls()) { + final String ef = url.toExternalForm().toLowerCase(); + final URL u = new URL(ef); + if (!urls.contains(u)) { + urls.add(u); + } } } Modified: tomee/tomee/trunk/examples/deltaspike-fullstack/pom.xml URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/deltaspike-fullstack/pom.xml?rev=1629050&r1=1629049&r2=1629050&view=diff ============================================================================== --- tomee/tomee/trunk/examples/deltaspike-fullstack/pom.xml (original) +++ tomee/tomee/trunk/examples/deltaspike-fullstack/pom.xml Thu Oct 2 19:24:53 2014 @@ -75,6 +75,14 @@ </configuration> </plugin> <plugin> + <groupId>org.apache.openejb.maven</groupId> + <artifactId>tomee-embedded-maven-plugin</artifactId> + <version>${version.tomee}</version> + <configuration> + <classpathAsWar>true</classpathAsWar> + </configuration> + </plugin> + <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.17</version> Modified: tomee/tomee/trunk/maven/tomee-embedded-maven-plugin/src/main/java/org/apache/openejb/maven/plugins/TomEEEmbeddedMojo.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/maven/tomee-embedded-maven-plugin/src/main/java/org/apache/openejb/maven/plugins/TomEEEmbeddedMojo.java?rev=1629050&r1=1629049&r2=1629050&view=diff ============================================================================== --- tomee/tomee/trunk/maven/tomee-embedded-maven-plugin/src/main/java/org/apache/openejb/maven/plugins/TomEEEmbeddedMojo.java (original) +++ tomee/tomee/trunk/maven/tomee-embedded-maven-plugin/src/main/java/org/apache/openejb/maven/plugins/TomEEEmbeddedMojo.java Thu Oct 2 19:24:53 2014 @@ -16,18 +16,33 @@ */ package org.apache.openejb.maven.plugins; +import org.apache.catalina.LifecycleState; +import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; +import org.apache.maven.project.MavenProject; +import org.apache.openejb.core.ParentClassLoaderFinder; +import org.apache.openejb.core.ProvidedClassLoaderFinder; +import org.apache.openejb.loader.SystemInstance; +import org.apache.openejb.maven.util.MavenLogStreamFactory; import org.apache.tomee.embedded.Configuration; import org.apache.tomee.embedded.Container; import java.io.File; import java.lang.reflect.Field; -import java.util.concurrent.CountDownLatch; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Scanner; +import java.util.Set; /** * Run an Embedded TomEE. @@ -41,55 +56,124 @@ public class TomEEEmbeddedMojo extends A protected File warFile; @Parameter(property = "tomee-embedded-plugin.http", defaultValue = "8080") - private int httpPort; + protected int httpPort; + + @Parameter(property = "tomee-embedded-plugin.httpsPort", defaultValue = "8443") + protected int httpsPort; @Parameter(property = "tomee-embedded-plugin.ajp", defaultValue = "8009") - private int ajpPort = 8009; + protected int ajpPort = 8009; @Parameter(property = "tomee-embedded-plugin.stop", defaultValue = "8005") - private int stopPort; + protected int stopPort; @Parameter(property = "tomee-embedded-plugin.host", defaultValue = "localhost") - private String host; + protected String host; @Parameter(property = "tomee-embedded-plugin.lib", defaultValue = "${project.build.directory}/apache-tomee-embedded") protected String dir; + @Parameter(property = "tomee-embedded-plugin.keystoreFile") + protected String keystoreFile; + + @Parameter(property = "tomee-embedded-plugin.keystorePass") + protected String keystorePass; + + @Parameter(property = "tomee-embedded-plugin.keystoreType", defaultValue = "JKS") + protected String keystoreType; + + @Parameter(property = "tomee-embedded-plugin.clientAuth") + protected String clientAuth; + + @Parameter(property = "tomee-embedded-plugin.keyAlias") + protected String keyAlias; + + @Parameter(property = "tomee-embedded-plugin.sslProtocol") + protected String sslProtocol; + @Parameter - private File serverXml; + protected File serverXml; + + @Parameter(property = "tomee-embedded-plugin.ssl", defaultValue = "false") + protected boolean ssl; + + @Parameter(property = "tomee-embedded-plugin.quickSession", defaultValue = "true") + protected boolean quickSession; + + @Parameter(property = "tomee-embedded-plugin.skipHttp", defaultValue = "false") + protected boolean skipHttp; + + @Parameter(property = "tomee-embedded-plugin.classpathAsWar", defaultValue = "false") + protected boolean classpathAsWar; + + @Parameter(property = "tomee-embedded-plugin.useProjectClasspath", defaultValue = "true") + protected boolean useProjectClasspath; + + @Parameter(property = "tomee-embedded-plugin.modules", defaultValue = "${project.build.outputDirectory}") + protected List<File> modules; + + @Parameter(property = "tomee-embedded-plugin.docBase", defaultValue = "${project.basedir}/src/main/webapp") + protected File docBase; + + @Parameter(property = "tomee-embedded-plugin.context") + protected String context; + + @Parameter // don't call it properties to avoid to break getConfig() + protected Map<String, String> containerProperties; + + @Parameter(defaultValue = "${project}", readonly = true, required = true) + private MavenProject project; @Override public void execute() throws MojoExecutionException, MojoFailureException { - if ("pom".equals(packaging)) { + if (!classpathAsWar && "pom".equals(packaging)) { getLog().warn("this project is a pom, it is not deployable"); return; } - final CountDownLatch latch = new CountDownLatch(1); + final ClassLoader loader = Thread.currentThread().getContextClassLoader(); + final String logFactory = System.getProperty("openejb.log.factory"); + MavenLogStreamFactory.setLogger(getLog()); System.setProperty("openejb.log.factory", "org.apache.openejb.maven.util.MavenLogStreamFactory"); final Container container = new Container(); final Configuration config = getConfig(); container.setup(config); - try { - container.start(); - Runtime.getRuntime().addShutdownHook(new Thread() { - @Override - public void run() { + final Thread hook = new Thread() { + @Override + public void run() { + if (container.getTomcat() != null && container.getTomcat().getServer().getState() != LifecycleState.DESTROYED) { try { - container.undeploy(warFile.getAbsolutePath()); + if (!classpathAsWar) { + container.undeploy(warFile.getAbsolutePath()); + } container.stop(); - } catch (Exception e) { + } catch (final Exception e) { getLog().error("can't stop TomEE", e); - } finally { - latch.countDown(); } } - }); + } + }; - container.deploy(warFile.getName(), warFile); + try { + container.start(); + SystemInstance.get().setComponent(ParentClassLoaderFinder.class, new ProvidedClassLoaderFinder(loader)); + + Runtime.getRuntime().addShutdownHook(hook); + + if (!classpathAsWar) { + if (context != null) { + getLog().warn("Context will be ignored since not using classpathAsWar"); + } + container.deploy(warFile.getName(), warFile); + } else { + if (useProjectClasspath) { + Thread.currentThread().setContextClassLoader(createClassLoader(loader)); + } + container.deployClasspathAsWebApp(context, docBase); // null is handled properly so no issue here + } getLog().info("TomEE embedded started on " + config.getHost() + ":" + config.getHttpPort()); } catch (Exception e) { @@ -97,17 +181,55 @@ public class TomEEEmbeddedMojo extends A } try { - latch.await(); - } catch (Exception e) { + String line; + final Scanner scanner = new Scanner(System.in); + while ((line = scanner.nextLine()) != null) { + switch (line.trim()) { + case "exit": + case "quit": + Runtime.getRuntime().removeShutdownHook(hook); + container.close(); + return; + } + } + } catch (final Exception e) { Thread.interrupted(); } finally { - System.clearProperty("openejb.log.factory"); + if (logFactory == null) { + System.clearProperty("openejb.log.factory"); + } else { + System.setProperty("openejb.log.factory", logFactory); + } + Thread.currentThread().setContextClassLoader(loader); + } + } + + private ClassLoader createClassLoader(final ClassLoader parent) { + final List<URL> urls = new ArrayList<>(); + for (final Artifact artifact : (Set<Artifact>) project.getArtifacts()) { + try { + urls.add(artifact.getFile().toURI().toURL()); + } catch (final MalformedURLException e) { + getLog().warn("can't use artifact " + artifact.toString()); + } } + for (final File file : modules) { + if (file.exists()) { + try { + urls.add(file.toURI().toURL()); + } catch (final MalformedURLException e) { + getLog().warn("can't use path " + file.getAbsolutePath()); + } + } else { + getLog().warn("can't find " + file.getAbsolutePath()); + } + } + return new URLClassLoader(urls.toArray(new URL[urls.size()]), parent); } private Configuration getConfig() { // lazy way but it works fine final Configuration config = new Configuration(); - for (Field field : getClass().getDeclaredFields()) { + for (final Field field : getClass().getDeclaredFields()) { try { final Field configField = Configuration.class.getDeclaredField(field.getName()); field.setAccessible(true); @@ -116,15 +238,20 @@ public class TomEEEmbeddedMojo extends A final Object value = field.get(this); if (value != null) { configField.set(config, value); - getLog().info("using " + field.getName() + " = " + value); + getLog().debug("using " + field.getName() + " = " + value); } - } catch (NoSuchFieldException nsfe) { + } catch (final NoSuchFieldException nsfe) { // ignored - } catch (Exception e) { + } catch (final Exception e) { getLog().warn("can't initialize attribute " + field.getName()); } } + if (containerProperties != null) { + final Properties props = new Properties(); + props.putAll(containerProperties); + config.setProperties(props); + } return config; } } Added: tomee/tomee/trunk/maven/tomee-embedded-maven-plugin/src/test/java/org/apache/openejb/maven/plugins/TomEEEmbeddedMojoTest.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/maven/tomee-embedded-maven-plugin/src/test/java/org/apache/openejb/maven/plugins/TomEEEmbeddedMojoTest.java?rev=1629050&view=auto ============================================================================== --- tomee/tomee/trunk/maven/tomee-embedded-maven-plugin/src/test/java/org/apache/openejb/maven/plugins/TomEEEmbeddedMojoTest.java (added) +++ tomee/tomee/trunk/maven/tomee-embedded-maven-plugin/src/test/java/org/apache/openejb/maven/plugins/TomEEEmbeddedMojoTest.java Thu Oct 2 19:24:53 2014 @@ -0,0 +1,114 @@ +/* + * 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.maven.plugins; + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugin.logging.SystemStreamLog; +import org.apache.openejb.config.DeploymentFilterable; +import org.apache.openejb.loader.IO; +import org.apache.openejb.util.NetworkUtil; +import org.junit.Test; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.HashMap; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +public class TomEEEmbeddedMojoTest { + @Test + public void run() throws MojoFailureException, MojoExecutionException, IOException { + final CountDownLatch started = new CountDownLatch(1); + final TomEEEmbeddedMojo mojo = new TomEEEmbeddedMojo(); + mojo.classpathAsWar = true; + mojo.httpPort = NetworkUtil.getNextAvailablePort(); + mojo.ssl = false; + mojo.containerProperties = new HashMap<>(); + mojo.containerProperties.put(DeploymentFilterable.CLASSPATH_INCLUDE, ".*tomee-embedded-maven-plugin.*"); + mojo.containerProperties.put("openejb.additional.include", "tomee-embedded-maven-plugin"); + mojo.setLog(new SystemStreamLog() { // not the best solution... + @Override + public void info(final CharSequence charSequence) { + final String string = charSequence.toString(); + if (string.startsWith("TomEE embedded started on") || string.equals("can't start TomEE")) { + started.countDown(); + } + super.info(charSequence); + } + }); + + final InputStream originalIn = System.in; + final ByteArrayInputStream newIn = new ByteArrayInputStream("exit".getBytes()); + final CountDownLatch sendExitLatch = new CountDownLatch(1); + final CountDownLatch stopped = new CountDownLatch(1); + System.setIn(new InputStream() { + @Override + public int read() throws IOException { + try { + sendExitLatch.await(); + } catch (final InterruptedException e) { + Thread.interrupted(); + } + return newIn.read(); + } + }); + + final AtomicReference<Exception> error = new AtomicReference<>(); + final Thread mojoThread = new Thread() { + { + setName("Mojo-Starter"); + } + + @Override + public void run() { + try { + mojo.execute(); + } catch (final Exception e) { + error.set(e); + } finally { + stopped.countDown(); + } + } + }; + mojoThread.start(); + try { + try { + started.await(10, TimeUnit.MINUTES); + } catch (final InterruptedException e) { + Thread.interrupted(); + } + assertNull("all started fine", error.get()); + assertEquals("ok", IO.slurp(new URL("http://localhost:" + mojo.httpPort + "/endpoint/")).trim()); + + sendExitLatch.countDown(); + try { + stopped.await(5, TimeUnit.MINUTES); + } catch (final InterruptedException e) { + Thread.interrupted(); + } + } finally { + System.setIn(originalIn); + } + } +} Added: tomee/tomee/trunk/maven/tomee-embedded-maven-plugin/src/test/java/org/superbiz/Endpoint.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/maven/tomee-embedded-maven-plugin/src/test/java/org/superbiz/Endpoint.java?rev=1629050&view=auto ============================================================================== --- tomee/tomee/trunk/maven/tomee-embedded-maven-plugin/src/test/java/org/superbiz/Endpoint.java (added) +++ tomee/tomee/trunk/maven/tomee-embedded-maven-plugin/src/test/java/org/superbiz/Endpoint.java Thu Oct 2 19:24:53 2014 @@ -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.superbiz; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +@Path("endpoint") +public class Endpoint { + @GET + public String get() { + return "ok"; + } +} Added: tomee/tomee/trunk/maven/tomee-embedded-maven-plugin/src/test/resources/META-INF/beans.xml URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/maven/tomee-embedded-maven-plugin/src/test/resources/META-INF/beans.xml?rev=1629050&view=auto ============================================================================== --- tomee/tomee/trunk/maven/tomee-embedded-maven-plugin/src/test/resources/META-INF/beans.xml (added) +++ tomee/tomee/trunk/maven/tomee-embedded-maven-plugin/src/test/resources/META-INF/beans.xml Thu Oct 2 19:24:53 2014 @@ -0,0 +1,19 @@ +<?xml version="1.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. +--> +<beans /> Modified: tomee/tomee/trunk/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Container.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Container.java?rev=1629050&r1=1629049&r2=1629050&view=diff ============================================================================== --- tomee/tomee/trunk/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Container.java (original) +++ tomee/tomee/trunk/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Container.java Thu Oct 2 19:24:53 2014 @@ -127,10 +127,10 @@ public class Container implements AutoCl } public Container deployClasspathAsWebApp() { - return deployClasspathAsWebApp(""); + return deployClasspathAsWebApp("", null); } - public Container deployClasspathAsWebApp(final String context, final String... dependencies) { + public Container deployClasspathAsWebApp(final String context, final File docBase, final String... dependencies) { final List<URL> jarList = DeploymentsResolver.loadFromClasspath(Thread.currentThread().getContextClassLoader()); if (dependencies != null) { for (final String dep : dependencies) { @@ -145,10 +145,10 @@ public class Container implements AutoCl } } - return deployPathsAsWebapp(context, jarList); + return deployPathsAsWebapp(context, jarList, docBase); } - public Container deployPathsAsWebapp(final String context, final List<URL> jarList) { + public Container deployPathsAsWebapp(final String context, final List<URL> jarList, final File docBase) { final ClassLoader loader = Thread.currentThread().getContextClassLoader(); final SystemInstance systemInstance = SystemInstance.get(); @@ -157,7 +157,10 @@ public class Container implements AutoCl contextRoot = "/" + context; } - final WebModule webModule = new WebModule(new WebApp(), contextRoot, loader, fakeRootDir().getAbsolutePath(), contextRoot); + final WebModule webModule = new WebModule(new WebApp(), contextRoot, loader, docBase == null ? fakeRootDir().getAbsolutePath() : docBase.getAbsolutePath(), contextRoot); + if (docBase == null) { + webModule.getProperties().put("fakeJarLocation", "true"); + } webModule.setUrls(jarList); webModule.setAddedUrls(Collections.<URL>emptyList()); webModule.setRarUrls(Collections.<URL>emptyList()); @@ -174,7 +177,8 @@ public class Container implements AutoCl app.setStandloneWebModule(); try { DeploymentLoader.addWebModule(webModule, app); - } catch (final OpenEJBException e) { + DeploymentLoader.addWebModuleDescriptors(new File(webModule.getJarLocation()).toURI().toURL(), webModule, app); + } catch (final Exception e) { throw new IllegalStateException(e); } @@ -184,7 +188,7 @@ public class Container implements AutoCl try { final AppInfo appInfo = configurationFactory.configureApplication(app); - systemInstance.getComponent(Assembler.class).createApplication(appInfo); + systemInstance.getComponent(Assembler.class).createApplication(appInfo, loader /* don't recreate a classloader */); } catch (final Exception e) { throw new IllegalStateException(e); } @@ -193,7 +197,7 @@ public class Container implements AutoCl } private static void addCallersAsEjbModule(final ClassLoader loader, final AppModule app) { - final Set<String> callers = NewLoaderLogic.callers(Filters.classes(Container.class.getName())); + final Set<String> callers = NewLoaderLogic.callers(Filters.classes(Container.class.getName(), "org.apache.openejb.maven.plugins.TomEEEmbeddedMojo")); if (callers.isEmpty()) { return; } Modified: tomee/tomee/trunk/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Main.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Main.java?rev=1629050&r1=1629049&r2=1629050&view=diff ============================================================================== --- tomee/tomee/trunk/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Main.java (original) +++ tomee/tomee/trunk/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Main.java Thu Oct 2 19:24:53 2014 @@ -33,6 +33,7 @@ public class Main { public static final String PATH = "path"; public static final String CONTEXT = "context"; public static final String DIRECTORY = "directory"; + public static final String DOC_BASE = "doc-base"; public static final String AS_WAR = "as-war"; public static void main(final String[] args) { @@ -78,7 +79,8 @@ public class Main { } } if (line.hasOption(AS_WAR)) { - container.deployClasspathAsWebApp(contexts == null || i == contexts.length ? "" : contexts[i]); + container.deployClasspathAsWebApp(contexts == null || i == contexts.length ? "" : contexts[i], + line.hasOption(DOC_BASE) ? new File(line.getOptionValue(DOC_BASE)) : null); } Runtime.getRuntime().addShutdownHook(new Thread() { Modified: tomee/tomee/trunk/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/internal/StandardContextCustomizer.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/internal/StandardContextCustomizer.java?rev=1629050&r1=1629049&r2=1629050&view=diff ============================================================================== --- tomee/tomee/trunk/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/internal/StandardContextCustomizer.java (original) +++ tomee/tomee/trunk/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/internal/StandardContextCustomizer.java Thu Oct 2 19:24:53 2014 @@ -56,6 +56,9 @@ public class StandardContextCustomizer { case Lifecycle.BEFORE_START_EVENT: final WebResourceRoot resources = new StandardRoot(context); context.setResources(resources); + if (!module.getProperties().containsKey("fakeJarLocation")) { + context.setDocBase(module.getJarLocation()); + } // move last fake folder, tomcat is broken without it so we can't remove it final List allResources = List.class.cast(Reflections.get(resources, "allResources")); @@ -67,9 +70,11 @@ public class StandardContextCustomizer { final String absolutePath = file.getAbsolutePath(); if (file.isDirectory()) { resources.createWebResourceSet(WebResourceRoot.ResourceSetType.CLASSES_JAR, "/WEB-INF/classes", absolutePath, "", "/"); - resources.createWebResourceSet(WebResourceRoot.ResourceSetType.RESOURCE_JAR, "/", absolutePath, "", "/META-INF/resources"); + if (new File(file, "META-INF/resources").exists()) { + resources.createWebResourceSet(WebResourceRoot.ResourceSetType.RESOURCE_JAR, "/", absolutePath, "", "/META-INF/resources"); + } } else { - resources.createWebResourceSet(WebResourceRoot.ResourceSetType.CLASSES_JAR, "/WEB-INF/lib", absolutePath, "", "/"); + resources.createWebResourceSet(WebResourceRoot.ResourceSetType.CLASSES_JAR, "/WEB-INF/lib", absolutePath, null, "/"); resources.createWebResourceSet(WebResourceRoot.ResourceSetType.RESOURCE_JAR, "/", url, "/META-INF/resources"); } } Modified: tomee/tomee/trunk/tomee/tomee-embedded/src/test/java/org/apache/tomee/embedded/ClasspathAsWebappTest.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/tomee/tomee-embedded/src/test/java/org/apache/tomee/embedded/ClasspathAsWebappTest.java?rev=1629050&r1=1629049&r2=1629050&view=diff ============================================================================== --- tomee/tomee/trunk/tomee/tomee-embedded/src/test/java/org/apache/tomee/embedded/ClasspathAsWebappTest.java (original) +++ tomee/tomee/trunk/tomee/tomee-embedded/src/test/java/org/apache/tomee/embedded/ClasspathAsWebappTest.java Thu Oct 2 19:24:53 2014 @@ -73,7 +73,7 @@ public class ClasspathAsWebappTest { new Configuration() .http(NetworkUtil.getNextAvailablePort()) .property("openejb.additional.include", "tomee-")) - .deployPathsAsWebapp("", asList(JarLocation.jarLocation(MyInitializer.class).toURI().toURL())) + .deployPathsAsWebapp("", asList(JarLocation.jarLocation(MyInitializer.class).toURI().toURL()), null) .inject(this)) { // Servlet (initializer, servlet)