You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jl...@apache.org on 2018/12/04 21:29:53 UTC
[1/4] tomee git commit: TOMEE-2253 - tomee.sh -version not working
properly with Java 11
Repository: tomee
Updated Branches:
refs/heads/tomee-7.1.x ab8dd10a2 -> 01fb28e1a
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/155fa669
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/155fa669
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/155fa669
Branch: refs/heads/tomee-7.1.x
Commit: 155fa669a5ddab7d10b5c440fa4da6f0ea0c5046
Parents: ab8dd10
Author: Daniel Cunha (soro) <da...@apache.org>
Authored: Tue Oct 23 17:29:37 2018 -0300
Committer: Daniel Cunha (soro) <da...@apache.org>
Committed: Tue Dec 4 14:09:01 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/155fa669/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/155fa669/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/155fa669/tomee/apache-tomee/pom.xml
----------------------------------------------------------------------
diff --git a/tomee/apache-tomee/pom.xml b/tomee/apache-tomee/pom.xml
index 258634a..1d3b325 100644
--- a/tomee/apache-tomee/pom.xml
+++ b/tomee/apache-tomee/pom.xml
@@ -50,6 +50,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/155fa669/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/155fa669/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/155fa669/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/155fa669/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!!"));
+ }
+}
[2/4] tomee git commit: Added test to call cli command from jaxrs
Posted by jl...@apache.org.
Added test to call cli command from jaxrs
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/cb5baa5a
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/cb5baa5a
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/cb5baa5a
Branch: refs/heads/tomee-7.1.x
Commit: cb5baa5af1a5d6516272f7d4b6fdf9ac312f1871
Parents: 155fa66
Author: Daniel Cunha (soro) <da...@apache.org>
Authored: Tue Nov 20 15:56:36 2018 -0300
Committer: Daniel Cunha (soro) <da...@apache.org>
Committed: Tue Dec 4 14:09:13 2018 -0300
----------------------------------------------------------------------
.../server/cxf/rs/TestCLIFromJaxRSTest.java | 70 ++++++++++++++++++++
1 file changed, 70 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/cb5baa5a/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/TestCLIFromJaxRSTest.java
----------------------------------------------------------------------
diff --git a/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/TestCLIFromJaxRSTest.java b/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/TestCLIFromJaxRSTest.java
new file mode 100644
index 0000000..bd00b23
--- /dev/null
+++ b/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/TestCLIFromJaxRSTest.java
@@ -0,0 +1,70 @@
+/*
+ * 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.server.cxf.rs;
+
+import org.apache.openejb.cli.Bootstrap;
+import org.apache.openejb.junit.ApplicationComposer;
+import org.apache.openejb.testing.Classes;
+import org.apache.openejb.testing.EnableServices;
+import org.apache.openejb.testing.RandomPort;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.core.MediaType;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.net.URL;
+
+import static org.junit.Assert.assertEquals;
+
+@EnableServices("jaxrs")
+@Classes(innerClassesAsBean = true)
+@RunWith(ApplicationComposer.class)
+public class TestCLIFromJaxRSTest {
+ @RandomPort("http")
+ private URL base;
+
+ @Test
+ public void mapping() {
+ final ByteArrayOutputStream out = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(out));
+
+
+ assertEquals(
+ "nice",
+ ClientBuilder.newClient().target(base.toExternalForm()).path("openejb/endpoint").request(MediaType.TEXT_PLAIN)
+ .get(String.class));
+
+ assertEquals("BeAUgMQKg6SzYbDM5vtzsQ==\n", out.toString());
+ }
+
+ @Path("endpoint")
+ public static class ValidateMe {
+ @GET
+ public String get() {
+ try {
+ new Bootstrap().main(new String[]{"cipher", "my-password"});
+ } catch (Exception e) {
+ return "fail";
+ }
+ return "nice";
+ }
+ }
+}
[4/4] tomee git commit: No needed classpath override
Posted by jl...@apache.org.
No needed classpath override
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/01fb28e1
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/01fb28e1
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/01fb28e1
Branch: refs/heads/tomee-7.1.x
Commit: 01fb28e1a50c5f5e6e56884c34652b1b562f3573
Parents: 6166f67
Author: Daniel Cunha (soro) <da...@apache.org>
Authored: Tue Dec 4 07:06:55 2018 -0300
Committer: Daniel Cunha (soro) <da...@apache.org>
Committed: Tue Dec 4 14:09:27 2018 -0300
----------------------------------------------------------------------
.../src/main/java/org/apache/openejb/cli/Bootstrap.java | 7 -------
1 file changed, 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/01fb28e1/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 0b9f26c..2bb4a01 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
@@ -153,13 +153,6 @@ public class Bootstrap {
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);
final Object main = clazz.getConstructor().newInstance();
[3/4] tomee git commit: Test classloader change
Posted by jl...@apache.org.
Test classloader change
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/6166f67e
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/6166f67e
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/6166f67e
Branch: refs/heads/tomee-7.1.x
Commit: 6166f67e478d59f15ef0cc2162aa7c797808ed58
Parents: cb5baa5
Author: Daniel Cunha (soro) <da...@apache.org>
Authored: Mon Nov 26 10:07:02 2018 -0300
Committer: Daniel Cunha (soro) <da...@apache.org>
Committed: Tue Dec 4 14:09:21 2018 -0300
----------------------------------------------------------------------
.../src/test/java/org/apache/tomee/TomEECliIT.java | 9 +++++++++
1 file changed, 9 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/6166f67e/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
index 92fe6f4..f33f53b 100644
--- a/tomee/apache-tomee/src/test/java/org/apache/tomee/TomEECliIT.java
+++ b/tomee/apache-tomee/src/test/java/org/apache/tomee/TomEECliIT.java
@@ -16,6 +16,7 @@
*/
package org.apache.tomee;
+import org.apache.openejb.cli.Bootstrap;
import org.apache.openejb.loader.IO;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
@@ -28,6 +29,7 @@ import java.io.FileFilter;
import java.io.IOException;
import java.nio.file.Files;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -269,4 +271,11 @@ public class TomEECliIT {
final String result = IO.slurp(start.getInputStream());
assertTrue(result.contains("TESTING CLASSLOADER!!"));
}
+
+ @Test
+ public void testIfClassloaderNotChange() throws Exception {
+ final ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
+ new Bootstrap().main(new String[]{"cipher"});
+ assertEquals(originalClassLoader, Thread.currentThread().getContextClassLoader());
+ }
}