geronimo-xbean-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r1393121 - in /geronimo/xbean/trunk/xbean-finder/src: main/java/org/apache/xbean/finder/archive/FileArchive.java test/java/org/apache/xbean/finder/archive/FileArchiveTest.java
Date Tue, 02 Oct 2012 19:24:35 GMT
Author: gnodet
Date: Tue Oct  2 19:24:34 2012
New Revision: 1393121

URL: http://svn.apache.org/viewvc?rev=1393121&view=rev
Log:
[XBEAN-207] FileArchive doesn't have a way to specify the base package

Modified:
    geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/FileArchive.java
    geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/FileArchiveTest.java

Modified: geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/FileArchive.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/FileArchive.java?rev=1393121&r1=1393120&r2=1393121&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/FileArchive.java
(original)
+++ geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/archive/FileArchive.java
Tue Oct  2 19:24:34 2012
@@ -32,16 +32,31 @@ import java.util.List;
 public class FileArchive implements Archive {
 
     private final ClassLoader loader;
+    private final String basePackage;
     private final File dir;
     private List<String> list;
 
     public FileArchive(ClassLoader loader, URL url) {
         this.loader = loader;
+        this.basePackage = "";
         this.dir = toFile(url);
     }
 
     public FileArchive(ClassLoader loader, File dir) {
         this.loader = loader;
+        this.basePackage = "";
+        this.dir = dir;
+    }
+
+    public FileArchive(ClassLoader loader, URL url, String basePackage) {
+        this.loader = loader;
+        this.basePackage = basePackage;
+        this.dir = toFile(url);
+    }
+
+    public FileArchive(ClassLoader loader, File dir, String basePackage) {
+        this.loader = loader;
+        this.basePackage = basePackage;
         this.dir = dir;
     }
 
@@ -87,7 +102,7 @@ public class FileArchive implements Arch
     private List<String> file(File dir) {
         List<String> classNames = new ArrayList<String>();
         if (dir.isDirectory()) {
-            scanDir(dir, classNames, "");
+            scanDir(dir, classNames, (basePackage.length() > 0) ? (basePackage + ".")
: basePackage);
         }
         return classNames;
     }

Modified: geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/FileArchiveTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/FileArchiveTest.java?rev=1393121&r1=1393120&r2=1393121&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/FileArchiveTest.java
(original)
+++ geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/archive/FileArchiveTest.java
Tue Oct  2 19:24:34 2012
@@ -19,6 +19,7 @@ package org.apache.xbean.finder.archive;
 import org.acme.foo.Blue;
 import org.acme.foo.Green;
 import org.acme.foo.Red;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -27,6 +28,8 @@ import java.io.File;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Iterator;
 import java.util.List;
 
 import static junit.framework.Assert.assertEquals;
@@ -57,6 +60,19 @@ public class FileArchiveTest {
         archive = new FileArchive(new URLClassLoader(urls), urls[0]);
     }
 
+    @Test
+    public void testBasePackageName() throws Exception {
+        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+        Enumeration<URL> resources = classLoader.getResources("org/acme/foo");
+        while (resources.hasMoreElements()) {
+            URL url = resources.nextElement();
+            FileArchive fileArchive = new FileArchive(classLoader, url, "org.acme.foo");
+            Iterator<Archive.Entry> iterator = fileArchive.iterator();
+            while ( iterator.hasNext() ) {
+                assertTrue(iterator.next().getName().startsWith("org.acme.foo"));
+            }
+        }
+    }
 
     @Test
     public void testGetBytecode() throws Exception {



Mime
View raw message