Skip to content

Commit

Permalink
remove scannotation
Browse files Browse the repository at this point in the history
  • Loading branch information
patriot1burke committed Mar 24, 2014
1 parent 18c9910 commit e7d9929
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 127 deletions.
Expand Up @@ -8,6 +8,15 @@

<chapter id="Migration_from_older_versions">
<title>Migration from older versions</title>
<sect1>
<title>Migrating from 3.0.6 to 3.0.7</title>
<itemizedlist>
<listitem>
Scannotation has been removed. If you are not running within an application server you must use the
ResteasyServletInitializer. See docs for more detail.
</listitem>
</itemizedlist>
</sect1>
<sect1>
<title>Migrating from 3.0 to 3.0.4</title>
<itemizedlist>
Expand Down
Expand Up @@ -35,7 +35,6 @@
<module name="org.apache.commons.codec" />
<module name="org.apache.httpcomponents" />
<module name="org.apache.log4j"/>
<module name="org.scannotation.scannotation" />
<module name="org.slf4j" />
<module name="javax.servlet.api"/>
<module name="javax.validation.api"/>
Expand Down
Expand Up @@ -35,7 +35,6 @@
<module name="org.apache.commons.codec" />
<module name="org.apache.httpcomponents" />
<module name="org.apache.log4j"/>
<module name="org.scannotation.scannotation" />
<module name="org.slf4j" />
<module name="javax.servlet.api"/>
<module name="javax.validation.api"/>
Expand Down
Expand Up @@ -35,7 +35,6 @@
<module name="org.apache.commons.codec" />
<module name="org.apache.httpcomponents" />
<module name="org.apache.log4j"/>
<module name="org.scannotation.scannotation" />
<module name="org.slf4j" />
<module name="javax.servlet.api"/>
<module name="javax.validation.api"/>
Expand Down
6 changes: 0 additions & 6 deletions jaxrs/pom.xml
Expand Up @@ -151,12 +151,6 @@
<version>1.2.14</version>
</dependency>

<dependency>
<groupId>org.scannotation</groupId>
<artifactId>scannotation</artifactId>
<version>1.0.3</version>
</dependency>

<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
Expand Down
9 changes: 3 additions & 6 deletions jaxrs/resteasy-jaxrs/pom.xml
Expand Up @@ -45,13 +45,10 @@
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency>
<!--
Scans classes on cp for annotations and builds quick lookup database
of them.
-->
<dependency>
<groupId>org.scannotation</groupId>
<artifactId>scannotation</artifactId>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<scope>test</scope>
</dependency>
<!--
Needed for javax.annotation.security.* which is part of javaee 6 XXX
Expand Down
Expand Up @@ -4,7 +4,6 @@
import org.jboss.resteasy.spi.ResteasyConfiguration;
import org.jboss.resteasy.spi.ResteasyDeployment;
import org.jboss.resteasy.util.HttpHeaderNames;
import org.scannotation.AnnotationDB;

import javax.ws.rs.Path;
import javax.ws.rs.core.Application;
Expand All @@ -27,10 +26,8 @@ abstract public class ConfigurationBootstrap implements ResteasyConfiguration
private static Logger logger = null;
private ResteasyDeployment deployment = new ResteasyDeployment();

public abstract URL[] getScanningUrls();


public ResteasyDeployment createDeployment()
public ResteasyDeployment createDeployment()
{
String loggerTypeString = getParameter("resteasy.logger.type");
if (loggerTypeString != null)
Expand Down Expand Up @@ -107,81 +104,30 @@ public ResteasyDeployment createDeployment()
String builtin = getParameter(ResteasyContextParameters.RESTEASY_USE_BUILTIN_PROVIDERS);
if (builtin != null) deployment.setRegisterBuiltin(Boolean.valueOf(builtin.trim()));

boolean scanProviders = false;
boolean scanResources = false;

String sProviders = getParameter(ResteasyContextParameters.RESTEASY_SCAN_PROVIDERS);
if (sProviders != null)
{
scanProviders = parseBooleanParam(ResteasyContextParameters.RESTEASY_SCAN_PROVIDERS, sProviders);
logger.warn(ResteasyContextParameters.RESTEASY_SCAN_PROVIDERS + " is no longer supported. Use a servlet 3.0 container and the ResteasyServletInitializer");
}
String scanAll = getParameter(ResteasyContextParameters.RESTEASY_SCAN);
if (scanAll != null)
{
boolean tmp = parseBooleanParam(ResteasyContextParameters.RESTEASY_SCAN, scanAll);
scanProviders = tmp || scanProviders;
scanResources = tmp || scanResources;
logger.warn(ResteasyContextParameters.RESTEASY_SCAN + " is no longer supported. Use a servlet 3.0 container and the ResteasyServletInitializer");
}
String sResources = getParameter(ResteasyContextParameters.RESTEASY_SCAN_RESOURCES);
if (sResources != null)
{
scanResources = parseBooleanParam(ResteasyContextParameters.RESTEASY_SCAN_RESOURCES, sResources);
logger.warn(ResteasyContextParameters.RESTEASY_SCAN_RESOURCES + " is no longer supported. Use a servlet 3.0 container and the ResteasyServletInitializer");
}

// Check to see if scanning is being done by deployer (i.e. JBoss App Server)
String sScannedByDeployer = getParameter(ResteasyContextParameters.RESTEASY_SCANNED_BY_DEPLOYER);
if (sScannedByDeployer != null)
{
boolean tmp = parseBooleanParam(ResteasyContextParameters.RESTEASY_SCANNED_BY_DEPLOYER, sScannedByDeployer);
if (tmp)
{
scanProviders = false;
scanResources = false;
}
}

if (scanProviders || scanResources)
{
logger.debug("Scanning...");

URL[] urls = getScanningUrls();
for (URL u : urls)
{
logger.debug("Scanning archive: " + u);
}
AnnotationDB db = new AnnotationDB();
String[] ignoredPackages = {"org.jboss.resteasy.plugins", "org.jboss.resteasy.annotations", "org.jboss.resteasy.client", "org.jboss.resteasy.specimpl", "org.jboss.resteasy.core", "org.jboss.resteasy.spi", "org.jboss.resteasy.util", "org.jboss.resteasy.mock", "javax.ws.rs"};
db.setIgnoredPackages(ignoredPackages);

// only index class annotations as we don't want sub-resources being picked up in the scan
db.setScanClassAnnotations(true);
db.setScanFieldAnnotations(false);
db.setScanMethodAnnotations(false);
db.setScanParameterAnnotations(false);
try
{
db.scanArchives(urls);
try
{
db.crossReferenceImplementedInterfaces();
db.crossReferenceMetaAnnotations();
}
catch (AnnotationDB.CrossReferenceException ignored)
{

}

}
catch (IOException e)
{
throw new RuntimeException("Unable to scan WEB-INF for JAX-RS annotations, you must manually register your classes/resources", e);
}

if (scanProviders) processScannedProviders(db);
if (scanResources) processScannedResources(db);
}


String scannedProviders = getParameter(ResteasyContextParameters.RESTEASY_SCANNED_PROVIDERS);

if (scannedProviders != null)
Expand Down Expand Up @@ -384,41 +330,4 @@ protected void processUnwrapped(String list)
}
}

protected void processScannedProviders(AnnotationDB db)
{
Set<String> classes = db.getAnnotationIndex().get(Provider.class.getName());
if (classes == null) return;
for (String clazz : classes)
{
logger.info("Adding scanned @Provider: " + clazz);
deployment.getScannedProviderClasses().add(clazz);
}
}

protected void processScannedResources(AnnotationDB db)
{
Set<String> classes = new HashSet<String>();
Set<String> paths = db.getAnnotationIndex().get(Path.class.getName());
if (paths != null) classes.addAll(paths);
for (String clazz : classes)
{
Class cls = null;
try
{
// Ignore interfaces and subresource classes
// Scanning is different than other deployment methods
// in other deployment methods we don't want to ignore interfaces and subresources as they are
// application errors
cls = Thread.currentThread().getContextClassLoader().loadClass(clazz.trim());
if (cls.isInterface()) continue;
}
catch (ClassNotFoundException e)
{
throw new RuntimeException(e);
}

logger.info("Adding scanned resource: " + clazz);
deployment.getScannedResourceClasses().add(clazz);
}
}
}
Expand Up @@ -2,14 +2,12 @@

import org.jboss.resteasy.spi.ResteasyConfiguration;
import org.jboss.resteasy.spi.ResteasyDeployment;
import org.scannotation.WarUrlFinder;

import javax.servlet.ServletContext;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -77,21 +75,6 @@ public static URL[] findWebInfLibClasspaths(ServletContext servletContext)
return list.toArray(new URL[list.size()]);
}

public URL[] getScanningUrls()
{
URL[] urls = findWebInfLibClasspaths(servletContext);
URL url = WarUrlFinder.findWebInfClassesPath(servletContext);
if (url == null) return urls;
URL[] all = new URL[urls.length + 1];
int i = 0;
for (i = 0; i < urls.length; i++)
{
all[i] = urls[i];
}
all[i] = url;
return all;
}

@Override
public Set<String> getParameterNames()
{
Expand Down

0 comments on commit e7d9929

Please sign in to comment.