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>
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;
--- /dev/null
+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()]);
+ }
+
+
+}
+
--- /dev/null
+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;
+
+ }
+}
--- /dev/null
+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;
+}
--- /dev/null
+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()
+ {
+ }
+}
--- /dev/null
+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);
+ }
+ }
+}
--- /dev/null
+package org.scannotation.archiveiterator;
+
+/**
+ * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
+ * @version $Revision: 1 $
+ */
+public interface Filter
+{
+ boolean accepts(String filename);
+}
--- /dev/null
+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();
+ }
+}
--- /dev/null
+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);
+ }
+ }
+}
--- /dev/null
+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)
+ {
+
+ }
+
+ }
+}
--- /dev/null
+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();
+}
+++ /dev/null
-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()]);
- }
-
-
-}
-
+++ /dev/null
-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;
-}
+++ /dev/null
-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()
- {
- }
-}
+++ /dev/null
-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);
- }
- }
-}
+++ /dev/null
-package org.scannotation.classpath;
-
-/**
- * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
- * @version $Revision: 1 $
- */
-public interface Filter
-{
- boolean accepts(String filename);
-}
+++ /dev/null
-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();
- }
-}
+++ /dev/null
-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);
- }
- }
-}
+++ /dev/null
-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)
- {
-
- }
-
- }
-}
+++ /dev/null
-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();
-}
+++ /dev/null
-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;
-
- }
-}
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;
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");
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();