* {@inheritDoc}
*/
@Override
public AnnotationRepository scan(URL[] urls, ClassLoader cl)
{
Indexer indexer = new Indexer();
if (urls != null && urls.length > 0)
{
for (URL url : urls)
{
String externalForm = url.toExternalForm();
if (externalForm.endsWith(".class"))
{
InputStream is = null;
try
{
is = new FileInputStream(new File(url.toURI()));
indexer.index(is);
}
catch (Throwable t)
{
log.error("Unable to process: " + externalForm, t);
}
finally
{
if (is != null)
{
try
{
is.close();
}
catch (IOException ioe)
{
// Nothing
}
}
}
}
else if (externalForm.endsWith(".jar"))
{
JarFile jarFile = null;
try
{
jarFile = new JarFile(new File(url.toURI()));
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements())
{
JarEntry jarEntry = entries.nextElement();
if (jarEntry.getName().endsWith(".class"))
{
InputStream is = null;
try
{
is = jarFile.getInputStream(jarEntry);
indexer.index(is);
}
catch (Throwable t)
{
log.error("Unable to process: " + jarEntry.getName(), t);
}
finally
{
if (is != null)
{
try
{
is.close();
}
catch (IOException ioe)
{
// Nothing
}
}
}
}
}
}
catch (Throwable t)
{
log.error("Unable to process: " + externalForm, t);
}
finally
{
if (jarFile != null)
{
try
{
jarFile.close();
}
catch (IOException ioe)
{
// Nothing
}
}
}
}
}
}
return new AnnotationRepositoryImpl(indexer.complete(), cl);
}