camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r880657 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/impl/scan/ camel-core/src/test/java/org/apache/camel/impl/scan/ camel-core/src/test/resources/ components/camel-spring/src/main/java/org/apache/camel/spring/ components/ca...
Date Mon, 16 Nov 2009 08:24:39 GMT
Author: davsclaus
Date: Mon Nov 16 08:24:20 2009
New Revision: 880657

URL: http://svn.apache.org/viewvc?rev=880657&view=rev
Log:
CAMEL-2174: Moved ANT based package scan from camel-core to camel-spring where it belongs
due to its usage of ANT path matcher from spring core.

Added:
    camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/PatternBasedPackageScanFilter.java
  (contents, props changed)
      - copied, changed from r880639, camel/trunk/camel-core/src/main/java/org/apache/camel/impl/scan/PatternBasedPackageScanFilter.java
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/DefaultPackageScanClassResolverTest.java
  (with props)
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/PackageScanFiltersTest.java
  (with props)
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/PatternBasedPackageScanFilterTest.java
  (with props)
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/ScanTestSupport.java
  (with props)
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/ScannableOne.java
  (with props)
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/ScannableTwo.java
  (with props)
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/a/
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/a/ScanTargetOne.java
  (with props)
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/b/
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/b/ScanTargetTwo.java
  (with props)
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/c/
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/c/NotAScanTarget.java
  (with props)
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/c/ScanTargetThree.java
  (with props)
    camel/trunk/components/camel-spring/src/test/resources/package+scan+test.jar   (props
changed)
      - copied unchanged from r880639, camel/trunk/camel-core/src/test/resources/package+scan+test.jar
    camel/trunk/components/camel-spring/src/test/resources/package_scan_test.jar   (props
changed)
      - copied unchanged from r880639, camel/trunk/camel-core/src/test/resources/package_scan_test.jar
Removed:
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/scan/PatternBasedPackageScanFilter.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/impl/scan/
    camel/trunk/camel-core/src/test/resources/package+scan+test.jar
    camel/trunk/camel-core/src/test/resources/package_scan_test.jar
Modified:
    camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java

Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java?rev=880657&r1=880656&r2=880657&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
(original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
Mon Nov 16 08:24:20 2009
@@ -32,7 +32,7 @@
 import org.apache.camel.RoutesBuilder;
 import org.apache.camel.builder.ErrorHandlerBuilderRef;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.impl.scan.PatternBasedPackageScanFilter;
+import org.apache.camel.spring.PatternBasedPackageScanFilter;
 import org.apache.camel.management.DefaultManagementAgent;
 import org.apache.camel.management.DefaultManagementLifecycleStrategy;
 import org.apache.camel.management.DefaultManagementStrategy;

Copied: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/PatternBasedPackageScanFilter.java
(from r880639, camel/trunk/camel-core/src/main/java/org/apache/camel/impl/scan/PatternBasedPackageScanFilter.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/PatternBasedPackageScanFilter.java?p2=camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/PatternBasedPackageScanFilter.java&p1=camel/trunk/camel-core/src/main/java/org/apache/camel/impl/scan/PatternBasedPackageScanFilter.java&r1=880639&r2=880657&rev=880657&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/scan/PatternBasedPackageScanFilter.java
(original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/PatternBasedPackageScanFilter.java
Mon Nov 16 08:24:20 2009
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.impl.scan;
+package org.apache.camel.spring;
 
 import java.util.ArrayList;
 import java.util.Collection;

Propchange: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/PatternBasedPackageScanFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/PatternBasedPackageScanFilter.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/DefaultPackageScanClassResolverTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/DefaultPackageScanClassResolverTest.java?rev=880657&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/DefaultPackageScanClassResolverTest.java
(added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/DefaultPackageScanClassResolverTest.java
Mon Nov 16 08:24:20 2009
@@ -0,0 +1,169 @@
+/**
+ * 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.camel.spring.scan;
+
+import java.lang.annotation.Annotation;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.camel.impl.DefaultPackageScanClassResolver;
+import org.apache.camel.spring.scan.a.ScanTargetOne;
+import org.apache.camel.spring.scan.b.ScanTargetTwo;
+import org.apache.camel.spring.scan.c.ScanTargetThree;
+
+public class DefaultPackageScanClassResolverTest extends org.apache.camel.spring.scan.ScanTestSupport
{
+
+    private DefaultPackageScanClassResolver resolver;
+    private Set<Class<? extends Annotation>> annotations = new HashSet<Class<?
extends Annotation>>();
+    private String scanPackage = "org.apache.camel.spring.scan";
+
+    public void setUp() throws Exception {
+        super.setUp();
+        resolver = new DefaultPackageScanClassResolver();
+        annotations.add(org.apache.camel.spring.scan.ScannableOne.class);
+        annotations.add(org.apache.camel.spring.scan.ScannableTwo.class);
+    }
+
+    public void testFindByAnnotationWithoutExtraFilters() {
+        Set<Class<?>> scanned = resolver.findAnnotated(org.apache.camel.spring.scan.ScannableOne.class,
scanPackage);
+        validateMatchingSetContains(scanned, ScanTargetOne.class, ScanTargetTwo.class);
+
+        scanned = resolver.findAnnotated(org.apache.camel.spring.scan.ScannableTwo.class,
scanPackage);
+        validateMatchingSetContains(scanned, ScanTargetThree.class);
+    }
+
+    public void testFindByAnnotationsWithoutExtraFilters() {
+        Set<Class<?>> scanned = resolver.findAnnotated(annotations, scanPackage);
+        validateMatchingSetContains(scanned, ScanTargetOne.class, ScanTargetTwo.class, ScanTargetThree.class);
+    }
+
+    public void testFindImplementationsWithoutExtraFilters() {
+        Set<Class<?>> scanned = resolver.findImplementations(ScanTargetOne.class,
scanPackage);
+        validateMatchingSetContains(scanned, ScanTargetOne.class, ScanTargetTwo.class);
+    }
+    
+    public void testFindByAnnotationWithIncludePackageFilter() {
+        filter.addIncludePattern(scanPackage + ".b.*");
+        resolver.addFilter(filter);
+
+        Set<Class<?>> scanned = resolver.findAnnotated(org.apache.camel.spring.scan.ScannableOne.class,
scanPackage);
+        validateMatchingSetContains(scanned, ScanTargetTwo.class);
+
+        scanned = resolver.findAnnotated(ScannableTwo.class, scanPackage);
+        validateMatchingSetContains(scanned);
+    }
+
+    public void testFindByAnnotationsWithIncludePackageFilter() {
+        filter.addIncludePattern(scanPackage + ".b.*");
+        filter.addIncludePattern(scanPackage + ".c.*");
+        resolver.addFilter(filter);
+
+        Set<Class<?>> scanned = resolver.findAnnotated(annotations, "org.apache.camel.spring.scan");
+        validateMatchingSetContains(scanned, ScanTargetTwo.class, ScanTargetThree.class);
+    }
+
+    public void testFindByAnnotationWithExcludePackageFilter() {
+        filter.addExcludePattern(scanPackage + ".b.*");
+        filter.addExcludePattern(scanPackage + ".c.*");
+        resolver.addFilter(filter);
+
+        Set<Class<?>> scanned = resolver.findAnnotated(ScannableOne.class, scanPackage);
+        validateMatchingSetContains(scanned, ScanTargetOne.class);
+
+        scanned = resolver.findAnnotated(org.apache.camel.spring.scan.ScannableTwo.class,
scanPackage);
+        validateMatchingSetContains(scanned);
+    }
+
+    public void testFindByAnnotationsWithExcludePackageFilter() {
+        filter.addExcludePattern(scanPackage + ".a.*");
+
+        Set<Class<?>> scanned = resolver.findAnnotated(annotations, "org.apache.camel.spring.scan");
+        validateMatchingSetContains(scanned, ScanTargetTwo.class, ScanTargetThree.class);
+    }
+
+    public void testFindByFilterWithIncludePackageFilter() {
+        filter.addIncludePattern(scanPackage + ".**.ScanTarget*");
+        resolver.addFilter(filter);
+
+        Set<Class<?>> scanned = resolver.findByFilter(filter, "org.apache.camel.spring.scan");
+        validateMatchingSetContains(scanned, ScanTargetOne.class, ScanTargetTwo.class, ScanTargetThree.class);
+    }
+    
+    public void testFindImplementationsWithIncludePackageFilter() {
+        filter.addIncludePattern(scanPackage + ".b.*");
+        resolver.addFilter(filter);
+        
+        Set<Class<?>> scanned = resolver.findImplementations(ScanTargetOne.class,
scanPackage);
+        validateMatchingSetContains(scanned,  ScanTargetTwo.class);
+    }
+    
+    public void testFindImplementationsWithExcludePackageFilter() {
+        filter.addExcludePattern(scanPackage + ".a.*");
+        resolver.addFilter(filter);
+        
+        Set<Class<?>> scanned = resolver.findImplementations(ScanTargetOne.class,
scanPackage);
+        validateMatchingSetContains(scanned,  ScanTargetTwo.class);
+    }
+    
+    public void testFindByFilterPackageInJarUrl() throws Exception {
+        ClassLoader savedClassLoader = null;
+        try {
+            savedClassLoader = Thread.currentThread().getContextClassLoader();
+            URL url = getClass().getResource("/package_scan_test.jar");
+            
+            URL urls[] = {new URL("jar:" + url.toString() + "!/")};
+            URLClassLoader classLoader = new URLClassLoader(urls, savedClassLoader);
+
+            Thread.currentThread().setContextClassLoader(classLoader);
+
+            filter.addIncludePattern("a.*.c.*");
+            resolver.addFilter(filter);
+            Set<Class<?>> scanned = resolver.findByFilter(filter, "a.b.c");
+            assertEquals(1, scanned.size());
+            assertEquals("class a.b.c.Test", scanned.iterator().next().toString());     
      
+        } finally {
+            if (savedClassLoader != null) {
+                Thread.currentThread().setContextClassLoader(savedClassLoader);
+            } 
+        }
+    }
+    
+    public void testFindByFilterPackageInJarUrlWithPlusChars() throws Exception {
+        ClassLoader savedClassLoader = null;
+        try {
+            savedClassLoader = Thread.currentThread().getContextClassLoader();
+            URL url = getClass().getResource("/package+scan+test.jar");
+
+            URL urls[] = {new URL("jar:" + url.toString() + "!/")};
+            URLClassLoader classLoader = new URLClassLoader(urls, savedClassLoader);
+
+            Thread.currentThread().setContextClassLoader(classLoader);
+
+            filter.addIncludePattern("a.*.c.*");
+            resolver.addFilter(filter);
+            Set<Class<?>> scanned = resolver.findByFilter(filter, "a.b.c");
+            assertEquals(1, scanned.size());
+            assertEquals("class a.b.c.Test", scanned.iterator().next().toString());
+        } finally {
+            if (savedClassLoader != null) {
+                Thread.currentThread().setContextClassLoader(savedClassLoader);
+            }
+        }
+    }
+}

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/DefaultPackageScanClassResolverTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/DefaultPackageScanClassResolverTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/PackageScanFiltersTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/PackageScanFiltersTest.java?rev=880657&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/PackageScanFiltersTest.java
(added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/PackageScanFiltersTest.java
Mon Nov 16 08:24:20 2009
@@ -0,0 +1,110 @@
+/**
+ * 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.camel.spring.scan;
+
+import java.lang.annotation.Annotation;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.apache.camel.impl.scan.AnnotatedWithAnyPackageScanFilter;
+import org.apache.camel.impl.scan.AnnotatedWithPackageScanFilter;
+import org.apache.camel.impl.scan.AssignableToPackageScanFilter;
+import org.apache.camel.impl.scan.CompositePackageScanFilter;
+import org.apache.camel.impl.scan.InvertingPackageScanFilter;
+import org.apache.camel.spi.PackageScanFilter;
+import org.apache.camel.spring.scan.a.ScanTargetOne;
+import org.apache.camel.spring.scan.b.ScanTargetTwo;
+import org.apache.camel.spring.scan.c.ScanTargetThree;
+import org.apache.camel.util.CollectionHelper;
+
+public class PackageScanFiltersTest extends TestCase {
+
+    public void testAssignableToPackageScanFilter() {
+        AssignableToPackageScanFilter filter = new AssignableToPackageScanFilter();
+        assertFalse(filter.matches(ScanTargetOne.class));
+
+        filter = new AssignableToPackageScanFilter(ScanTargetOne.class);
+        validateFilter(filter, ScanTargetOne.class);
+
+        filter = new AssignableToPackageScanFilter(ScanTargetOne.class);
+        validateFilter(filter, ScanTargetTwo.class);
+
+        Set<Class<?>> classes = new LinkedHashSet<Class<?>>();
+        classes.add(ScanTargetOne.class);
+        classes.add(ScanTargetThree.class);
+        filter = new AssignableToPackageScanFilter(classes);
+        validateFilter(filter, ScanTargetOne.class);
+        validateFilter(filter, ScanTargetTwo.class);
+        validateFilter(filter, ScanTargetThree.class);
+
+        assertTrue(filter.toString().contains("ScanTargetOne"));
+        assertTrue(filter.toString().contains("ScanTargetThree"));
+    }
+
+    public void testAnnotatedWithAnyPackageScanFilter() {
+        Set<Class<? extends Annotation>> annotations = new LinkedHashSet<Class<?
extends Annotation>>();
+        annotations.add(org.apache.camel.spring.scan.ScannableOne.class);
+        annotations.add(org.apache.camel.spring.scan.ScannableTwo.class);
+
+        AnnotatedWithAnyPackageScanFilter filter = new AnnotatedWithAnyPackageScanFilter(annotations);
+        Class<ScanTargetOne> type = ScanTargetOne.class;
+        validateFilter(filter, type);
+        validateFilter(filter, ScanTargetThree.class);
+
+        assertEquals("annotated with any @[[interface org.apache.camel.spring.scan.ScannableOne,
interface org.apache.camel.spring.scan.ScannableTwo]]", filter.toString());
+    }
+
+    public void testAnnotatedWithPackageScanFilter() {
+        AnnotatedWithPackageScanFilter filter = new AnnotatedWithPackageScanFilter(org.apache.camel.spring.scan.ScannableOne.class);
+        validateFilter(filter, ScanTargetOne.class);
+        validateFilter(filter, ScanTargetTwo.class);
+
+        filter = new AnnotatedWithPackageScanFilter(ScannableTwo.class);
+        validateFilter(filter, ScanTargetThree.class);
+        assertEquals("annotated with @ScannableTwo", filter.toString());
+    }
+
+    public void testCompositePackageScanFilter() {
+        PackageScanFilter one = new AnnotatedWithPackageScanFilter(org.apache.camel.spring.scan.ScannableOne.class);
+        PackageScanFilter two = new AssignableToPackageScanFilter(ScanTargetOne.class);
+        Set<PackageScanFilter> filters = CollectionHelper.createSetContaining(one,
two);
+
+        CompositePackageScanFilter filter = new CompositePackageScanFilter(filters);
+        validateFilter(filter, ScanTargetOne.class);
+        validateFilter(filter, ScanTargetTwo.class);
+
+        filter = new CompositePackageScanFilter();
+        filter.addFilter(one);
+        filter.addFilter(two);
+        validateFilter(filter, ScanTargetOne.class);
+        validateFilter(filter, ScanTargetTwo.class);
+    }
+
+    public void testInvertingFilter() {
+        InvertingPackageScanFilter filter = new InvertingPackageScanFilter(new AnnotatedWithPackageScanFilter(ScannableOne.class));
+        validateFilter(filter, ScanTargetThree.class);
+        assertEquals("![annotated with @ScannableOne]", filter.toString());
+    }
+
+    private void validateFilter(PackageScanFilter filter, Class<?> type) {
+        assertTrue(filter.matches(type));
+        assertFalse(new InvertingPackageScanFilter(filter).matches(type));
+    }
+
+}

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/PackageScanFiltersTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/PackageScanFiltersTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/PatternBasedPackageScanFilterTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/PatternBasedPackageScanFilterTest.java?rev=880657&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/PatternBasedPackageScanFilterTest.java
(added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/PatternBasedPackageScanFilterTest.java
Mon Nov 16 08:24:20 2009
@@ -0,0 +1,181 @@
+/**
+ * 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.camel.spring.scan;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.RandomAccessFile;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+import java.util.jar.JarFile;
+
+import org.apache.camel.spring.PatternBasedPackageScanFilter;
+import org.apache.camel.util.CollectionHelper;
+
+@SuppressWarnings("unchecked")
+public class PatternBasedPackageScanFilterTest extends org.apache.camel.spring.scan.ScanTestSupport
{
+
+    private Set<Class<?>> allClasses;
+
+    public void setUp() throws Exception {
+        // use classes that are pretty much constants
+        allClasses = new HashSet<Class<?>>();
+        allClasses.add(List.class);
+        allClasses.add(ArrayList.class);
+        allClasses.add(LinkedList.class);
+        allClasses.add(File.class);
+        allClasses.add(FileInputStream.class);
+        allClasses.add(RandomAccessFile.class);
+        // contains file pattern but in util pkg not io
+        allClasses.add(JarFile.class);
+        super.setUp();
+    }
+
+    public void testNoPattersIncludeAllClasses() {
+        validateMatchingSetContains(allClasses);
+    }
+
+    public void testIncludePatterns() {
+        addIncludePatterns("*");
+        validateMatchingSetContains(allClasses);
+
+        filter = new PatternBasedPackageScanFilter();
+        addIncludePatterns("java*");
+        validateMatchingSetContains(allClasses);
+
+        filter = new PatternBasedPackageScanFilter();
+        addIncludePatterns("java.io.*");
+        validateMatchingSetContains(File.class, FileInputStream.class, RandomAccessFile.class);
+
+        filter = new PatternBasedPackageScanFilter();
+        addIncludePatterns("java.util.**");
+        validateMatchingSetContains(List.class, ArrayList.class, LinkedList.class, JarFile.class);
+
+        filter = new PatternBasedPackageScanFilter();
+        addIncludePatterns("java.io.*", "java.util.*");
+        validateMatchingSetContains(allClasses);
+
+        filter = new PatternBasedPackageScanFilter();
+        addIncludePatterns("java.io.File");
+        validateMatchingSetContains(File.class);
+
+        filter = new PatternBasedPackageScanFilter();
+        addIncludePatterns("java.io.File*");
+        validateMatchingSetContains(File.class, FileInputStream.class);
+
+        filter = new PatternBasedPackageScanFilter();
+        addIncludePatterns("java.io.*File*");
+        validateMatchingSetContains(File.class, FileInputStream.class, RandomAccessFile.class);
+
+        filter = new PatternBasedPackageScanFilter();
+        addIncludePatterns("java.**.*File*");
+        validateMatchingSetContains(File.class, FileInputStream.class, RandomAccessFile.class,
JarFile.class);
+
+        filter = new PatternBasedPackageScanFilter();
+        addIncludePatterns("java.util.*List");
+        validateMatchingSetContains(List.class, ArrayList.class, LinkedList.class);
+
+        filter = new PatternBasedPackageScanFilter();
+        addIncludePatterns("java.lang", "java.lang.*");
+        validateMatchingSetContains();
+
+        filter = new PatternBasedPackageScanFilter();
+        addIncludePatterns("java.lang", "java.lang.*");
+        validateMatchingSetContains();
+    }
+
+    public void testExcludePatterns() {
+        addExcludePatterns("*");
+        validateMatchingSetContains();
+
+        filter = new PatternBasedPackageScanFilter();
+        addExcludePatterns("java*");
+        validateMatchingSetContains();
+
+        filter = new PatternBasedPackageScanFilter();
+        addExcludePatterns("java.io.*");
+        validateMatchingSetContains(List.class, ArrayList.class, LinkedList.class, JarFile.class);
+
+        filter = new PatternBasedPackageScanFilter();
+        addExcludePatterns("java.util.**");
+        validateMatchingSetContains(File.class, FileInputStream.class, RandomAccessFile.class);
+
+        filter = new PatternBasedPackageScanFilter();
+        addExcludePatterns("java.io.*", "java.util.*");
+        validateMatchingSetContains();
+
+        filter = new PatternBasedPackageScanFilter();
+        addExcludePatterns("java.io.File");
+        validateMatchingSetContains(List.class, ArrayList.class, LinkedList.class, JarFile.class,
FileInputStream.class, RandomAccessFile.class);
+
+        filter = new PatternBasedPackageScanFilter();
+        addExcludePatterns("java.io.File*");
+        validateMatchingSetContains(List.class, ArrayList.class, LinkedList.class, JarFile.class,
RandomAccessFile.class);
+
+        filter = new PatternBasedPackageScanFilter();
+        addExcludePatterns("java.io.*File*");
+        validateMatchingSetContains(List.class, ArrayList.class, LinkedList.class, JarFile.class);
+
+        filter = new PatternBasedPackageScanFilter();
+        addExcludePatterns("java.**.*File*");
+        validateMatchingSetContains(List.class, ArrayList.class, LinkedList.class);
+
+        filter = new PatternBasedPackageScanFilter();
+        addExcludePatterns("java.util.*List");
+        validateMatchingSetContains(File.class, FileInputStream.class, RandomAccessFile.class,
JarFile.class);
+
+        filter = new PatternBasedPackageScanFilter();
+        addExcludePatterns("java.lang", "java.lang.*");
+        validateMatchingSetContains(allClasses);
+
+        filter = new PatternBasedPackageScanFilter();
+        addExcludePatterns("java.lang", "java.lang.*");
+        validateMatchingSetContains(allClasses);
+    }
+
+    public void testExcludeHasPrecedenceOverInclude() {
+        // include any classes from the util pkg but exclude those in jar
+        addIncludePatterns("java.util.*");
+        addExcludePatterns("java.util.jar.*");
+        validateMatchingSetContains(List.class, ArrayList.class, LinkedList.class);
+    }
+    
+    public void testBulkIncludeAdd() {
+        // include any classes from the util pkg but exclude those in jar
+        Set<String> includes = CollectionHelper.createSetContaining("java.io.*", "java.util.*");
+        filter.addIncludePatterns(includes);
+        validateMatchingSetContains(allClasses);
+    }
+    
+    public void testBulkExcludeAdd() {
+        // include any classes from the util pkg but exclude those in jar
+        Set<String> excludes = CollectionHelper.createSetContaining("java.io.*", "java.util.*");
+        filter.addExcludePatterns(excludes);
+        validateMatchingSetContains();
+    }
+
+    protected void validateMatchingSetContains(Class<?>... matchingClasses) {
+        super.validateMatchingSetContains(allClasses, matchingClasses);
+    }
+
+    protected void validateMatchingSetContains(Set<Class<?>> matchingClasses)
{
+        super.validateMatchingSetContains(allClasses, matchingClasses);
+    }
+}

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/PatternBasedPackageScanFilterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/PatternBasedPackageScanFilterTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/ScanTestSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/ScanTestSupport.java?rev=880657&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/ScanTestSupport.java
(added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/ScanTestSupport.java
Mon Nov 16 08:24:20 2009
@@ -0,0 +1,74 @@
+/**
+ * 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.camel.spring.scan;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import junit.framework.TestCase;
+import org.apache.camel.spring.PatternBasedPackageScanFilter;
+
+@SuppressWarnings("unchecked")
+public abstract class ScanTestSupport extends TestCase {
+
+    protected PatternBasedPackageScanFilter filter;
+
+    public void setUp() throws Exception {
+        filter = new PatternBasedPackageScanFilter();
+    }
+
+    protected void validateMatchingSetContains(Set<Class<?>> scannedClasses,
Class<?>... matchingClasses) {
+        HashSet<Class<?>> expectedSet = new HashSet<Class<?>>();
+        for (Class expected : matchingClasses) {
+            expectedSet.add(expected);
+        }
+        validateMatchingSetContains(scannedClasses, expectedSet);
+    }
+
+    protected void validateMatchingSetContains(Set<Class<?>> scannedClasses,
Set<Class<?>> matchingClasses) {
+        Set<Class<?>> matching = getMatchingClasses(scannedClasses, filter);
+        assertEquals("Incorrect number of classes matched", matchingClasses.size(), matching.size());
+
+        for (Class<?> expected : matchingClasses) {
+            assertTrue("Expected matching class '" + expected + "' is not present", matching.contains(expected));
+        }
+    }
+
+    protected void addIncludePatterns(String... patterns) {
+        for (String pattern : patterns) {
+            filter.addIncludePattern(pattern);
+        }
+    }
+
+    protected void addExcludePatterns(String... patterns) {
+        for (String pattern : patterns) {
+            filter.addExcludePattern(pattern);
+        }
+    }
+
+    public Set<Class<?>> getMatchingClasses(Set<Class<?>> scannedClasses,
PatternBasedPackageScanFilter filter) {
+        Set<Class<?>> matching = new HashSet<Class<?>>();
+
+        for (Class candidate : scannedClasses) {
+            if (filter.matches(candidate)) {
+                matching.add(candidate);
+            }
+        }
+
+        return matching;
+    }
+}

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/ScanTestSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/ScanTestSupport.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/ScannableOne.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/ScannableOne.java?rev=880657&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/ScannableOne.java
(added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/ScannableOne.java
Mon Nov 16 08:24:20 2009
@@ -0,0 +1,25 @@
+/**
+ * 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.camel.spring.scan;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+@Retention(RetentionPolicy.RUNTIME)
+public @interface ScannableOne {
+
+}

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/ScannableOne.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/ScannableOne.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/ScannableTwo.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/ScannableTwo.java?rev=880657&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/ScannableTwo.java
(added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/ScannableTwo.java
Mon Nov 16 08:24:20 2009
@@ -0,0 +1,25 @@
+/**
+ * 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.camel.spring.scan;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+@Retention(RetentionPolicy.RUNTIME)
+public @interface ScannableTwo {
+
+}

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/ScannableTwo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/ScannableTwo.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/a/ScanTargetOne.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/a/ScanTargetOne.java?rev=880657&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/a/ScanTargetOne.java
(added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/a/ScanTargetOne.java
Mon Nov 16 08:24:20 2009
@@ -0,0 +1,25 @@
+/**
+ * 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.camel.spring.scan.a;
+
+@org.apache.camel.spring.scan.ScannableOne
+public class ScanTargetOne {
+
+    public void someMethod() {
+    }
+
+}

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/a/ScanTargetOne.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/a/ScanTargetOne.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/b/ScanTargetTwo.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/b/ScanTargetTwo.java?rev=880657&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/b/ScanTargetTwo.java
(added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/b/ScanTargetTwo.java
Mon Nov 16 08:24:20 2009
@@ -0,0 +1,29 @@
+/**
+ * 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.camel.spring.scan.b;
+
+import org.apache.camel.spring.scan.ScannableOne;
+import org.apache.camel.spring.scan.a.ScanTargetOne;
+
+@ScannableOne
+@SuppressWarnings("all")
+public class ScanTargetTwo extends ScanTargetOne {
+
+    public void someMethod() {
+    }
+
+}

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/b/ScanTargetTwo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/b/ScanTargetTwo.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/c/NotAScanTarget.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/c/NotAScanTarget.java?rev=880657&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/c/NotAScanTarget.java
(added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/c/NotAScanTarget.java
Mon Nov 16 08:24:20 2009
@@ -0,0 +1,24 @@
+/**
+ * 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.camel.spring.scan.c;
+
+public class NotAScanTarget {
+
+    public void someMethod() {
+    }
+
+}

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/c/NotAScanTarget.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/c/NotAScanTarget.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/c/ScanTargetThree.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/c/ScanTargetThree.java?rev=880657&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/c/ScanTargetThree.java
(added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/c/ScanTargetThree.java
Mon Nov 16 08:24:20 2009
@@ -0,0 +1,27 @@
+/**
+ * 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.camel.spring.scan.c;
+
+import org.apache.camel.spring.scan.ScannableTwo;
+
+@ScannableTwo()
+public class ScanTargetThree {
+
+    public void someMethod() {
+    }
+
+}

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/c/ScanTargetThree.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/scan/c/ScanTargetThree.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/components/camel-spring/src/test/resources/package+scan+test.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Propchange: camel/trunk/components/camel-spring/src/test/resources/package_scan_test.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



Mime
View raw message