openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1772610 - in /openwebbeans/meecrowave/trunk: meecrowave-arquillian/src/main/java/org/apache/meecrowave/arquillian/ meecrowave-core/src/main/java/org/apache/catalina/startup/ meecrowave-core/src/main/java/org/apache/meecrowave/ meecrowave-c...
Date Mon, 05 Dec 2016 09:04:23 GMT
Author: rmannibucau
Date: Mon Dec  5 09:04:23 2016
New Revision: 1772610

URL: http://svn.apache.org/viewvc?rev=1772610&view=rev
Log:
few code cleanup and adding scaninng include/exclude to the configuration. Also fixing the
mojo js customizer variables adding project and renaming catalinaBase to meecrowaveBase

Modified:
    openwebbeans/meecrowave/trunk/meecrowave-arquillian/src/main/java/org/apache/meecrowave/arquillian/MeecrowaveConfiguration.java
    openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/catalina/startup/MeecrowaveContextConfig.java
    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-core/src/main/java/org/apache/meecrowave/openwebbeans/OWBTomcatWebScannerService.java
    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-maven-plugin/src/main/java/org/apache/meecrowave/maven/MeecrowaveRunMojo.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=1772610&r1=1772609&r2=1772610&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
Mon Dec  5 09:04:23 2016
@@ -95,6 +95,8 @@ public class MeecrowaveConfiguration imp
     private String jsonbNamingStrategy;
     private String jsonbOrderStrategy;
     private boolean java9SkipWorkarounds = false;
+    private String scanningIncludes;
+    private String scanningExcludes;
 
     @Override
     public void validate() throws ConfigurationException {
@@ -562,4 +564,20 @@ public class MeecrowaveConfiguration imp
     public void setUseLog4j2JulLogManager(final boolean useLog4j2JulLogManager) {
         this.useLog4j2JulLogManager = useLog4j2JulLogManager;
     }
+
+    public String getScanningIncludes() {
+        return scanningIncludes;
+    }
+
+    public void setScanningIncludes(final String scanningIncludes) {
+        this.scanningIncludes = scanningIncludes;
+    }
+
+    public String getScanningExcludes() {
+        return scanningExcludes;
+    }
+
+    public void setScanningExcludes(final String scanningExcludes) {
+        this.scanningExcludes = scanningExcludes;
+    }
 }

Modified: openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/catalina/startup/MeecrowaveContextConfig.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/catalina/startup/MeecrowaveContextConfig.java?rev=1772610&r1=1772609&r2=1772610&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/catalina/startup/MeecrowaveContextConfig.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/catalina/startup/MeecrowaveContextConfig.java
Mon Dec  5 09:04:23 2016
@@ -22,6 +22,7 @@ import org.apache.catalina.WebResource;
 import org.apache.meecrowave.Meecrowave;
 import org.apache.meecrowave.logging.tomcat.LogFacade;
 import org.apache.meecrowave.openwebbeans.OWBTomcatWebScannerService;
+import org.apache.tomcat.JarScanner;
 import org.apache.tomcat.util.descriptor.web.WebXml;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.corespi.scanner.xbean.CdiArchive;
@@ -74,7 +75,7 @@ public class MeecrowaveContextConfig ext
         thread.setContextClassLoader(loader);
         try {
             final OWBTomcatWebScannerService scannerService = OWBTomcatWebScannerService.class.cast(WebBeansContext.getInstance().getScannerService());
-            ofNullable(context.getJarScanner()).ifPresent(s -> scannerService.setFilter(s.getJarScanFilter()));
+            scannerService.setFilter(ofNullable(context.getJarScanner()).map(JarScanner::getJarScanFilter).orElse(null),
context.getServletContext());
             scannerService.setDocBase(context.getDocBase());
             scannerService.setShared(configuration.getSharedLibraries());
             scannerService.scan();

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=1772610&r1=1772609&r2=1772610&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
Mon Dec  5 09:04:23 2016
@@ -183,10 +183,11 @@ public class Meecrowave implements AutoC
             return d;
         });
 
+        final OWBJarScanner scanner = new OWBJarScanner();
         final StandardContext ctx = new StandardContext();
         ctx.setPath(meta.context);
         ctx.setName(meta.context);
-        ctx.setJarScanner(new OWBJarScanner());
+        ctx.setJarScanner(scanner);
         ctx.setInstanceManager(new CDIInstanceManager());
         try {
             ctx.setDocBase(dir.getCanonicalPath());
@@ -194,13 +195,11 @@ public class Meecrowave implements AutoC
             ctx.setDocBase(dir.getAbsolutePath());
         }
         ofNullable(configuration.tomcatFilter).ifPresent(filter -> {
-            final OWBJarScanner jarScanner = new OWBJarScanner();
             try {
-                jarScanner.setJarScanFilter(JarScanFilter.class.cast(Thread.currentThread().getContextClassLoader().loadClass(filter).newInstance()));
+                scanner.setJarScanFilter(JarScanFilter.class.cast(Thread.currentThread().getContextClassLoader().loadClass(filter).newInstance()));
             } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException
e) {
                 throw new IllegalArgumentException(e);
             }
-            ctx.setJarScanner(jarScanner);
         });
         ctx.addLifecycleListener(new MeecrowaveContextConfig(configuration));
         ctx.addLifecycleListener(event -> {
@@ -209,6 +208,7 @@ public class Meecrowave implements AutoC
                     ctx.getResources().setCachingAllowed(configuration.webResourceCached);
                     break;
                 case Lifecycle.BEFORE_INIT_EVENT:
+                    ctx.getServletContext().setAttribute("meecrowave.configuration", configuration);
                     if (configuration.loginConfig != null) {
                         ctx.setLoginConfig(configuration.loginConfig.build());
                     }
@@ -226,8 +226,6 @@ public class Meecrowave implements AutoC
         ctx.addLifecycleListener(new Tomcat.FixContextListener()); // after having configured
the security!!!
 
         ctx.addServletContainerInitializer((c, ctx1) -> {
-            ctx.getServletContext().setAttribute("meecrowave.configuration", configuration);
-
             new OWBAutoSetup().onStartup(c, ctx1);
             new CxfCdiAutoSetup().onStartup(c, ctx1);
             new TomcatAutoInitializer().onStartup(c, ctx1);
@@ -869,6 +867,12 @@ public class Meecrowave implements AutoC
         @CliOption(name = "tomcat-filter", description = "A Tomcat JarScanFilter")
         private String tomcatFilter;
 
+        @CliOption(name = "scanning-include", description = "A forced include list of jar
names (comma separated values)")
+        private String scanningIncludes;
+
+        @CliOption(name = "scanning-exclude", description = "A forced exclude list of jar
names (comma separated values)")
+        private String scanningExcludes;
+
         @CliOption(name = "tomcat-default", description = "Should Tomcat default be set (session
timeout, mime mapping etc...)")
         private boolean useTomcatDefaults = true;
 
@@ -904,6 +908,22 @@ public class Meecrowave implements AutoC
             extensions.put(type, value);
         }
 
+        public String getScanningIncludes() {
+            return scanningIncludes;
+        }
+
+        public void setScanningIncludes(final String scanningIncludes) {
+            this.scanningIncludes = scanningIncludes;
+        }
+
+        public String getScanningExcludes() {
+            return scanningExcludes;
+        }
+
+        public void setScanningExcludes(final String scanningExcludes) {
+            this.scanningExcludes = scanningExcludes;
+        }
+
         public boolean isJava9SkipWorkarounds() {
             return java9SkipWorkarounds;
         }

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=1772610&r1=1772609&r2=1772610&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
Mon Dec  5 09:04:23 2016
@@ -18,11 +18,16 @@
  */
 package org.apache.meecrowave.openwebbeans;
 
+import org.apache.meecrowave.Meecrowave;
 import org.apache.tomcat.JarScanFilter;
 import org.apache.tomcat.JarScanType;
 
 import java.util.Collection;
 import java.util.HashSet;
+import java.util.stream.Stream;
+
+import static java.util.Optional.ofNullable;
+import static java.util.stream.Collectors.toSet;
 
 public class KnownJarsFilter implements JarScanFilter {
     private final Collection<String> forceIncludes = new HashSet<String>() {{
@@ -297,9 +302,21 @@ public class KnownJarsFilter implements
         add("zipfs.jar");
     }};
 
+    public KnownJarsFilter() {
+        // no-op
+    }
+
+    KnownJarsFilter(final Meecrowave.Builder config) {
+        ofNullable(config.getScanningIncludes()).ifPresent(i -> {
+            forceIncludes.clear();
+            forceIncludes.addAll(Stream.of(i.split(",")).map(String::trim).filter(j ->
!j.isEmpty()).collect(toSet()));
+        });
+        ofNullable(config.getScanningExcludes())
+                .ifPresent(i -> excludes.addAll(Stream.of(i.split(",")).map(String::trim).filter(j
-> !j.isEmpty()).collect(toSet())));
+    }
+
     @Override
     public boolean check(final JarScanType jarScanType, final String jarName) {
-        return forceIncludes.stream().filter(jarName::startsWith).findAny().isPresent()
-                || !excludes.stream().filter(jarName::startsWith).findAny().isPresent();
+        return forceIncludes.stream().anyMatch(jarName::startsWith) || excludes.stream().noneMatch(jarName::startsWith);
     }
 }

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=1772610&r1=1772609&r2=1772610&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
Mon Dec  5 09:04:23 2016
@@ -18,10 +18,12 @@
  */
 package org.apache.meecrowave.openwebbeans;
 
+import org.apache.meecrowave.Meecrowave;
 import org.apache.meecrowave.logging.tomcat.LogFacade;
 import org.apache.tomcat.JarScanFilter;
 import org.apache.webbeans.web.scanner.WebScannerService;
 
+import javax.servlet.ServletContext;
 import java.io.File;
 import java.net.MalformedURLException;
 import java.net.URL;
@@ -44,6 +46,11 @@ public class OWBTomcatWebScannerService
     private String shared;
 
     @Override
+    public void init(final Object context) {
+        // no-op
+    }
+
+    @Override
     public void scan() {
         if (finder != null) {
             return;
@@ -71,7 +78,7 @@ public class OWBTomcatWebScannerService
                     shownValue = "${maven}/" + shownValue.substring(shownValue.replace(File.separatorChar,
'/').lastIndexOf('/') + 1);
                 } else if (shownValue.startsWith(base)) {
                     shownValue = "${app}" + shownValue.replace(base, "");
-                } else if (sharedBase != null && shownValue.startsWith(sharedBase))
{
+                } else if (shownValue.startsWith(sharedBase)) {
                     shownValue = "${shared}" + shownValue.replace(sharedBase, "");
                 }
 
@@ -86,10 +93,6 @@ public class OWBTomcatWebScannerService
 
     @Override
     protected void filterExcludedJars(final Set<URL> classPathUrls) {
-        if (filter == null) {
-            filter = new KnownJarsFilter();
-        }
-
         String jreBaseTmp;
         try {
             jreBaseTmp = new File(System.getProperty("java.home")).toURI().toURL().toExternalForm();
@@ -124,8 +127,15 @@ public class OWBTomcatWebScannerService
         return filter.check(PLUGGABILITY, path.substring(filenameIdx)) ? -1 : (path.indexOf(".jar")
- 1);
     }
 
-    public void setFilter(final JarScanFilter filter) {
+    // replace init
+    public void setFilter(final JarScanFilter filter, final ServletContext ctx) {
         this.filter = filter;
+
+        super.init(ctx);
+        if (this.filter == null) {
+            final Meecrowave.Builder config = Meecrowave.Builder.class.cast(ServletContext.class.cast(ctx).getAttribute("meecrowave.configuration"));
+            this.filter = new KnownJarsFilter(config);
+        }
     }
 
     @Override

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=1772610&r1=1772609&r2=1772610&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
Mon Dec  5 09:04:23 2016
@@ -85,6 +85,8 @@ public class MeecrowaveExtension {
     private String jsonbNamingStrategy;
     private String jsonbOrderStrategy;
     private boolean java9SkipWorkarounds = false;
+    private String scanningIncludes;
+    private String scanningExcludes;
 
     public boolean isJava9SkipWorkarounds() {
         return java9SkipWorkarounds;
@@ -565,4 +567,20 @@ public class MeecrowaveExtension {
     public void setTomcatAutoSetup(final boolean tomcatAutoSetup) {
         this.tomcatAutoSetup = tomcatAutoSetup;
     }
+
+    public String getScanningIncludes() {
+        return scanningIncludes;
+    }
+
+    public void setScanningIncludes(final String scanningIncludes) {
+        this.scanningIncludes = scanningIncludes;
+    }
+
+    public String getScanningExcludes() {
+        return scanningExcludes;
+    }
+
+    public void setScanningExcludes(final String scanningExcludes) {
+        this.scanningExcludes = scanningExcludes;
+    }
 }

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=1772610&r1=1772609&r2=1772610&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
Mon Dec  5 09:04:23 2016
@@ -299,6 +299,14 @@ public class MeecrowaveTask extends Defa
     @Optional
     private boolean java9SkipWorkarounds = false;
 
+    @Input
+    @Optional
+    private String scanningIncludes;
+
+    @Input
+    @Optional
+    private String scanningExcludes;
+
     @TaskAction
     public void bake() {
         fixConfig();
@@ -947,4 +955,20 @@ public class MeecrowaveTask extends Defa
     public void setJava9SkipWorkarounds(final boolean java9SkipWorkarounds) {
         this.java9SkipWorkarounds = java9SkipWorkarounds;
     }
+
+    public String getScanningIncludes() {
+        return scanningIncludes;
+    }
+
+    public void setScanningIncludes(final String scanningIncludes) {
+        this.scanningIncludes = scanningIncludes;
+    }
+
+    public String getScanningExcludes() {
+        return scanningExcludes;
+    }
+
+    public void setScanningExcludes(final String scanningExcludes) {
+        this.scanningExcludes = scanningExcludes;
+    }
 }

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=1772610&r1=1772609&r2=1772610&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
Mon Dec  5 09:04:23 2016
@@ -242,6 +242,12 @@ public class MeecrowaveRunMojo extends A
     @Parameter(property = "meecrowave.jsonb-order-strategy")
     private String jsonbOrderStrategy;
 
+    @Parameter(property = "meecrowave.scanning-exclude")
+    private String scanningIncludes;
+
+    @Parameter(property = "meecrowave.scanning-include")
+    private String scanningExcludes;
+
     @Override
     public void execute() throws MojoExecutionException, MojoFailureException {
         if (skip) {
@@ -293,7 +299,8 @@ public class MeecrowaveRunMojo extends A
         for (final String js : customizers) {
             try {
                 final SimpleBindings bindings = new SimpleBindings();
-                bindings.put("catalinaBase", base);
+                bindings.put("meecrowaveBase", base);
+                bindings.put("project", project);
                 engine.eval(new StringReader(js), bindings);
             } catch (final ScriptException e) {
                 throw new IllegalStateException(e.getMessage(), e);



Mime
View raw message