openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1770581 - in /openwebbeans/meecrowave/trunk: meecrowave-arquillian/src/main/java/org/apache/meecrowave/arquillian/ meecrowave-core/ meecrowave-core/src/main/java/org/apache/meecrowave/ meecrowave-core/src/main/java/org/apache/meecrowave/ha...
Date Sun, 20 Nov 2016 19:37:36 GMT
Author: rmannibucau
Date: Sun Nov 20 19:37:36 2016
New Revision: 1770581

URL: http://svn.apache.org/viewvc?rev=1770581&view=rev
Log:
adding some workaround for java 9 and a note on the download page

Added:
    openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/hack/
    openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/hack/Java9WorkArounds.java
Modified:
    openwebbeans/meecrowave/trunk/meecrowave-arquillian/src/main/java/org/apache/meecrowave/arquillian/MeecrowaveConfiguration.java
    openwebbeans/meecrowave/trunk/meecrowave-core/pom.xml
    openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java
    openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/KnownJarsFilter.java
    openwebbeans/meecrowave/trunk/meecrowave-doc/src/main/jbake/content/download.adoc
    openwebbeans/meecrowave/trunk/meecrowave-gradle-plugin/src/main/java/org/apache/meecrowave/gradle/MeecrowaveExtension.java
    openwebbeans/meecrowave/trunk/meecrowave-gradle-plugin/src/main/java/org/apache/meecrowave/gradle/MeecrowaveTask.java
    openwebbeans/meecrowave/trunk/meecrowave-jpa/src/test/java/org/apache/meecrowave/jpa/internal/JpaExtensionTest.java
    openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/main/java/org/apache/meecrowave/maven/MeecrowaveRunMojo.java
    openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/java/org/apache/meecrowave/maven/MeecrowaveRunMojoTest.java

Modified: openwebbeans/meecrowave/trunk/meecrowave-arquillian/src/main/java/org/apache/meecrowave/arquillian/MeecrowaveConfiguration.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-arquillian/src/main/java/org/apache/meecrowave/arquillian/MeecrowaveConfiguration.java?rev=1770581&r1=1770580&r2=1770581&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-arquillian/src/main/java/org/apache/meecrowave/arquillian/MeecrowaveConfiguration.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-arquillian/src/main/java/org/apache/meecrowave/arquillian/MeecrowaveConfiguration.java
Sun Nov 20 19:37:36 2016
@@ -94,6 +94,7 @@ public class MeecrowaveConfiguration imp
     private String jsonbBinaryStrategy;
     private String jsonbNamingStrategy;
     private String jsonbOrderStrategy;
+    private boolean java9SkipWorkarounds = false;
 
     @Override
     public void validate() throws ConfigurationException {

Modified: openwebbeans/meecrowave/trunk/meecrowave-core/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/pom.xml?rev=1770581&r1=1770580&r2=1770581&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/pom.xml (original)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/pom.xml Sun Nov 20 19:37:36 2016
@@ -38,6 +38,7 @@
     <cxf.version>3.1.9-SNAPSHOT</cxf.version>
     <johnzon.version>0.9.5</johnzon.version>
     <log4j2.version>2.7</log4j2.version>
+    <jaxb.version>2.2.11</jaxb.version>
   </properties>
 
   <dependencies>

Modified: openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java?rev=1770581&r1=1770580&r2=1770581&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java
Sun Nov 20 19:37:36 2016
@@ -39,6 +39,7 @@ import org.apache.commons.lang3.text.Str
 import org.apache.coyote.http2.Http2Protocol;
 import org.apache.johnzon.core.BufferStrategy;
 import org.apache.meecrowave.cxf.CxfCdiAutoSetup;
+import org.apache.meecrowave.hack.Java9WorkArounds;
 import org.apache.meecrowave.io.IO;
 import org.apache.meecrowave.logging.jul.Log4j2Logger;
 import org.apache.meecrowave.logging.openwebbeans.Log4j2LoggerFactory;
@@ -110,6 +111,9 @@ public class Meecrowave implements AutoC
     public Meecrowave(final Builder builder) {
         this.configuration = builder;
         this.ownedTempDir = new File(configuration.tempDir, "meecrowave_" + System.nanoTime());
+        if (!builder.isJava9SkipWorkarounds()) {
+            Java9WorkArounds.execute();
+        }
     }
 
     public Builder getConfiguration() {
@@ -703,6 +707,9 @@ public class Meecrowave implements AutoC
     // accessible through builder.getExtension(type) builder being accessible through the
meecrowave.configuration
     // attribute of the ServletContext.
     public static class Builder {
+        @CliOption(name = "java9-skip-workarounds", description = "Should the java9 workarounds
be skipped, default to false if on java 9")
+        private boolean java9SkipWorkarounds;
+
         @CliOption(name = "http", description = "HTTP port")
         private int httpPort = 8080;
 
@@ -897,6 +904,14 @@ public class Meecrowave implements AutoC
             extensions.put(type, value);
         }
 
+        public boolean isJava9SkipWorkarounds() {
+            return java9SkipWorkarounds;
+        }
+
+        public void setJava9SkipWorkarounds(final boolean java9SkipWorkarounds) {
+            this.java9SkipWorkarounds = java9SkipWorkarounds;
+        }
+
         public String getJsonpBufferStrategy() {
             return jsonpBufferStrategy;
         }

Added: openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/hack/Java9WorkArounds.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/hack/Java9WorkArounds.java?rev=1770581&view=auto
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/hack/Java9WorkArounds.java
(added)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/hack/Java9WorkArounds.java
Sun Nov 20 19:37:36 2016
@@ -0,0 +1,119 @@
+/*
+ * 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.meecrowave.hack;
+
+import org.apache.meecrowave.io.IO;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.stream.Stream;
+import java.util.zip.ZipFile;
+
+import static java.util.Collections.list;
+import static java.util.stream.Collectors.toSet;
+
+// no logger in this class!
+
+/**
+ * Workaround class providing an execute() method to enforce java.activation loading.
+ *
+ * For Meecrowave we could use private or package methods but it is open in case end users
hit the same issues.
+ */
+public class Java9WorkArounds {
+    private Java9WorkArounds() {
+        // no-op
+    }
+
+    public static void execute() {
+        final String version = System.getProperty("java.version", "-");
+        final boolean j9hacks = !version.startsWith("1.") || version.startsWith("1.9.");
+        if (!j9hacks) {
+            return;
+        }
+
+        ClassLoader loader = Thread.currentThread().getContextClassLoader();
+        if (loader == null) {
+            loader = ClassLoader.getSystemClassLoader();
+        }
+
+        try { // enforce to load javax.activation.* if we can't directly do it cause CXF
needs it
+            loader.loadClass("javax.activation.DataSource");
+        } catch (final ClassNotFoundException cnfe) {
+            final File file = new File(System.getProperty("java.home"), "jmods/java.activation.jmod");
+            if (file.isFile()) {
+                doLoad(file, findDefineClass(loader), loader, Stream.of(
+                        "javax.activation.FileTypeMap",
+                        "javax.activation.MimetypesFileTypeMap",
+                        "javax.activation.CommandMap",
+                        "javax.activation.MailcapCommandMap",
+                        "module-info")
+                        .map(e -> "classes/" + e.replace('.', '/') + ".class")
+                        .collect(toSet()));
+            } else {
+                System.err.println("Cannot find " + file.getAbsolutePath() + " so javax.activation
will not be available");
+            }
+        }
+    }
+
+    // use with caution but public for user packages like javax.transaction etc...
+    public static void doLoad(final File file, final Method defineClass, final ClassLoader
loader, final Collection<String> excluded) {
+        try (final ZipFile zip = new ZipFile(file)) {
+            list(zip.entries()).stream()
+                    .filter(e -> e.getName().startsWith("classes/") && e.getName().endsWith(".class")
&& !excluded.contains(e.getName()))
+                    .forEach(e -> {
+                        try (final InputStream is = zip.getInputStream(e)) {
+                            final ByteArrayOutputStream out = new ByteArrayOutputStream();
+                            IO.copy(is, out);
+
+                            final String name = e.getName().substring("classes/".length(),
e.getName().length() - ".class".length()).replace("/", ".");
+                            final byte[] bytes = out.toByteArray();
+                            defineClass.invoke(loader, name, bytes, 0, bytes.length);
+
+                            loader.loadClass(name);
+                        } catch (final IOException | InvocationTargetException | ClassNotFoundException
| IllegalAccessException e1) {
+                            e1.printStackTrace();
+                        }
+                    });
+        } catch (final IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    private static Method findDefineClass(final ClassLoader loader) {
+        Method 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);
+        if (!defineClass.isAccessible()) {
+            defineClass.setAccessible(true);
+        }
+        return defineClass;
+    }
+}

Modified: openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/KnownJarsFilter.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/KnownJarsFilter.java?rev=1770581&r1=1770580&r2=1770581&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/KnownJarsFilter.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/KnownJarsFilter.java
Sun Nov 20 19:37:36 2016
@@ -107,6 +107,7 @@ public class KnownJarsFilter implements
         add("eclipselink-");
         add("ehcache-");
         add("FastInfoset");
+        add("jaxb-");
         add("jce.jar");
         add("jfr.jar");
         add("jfxrt.jar");

Modified: openwebbeans/meecrowave/trunk/meecrowave-doc/src/main/jbake/content/download.adoc
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-doc/src/main/jbake/content/download.adoc?rev=1770581&r1=1770580&r2=1770581&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-doc/src/main/jbake/content/download.adoc (original)
+++ openwebbeans/meecrowave/trunk/meecrowave-doc/src/main/jbake/content/download.adoc Sun
Nov 20 19:37:36 2016
@@ -8,6 +8,8 @@
 
 License is ASF v2.
 
+IMPORTANT: java 9 support is still experimental, you need at least to add `jaxb` dependency.
+
 [.table.table-bordered,options="header"]
 |===
 |Name|Version|Date|Size|Type|Links

Modified: openwebbeans/meecrowave/trunk/meecrowave-gradle-plugin/src/main/java/org/apache/meecrowave/gradle/MeecrowaveExtension.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-gradle-plugin/src/main/java/org/apache/meecrowave/gradle/MeecrowaveExtension.java?rev=1770581&r1=1770580&r2=1770581&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-gradle-plugin/src/main/java/org/apache/meecrowave/gradle/MeecrowaveExtension.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-gradle-plugin/src/main/java/org/apache/meecrowave/gradle/MeecrowaveExtension.java
Sun Nov 20 19:37:36 2016
@@ -84,6 +84,15 @@ public class MeecrowaveExtension {
     private String jsonbBinaryStrategy;
     private String jsonbNamingStrategy;
     private String jsonbOrderStrategy;
+    private boolean java9SkipWorkarounds = false;
+
+    public boolean isJava9SkipWorkarounds() {
+        return java9SkipWorkarounds;
+    }
+
+    public void setJava9SkipWorkarounds(final boolean java9SkipWorkarounds) {
+        this.java9SkipWorkarounds = java9SkipWorkarounds;
+    }
 
     public String getJsonpBufferStrategy() {
         return jsonpBufferStrategy;

Modified: openwebbeans/meecrowave/trunk/meecrowave-gradle-plugin/src/main/java/org/apache/meecrowave/gradle/MeecrowaveTask.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-gradle-plugin/src/main/java/org/apache/meecrowave/gradle/MeecrowaveTask.java?rev=1770581&r1=1770580&r2=1770581&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-gradle-plugin/src/main/java/org/apache/meecrowave/gradle/MeecrowaveTask.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-gradle-plugin/src/main/java/org/apache/meecrowave/gradle/MeecrowaveTask.java
Sun Nov 20 19:37:36 2016
@@ -295,6 +295,10 @@ public class MeecrowaveTask extends Defa
     @Optional
     private String jsonbOrderStrategy;
 
+    @Input
+    @Optional
+    private boolean java9SkipWorkarounds = false;
+
     @TaskAction
     public void bake() {
         fixConfig();
@@ -935,4 +939,12 @@ public class MeecrowaveTask extends Defa
     public void setUseLog4j2JulLogManager(final boolean useLog4j2JulLogManager) {
         this.useLog4j2JulLogManager = useLog4j2JulLogManager;
     }
+
+    public boolean isJava9SkipWorkarounds() {
+        return java9SkipWorkarounds;
+    }
+
+    public void setJava9SkipWorkarounds(final boolean java9SkipWorkarounds) {
+        this.java9SkipWorkarounds = java9SkipWorkarounds;
+    }
 }

Modified: openwebbeans/meecrowave/trunk/meecrowave-jpa/src/test/java/org/apache/meecrowave/jpa/internal/JpaExtensionTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-jpa/src/test/java/org/apache/meecrowave/jpa/internal/JpaExtensionTest.java?rev=1770581&r1=1770580&r2=1770581&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-jpa/src/test/java/org/apache/meecrowave/jpa/internal/JpaExtensionTest.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-jpa/src/test/java/org/apache/meecrowave/jpa/internal/JpaExtensionTest.java
Sun Nov 20 19:37:36 2016
@@ -21,21 +21,32 @@ package org.apache.meecrowave.jpa.intern
 import org.apache.meecrowave.Meecrowave;
 import org.apache.meecrowave.junit.MeecrowaveRule;
 import org.app.JPADao;
+import org.junit.Assume;
 import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.TestRule;
+import org.junit.runners.model.Statement;
 
 import javax.inject.Inject;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.rules.RuleChain.outerRule;
 
 public class JpaExtensionTest {
     @Rule
-    public final MeecrowaveRule rule = new MeecrowaveRule(
+    public final TestRule rule = outerRule((base, description) -> new Statement() {
+        @Override
+        public void evaluate() throws Throwable {
+            final String jVersion = System.getProperty("java.version");
+            Assume.assumeFalse(jVersion.startsWith("9-") || jVersion.startsWith("1.9"));
// openjpa loops on java 9 bytecode
+            base.evaluate();
+        }
+    }).around(new MeecrowaveRule(
             new Meecrowave.Builder().randomHttpPort()
                     .property("jpa.property.openjpa.RuntimeUnenhancedClasses", "supported")
                     .property("jpa.property.openjpa.jdbc.SynchronizeMappings", "buildSchema"),
             "")
-            .inject(this);
+            .inject(this));
 
     @Inject
     private JPADao service;

Modified: openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/main/java/org/apache/meecrowave/maven/MeecrowaveRunMojo.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/main/java/org/apache/meecrowave/maven/MeecrowaveRunMojo.java?rev=1770581&r1=1770580&r2=1770581&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/main/java/org/apache/meecrowave/maven/MeecrowaveRunMojo.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/main/java/org/apache/meecrowave/maven/MeecrowaveRunMojo.java
Sun Nov 20 19:37:36 2016
@@ -97,6 +97,9 @@ public class MeecrowaveRunMojo extends A
     @Parameter(property = "meecrowave.tomcatAutoSetup", defaultValue = "true")
     private boolean tomcatAutoSetup;
 
+    @Parameter(property = "meecrowave.java9SkipWorkarounds")
+    private boolean java9SkipWorkarounds;
+
     @Parameter(property = "meecrowave.skipHttp")
     private boolean skipHttp;
 

Modified: openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/java/org/apache/meecrowave/maven/MeecrowaveRunMojoTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/java/org/apache/meecrowave/maven/MeecrowaveRunMojoTest.java?rev=1770581&r1=1770580&r2=1770581&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/java/org/apache/meecrowave/maven/MeecrowaveRunMojoTest.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/java/org/apache/meecrowave/maven/MeecrowaveRunMojoTest.java
Sun Nov 20 19:37:36 2016
@@ -27,6 +27,7 @@ import org.apache.maven.plugin.testing.M
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.ProjectBuilder;
 import org.apache.maven.project.ProjectBuildingRequest;
+import org.apache.meecrowave.hack.Java9WorkArounds;
 import org.codehaus.plexus.util.xml.Xpp3Dom;
 import org.eclipse.aether.DefaultRepositorySystemSession;
 import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
@@ -47,6 +48,10 @@ import static org.junit.Assert.assertEqu
 import static org.junit.Assert.fail;
 
 public class MeecrowaveRunMojoTest {
+    static { // if not that eager then we can't run the test on java 9
+        Java9WorkArounds.execute();
+    }
+
     @Rule
     public final MojoRule mojo = new MojoRule();
 



Mime
View raw message