boolean hasBoot = hasBootClasses(webdata);
resteasyDeploymentData.setBootClasses(hasBoot);
// Looked for annotated resources and providers
indexes.add(du.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX));
CompositeIndex index = new CompositeIndex(indexes.toArray(EMPTY_INDEXES));
Class<?> declaredApplicationClass = checkDeclaredApplicationClassAsServlet(du, webdata, classLoader);
// Assume that checkDeclaredApplicationClassAsServlet created the dispatcher
if (declaredApplicationClass != null)
resteasyDeploymentData.setDispatcherCreated(true);
// set scanning on only if there are no boot classes
if (hasBoot == false && !webdata.isMetadataComplete()) {
resteasyDeploymentData.setScanAll(true);
resteasyDeploymentData.setScanProviders(true);
resteasyDeploymentData.setScanResources(true);
}
// check resteasy configuration flags
List<ParamValueMetaData> contextParams = webdata.getContextParams();
if (contextParams != null) {
for (ParamValueMetaData param : contextParams) {
if (param.getParamName().equals(ResteasyContextParameters.RESTEASY_SCAN)) {
resteasyDeploymentData.setScanAll(Boolean.valueOf(param.getParamValue()));
} else if (param.getParamName().equals(ResteasyContextParameters.RESTEASY_SCAN_PROVIDERS)) {
resteasyDeploymentData.setScanProviders(Boolean.valueOf(param.getParamValue()));
} else if (param.getParamName().equals(ResteasyContextParameters.RESTEASY_SCAN_RESOURCES)) {
resteasyDeploymentData.setScanResources(Boolean.valueOf(param.getParamValue()));
} else if (param.getParamName().equals(ResteasyContextParameters.RESTEASY_UNWRAPPED_EXCEPTIONS)) {
resteasyDeploymentData.setUnwrappedExceptionsParameterSet(true);
}
}
}
if (!resteasyDeploymentData.shouldScan()) {
return;
}
// look for Application class. Don't scan for one if there is a declared one.
if (declaredApplicationClass == null) {
final Set<ClassInfo> applicationClass = index.getAllKnownSubclasses(APPLICATION);
try {
if (applicationClass.size() > 1) {
StringBuilder builder = new StringBuilder("Only one JAX-RS Application Class allowed.");
Set<ClassInfo> aClasses = new HashSet<ClassInfo>();
for (ClassInfo c : applicationClass) {
if (!Modifier.isAbstract(c.flags())) {
aClasses.add(c);
}
builder.append(" ").append(c.name().toString());
}
if (aClasses.size() > 1) {
throw new DeploymentUnitProcessingException(builder.toString());
} else if (aClasses.size() == 1) {
ClassInfo aClass = applicationClass.iterator().next();
resteasyDeploymentData.setScannedApplicationClass((Class<? extends Application>) classLoader
.loadClass(aClass.name().toString()));
}
} else if (applicationClass.size() == 1) {
ClassInfo aClass = applicationClass.iterator().next();
resteasyDeploymentData.setScannedApplicationClass((Class<? extends Application>) classLoader
.loadClass(aClass.name().toString()));
}
} catch (ClassNotFoundException e) {
throw new DeploymentUnitProcessingException("Could not load JAX-RS Application class:", e);
}
}
List<AnnotationInstance> resources = null;
List<AnnotationInstance> providers = null;
if (resteasyDeploymentData.isScanResources()) {
resources = index.getAnnotations(JaxrsAnnotations.PATH.getDotName());
}
if (resteasyDeploymentData.isScanProviders()) {
providers = index.getAnnotations(JaxrsAnnotations.PROVIDER.getDotName());
}
if ((resources == null || resources.isEmpty()) && (providers == null || providers.isEmpty()))
return;
final Set<ClassInfo> pathInterfaces = new HashSet<ClassInfo>();
if (resources != null) {
for (AnnotationInstance e : resources) {
final ClassInfo info;
if (e.target() instanceof ClassInfo) {
info = (ClassInfo) e.target();
} else if (e.target() instanceof MethodInfo) {
info = ((MethodInfo) e.target()).declaringClass();
} else {
log.warnf("@Path annotation not on Class or Method: %s", e.target());
continue;
}
if (!Modifier.isInterface(info.flags())) {
resteasyDeploymentData.getScannedResourceClasses().add(info.name().toString());
} else {
pathInterfaces.add(info);
}
}
}
if (providers != null) {
for (AnnotationInstance e : providers) {
if (e.target() instanceof ClassInfo) {
ClassInfo info = (ClassInfo) e.target();
if (!Modifier.isInterface(info.flags())) {
resteasyDeploymentData.getScannedProviderClasses().add(info.name().toString());
}
} else {
log.warnf("@Provider annotation not on Class: %s", e.target());
}
}
}
// look for all implementations of interfaces annotated @Path
for (final ClassInfo iface : pathInterfaces) {
final Set<ClassInfo> implementors = index.getAllKnownImplementors(iface.name());
for (final ClassInfo implementor : implementors) {
resteasyDeploymentData.getScannedResourceClasses().add(implementor.name().toString());
}
}
}