tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject tomee git commit: TOMEE-1798 basic java 9 support
Date Tue, 03 May 2016 08:26:05 GMT
Repository: tomee
Updated Branches:
  refs/heads/master 31a309440 -> 8203e7c77


TOMEE-1798 basic java 9 support


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

Branch: refs/heads/master
Commit: 8203e7c77d81c6ba558f1ae9d9417d841d8203e8
Parents: 31a3094
Author: Romain manni-Bucau <rmannibucau@gmail.com>
Authored: Tue May 3 10:25:49 2016 +0200
Committer: Romain manni-Bucau <rmannibucau@gmail.com>
Committed: Tue May 3 10:25:49 2016 +0200

----------------------------------------------------------------------
 .../org/apache/openejb/ClassLoaderUtil.java     |  3 +
 .../main/java/org/apache/openejb/OpenEJB.java   |  1 -
 .../main/java/org/apache/openejb/util/URLs.java |  5 +-
 .../src/main/resources/default.exclusions       |  1 +
 .../apache/openejb/loader/SystemInstance.java   | 83 ++++++++++++++++++++
 5 files changed, 91 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/8203e7c7/container/openejb-core/src/main/java/org/apache/openejb/ClassLoaderUtil.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/ClassLoaderUtil.java
b/container/openejb-core/src/main/java/org/apache/openejb/ClassLoaderUtil.java
index 4a0588b..a87e27d 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/ClassLoaderUtil.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/ClassLoaderUtil.java
@@ -470,6 +470,9 @@ public class ClassLoaderUtil {
         } catch (final ClassNotFoundException | NoSuchFieldException e) {
             // not a sun vm
         } catch (final Throwable e) {
+            if (Boolean.getBoolean("openejb.java9.hack")) {
+                return; // reflection fails cause internals are not exported, close() is
called and should be fine
+            }
             logger.error("Unable to clear Sun JarFileFactory cache", e);
         }
     }

http://git-wip-us.apache.org/repos/asf/tomee/blob/8203e7c7/container/openejb-core/src/main/java/org/apache/openejb/OpenEJB.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/OpenEJB.java b/container/openejb-core/src/main/java/org/apache/openejb/OpenEJB.java
index 0cad62b..bb6b682 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/OpenEJB.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/OpenEJB.java
@@ -41,7 +41,6 @@ import java.util.concurrent.atomic.AtomicReference;
  * @version $Rev$ $Date$
  */
 public final class OpenEJB {
-
     private static Instance instance;
 
     private OpenEJB() {

http://git-wip-us.apache.org/repos/asf/tomee/blob/8203e7c7/container/openejb-core/src/main/java/org/apache/openejb/util/URLs.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/util/URLs.java b/container/openejb-core/src/main/java/org/apache/openejb/util/URLs.java
index 7777dcf..397d058 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/util/URLs.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/util/URLs.java
@@ -69,10 +69,13 @@ public final class URLs {
     }
 
     public static UrlSet cullSystemJars(final UrlSet original) throws IOException {
+        final String sunboot = System.getProperty("sun.boot.class.path", "");
         UrlSet urls = new UrlSet(original.getUrls());
         urls = urls.exclude(ClassLoader.getSystemClassLoader().getParent());
         urls = urls.excludeJvm();
-        urls = urls.excludePaths(System.getProperty("sun.boot.class.path", ""));
+        if (!sunboot.isEmpty()) { // else on java9 it excludes new File(".") so all maven
builds fail
+            urls = urls.excludePaths(sunboot);
+        }
         urls = urls.exclude(".*/JavaVM.framework/.*");
         return urls;
     }

http://git-wip-us.apache.org/repos/asf/tomee/blob/8203e7c7/container/openejb-core/src/main/resources/default.exclusions
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/resources/default.exclusions b/container/openejb-core/src/main/resources/default.exclusions
index 601ed51..c993bd0 100644
--- a/container/openejb-core/src/main/resources/default.exclusions
+++ b/container/openejb-core/src/main/resources/default.exclusions
@@ -57,6 +57,7 @@ commons-logging-
 commons-logging-api-
 commons-net-
 commons-pool-
+commons-pool2-
 cryptacular-
 cssparser-
 cxf-

http://git-wip-us.apache.org/repos/asf/tomee/blob/8203e7c7/container/openejb-loader/src/main/java/org/apache/openejb/loader/SystemInstance.java
----------------------------------------------------------------------
diff --git a/container/openejb-loader/src/main/java/org/apache/openejb/loader/SystemInstance.java
b/container/openejb-loader/src/main/java/org/apache/openejb/loader/SystemInstance.java
index 1474c43..ec2251f 100644
--- a/container/openejb-loader/src/main/java/org/apache/openejb/loader/SystemInstance.java
+++ b/container/openejb-loader/src/main/java/org/apache/openejb/loader/SystemInstance.java
@@ -21,13 +21,19 @@ import org.apache.openejb.loader.event.ComponentRemoved;
 import org.apache.openejb.loader.provisining.ProvisioningResolver;
 import org.apache.openejb.observer.ObserverManager;
 
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Method;
+import java.net.URL;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
 import java.util.concurrent.atomic.AtomicReference;
 
+import static java.util.Arrays.asList;
+
 /**
  * This class aims to be the one and only static in the entire system
  * A static, singleton, instance of this class can be created with the {@link #init(Properties)}
method
@@ -40,6 +46,83 @@ import java.util.concurrent.atomic.AtomicReference;
  * @org.apache.xbean.XBean element="system"
  */
 public final class SystemInstance {
+    static { // preload API to not fall into module hell on JVM >= 9
+        final String version = System.getProperty("java.version", "-");
+        final boolean j9hacks = (!version.startsWith("1.") || version.startsWith("1.9."))
&& !Boolean.getBoolean("openejb.java9.skip-hacks");
+        System.setProperty("openejb.java9.hack", Boolean.toString(j9hacks));
+        if (j9hacks) {
+            ClassLoader loader = Thread.currentThread().getContextClassLoader();
+            if (loader == null) {
+                loader = ClassLoader.getSystemClassLoader();
+            }
+            Method defineClass = null;
+            for (final String clazz : asList(
+                    // JTA - rt.jar API
+                    "javax.transaction.HeuristicCommitException",
+                    "javax.transaction.HeuristicMixedException",
+                    "javax.transaction.HeuristicRollbackException",
+                    "javax.transaction.NotSupportedException",
+                    "javax.transaction.RollbackException",
+                    "javax.transaction.Status",
+                    "javax.transaction.Synchronization",
+                    "javax.transaction.SystemException",
+                    "javax.transaction.Transaction",
+                    "javax.transaction.Transactional",
+                    "javax.transaction.TransactionalException",
+                    "javax.transaction.TransactionManager",
+                    "javax.transaction.TransactionScoped",
+                    "javax.transaction.TransactionSynchronizationRegistry",
+                    "javax.transaction.UserTransaction",
+                    // javax.annotation - rt.jar
+                    "javax.annotation.security.DeclareRoles",
+                    "javax.annotation.security.DenyAll",
+                    "javax.annotation.security.PermitAll",
+                    "javax.annotation.security.RolesAllowed",
+                    "javax.annotation.security.RunAs",
+                    "javax.annotation.sql.DataSourceDefinition",
+                    "javax.annotation.sql.DataSourceDefinitions",
+                    "javax.annotation.ManagedBean",
+                    "javax.annotation.Priority"
+            )) {
+                try {
+                    loader.loadClass(clazz);
+                } catch (final ClassNotFoundException e) {
+                    // DONT CALL LOGGER THERE
+                    final URL url = loader.getResource(clazz.replace('.', '/') + ".class");
+                    if (url == null) {
+                        e.printStackTrace();
+                        continue;
+                    }
+                    try {
+                        if (defineClass == null) {
+                            Class<?> type = loader.getClass();
+                            do {
+                                try {
+                                    defineClass = type.getDeclaredMethod("defineClass", String.class,
byte[].class, int.class, int.class);
+                                } catch (final NoSuchMethodException ignore) {
+                                    // do nothing, we need to search the superclass
+                                }
+                                type = type.getSuperclass();
+                            } while (defineClass == null && type != Object.class);
+                            defineClass.setAccessible(true);
+                        }
+                        try (final InputStream is = url.openStream()) {
+                            final ByteArrayOutputStream out = new ByteArrayOutputStream();
+                            IO.copy(is, out);
+
+                            final byte[] bytes = out.toByteArray();
+                            defineClass.invoke(loader, clazz, bytes, 0, bytes.length);
+
+                            loader.loadClass(clazz);
+                        }
+                    } catch (final Throwable oops) {
+                        e.printStackTrace(); // no logger!
+                    }
+                }
+            }
+        }
+    }
+
     private static final String PROFILE_PROP = "openejb.profile";
     private static final String DEFAULT_PROFILE = "development";
 


Mime
View raw message