Renaming artifact and packages
authorpatriot1burke <patriot1burke@sourceforge.net>
Thu, 10 Jan 2008 21:04:35 +0000 (21:04 +0000)
committerKai Moritz <kai@juplo.de>
Tue, 12 May 2015 19:22:49 +0000 (21:22 +0200)
23 files changed:
pom.xml
src/main/java/org/scannotation/AnnotationDB.java
src/main/java/org/scannotation/ClasspathUrlFinder.java [new file with mode: 0644]
src/main/java/org/scannotation/WarUrlFinder.java [new file with mode: 0644]
src/main/java/org/scannotation/archiveiterator/DirectoryIteratorFactory.java [new file with mode: 0644]
src/main/java/org/scannotation/archiveiterator/FileIterator.java [new file with mode: 0644]
src/main/java/org/scannotation/archiveiterator/FileProtocolIteratorFactory.java [new file with mode: 0644]
src/main/java/org/scannotation/archiveiterator/Filter.java [new file with mode: 0644]
src/main/java/org/scannotation/archiveiterator/InputStreamWrapper.java [new file with mode: 0644]
src/main/java/org/scannotation/archiveiterator/IteratorFactory.java [new file with mode: 0644]
src/main/java/org/scannotation/archiveiterator/JarIterator.java [new file with mode: 0644]
src/main/java/org/scannotation/archiveiterator/StreamIterator.java [new file with mode: 0644]
src/main/java/org/scannotation/classpath/ClasspathUrlFinder.java [deleted file]
src/main/java/org/scannotation/classpath/DirectoryIteratorFactory.java [deleted file]
src/main/java/org/scannotation/classpath/FileIterator.java [deleted file]
src/main/java/org/scannotation/classpath/FileProtocolIteratorFactory.java [deleted file]
src/main/java/org/scannotation/classpath/Filter.java [deleted file]
src/main/java/org/scannotation/classpath/InputStreamWrapper.java [deleted file]
src/main/java/org/scannotation/classpath/IteratorFactory.java [deleted file]
src/main/java/org/scannotation/classpath/JarIterator.java [deleted file]
src/main/java/org/scannotation/classpath/StreamIterator.java [deleted file]
src/main/java/org/scannotation/classpath/WarUrlFinder.java [deleted file]
src/test/java/org/scannotation/test/TestSmoke.java

diff --git a/pom.xml b/pom.xml
index 353ce83..82486f4 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -2,10 +2,10 @@
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
     <modelVersion>4.0.0</modelVersion>
     <groupId>org.scannotation</groupId>
-    <artifactId>annotation-db</artifactId>
+    <artifactId>scannotation</artifactId>
     <packaging>jar</packaging>
     <version>1.0</version>
-    <name>resteasy-jsr311</name>
+    <name>scannotation</name>
     <url>http://maven.apache.org</url>
     <repositories>
         <repository>
             <scope>provided</scope>
         </dependency>
     </dependencies>
+  <reporting>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-javadoc-plugin</artifactId>
+      </plugin>
+    </plugins>
+  </reporting>
     <build>
         <plugins>
             <plugin>
index da19ea2..35f3a8d 100644 (file)
@@ -6,9 +6,9 @@ import javassist.bytecode.FieldInfo;
 import javassist.bytecode.MethodInfo;
 import javassist.bytecode.ParameterAnnotationsAttribute;
 import javassist.bytecode.annotation.Annotation;
-import org.scannotation.classpath.Filter;
-import org.scannotation.classpath.IteratorFactory;
-import org.scannotation.classpath.StreamIterator;
+import org.scannotation.archiveiterator.Filter;
+import org.scannotation.archiveiterator.IteratorFactory;
+import org.scannotation.archiveiterator.StreamIterator;
 
 import java.io.BufferedInputStream;
 import java.io.DataInputStream;
diff --git a/src/main/java/org/scannotation/ClasspathUrlFinder.java b/src/main/java/org/scannotation/ClasspathUrlFinder.java
new file mode 100644 (file)
index 0000000..122dfd0
--- /dev/null
@@ -0,0 +1,190 @@
+package org.scannotation;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.StringTokenizer;
+
+/**
+ * Various functions to locate URLs to scan
+ *
+ * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
+ * @version $Revision: 1 $
+ */
+public class ClasspathUrlFinder
+{
+
+   /**
+    * Find the classpath URLs for a specific classpath resource.  The classpath URL is extracted
+    * from loader.getResources() using the baseResource.
+    *
+    * @param baseResource
+    * @return
+    */
+   public static URL[] findResourceBases(String baseResource, ClassLoader loader)
+   {
+      ArrayList<URL> list = new ArrayList<URL>();
+      try
+      {
+         Enumeration<URL> urls = loader.getResources(baseResource);
+         while (urls.hasMoreElements())
+         {
+            URL url = urls.nextElement();
+            list.add(findResourceBase(url, baseResource));
+         }
+      }
+      catch (IOException e)
+      {
+         throw new RuntimeException(e);
+      }
+      return list.toArray(new URL[list.size()]);
+   }
+
+   /**
+    * Find the classpath URLs for a specific classpath resource.  The classpath URL is extracted
+    * from loader.getResources() using the baseResource.
+    *
+    * @param baseResource
+    * @return
+    */
+   public static URL[] findResourceBases(String baseResource)
+   {
+      return findResourceBases(baseResource, Thread.currentThread().getContextClassLoader());
+   }
+
+   private static URL findResourceBase(URL url, String baseResource)
+   {
+      String urlString = url.toString();
+      int idx = urlString.lastIndexOf(baseResource);
+      urlString = urlString.substring(0, idx);
+      URL deployUrl = null;
+      try
+      {
+         deployUrl = new URL(urlString);
+      }
+      catch (MalformedURLException e)
+      {
+         throw new RuntimeException(e);
+      }
+      return deployUrl;
+   }
+
+   /**
+    * Find the classpath URL for a specific classpath resource.  The classpath URL is extracted
+    * from Thread.currentThread().getContextClassLoader().getResource() using the baseResource.
+    *
+    * @param baseResource
+    * @return
+    */
+   public static URL findResourceBase(String baseResource)
+   {
+      return findResourceBase(baseResource, Thread.currentThread().getContextClassLoader());
+   }
+
+   /**
+    * Find the classpath URL for a specific classpath resource.  The classpath URL is extracted
+    * from loader.getResource() using the baseResource.
+    *
+    * @param baseResource
+    * @param loader
+    * @return
+    */
+   public static URL findResourceBase(String baseResource, ClassLoader loader)
+   {
+      URL url = loader.getResource(baseResource);
+      return findResourceBase(url, baseResource);
+   }
+
+   /**
+    * Find the classpath for the particular class
+    *
+    * @param clazz
+    * @return
+    */
+   public static URL findClassBase(Class clazz)
+   {
+      String resource = clazz.getName().replace('.', '/') + ".class";
+      return findResourceBase(resource, clazz.getClassLoader());
+   }
+
+   /**
+    * Uses the java.class.path system property to obtain a list of URLs that represent the CLASSPATH
+    *
+    * @return
+    */
+   public static URL[] findClassPaths()
+   {
+      List<URL> list = new ArrayList<URL>();
+      String classpath = System.getProperty("java.class.path");
+      StringTokenizer tokenizer = new StringTokenizer(classpath, File.pathSeparator);
+
+      while (tokenizer.hasMoreTokens())
+      {
+         String path = tokenizer.nextToken();
+         File fp = new File(path);
+         if (!fp.exists()) throw new RuntimeException("File in java.class.path does not exist: " + fp);
+         try
+         {
+            list.add(fp.toURL());
+         }
+         catch (MalformedURLException e)
+         {
+            throw new RuntimeException(e);
+         }
+      }
+      return list.toArray(new URL[list.size()]);
+   }
+
+   /**
+    * Uses the java.class.path system property to obtain a list of URLs that represent the CLASSPATH
+    * <p/>
+    * paths is used as a filter to only include paths that have the specific relative file within it
+    *
+    * @param paths comma list of files that should exist in a particular path
+    * @return
+    */
+   public static URL[] findClassPaths(String... paths)
+   {
+      ArrayList<URL> list = new ArrayList<URL>();
+
+      String classpath = System.getProperty("java.class.path");
+      StringTokenizer tokenizer = new StringTokenizer(classpath, File.pathSeparator);
+      for (int i = 0; i < paths.length; i++)
+      {
+         paths[i] = paths[i].trim();
+      }
+
+      while (tokenizer.hasMoreTokens())
+      {
+         String path = tokenizer.nextToken().trim();
+         boolean found = false;
+         for (String wantedPath : paths)
+         {
+            if (path.endsWith(File.separator + wantedPath))
+            {
+               found = true;
+               break;
+            }
+         }
+         if (!found) continue;
+         File fp = new File(path);
+         if (!fp.exists()) throw new RuntimeException("File in java.class.path does not exists: " + fp);
+         try
+         {
+            list.add(fp.toURL());
+         }
+         catch (MalformedURLException e)
+         {
+            throw new RuntimeException(e);
+         }
+      }
+      return list.toArray(new URL[list.size()]);
+   }
+
+
+}
+
diff --git a/src/main/java/org/scannotation/WarUrlFinder.java b/src/main/java/org/scannotation/WarUrlFinder.java
new file mode 100644 (file)
index 0000000..f253764
--- /dev/null
@@ -0,0 +1,74 @@
+package org.scannotation;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
+ * @version $Revision: 1 $
+ */
+public class WarUrlFinder
+{
+   public static URL[] findWebInfLibClasspaths(ServletContextEvent servletContextEvent)
+   {
+      ServletContext servletContext = servletContextEvent.getServletContext();
+      return findWebInfLibClasspaths(servletContext);
+   }
+
+   public static URL[] findWebInfLibClasspaths(ServletContext servletContext)
+   {
+      ArrayList<URL> list = new ArrayList<URL>();
+      Set libJars = servletContext.getResourcePaths("/WEB-INF/lib");
+      for (Object jar : libJars)
+      {
+         try
+         {
+            list.add(servletContext.getResource((String) jar));
+         }
+         catch (MalformedURLException e)
+         {
+            throw new RuntimeException(e);
+         }
+      }
+      return list.toArray(new URL[list.size()]);
+   }
+
+   public static URL findWebInfClassesPath(ServletContextEvent servletContextEvent)
+   {
+      ServletContext servletContext = servletContextEvent.getServletContext();
+      return findWebInfClassesPath(servletContext);
+   }
+
+   /**
+    * Find the URL pointing to "/WEB-INF/classes"  This method may not work in conjunction with IteratorFactory
+    * if your servlet container does not extract the /WEB-INF/classes into a real file-based directory
+    *
+    * @param servletContext
+    * @return
+    */
+   public static URL findWebInfClassesPath(ServletContext servletContext)
+   {
+      Set libJars = servletContext.getResourcePaths("/WEB-INF/classes");
+      for (Object jar : libJars)
+      {
+         try
+         {
+            URL url = servletContext.getResource((String) jar);
+            String urlString = url.toString();
+            int index = urlString.lastIndexOf("/WEB-INF/classes/");
+            urlString = urlString.substring(0, index + "/WEB-INF/classes/".length());
+            return new URL(urlString);
+         }
+         catch (MalformedURLException e)
+         {
+            throw new RuntimeException(e);
+         }
+      }
+      return null;
+
+   }
+}
diff --git a/src/main/java/org/scannotation/archiveiterator/DirectoryIteratorFactory.java b/src/main/java/org/scannotation/archiveiterator/DirectoryIteratorFactory.java
new file mode 100644 (file)
index 0000000..699074d
--- /dev/null
@@ -0,0 +1,13 @@
+package org.scannotation.archiveiterator;
+
+import java.io.IOException;
+import java.net.URL;
+
+/**
+ * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
+ * @version $Revision: 1 $
+ */
+public interface DirectoryIteratorFactory
+{
+   StreamIterator create(URL url, Filter filter) throws IOException;
+}
diff --git a/src/main/java/org/scannotation/archiveiterator/FileIterator.java b/src/main/java/org/scannotation/archiveiterator/FileIterator.java
new file mode 100644 (file)
index 0000000..aa3593b
--- /dev/null
@@ -0,0 +1,68 @@
+package org.scannotation.archiveiterator;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
+ * @version $Revision: 1 $
+ */
+public class FileIterator implements StreamIterator
+{
+   private ArrayList files;
+   private int index = 0;
+
+   public FileIterator(File file, Filter filter)
+   {
+      files = new ArrayList();
+      try
+      {
+         create(files, file, filter);
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+
+   protected static void create(List list, File dir, Filter filter) throws Exception
+   {
+      File[] files = dir.listFiles();
+      for (int i = 0; i < files.length; i++)
+      {
+         if (files[i].isDirectory())
+         {
+            create(list, files[i], filter);
+         }
+         else
+         {
+            if (filter == null || filter.accepts(files[i].getAbsolutePath()))
+            {
+               list.add(files[i]);
+            }
+         }
+      }
+   }
+
+   public InputStream next()
+   {
+      if (index >= files.size()) return null;
+      File fp = (File) files.get(index++);
+      try
+      {
+         return new FileInputStream(fp);
+      }
+      catch (FileNotFoundException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+
+   public void close()
+   {
+   }
+}
diff --git a/src/main/java/org/scannotation/archiveiterator/FileProtocolIteratorFactory.java b/src/main/java/org/scannotation/archiveiterator/FileProtocolIteratorFactory.java
new file mode 100644 (file)
index 0000000..a8c0a40
--- /dev/null
@@ -0,0 +1,26 @@
+package org.scannotation.archiveiterator;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+
+/**
+ * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
+ * @version $Revision: 1 $
+ */
+public class FileProtocolIteratorFactory implements DirectoryIteratorFactory
+{
+
+   public StreamIterator create(URL url, Filter filter) throws IOException
+   {
+      File f = new File(url.getPath());
+      if (f.isDirectory())
+      {
+         return new FileIterator(f, filter);
+      }
+      else
+      {
+         return new JarIterator(url.openStream(), filter);
+      }
+   }
+}
diff --git a/src/main/java/org/scannotation/archiveiterator/Filter.java b/src/main/java/org/scannotation/archiveiterator/Filter.java
new file mode 100644 (file)
index 0000000..b1eecfb
--- /dev/null
@@ -0,0 +1,10 @@
+package org.scannotation.archiveiterator;
+
+/**
+ * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
+ * @version $Revision: 1 $
+ */
+public interface Filter
+{
+   boolean accepts(String filename);
+}
diff --git a/src/main/java/org/scannotation/archiveiterator/InputStreamWrapper.java b/src/main/java/org/scannotation/archiveiterator/InputStreamWrapper.java
new file mode 100644 (file)
index 0000000..5adb77d
--- /dev/null
@@ -0,0 +1,72 @@
+package org.scannotation.archiveiterator;
+
+import java.io.InputStream;
+import java.io.IOException;
+
+/**
+ * Delegate to everything but close().  This object will not close the stream
+ *
+ * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
+ * @version $Revision: 1 $
+ */
+public class InputStreamWrapper extends InputStream
+{
+   private InputStream delegate;
+
+   public InputStreamWrapper(InputStream delegate)
+   {
+      this.delegate = delegate;
+   }
+
+   public int read()
+           throws IOException
+   {
+      return delegate.read();
+   }
+
+   public int read(byte[] bytes)
+           throws IOException
+   {
+      return delegate.read(bytes);
+   }
+
+   public int read(byte[] bytes, int i, int i1)
+           throws IOException
+   {
+      return delegate.read(bytes, i, i1);
+   }
+
+   public long skip(long l)
+           throws IOException
+   {
+      return delegate.skip(l);
+   }
+
+   public int available()
+           throws IOException
+   {
+      return delegate.available();
+   }
+
+   public void close()
+           throws IOException
+   {
+      // ignored
+   }
+
+   public void mark(int i)
+   {
+      delegate.mark(i);
+   }
+
+   public void reset()
+           throws IOException
+   {
+      delegate.reset();
+   }
+
+   public boolean markSupported()
+   {
+      return delegate.markSupported();
+   }
+}
diff --git a/src/main/java/org/scannotation/archiveiterator/IteratorFactory.java b/src/main/java/org/scannotation/archiveiterator/IteratorFactory.java
new file mode 100644 (file)
index 0000000..5006ea7
--- /dev/null
@@ -0,0 +1,43 @@
+package org.scannotation.archiveiterator;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
+ * @version $Revision: 1 $
+ */
+public class IteratorFactory
+{
+   private static final ConcurrentHashMap<String, DirectoryIteratorFactory> registry = new ConcurrentHashMap<String, DirectoryIteratorFactory>();
+
+   static
+   {
+      registry.put("file", new FileProtocolIteratorFactory());
+   }
+
+
+   public static StreamIterator create(URL url, Filter filter) throws IOException
+   {
+      String urlString = url.toString();
+      if (urlString.endsWith("!/"))
+      {
+         urlString = urlString.substring(4);
+         urlString = urlString.substring(0, urlString.length() - 2);
+         url = new URL(urlString);
+      }
+
+
+      if (!urlString.endsWith("/"))
+      {
+         return new JarIterator(url.openStream(), filter);
+      }
+      else
+      {
+         DirectoryIteratorFactory factory = registry.get(url.getProtocol());
+         if (factory == null) throw new IOException("Unable to scan directory of protocol: " + url.getProtocol());
+         return factory.create(url, filter);
+      }
+   }
+}
diff --git a/src/main/java/org/scannotation/archiveiterator/JarIterator.java b/src/main/java/org/scannotation/archiveiterator/JarIterator.java
new file mode 100644 (file)
index 0000000..67291a6
--- /dev/null
@@ -0,0 +1,77 @@
+package org.scannotation.archiveiterator;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.jar.JarEntry;
+import java.util.jar.JarInputStream;
+
+/**
+ * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
+ * @version $Revision: 1 $
+ */
+public class JarIterator implements StreamIterator
+{
+   JarInputStream jar;
+   JarEntry next;
+   Filter filter;
+   boolean initial = true;
+   boolean closed = false;
+
+   public JarIterator(File file, Filter filter) throws IOException
+   {
+      this(new FileInputStream(file), filter);
+   }
+
+
+   public JarIterator(InputStream is, Filter filter) throws IOException
+   {
+      this.filter = filter;
+      jar = new JarInputStream(is);
+   }
+
+   private void setNext()
+   {
+      initial = true;
+      try
+      {
+         if (next != null) jar.closeEntry();
+         next = null;
+         do
+         {
+            next = jar.getNextJarEntry();
+         } while (next != null && (next.isDirectory() || (filter == null || !filter.accepts(next.getName()))));
+         if (next == null)
+         {
+            close();
+         }
+      }
+      catch (IOException e)
+      {
+         throw new RuntimeException("failed to browse jar", e);
+      }
+   }
+
+   public InputStream next()
+   {
+      if (closed || (next == null && !initial)) return null;
+      setNext();
+      if (next == null) return null;
+      return new InputStreamWrapper(jar);
+   }
+
+   public void close()
+   {
+      try
+      {
+         closed = true;
+         jar.close();
+      }
+      catch (IOException ignored)
+      {
+
+      }
+
+   }
+}
diff --git a/src/main/java/org/scannotation/archiveiterator/StreamIterator.java b/src/main/java/org/scannotation/archiveiterator/StreamIterator.java
new file mode 100644 (file)
index 0000000..9d4e4f1
--- /dev/null
@@ -0,0 +1,25 @@
+package org.scannotation.archiveiterator;
+
+import java.io.InputStream;
+
+/**
+ * Simpler iterator than java.util.iterator.  Things like JarInputStream does not allow you to implement hasNext()
+ *
+ * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
+ * @version $Revision: 1 $
+ */
+public interface StreamIterator
+{
+   /**
+    * User is resposible for closing the InputStream returned
+    *
+    * @return null if no more streams left to iterate on
+    */
+   InputStream next();
+
+   /**
+    * Cleanup any open resources of the iterator
+    *
+    */
+   void close();
+}
diff --git a/src/main/java/org/scannotation/classpath/ClasspathUrlFinder.java b/src/main/java/org/scannotation/classpath/ClasspathUrlFinder.java
deleted file mode 100644 (file)
index f56be22..0000000
+++ /dev/null
@@ -1,190 +0,0 @@
-package org.scannotation.classpath;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.StringTokenizer;
-
-/**
- * Various functions to locate URLs to scan
- *
- * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
- * @version $Revision: 1 $
- */
-public class ClasspathUrlFinder
-{
-
-   /**
-    * Find the classpath URLs for a specific classpath resource.  The classpath URL is extracted
-    * from loader.getResources() using the baseResource.
-    *
-    * @param baseResource
-    * @return
-    */
-   public static URL[] findResourceBases(String baseResource, ClassLoader loader)
-   {
-      ArrayList<URL> list = new ArrayList<URL>();
-      try
-      {
-         Enumeration<URL> urls = loader.getResources(baseResource);
-         while (urls.hasMoreElements())
-         {
-            URL url = urls.nextElement();
-            list.add(findResourceBase(url, baseResource));
-         }
-      }
-      catch (IOException e)
-      {
-         throw new RuntimeException(e);
-      }
-      return list.toArray(new URL[list.size()]);
-   }
-
-   /**
-    * Find the classpath URLs for a specific classpath resource.  The classpath URL is extracted
-    * from loader.getResources() using the baseResource.
-    *
-    * @param baseResource
-    * @return
-    */
-   public static URL[] findResourceBases(String baseResource)
-   {
-      return findResourceBases(baseResource, Thread.currentThread().getContextClassLoader());
-   }
-
-   private static URL findResourceBase(URL url, String baseResource)
-   {
-      String urlString = url.toString();
-      int idx = urlString.lastIndexOf(baseResource);
-      urlString = urlString.substring(0, idx);
-      URL deployUrl = null;
-      try
-      {
-         deployUrl = new URL(urlString);
-      }
-      catch (MalformedURLException e)
-      {
-         throw new RuntimeException(e);
-      }
-      return deployUrl;
-   }
-
-   /**
-    * Find the classpath URL for a specific classpath resource.  The classpath URL is extracted
-    * from Thread.currentThread().getContextClassLoader().getResource() using the baseResource.
-    *
-    * @param baseResource
-    * @return
-    */
-   public static URL findResourceBase(String baseResource)
-   {
-      return findResourceBase(baseResource, Thread.currentThread().getContextClassLoader());
-   }
-
-   /**
-    * Find the classpath URL for a specific classpath resource.  The classpath URL is extracted
-    * from loader.getResource() using the baseResource.
-    *
-    * @param baseResource
-    * @param loader
-    * @return
-    */
-   public static URL findResourceBase(String baseResource, ClassLoader loader)
-   {
-      URL url = loader.getResource(baseResource);
-      return findResourceBase(url, baseResource);
-   }
-
-   /**
-    * Find the classpath for the particular class
-    *
-    * @param clazz
-    * @return
-    */
-   public static URL findClassBase(Class clazz)
-   {
-      String resource = clazz.getName().replace('.', '/') + ".class";
-      return findResourceBase(resource, clazz.getClassLoader());
-   }
-
-   /**
-    * Uses the java.class.path system property to obtain a list of URLs that represent the CLASSPATH
-    *
-    * @return
-    */
-   public static URL[] findClassPaths()
-   {
-      List<URL> list = new ArrayList<URL>();
-      String classpath = System.getProperty("java.class.path");
-      StringTokenizer tokenizer = new StringTokenizer(classpath, File.pathSeparator);
-
-      while (tokenizer.hasMoreTokens())
-      {
-         String path = tokenizer.nextToken();
-         File fp = new File(path);
-         if (!fp.exists()) throw new RuntimeException("File in java.class.path does not exist: " + fp);
-         try
-         {
-            list.add(fp.toURL());
-         }
-         catch (MalformedURLException e)
-         {
-            throw new RuntimeException(e);
-         }
-      }
-      return list.toArray(new URL[list.size()]);
-   }
-
-   /**
-    * Uses the java.class.path system property to obtain a list of URLs that represent the CLASSPATH
-    * <p/>
-    * paths is used as a filter to only include paths that have the specific relative file within it
-    *
-    * @param paths comma list of files that should exist in a particular path
-    * @return
-    */
-   public static URL[] findClassPaths(String... paths)
-   {
-      ArrayList<URL> list = new ArrayList<URL>();
-
-      String classpath = System.getProperty("java.class.path");
-      StringTokenizer tokenizer = new StringTokenizer(classpath, File.pathSeparator);
-      for (int i = 0; i < paths.length; i++)
-      {
-         paths[i] = paths[i].trim();
-      }
-
-      while (tokenizer.hasMoreTokens())
-      {
-         String path = tokenizer.nextToken().trim();
-         boolean found = false;
-         for (String wantedPath : paths)
-         {
-            if (path.endsWith(File.separator + wantedPath))
-            {
-               found = true;
-               break;
-            }
-         }
-         if (!found) continue;
-         File fp = new File(path);
-         if (!fp.exists()) throw new RuntimeException("File in java.class.path does not exists: " + fp);
-         try
-         {
-            list.add(fp.toURL());
-         }
-         catch (MalformedURLException e)
-         {
-            throw new RuntimeException(e);
-         }
-      }
-      return list.toArray(new URL[list.size()]);
-   }
-
-
-}
-
diff --git a/src/main/java/org/scannotation/classpath/DirectoryIteratorFactory.java b/src/main/java/org/scannotation/classpath/DirectoryIteratorFactory.java
deleted file mode 100644 (file)
index 7239d1b..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-package org.scannotation.classpath;
-
-import java.io.IOException;
-import java.net.URL;
-
-/**
- * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
- * @version $Revision: 1 $
- */
-public interface DirectoryIteratorFactory
-{
-   StreamIterator create(URL url, Filter filter) throws IOException;
-}
diff --git a/src/main/java/org/scannotation/classpath/FileIterator.java b/src/main/java/org/scannotation/classpath/FileIterator.java
deleted file mode 100644 (file)
index b69709c..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-package org.scannotation.classpath;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
- * @version $Revision: 1 $
- */
-public class FileIterator implements StreamIterator
-{
-   private ArrayList files;
-   private int index = 0;
-
-   public FileIterator(File file, Filter filter)
-   {
-      files = new ArrayList();
-      try
-      {
-         create(files, file, filter);
-      }
-      catch (Exception e)
-      {
-         throw new RuntimeException(e);
-      }
-   }
-
-   protected static void create(List list, File dir, Filter filter) throws Exception
-   {
-      File[] files = dir.listFiles();
-      for (int i = 0; i < files.length; i++)
-      {
-         if (files[i].isDirectory())
-         {
-            create(list, files[i], filter);
-         }
-         else
-         {
-            if (filter == null || filter.accepts(files[i].getAbsolutePath()))
-            {
-               list.add(files[i]);
-            }
-         }
-      }
-   }
-
-   public InputStream next()
-   {
-      if (index >= files.size()) return null;
-      File fp = (File) files.get(index++);
-      try
-      {
-         return new FileInputStream(fp);
-      }
-      catch (FileNotFoundException e)
-      {
-         throw new RuntimeException(e);
-      }
-   }
-
-   public void close()
-   {
-   }
-}
diff --git a/src/main/java/org/scannotation/classpath/FileProtocolIteratorFactory.java b/src/main/java/org/scannotation/classpath/FileProtocolIteratorFactory.java
deleted file mode 100644 (file)
index 5d3b44c..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-package org.scannotation.classpath;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URL;
-
-/**
- * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
- * @version $Revision: 1 $
- */
-public class FileProtocolIteratorFactory implements DirectoryIteratorFactory
-{
-
-   public StreamIterator create(URL url, Filter filter) throws IOException
-   {
-      File f = new File(url.getPath());
-      if (f.isDirectory())
-      {
-         return new FileIterator(f, filter);
-      }
-      else
-      {
-         return new JarIterator(url.openStream(), filter);
-      }
-   }
-}
diff --git a/src/main/java/org/scannotation/classpath/Filter.java b/src/main/java/org/scannotation/classpath/Filter.java
deleted file mode 100644 (file)
index 208b313..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-package org.scannotation.classpath;
-
-/**
- * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
- * @version $Revision: 1 $
- */
-public interface Filter
-{
-   boolean accepts(String filename);
-}
diff --git a/src/main/java/org/scannotation/classpath/InputStreamWrapper.java b/src/main/java/org/scannotation/classpath/InputStreamWrapper.java
deleted file mode 100644 (file)
index c19d0e7..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-package org.scannotation.classpath;
-
-import java.io.InputStream;
-import java.io.IOException;
-
-/**
- * Delegate to everything but close().  This object will not close the stream
- *
- * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
- * @version $Revision: 1 $
- */
-public class InputStreamWrapper extends InputStream
-{
-   private InputStream delegate;
-
-   public InputStreamWrapper(InputStream delegate)
-   {
-      this.delegate = delegate;
-   }
-
-   public int read()
-           throws IOException
-   {
-      return delegate.read();
-   }
-
-   public int read(byte[] bytes)
-           throws IOException
-   {
-      return delegate.read(bytes);
-   }
-
-   public int read(byte[] bytes, int i, int i1)
-           throws IOException
-   {
-      return delegate.read(bytes, i, i1);
-   }
-
-   public long skip(long l)
-           throws IOException
-   {
-      return delegate.skip(l);
-   }
-
-   public int available()
-           throws IOException
-   {
-      return delegate.available();
-   }
-
-   public void close()
-           throws IOException
-   {
-      // ignored
-   }
-
-   public void mark(int i)
-   {
-      delegate.mark(i);
-   }
-
-   public void reset()
-           throws IOException
-   {
-      delegate.reset();
-   }
-
-   public boolean markSupported()
-   {
-      return delegate.markSupported();
-   }
-}
diff --git a/src/main/java/org/scannotation/classpath/IteratorFactory.java b/src/main/java/org/scannotation/classpath/IteratorFactory.java
deleted file mode 100644 (file)
index adbc091..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-package org.scannotation.classpath;
-
-import java.io.IOException;
-import java.net.URL;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
- * @version $Revision: 1 $
- */
-public class IteratorFactory
-{
-   private static final ConcurrentHashMap<String, DirectoryIteratorFactory> registry = new ConcurrentHashMap<String, DirectoryIteratorFactory>();
-
-   static
-   {
-      registry.put("file", new FileProtocolIteratorFactory());
-   }
-
-
-   public static StreamIterator create(URL url, Filter filter) throws IOException
-   {
-      String urlString = url.toString();
-      if (urlString.endsWith("!/"))
-      {
-         urlString = urlString.substring(4);
-         urlString = urlString.substring(0, urlString.length() - 2);
-         url = new URL(urlString);
-      }
-
-
-      if (!urlString.endsWith("/"))
-      {
-         return new JarIterator(url.openStream(), filter);
-      }
-      else
-      {
-         DirectoryIteratorFactory factory = registry.get(url.getProtocol());
-         if (factory == null) throw new IOException("Unable to scan directory of protocol: " + url.getProtocol());
-         return factory.create(url, filter);
-      }
-   }
-}
diff --git a/src/main/java/org/scannotation/classpath/JarIterator.java b/src/main/java/org/scannotation/classpath/JarIterator.java
deleted file mode 100644 (file)
index dd4cf35..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-package org.scannotation.classpath;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.jar.JarEntry;
-import java.util.jar.JarInputStream;
-
-/**
- * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
- * @version $Revision: 1 $
- */
-public class JarIterator implements StreamIterator
-{
-   JarInputStream jar;
-   JarEntry next;
-   Filter filter;
-   boolean initial = true;
-   boolean closed = false;
-
-   public JarIterator(File file, Filter filter) throws IOException
-   {
-      this(new FileInputStream(file), filter);
-   }
-
-
-   public JarIterator(InputStream is, Filter filter) throws IOException
-   {
-      this.filter = filter;
-      jar = new JarInputStream(is);
-   }
-
-   private void setNext()
-   {
-      initial = true;
-      try
-      {
-         if (next != null) jar.closeEntry();
-         next = null;
-         do
-         {
-            next = jar.getNextJarEntry();
-         } while (next != null && (next.isDirectory() || (filter == null || !filter.accepts(next.getName()))));
-         if (next == null)
-         {
-            close();
-         }
-      }
-      catch (IOException e)
-      {
-         throw new RuntimeException("failed to browse jar", e);
-      }
-   }
-
-   public InputStream next()
-   {
-      if (closed || (next == null && !initial)) return null;
-      setNext();
-      if (next == null) return null;
-      return new InputStreamWrapper(jar);
-   }
-
-   public void close()
-   {
-      try
-      {
-         closed = true;
-         jar.close();
-      }
-      catch (IOException ignored)
-      {
-
-      }
-
-   }
-}
diff --git a/src/main/java/org/scannotation/classpath/StreamIterator.java b/src/main/java/org/scannotation/classpath/StreamIterator.java
deleted file mode 100644 (file)
index 410df8f..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-package org.scannotation.classpath;
-
-import java.io.InputStream;
-
-/**
- * Simpler iterator than java.util.iterator.  Things like JarInputStream does not allow you to implement hasNext()
- *
- * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
- * @version $Revision: 1 $
- */
-public interface StreamIterator
-{
-   /**
-    * User is resposible for closing the InputStream returned
-    *
-    * @return null if no more streams left to iterate on
-    */
-   InputStream next();
-
-   /**
-    * Cleanup any open resources of the iterator
-    *
-    */
-   void close();
-}
diff --git a/src/main/java/org/scannotation/classpath/WarUrlFinder.java b/src/main/java/org/scannotation/classpath/WarUrlFinder.java
deleted file mode 100644 (file)
index 73d3372..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-package org.scannotation.classpath;
-
-import javax.servlet.ServletContext;
-import javax.servlet.ServletContextEvent;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Set;
-
-/**
- * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
- * @version $Revision: 1 $
- */
-public class WarUrlFinder
-{
-   public static URL[] findWebInfLibClasspaths(ServletContextEvent servletContextEvent)
-   {
-      ServletContext servletContext = servletContextEvent.getServletContext();
-      return findWebInfLibClasspaths(servletContext);
-   }
-
-   public static URL[] findWebInfLibClasspaths(ServletContext servletContext)
-   {
-      ArrayList<URL> list = new ArrayList<URL>();
-      Set libJars = servletContext.getResourcePaths("/WEB-INF/lib");
-      for (Object jar : libJars)
-      {
-         try
-         {
-            list.add(servletContext.getResource((String) jar));
-         }
-         catch (MalformedURLException e)
-         {
-            throw new RuntimeException(e);
-         }
-      }
-      return list.toArray(new URL[list.size()]);
-   }
-
-   public static URL findWebInfClassesPath(ServletContextEvent servletContextEvent)
-   {
-      ServletContext servletContext = servletContextEvent.getServletContext();
-      return findWebInfClassesPath(servletContext);
-   }
-
-   /**
-    * Find the URL pointing to "/WEB-INF/classes"  This method may not work in conjunction with IteratorFactory
-    * if your servlet container does not extract the /WEB-INF/classes into a real file-based directory
-    *
-    * @param servletContext
-    * @return
-    */
-   public static URL findWebInfClassesPath(ServletContext servletContext)
-   {
-      Set libJars = servletContext.getResourcePaths("/WEB-INF/classes");
-      for (Object jar : libJars)
-      {
-         try
-         {
-            URL url = servletContext.getResource((String) jar);
-            String urlString = url.toString();
-            int index = urlString.lastIndexOf("/WEB-INF/classes/");
-            urlString = urlString.substring(0, index + "/WEB-INF/classes/".length());
-            return new URL(urlString);
-         }
-         catch (MalformedURLException e)
-         {
-            throw new RuntimeException(e);
-         }
-      }
-      return null;
-
-   }
-}
index 8f914aa..8a9331d 100644 (file)
@@ -4,7 +4,7 @@ import com.titan.domain.Address;
 import org.junit.Assert;
 import org.junit.Test;
 import org.scannotation.AnnotationDB;
-import org.scannotation.classpath.ClasspathUrlFinder;
+import org.scannotation.ClasspathUrlFinder;
 
 import java.io.IOException;
 import java.net.URL;
@@ -41,6 +41,7 @@ public class TestSmoke
       if (System.getProperty("java.class.path").indexOf("titan-cruise-1.0.jar") == -1)
       {
          System.err.println("WARNING!!!!!!!! CANNOT TEST testFindClasspaths():  This is a Maven2 and Surefire problem in that it doesn't set java.class.path correctly.  I run this test within the IDE");
+         return;
       }
 
       URL[] urls = ClasspathUrlFinder.findClassPaths("titan-cruise-1.0.jar");
@@ -56,6 +57,7 @@ public class TestSmoke
       if (System.getProperty("java.class.path").indexOf("titan-cruise-1.0.jar") == -1)
       {
          System.err.println("WARNING!!!!!!! CANNOT TEST testFindClasspaths2():  This is a Maven2 and Surefire problem in that it doesn't set java.class.path correctly.  I run this test within the IDE");
+         return;
       }
 
       URL[] urls = ClasspathUrlFinder.findClassPaths();