Author: xcoulon
Date: 2012-01-06 03:06:06 -0500 (Fri, 06 Jan 2012)
New Revision: 37669
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsAnnotatedTypeApplication.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsApplication.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/JaxrsMetamodelChangedEvent.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/projects/org.jboss.tools.ws.jaxrs.tests.sampleproject/src/main/java/org/jboss/tools/ws/jaxrs/sample/services/RestApplication.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/jdt/JaxrsAnnotationScannerTestCase.java
Removed:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsApplication.java
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedListener.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedProcessor.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsElementChangedEvent.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsElementChangedProcessor.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsElementChangedPublisher.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuildJob.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuilder.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/ResourceChangedProcessor.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsElement.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsElementFactory.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsEndpoint.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsMetamodel.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsResource.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JaxrsAnnotationsScanner.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/plugin.xml
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriMappingsContentProvider.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/AllTests.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedProcessorTestCase.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsElementChangedProcessorTestCase.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/ResourceChangedProcessorTestCase.java
Log:
Working on JBIDE-10425
Sometimes, the 'JAX-RS REST Web Services' node remains in a 'Building..'
state (
https://issues.jboss.org/browse/JBIDE-10425)
Working on JBIDE-10287
Add support for JAX-RS Application (
https://issues.jboss.org/browse/JBIDE-10287)
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedListener.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedListener.java 2012-01-06
04:09:33 UTC (rev 37668)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedListener.java 2012-01-06
08:06:06 UTC (rev 37669)
@@ -41,12 +41,12 @@
*/
@Override
public void elementChanged(ElementChangedEvent event) {
- scanDelta(event.getDelta(), event.getType());
+ logDelta(event.getDelta(), event.getType());
Job job = new JaxrsMetamodelBuildJob(event);
job.schedule();
}
- private void scanDelta(final IJavaElementDelta delta, final int eventType) {
+ private void logDelta(final IJavaElementDelta delta, final int eventType) {
IJavaElement element = delta.getElement();
// skip as the project is closed
int deltaKind = retrieveDeltaKind(delta);
@@ -57,10 +57,10 @@
Logger.trace("Event {}", event);
// carry on with children elements.
for (IJavaElementDelta affectedChild : delta.getAffectedChildren()) {
- scanDelta(affectedChild, eventType);
+ logDelta(affectedChild, eventType);
}
for (IJavaElementDelta annotation : delta.getAnnotationDeltas()) {
- scanDelta(annotation, eventType);
+ logDelta(annotation, eventType);
}
}
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedProcessor.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedProcessor.java 2012-01-06
04:09:33 UTC (rev 37668)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedProcessor.java 2012-01-06
08:06:06 UTC (rev 37669)
@@ -38,6 +38,7 @@
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsApplication;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsElement;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsElementFactory;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsHttpMethod;
@@ -143,8 +144,7 @@
}
/**
- * Process the addition of a Java Element (can be a JavaProject or a Java
- * Package Fragment root).
+ * Process the addition of a Java Element (can be a JavaProject or a Java Package
Fragment root).
*
* @param scope
* the java element that may contain JAX-RS items
@@ -162,7 +162,7 @@
if (metamodel.getElement(scope) == null) {
// process this type as it is not already known from the metamodel
// let's see if the given project contains JAX-RS HTTP Methods
- final List<IType> matchingHttpMethodTypes =
JaxrsAnnotationsScanner.findHTTPMethodTypes(scope,
+ final List<IType> matchingHttpMethodTypes =
JaxrsAnnotationsScanner.findHttpMethodTypes(scope,
progressMonitor);
for (IType type : matchingHttpMethodTypes) {
final CompilationUnit ast = JdtUtils.parse(type, progressMonitor);
@@ -174,7 +174,7 @@
}
}
// let's see if the given project contains JAX-RS HTTP Resources
- final List<IType> matchingResourceTypes =
JaxrsAnnotationsScanner.findResources(scope, progressMonitor);
+ final List<IType> matchingResourceTypes =
JaxrsAnnotationsScanner.findResourceTypes(scope, progressMonitor);
for (IType matchingType : matchingResourceTypes) {
final CompilationUnit ast = JdtUtils.parse(matchingType, progressMonitor);
final JaxrsResource createdResource = factory.createResource(matchingType, ast,
metamodel);
@@ -191,6 +191,17 @@
}
}
}
+ // let's see if the given project contains JAX-RS Application
+ final List<IType> matchingApplicationTypes =
JaxrsAnnotationsScanner.findApplicationTypes(scope,
+ progressMonitor);
+ for (IType matchingType : matchingApplicationTypes) {
+ final CompilationUnit ast = JdtUtils.parse(matchingType, progressMonitor);
+ final JaxrsApplication createdApplication = factory.createApplication(matchingType,
ast, metamodel);
+ if (createdApplication != null) {
+ metamodel.add(createdApplication);
+ changes.add(new JaxrsElementChangedEvent(createdApplication, ADDED));
+ }
+ }
}
return changes;
@@ -227,6 +238,12 @@
metamodel.add(resource);
changes.add(new JaxrsElementChangedEvent(resource, ADDED));
}
+ // now,let's see if the given type can be an Application
+ final JaxrsApplication application = factory.createApplication(javaType, ast,
metamodel);
+ if (application != null) {
+ metamodel.add(application);
+ changes.add(new JaxrsElementChangedEvent(application, ADDED));
+ }
// TODO: now,let's see if the given type can be a Provider
return changes;
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsElementChangedEvent.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsElementChangedEvent.java 2012-01-06
04:09:33 UTC (rev 37668)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsElementChangedEvent.java 2012-01-06
08:06:06 UTC (rev 37669)
@@ -44,24 +44,26 @@
public static final int F_PATH_VALUE = 4;
- public static final int F_HTTP_METHOD_VALUE = 8;
+ public static final int F_APPLICATION_PATH_VALUE = 8;
- public static final int F_PATH_PARAM_VALUE = 16;
+ public static final int F_HTTP_METHOD_VALUE = 16;
- public static final int F_QUERY_PARAM_VALUE = 32;
+ public static final int F_PATH_PARAM_VALUE = 32;
- public static final int F_MATRIX_PARAM_VALUE = 64;
+ public static final int F_QUERY_PARAM_VALUE = 64;
- public static final int F_DEFAULT_VALUE_VALUE = 128;
+ public static final int F_MATRIX_PARAM_VALUE = 128;
- public static final int F_CONSUMED_MEDIATYPES_VALUE = 256;
+ public static final int F_DEFAULT_VALUE_VALUE = 256;
- public static final int F_PRODUCED_MEDIATYPES_VALUE = 512;
+ public static final int F_CONSUMED_MEDIATYPES_VALUE = 512;
- public static final int F_METHOD_PARAMETERS = 1024;
+ public static final int F_PRODUCED_MEDIATYPES_VALUE = 1024;
- public static final int F_METHOD_RETURN_TYPE = 2048;
+ public static final int F_METHOD_PARAMETERS = 2048;
+ public static final int F_METHOD_RETURN_TYPE = 4096;
+
/**
* Full constructor.
*
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsElementChangedProcessor.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsElementChangedProcessor.java 2012-01-06
04:09:33 UTC (rev 37668)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsElementChangedProcessor.java 2012-01-06
08:06:06 UTC (rev 37669)
@@ -28,6 +28,7 @@
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.ITypeHierarchy;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsApplication;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsElement;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsEndpoint;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsHttpMethod;
@@ -80,6 +81,8 @@
switch (event.getDeltaKind()) {
case ADDED:
switch (elementKind) {
+ case APPLICATION:
+ return processAddition((JaxrsApplication) element);
case HTTP_METHOD:
return processAddition((JaxrsHttpMethod) element);
case RESOURCE:
@@ -89,6 +92,8 @@
}
case CHANGED:
switch (elementKind) {
+ case APPLICATION:
+ return processChange((JaxrsApplication) element, flags);
case HTTP_METHOD:
return processChange((JaxrsHttpMethod) element, flags);
case RESOURCE:
@@ -98,6 +103,8 @@
}
case REMOVED:
switch (elementKind) {
+ case APPLICATION:
+ return processRemoval((JaxrsApplication) element);
case HTTP_METHOD:
return processRemoval((JaxrsHttpMethod) element);
case RESOURCE:
@@ -109,11 +116,32 @@
return Collections.emptyList();
}
- private List<JaxrsEndpointChangedEvent> processAddition(final JaxrsHttpMethod
httpMethod) {
+ /**
+ * Process changes in the JAX-RS Metamodel when a new Application element is added.
There should be only one,
+ * though...
+ *
+ * @param application
+ * @return
+ */
+ private List<JaxrsEndpointChangedEvent> processAddition(final JaxrsApplication
application) {
final List<JaxrsEndpointChangedEvent> changes = new
ArrayList<JaxrsEndpointChangedEvent>();
+ final JaxrsMetamodel metamodel = application.getMetamodel();
+ // if the given application becomes the used application in the metamodel
+ if (application.equals(metamodel.getApplication())) {
+ for (Iterator<JaxrsEndpoint> iterator = metamodel.getEndpoints().iterator();
iterator.hasNext();) {
+ JaxrsEndpoint endpoint = iterator.next();
+ if (endpoint.refresh(application)) {
+ changes.add(new JaxrsEndpointChangedEvent(endpoint, CHANGED));
+ }
+ }
+ }
return changes;
}
+ private List<JaxrsEndpointChangedEvent> processAddition(final JaxrsHttpMethod
httpMethod) {
+ return Collections.emptyList();
+ }
+
private List<JaxrsEndpointChangedEvent> processAddition(final JaxrsResource
resource) throws CoreException {
final List<JaxrsEndpointChangedEvent> changes = new
ArrayList<JaxrsEndpointChangedEvent>();
for (JaxrsResourceMethod resourceMethod : resource.getMethods().values()) {
@@ -175,7 +203,8 @@
if (returnTypeHandler != null &&
supertypesHandlers.contains(returnTypeHandler)) {
final LinkedList<JaxrsResourceMethod> resourceMethods = new
LinkedList<JaxrsResourceMethod>(
Arrays.asList(otherResourceMethod, resourceMethod));
- final JaxrsEndpoint endpoint = new JaxrsEndpoint(httpMethod, resourceMethods);
+ final JaxrsEndpoint endpoint = new JaxrsEndpoint(metamodel.getApplication(),
httpMethod,
+ resourceMethods);
if (metamodel.add(endpoint)) {
changes.add(new JaxrsEndpointChangedEvent(endpoint, ADDED));
}
@@ -191,7 +220,7 @@
final JaxrsMetamodel metamodel) {
final JaxrsHttpMethod httpMethod =
metamodel.getHttpMethod(resourceMethod.getHttpMethodAnnotation());
final List<JaxrsEndpointChangedEvent> changes = new
ArrayList<JaxrsEndpointChangedEvent>();
- final JaxrsEndpoint endpoint = new JaxrsEndpoint(httpMethod, resourceMethod);
+ final JaxrsEndpoint endpoint = new JaxrsEndpoint(metamodel.getApplication(),
httpMethod, resourceMethod);
if (metamodel.add(endpoint)) {
changes.add(new JaxrsEndpointChangedEvent(endpoint, ADDED));
}
@@ -222,7 +251,8 @@
.getHttpMethodAnnotation());
final LinkedList<JaxrsResourceMethod> resourceMethods = new
LinkedList<JaxrsResourceMethod>(
Arrays.asList(subresourceLocator, resourceMethod));
- final JaxrsEndpoint endpoint = new JaxrsEndpoint(httpMethod, resourceMethods);
+ final JaxrsEndpoint endpoint = new JaxrsEndpoint(metamodel.getApplication(),
+ httpMethod, resourceMethods);
if (metamodel.add(endpoint)) {
changes.add(new JaxrsEndpointChangedEvent(endpoint, ADDED));
}
@@ -244,6 +274,21 @@
return supertypesHandlers;
}
+ private List<JaxrsEndpointChangedEvent> processChange(final JaxrsApplication
application, int flags) {
+ final List<JaxrsEndpointChangedEvent> changes = new
ArrayList<JaxrsEndpointChangedEvent>();
+ final JaxrsMetamodel metamodel = application.getMetamodel();
+ if (application.equals(metamodel.getApplication())) {
+ for (Iterator<JaxrsEndpoint> iterator = metamodel.getEndpoints().iterator();
iterator.hasNext();) {
+ JaxrsEndpoint endpoint = iterator.next();
+ if (endpoint.refresh(application)) {
+ // just notify changes to the UI, no refresh required
+ changes.add(new JaxrsEndpointChangedEvent(endpoint, CHANGED));
+ }
+ }
+ }
+ return changes;
+ }
+
private List<JaxrsEndpointChangedEvent> processChange(final JaxrsHttpMethod
httpMethod, int flags) {
final List<JaxrsEndpointChangedEvent> changes = new
ArrayList<JaxrsEndpointChangedEvent>();
for (Iterator<JaxrsEndpoint> iterator =
httpMethod.getMetamodel().getEndpoints().iterator(); iterator.hasNext();) {
@@ -352,6 +397,19 @@
return changes;
}
+ private List<JaxrsEndpointChangedEvent> processRemoval(final JaxrsApplication
application) {
+ final List<JaxrsEndpointChangedEvent> changes = new
ArrayList<JaxrsEndpointChangedEvent>();
+ final JaxrsMetamodel metamodel = application.getMetamodel();
+ for (Iterator<JaxrsEndpoint> iterator = metamodel.getEndpoints().iterator();
iterator
+ .hasNext();) {
+ JaxrsEndpoint endpoint = iterator.next();
+ if (endpoint.refresh(metamodel.getApplication())) {
+ changes.add(new JaxrsEndpointChangedEvent(endpoint, CHANGED));
+ }
+ }
+ return changes;
+ }
+
private List<JaxrsEndpointChangedEvent> processRemoval(final JaxrsResource
resource) {
final List<JaxrsEndpointChangedEvent> changes = new
ArrayList<JaxrsEndpointChangedEvent>();
for (JaxrsResourceMethod resourceMethod : resource.getMethods().values()) {
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsElementChangedPublisher.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsElementChangedPublisher.java 2012-01-06
04:09:33 UTC (rev 37668)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsElementChangedPublisher.java 2012-01-06
08:06:06 UTC (rev 37669)
@@ -22,6 +22,7 @@
if (jaxrsEndpointChanges == null || jaxrsEndpointChanges.isEmpty()) {
Logger.debug("No JAX-RS change to publish to the UI");
} else {
+ Logger.debug("*** Notifying JAX-RS {} changes to publish to the UI ***",
jaxrsEndpointChanges.size());
for (JaxrsEndpointChangedEvent change : jaxrsEndpointChanges) {
Logger.debug(change.toString());
EventService.getInstance().publish(change);
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuildJob.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuildJob.java 2012-01-06
04:09:33 UTC (rev 37668)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuildJob.java 2012-01-06
08:06:06 UTC (rev 37669)
@@ -10,6 +10,8 @@
******************************************************************************/
package org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder;
+import static
org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsMetamodelBuilder.SCALE;
+
import java.util.List;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -19,8 +21,6 @@
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jdt.core.ElementChangedEvent;
import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
-import org.jboss.tools.ws.jaxrs.core.pubsub.EventService;
-import static
org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsMetamodelBuilder.SCALE;
/** @author xcoulon */
public class JaxrsMetamodelBuildJob extends Job {
@@ -38,7 +38,7 @@
}
@Override
- protected IStatus run(IProgressMonitor progressMonitor) {
+ protected IStatus run(final IProgressMonitor progressMonitor) {
try {
progressMonitor.beginTask("Building JAX-RS Metamodel", 4 * SCALE);
progressMonitor.worked(SCALE);
@@ -46,7 +46,6 @@
if (progressMonitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
- // create fake event at the JavaProject level:
// scan and filter delta, retrieve a list of java changes
final List<JavaElementChangedEvent> events = new
JavaElementChangedEventScanner().scanAndFilterEvent(event,
new SubProgressMonitor(progressMonitor, SCALE));
@@ -63,13 +62,9 @@
if (progressMonitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
- if (jaxrsEndpointChanges == null || jaxrsEndpointChanges.isEmpty()) {
- Logger.debug("*** No JAX-RS change to publish to the UI ***");
- } else {
- for (JaxrsEndpointChangedEvent change : jaxrsEndpointChanges) {
- EventService.getInstance().publish(change);
- }
- }
+ new JaxrsElementChangedPublisher().publish(jaxrsEndpointChanges, new
SubProgressMonitor(progressMonitor,
+ SCALE));
+
} catch (Throwable e) {
Logger.error("Failed to build or refresh the JAX-RS metamodel", e);
} finally {
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuilder.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuilder.java 2012-01-06
04:09:33 UTC (rev 37668)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuilder.java 2012-01-06
08:06:06 UTC (rev 37669)
@@ -134,6 +134,7 @@
final List<JaxrsEndpointChangedEvent> jaxrsEndpointChanges = new
JaxrsElementChangedProcessor()
.processEvents(jaxrsElementChanges, new SubProgressMonitor(progressMonitor,
SCALE));
progressMonitor.worked(SCALE);
+
new JaxrsElementChangedPublisher().publish(jaxrsEndpointChanges, new
SubProgressMonitor(progressMonitor,
SCALE));
progressMonitor.worked(SCALE);
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/ResourceChangedProcessor.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/ResourceChangedProcessor.java 2012-01-06
04:09:33 UTC (rev 37668)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/ResourceChangedProcessor.java 2012-01-06
08:06:06 UTC (rev 37669)
@@ -30,6 +30,7 @@
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsApplication;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsElementFactory;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsHttpMethod;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsMetamodel;
@@ -81,11 +82,13 @@
switch (deltaKind) {
case ADDED:
case CHANGED:
+ results.addAll(processApplicationChangesOnScopeAdditionOrChange(scope, metamodel,
progressMonitor));
results.addAll(processHttpMethodChangesOnScopeAdditionOrChange(scope, metamodel,
progressMonitor));
results.addAll(processResourceChangesOnScopeAdditionOrChange(scope, metamodel,
deltaKind,
progressMonitor));
break;
case REMOVED:
+ results.addAll(processApplicationChangesOnScopeRemoval(scope, metamodel,
progressMonitor));
results.addAll(processHttpMethodChangesOnScopeRemoval(scope, metamodel,
progressMonitor));
results.addAll(processResourceChangesOnScopeRemoval(scope, metamodel,
progressMonitor));
break;
@@ -95,47 +98,136 @@
return results;
}
- private List<JaxrsElementChangedEvent>
processHttpMethodChangesOnScopeAdditionOrChange(IJavaElement scope,
+ private List<JaxrsElementChangedEvent>
processApplicationChangesOnScopeAdditionOrChange(IJavaElement scope,
JaxrsMetamodel metamodel, IProgressMonitor progressMonitor) throws JavaModelException,
CoreException {
final List<JaxrsElementChangedEvent> results = new
ArrayList<JaxrsElementChangedEvent>();
- final List<JaxrsElementChangedEvent> changes =
preprocessHttpMethodChangesOnScopeAdditionOrChange(scope,
+ final List<JaxrsElementChangedEvent> changes =
preprocessApplicationChangesOnScopeAdditionOrChange(scope,
metamodel, progressMonitor);
for (JaxrsElementChangedEvent change : changes) {
- results.addAll(postProcessHttpMethod(change, progressMonitor));
+ results.addAll(postProcessApplication(change, progressMonitor));
}
return results;
}
- private List<JaxrsElementChangedEvent>
processResourceChangesOnScopeAdditionOrChange(IJavaElement scope,
- JaxrsMetamodel metamodel, int deltaKind, IProgressMonitor progressMonitor) throws
JavaModelException,
- CoreException {
+ /**
+ * See if Applications exist in the given scope. The exact kind of the
+ * {@link JaxrsElementChangedEvent} event is not determined at this stage,
+ * it's the responsibility of the
+ * {@link ResourceChangedProcessor#postProcessApplication(JaxrsElementChangedEvent,
IProgressMonitor)}
+ * method.
+ *
+ * @param scope
+ * @param metamodel
+ * @param progressMonitor
+ * @return events containing the new Applications (already added to the
+ * metamodel)
+ * @throws CoreException
+ * @throws JavaModelException
+ */
+ private List<JaxrsElementChangedEvent>
preprocessApplicationChangesOnScopeAdditionOrChange(final IJavaElement scope,
+ final JaxrsMetamodel metamodel, final IProgressMonitor progressMonitor) throws
CoreException,
+ JavaModelException {
final List<JaxrsElementChangedEvent> results = new
ArrayList<JaxrsElementChangedEvent>();
- final List<JaxrsElementChangedEvent> changes =
preprocessResourceChangesOnScopeAdditionOrChange(scope,
- metamodel, progressMonitor);
- for (JaxrsElementChangedEvent change : changes) {
- results.addAll(postProcessResource(change, progressMonitor));
+ // see if there may be elements to add/change from the given scope
+ final List<JaxrsApplication> matchingApplications = new
ArrayList<JaxrsApplication>();
+ final List<IType> matchingApplicationTypes =
JaxrsAnnotationsScanner.findApplicationTypes(scope, progressMonitor);
+ for (IType matchingApplicationType : matchingApplicationTypes) {
+ final CompilationUnit ast = JdtUtils.parse(matchingApplicationType, progressMonitor);
+ final JaxrsApplication matchingApplication =
factory.createApplication(matchingApplicationType, ast, metamodel);
+ if (matchingApplication != null) {
+ matchingApplications.add(matchingApplication);
+ }
}
+ // retrieve the existing elements from the Metamodel
+ final List<JaxrsApplication> existingApplications = metamodel.getElements(scope,
JaxrsApplication.class);
+ // compute the differences, with a 'fuzzy' case when the kind is
+ // 'changed'
+ final Collection<JaxrsApplication> addedApplications =
CollectionUtils.difference(matchingApplications,
+ existingApplications);
+ for (JaxrsApplication application : addedApplications) {
+ results.add(new JaxrsElementChangedEvent(application, ADDED));
+ }
+ final Collection<JaxrsApplication> changedApplications =
CollectionUtils.intersection(matchingApplications,
+ existingApplications);
+ for (JaxrsApplication application : changedApplications) {
+ results.add(new JaxrsElementChangedEvent(application, CHANGED, F_FINE_GRAINED));
+ }
+ final Collection<JaxrsApplication> removedApplications =
CollectionUtils.difference(existingApplications,
+ matchingApplications);
+ for (JaxrsApplication application : removedApplications) {
+ results.add(new JaxrsElementChangedEvent(application, REMOVED));
+ }
return results;
}
- private List<JaxrsElementChangedEvent>
processResourceChangesOnScopeRemoval(IJavaElement scope,
+ private List<JaxrsElementChangedEvent>
processApplicationChangesOnScopeRemoval(IJavaElement scope,
JaxrsMetamodel metamodel, IProgressMonitor progressMonitor) throws JavaModelException,
CoreException {
final List<JaxrsElementChangedEvent> results = new
ArrayList<JaxrsElementChangedEvent>();
- final List<JaxrsElementChangedEvent> changes =
preprocessHttpMethodChangesOnScopeRemoval(scope, metamodel,
+ final List<JaxrsElementChangedEvent> changes =
preprocessApplicationChangesOnScopeRemoval(scope, metamodel,
progressMonitor);
for (JaxrsElementChangedEvent change : changes) {
- results.addAll(postProcessHttpMethod(change, progressMonitor));
+ results.addAll(postProcessApplication(change, progressMonitor));
}
return results;
}
- private List<JaxrsElementChangedEvent>
processHttpMethodChangesOnScopeRemoval(IJavaElement scope,
+ /**
+ * See if Applications existed in the given scope. These elements can only be
+ * marked as removed.
+ *
+ * @param scope
+ * @param metamodel
+ * @param progressMonitor
+ * @return events containing the new Applications (already added to the
+ * metamodel)
+ * @throws CoreException
+ * @throws JavaModelException
+ */
+ private List<JaxrsElementChangedEvent>
preprocessApplicationChangesOnScopeRemoval(final IJavaElement scope,
+ final JaxrsMetamodel metamodel, final IProgressMonitor progressMonitor) throws
CoreException,
+ JavaModelException {
+ final List<JaxrsElementChangedEvent> results = new
ArrayList<JaxrsElementChangedEvent>();
+ // retrieve the existing elements from the Metamodel
+ final List<JaxrsApplication> existingApplications = metamodel.getElements(scope,
JaxrsApplication.class);
+ for (JaxrsApplication application : existingApplications) {
+ results.add(new JaxrsElementChangedEvent(application, REMOVED));
+ }
+ return results;
+ }
+
+ private List<JaxrsElementChangedEvent>
postProcessApplication(JaxrsElementChangedEvent event,
+ IProgressMonitor progressMonitor) {
+ final List<JaxrsElementChangedEvent> results = new
ArrayList<JaxrsElementChangedEvent>();
+ final JaxrsApplication eventApplication = (JaxrsApplication) event.getElement();
+ final JaxrsMetamodel metamodel = eventApplication.getMetamodel();
+ switch (event.getDeltaKind()) {
+ case ADDED:
+ metamodel.add(eventApplication);
+ results.add(event);
+ break;
+ case REMOVED:
+ metamodel.remove(eventApplication);
+ results.add(event);
+ break;
+ case CHANGED:
+ final JaxrsApplication existingApplication =
metamodel.getElement(eventApplication.getJavaElement(),
+ JaxrsApplication.class);
+ final int flags = existingApplication.update(eventApplication);
+ if (flags != 0) {
+ results.add(new JaxrsElementChangedEvent(existingApplication, CHANGED, flags));
+ }
+ break;
+ }
+ return results;
+ }
+
+ private List<JaxrsElementChangedEvent>
processHttpMethodChangesOnScopeAdditionOrChange(IJavaElement scope,
JaxrsMetamodel metamodel, IProgressMonitor progressMonitor) throws JavaModelException,
CoreException {
final List<JaxrsElementChangedEvent> results = new
ArrayList<JaxrsElementChangedEvent>();
- final List<JaxrsElementChangedEvent> changes =
preprocessResourceChangesOnScopeRemoval(scope, metamodel,
- progressMonitor);
+ final List<JaxrsElementChangedEvent> changes =
preprocessHttpMethodChangesOnScopeAdditionOrChange(scope,
+ metamodel, progressMonitor);
for (JaxrsElementChangedEvent change : changes) {
- results.addAll(postProcessResource(change, progressMonitor));
+ results.addAll(postProcessHttpMethod(change, progressMonitor));
}
return results;
}
@@ -161,7 +253,7 @@
final List<JaxrsElementChangedEvent> results = new
ArrayList<JaxrsElementChangedEvent>();
// see if there may be elements to add/change from the given scope
final List<JaxrsHttpMethod> matchingHttpMethods = new
ArrayList<JaxrsHttpMethod>();
- final List<IType> matchingHttpMethodTypes =
JaxrsAnnotationsScanner.findHTTPMethodTypes(scope, progressMonitor);
+ final List<IType> matchingHttpMethodTypes =
JaxrsAnnotationsScanner.findHttpMethodTypes(scope, progressMonitor);
for (IType matchingHttpMethodType : matchingHttpMethodTypes) {
final CompilationUnit ast = JdtUtils.parse(matchingHttpMethodType, progressMonitor);
final JaxrsHttpMethod matchingHttpMethod =
factory.createHttpMethod(matchingHttpMethodType, ast, metamodel);
@@ -191,6 +283,16 @@
return results;
}
+ private List<JaxrsElementChangedEvent>
processHttpMethodChangesOnScopeRemoval(IJavaElement scope,
+ JaxrsMetamodel metamodel, IProgressMonitor progressMonitor) throws JavaModelException,
CoreException {
+ final List<JaxrsElementChangedEvent> results = new
ArrayList<JaxrsElementChangedEvent>();
+ final List<JaxrsElementChangedEvent> changes =
preprocessHttpMethodChangesOnScopeRemoval(scope, metamodel, progressMonitor);
+ for (JaxrsElementChangedEvent change : changes) {
+ results.addAll(postProcessHttpMethod(change, progressMonitor));
+ }
+ return results;
+ }
+
/**
* See if HttpMethods existed in the given scope. These elements can only be
* marked as removed.
@@ -215,6 +317,44 @@
return results;
}
+ private List<JaxrsElementChangedEvent>
postProcessHttpMethod(JaxrsElementChangedEvent event,
+ IProgressMonitor progressMonitor) {
+ final List<JaxrsElementChangedEvent> results = new
ArrayList<JaxrsElementChangedEvent>();
+ final JaxrsHttpMethod eventHttpMethod = (JaxrsHttpMethod) event.getElement();
+ final JaxrsMetamodel metamodel = eventHttpMethod.getMetamodel();
+ switch (event.getDeltaKind()) {
+ case ADDED:
+ metamodel.add(eventHttpMethod);
+ results.add(event);
+ break;
+ case REMOVED:
+ metamodel.remove(eventHttpMethod);
+ results.add(event);
+ break;
+ case CHANGED:
+ final JaxrsHttpMethod existingHttpMethod =
metamodel.getElement(eventHttpMethod.getJavaElement(),
+ JaxrsHttpMethod.class);
+ final int flags = existingHttpMethod.update(eventHttpMethod);
+ if (flags != 0) {
+ results.add(new JaxrsElementChangedEvent(existingHttpMethod, CHANGED, flags));
+ }
+ break;
+ }
+ return results;
+ }
+
+ private List<JaxrsElementChangedEvent>
processResourceChangesOnScopeAdditionOrChange(IJavaElement scope,
+ JaxrsMetamodel metamodel, int deltaKind, IProgressMonitor progressMonitor) throws
JavaModelException,
+ CoreException {
+ final List<JaxrsElementChangedEvent> results = new
ArrayList<JaxrsElementChangedEvent>();
+ final List<JaxrsElementChangedEvent> changes =
preprocessResourceChangesOnScopeAdditionOrChange(scope,
+ metamodel, progressMonitor);
+ for (JaxrsElementChangedEvent change : changes) {
+ results.addAll(postProcessResource(change, progressMonitor));
+ }
+ return results;
+ }
+
/**
* See if new JAX-RS Resources exist in the given scope. The exact kind of
* the {@link JaxrsElementChangedEvent} event is not determined at this
@@ -235,7 +375,7 @@
final List<JaxrsElementChangedEvent> results = new
ArrayList<JaxrsElementChangedEvent>();
// see if there may be elements to add/change from the given scope
final List<JaxrsResource> matchingResources = new
ArrayList<JaxrsResource>();
- final List<IType> matchingResourceTypes =
JaxrsAnnotationsScanner.findResources(scope, progressMonitor);
+ final List<IType> matchingResourceTypes =
JaxrsAnnotationsScanner.findResourceTypes(scope, progressMonitor);
for (IType matchingResourceType : matchingResourceTypes) {
final CompilationUnit ast = JdtUtils.parse(matchingResourceType, progressMonitor);
final JaxrsResource matchingResource = factory.createResource(matchingResourceType,
ast, metamodel);
@@ -262,7 +402,18 @@
for (JaxrsResource resource : removedResources) {
results.add(new JaxrsElementChangedEvent(resource, REMOVED));
}
+
+ return results;
+ }
+ private List<JaxrsElementChangedEvent>
processResourceChangesOnScopeRemoval(IJavaElement scope,
+ JaxrsMetamodel metamodel, IProgressMonitor progressMonitor) throws JavaModelException,
CoreException {
+ final List<JaxrsElementChangedEvent> results = new
ArrayList<JaxrsElementChangedEvent>();
+ final List<JaxrsElementChangedEvent> changes =
preprocessResourceChangesOnScopeRemoval(scope, metamodel,
+ progressMonitor);
+ for (JaxrsElementChangedEvent change : changes) {
+ results.addAll(postProcessResource(change, progressMonitor));
+ }
return results;
}
@@ -408,32 +559,4 @@
}
return changes;
}
-
- private List<JaxrsElementChangedEvent>
postProcessHttpMethod(JaxrsElementChangedEvent event,
- IProgressMonitor progressMonitor) {
- final List<JaxrsElementChangedEvent> results = new
ArrayList<JaxrsElementChangedEvent>();
- final JaxrsHttpMethod eventHttpMethod = (JaxrsHttpMethod) event.getElement();
- final JaxrsMetamodel metamodel = eventHttpMethod.getMetamodel();
- switch (event.getDeltaKind()) {
- case ADDED:
- metamodel.add(eventHttpMethod);
- results.add(event);
- break;
- case REMOVED:
- metamodel.remove(eventHttpMethod);
- results.add(event);
- // FIXME: also remove all resourceMethods / update all subresource
- // methods using this HttpMethod
- break;
- case CHANGED:
- final JaxrsHttpMethod existingHttpMethod =
metamodel.getElement(eventHttpMethod.getJavaElement(),
- JaxrsHttpMethod.class);
- final int flags = existingHttpMethod.update(eventHttpMethod);
- if (flags != 0) {
- results.add(new JaxrsElementChangedEvent(existingHttpMethod, CHANGED, flags));
- }
- break;
- }
- return results;
- }
}
Copied:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsAnnotatedTypeApplication.java
(from rev 37612,
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsApplication.java)
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsAnnotatedTypeApplication.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsAnnotatedTypeApplication.java 2012-01-06
08:06:06 UTC (rev 37669)
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Coulon - Initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain;
+
+import static
org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsElementChangedEvent.F_APPLICATION_PATH_VALUE;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ws.rs.ApplicationPath;
+
+import org.eclipse.jdt.core.IType;
+import org.eclipse.wst.validation.ValidatorMessage;
+import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
+import org.jboss.tools.ws.jaxrs.core.metamodel.EnumElementKind;
+import org.jboss.tools.ws.jaxrs.core.metamodel.EnumKind;
+
+/**
+ * This domain element describes a subtype of {@link jvax.ws.rs.Application} annotated
with
+ * {@link jvax.ws.rs.ApplicationPath}.
+ *
+ * @author xcoulon
+ */
+public class JaxrsAnnotatedTypeApplication extends JaxrsApplication {
+
+ /**
+ * Full constructor.
+ *
+ * @param javaType
+ * @param applicationPathAnnocation
+ * @param metamodel
+ */
+ public JaxrsAnnotatedTypeApplication(IType javaType, Annotation
applicationPathAnnocation, JaxrsMetamodel metamodel) {
+ super(javaType, applicationPathAnnocation, metamodel);
+ }
+
+ @Override
+ public EnumElementKind getElementKind() {
+ return EnumElementKind.APPLICATION;
+ }
+
+ @Override
+ public EnumKind getKind() {
+ if (getAnnotation(ApplicationPath.class.getName()) != null) {
+ return EnumKind.APPLICATION;
+ }
+ return EnumKind.UNDEFINED;
+ }
+
+ @Override
+ public List<ValidatorMessage> validate() {
+ List<ValidatorMessage> messages = new ArrayList<ValidatorMessage>();
+ return messages;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getApplicationPath() {
+ final Annotation applicationPathAnnotation =
getAnnotation(ApplicationPath.class.getName());
+ if (applicationPathAnnotation != null) {
+ return applicationPathAnnotation.getValue("value");
+ }
+ return null;
+ }
+
+ /**
+ * Update this Application with the elements of the given Application
+ *
+ * @param application
+ * @return the flags indicating the kind of changes that occurred during the
+ * update.
+ */
+ @Override
+ public int update(JaxrsApplication application) {
+ int flags = 0;
+ final Annotation annotation = this.getAnnotation(ApplicationPath.class.getName());
+ final Annotation otherAnnotation =
application.getAnnotation(ApplicationPath.class.getName());
+ if (annotation != null && otherAnnotation != null &&
!annotation.equals(otherAnnotation)
+ && annotation.update(otherAnnotation)) {
+ flags += F_APPLICATION_PATH_VALUE;
+ }
+ return flags;
+ }
+
+
+}
Property changes on:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsAnnotatedTypeApplication.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Deleted:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsApplication.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsApplication.java 2012-01-06
04:09:33 UTC (rev 37668)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsApplication.java 2012-01-06
08:06:06 UTC (rev 37669)
@@ -1,107 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Xavier Coulon - Initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.wst.validation.ValidatorMessage;
-import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
-import org.jboss.tools.ws.jaxrs.core.metamodel.EnumElementKind;
-import org.jboss.tools.ws.jaxrs.core.metamodel.EnumKind;
-import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsApplication;
-
-/**
- * The optional '@Application' annotation, used to designate the base context
- * URI of the root resources.
- *
- *
- * @author xcoulon
- */
-public class JaxrsApplication extends JaxrsElement<IType> implements
IJaxrsApplication {
-
- /**
- * Internal 'HttpMethod' element builder.
- *
- * @author xcoulon
- */
- public static class Builder {
-
- private final JaxrsMetamodel metamodel;
- private final IType javaType;
-
- /**
- * Mandatory attributes of the enclosing 'HttpMethod' element.
- *
- * @param javaType
- * @param metamodel
- */
- public Builder(final IType javaType, final JaxrsMetamodel metamodel) {
- this.javaType = javaType;
- this.metamodel = metamodel;
- }
-
- /**
- * Builds and returns the elements. Internally calls the merge() method.
- *
- * @param progressMonitor
- * @return
- * @throws CoreException
- */
- public JaxrsApplication build(IProgressMonitor progressMonitor) throws CoreException {
- JaxrsApplication app = new JaxrsApplication(this);
- // app.merge(javaType, progressMonitor);
- return app;
- }
- }
-
- /**
- * Full constructor using the inner 'Builder' static class.
- *
- * @param builder
- */
- private JaxrsApplication(Builder builder) {
- super(builder.javaType, (Annotation) null, builder.metamodel);
- }
-
- @Override
- public EnumElementKind getElementKind() {
- return EnumElementKind.APPLICATION;
- }
-
- /*
- * @Override public Set<EnumElementChange> merge(IType element,
- * IProgressMonitor progressMonitor) throws CoreException {
- * Set<EnumElementChange> changes = new HashSet<EnumElementChange>(); if
- * (getJavaElement() != null) { CompilationUnit compilationUnit =
- * getCompilationUnit(progressMonitor); String appPath = (String)
- * JdtUtils.resolveAnnotationAttributeValue(getJavaElement(),
- * compilationUnit, javax.ws.rs.ApplicationPath.class, "value"); if (appPath
- * != null) { getMetamodel().setServiceUri(appPath); } else {
- * getMetamodel().setServiceUri("/"); } } else {
- * getMetamodel().setServiceUri("/"); } return changes; }
- */
-
- @Override
- public EnumKind getKind() {
- return EnumKind.APPLICATION;
- }
-
- @Override
- public List<ValidatorMessage> validate() {
- List<ValidatorMessage> messages = new ArrayList<ValidatorMessage>();
- return messages;
- }
-
-}
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsApplication.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsApplication.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsApplication.java 2012-01-06
08:06:06 UTC (rev 37669)
@@ -0,0 +1,27 @@
+package org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain;
+
+import java.util.List;
+
+import org.eclipse.jdt.core.IType;
+import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
+import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsApplication;
+
+public abstract class JaxrsApplication extends JaxrsElement<IType> implements
IJaxrsApplication {
+
+
+ public JaxrsApplication(IType element, Annotation annotation, JaxrsMetamodel metamodel)
{
+ super(element, annotation, metamodel);
+ }
+
+ public JaxrsApplication(IType element, List<Annotation> annotations,
JaxrsMetamodel metamodel) {
+ super(element, annotations, metamodel);
+ }
+
+ /**
+ * @return the value of the {@link javax.ws.rs.ApplicationPath} annotation or null if it
does not exist in te
+ * associated java type.
+ */
+ public abstract String getApplicationPath();
+
+ public abstract int update(JaxrsApplication eventApplication);
+}
\ No newline at end of file
Property changes on:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsApplication.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsElement.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsElement.java 2012-01-06
04:09:33 UTC (rev 37668)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsElement.java 2012-01-06
08:06:06 UTC (rev 37669)
@@ -11,6 +11,7 @@
package org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain;
+import static
org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsElementChangedEvent.F_APPLICATION_PATH_VALUE;
import static
org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsElementChangedEvent.F_CONSUMED_MEDIATYPES_VALUE;
import static
org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsElementChangedEvent.F_DEFAULT_VALUE_VALUE;
import static
org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsElementChangedEvent.F_ELEMENT_KIND;
@@ -29,6 +30,7 @@
import java.util.Map;
import java.util.Map.Entry;
+import javax.ws.rs.ApplicationPath;
import javax.ws.rs.Consumes;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.HttpMethod;
@@ -211,6 +213,8 @@
final EnumKind currentKind = getKind();
if (annotationName.equals(Path.class.getName())) {
flag = F_PATH_VALUE;
+ } else if (annotationName.equals(ApplicationPath.class.getName())) {
+ flag = F_APPLICATION_PATH_VALUE;
} else if (annotationName.equals(HttpMethod.class.getName())) {
flag = F_HTTP_METHOD_VALUE;
} else if (annotationName.equals(PathParam.class.getName())) {
@@ -256,6 +260,8 @@
iterator.remove();
if (annotationName.equals(Path.class.getName())) {
flag = F_PATH_VALUE;
+ }else if (annotationName.equals(ApplicationPath.class.getName())) {
+ flag = F_APPLICATION_PATH_VALUE;
} else if (annotationName.equals(HttpMethod.class.getName())) {
flag = F_HTTP_METHOD_VALUE;
} else if (annotationName.equals(PathParam.class.getName())) {
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsElementFactory.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsElementFactory.java 2012-01-06
04:09:33 UTC (rev 37668)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsElementFactory.java 2012-01-06
08:06:06 UTC (rev 37669)
@@ -19,6 +19,7 @@
import java.util.List;
import java.util.Map;
+import javax.ws.rs.ApplicationPath;
import javax.ws.rs.Consumes;
import javax.ws.rs.CookieParam;
import javax.ws.rs.DefaultValue;
@@ -34,6 +35,7 @@
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.IAnnotation;
import org.eclipse.jdt.core.IField;
+import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
@@ -52,14 +54,13 @@
public class JaxrsElementFactory {
/**
- * Attempts to create a new JAX-RS element from the given Java annotation,
- * <b>without adding it to the given JAX-RS Metamodel</b>
+ * Attempts to create a new JAX-RS element from the given Java annotation,
<b>without adding it to the given JAX-RS
+ * Metamodel</b>
*
* @param element
* @param ast
* @param metamodel
- * @return the created JAX-RS element or null if the given Java annotation
- * is not a valid one.
+ * @return the created JAX-RS element or null if the given Java annotation is not a
valid one.
* @throws CoreException
*/
public JaxrsElement<?> createElement(IAnnotation javaAnnotation, CompilationUnit
ast, JaxrsMetamodel metamodel)
@@ -69,6 +70,9 @@
if (annotationName.equals(HttpMethod.class.getName())) {
final JaxrsHttpMethod httpMethod = createHttpMethod(annotation, ast, metamodel);
return httpMethod;
+ } else if (annotationName.equals(ApplicationPath.class.getName())) {
+ final JaxrsApplication application = createApplication(annotation, ast, metamodel);
+ return application;
} else {
switch (javaAnnotation.getParent().getElementType()) {
case TYPE:
@@ -97,17 +101,15 @@
}
/**
- * Creates a JAX-RS Root Resource (including its methods and its fields)
- * from the given path annotation and its AST, <b>without adding it to the
- * given JAX-RS Metamodel</b>
+ * Creates a JAX-RS Root Resource (including its methods and its fields) from the given
path annotation and its AST,
+ * <b>without adding it to the given JAX-RS Metamodel</b>
*
* @param pathAnnotation
* the @Path annotation found on the Java Type
* @param ast
* the AST associated to the annotated java type
* @param metamodel
- * the current metamodel, in which the Root Resource should be
- * added
+ * the current metamodel, in which the Root Resource should be added
* @return the created Root Resource
* @throws CoreException
*/
@@ -118,17 +120,15 @@
}
/**
- * Creates a JAX-RS Resource (including its methods and its fields) from the
- * given type and its AST, <b>without adding it to the given JAX-RS
- * Metamodel</b>
+ * Creates a JAX-RS Resource (including its methods and its fields) from the given type
and its AST, <b>without
+ * adding it to the given JAX-RS Metamodel</b>
*
* @param javaType
* the Java Type
* @param ast
* the AST associated to the java type
* @param metamodel
- * the current metamodel, in which the JAX-RS Resource should be
- * added
+ * the current metamodel, in which the JAX-RS Resource should be added
* @return the created resource
* @throws CoreException
*/
@@ -167,10 +167,8 @@
}
/**
- * Creates a JAX-RS resource method from the given annotation (@Path or an
- * HttpMethod) and its AST, <b>without adding it to the given JAX-RS
- * Metamodel</b>. If the parent resource did not exist before, its is also
- * created.
+ * Creates a JAX-RS resource method from the given annotation (@Path or an HttpMethod)
and its AST, <b>without
+ * adding it to the given JAX-RS Metamodel</b>. If the parent resource did not
exist before, its is also created.
*
* @param annotation
* @param ast
@@ -185,9 +183,8 @@
}
/**
- * Creates a JAX-RS resource method from the given annotation (@Path or an
- * HttpMethod) and its AST, <b>without adding it to the given JAX-RS
- * Metamodel</b>
+ * Creates a JAX-RS resource method from the given annotation (@Path or an HttpMethod)
and its AST, <b>without
+ * adding it to the given JAX-RS Metamodel</b>
*
* @param annotation
* @param ast
@@ -248,8 +245,8 @@
}
/**
- * Creates a JAX-RS HTTP Method from the given pathAnnotation and its AST,
- * <b>without adding it to the given JAX-RS Metamodel</b>
+ * Creates a JAX-RS HTTP Method from the given {@link javax.ws.rs.HttpMethod} annotation
and its AST, <b>without
+ * adding it to the given JAX-RS Metamodel</b>
*
* @param ast
* @param metamodel
@@ -268,8 +265,8 @@
}
/**
- * Creates a JAX-RS HTTP Method from the given pathAnnotation and its AST,
- * <b>without adding it to the given JAX-RS Metamodel</b>.
+ * Creates a JAX-RS Application from the given pathAnnotation and its AST,
<b>without adding it to the given JAX-RS
+ * Metamodel</b>.
*
* @param ast
* @param metamodel
@@ -279,15 +276,54 @@
*/
public JaxrsHttpMethod createHttpMethod(final Annotation annotation, final
CompilationUnit ast,
final JaxrsMetamodel metamodel) throws CoreException {
- final JaxrsHttpMethod httpMethod = new JaxrsHttpMethod((IType)
annotation.getJavaParent(), annotation,
- metamodel);
- return httpMethod;
+ if (annotation.getJavaParent() != null &&
annotation.getJavaParent().getElementType() == IJavaElement.TYPE
+ && annotation.getName().equals(HttpMethod.class.getName())) {
+ return new JaxrsHttpMethod((IType) annotation.getJavaParent(), annotation,
metamodel);
+ }
+ return null;
}
/**
- * Create a JAX-RS Resource field from the given annotation, <b>without
- * adding it to the given JAX-RS Metamodel</b>
+ * Creates a JAX-RS Application from the given type and its AST, <b>without adding
it to the given JAX-RS
+ * Metamodel</b>
*
+ * @param ast
+ * @param metamodel
+ * @param annotation
+ * @return
+ * @throws CoreException
+ */
+ public JaxrsApplication createApplication(final IType javaType, final CompilationUnit
ast,
+ final JaxrsMetamodel metamodel) throws CoreException {
+ Annotation applicationPathAnnotation = JdtUtils.resolveAnnotation(javaType, ast,
ApplicationPath.class);
+ if (applicationPathAnnotation == null) {
+ return null;
+ }
+ return new JaxrsAnnotatedTypeApplication(javaType, applicationPathAnnotation,
metamodel);
+ }
+
+ /**
+ * Creates a JAX-RS Application from the given {@link javax.ws.rs.ApplicationPath }
annotation and its AST,
+ * <b>without adding it to the given JAX-RS Metamodel</b>.
+ *
+ * @param ast
+ * @param metamodel
+ * @param annotation
+ * @return
+ * @throws CoreException
+ */
+ public JaxrsApplication createApplication(final Annotation annotation, final
CompilationUnit ast,
+ final JaxrsMetamodel metamodel) throws CoreException {
+ if (annotation.getJavaParent() != null &&
annotation.getJavaParent().getElementType() == IJavaElement.TYPE
+ && annotation.getName().equals(ApplicationPath.class.getName())) {
+ return new JaxrsAnnotatedTypeApplication((IType) annotation.getJavaParent(),
annotation, metamodel);
+ }
+ return null;
+ }
+
+ /**
+ * Create a JAX-RS Resource field from the given annotation, <b>without adding it
to the given JAX-RS Metamodel</b>
+ *
* @param pathParamannotation
* @param ast
* @param metamodel
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsEndpoint.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsEndpoint.java 2012-01-06
04:09:33 UTC (rev 37668)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsEndpoint.java 2012-01-06
08:06:06 UTC (rev 37669)
@@ -38,17 +38,20 @@
private final LinkedList<JaxrsResourceMethod> resourceMethods;
+ private JaxrsApplication application = null;
+
private String uriPathTemplate = null;
private List<String> consumedMediaTypes = null;
private List<String> producedMediaTypes = null;
- public JaxrsEndpoint(JaxrsHttpMethod httpMethod, JaxrsResourceMethod resourceMethod) {
- this(httpMethod, new
LinkedList<JaxrsResourceMethod>(Arrays.asList(resourceMethod)));
+ public JaxrsEndpoint(final JaxrsApplication application, final JaxrsHttpMethod
httpMethod, final JaxrsResourceMethod resourceMethod) {
+ this(application, httpMethod, new
LinkedList<JaxrsResourceMethod>(Arrays.asList(resourceMethod)));
}
- public JaxrsEndpoint(JaxrsHttpMethod httpMethod, LinkedList<JaxrsResourceMethod>
resourceMethods) {
+ public JaxrsEndpoint(final JaxrsApplication application, final JaxrsHttpMethod
httpMethod, final LinkedList<JaxrsResourceMethod> resourceMethods) {
+ this.application = application;
this.httpMethod = httpMethod;
this.resourceMethods = resourceMethods;
refreshUriPathTemplate();
@@ -142,6 +145,18 @@
}
/**
+ * Triggers a refresh when changes occurred on the application element (whatever
operation).
+ *
+ * @return true if the endpoint is still valid, false otherwise (it should
+ * be removed from the metamodel)
+ */
+ public boolean refresh(JaxrsApplication application) {
+ this.application = application;
+ refreshUriPathTemplate();
+ return true;
+ }
+
+ /**
* Triggers a refresh when changes occurred on one or more elements
* (HttpMethod and/or ResourcMethods) of the endpoint.
*
@@ -198,6 +213,9 @@
private void refreshUriPathTemplate() {
// compute the URI Path Template from the chain of Methods/Resources
StringBuilder uriPathTemplateBuilder = new StringBuilder();
+ if(application != null) {
+ uriPathTemplateBuilder.append(application.getApplicationPath());
+ }
for (JaxrsResourceMethod resourceMethod : resourceMethods) {
if (resourceMethod.getParentResource().getPathTemplate() != null) {
uriPathTemplateBuilder.append("/").append(resourceMethod.getParentResource().getPathTemplate());
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsMetamodel.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsMetamodel.java 2012-01-06
04:09:33 UTC (rev 37668)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsMetamodel.java 2012-01-06
08:06:06 UTC (rev 37669)
@@ -44,16 +44,14 @@
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsResourceMethod;
/**
- * Manages all the JAX-RS domain classes of the JAX-RS Metamodel. Not only a
- * POJO, but also provides business services.
+ * Manages all the JAX-RS domain classes of the JAX-RS Metamodel. Not only a POJO, but
also provides business services.
*
* @author xcoulon
*/
public class JaxrsMetamodel implements IJaxrsMetamodel {
/**
- * The qualified name of the metamodel when stored in the project session
- * properties.
+ * The qualified name of the metamodel when stored in the project session properties.
*/
public static final QualifiedName METAMODEL_QUALIFIED_NAME = new
QualifiedName(JBossJaxrsCorePlugin.PLUGIN_ID,
"metamodel");
@@ -65,21 +63,19 @@
private String serviceUri = "/";
/**
- * All the subclasses of <code>javax.ws.rs.core.Application</code>,
although
- * there should be only one.
+ * All the subclasses of <code>javax.ws.rs.core.Application</code>, although
there should be only one.
*/
private final List<JaxrsApplication> applications = new
ArrayList<JaxrsApplication>();
/**
- * All the resources (both rootresources and subresources) available in the
- * service , indexed by their associated java type fully qualified name.
+ * All the resources (both rootresources and subresources) available in the service ,
indexed by their associated
+ * java type fully qualified name.
*/
private final List<JaxrsResource> resources = new
ArrayList<JaxrsResource>();
/**
- * The available providers (classes which implement MessageBodyWriter<T>,
- * MessageBodyReader<T> or ExceptionMapper<T>), , indexed by their
- * associated java type fully qualified name.
+ * The available providers (classes which implement MessageBodyWriter<T>,
MessageBodyReader<T> or
+ * ExceptionMapper<T>), , indexed by their associated java type fully qualified
name.
*/
private final List<JaxrsProvider> providers = new
ArrayList<JaxrsProvider>();
@@ -106,10 +102,7 @@
/*
* (non-Javadoc)
- *
- * @see
- * org.jboss.tools.ws.jaxrs.core.internal.metamodel.IMetamodel#getJavaProject
- * ()
+ * @see org.jboss.tools.ws.jaxrs.core.internal.metamodel.IMetamodel#getJavaProject ()
*/
public IJavaProject getJavaProject() {
return javaProject;
@@ -146,6 +139,7 @@
public void add(JaxrsElement<?> element) {
switch (element.getElementKind()) {
case APPLICATION:
+ this.applications.add((JaxrsApplication) element);
break;
case HTTP_METHOD:
this.httpMethods.add((JaxrsHttpMethod) element);
@@ -157,22 +151,6 @@
final JaxrsResource resource = (JaxrsResource) element;
this.resources.add(resource);
break;
-
- // case RESOURCE_FIELD:
- // final JaxrsResource fieldParent = findResource((IType)
- // element.getJavaElement().getParent());
- // if (fieldParent != null) {
- // fieldParent.addField((JaxrsParamField) element);
- // }
- // break;
- // case RESOURCE_METHOD:
- // final JaxrsResource methodParent = findResource((IType)
- // element.getJavaElement().getParent());
- // if (methodParent != null) {
- // methodParent.addMethod((IJaxrsResourceMethod) element);
- // }
- // break;
- //
}
indexElement(element);
}
@@ -263,9 +241,8 @@
}
/**
- * Unindex the given JAX-RS Element so that it cannot be retrieved when
- * searching for elements with the given handleIdentifier. This does not
- * mean that the given JAX-RS Element won't be findable anymore.
+ * Unindex the given JAX-RS Element so that it cannot be retrieved when searching for
elements with the given
+ * handleIdentifier. This does not mean that the given JAX-RS Element won't be
findable anymore.
*
* @param jaxrsElement
* @param handleIdentifier
@@ -277,29 +254,26 @@
}
}
- /*
- * (non-Javadoc)
- *
- * @see
- * org.jboss.tools.ws.jaxrs.core.internal.metamodel.IMetamodel#getProviders
- * ()
+ /**
+ * @return the application that is used to compute the Endpoint's URI Path
Templates, or null if no application was
+ * specified in the code. An invalid application may be returned, though (ie, a
Type annotated with
+ * {@link javax.ws.rs.ApplicationPath} but not extending the {@link
javax.ws.rs.Application} type).
*/
+ public final JaxrsApplication getApplication() {
+ if (applications.isEmpty()) {
+ return null;
+ }
+ return applications.get(0);
+ }
+
+ public final List<JaxrsApplication> getAllApplications() {
+ return Collections.unmodifiableList(new
ArrayList<JaxrsApplication>(applications));
+ }
+
public final List<IJaxrsProvider> getAllProviders() {
return Collections.unmodifiableList(new ArrayList<IJaxrsProvider>(providers));
}
- /**
- * @param field
- * @param iJavaElement
- * @return private JaxrsResource findResource(final IType javaElement) {
- * final String targetIdentifier =
- * javaElement.getHandleIdentifier(); for (IJaxrsResource resource :
- * resources) { final String resourceIdentifier =
- * resource.getJavaElement().getHandleIdentifier(); if
- * (resourceIdentifier.equals(targetIdentifier)) { return
- * (JaxrsResource) resource; } } return null; }
- */
-
public final List<IJaxrsHttpMethod> getAllHttpMethods() {
return Collections.unmodifiableList(new
ArrayList<IJaxrsHttpMethod>(httpMethods));
}
@@ -349,8 +323,7 @@
}
/**
- * Report errors from the given markers into the JAX-RS element(s)
- * associated with the given compiltation unit.
+ * Report errors from the given markers into the JAX-RS element(s) associated with the
given compiltation unit.
*
* @param compilationUnit
* the compilation unit
@@ -379,11 +352,9 @@
}
/**
- * Resets this metamodel for further re-use (ie, before a new 'full/clean'
- * build). Keeping the same instance of Metamodel in the project's session
- * properties is a convenient thing, especially on the UI side, where some
- * caching system is use to maintain the state of nodes in the Common
- * Navigator (framework).
+ * Resets this metamodel for further re-use (ie, before a new 'full/clean'
build). Keeping the same instance of
+ * Metamodel in the project's session properties is a convenient thing, especially
on the UI side, where some
+ * caching system is use to maintain the state of nodes in the Common Navigator
(framework).
*/
public void reset() {
Logger.debug("Reseting the JAX-RS Metamodel fpr project {}",
this.javaProject.getElementName());
@@ -468,7 +439,7 @@
final List<T> elements = new ArrayList<T>();
if (elementsIndex.containsKey(key)) {
for (JaxrsElement<?> element : elementsIndex.get(key)) {
- if (element.getClass().isAssignableFrom(T)) {
+ if (element.getClass().isAssignableFrom(T) || T.isAssignableFrom(element.getClass()))
{
elements.add((T) element);
}
}
@@ -487,6 +458,9 @@
return;
}
switch (element.getElementKind()) {
+ case APPLICATION:
+ this.applications.remove(element);
+ break;
case HTTP_METHOD:
this.httpMethods.remove(element);
break;
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsResource.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsResource.java 2012-01-06
04:09:33 UTC (rev 37668)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsResource.java 2012-01-06
08:06:06 UTC (rev 37669)
@@ -42,7 +42,7 @@
public class JaxrsResource extends JaxrsElement<IType> implements IJaxrsResource {
/** Optional Application. */
- private final JaxrsApplication application = null;
+ private final JaxrsAnnotatedTypeApplication application = null;
private final Map<String, JaxrsResourceField> resourceFields = new
HashMap<String, JaxrsResourceField>();
@@ -62,17 +62,17 @@
this.metamodel = metamodel;
}
- public Builder pathTemplate(Annotation pathAnnotation) {
+ public Builder pathTemplate(final Annotation pathAnnotation) {
this.pathAnnotation = pathAnnotation;
return this;
}
- public Builder consumes(Annotation consumesAnnotation) {
+ public Builder consumes(final Annotation consumesAnnotation) {
this.consumesAnnotation = consumesAnnotation;
return this;
}
- public Builder produces(Annotation producesAnnotation) {
+ public Builder produces(final Annotation producesAnnotation) {
this.producesAnnotation = producesAnnotation;
return this;
}
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JaxrsAnnotationsScanner.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JaxrsAnnotationsScanner.java 2012-01-06
04:09:33 UTC (rev 37668)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JaxrsAnnotationsScanner.java 2012-01-06
08:06:06 UTC (rev 37669)
@@ -14,6 +14,7 @@
import java.util.ArrayList;
import java.util.List;
+import javax.ws.rs.ApplicationPath;
import javax.ws.rs.HttpMethod;
import javax.ws.rs.Path;
import javax.ws.rs.ext.Provider;
@@ -32,8 +33,7 @@
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsHttpMethod;
/**
- * Class that scan the projec's classpath to find JAX-RS Resources and
- * Providers.
+ * Class that scan the projec's classpath to find JAX-RS Resources and Providers.
*/
public final class JaxrsAnnotationsScanner {
@@ -43,8 +43,10 @@
}
/**
- * Returns all JAX-RS providers in the given scope (ex : javaProject), ie,
- * types annotated with <code>javax.ws.rs.ext.Provider</code> annotation.
+ * Returns all JAX-RS Applications in the given scope (ex : javaProject), ie, types
annotated with
+ * <code>javax.ws.rs.ApplicationPath</code> annotation. Those types should
be subtypes of
+ * {@link javax.ws.rs.Application}, but this will be verified at validation time,
eventually reporting the
+ * missing/wrong super type (hierarchy).
*
*
* @param scope
@@ -57,6 +59,29 @@
* @throws CoreException
* in case of exception
*/
+ public static List<IType> findApplicationTypes(final IJavaElement scope, final
IProgressMonitor progressMonitor)
+ throws CoreException {
+ IJavaSearchScope searchScope = null;
+ searchScope = SearchEngine.createJavaSearchScope(new IJavaElement[] { scope },
IJavaSearchScope.SOURCES
+ | IJavaSearchScope.REFERENCED_PROJECTS);
+ return searchForAnnotatedTypes(ApplicationPath.class, searchScope, progressMonitor);
+ }
+
+ /**
+ * Returns all JAX-RS providers in the given scope (ex : javaProject), ie, types
annotated with
+ * <code>javax.ws.rs.ext.Provider</code> annotation.
+ *
+ *
+ * @param scope
+ * the search scope (project, compilation unit, type, etc.)
+ * @param includeLibraries
+ * include project libraries in search scope or not
+ * @param progressMonitor
+ * the progress monitor
+ * @return providers the JAX-RS provider types
+ * @throws CoreException
+ * in case of exception
+ */
public static List<IType> findProviderTypes(final IJavaElement scope, final
boolean includeLibraries,
final IProgressMonitor progressMonitor) throws CoreException {
IJavaSearchScope searchScope = null;
@@ -71,9 +96,8 @@
}
/**
- * Returns all JAX-RS resources resourceMethods (ie, class resourceMethods
- * annotated with an @HttpMethod annotation) in the given scope (ex :
- * javaProject).
+ * Returns all JAX-RS resources resourceMethods (ie, class resourceMethods annotated
with an @HttpMethod annotation)
+ * in the given scope (ex : javaProject).
*
* @param scope
* the search scope (project, compilation unit, type, etc.)
@@ -81,12 +105,11 @@
* the fully qualified names of the HttpMethod java types.
* @param progressMonitor
* the progress monitor
- * @return JAX-RS resource resourceMethods in a map, indexed by the
- * declaring type of the resourceMethods
+ * @return JAX-RS resource resourceMethods in a map, indexed by the declaring type of
the resourceMethods
* @throws CoreException
* in case of underlying exception
*/
- public static List<IType> findResources(final IJavaElement scope, final
IProgressMonitor progressMonitor)
+ public static List<IType> findResourceTypes(final IJavaElement scope, final
IProgressMonitor progressMonitor)
throws CoreException {
IJavaSearchScope searchScope = SearchEngine.createJavaSearchScope(new IJavaElement[] {
scope },
IJavaSearchScope.SOURCES | IJavaSearchScope.REFERENCED_PROJECTS);
@@ -102,9 +125,8 @@
}
/**
- * Returns all HTTP Methods (ie, annotation meta-annotated with the
- * <code>javax.ws.rs.HttpMethod</code> annotation) in the given scope (ex :
- * javaProject).
+ * Returns all HTTP Methods (ie, annotation meta-annotated with the
<code>javax.ws.rs.HttpMethod</code> annotation)
+ * in the given scope (ex : javaProject).
*
* @param scope
* the search scope (project, compilation unit, type, etc.)
@@ -114,7 +136,7 @@
* @throws CoreException
* in case of underlying exceptions.
*/
- public static List<IType> findHTTPMethodTypes(final IJavaElement scope, final
IProgressMonitor progressMonitor)
+ public static List<IType> findHttpMethodTypes(final IJavaElement scope, final
IProgressMonitor progressMonitor)
throws CoreException {
IJavaSearchScope searchScope = null;
if (scope instanceof IJavaProject) {
@@ -127,8 +149,7 @@
}
/**
- * Search for types that are annotated with the given annotation name, in
- * the given search scope.
+ * Search for types that are annotated with the given annotation name, in the given
search scope.
*
* @param annotationName
* the annotation type name
@@ -154,19 +175,16 @@
}
/**
- * Returns all JAX-RS resources resourceMethods (ie, class resourceMethods
- * annotated with an @HttpMethod annotation) in the given scope (ex :
- * javaProject).
+ * Returns all JAX-RS resources resourceMethods (ie, class resourceMethods annotated
with an @HttpMethod annotation)
+ * in the given scope (ex : javaProject).
*
* @param scope
* the search scope
* @param list
- * the types annotated with <code>javax.ws.rs.HttpMethod</code>
- * annotation
+ * the types annotated with <code>javax.ws.rs.HttpMethod</code>
annotation
* @param progressMonitor
* the progress monitor
- * @return JAX-RS resource resourceMethods in a map, indexed by the
- * declaring type of the resourceMethods
+ * @return JAX-RS resource resourceMethods in a map, indexed by the declaring type of
the resourceMethods
* @throws CoreException
* in case of underlying exception
*/
@@ -183,8 +201,7 @@
}
/**
- * Search for methods annotated with one of the given annotations, in the
- * search scope.
+ * Search for methods annotated with one of the given annotations, in the search scope.
*
* @param annotationNames
* the annotations fully qualified names
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/JaxrsMetamodelChangedEvent.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/JaxrsMetamodelChangedEvent.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/JaxrsMetamodelChangedEvent.java 2012-01-06
08:06:06 UTC (rev 37669)
@@ -0,0 +1,43 @@
+/**
+ *
+ */
+package org.jboss.tools.ws.jaxrs.core.metamodel;
+
+import java.util.ArrayList;
+import java.util.EventObject;
+import java.util.List;
+
+import
org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsEndpointChangedEvent;
+
+/**
+ * @author Xavier Coulon
+ *
+ */
+public class JaxrsMetamodelChangedEvent extends EventObject {
+
+ /**
+ * generated Serial Version UID.
+ */
+ private static final long serialVersionUID = -5946354315088280844L;
+
+ /** List of underlying JarxEndpoints change events carried by this event.*/
+ private final List<IJaxrsEndpointChangedEvent> endpointChangedEvents;
+
+ /**
+ * Full constructor.
+ * @param events
+ */
+ public JaxrsMetamodelChangedEvent(List<JaxrsEndpointChangedEvent> events) {
+ super(events);
+ this.endpointChangedEvents = new ArrayList<IJaxrsEndpointChangedEvent>(events);
+ }
+
+ /**
+ * @return the endpointChangedEvents
+ */
+ public List<IJaxrsEndpointChangedEvent> getEndpointChangedEvents() {
+ return endpointChangedEvents;
+ }
+
+
+}
Property changes on:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/JaxrsMetamodelChangedEvent.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/plugin.xml
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/plugin.xml 2012-01-06 04:09:33 UTC (rev
37668)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/plugin.xml 2012-01-06 08:06:06 UTC (rev
37669)
@@ -12,6 +12,7 @@
</contentExtension>
</includes>
</viewerContentBinding>
+
<viewerContentBinding
viewerId="org.eclipse.ui.navigator.ProjectExplorer">
<includes>
@@ -21,6 +22,7 @@
</contentExtension>
</includes>
</viewerContentBinding>
+
<!-- Viewer content binding for our Custom implementation of
o.e.ui.navigator.CommonNavigator : keep for later-->
<!--viewer
viewerId="org.jboss.tools.ws.jaxrs.ui.viewpart.OutlineView">
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriMappingsContentProvider.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriMappingsContentProvider.java 2012-01-06
04:09:33 UTC (rev 37668)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriMappingsContentProvider.java 2012-01-06
08:06:06 UTC (rev 37669)
@@ -14,6 +14,7 @@
import java.util.Date;
import java.util.EventObject;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.eclipse.core.resources.IProject;
@@ -28,6 +29,7 @@
import org.eclipse.swt.widgets.Display;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsEndpoint;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsEndpointChangedEvent;
+import org.jboss.tools.ws.jaxrs.core.metamodel.JaxrsMetamodelChangedEvent;
import org.jboss.tools.ws.jaxrs.core.metamodel.JaxrsMetamodelLocator;
import org.jboss.tools.ws.jaxrs.core.pubsub.EventService;
import org.jboss.tools.ws.jaxrs.core.pubsub.Subscriber;
@@ -59,13 +61,17 @@
if (!uriPathTemplateCategories.containsKey(project)) {
if (JaxrsMetamodelLocator.get(project) == null) {
Logger.debug("JAX-RS Metamodel needs to be built for project '" +
project.getName() + "'");
- Job buildJob = CoreUtility.getBuildJob(project);
- buildJob.setRule(ResourcesPlugin.getWorkspace().getRoot());
- buildJob.schedule();
+ // this piece of code must run in an async manner to avoid reentrant call while
viewer is busy.
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ Job buildJob = CoreUtility.getBuildJob(project);
+ buildJob.setRule(ResourcesPlugin.getWorkspace().getRoot());
+ buildJob.schedule();
+ }
+ });
return new Object[] { new WaitWhileBuildingElement() };
}
- UriPathTemplateCategory uriPathTemplateCategory = new UriPathTemplateCategory(this,
project);
- uriPathTemplateCategories.put(project, uriPathTemplateCategory);
}
return new Object[] { uriPathTemplateCategories.get(project) };
} catch (CoreException e) {
@@ -111,13 +117,16 @@
}
/*
- * @Override public void resourceChanged(IResourceChangeEvent event) {
- * refreshChangedProjects(event.getDelta()); }
+ * @Override public void resourceChanged(IResourceChangeEvent event) {
refreshChangedProjects(event.getDelta()); }
*/
@Override
public void inform(EventObject event) {
- if (event instanceof IJaxrsEndpointChangedEvent) {
+ //FIXME: should receive a single JaxrsMetamodelChangedEvent containing 0 or more
IJaxrsEndpointChangedEvent(s)
+ if (event instanceof JaxrsMetamodelChangedEvent) {
+ final JaxrsMetamodelChangedEvent metamodelChangedEvent = (JaxrsMetamodelChangedEvent)
event;
+ final List<IJaxrsEndpointChangedEvent> endpointChangedEvents =
metamodelChangedEvent.getEndpointChangedEvents();
+
final IJaxrsEndpointChangedEvent change = (IJaxrsEndpointChangedEvent) event;
final IJaxrsEndpoint endpoint = change.getEndpoint();
refreshContent(endpoint.getJavaProject().getProject());
@@ -128,6 +137,8 @@
Logger.debug("Refreshing navigator view");
final Object target = uriPathTemplateCategories.containsKey(project) ?
uriPathTemplateCategories.get(project)
: project;
+ UriPathTemplateCategory uriPathTemplateCategory = new UriPathTemplateCategory(this,
project);
+ uriPathTemplateCategories.put(project, uriPathTemplateCategory);
// this piece of code must run in an async manner to avoid reentrant call while viewer
is busy.
Display.getDefault().asyncExec(new Runnable() {
@Override
@@ -140,6 +151,7 @@
}
});
}
+
@Override
/**
* Subscriber ID
Added:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/projects/org.jboss.tools.ws.jaxrs.tests.sampleproject/src/main/java/org/jboss/tools/ws/jaxrs/sample/services/RestApplication.java
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/projects/org.jboss.tools.ws.jaxrs.tests.sampleproject/src/main/java/org/jboss/tools/ws/jaxrs/sample/services/RestApplication.java
(rev 0)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/projects/org.jboss.tools.ws.jaxrs.tests.sampleproject/src/main/java/org/jboss/tools/ws/jaxrs/sample/services/RestApplication.java 2012-01-06
08:06:06 UTC (rev 37669)
@@ -0,0 +1,10 @@
+package org.jboss.tools.ws.jaxrs.sample.services;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+@SuppressWarnings("unused")
+@ApplicationPath("/app")
+public class RestApplication extends Application {
+
+}
Property changes on:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/projects/org.jboss.tools.ws.jaxrs.tests.sampleproject/src/main/java/org/jboss/tools/ws/jaxrs/sample/services/RestApplication.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/AllTests.java
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/AllTests.java 2012-01-06
04:09:33 UTC (rev 37668)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/AllTests.java 2012-01-06
08:06:06 UTC (rev 37669)
@@ -24,6 +24,7 @@
import
org.jboss.tools.ws.jaxrs.core.internal.metamodel.validation.JaxrsMetamodelValidatorTestCase;
import org.jboss.tools.ws.jaxrs.core.internal.utils.CollectionUtilsTestCase;
import org.jboss.tools.ws.jaxrs.core.jdt.CompilationUnitsRepositoryTestCase;
+import org.jboss.tools.ws.jaxrs.core.jdt.JaxrsAnnotationScannerTestCase;
import org.jboss.tools.ws.jaxrs.core.jdt.JdtUtilsTestCase;
import org.jboss.tools.ws.jaxrs.core.pubsub.PubSubServiceTestCase;
import org.junit.runner.RunWith;
@@ -37,7 +38,8 @@
JaxrsElementChangedProcessorTestCase.class, JaxrsMetamodelTestCase.class,
JaxrsElementFactoryTestCase.class, JaxrsMetamodelBuilderTestCase.class,
CollectionUtilsTestCase.class,
PubSubServiceTestCase.class, JaxrsMetamodelValidatorTestCase.class,
- ResourceChangedProcessorTestCase.class, ResourceChangedListenerTestCase.class})
+ ResourceChangedProcessorTestCase.class, ResourceChangedListenerTestCase.class,
+ JaxrsAnnotationScannerTestCase.class})
public class AllTests {
}
Modified:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedProcessorTestCase.java
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedProcessorTestCase.java 2012-01-06
04:09:33 UTC (rev 37668)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedProcessorTestCase.java 2012-01-06
08:06:06 UTC (rev 37669)
@@ -43,6 +43,7 @@
import java.util.List;
import java.util.Map;
+import javax.ws.rs.ApplicationPath;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
@@ -76,6 +77,8 @@
import org.jboss.tools.ws.jaxrs.core.AbstractCommonTestCase;
import org.jboss.tools.ws.jaxrs.core.JBossJaxrsCorePlugin;
import org.jboss.tools.ws.jaxrs.core.WorkbenchUtils;
+import
org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsAnnotatedTypeApplication;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsApplication;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsHttpMethod;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsMetamodel;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsResource;
@@ -186,9 +189,9 @@
final JavaElementChangedEvent event = createEvent(sourceFolder, ADDED);
final List<JaxrsElementChangedEvent> impacts = processEvent(event,
progressMonitor);
// verifications
- // 1 HttpMethod + 3 RootResources + 2 Subresources + all their methods and fields
(total of 16)..
- assertThat(impacts.size(), equalTo(22));
- assertThat(metamodel.getElements(javaProject).size(), equalTo(26)); // 4 previous
HttpMethods + 22 added items
+ // 1 Application + 1 HttpMethod + 3 RootResources + 2 Subresources + all their methods
and fields (total of 16)..
+ assertThat(impacts.size(), equalTo(23));
+ assertThat(metamodel.getElements(javaProject).size(), equalTo(27)); // 4 previous
HttpMethods + 23 added items
assertThat(impacts, everyItem(Matchers.<JaxrsElementChangedEvent>
hasProperty("deltaKind", equalTo(ADDED))));
}
@@ -208,6 +211,221 @@
}
@Test
+ public void shouldAddApplicationWhenAddingSourceCompilationUnit() throws CoreException
{
+ // pre-conditions
+ final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
+ javaProject, progressMonitor);
+ // operation
+ final JavaElementChangedEvent event = createEvent(type.getCompilationUnit(), ADDED);
+ final List<JaxrsElementChangedEvent> impacts = processEvent(event,
progressMonitor);
+ // verifications
+ assertThat(impacts.size(), equalTo(1));
+ assertThat(impacts.get(0).getElement().getElementKind(),
equalTo(EnumElementKind.APPLICATION));
+ assertThat(impacts.get(0).getDeltaKind(), equalTo(ADDED));
+ assertThat(((JaxrsApplication) impacts.get(0).getElement()).getApplicationPath(),
equalTo("/app"));
+ verify(metamodel, times(1)).add(any(JaxrsApplication.class));
+ assertThat(metamodel.getElements(javaProject).size(), equalTo(1));
+ }
+
+ @Test
+ public void shouldAddApplicationWhenAddingSourceType() throws CoreException {
+ // pre-conditions
+ final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
+ javaProject, progressMonitor);
+ // operation
+ final JavaElementChangedEvent event = createEvent(type, ADDED);
+ final List<JaxrsElementChangedEvent> impacts = processEvent(event,
progressMonitor);
+ // verifications
+ assertThat(impacts.size(), equalTo(1));
+ assertThat(impacts.get(0).getElement().getElementKind(),
equalTo(EnumElementKind.APPLICATION));
+ assertThat(impacts.get(0).getDeltaKind(), equalTo(ADDED));
+ assertThat(((JaxrsApplication) impacts.get(0).getElement()).getApplicationPath(),
equalTo("/app"));
+ verify(metamodel, times(1)).add(any(JaxrsApplication.class));
+ assertThat(metamodel.getElements(javaProject).size(), equalTo(1));
+ }
+
+ @Test
+ public void shouldAddApplicationWhenAddingApplicationPathAnnotation() throws
CoreException {
+ // pre-conditions
+ final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
+ javaProject, progressMonitor);
+ final Annotation annotation = getAnnotation(type, ApplicationPath.class);
+ // operation
+ final JavaElementChangedEvent event = createEvent(annotation, ADDED);
+ final List<JaxrsElementChangedEvent> impacts = processEvent(event,
progressMonitor);
+ // verifications
+ assertThat(impacts.size(), equalTo(1));
+ assertThat(impacts.get(0).getElement().getElementKind(),
equalTo(EnumElementKind.APPLICATION));
+ assertThat(impacts.get(0).getDeltaKind(), equalTo(ADDED));
+ assertThat(((JaxrsApplication) impacts.get(0).getElement()).getApplicationPath(),
equalTo("/app"));
+ verify(metamodel, times(1)).add(any(JaxrsApplication.class));
+ assertThat(metamodel.getElements(javaProject).size(), equalTo(1));
+ }
+
+ @Test
+ public void shouldDoNothingWhenAddingUnrelatedAnnotationOnApplication() throws
CoreException {
+ // pre-conditions
+ final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
+ javaProject, progressMonitor);
+ final JaxrsApplication application = new JaxrsAnnotatedTypeApplication(type,
getAnnotation(type, ApplicationPath.class), metamodel);
+ metamodel.add(application);
+ final Annotation annotation = getAnnotation(type, SuppressWarnings.class);
+ // operation
+ final JavaElementChangedEvent event = createEvent(annotation, ADDED);
+ final List<JaxrsElementChangedEvent> impacts = processEvent(event,
progressMonitor);
+ // verifications
+ assertThat(impacts.size(), equalTo(0));
+ verify(metamodel, times(1)).add(any(JaxrsApplication.class)); // one call, during
pre-conditions
+ assertThat(metamodel.getElements(javaProject).size(), equalTo(1));
+ }
+
+ @Test
+ public void shouldUpdateApplicationWhenChangingAnnotationValue() throws CoreException {
+ // pre-conditions
+ final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
+ javaProject, progressMonitor);
+ final Annotation annotation = getAnnotation(type, ApplicationPath.class,
"/bar");
+ final JaxrsApplication application = new JaxrsAnnotatedTypeApplication(type,
annotation, metamodel);
+ metamodel.add(application);
+ // operation
+ final JavaElementChangedEvent event = createEvent(annotation, CHANGED);
+ final List<JaxrsElementChangedEvent> impacts = processEvent(event,
progressMonitor);
+ // verifications
+ assertThat(impacts.size(), equalTo(1));
+ assertThat(impacts.get(0).getElement().getElementKind(),
equalTo(EnumElementKind.APPLICATION));
+ assertThat(impacts.get(0).getDeltaKind(), equalTo(CHANGED));
+ assertThat(((JaxrsApplication) impacts.get(0).getElement()).getApplicationPath(),
equalTo("/app"));
+ assertThat(metamodel.getElements(javaProject).size(), equalTo(1));
+ }
+
+ @Test
+ public void shouldDoNothingWhenAnnotationValueRemainsSameOnApplication() throws
CoreException {
+ // pre-conditions
+ final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
+ javaProject, progressMonitor);
+ final Annotation annotation = getAnnotation(type, ApplicationPath.class);
+ final JaxrsApplication application = new JaxrsAnnotatedTypeApplication(type,
annotation, metamodel);
+ metamodel.add(application);
+ // operation
+ final JavaElementChangedEvent event = createEvent(annotation, CHANGED);
+ final List<JaxrsElementChangedEvent> impacts = processEvent(event,
progressMonitor);
+ // verifications
+ assertThat(impacts.size(), equalTo(0));
+ assertThat(metamodel.getElements(javaProject).size(), equalTo(1));
+ }
+
+ @Test
+ public void shouldDoNothingWhenChangingUnrelatedApplicationAnnotationValue() throws
CoreException {
+ // pre-conditions
+ final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
+ javaProject, progressMonitor);
+ final Annotation annotation = getAnnotation(type, ApplicationPath.class);
+ final JaxrsApplication application = new JaxrsAnnotatedTypeApplication(type,
annotation, metamodel);
+ metamodel.add(application);
+ final Annotation suppressWarningsAnnotation = getAnnotation(type,
SuppressWarnings.class);
+ // operation
+ final JavaElementChangedEvent event = createEvent(suppressWarningsAnnotation,
CHANGED);
+ final List<JaxrsElementChangedEvent> impacts = processEvent(event,
progressMonitor);
+ // verifications
+ assertThat(impacts.size(), equalTo(0));
+ assertThat(metamodel.getElements(javaProject).size(), equalTo(1));
+ }
+
+ @Test
+ public void shouldRemoveApplicationWhenRemovingCompilationUnit() throws CoreException {
+ // pre-conditions
+ final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
+ javaProject, progressMonitor);
+ final Annotation annotation = getAnnotation(type, ApplicationPath.class);
+ final JaxrsApplication application = new JaxrsAnnotatedTypeApplication(type,
annotation, metamodel);
+ metamodel.add(application);
+ // operation
+ final JavaElementChangedEvent event = createEvent(type.getCompilationUnit(), REMOVED);
+ final List<JaxrsElementChangedEvent> impacts = processEvent(event,
progressMonitor);
+ // verifications
+ assertThat(impacts.size(), equalTo(1));
+ assertThat(impacts.get(0).getElement().getElementKind(),
equalTo(EnumElementKind.APPLICATION));
+ assertThat(impacts.get(0).getDeltaKind(), equalTo(REMOVED));
+ assertThat(((JaxrsApplication) impacts.get(0).getElement()), equalTo(application));
+ assertThat(metamodel.getElements(javaProject).size(), equalTo(0));
+ }
+
+ @Test
+ public void shouldRemoveApplicationWhenRemovingSourceType() throws CoreException {
+ // pre-conditions
+ final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
+ javaProject, progressMonitor);
+ final Annotation annotation = getAnnotation(type, ApplicationPath.class);
+ final JaxrsApplication application = new JaxrsAnnotatedTypeApplication(type,
annotation, metamodel);
+ metamodel.add(application);
+ // operation
+ final JavaElementChangedEvent event = createEvent(type, REMOVED);
+ final List<JaxrsElementChangedEvent> impacts = processEvent(event,
progressMonitor);
+ // verifications
+ assertThat(impacts.size(), equalTo(1));
+ assertThat(impacts.get(0).getElement().getElementKind(),
equalTo(EnumElementKind.APPLICATION));
+ assertThat(impacts.get(0).getDeltaKind(), equalTo(REMOVED));
+ assertThat(((JaxrsApplication) impacts.get(0).getElement()).getApplicationPath(),
equalTo("/app"));
+ assertThat(metamodel.getElements(javaProject).size(), equalTo(0));
+ }
+
+ @Test
+ public void shouldRemoveApplicationWhenRemovingAnnotation() throws CoreException {
+ // pre-conditions
+ final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
+ javaProject, progressMonitor);
+ final Annotation annotation = getAnnotation(type, ApplicationPath.class);
+ final JaxrsApplication application = new JaxrsAnnotatedTypeApplication(type,
annotation, metamodel);
+ metamodel.add(application);
+ // operation
+ final JavaElementChangedEvent event = createEvent(annotation, REMOVED);
+ final List<JaxrsElementChangedEvent> impacts = processEvent(event,
progressMonitor);
+ // verifications
+ assertThat(impacts.size(), equalTo(1));
+ assertThat(impacts.get(0).getElement().getElementKind(),
equalTo(EnumElementKind.APPLICATION));
+ assertThat(impacts.get(0).getDeltaKind(), equalTo(REMOVED));
+ assertThat(impacts.get(0).getElement(), is(notNullValue()));
+ assertThat(metamodel.getElements(javaProject).size(), equalTo(0));
+ }
+
+ @Test
+ public void shouldDoNothingWhenRemovingUnrelatedAnnotationOnApplication() throws
CoreException {
+ // pre-conditions
+ final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
+ javaProject, progressMonitor);
+ final Annotation annotation = getAnnotation(type, ApplicationPath.class);
+ final JaxrsApplication application = new JaxrsAnnotatedTypeApplication(type,
annotation, metamodel);
+ metamodel.add(application);
+ // operation
+ final JavaElementChangedEvent event = createEvent(getAnnotation(type,
SuppressWarnings.class), REMOVED);
+ final List<JaxrsElementChangedEvent> impacts = processEvent(event,
progressMonitor);
+ // verifications
+ assertThat(impacts.size(), equalTo(0));
+ assertThat(metamodel.getElements(javaProject).size(), equalTo(1));
+ }
+
+ @Test
+ public void shouldRemoveApplicationWhenRemovingSourceFolder() throws CoreException {
+ // pre-conditions
+ final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
+ javaProject, progressMonitor);
+ final Annotation annotation = getAnnotation(type, ApplicationPath.class);
+ final JaxrsApplication application = new JaxrsAnnotatedTypeApplication(type,
annotation, metamodel);
+ metamodel.add(application);
+ final IPackageFragmentRoot sourceFolder =
WorkbenchUtils.getPackageFragmentRoot(javaProject, "src/main/java",
+ progressMonitor);
+ // operation
+ final JavaElementChangedEvent event = createEvent(sourceFolder, REMOVED);
+ final List<JaxrsElementChangedEvent> impacts = processEvent(event,
progressMonitor);
+ // verifications
+ assertThat(impacts.size(), equalTo(1));
+ assertThat(impacts.get(0).getElement().getElementKind(),
equalTo(EnumElementKind.APPLICATION));
+ assertThat(impacts.get(0).getElement(), is(notNullValue()));
+ assertThat(impacts.get(0).getDeltaKind(), equalTo(REMOVED));
+ assertThat(metamodel.getElements(javaProject).size(), equalTo(0));
+ }
+
+ @Test
public void shouldAddHttpMethodWhenAddingSourceCompilationUnit() throws CoreException {
// pre-conditions
final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.FOO",
javaProject,
@@ -260,7 +478,7 @@
}
@Test
- public void shouldDoNothingWhenAddingUnrelatedAnnotation() throws CoreException {
+ public void shouldDoNothingWhenAddingUnrelatedAnnotationOnHttpMethod() throws
CoreException {
// pre-conditions
final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.FOO",
javaProject,
progressMonitor);
@@ -1921,11 +2139,11 @@
final IMethod method = getMethod(type, "getPicture");
final JavaMethodParameter startParameter = new JavaMethodParameter("id",
Integer.class.getName(),
Arrays.asList(createAnnotation(PathParam.class, "id")));
- final JavaMethodParameter sizeParameter = new JavaMethodParameter("color",
String.class.getName(), new ArrayList<Annotation>());
+ final JavaMethodParameter sizeParameter = new JavaMethodParameter("color",
String.class.getName(),
+ new ArrayList<Annotation>());
final JaxrsResourceMethod jaxrsMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
.httpMethod(getAnnotation(method,
GET.class)).returnType(getType("java.lang.Object", javaProject))
- .methodParameter(startParameter).methodParameter(sizeParameter)
- .build();
+ .methodParameter(startParameter).methodParameter(sizeParameter).build();
metamodel.add(jaxrsMethod);
// operation
final JavaElementChangedEvent event = createEvent(method, CHANGED, F_SIGNATURE);
@@ -1953,12 +2171,11 @@
final IMethod method = getMethod(type, "getPicture");
final JavaMethodParameter startParameter = new JavaMethodParameter("id",
Integer.class.getName(),
Arrays.asList(createAnnotation(PathParam.class, "id")));
- final JavaMethodParameter sizeParameter = new JavaMethodParameter("color",
String.class.getName(), Arrays.asList(
- createAnnotation(MatrixParam.class, "foo")));
+ final JavaMethodParameter sizeParameter = new JavaMethodParameter("color",
String.class.getName(),
+ Arrays.asList(createAnnotation(MatrixParam.class, "foo")));
final JaxrsResourceMethod jaxrsMethod = new JaxrsResourceMethod.Builder(method,
resource, metamodel)
.httpMethod(getAnnotation(method,
GET.class)).returnType(getType("java.lang.Object", javaProject))
- .methodParameter(startParameter).methodParameter(sizeParameter)
- .build();
+ .methodParameter(startParameter).methodParameter(sizeParameter).build();
metamodel.add(jaxrsMethod);
// operation
final JavaElementChangedEvent event = createEvent(method, CHANGED, F_SIGNATURE);
Modified:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsElementChangedProcessorTestCase.java
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsElementChangedProcessorTestCase.java 2012-01-06
04:09:33 UTC (rev 37668)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsElementChangedProcessorTestCase.java 2012-01-06
08:06:06 UTC (rev 37669)
@@ -29,6 +29,7 @@
import java.util.LinkedList;
import java.util.List;
+import javax.ws.rs.ApplicationPath;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.HttpMethod;
@@ -44,6 +45,8 @@
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.jboss.tools.ws.jaxrs.core.AbstractCommonTestCase;
+import
org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsAnnotatedTypeApplication;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsApplication;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsEndpoint;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsHttpMethod;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsMetamodel;
@@ -74,12 +77,20 @@
metamodel = spy(JaxrsMetamodel.create(javaProject));
}
+ private JaxrsApplication createApplication(String typeName) throws CoreException,
JavaModelException {
+ final IType applicationType = getType(typeName, javaProject);
+ final JaxrsApplication application = new
JaxrsAnnotatedTypeApplication(applicationType,
+ getAnnotation(applicationType, ApplicationPath.class), metamodel);
+ metamodel.add(application);
+ return application;
+ }
+
private JaxrsResource createResource(String typeName) throws CoreException,
JavaModelException {
final IType resourceType = getType(typeName, javaProject);
- final JaxrsResource customerResource = new JaxrsResource.Builder(resourceType,
metamodel).pathTemplate(
+ final JaxrsResource resource = new JaxrsResource.Builder(resourceType,
metamodel).pathTemplate(
getAnnotation(resourceType, Path.class)).build();
- metamodel.add(customerResource);
- return customerResource;
+ metamodel.add(resource);
+ return resource;
}
private JaxrsResourceMethod createResourceMethod(String methodName, JaxrsResource
parentResource,
@@ -109,8 +120,15 @@
return httpMethod;
}
+ private JaxrsEndpoint createEndpoint(JaxrsApplication application, JaxrsHttpMethod
httpMethod, JaxrsResourceMethod... resourceMethods) {
+ JaxrsEndpoint endpoint = new JaxrsEndpoint(application, httpMethod, new
LinkedList<JaxrsResourceMethod>(
+ Arrays.asList(resourceMethods)));
+ metamodel.add(endpoint);
+ return endpoint;
+ }
+
private JaxrsEndpoint createEndpoint(JaxrsHttpMethod httpMethod, JaxrsResourceMethod...
resourceMethods) {
- JaxrsEndpoint endpoint = new JaxrsEndpoint(httpMethod, new
LinkedList<JaxrsResourceMethod>(
+ JaxrsEndpoint endpoint = new JaxrsEndpoint(null, httpMethod, new
LinkedList<JaxrsResourceMethod>(
Arrays.asList(resourceMethods)));
metamodel.add(endpoint);
return endpoint;
@@ -290,6 +308,27 @@
}
@Test
+ public void shoudChangeUriPathTemplateWhenAddingApplication() throws JavaModelException,
CoreException {
+ // the subresource becomes a root resource !
+ // pre-conditions
+ final JaxrsHttpMethod httpMethod = createHttpMethod(GET.class);
+ final JaxrsResource customerResource =
createResource("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final JaxrsResourceMethod customerResourceMethod =
createResourceMethod("getCustomer", customerResource,
+ GET.class);
+ final JaxrsEndpoint endpoint = createEndpoint(httpMethod, customerResourceMethod);
+ assertThat(endpoint.getUriPathTemplate(), equalTo("/customers/{id}"));
+ // operation
+ final JaxrsApplication application =
createApplication("org.jboss.tools.ws.jaxrs.sample.services.RestApplication");
+ final JaxrsElementChangedEvent event = new JaxrsElementChangedEvent(application,
ADDED);
+ final List<JaxrsEndpointChangedEvent> changes = processEvent(event,
progressMonitor);
+ // verifications
+ assertThat(changes.size(), equalTo(1));
+ assertThat(changes.get(0).getDeltaKind(), equalTo(CHANGED));
+ assertThat(changes.get(0).getEndpoint(), equalTo((IJaxrsEndpoint) endpoint));
+ assertThat(changes.get(0).getEndpoint().getUriPathTemplate(),
equalTo("/app/customers/{id}"));
+ }
+
+ @Test
public void shoudChangeUriPathTemplateWhenAddingResourcePathAnnotation() throws
JavaModelException, CoreException {
// the subresource becomes a root resource !
// pre-conditions
@@ -335,6 +374,30 @@
}
@Test
+ public void shoudChangeUriPathTemplateWhenChangingApplicationPathAnnotation() throws
JavaModelException, CoreException {
+ // pre-conditions
+ final JaxrsApplication application =
createApplication("org.jboss.tools.ws.jaxrs.sample.services.RestApplication");
+ final JaxrsHttpMethod httpMethod = createHttpMethod(GET.class);
+ final JaxrsResource customerResource =
createResource("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final JaxrsResourceMethod customerResourceMethod =
createResourceMethod("getCustomer", customerResource,
+ GET.class);
+ final JaxrsEndpoint endpoint = createEndpoint(application, httpMethod,
customerResourceMethod);
+ assertThat(endpoint.getUriPathTemplate(), equalTo("/app/customers/{id}"));
+ // operation
+ final Annotation annotation = getAnnotation(application.getJavaElement(),
ApplicationPath.class, "/foo");
+ int flags = application.addOrUpdateAnnotation(annotation);
+ final JaxrsElementChangedEvent event = new JaxrsElementChangedEvent(application,
CHANGED, flags);
+ final List<JaxrsEndpointChangedEvent> changes = processEvent(event,
progressMonitor);
+ // verifications
+ assertThat(changes.size(), equalTo(1));
+ final JaxrsEndpointChangedEvent change = changes.get(0);
+ assertThat(change.getDeltaKind(), equalTo(CHANGED));
+ assertThat(change.getEndpoint(), equalTo((IJaxrsEndpoint) endpoint));
+ assertThat(change.getEndpoint().getHttpMethod(), equalTo((IJaxrsHttpMethod)
httpMethod));
+ assertThat(change.getEndpoint().getUriPathTemplate(),
equalTo("/foo/customers/{id}"));
+ }
+
+ @Test
public void shoudChangeUriPathTemplateWhenChangingResourcePathAnnotation() throws
JavaModelException, CoreException {
// pre-conditions
final JaxrsHttpMethod httpMethod = createHttpMethod(GET.class);
@@ -432,6 +495,29 @@
}
@Test
+ public void shoudChangeUriPathTemplateWhenRemovingMetamodelApplication() throws
JavaModelException, CoreException {
+ // pre-conditions
+ final JaxrsApplication application =
createApplication("org.jboss.tools.ws.jaxrs.sample.services.RestApplication");
+ final JaxrsHttpMethod httpMethod = createHttpMethod(GET.class);
+ final JaxrsResource customerResource =
createResource("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final JaxrsResourceMethod customerResourceMethod =
createResourceMethod("getCustomer", customerResource,
+ GET.class);
+ final JaxrsEndpoint endpoint = createEndpoint(application, httpMethod,
customerResourceMethod);
+ assertThat(endpoint.getUriPathTemplate(), equalTo("/app/customers/{id}"));
+ // operation : no 'application' left in the metamodel
+ metamodel.remove(application);
+ final JaxrsElementChangedEvent event = new JaxrsElementChangedEvent(application,
REMOVED);
+ final List<JaxrsEndpointChangedEvent> changes = processEvent(event,
progressMonitor);
+ // verifications
+ assertThat(changes.size(), equalTo(1));
+ assertThat(changes.get(0).getDeltaKind(), equalTo(CHANGED));
+ assertThat(changes.get(0).getEndpoint(), equalTo((IJaxrsEndpoint) endpoint));
+ assertThat(changes.get(0).getEndpoint().getHttpMethod(), equalTo((IJaxrsHttpMethod)
httpMethod));
+ assertThat(changes.get(0).getEndpoint().getUriPathTemplate(),
equalTo("/customers/{id}"));
+ assertThat(metamodel.getAllApplications().size(), equalTo(0));
+ }
+
+ @Test
public void shoudChangeUriPathTemplateWhenRemovingMethodPathAnnotation() throws
JavaModelException, CoreException {
// pre-conditions
final JaxrsHttpMethod httpMethod = createHttpMethod(GET.class);
Modified:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/ResourceChangedProcessorTestCase.java
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/ResourceChangedProcessorTestCase.java 2012-01-06
04:09:33 UTC (rev 37668)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/ResourceChangedProcessorTestCase.java 2012-01-06
08:06:06 UTC (rev 37669)
@@ -29,6 +29,7 @@
import java.util.Iterator;
import java.util.List;
+import javax.ws.rs.ApplicationPath;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
@@ -48,6 +49,8 @@
import org.jboss.tools.ws.jaxrs.core.AbstractCommonTestCase;
import org.jboss.tools.ws.jaxrs.core.JBossJaxrsCorePlugin;
import org.jboss.tools.ws.jaxrs.core.WorkbenchUtils;
+import
org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsAnnotatedTypeApplication;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsApplication;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsElementFactory;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsHttpMethod;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsMetamodel;
@@ -85,6 +88,17 @@
javaProject.getProject().setSessionProperty(JaxrsMetamodel.METAMODEL_QUALIFIED_NAME,
metamodel);
}
+ private JaxrsApplication createApplication(IType type) throws JavaModelException {
+ final Annotation annotation = getAnnotation(type, ApplicationPath.class);
+ return new JaxrsAnnotatedTypeApplication(type, annotation, metamodel);
+ }
+
+ private JaxrsApplication createApplication(IType type, String applicationPath) throws
JavaModelException {
+ final Annotation annotation = getAnnotation(type, ApplicationPath.class,
applicationPath);
+ return new JaxrsAnnotatedTypeApplication(type, annotation, metamodel);
+ }
+
+
/**
* @return
* @throws CoreException
@@ -147,11 +161,11 @@
final ResourceChangedEvent event = createEvent(sourceFolder.getResource(), ADDED);
final List<JaxrsElementChangedEvent> impacts = processEvent(event,
progressMonitor);
// verifications
- // 1 HttpMethod + 3 RootResources + 2 Subresources
- assertThat(impacts.size(), equalTo(6));
+ // 1 application + 1 HttpMethod + 3 RootResources + 2 Subresources
+ assertThat(impacts.size(), equalTo(7));
assertThat(impacts, everyItem(Matchers.<JaxrsElementChangedEvent>
hasProperty("deltaKind", equalTo(ADDED))));
// all HttpMethods, Resources, ResourceMethods and ResourceFields
- assertThat(metamodel.getElements(javaProject).size(), equalTo(26));
+ assertThat(metamodel.getElements(javaProject).size(), equalTo(27));
}
@Test
@@ -185,6 +199,141 @@
}
@Test
+ public void shouldAddApplicationWhenChangingResource() throws CoreException {
+ // pre-conditions
+ final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
javaProject,
+ progressMonitor);
+ final Annotation annotation = getAnnotation(type, ApplicationPath.class);
+ // operation
+ final ResourceChangedEvent event =
createEvent(annotation.getJavaParent().getResource(), CHANGED);
+ final List<JaxrsElementChangedEvent> impacts = processEvent(event,
progressMonitor);
+ // verifications
+ assertThat(impacts.size(), equalTo(1));
+ assertThat(impacts.get(0).getElement().getElementKind(),
equalTo(EnumElementKind.APPLICATION));
+ assertThat(impacts.get(0).getDeltaKind(), equalTo(ADDED));
+ assertThat(((JaxrsApplication) impacts.get(0).getElement()).getApplicationPath(),
equalTo("/app"));
+ verify(metamodel, times(1)).add(any(JaxrsApplication.class));
+ assertThat(metamodel.getElements(javaProject).size(), equalTo(1));
+ }
+
+ @Test
+ public void shouldChangeApplicationWhenChangingResource() throws CoreException {
+ // pre-conditions
+ final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
javaProject,
+ progressMonitor);
+ metamodel.add(createApplication(type, "/bar"));
+ // operation
+ final ResourceChangedEvent event = createEvent(type.getResource(), CHANGED);
+ final List<JaxrsElementChangedEvent> impacts = processEvent(event,
progressMonitor);
+ // verifications
+ assertThat(impacts.size(), equalTo(1));
+ assertThat(impacts.get(0).getElement().getElementKind(),
equalTo(EnumElementKind.APPLICATION));
+ assertThat(impacts.get(0).getDeltaKind(), equalTo(CHANGED));
+ assertThat(((JaxrsApplication) impacts.get(0).getElement()).getApplicationPath(),
equalTo("/app"));
+ verify(metamodel, times(1)).add(any(JaxrsApplication.class));
+ assertThat(metamodel.getElements(javaProject).size(), equalTo(1));
+ }
+
+ @Test
+ public void shouldRemoveApplicationWhenChangingResource() throws CoreException {
+ // pre-conditions
+ final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
javaProject,
+ progressMonitor);
+ metamodel.add(createApplication(type));
+ final Annotation annotation = getAnnotation(type, ApplicationPath.class);
+ // operation
+ WorkbenchUtils.delete(annotation.getJavaAnnotation(), false);
+ final ResourceChangedEvent event =
createEvent(annotation.getJavaParent().getResource(), CHANGED);
+ final List<JaxrsElementChangedEvent> impacts = processEvent(event,
progressMonitor);
+ // verifications
+ assertThat(impacts.size(), equalTo(1));
+ assertThat(impacts.get(0).getElement().getElementKind(),
equalTo(EnumElementKind.APPLICATION));
+ assertThat(impacts.get(0).getDeltaKind(), equalTo(REMOVED));
+ assertThat(((JaxrsApplication) impacts.get(0).getElement()).getApplicationPath(),
equalTo("/app"));
+ verify(metamodel, times(1)).add(any(JaxrsHttpMethod.class));
+ assertThat(metamodel.getElements(javaProject).size(), equalTo(0));
+ }
+
+ @Test
+ public void shouldRemoveApplicationWhenRemovingCompilationUnit() throws CoreException {
+ // pre-conditions
+ // JaxrsMetamodel metamodel = new JaxrsMetamodel(javaProject);
+ final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
javaProject,
+ progressMonitor);
+ final JaxrsApplication application = createApplication(type);
+ metamodel.add(application);
+ // operation
+ final ResourceChangedEvent event = createEvent(type.getResource(), REMOVED);
+ final List<JaxrsElementChangedEvent> impacts = processEvent(event,
progressMonitor);
+ // verifications
+ assertThat(impacts.size(), equalTo(1));
+ assertThat(impacts.get(0).getElement().getElementKind(),
equalTo(EnumElementKind.APPLICATION));
+ assertThat(impacts.get(0).getDeltaKind(), equalTo(REMOVED));
+ assertThat(((JaxrsApplication) impacts.get(0).getElement()), equalTo(application));
+ assertThat(metamodel.getElements(javaProject).size(), equalTo(0));
+ }
+
+ @Test
+ public void shouldRemoveApplicationWhenRemovingSourceType() throws CoreException {
+ // pre-conditions
+ final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.FOO",
javaProject,
+ progressMonitor);
+ final Annotation annotation = getAnnotation(type, HttpMethod.class);
+ final JaxrsHttpMethod httpMethod = new JaxrsHttpMethod(type, annotation, metamodel);
+ metamodel.add(httpMethod);
+ // operation
+ WorkbenchUtils.delete(type);
+ final ResourceChangedEvent event = createEvent(type.getResource(), CHANGED);
+ final List<JaxrsElementChangedEvent> impacts = processEvent(event,
progressMonitor);
+ // verifications
+ assertThat(impacts.size(), equalTo(1));
+ assertThat(impacts.get(0).getElement().getElementKind(),
equalTo(EnumElementKind.HTTP_METHOD));
+ assertThat(impacts.get(0).getDeltaKind(), equalTo(REMOVED));
+ assertThat(((IJaxrsHttpMethod) impacts.get(0).getElement()).getHttpVerb(),
equalTo("FOO"));
+ assertThat(metamodel.getElements(javaProject).size(), equalTo(0));
+ }
+
+ @Test
+ public void shouldRemoveApplicationWhenRemovingSourceFolder() throws CoreException {
+ // pre-conditions
+ final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
javaProject,
+ progressMonitor);
+ final JaxrsApplication application = createApplication(type);
+ metamodel.add(application);
+ final IPackageFragmentRoot sourceFolder =
WorkbenchUtils.getPackageFragmentRoot(javaProject, "src/main/java",
+ progressMonitor);
+ // operation
+ final ResourceChangedEvent event = createEvent(sourceFolder.getResource(), REMOVED);
+ final List<JaxrsElementChangedEvent> impacts = processEvent(event,
progressMonitor);
+ // verifications
+ assertThat(impacts.size(), equalTo(1));
+ assertThat(impacts.get(0).getElement().getElementKind(),
equalTo(EnumElementKind.APPLICATION));
+ assertThat(impacts.get(0).getElement(), is(notNullValue()));
+ assertThat(impacts.get(0).getDeltaKind(), equalTo(REMOVED));
+ assertThat(metamodel.getElements(javaProject).size(), equalTo(0));
+ }
+
+ @Test
+ public void shouldRemoveHttpMethodWhenRemovingBinaryLib() throws CoreException {
+ // pre-conditions
+ final IPackageFragmentRoot lib = WorkbenchUtils.getPackageFragmentRoot(javaProject,
+ "lib/jaxrs-api-2.0.1.GA.jar", progressMonitor);
+ // let's suppose that this jar only contains 1 HTTP Methods ;-)
+ final IType type = JdtUtils.resolveType("javax.ws.rs.GET", javaProject,
progressMonitor);
+ final Annotation annotation = getAnnotation(type, HttpMethod.class);
+ final JaxrsHttpMethod httpMethod = new JaxrsHttpMethod(type, annotation, metamodel);
+ metamodel.add(httpMethod);
+ // operation
+ final ResourceChangedEvent event = createEvent(lib.getResource(), REMOVED);
+ final List<JaxrsElementChangedEvent> impacts = processEvent(event,
progressMonitor);
+ // verifications
+ assertThat(impacts.size(), equalTo(1));
+ assertThat(impacts.get(0).getElement().getElementKind(),
equalTo(EnumElementKind.HTTP_METHOD));
+ assertThat(impacts, everyItem(Matchers.<JaxrsElementChangedEvent>
hasProperty("deltaKind", equalTo(REMOVED))));
+ assertThat(metamodel.getElements(javaProject).size(), equalTo(0));
+ }
+
+ @Test
public void shouldAddHttpMethodWhenChangingResource() throws CoreException {
// pre-conditions
final IType type =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.FOO",
javaProject,
@@ -301,25 +450,6 @@
assertThat(metamodel.getElements(javaProject).size(), equalTo(0));
}
- @Test
- public void shouldRemoveHttpMethodWhenRemovingBinaryLib() throws CoreException {
- // pre-conditions
- final IPackageFragmentRoot lib = WorkbenchUtils.getPackageFragmentRoot(javaProject,
- "lib/jaxrs-api-2.0.1.GA.jar", progressMonitor);
- // let's suppose that this jar only contains 1 HTTP Methods ;-)
- final IType type = JdtUtils.resolveType("javax.ws.rs.GET", javaProject,
progressMonitor);
- final Annotation annotation = getAnnotation(type, HttpMethod.class);
- final JaxrsHttpMethod httpMethod = new JaxrsHttpMethod(type, annotation, metamodel);
- metamodel.add(httpMethod);
- // operation
- final ResourceChangedEvent event = createEvent(lib.getResource(), REMOVED);
- final List<JaxrsElementChangedEvent> impacts = processEvent(event,
progressMonitor);
- // verifications
- assertThat(impacts.size(), equalTo(1));
- assertThat(impacts.get(0).getElement().getElementKind(),
equalTo(EnumElementKind.HTTP_METHOD));
- assertThat(impacts, everyItem(Matchers.<JaxrsElementChangedEvent>
hasProperty("deltaKind", equalTo(REMOVED))));
- assertThat(metamodel.getElements(javaProject).size(), equalTo(0));
- }
@Test
public void shouldAddResourceWhenAddingSourceCompilationUnit() throws CoreException {
Added:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/jdt/JaxrsAnnotationScannerTestCase.java
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/jdt/JaxrsAnnotationScannerTestCase.java
(rev 0)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/jdt/JaxrsAnnotationScannerTestCase.java 2012-01-06
08:06:06 UTC (rev 37669)
@@ -0,0 +1,139 @@
+package org.jboss.tools.ws.jaxrs.core.jdt;
+
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.junit.Assert.assertThat;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IType;
+import org.jboss.tools.ws.jaxrs.core.AbstractCommonTestCase;
+import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsHttpMethod;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class JaxrsAnnotationScannerTestCase extends AbstractCommonTestCase {
+
+ @Test
+ public void shouldRetrieveAllResourcesInTheProject() throws CoreException {
+ // pre-conditions
+ // operation
+ final List<IType> resources =
JaxrsAnnotationsScanner.findResourceTypes(javaProject, new NullProgressMonitor());
+ // verifications
+ assertThat(resources.size(), equalTo(5));
+ }
+
+ @Test
+ public void shouldRetrieveOneResourceInType() throws CoreException {
+ // pre-conditions
+ IType customerType =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
+ javaProject, null);
+ assertThat(customerType, notNullValue());
+ // operation
+ final List<IType> resources = JaxrsAnnotationsScanner
+ .findResourceTypes(customerType, new NullProgressMonitor());
+ // verifications
+ assertThat(resources.size(), equalTo(1));
+ }
+
+ @Test
+ public void shouldNotRetrieveResourceInOtherType() throws CoreException {
+ // pre-conditions
+ IType customerType =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
+ javaProject, null);
+ assertThat(customerType, notNullValue());
+ // operation
+ final List<IType> resources = JaxrsAnnotationsScanner
+ .findResourceTypes(customerType, new NullProgressMonitor());
+ // verifications
+ assertThat(resources.size(), equalTo(0));
+ }
+
+ @Test
+ public void shouldRetrieveAllResourceMethodsInProject() throws CoreException {
+ // pre-conditions
+ // operation
+ final List<IMethod> resourceMethods =
JaxrsAnnotationsScanner.findResourceMethods(javaProject,new
ArrayList<IJaxrsHttpMethod>(),
+ new NullProgressMonitor());
+ // verifications
+ assertThat(resourceMethods.size(), equalTo(9)); // just sub resource methods with @Path
annotation
+ }
+
+ @Test
+ public void shouldRetrieveAllResourceMethodsInType() throws CoreException {
+ // pre-conditions
+ IType customerType =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
+ javaProject, null);
+ assertThat(customerType, notNullValue());
+ // operation
+ final List<IMethod> resourceMethods =
JaxrsAnnotationsScanner.findResourceMethods(customerType,new
ArrayList<IJaxrsHttpMethod>(),
+ new NullProgressMonitor());
+ // verifications
+ assertThat(resourceMethods.size(), equalTo(4)); // just sub resource methods with @Path
annotation
+ }
+
+ @Test
+ public void shouldRetrieveAllHttpMethodsInProject() throws CoreException {
+ // pre-conditions
+ // operation
+ final List<IType> resourceMethods =
JaxrsAnnotationsScanner.findHttpMethodTypes(javaProject,
+ new NullProgressMonitor());
+ // verifications
+ assertThat(resourceMethods.size(), equalTo(7));
+ }
+
+ @Test
+ public void shouldRetrieveOneHttpMethodsInType() throws CoreException {
+ // pre-conditions
+ IType fooType =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.FOO",
javaProject, null);
+ assertThat(fooType, notNullValue());
+ // operation
+ final List<IType> resourceMethods =
JaxrsAnnotationsScanner.findHttpMethodTypes(fooType,
+ new NullProgressMonitor());
+ // verifications
+ assertThat(resourceMethods.size(), equalTo(1));
+ }
+
+ @Test
+ @Ignore("Providers are not supported yet")
+ public void shouldRetrieveProviders() {
+ }
+
+ @Test
+ public void shouldRetrieveAllApplicationsInProject() throws CoreException {
+ // pre-conditions
+ // operation
+ final List<IType> applications =
JaxrsAnnotationsScanner.findApplicationTypes(javaProject,
+ new NullProgressMonitor());
+ // verifications
+ assertThat(applications.size(), equalTo(1));
+ }
+
+ @Test
+ public void shouldRetrieveOneApplicationsInType() throws CoreException {
+ // pre-conditions
+ IType restType =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
javaProject, null);
+ assertThat(restType, notNullValue());
+ // operation
+ final List<IType> applications =
JaxrsAnnotationsScanner.findApplicationTypes(restType,
+ new NullProgressMonitor());
+ // verifications
+ assertThat(applications.size(), equalTo(1));
+ }
+
+ @Test
+ public void shouldNotRetrieveApplicationsInOtherType() throws CoreException {
+ // pre-conditions
+ IType fooType =
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.FOO",
javaProject, null);
+ assertThat(fooType, notNullValue());
+ // operation
+ final List<IType> applications =
JaxrsAnnotationsScanner.findApplicationTypes(fooType,
+ new NullProgressMonitor());
+ // verifications
+ assertThat(applications.size(), equalTo(0));
+ }
+}
Property changes on:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/jdt/JaxrsAnnotationScannerTestCase.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain