openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1777484 - in /openwebbeans/meecrowave/trunk: meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/ meecrowave-core/src/main/java/org/apache/meecrowave/tomcat/ meecrowave-core/src/test/java/org/apache/meecrowave/ meecrowave-doc/...
Date Thu, 05 Jan 2017 17:30:46 GMT
Author: rmannibucau
Date: Thu Jan  5 17:30:46 2017
New Revision: 1777484

URL: http://svn.apache.org/viewvc?rev=1777484&view=rev
Log:
OWB-1168 groovy support

Modified:
    openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/KnownJarsFilter.java
    openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/OWBTomcatWebScannerService.java
    openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/tomcat/OWBJarScanner.java
    openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/NoConnectorTest.java
    openwebbeans/meecrowave/trunk/meecrowave-doc/src/main/jbake/content/start.adoc

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=1777484&r1=1777483&r2=1777484&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
Thu Jan  5 17:30:46 2017
@@ -46,6 +46,7 @@ public class KnownJarsFilter implements
         add("akka-actor-");
         add("akka-cluster-");
         add("akka-remote-");
+        add("ant-");
         add("antlr-");
         add("aopalliance-");
         add("args4j-");
@@ -73,6 +74,7 @@ public class KnownJarsFilter implements
         add("batchee-jbatch");
         add("bcprov-");
         add("bootstrap.jar");
+        add("bsf-");
         add("bval-core");
         add("bval-jsr");
         add("c3p0-");
@@ -128,6 +130,7 @@ public class KnownJarsFilter implements
         add("fusemq-leveldb-");
         add("geronimo-");
         add("google-");
+        add("gpars-");
         add("gragent.jar");
         add("groovy-");
         add("gson-");
@@ -149,6 +152,7 @@ public class KnownJarsFilter implements
         add("idb-");
         add("idea_rt.jar");
         add("istack-commons-runtime-");
+        add("ivy-");
         add("jackson-annotations-");
         add("jackson-core-");
         add("jackson-databind-");
@@ -186,6 +190,7 @@ public class KnownJarsFilter implements
         add("jsoup-");
         add("jsonb-api");
         add("jsp-api");
+        add("jsr166");
         add("jsr299-");
         add("jsr311-");
         add("jsse.jar");
@@ -207,6 +212,7 @@ public class KnownJarsFilter implements
         add("mimepull-");
         add("mina-");
         add("mqtt-client-");
+        add("multiverse-core-");
         add("myfaces-api");
         add("myfaces-impl");
         add("mysql-connector-java-");
@@ -235,6 +241,7 @@ public class KnownJarsFilter implements
         add("plugin.jar");
         add("poi-");
         add("quartz-2");
+        add("qdox-");
         add("quartz-openejb-");
         add("resources.jar");
         add("rmock-");
@@ -303,11 +310,13 @@ public class KnownJarsFilter implements
         add("xml-apis-");
         add("xml-resolver-");
         add("xmlbeans-");
+        add("xmlpull-");
         add("xmlrpc-");
         add("xmlschema-");
         add("xmlsec-");
         add("xmltooling-");
         add("xmlunit-");
+        add("xstream-");
         add("ziplock-");
         add("zipfs.jar");
     }};

Modified: openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/OWBTomcatWebScannerService.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/OWBTomcatWebScannerService.java?rev=1777484&r1=1777483&r2=1777484&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/OWBTomcatWebScannerService.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/OWBTomcatWebScannerService.java
Thu Jan  5 17:30:46 2017
@@ -21,18 +21,29 @@ package org.apache.meecrowave.openwebbea
 import org.apache.meecrowave.Meecrowave;
 import org.apache.meecrowave.logging.tomcat.LogFacade;
 import org.apache.tomcat.JarScanFilter;
+import org.apache.webbeans.corespi.scanner.xbean.CdiArchive;
+import org.apache.webbeans.spi.BeanArchiveService;
+import org.apache.webbeans.util.WebBeansUtil;
 import org.apache.webbeans.web.scanner.WebScannerService;
+import org.apache.xbean.finder.AnnotationFinder;
 import org.apache.xbean.finder.filter.Filter;
 
 import javax.servlet.ServletContext;
 import java.io.File;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.net.MalformedURLException;
+import java.net.URI;
 import java.net.URL;
+import java.util.Collection;
 import java.util.HashSet;
 import java.util.Set;
+import java.util.stream.Stream;
 
 import static java.util.Optional.of;
 import static java.util.Optional.ofNullable;
+import static java.util.stream.Collectors.toSet;
 import static org.apache.tomcat.JarScanType.PLUGGABILITY;
 
 public class OWBTomcatWebScannerService extends WebScannerService {
@@ -57,6 +68,7 @@ public class OWBTomcatWebScannerService
             return;
         }
         super.scan();
+        scanGroovy(WebBeansUtil.getCurrentClassLoader());
         if (!urls.isEmpty()) {
             logger.info("OpenWebBeans scanning:");
             final String m2 = new File(System.getProperty("user.home", "."), ".m2/repository").getAbsolutePath();
@@ -92,6 +104,70 @@ public class OWBTomcatWebScannerService
         shared = null;
     }
 
+    private void scanGroovy(final ClassLoader currentClassLoader) {
+        if (currentClassLoader == null || !currentClassLoader.getClass().getName().equals("groovy.lang.GroovyClassLoader"))
{
+            return;
+        }
+        try {
+            final Class<?>[] getLoadedClasses = Class[].class.cast(
+                    currentClassLoader.getClass()
+                            .getMethod("getLoadedClasses")
+                            .invoke(currentClassLoader));
+            addClassesToDefault(getLoadedClasses);
+        } catch (final Exception e) {
+            new LogFacade(OWBTomcatWebScannerService.class.getName()).warn(e.getMessage());
+        }
+    }
+
+    private void addClassesToDefault(final Class<?>[] all) throws Exception {
+        if (all == null || all.length == 0) {
+            return;
+        }
+
+        final Field linking = AnnotationFinder.class.getDeclaredField("linking");
+        final Method readClassDef = AnnotationFinder.class.getDeclaredMethod("readClassDef",
Class.class);
+        if (!readClassDef.isAccessible()) {
+            readClassDef.setAccessible(true);
+        }
+        if (!linking.isAccessible()) {
+            linking.setAccessible(true);
+        }
+
+        final URI uri = URI.create("jar:file://!/"); // we'll never find it during scanning
and it avoids to create a custom handler
+        final URL url = uri.toURL();
+        final String key = uri.toASCIIString();
+        CdiArchive.FoundClasses foundClasses = archive.classesByUrl().get(key);
+        if (foundClasses == null) {
+            final BeanArchiveService beanArchiveService = webBeansContext.getBeanArchiveService();
+            foundClasses = CdiArchive.FoundClasses.class.cast(
+                    CdiArchive.FoundClasses.class.getConstructor(CdiArchive.class, URL.class,
Collection.class, BeanArchiveService.BeanArchiveInformation.class)
+                            .newInstance(null, url, new HashSet<>(), beanArchiveService.getBeanArchiveInformation(url)));
+            archive.classesByUrl().put(key, foundClasses);
+        }
+
+        foundClasses.getClassNames().addAll(Stream.of(all).map(Class::getName).collect(toSet()));
+
+        try {
+            linking.set(finder, true);
+
+            Stream.of(all).forEach(c -> { // populate classInfos map to support annotated
mode which relies on ClassInfo
+                try {
+                    readClassDef.invoke(finder, c);
+                } catch (final IllegalAccessException e) {
+                    throw new IllegalStateException(e);
+                } catch (final InvocationTargetException e) {
+                    throw new IllegalStateException(e.getCause());
+                }
+            });
+        } finally {
+            try {
+                linking.set(finder, false);
+            } catch (final IllegalAccessException e) {
+                // no-op
+            }
+        }
+    }
+
     @Override
     protected void filterExcludedJars(final Set<URL> classPathUrls) {
         String jreBaseTmp;

Modified: openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/tomcat/OWBJarScanner.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/tomcat/OWBJarScanner.java?rev=1777484&r1=1777483&r2=1777484&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/tomcat/OWBJarScanner.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/tomcat/OWBJarScanner.java
Thu Jan  5 17:30:46 2017
@@ -45,29 +45,31 @@ public class OWBJarScanner implements Ja
         switch (jarScanType) {
             case PLUGGABILITY:
                 CdiArchive.class.cast(WebScannerService.class.cast(WebBeansContext.getInstance().getScannerService()).getFinder().getArchive())
-                        .classesByUrl().keySet().forEach(u -> {
-                    try {
-                        final URL url = new URL(u);
-                        if ("jar".equals(url.getProtocol()) || url.getPath().endsWith(Constants.JAR_EXT))
{
-                            try (final Jar jar = JarFactory.newInstance(url)) {
-                                callback.scan(jar, u, true);
-                            }
-                        } else if ("file".equals(url.getProtocol())) {
-                            final File f = new File(url.toURI());
-                            if (f.isFile()) {
-                                try (final Jar jar = JarFactory.newInstance(UriUtil.buildJarUrl(f)))
{
-                                    callback.scan(jar, f.getAbsolutePath(), true);
+                        .classesByUrl().keySet().stream()
+                        .filter(u -> !"jar:file://!/".equals(u)) // not a fake in memory
url
+                        .forEach(u -> {
+                            try {
+                                final URL url = new URL(u);
+                                if ("jar".equals(url.getProtocol()) || url.getPath().endsWith(Constants.JAR_EXT))
{
+                                    try (final Jar jar = JarFactory.newInstance(url)) {
+                                        callback.scan(jar, u, true);
+                                    }
+                                } else if ("file".equals(url.getProtocol())) {
+                                    final File f = new File(url.toURI());
+                                    if (f.isFile()) {
+                                        try (final Jar jar = JarFactory.newInstance(UriUtil.buildJarUrl(f)))
{
+                                            callback.scan(jar, f.getAbsolutePath(), true);
+                                        }
+                                    } else if (f.isDirectory()) {
+                                        callback.scan(f, f.getAbsolutePath(), true);
+                                    }
                                 }
-                            } else if (f.isDirectory()) {
-                                callback.scan(f, f.getAbsolutePath(), true);
+                            } catch (final MalformedURLException e) {
+                                // skip
+                            } catch (final IOException | URISyntaxException ioe) {
+                                throw new IllegalArgumentException(ioe);
                             }
-                        }
-                    } catch (final MalformedURLException e) {
-                        // skip
-                    } catch (final IOException | URISyntaxException ioe) {
-                        throw new IllegalArgumentException(ioe);
-                    }
-                });
+                        });
                 return;
 
             case TLD:

Modified: openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/NoConnectorTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/NoConnectorTest.java?rev=1777484&r1=1777483&r2=1777484&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/NoConnectorTest.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/NoConnectorTest.java
Thu Jan  5 17:30:46 2017
@@ -45,7 +45,7 @@ public class NoConnectorTest {
                     .get());
             IntStream.of(config.getHttpPort(), config.getHttpsPort()).forEach(port ->
{
                 try (final Socket socket = new Socket("localhost", port)) {
-                    fail("port " + config.getHttpsPort() + " is opened");
+                    fail("port " + port + " is opened");
                 } catch (final IOException e) {
                     // ok
                 }

Modified: openwebbeans/meecrowave/trunk/meecrowave-doc/src/main/jbake/content/start.adoc
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-doc/src/main/jbake/content/start.adoc?rev=1777484&r1=1777483&r2=1777484&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-doc/src/main/jbake/content/start.adoc (original)
+++ openwebbeans/meecrowave/trunk/meecrowave-doc/src/main/jbake/content/start.adoc Thu Jan
 5 17:30:46 2017
@@ -46,3 +46,43 @@ And you can check it works doing:
 ----
 curl http://localhost:8080/kitchen
 ----
+
+== You're in a hurry? Use groovy!
+
+Create a file called `hello.groovy`:
+
+[source,groovy]
+----
+@Grab('org.apache.meecrowave:meecrowave-core:0.3.0')
+
+import org.apache.meecrowave.Meecrowave
+
+import javax.ws.rs.GET
+import javax.ws.rs.Path
+import javax.enterprise.context.ApplicationScoped
+
+@Path("hello")
+@ApplicationScoped
+class Hello {
+    @GET
+    hi() {
+        "hi"
+    }
+}
+
+new Meecrowave().bake().await()
+----
+
+then
+
+[source,groovy]
+----
+groovy hello.groovy
+----
+
+Finally you can test it:
+
+[source]
+----
+curl http://localhost:8080/hello
+----
\ No newline at end of file



Mime
View raw message