openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1823356 - in /openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave: Meecrowave.java openwebbeans/KnownClassesFilter.java
Date Tue, 06 Feb 2018 16:02:33 GMT
Author: struberg
Date: Tue Feb  6 16:02:33 2018
New Revision: 1823356

URL: http://svn.apache.org/viewvc?rev=1823356&view=rev
Log:
MEECROWAVE-96 add withPackages 

to not exclude all scanning of anything else like done with excludePackage

Modified:
    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/KnownClassesFilter.java

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=1823356&r1=1823355&r2=1823356&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
Tue Feb  6 16:02:33 2018
@@ -1286,6 +1286,10 @@ public class Meecrowave implements AutoC
             return scanningPackageIncludes;
         }
 
+        /**
+         * Define some package names (startsWith) which must get scanned for beans.
+         * This rule get's applied before {@link #setScanningPackageExcludes(String)}
+         */
         public void setScanningPackageIncludes(final String scanningPackageIncludes) {
             this.scanningPackageIncludes = scanningPackageIncludes;
         }
@@ -1294,6 +1298,13 @@ public class Meecrowave implements AutoC
             return scanningPackageExcludes;
         }
 
+        /**
+         * Define some package names (startsWith) which must <em>NOT</em> get
scanned for beans.
+         * This rule get's applied after {@link #setScanningPackageIncludes(String)}.
+         *
+         * Defining just a '*' will be a marker for skipping all not-included packages.
+         * Otherwise we will defer to the standard OpenWebBeans class Filter mechanism.
+         */
         public void setScanningPackageExcludes(final String scanningPackageExcludes) {
             this.scanningPackageExcludes = scanningPackageExcludes;
         }
@@ -1303,8 +1314,21 @@ public class Meecrowave implements AutoC
             return this;
         }
 
+        /**
+         * Only scan the very packages given (startsWith).
+         * This will exclude <em>all</em> other packages from bean scanning
+         */
         public Builder includePackages(final String packages) {
             this.setScanningPackageIncludes(packages);
+            this.setScanningPackageExcludes("*");
+            return this;
+        }
+
+        /**
+         * Scan the very packages given (startsWith) <em>in addition</em> to
the default rules.
+         */
+        public Builder withPackages(final String packages) {
+            this.setScanningPackageIncludes(packages);
             return this;
         }
 

Modified: openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/KnownClassesFilter.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/KnownClassesFilter.java?rev=1823356&r1=1823355&r2=1823356&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/KnownClassesFilter.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/KnownClassesFilter.java
Tue Feb  6 16:02:33 2018
@@ -37,6 +37,7 @@ public class KnownClassesFilter implemen
 
     private final Filter delegateAccept;
     private final Filter delegateSkip;
+    private boolean skipAll = false;
 
     public KnownClassesFilter() {
         final Set<String> excluded = new HashSet<>();
@@ -173,6 +174,9 @@ public class KnownClassesFilter implemen
     public void init(final Meecrowave.Builder config) {
         forced = buildArray(config.getScanningPackageIncludes()).orElse(forced);
         skipped = buildArray(config.getScanningPackageExcludes()).orElse(skipped);
+
+        // if we only got one skip and this is '*' then we skip all packages
+       skipAll = skipped.length == 1 && "*".equals(skipped[0]);
     }
 
     private Optional<String[]> buildArray(final String config) {
@@ -189,9 +193,13 @@ public class KnownClassesFilter implemen
             return true;
         }
 
-        // skip has the same logic than forced + the fact that if we have some forced packaged
we skip all others
-        // this is not symmetric but often what is desired
-        if ((skipped != null && skipped.length > 0 && startsWith(skipped,
name)) || (skipped != null && skipped.length == 0 && forced != null &&
forced.length > 0)) {
+        // in case skipped = '*' we skip all and do not delegate
+        if (skipAll) {
+            return false;
+        }
+
+        // skip has the same logic than forced
+        if (skipped != null && skipped.length > 0 && startsWith(skipped,
name)) {
             return false;
         }
 



Mime
View raw message