tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgallim...@apache.org
Subject [1/9] tomee git commit: TOMEE-2253 - tomee.sh -version not working properly with Java 11
Date Thu, 06 Dec 2018 20:53:52 GMT
Repository: tomee
Updated Branches:
  refs/heads/tomee-7.0.x 35f131e12 -> 8f8394f4e


TOMEE-2253 - tomee.sh -version not working properly with Java 11


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/e5ad4b2d
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/e5ad4b2d
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/e5ad4b2d

Branch: refs/heads/tomee-7.0.x
Commit: e5ad4b2d769aafc93f8817b23ddc55dea9327b1b
Parents: 35f131e
Author: Daniel Cunha (soro) <danielsoro@apache.org>
Authored: Tue Oct 23 17:29:37 2018 -0300
Committer: Daniel Cunha (soro) <danielsoro@apache.org>
Committed: Tue Dec 4 14:06:18 2018 -0300

----------------------------------------------------------------------
 .../java/org/apache/openejb/cli/Bootstrap.java  |  44 +--
 .../openejb/loader/BasicURLClassPath.java       |   4 +-
 tomee/apache-tomee/pom.xml                      |  12 +
 .../src/test/java/org/apache/tomee/Test.java    |  24 ++
 .../java/org/apache/tomee/TestCommand1.java     |  25 ++
 .../java/org/apache/tomee/TestCommand2.java     |  26 ++
 .../test/java/org/apache/tomee/TomEECliIT.java  | 272 +++++++++++++++++++
 7 files changed, 385 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/e5ad4b2d/container/openejb-core/src/main/java/org/apache/openejb/cli/Bootstrap.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/cli/Bootstrap.java b/container/openejb-core/src/main/java/org/apache/openejb/cli/Bootstrap.java
index 98f8741..0b9f26c 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/cli/Bootstrap.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/cli/Bootstrap.java
@@ -17,7 +17,7 @@
 
 package org.apache.openejb.cli;
 
-import org.apache.openejb.loader.ClassPath;
+import org.apache.openejb.loader.BasicURLClassPath;
 import org.apache.openejb.loader.IO;
 import org.apache.openejb.loader.SystemClassPath;
 import org.apache.openejb.util.JavaSecurityManagers;
@@ -28,8 +28,11 @@ import java.io.File;
 import java.lang.reflect.InvocationTargetException;
 import java.net.URI;
 import java.net.URL;
+import java.net.URLClassLoader;
 import java.util.StringTokenizer;
 
+import static org.apache.openejb.loader.JarLocation.jarLocation;
+
 /**
  * @version $Rev$ $Date$
  */
@@ -87,13 +90,14 @@ public class Bootstrap {
         JavaSecurityManagers.setSystemProperty(prop, val);
     }
 
-    private static ClassLoader setupClasspath() {
+    private static URLClassLoader setupClasspath() {
         final String base = JavaSecurityManagers.getSystemProperty(OPENEJB_BASE_PROPERTY_NAME,
"");
         final String home = JavaSecurityManagers.getSystemProperty("catalina.home", JavaSecurityManagers.getSystemProperty(OPENEJB_HOME_PROPERTY_NAME,
base));
         try {
             final File lib = new File(home + File.separator + "lib");
-            final ClassPath systemCP = new SystemClassPath();
-            systemCP.getClassLoader();
+            final BasicURLClassPath.CustomizableURLClassLoader dynamicURLClassLoader =
+                    new BasicURLClassPath.CustomizableURLClassLoader(ClassLoader.getSystemClassLoader());
+
             File config = new File(base, "conf/catalina.properties");
             if (!config.isFile()) {
                 config = new File(home, "conf/catalina.properties");
@@ -116,25 +120,25 @@ public class Bootstrap {
                     if (repository.endsWith("*.jar")) {
                         final File dir = new File(repository.substring(0, repository.length()
- "*.jar".length()));
                         if (dir.isDirectory()) {
-                            systemCP.addJarsToPath(dir);
+                            dynamicURLClassLoader.add(dir.toURI().toURL());
                         }
                     } else if (repository.endsWith(".jar")) {
                         final File file = new File(repository);
                         if (file.isFile()) {
-                            systemCP.addJarToPath(file.toURI().toURL());
+                            dynamicURLClassLoader.add(file.toURI().toURL());
                         }
                     } else {
                         final File dir = new File(repository);
                         if (dir.isDirectory()) {
-                            systemCP.addJarToPath(dir.toURI().toURL());
+                            dynamicURLClassLoader.add(dir.toURI().toURL());
                         }
                     }
                 }
             } else {
-                systemCP.addJarsToPath(lib);
-                systemCP.addJarToPath(lib.toURI().toURL());
+                dynamicURLClassLoader.add(lib.toURI().toURL());
             }
-            return systemCP.getClassLoader();
+
+            return dynamicURLClassLoader;
         } catch (final Exception e) {
             System.err.println("Error setting up the classpath: " + e.getClass() + ": " +
e.getMessage());
             e.printStackTrace();
@@ -146,17 +150,18 @@ public class Bootstrap {
      * Read commands from BASE_PATH (using XBean's ResourceFinder) and execute the one specified
on the command line
      */
     public static void main(final String[] args) throws Exception {
-        setupHome(args);
-        final ClassLoader loader = setupClasspath();
-        if (loader != null) {
-            Thread.currentThread().setContextClassLoader(loader);
-            if (loader != ClassLoader.getSystemClassLoader()) {
-                System.setProperty("openejb.classloader.first.disallow-system-loading", "true");
+        try (final URLClassLoader loader = setupClasspath()) {
+            setupHome(args);
+
+            if (loader != null) {
+                Thread.currentThread().setContextClassLoader(loader);
+                if (loader != ClassLoader.getSystemClassLoader()) {
+                    System.setProperty("openejb.classloader.first.disallow-system-loading",
"true");
+                }
             }
-        }
 
-        final Class<?> clazz = (loader == null ? Bootstrap.class.getClassLoader() :
loader).loadClass(OPENEJB_CLI_MAIN_CLASS_NAME);
-        try {
+            final Class<?> clazz = (loader == null ? Bootstrap.class.getClassLoader()
: loader).loadClass(OPENEJB_CLI_MAIN_CLASS_NAME);
+
             final Object main = clazz.getConstructor().newInstance();
             main.getClass().getMethod("main", String[].class).invoke(main, new Object[]{args});
         } catch (final InvocationTargetException e) {
@@ -173,5 +178,4 @@ public class Bootstrap {
             throw new IllegalStateException(cause);
         }
     }
-
 }

http://git-wip-us.apache.org/repos/asf/tomee/blob/e5ad4b2d/container/openejb-loader/src/main/java/org/apache/openejb/loader/BasicURLClassPath.java
----------------------------------------------------------------------
diff --git a/container/openejb-loader/src/main/java/org/apache/openejb/loader/BasicURLClassPath.java
b/container/openejb-loader/src/main/java/org/apache/openejb/loader/BasicURLClassPath.java
index d459664..e8acf96 100644
--- a/container/openejb-loader/src/main/java/org/apache/openejb/loader/BasicURLClassPath.java
+++ b/container/openejb-loader/src/main/java/org/apache/openejb/loader/BasicURLClassPath.java
@@ -142,12 +142,12 @@ public abstract class BasicURLClassPath implements ClassPath {
         return ucpField;
     }
 
-    protected static class CustomizableURLClassLoader extends URLClassLoader {
+    public static class CustomizableURLClassLoader extends URLClassLoader {
         static {
             ClassLoader.registerAsParallelCapable();
         }
 
-        protected CustomizableURLClassLoader(final ClassLoader parent) {
+        public CustomizableURLClassLoader(final ClassLoader parent) {
             super(new URL[0], parent);
         }
 

http://git-wip-us.apache.org/repos/asf/tomee/blob/e5ad4b2d/tomee/apache-tomee/pom.xml
----------------------------------------------------------------------
diff --git a/tomee/apache-tomee/pom.xml b/tomee/apache-tomee/pom.xml
index 45919d9..da7de9e 100644
--- a/tomee/apache-tomee/pom.xml
+++ b/tomee/apache-tomee/pom.xml
@@ -49,6 +49,18 @@
       <scope>test</scope>
     </dependency>
     <dependency>
+      <groupId>org.jboss.shrinkwrap</groupId>
+      <artifactId>shrinkwrap-api</artifactId>
+      <version>1.2.6</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.shrinkwrap</groupId>
+      <artifactId>shrinkwrap-impl-base</artifactId>
+      <version>1.2.6</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
       <groupId>jline</groupId>
       <artifactId>jline</artifactId>
       <scope>provided</scope>

http://git-wip-us.apache.org/repos/asf/tomee/blob/e5ad4b2d/tomee/apache-tomee/src/test/java/org/apache/tomee/Test.java
----------------------------------------------------------------------
diff --git a/tomee/apache-tomee/src/test/java/org/apache/tomee/Test.java b/tomee/apache-tomee/src/test/java/org/apache/tomee/Test.java
new file mode 100644
index 0000000..c788582
--- /dev/null
+++ b/tomee/apache-tomee/src/test/java/org/apache/tomee/Test.java
@@ -0,0 +1,24 @@
+/**
+ * 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.tomee;
+
+public class Test {
+
+    public static void main(String[] args) {
+        System.out.println("TESTING CLASSLOADER!!");
+    }
+}

http://git-wip-us.apache.org/repos/asf/tomee/blob/e5ad4b2d/tomee/apache-tomee/src/test/java/org/apache/tomee/TestCommand1.java
----------------------------------------------------------------------
diff --git a/tomee/apache-tomee/src/test/java/org/apache/tomee/TestCommand1.java b/tomee/apache-tomee/src/test/java/org/apache/tomee/TestCommand1.java
new file mode 100644
index 0000000..1fe2af7
--- /dev/null
+++ b/tomee/apache-tomee/src/test/java/org/apache/tomee/TestCommand1.java
@@ -0,0 +1,25 @@
+/**
+ * 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.tomee;
+
+public class TestCommand1 {
+
+    public static void main(String[] args) {
+        final Test test = new Test();
+        test.main(args);
+    }
+}

http://git-wip-us.apache.org/repos/asf/tomee/blob/e5ad4b2d/tomee/apache-tomee/src/test/java/org/apache/tomee/TestCommand2.java
----------------------------------------------------------------------
diff --git a/tomee/apache-tomee/src/test/java/org/apache/tomee/TestCommand2.java b/tomee/apache-tomee/src/test/java/org/apache/tomee/TestCommand2.java
new file mode 100644
index 0000000..b66bedd
--- /dev/null
+++ b/tomee/apache-tomee/src/test/java/org/apache/tomee/TestCommand2.java
@@ -0,0 +1,26 @@
+/**
+ * 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.tomee;
+
+import org.apache.openejb.cli.Bootstrap;
+
+public class TestCommand2 {
+
+    public static void main(String[] args) throws Exception {
+        new Bootstrap().main(new String[]{"classloadertest"});
+    }
+}

http://git-wip-us.apache.org/repos/asf/tomee/blob/e5ad4b2d/tomee/apache-tomee/src/test/java/org/apache/tomee/TomEECliIT.java
----------------------------------------------------------------------
diff --git a/tomee/apache-tomee/src/test/java/org/apache/tomee/TomEECliIT.java b/tomee/apache-tomee/src/test/java/org/apache/tomee/TomEECliIT.java
new file mode 100644
index 0000000..92fe6f4
--- /dev/null
+++ b/tomee/apache-tomee/src/test/java/org/apache/tomee/TomEECliIT.java
@@ -0,0 +1,272 @@
+/**
+ * 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.tomee;
+
+import org.apache.openejb.loader.IO;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.StringAsset;
+import org.jboss.shrinkwrap.api.exporter.ZipExporter;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.IOException;
+import java.nio.file.Files;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+public class TomEECliIT {
+
+    @Test
+    public void testTomEECliWithJar() throws IOException, InterruptedException {
+        final File file = Files.createTempDirectory("tomee-test").toFile();
+        final File jar = new File(file.getAbsolutePath() + "/test.jar");
+
+        final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "test.jar")
+                .addClasses(org.apache.tomee.Test.class)
+                .add(new StringAsset("main.class = org.apache.tomee.Test\n" +
+                        "name = classloadertest\n" +
+                        "description = Show a simple msg"), "META-INF/org.apache.openejb.cli/classloadertest");
+
+        archive.as(ZipExporter.class).exportTo(jar);
+
+        File work = new File("target/webprofile-work-dir/").getAbsoluteFile();
+        if (!work.exists()) {
+            work = new File("apache-tomee/target/webprofile-work-dir/").getAbsoluteFile();
+        }
+
+        final File[] files = work.listFiles(new FileFilter() {
+            @Override
+            public boolean accept(final File pathname) {
+                return pathname.isDirectory() && pathname.getName().startsWith("apache-tomcat-");
+            }
+        });
+
+        final File tomee = (null != files ? files[0] : null);
+        if (tomee == null) {
+            fail("Failed to find Tomcat directory required for this test - Ensure you have
run at least the maven phase: mvn process-resources");
+        }
+
+        final ProcessBuilder builder = new ProcessBuilder()
+            .command("java", "-cp", jar.getAbsolutePath() + File.pathSeparator +
+                            tomee.getAbsolutePath() + File.separator + "lib" + File.separator
+ "openejb-core-8.0.0-SNAPSHOT.jar" + File.pathSeparator +
+                            tomee.getAbsolutePath() + File.separator + "lib" + File.separator
+ "commons-cli-1.2.jar",
+                    "org.apache.openejb.cli.Bootstrap", "classloadertest");
+
+        final Process start = builder.start();
+        start.waitFor();
+
+        final String result = IO.slurp(start.getInputStream());
+        assertTrue(result.contains("TESTING CLASSLOADER!!"));
+    }
+
+    @Test
+    public void testTomEECliWithJarDir() throws IOException, InterruptedException {
+        final File file = Files.createTempDirectory("tomee-test").toFile();
+        final File jar = new File(file.getAbsolutePath() + "/test.jar");
+
+        final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "test.jar")
+                .addClasses(org.apache.tomee.Test.class)
+                .add(new StringAsset("main.class = org.apache.tomee.Test\n" +
+                        "name = classloadertest\n" +
+                        "description = Show a simple msg"), "META-INF/org.apache.openejb.cli/classloadertest");
+
+        archive.as(ZipExporter.class).exportTo(jar);
+
+        File work = new File("target/webprofile-work-dir/").getAbsoluteFile();
+        if (!work.exists()) {
+            work = new File("apache-tomee/target/webprofile-work-dir/").getAbsoluteFile();
+        }
+
+        final File[] files = work.listFiles(new FileFilter() {
+            @Override
+            public boolean accept(final File pathname) {
+                return pathname.isDirectory() && pathname.getName().startsWith("apache-tomcat-");
+            }
+        });
+
+        final File tomee = (null != files ? files[0] : null);
+        if (tomee == null) {
+            fail("Failed to find Tomcat directory required for this test - Ensure you have
run at least the maven phase: mvn process-resources");
+        }
+
+        final ProcessBuilder builder = new ProcessBuilder()
+                .command("java", "-cp", file.getAbsolutePath() + File.separator + "*" + File.pathSeparator
+
+                                tomee.getAbsolutePath() + File.separator + "lib" + File.separator
+ "*",
+                        "org.apache.openejb.cli.Bootstrap", "classloadertest");
+
+        final Process start = builder.start();
+        start.waitFor();
+
+        final String result = IO.slurp(start.getInputStream());
+        assertTrue(result.contains("TESTING CLASSLOADER!!"));
+    }
+
+    @Test
+    public void testTomEECliWithJarCallingAnotherMain() throws IOException, InterruptedException
{
+        final File file = Files.createTempDirectory("tomee-test").toFile();
+        final File jar = new File(file.getAbsolutePath() + "/test.jar");
+        final File jar2 = new File(file.getAbsolutePath() + "/test2.jar");
+
+        final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "test.jar")
+                .addClasses(org.apache.tomee.Test.class)
+                .add(new StringAsset("main.class = org.apache.tomee.Test\n" +
+                        "name = classloadertest\n" +
+                        "description = Show a simple msg"), "META-INF/org.apache.openejb.cli/classloadertest");
+
+        final JavaArchive archive2 = ShrinkWrap.create(JavaArchive.class, "test2.jar")
+                .addClasses(org.apache.tomee.TestCommand1.class)
+                .add(new StringAsset("main.class = org.apache.tomee.TestCommand1\n" +
+                        "name = classloadertest2\n" +
+                        "description = Show a simple msg"), "META-INF/org.apache.openejb.cli/classloadertest2");
+
+        archive.as(ZipExporter.class).exportTo(jar);
+        archive2.as(ZipExporter.class).exportTo(jar2);
+
+        File work = new File("target/webprofile-work-dir/").getAbsoluteFile();
+        if (!work.exists()) {
+            work = new File("apache-tomee/target/webprofile-work-dir/").getAbsoluteFile();
+        }
+
+        final File[] files = work.listFiles(new FileFilter() {
+            @Override
+            public boolean accept(final File pathname) {
+                return pathname.isDirectory() && pathname.getName().startsWith("apache-tomcat-");
+            }
+        });
+
+        final File tomee = (null != files ? files[0] : null);
+        if (tomee == null) {
+            fail("Failed to find Tomcat directory required for this test - Ensure you have
run at least the maven phase: mvn process-resources");
+        }
+
+        final ProcessBuilder builder = new ProcessBuilder()
+                .command("java", "-cp", jar.getAbsolutePath() + File.pathSeparator +
+                                jar2.getAbsolutePath() + File.pathSeparator +
+                                tomee.getAbsolutePath() + File.separator + "lib" + File.separator
+ "openejb-core-8.0.0-SNAPSHOT.jar" + File.pathSeparator +
+                                tomee.getAbsolutePath() + File.separator + "lib" + File.separator
+ "commons-cli-1.2.jar",
+                        "org.apache.openejb.cli.Bootstrap", "classloadertest2");
+
+        final Process start = builder.start();
+        start.waitFor();
+
+        final String result = IO.slurp(start.getInputStream());
+        assertTrue(result.contains("TESTING CLASSLOADER!!"));
+    }
+
+    @Test
+    public void testTomEECliWithJarDirCallingAnotherMain() throws IOException, InterruptedException
{
+        final File file = Files.createTempDirectory("tomee-test").toFile();
+        final File jar = new File(file.getAbsolutePath() + "/test.jar");
+        final File jar2 = new File(file.getAbsolutePath() + "/test2.jar");
+
+        final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "test.jar")
+                .addClasses(org.apache.tomee.Test.class)
+                .add(new StringAsset("main.class = org.apache.tomee.Test\n" +
+                        "name = classloadertest\n" +
+                        "description = Show a simple msg"), "META-INF/org.apache.openejb.cli/classloadertest");
+
+        final JavaArchive archive2 = ShrinkWrap.create(JavaArchive.class, "test2.jar")
+                .addClasses(org.apache.tomee.TestCommand1.class)
+                .add(new StringAsset("main.class = org.apache.tomee.TestCommand1\n" +
+                        "name = classloadertest2\n" +
+                        "description = Show a simple msg"), "META-INF/org.apache.openejb.cli/classloadertest2");
+
+        archive.as(ZipExporter.class).exportTo(jar);
+        archive2.as(ZipExporter.class).exportTo(jar2);
+
+        File work = new File("target/webprofile-work-dir/").getAbsoluteFile();
+        if (!work.exists()) {
+            work = new File("apache-tomee/target/webprofile-work-dir/").getAbsoluteFile();
+        }
+
+        final File[] files = work.listFiles(new FileFilter() {
+            @Override
+            public boolean accept(final File pathname) {
+                return pathname.isDirectory() && pathname.getName().startsWith("apache-tomcat-");
+            }
+        });
+
+        final File tomee = (null != files ? files[0] : null);
+        if (tomee == null) {
+            fail("Failed to find Tomcat directory required for this test - Ensure you have
run at least the maven phase: mvn process-resources");
+        }
+
+        final ProcessBuilder builder = new ProcessBuilder()
+                .command("java", "-cp", file.getAbsolutePath() + File.separator + "*" + File.pathSeparator
+
+                                tomee.getAbsolutePath() + File.separator + "lib" + File.separator
+ "*",
+                        "org.apache.openejb.cli.Bootstrap", "classloadertest2");
+
+        final Process start = builder.start();
+        start.waitFor();
+
+        final String result = IO.slurp(start.getInputStream());
+        assertTrue(result.contains("TESTING CLASSLOADER!!"));
+    }
+
+    @Test
+    public void testDelegatesToCLIMain() throws IOException, InterruptedException {
+        final File file = Files.createTempDirectory("tomee-test").toFile();
+        final File jar = new File(file.getAbsolutePath() + "/test.jar");
+        final File jar2 = new File(file.getAbsolutePath() + "/test2.jar");
+
+        final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "test.jar")
+                .addClasses(org.apache.tomee.Test.class)
+                .add(new StringAsset("main.class = org.apache.tomee.Test\n" +
+                        "name = classloadertest\n" +
+                        "description = Show a simple msg"), "META-INF/org.apache.openejb.cli/classloadertest");
+
+        final JavaArchive archive2 = ShrinkWrap.create(JavaArchive.class, "test2.jar")
+                .addClasses(org.apache.tomee.TestCommand2.class)
+                .add(new StringAsset("main.class = org.apache.tomee.TestCommand2\n" +
+                        "name = classloadertest2\n" +
+                        "description = Show a simple msg"), "META-INF/org.apache.openejb.cli/classloadertest2");
+
+        archive.as(ZipExporter.class).exportTo(jar);
+        archive2.as(ZipExporter.class).exportTo(jar2);
+
+        File work = new File("target/webprofile-work-dir/").getAbsoluteFile();
+        if (!work.exists()) {
+            work = new File("apache-tomee/target/webprofile-work-dir/").getAbsoluteFile();
+        }
+
+        final File[] files = work.listFiles(new FileFilter() {
+            @Override
+            public boolean accept(final File pathname) {
+                return pathname.isDirectory() && pathname.getName().startsWith("apache-tomcat-");
+            }
+        });
+
+        final File tomee = (null != files ? files[0] : null);
+        if (tomee == null) {
+            fail("Failed to find Tomcat directory required for this test - Ensure you have
run at least the maven phase: mvn process-resources");
+        }
+
+        final ProcessBuilder builder = new ProcessBuilder()
+                .command("java", "-cp", file.getAbsolutePath() + File.separator + "*" + File.pathSeparator
+
+                                tomee.getAbsolutePath() + File.separator + "lib" + File.separator
+ "*",
+                        "org.apache.openejb.cli.Bootstrap", "classloadertest2");
+
+        final Process start = builder.start();
+        start.waitFor();
+
+        final String result = IO.slurp(start.getInputStream());
+        assertTrue(result.contains("TESTING CLASSLOADER!!"));
+    }
+}


Mime
View raw message