[jbosstools-commits] JBoss Tools SVN: r43940 - in trunk/ws: plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder and 15 other directories.
jbosstools-commits at lists.jboss.org
jbosstools-commits at lists.jboss.org
Fri Sep 21 17:39:43 EDT 2012
Author: xcoulon
Date: 2012-09-21 17:39:42 -0400 (Fri, 21 Sep 2012)
New Revision: 43940
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsJavaApplicationValidatorDelegate.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMetamodelValidatorDelegate.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsWebxmlApplicationValidatorDelegate.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-2_3-with-default-servlet-mapping.xml
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-2_4-with-default-servlet-mapping.xml
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-2_5-with-default-servlet-mapping.xml
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-3_0-with-custom-servlet-mapping.xml
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-3_0-with-default-servlet-mapping.xml
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsApplicationValidatorTestCase.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsHttpMethodValidatorTestCase.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsResourceValidatorTestCase.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/MarkerUtils.java
Removed:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsApplicationValidatorDelegate.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsValidationErrorManager.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/MarkerUtils.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-2_3-with-servlet-mapping.xml
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-2_4-with-servlet-mapping.xml
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-2_5-with-servlet-mapping.xml
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-3_0-with-servlet-mapping.xml
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMetamodelValidatorTestCase.java
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/META-INF/MANIFEST.MF
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/JaxrsElementDelta.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelChangedProcessor.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/JaxrsBaseElement.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsBuiltinHttpMethod.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/JaxrsHttpMethod.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsJavaApplication.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsJavaElement.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/JaxrsResourceMethod.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsWebxmlApplication.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/AbstractJaxrsElementValidatorDelegate.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsHttpMethodValidatorDelegate.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMetamodelValidator.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsResourceMethodValidatorDelegate.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsResourceValidatorDelegate.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsValidationMessages.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsValidationMessages.properties
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/CollectionUtils.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/ConstantUtils.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/ValidationMessages.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/WtpUtils.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.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JdtUtils.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/EnumElementCategory.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/EnumElementKind.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/IJaxrsApplication.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/IJaxrsElement.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/IJaxrsHttpMethod.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/IJaxrsMetamodel.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/quickfix/JaxrsValidationQuickFixes.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/preferences/JaxrsPreferenceInitializer.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/preferences/JaxrsPreferences.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/preferences/JaxrsPreferencesMessages.properties
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/WorkbenchUtils.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/JaxrsMetamodelChangedProcessorTestCase.java
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/domain/JaxrsElementFactoryTestCase.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsMetamodelTestCase.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/utils/WtpUtilsTestCase.java
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/JdtUtilsTestCase.java
Log:
JBIDE-10287 Add support for JAX-RS Application
JBIDE-12633 Support for JAX-RS Application subclassing with configuration in web.xml
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/META-INF/MANIFEST.MF
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/META-INF/MANIFEST.MF 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/META-INF/MANIFEST.MF 2012-09-21 21:39:42 UTC (rev 43940)
@@ -29,7 +29,8 @@
org.eclipse.wst.common.frameworks.ui;bundle-version="1.1.301",
org.eclipse.jface.text;bundle-version="3.7.1",
org.jboss.tools.common.validation;bundle-version="3.4.0",
- org.jboss.tools.common;bundle-version="3.4.0"
+ org.jboss.tools.common;bundle-version="3.4.0",
+ org.eclipse.wst.sse.core;bundle-version="1.1.701"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Export-Package: org.jboss.tools.ws.jaxrs.core,
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-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedProcessor.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -40,7 +40,6 @@
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.JaxrsBaseElement;
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.JaxrsJavaApplication;
@@ -57,6 +56,7 @@
import org.jboss.tools.ws.jaxrs.core.jdt.JdtUtils;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumElementCategory;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumElementKind;
+import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsElement;
import org.jboss.tools.ws.jaxrs.core.metamodel.JaxrsMetamodelDelta;
import org.jboss.tools.ws.jaxrs.core.metamodel.JaxrsMetamodelLocator;
@@ -73,7 +73,7 @@
for (JavaElementDelta affectedJavaElement : affectedJavaElements) {
final List<JaxrsElementDelta> affectedJaxrsElement = processAffectedElement(affectedJavaElement, progressMonitor);
for (JaxrsElementDelta jaxrsElementDelta : affectedJaxrsElement) {
- final JaxrsMetamodel affectedMetamodel = jaxrsElementDelta.getElement().getMetamodel();
+ final JaxrsMetamodel affectedMetamodel = (JaxrsMetamodel) jaxrsElementDelta.getElement().getMetamodel();
if(!affectedMetamodels.containsKey(affectedMetamodel)) {
affectedMetamodels.put(affectedMetamodel, new JaxrsMetamodelDelta(affectedMetamodel, CHANGED));
}
@@ -378,7 +378,7 @@
private List<JaxrsElementDelta> processChange(IMethod javaMethod, CompilationUnit ast,
JaxrsMetamodel metamodel, IProgressMonitor progressMonitor) throws CoreException {
final List<JaxrsElementDelta> changes = new ArrayList<JaxrsElementDelta>();
- final JaxrsBaseElement jaxrsElement = metamodel.getElement(javaMethod);
+ final IJaxrsElement jaxrsElement = metamodel.getElement(javaMethod);
if (jaxrsElement != null && jaxrsElement.getElementCategory() == EnumElementCategory.RESOURCE_METHOD) {
final int flag = ((JaxrsResourceMethod) jaxrsElement).update(CompilationUnitsRepository.getInstance()
.getMethodSignature(javaMethod));
@@ -398,8 +398,8 @@
private List<JaxrsElementDelta> processRemoval(IPackageFragmentRoot packageFragmentRoot,
final JaxrsMetamodel metamodel, IProgressMonitor progressMonitor) throws CoreException {
final List<JaxrsElementDelta> changes = new ArrayList<JaxrsElementDelta>();
- final List<JaxrsBaseElement> elements = metamodel.getElements(packageFragmentRoot);
- for (JaxrsBaseElement element : elements) {
+ final List<IJaxrsElement> elements = metamodel.getElements(packageFragmentRoot);
+ for (IJaxrsElement element : elements) {
metamodel.remove(element);
changes.add(new JaxrsElementDelta(element, REMOVED));
}
@@ -416,8 +416,8 @@
private List<JaxrsElementDelta> processRemoval(ICompilationUnit compilationUnit, CompilationUnit ast,
final JaxrsMetamodel metamodel, IProgressMonitor progressMonitor) throws CoreException {
final List<JaxrsElementDelta> changes = new ArrayList<JaxrsElementDelta>();
- final List<JaxrsBaseElement> elements = metamodel.getElements(compilationUnit);
- for (JaxrsBaseElement element : elements) {
+ final List<IJaxrsElement> elements = metamodel.getElements(compilationUnit);
+ for (IJaxrsElement element : elements) {
metamodel.remove(element);
CompilationUnitsRepository.getInstance().removeAST(compilationUnit);
changes.add(new JaxrsElementDelta(element, REMOVED));
@@ -433,7 +433,7 @@
private List<JaxrsElementDelta> processRemoval(final IType javaType, final CompilationUnit ast,
final JaxrsMetamodel metamodel, final IProgressMonitor progressMonitor) throws CoreException {
final List<JaxrsElementDelta> changes = new ArrayList<JaxrsElementDelta>();
- final JaxrsBaseElement element = metamodel.getElement(javaType);
+ final IJaxrsElement element = metamodel.getElement(javaType);
// if item does not exist yet, then don't care about the removed type
if (element != null) {
metamodel.remove(element);
@@ -467,8 +467,8 @@
private List<JaxrsElementDelta> processRemoval(IField field, CompilationUnit ast, JaxrsMetamodel metamodel,
IProgressMonitor progressMonitor) {
final List<JaxrsElementDelta> changes = new ArrayList<JaxrsElementDelta>();
- final List<JaxrsBaseElement> elements = metamodel.getElements(field);
- for (JaxrsBaseElement element : elements) {
+ final List<IJaxrsElement> elements = metamodel.getElements(field);
+ for (IJaxrsElement element : elements) {
metamodel.remove(element);
changes.add(new JaxrsElementDelta(element, REMOVED));
}
@@ -478,8 +478,8 @@
private List<JaxrsElementDelta> processRemoval(IMethod method, CompilationUnit ast,
JaxrsMetamodel metamodel, IProgressMonitor progressMonitor) {
final List<JaxrsElementDelta> changes = new ArrayList<JaxrsElementDelta>();
- final List<JaxrsBaseElement> elements = metamodel.getElements(method);
- for (JaxrsBaseElement element : elements) {
+ final List<IJaxrsElement> elements = metamodel.getElements(method);
+ for (IJaxrsElement element : elements) {
if (element.getElementCategory() == EnumElementCategory.RESOURCE_METHOD) {
metamodel.remove(element);
changes.add(new JaxrsElementDelta(element, REMOVED));
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsElementDelta.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsElementDelta.java 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsElementDelta.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -18,19 +18,13 @@
import java.util.List;
import org.eclipse.jdt.core.IJavaElementDelta;
-import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsBaseElement;
import org.jboss.tools.ws.jaxrs.core.internal.utils.ConstantUtils;
import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumElementKind;
+import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsElement;
public class JaxrsElementDelta implements Comparable<JaxrsElementDelta> {
- private final JaxrsBaseElement element;
-
- private final int deltaKind;
-
- private final int flags;
-
/** No change. */
public static final int F_NONE = 0;
@@ -43,35 +37,45 @@
public static final int F_APPLICATION_PATH_VALUE = 0x8;
- public static final int F_HTTP_METHOD_VALUE = 0x10;
+ public static final int F_APPLICATION_PATH_VALUE_ORVERRIDE = 0x10;
- public static final int F_PATH_PARAM_VALUE = 0x20;
+ public static final int F_APPLICATION_HIERARCHY = 0x20;
- public static final int F_QUERY_PARAM_VALUE = 0x40;
+ public static final int F_HTTP_METHOD_VALUE = 0x40;
- public static final int F_MATRIX_PARAM_VALUE = 0x80;
+ public static final int F_PATH_PARAM_VALUE = 0x80;
- public static final int F_DEFAULT_VALUE_VALUE = 0x100;
+ public static final int F_QUERY_PARAM_VALUE = 0x100;
- public static final int F_CONSUMED_MEDIATYPES_VALUE = 0x200;
+ public static final int F_MATRIX_PARAM_VALUE = 0x200;
- public static final int F_PRODUCED_MEDIATYPES_VALUE = 0x400;
+ public static final int F_DEFAULT_VALUE_VALUE = 0x400;
- public static final int F_METHOD_PARAMETERS = 0x800;
+ public static final int F_CONSUMED_MEDIATYPES_VALUE = 0x800;
- public static final int F_METHOD_RETURN_TYPE = 0x1000;
+ public static final int F_PRODUCED_MEDIATYPES_VALUE = 0x1000;
- public static final int F_TARGET_VALUE = 0x2000;
+ public static final int F_METHOD_PARAMETERS = 0x2000;
+
+ public static final int F_METHOD_RETURN_TYPE = 0x4000;
+
+ public static final int F_TARGET_VALUE = 0x8000;
- public static final int F_RETENTION_VALUE = 0x4000;
+ public static final int F_RETENTION_VALUE = 0x10000;
+ private final IJaxrsElement element;
+
+ private final int deltaKind;
+
+ private final int flags;
+
/**
* Full constructor.
*
* @param element
* @param deltaKind
*/
- public JaxrsElementDelta(JaxrsBaseElement element, int deltaKind) {
+ public JaxrsElementDelta(IJaxrsElement element, int deltaKind) {
this(element, deltaKind, 0);
}
@@ -82,7 +86,7 @@
* @param deltaKind
* @param flags
*/
- public JaxrsElementDelta(JaxrsBaseElement element, int deltaKind, int flags) {
+ public JaxrsElementDelta(IJaxrsElement element, int deltaKind, int flags) {
this.element = element;
this.deltaKind = deltaKind;
this.flags = flags;
@@ -92,7 +96,7 @@
}
/** @return the element */
- public JaxrsBaseElement getElement() {
+ public IJaxrsElement getElement() {
return element;
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelChangedProcessor.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelChangedProcessor.java 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelChangedProcessor.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -28,7 +28,6 @@
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.JaxrsBaseElement;
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;
@@ -39,6 +38,7 @@
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumElementCategory;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumElementKind;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsApplication;
+import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsElement;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsResource;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsResourceMethod;
import org.jboss.tools.ws.jaxrs.core.metamodel.JaxrsEndpointDelta;
@@ -86,7 +86,7 @@
@SuppressWarnings("incomplete-switch")
private List<JaxrsEndpointDelta> processEvent(final JaxrsElementDelta event) throws CoreException {
- final JaxrsBaseElement element = event.getElement();
+ final IJaxrsElement element = event.getElement();
final EnumElementCategory elementKind = element.getElementCategory();
final int flags = event.getFlags();
switch (event.getDeltaKind()) {
@@ -203,7 +203,7 @@
final JaxrsResource resource = resourceMethod.getParentResource();
final IProgressMonitor progressMonitor = new NullProgressMonitor();
final IType resourceType = resource.getJavaElement();
- final ITypeHierarchy returnTypeHierarchy = JdtUtils.resolveTypeHierarchy(resourceType, false, progressMonitor);
+ final ITypeHierarchy returnTypeHierarchy = JdtUtils.resolveTypeHierarchy(resourceType, resourceType.getJavaProject(), false, progressMonitor);
final List<String> supertypesHandlers = extractHandlers(returnTypeHierarchy.getAllSupertypes(resourceType));
for (IJaxrsResource otherResource : metamodel.getAllResources()) {
if (((JaxrsResource) otherResource).isRootResource()) {
@@ -246,7 +246,7 @@
final IType returnType = subresourceLocator.getReturnType();
if (returnType != null) {
final ITypeHierarchy returnTypeHierarchy = JdtUtils
- .resolveTypeHierarchy(returnType, false, progressMonitor);
+ .resolveTypeHierarchy(returnType, returnType.getJavaProject(), false, progressMonitor);
if (returnTypeHierarchy != null) {
final List<String> subtypesHandlers = extractHandlers(returnTypeHierarchy.getAllSubtypes(returnType));
for (Iterator<IJaxrsResource> iterator = metamodel.getAllResources().iterator(); iterator.hasNext();) {
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-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/ResourceChangedProcessor.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -13,6 +13,8 @@
import static org.eclipse.jdt.core.IJavaElementDelta.ADDED;
import static org.eclipse.jdt.core.IJavaElementDelta.CHANGED;
import static org.eclipse.jdt.core.IJavaElementDelta.REMOVED;
+import static org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsElementDelta.F_APPLICATION_PATH_VALUE;
+import static org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsElementDelta.F_APPLICATION_PATH_VALUE_ORVERRIDE;
import static org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsElementDelta.F_ELEMENT_KIND;
import static org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsElementDelta.F_FINE_GRAINED;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.APPLICATION;
@@ -52,7 +54,6 @@
import org.jboss.tools.ws.jaxrs.core.jdt.JaxrsAnnotationsScanner;
import org.jboss.tools.ws.jaxrs.core.jdt.JdtUtils;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumElementKind;
-import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsApplication;
import org.jboss.tools.ws.jaxrs.core.metamodel.JaxrsMetamodelDelta;
import org.jboss.tools.ws.jaxrs.core.metamodel.JaxrsMetamodelLocator;
@@ -195,12 +196,26 @@
break;
}
}
-
+ for (JaxrsElementDelta delta : results) {
+ Logger.debug("Resulting event: {}", delta);
+ }
return results;
}
private List<JaxrsElementDelta> processApplicationChangesOnWebxmlAdditionOrChange(IResource resource,
JaxrsMetamodel metamodel, IProgressMonitor progressMonitor) throws CoreException {
+ final List<JaxrsElementDelta> results = new ArrayList<JaxrsElementDelta>();
+ final List<JaxrsElementDelta> changes = preprocessApplicationChangesOnWebxmlAdditionOrChange(resource, metamodel,
+ progressMonitor);
+ for (JaxrsElementDelta change : changes) {
+ results.addAll(postProcessWebxmlApplication(change, progressMonitor));
+ }
+ return results;
+
+ }
+
+ private List<JaxrsElementDelta> preprocessApplicationChangesOnWebxmlAdditionOrChange(IResource resource,
+ JaxrsMetamodel metamodel, IProgressMonitor progressMonitor) throws CoreException {
final IType applicationType = JdtUtils.resolveType(APPLICATION.qualifiedName, metamodel.getJavaProject(),
progressMonitor);
// occurs when the project has the jax-rs nature (the builder is called), but no jaxrs library is in the classpath
@@ -208,25 +223,43 @@
return Collections.emptyList();
}
final List<JaxrsElementDelta> results = new ArrayList<JaxrsElementDelta>();
- final ITypeHierarchy applicationTypeHierarchy = JdtUtils.resolveTypeHierarchy(applicationType, false,
+ final ITypeHierarchy applicationTypeHierarchy = JdtUtils.resolveTypeHierarchy(applicationType, applicationType.getJavaProject(), false,
progressMonitor);
final IType[] applicationSubclasses = applicationTypeHierarchy.getSubclasses(applicationType);
// add the standard Application type in last position in the hierarchy
- final IType[] applicationClasses = new IType[applicationSubclasses.length + 1];
- System.arraycopy(applicationSubclasses, 0, applicationClasses, 0, applicationSubclasses.length);
- applicationClasses[applicationClasses.length -1] = applicationType;
- String resolvedApplicationPath = null;
+ final IType[] applicationClasses = CollectionUtils.append(applicationSubclasses, applicationType,
+ new IType[applicationSubclasses.length + 1]);
+ // existing web.xml-based JAX-RS applications in the metamodel
+ final List<JaxrsWebxmlApplication> existingApplications = metamodel.getWebxmlApplications();
+ // web.xml-based JAX-RS applications declared in the web deployment descriptor
+ final List<JaxrsWebxmlApplication> declaredApplications = new ArrayList<JaxrsWebxmlApplication>();
for (IType applicationClass : applicationClasses) {
- final String applicationPath = WtpUtils.getApplicationPath(resource.getProject(),
- applicationClass.getFullyQualifiedName());
+ final String applicationClassName = applicationClass.getFullyQualifiedName();
+ final String applicationPath = WtpUtils.getApplicationPath(resource,
+ applicationClassName);
if (applicationPath != null) {
- resolvedApplicationPath = applicationPath;
- break;
+ declaredApplications.add(factory.createApplication(applicationClassName, applicationPath, resource, metamodel));
}
}
- final IJaxrsApplication application = metamodel.getApplication();
+ // now compare the 'existing' vs 'declared' lists to update the metamodel (adding/updating/removing items)
+ final Collection<JaxrsWebxmlApplication> addedApplications = CollectionUtils.difference(declaredApplications,
+ existingApplications);
+ for (JaxrsWebxmlApplication application : addedApplications) {
+ results.add(new JaxrsElementDelta(application, ADDED));
+ }
+ final Collection<JaxrsWebxmlApplication> changedApplications = CollectionUtils.intersection(declaredApplications,
+ existingApplications);
+ for (JaxrsWebxmlApplication application : changedApplications) {
+ results.add(new JaxrsElementDelta(application, CHANGED, F_FINE_GRAINED));
+ }
+ final Collection<JaxrsWebxmlApplication> removedApplications = CollectionUtils.difference(existingApplications,
+ declaredApplications);
+ for (JaxrsWebxmlApplication application : removedApplications) {
+ results.add(new JaxrsElementDelta(application, REMOVED));
+ }
+
+ /*final IJaxrsApplication application = metamodel.getApplication();
if (resolvedApplicationPath != null) {
- final JaxrsWebxmlApplication webxmlApplication = factory.createApplication(resolvedApplicationPath, resource, metamodel);
if (application == null || application.getElementKind() == EnumElementKind.APPLICATION_JAVA) {
metamodel.add(webxmlApplication);
results.add(new JaxrsElementDelta(webxmlApplication, ADDED));
@@ -238,17 +271,65 @@
final JaxrsWebxmlApplication webxmlApplication = (JaxrsWebxmlApplication) application;
metamodel.remove(webxmlApplication);
results.add(new JaxrsElementDelta(webxmlApplication, REMOVED));
- }
+ }*/
// otherwise, do nothing (application path not declared in web.xml, or not valid but can't be discovered)
return results;
}
+
+ private List<JaxrsElementDelta> postProcessWebxmlApplication(JaxrsElementDelta event, IProgressMonitor progressMonitor) {
+ final List<JaxrsElementDelta> results = new ArrayList<JaxrsElementDelta>();
+ final JaxrsWebxmlApplication webxmlApplication = (JaxrsWebxmlApplication) event.getElement();
+ final JaxrsMetamodel metamodel = webxmlApplication.getMetamodel();
+ JaxrsJavaApplication overridenJaxrsJavaApplication;
+ switch (event.getDeltaKind()) {
+ case ADDED:
+ metamodel.add(webxmlApplication);
+ results.add(event);
+ overridenJaxrsJavaApplication = webxmlApplication.getOverridenJaxrsJavaApplication();
+ if(overridenJaxrsJavaApplication != null) {
+ overridenJaxrsJavaApplication.setApplicationPathOverride(webxmlApplication.getApplicationPath());
+ results.add(new JaxrsElementDelta(overridenJaxrsJavaApplication, CHANGED, F_APPLICATION_PATH_VALUE));
+ }
+ break;
+ case REMOVED:
+ metamodel.remove(webxmlApplication);
+ results.add(event);
+ overridenJaxrsJavaApplication = webxmlApplication.getOverridenJaxrsJavaApplication();
+ if(overridenJaxrsJavaApplication != null) {
+ overridenJaxrsJavaApplication.unsetApplicationPathOverride();
+ results.add(new JaxrsElementDelta(overridenJaxrsJavaApplication, CHANGED, F_APPLICATION_PATH_VALUE));
+ }
+
+ break;
+ case CHANGED:
+ final JaxrsWebxmlApplication existingWebxmlApplication = metamodel.getWebxmlApplication(webxmlApplication.getJavaClassName());
+ final int flags = existingWebxmlApplication.update(webxmlApplication);
+ if (flags != 0) {
+ results.add(new JaxrsElementDelta(existingWebxmlApplication, CHANGED, flags));
+ }
+ break;
+ }
+ return results;
+ }
+
private List<JaxrsElementDelta> processApplicationChangesOnWebxmlRemoval(IResource resource,
JaxrsMetamodel metamodel, IProgressMonitor progressMonitor) {
final List<JaxrsElementDelta> results = new ArrayList<JaxrsElementDelta>();
- for (Iterator<IJaxrsApplication> iterator = metamodel.getAllApplications().iterator(); iterator.hasNext();) {
- IJaxrsApplication application = (IJaxrsApplication) iterator.next();
- if(application instanceof JaxrsWebxmlApplication) {
+ final List<JaxrsElementDelta> changes = preprocessApplicationChangesOnWebxmlRemoval(resource, metamodel,
+ progressMonitor);
+ for (JaxrsElementDelta change : changes) {
+ results.addAll(postProcessWebxmlApplication(change, progressMonitor));
+ }
+ return results;
+ }
+
+ private List<JaxrsElementDelta> preprocessApplicationChangesOnWebxmlRemoval(IResource resource,
+ JaxrsMetamodel metamodel, IProgressMonitor progressMonitor) {
+ final List<JaxrsElementDelta> results = new ArrayList<JaxrsElementDelta>();
+ for (Iterator<JaxrsWebxmlApplication> iterator = metamodel.getWebxmlApplications().iterator(); iterator.hasNext();) {
+ JaxrsWebxmlApplication application = iterator.next();
+ if(application.getResource().equals(resource)) {
Logger.debug("Removing {}", application);
final JaxrsWebxmlApplication webxmlApplication = (JaxrsWebxmlApplication)application;
metamodel.remove(webxmlApplication);
@@ -264,7 +345,7 @@
final List<JaxrsElementDelta> changes = preprocessApplicationChangesOnScopeAdditionOrChange(scope, metamodel,
progressMonitor);
for (JaxrsElementDelta change : changes) {
- results.addAll(postProcessApplication(change, progressMonitor));
+ results.addAll(postProcessJavaApplication(change, progressMonitor));
}
return results;
}
@@ -272,7 +353,7 @@
/**
* See if Applications exist in the given scope. The exact kind of the {@link JaxrsElementDelta} event is not
* determined at this stage, it's the responsibility of the
- * {@link ResourceChangedProcessor#postProcessApplication(JaxrsElementDelta, IProgressMonitor)} method.
+ * {@link ResourceChangedProcessor#postProcessJavaApplication(JaxrsElementDelta, IProgressMonitor)} method.
*
* @param scope
* @param metamodel
@@ -319,14 +400,14 @@
}
return results;
}
-
+
private List<JaxrsElementDelta> processApplicationChangesOnScopeRemoval(IJavaElement scope,
JaxrsMetamodel metamodel, IProgressMonitor progressMonitor) throws JavaModelException, CoreException {
final List<JaxrsElementDelta> results = new ArrayList<JaxrsElementDelta>();
final List<JaxrsElementDelta> changes = preprocessApplicationChangesOnScopeRemoval(scope, metamodel,
progressMonitor);
for (JaxrsElementDelta change : changes) {
- results.addAll(postProcessApplication(change, progressMonitor));
+ results.addAll(postProcessJavaApplication(change, progressMonitor));
}
return results;
}
@@ -354,25 +435,36 @@
return results;
}
- private List<JaxrsElementDelta> postProcessApplication(JaxrsElementDelta event, IProgressMonitor progressMonitor) {
+ private List<JaxrsElementDelta> postProcessJavaApplication(final JaxrsElementDelta event, final IProgressMonitor progressMonitor) {
final List<JaxrsElementDelta> results = new ArrayList<JaxrsElementDelta>();
- final JaxrsJavaApplication eventApplication = (JaxrsJavaApplication) event.getElement();
- final JaxrsMetamodel metamodel = eventApplication.getMetamodel();
+ final JaxrsJavaApplication eventJavaApplication = (JaxrsJavaApplication) event.getElement();
+ final JaxrsMetamodel metamodel = eventJavaApplication.getMetamodel();
+ JaxrsWebxmlApplication webxmlApplication = null;
switch (event.getDeltaKind()) {
case ADDED:
- metamodel.add(eventApplication);
- results.add(event);
+ metamodel.add(eventJavaApplication);
+ webxmlApplication = metamodel.getWebxmlApplication(eventJavaApplication.getJavaClassName());
+ if(webxmlApplication != null) {
+ eventJavaApplication.setApplicationPathOverride(webxmlApplication.getApplicationPath());
+ results.add(new JaxrsElementDelta(eventJavaApplication, ADDED, F_APPLICATION_PATH_VALUE_ORVERRIDE));
+ } else {
+ results.add(event);
+ }
break;
case REMOVED:
- metamodel.remove(eventApplication);
+ metamodel.remove(eventJavaApplication);
results.add(event);
break;
case CHANGED:
- final JaxrsJavaApplication existingApplication = metamodel.getElement(eventApplication.getJavaElement(),
+ final JaxrsJavaApplication existingJavaApplication = metamodel.getElement(eventJavaApplication.getJavaElement(),
JaxrsJavaApplication.class);
- final int flags = existingApplication.update(eventApplication);
- if (flags != 0) {
- results.add(new JaxrsElementDelta(existingApplication, CHANGED, flags));
+ final int flags = existingJavaApplication.update(eventJavaApplication);
+ webxmlApplication = metamodel.getWebxmlApplication(eventJavaApplication.getJavaClassName());
+ if(flags != 0 && webxmlApplication != null) {
+ eventJavaApplication.setApplicationPathOverride(webxmlApplication.getApplicationPath());
+ results.add(new JaxrsElementDelta(eventJavaApplication, CHANGED, flags + F_APPLICATION_PATH_VALUE_ORVERRIDE));
+ } else if(flags != 0) {
+ results.add(new JaxrsElementDelta(existingJavaApplication, CHANGED, flags));
}
break;
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsBaseElement.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsBaseElement.java 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsBaseElement.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -1,8 +1,16 @@
+/*******************************************************************************
+ * 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 org.eclipse.core.resources.IResource;
-import org.jboss.tools.ws.jaxrs.core.metamodel.EnumElementCategory;
-import org.jboss.tools.ws.jaxrs.core.metamodel.EnumElementKind;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsElement;
public abstract class JaxrsBaseElement implements IJaxrsElement {
@@ -42,12 +50,4 @@
return metamodel;
}
- public abstract EnumElementCategory getElementCategory();
-
- public abstract EnumElementKind getElementKind();
-
- public abstract IResource getResource();
-
- public abstract String getName();
-
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsBuiltinHttpMethod.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsBuiltinHttpMethod.java 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsBuiltinHttpMethod.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -58,7 +58,7 @@
}
@Override
- public String getFullyQualifiedName() {
+ public String getJavaClassName() {
return annotationName;
}
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-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsElementFactory.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -58,6 +58,7 @@
import org.jboss.tools.ws.jaxrs.core.jdt.JdtUtils;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumElementCategory;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumElementKind;
+import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsElement;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsHttpMethod;
public class JaxrsElementFactory {
@@ -221,7 +222,7 @@
JaxrsMetamodel metamodel, JaxrsResource parentResource) throws JavaModelException {
final List<String> httpMethodAnnotationNames = new ArrayList<String>();
for (IJaxrsHttpMethod httpMethod : metamodel.getAllHttpMethods()) {
- httpMethodAnnotationNames.add(httpMethod.getFullyQualifiedName());
+ httpMethodAnnotationNames.add(httpMethod.getJavaClassName());
}
final List<String> annotationNames = new ArrayList<String>();
annotationNames.addAll(Arrays.asList(PATH.qualifiedName, PRODUCES.qualifiedName, CONSUMES.qualifiedName));
@@ -312,10 +313,7 @@
public JaxrsJavaApplication createApplication(final IType javaType, final CompilationUnit ast,
final JaxrsMetamodel metamodel) throws CoreException {
Annotation applicationPathAnnotation = JdtUtils.resolveAnnotation(javaType, ast, APPLICATION_PATH.qualifiedName);
- if (applicationPathAnnotation == null) {
- return null;
- }
- return new JaxrsJavaApplication(javaType, applicationPathAnnotation, metamodel);
+ return createApplication(javaType, applicationPathAnnotation, metamodel);
}
/**
@@ -330,13 +328,36 @@
*/
public JaxrsJavaApplication createApplication(final Annotation annotation, final CompilationUnit ast,
final JaxrsMetamodel metamodel) throws CoreException {
- if (annotation.getJavaParent() != null && annotation.getJavaParent().getElementType() == IJavaElement.TYPE
+ final IJavaElement javaParent = annotation.getJavaParent();
+ if (javaParent != null && javaParent.getElementType() == IJavaElement.TYPE
&& annotation.getName().equals(APPLICATION_PATH.qualifiedName)) {
- return new JaxrsJavaApplication((IType) annotation.getJavaParent(), annotation, metamodel);
+ final IType javaType = (IType) javaParent;
+ return createApplication(javaType, annotation, metamodel);
}
return null;
}
+
+ /**
+ * 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
+ */
+ private JaxrsJavaApplication createApplication(final IType applicationType, final Annotation appPathAnnotation,
+ final JaxrsMetamodel metamodel) throws CoreException {
+ final IType applicationSupertype = JdtUtils.resolveType(EnumJaxrsClassname.APPLICATION.qualifiedName, applicationType.getJavaProject(), new NullProgressMonitor());
+ final boolean isApplicationSubclass = JdtUtils.isTypeOrSuperType(applicationSupertype, applicationType);
+ if(isApplicationSubclass || appPathAnnotation != null) {
+ return new JaxrsJavaApplication(applicationType, appPathAnnotation, isApplicationSubclass, metamodel);
+ }
+ return null;
+ }
+
/**
* Create a JAX-RS Resource field from the given annotation, <b>without adding it to the given JAX-RS Metamodel</b>
*
@@ -356,7 +377,7 @@
public JaxrsResourceField createField(IField javaField, CompilationUnit ast, JaxrsMetamodel metamodel)
throws JavaModelException {
final IType parentType = (IType) javaField.getParent();
- JaxrsBaseElement parentResource = metamodel.getElement(parentType);
+ IJaxrsElement parentResource = metamodel.getElement(parentType);
if (parentResource == null) {
// creating the parent resource but not adding it to the metamodel
// yet..
@@ -386,8 +407,8 @@
return null;
}
- public JaxrsWebxmlApplication createApplication(String applicationPath, IResource resource, JaxrsMetamodel metamodel) {
- return new JaxrsWebxmlApplication(applicationPath, resource, metamodel);
+ public JaxrsWebxmlApplication createApplication(final String javaClassName, final String applicationPath, final IResource resource, final JaxrsMetamodel metamodel) {
+ return new JaxrsWebxmlApplication(javaClassName, applicationPath, resource, metamodel);
}
/**
@@ -409,7 +430,7 @@
if(JdtUtils.isAbstractType(javaType)) {
return null;
}
- ITypeHierarchy providerTypeHierarchy = JdtUtils.resolveTypeHierarchy(javaType, false, progressMonitor);
+ ITypeHierarchy providerTypeHierarchy = JdtUtils.resolveTypeHierarchy(javaType, javaType.getJavaProject(), false, progressMonitor);
IType[] subtypes = providerTypeHierarchy.getSubtypes(javaType);
// assert that given java type has no sub-type, or continue;
if (subtypes != null && subtypes.length > 0) {
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsHttpMethod.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsHttpMethod.java 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsHttpMethod.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -195,7 +195,7 @@
* ()
*/
@Override
- public String getFullyQualifiedName() {
+ public String getJavaClassName() {
return getJavaElement().getFullyQualifiedName();
}
@@ -206,7 +206,7 @@
*/
@Override
public final String toString() {
- return "HttpMethod [@" + getFullyQualifiedName() + ":" + getHttpMethodAnnotation() + "]";
+ return "HttpMethod [@" + getJavaClassName() + ":" + getHttpMethodAnnotation() + "]";
}
@Override
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsJavaApplication.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsJavaApplication.java 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsJavaApplication.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -10,10 +10,11 @@
******************************************************************************/
package org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain;
-import static org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsElementDelta.F_APPLICATION_PATH_VALUE;
+import static org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsElementDelta.*;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.APPLICATION_PATH;
import org.eclipse.jdt.core.IType;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumElementCategory;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumElementKind;
@@ -27,6 +28,12 @@
*/
public class JaxrsJavaApplication extends JaxrsJavaElement<IType> implements IJaxrsApplication {
+ /** Indicates whether the underlying Java type is a subclass of <code>javax.ws.rs.core.Application</code>. */
+ private boolean isApplicationSubclass;
+
+ /** The ApplicationPath overriden value that can be configured in the web.xml. */
+ private String applicationPathOverride = null;
+
/**
* Full constructor.
*
@@ -34,27 +41,61 @@
* @param applicationPathAnnocation
* @param metamodel
*/
- public JaxrsJavaApplication(IType javaType, Annotation applicationPathAnnocation, JaxrsMetamodel metamodel) {
+ public JaxrsJavaApplication(final IType javaType, final Annotation applicationPathAnnocation, final boolean isApplicationSubclass, final JaxrsMetamodel metamodel) {
super(javaType, applicationPathAnnocation, metamodel);
+ this.isApplicationSubclass = isApplicationSubclass;
}
@Override
public EnumElementCategory getElementCategory() {
return EnumElementCategory.APPLICATION;
}
-
+
@Override
public EnumElementKind getElementKind() {
- if (getAnnotation(APPLICATION_PATH.qualifiedName) != null) {
- return EnumElementKind.APPLICATION_JAVA;
- }
- return EnumElementKind.UNDEFINED;
+ return EnumElementKind.APPLICATION_JAVA;
}
+
+ public boolean isJaxrsCoreApplicationSubclass() {
+ return isApplicationSubclass;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.jboss.tools.ws.jaxrs.core.internal.metamodel.IHttpMethod#getSimpleName
+ * ()
+ */
+ @Override
+ public String getJavaClassName() {
+ return getJavaElement().getFullyQualifiedName();
+ }
/**
+ * Sets the ApplicationPath override that can be configured from web.xml
+ * @param applicationPathOverride the override value
+ */
+ public void setApplicationPathOverride(final String applicationPathOverride) {
+ Logger.debug("Override @ApplicationPath value with '{}'", applicationPathOverride);
+ this.applicationPathOverride = applicationPathOverride;
+ }
+
+ /**
+ * Unsets the ApplicationPath override that can be configured from web.xml
+ */
+ public void unsetApplicationPathOverride() {
+ Logger.debug("Unoverriding @ApplicationPath value");
+ this.applicationPathOverride = null;
+ }
+
+ /**
* {@inheritDoc}
*/
public String getApplicationPath() {
+ if(applicationPathOverride != null) {
+ return applicationPathOverride;
+ }
final Annotation applicationPathAnnotation = getAnnotation(APPLICATION_PATH.qualifiedName);
if (applicationPathAnnotation != null) {
return applicationPathAnnotation.getValue("value");
@@ -62,6 +103,10 @@
return null;
}
+ public boolean isOverriden() {
+ return (metamodel.getWebxmlApplication(this.getJavaClassName()) != null);
+ }
+
/**
* Update this Application with the elements of the given Application
*
@@ -73,17 +118,30 @@
int flags = 0;
final Annotation annotation = this.getAnnotation(APPLICATION_PATH.qualifiedName);
final Annotation otherAnnotation = application.getAnnotation(APPLICATION_PATH.qualifiedName);
- if (annotation != null && otherAnnotation != null && !annotation.equals(otherAnnotation)
- && annotation.update(otherAnnotation)) {
+ // handle case where annotation is added
+ if (annotation == null && otherAnnotation != null) {
+ flags += addOrUpdateAnnotation(annotation);
+ }
+ // handle case where annotation is removed
+ else if(annotation != null && otherAnnotation == null) {
+ flags += removeAnnotation(annotation);
+ }
+ // handle case where annotation is changed
+ else if(annotation != null && otherAnnotation != null
+ && annotation.update(otherAnnotation)) {
flags += F_APPLICATION_PATH_VALUE;
}
+
+ if(this.isJaxrsCoreApplicationSubclass() != application.isJaxrsCoreApplicationSubclass()) {
+ flags += F_APPLICATION_HIERARCHY;
+ }
+
return flags;
}
@Override
public String toString() {
- return ("Application '" + getJavaElement().getElementName() + "': " + getApplicationPath());
+ return ("JavaApplication '" + getJavaElement().getElementName() + "': " + getApplicationPath());
}
-
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsJavaElement.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsJavaElement.java 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsJavaElement.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -36,6 +36,7 @@
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.RETENTION;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.TARGET;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
@@ -43,21 +44,10 @@
import java.util.Map;
import java.util.Map.Entry;
-import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
-import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IMember;
-import org.eclipse.jdt.core.ISourceRange;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.wst.validation.ValidatorMessage;
-import org.jboss.tools.ws.jaxrs.core.internal.metamodel.validation.JaxrsMetamodelValidator;
import org.jboss.tools.ws.jaxrs.core.internal.utils.CollectionUtils;
-import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
-import org.jboss.tools.ws.jaxrs.core.internal.utils.ValidationMessages;
import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
-import org.jboss.tools.ws.jaxrs.core.jdt.CompilationUnitsRepository;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumElementKind;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsHttpMethod;
@@ -89,7 +79,7 @@
* the underlying java element
*/
public JaxrsJavaElement(final T element, final Annotation annotation, final JaxrsMetamodel metamodel) {
- this(element, Arrays.asList(annotation), metamodel);
+ this(element, (annotation != null ? Arrays.asList(annotation) : new ArrayList<Annotation>()), metamodel);
}
/**
@@ -130,7 +120,7 @@
public int addOrUpdateAnnotation(final Annotation annotation) {
if (annotation == null) {
- return 0;
+ return F_NONE;
}
boolean changed = false;
final EnumElementKind previousKind = getElementKind();
@@ -194,7 +184,7 @@
flag = F_PRODUCED_MEDIATYPES_VALUE;
} else {
for (IJaxrsHttpMethod httpMethod : metamodel.getAllHttpMethods()) {
- if (httpMethod.getFullyQualifiedName().equals(annotationName)) {
+ if (httpMethod.getJavaClassName().equals(annotationName)) {
flag = F_HTTP_METHOD_VALUE;
break;
}
@@ -243,7 +233,7 @@
flag = F_RETENTION_VALUE;
} else {
for (IJaxrsHttpMethod httpMethod : metamodel.getAllHttpMethods()) {
- if (httpMethod.getFullyQualifiedName().equals(annotationName)) {
+ if (httpMethod.getJavaClassName().equals(annotationName)) {
flag = F_HTTP_METHOD_VALUE;
break;
}
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-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsMetamodel.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -11,6 +11,13 @@
package org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain;
+import static org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsBuiltinHttpMethod.DELETE;
+import static org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsBuiltinHttpMethod.GET;
+import static org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsBuiltinHttpMethod.HEAD;
+import static org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsBuiltinHttpMethod.OPTIONS;
+import static org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsBuiltinHttpMethod.POST;
+import static org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsBuiltinHttpMethod.PUT;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -23,21 +30,24 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
-import static org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsBuiltinHttpMethod.*;
+
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.JavaModelException;
import org.jboss.tools.ws.jaxrs.core.JBossJaxrsCorePlugin;
import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
+import org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname;
import org.jboss.tools.ws.jaxrs.core.jdt.JdtUtils;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumElementCategory;
+import org.jboss.tools.ws.jaxrs.core.metamodel.EnumElementKind;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsApplication;
+import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsElement;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsEndpoint;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsHttpMethod;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsMetamodel;
@@ -81,12 +91,16 @@
/** The HTTP ResourceMethod elements container. */
private final List<JaxrsHttpMethod> httpMethods = new ArrayList<JaxrsHttpMethod>();
- /** Internal index of all the elements of this metamodel. */
- private final Map<String, Set<JaxrsBaseElement>> elementsIndex = new HashMap<String, Set<JaxrsBaseElement>>();
+ /** Internal index of all the elements of this metamodel (by handleIdentifier of their associated java element). */
+ private final Map<String, Set<IJaxrsElement>> elementsIndex = new HashMap<String, Set<IJaxrsElement>>();
+ /** Internal index of all the elements of this metamodel (by fullpath of their underlying resource). */
+ private final Map<String, Set<IJaxrsElement>> resourcesIndex = new HashMap<String, Set<IJaxrsElement>>();
+
/** the endpoints, built from the resource methods. */
private final List<JaxrsEndpoint> endpoints = new ArrayList<JaxrsEndpoint>();
+
/**
* Full constructor.
*
@@ -97,9 +111,35 @@
*/
private JaxrsMetamodel(final IJavaProject javaProject) throws CoreException {
this.javaProject = javaProject;
- preloadHttpMethods();
+ init();
}
+
+ @Override
+ public IJaxrsMetamodel getMetamodel() {
+ return this;
+ }
+ @Override
+ public EnumElementKind getElementKind() {
+ return EnumElementKind.METAMODEL;
+ }
+
+ @Override
+ public EnumElementCategory getElementCategory() {
+ return EnumElementCategory.METAMODEL;
+ }
+
+ @Override
+ public IResource getResource() {
+ return getProject();
+ }
+
+ @Override
+ public String getName() {
+ return "JAX-RS Metamodel for project " + getProject().getName();
+ }
+
+
/**
* Preload the HttpMethods collection with 6 items from the specification:
* <ul>
@@ -111,14 +151,16 @@
* <li>@HEAD</li>
* </ul>
*/
- private void preloadHttpMethods() {
+ private void init() {
httpMethods.addAll(Arrays.asList(GET, POST, PUT, DELETE, HEAD, OPTIONS));
- elementsIndex.put(GET.getFullyQualifiedName(), new HashSet<JaxrsBaseElement>(Arrays.asList(GET)));
- elementsIndex.put(POST.getFullyQualifiedName(), new HashSet<JaxrsBaseElement>(Arrays.asList(POST)));
- elementsIndex.put(PUT.getFullyQualifiedName(), new HashSet<JaxrsBaseElement>(Arrays.asList(PUT)));
- elementsIndex.put(DELETE.getFullyQualifiedName(), new HashSet<JaxrsBaseElement>(Arrays.asList(DELETE)));
- elementsIndex.put(OPTIONS.getFullyQualifiedName(), new HashSet<JaxrsBaseElement>(Arrays.asList(OPTIONS)));
- elementsIndex.put(HEAD.getFullyQualifiedName(), new HashSet<JaxrsBaseElement>(Arrays.asList(HEAD)));
+ elementsIndex.put(GET.getJavaClassName(), new HashSet<IJaxrsElement>(Arrays.asList(GET)));
+ elementsIndex.put(POST.getJavaClassName(), new HashSet<IJaxrsElement>(Arrays.asList(POST)));
+ elementsIndex.put(PUT.getJavaClassName(), new HashSet<IJaxrsElement>(Arrays.asList(PUT)));
+ elementsIndex.put(DELETE.getJavaClassName(), new HashSet<IJaxrsElement>(Arrays.asList(DELETE)));
+ elementsIndex.put(OPTIONS.getJavaClassName(), new HashSet<IJaxrsElement>(Arrays.asList(OPTIONS)));
+ elementsIndex.put(HEAD.getJavaClassName(), new HashSet<IJaxrsElement>(Arrays.asList(HEAD)));
+
+ indexElement(this, getProject());
}
/*
@@ -190,7 +232,8 @@
return app1.getElementKind().compareTo(app2.getElementKind());
}
});
- indexElement(application, javaProject);
+ indexElement(application, this.javaProject);
+ indexElement(application, application.getResource());
}
/** @param jaxrsElement */
@@ -201,6 +244,7 @@
unindexElement(jaxrsElement);
// then, index for good
indexElement(jaxrsElement, javaElement);
+ indexElement(jaxrsElement, javaElement.getResource());
// index element that are bound to a java type, not a field or a method
// if (element.getJavaElement().getElementType() == IJavaElement.TYPE) {
indexElement(jaxrsElement, JdtUtils.getCompilationUnit(javaElement));
@@ -225,12 +269,13 @@
protected void indexElement(final JaxrsJavaElement<?> element, final Annotation annotation) {
if (annotation != null) {
indexElement(element, annotation.getJavaAnnotation());
+ indexElement(element, annotation.getJavaAnnotation().getResource());
}
}
/**
- * @param jaxrsElement
- * @param javaElement
+ * @param jaxrsElement the JAX-RS element of the metamodel to index
+ * @param javaElement the associated Java Element
*/
private void indexElement(final JaxrsBaseElement jaxrsElement, final IJavaElement javaElement) {
if (javaElement == null) {
@@ -238,14 +283,30 @@
}
final String key = javaElement.getHandleIdentifier();
if (!elementsIndex.containsKey(key)) {
- elementsIndex.put(key, new HashSet<JaxrsBaseElement>(Arrays.asList(jaxrsElement)));
+ elementsIndex.put(key, new HashSet<IJaxrsElement>(Arrays.asList(jaxrsElement)));
} else {
elementsIndex.get(key).add(jaxrsElement);
}
}
+ /**
+ * @param jaxrsElement the JAX-RS element of the metamodel to index
+ * @param resource the underlying resource
+ */
+ private void indexElement(final IJaxrsElement jaxrsElement, final IResource resource) {
+ if (resource == null) {
+ return;
+ }
+ final String key = resource.getFullPath().toPortableString();
+ if (!resourcesIndex.containsKey(key)) {
+ resourcesIndex.put(key, new HashSet<IJaxrsElement>(Arrays.asList(jaxrsElement)));
+ } else {
+ resourcesIndex.get(key).add(jaxrsElement);
+ }
+ }
+
/** @param jaxrsElement */
- protected void unindexElement(final JaxrsBaseElement jaxrsElement) {
+ protected void unindexElement(final IJaxrsElement jaxrsElement) {
// if the given element is a JAX-RS Resource, also unindex its children
// ResourceMethod
if (jaxrsElement.getElementCategory() == EnumElementCategory.RESOURCE) {
@@ -258,15 +319,24 @@
}
}
// unindex the given element, whatever its kind
- for (Iterator<Entry<String, Set<JaxrsBaseElement>>> indexIterator = elementsIndex.entrySet().iterator(); indexIterator
+ unindex(jaxrsElement, elementsIndex);
+ unindex(jaxrsElement, resourcesIndex);
+ }
+
+ /**
+ * @param jaxrsElement
+ * @param index
+ */
+ private void unindex(final IJaxrsElement jaxrsElement, Map<String, Set<IJaxrsElement>> index) {
+ for (Iterator<Entry<String, Set<IJaxrsElement>>> indexIterator = index.entrySet().iterator(); indexIterator
.hasNext();) {
- final Entry<String, Set<JaxrsBaseElement>> indexEntry = indexIterator.next();
- final Set<JaxrsBaseElement> indexEntryElements = indexEntry.getValue();
- // because the elements.remove(jaxrsElement); does not work here
+ final Entry<String, Set<IJaxrsElement>> indexEntry = indexIterator.next();
+ final Set<IJaxrsElement> indexEntryElements = indexEntry.getValue();
+ // iterating because the elements.remove(jaxrsElement); does not work here
// (hashcode has changed between the time the jaxrsElement was added
// and now !)
- for (Iterator<JaxrsBaseElement> indexEntryElementsIterator = indexEntryElements.iterator(); indexEntryElementsIterator.hasNext();) {
- JaxrsBaseElement element = indexEntryElementsIterator.next();
+ for (Iterator<IJaxrsElement> indexEntryElementsIterator = indexEntryElements.iterator(); indexEntryElementsIterator.hasNext();) {
+ IJaxrsElement element = indexEntryElementsIterator.next();
if (element.equals(jaxrsElement)) {
Logger.trace(" Removing {} from index", element);
indexEntryElementsIterator.remove();
@@ -287,23 +357,24 @@
* @param handleIdentifier
*/
protected void unindexElement(final JaxrsBaseElement jaxrsElement, final String handleIdentifier) {
- Set<JaxrsBaseElement> jaxrsElements = elementsIndex.get(handleIdentifier);
+ Set<IJaxrsElement> jaxrsElements = elementsIndex.get(handleIdentifier);
if (jaxrsElements != null) {
jaxrsElements.remove(jaxrsElement);
}
}
/**
- * Returns an unmodifiable list of all the elements in the Metamodel.
+ * Returns an unmodifiable set of all the elements in the Metamodel.
* @return
*/
- public List<JaxrsBaseElement> getAllElements() {
- final Collection<Set<JaxrsBaseElement>> values = elementsIndex.values();
- final List<JaxrsBaseElement> elements = new ArrayList<JaxrsBaseElement>();
- for (Set<JaxrsBaseElement> subSet : values) {
+ public Set<IJaxrsElement> getAllElements() {
+ // using a set automatically remove duplicates (because elements are indexed under several criteria)
+ final Collection<Set<IJaxrsElement>> values = elementsIndex.values();
+ final Set<IJaxrsElement> elements = new HashSet<IJaxrsElement>();
+ for (Set<IJaxrsElement> subSet : values) {
elements.addAll(subSet);
}
- return Collections.unmodifiableList(elements);
+ return Collections.unmodifiableSet(elements);
}
@@ -311,18 +382,139 @@
* @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).
+ * If multiple applications have been defined, the pure web.xml one is returned.
*/
public final IJaxrsApplication getApplication() {
- if (applications.isEmpty()) {
+ // try to return pure web.xml first
+ final JaxrsWebxmlApplication webxmlApplication = getWebxmlApplication();
+ if(webxmlApplication != null) {
+ return webxmlApplication;
+ }
+ final List<JaxrsJavaApplication> javaApplications = getJavaApplications();
+ if (javaApplications.isEmpty()) {
return null;
}
- return applications.get(0);
+ // otherwise, return first java-based application
+ return javaApplications.get(0);
}
+
+ /**
+ * Returns the Application (Java or Webxml) those underlying resource matches the given resource, or null if not found
+ * @param changedResource
+ * @return the associated application or null
+ */
+ public final IJaxrsApplication getApplication(IResource changedResource) {
+ for (IJaxrsApplication application : this.applications) {
+ if(application.getResource().equals(changedResource)) {
+ return application;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @return the java application that matches the given classname, or null if none was found.
+ */
+ public final JaxrsJavaApplication getJavaApplication(final String className) {
+ if (className != null) {
+ for (IJaxrsApplication application : this.applications) {
+ if (application.getElementKind() == EnumElementKind.APPLICATION_JAVA && className.equals(application.getJavaClassName())) {
+ return (JaxrsJavaApplication) application;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @return the webxml application that matches the given classname, or null if none was found.
+ */
+ public final JaxrsWebxmlApplication getWebxmlApplication(final String className) {
+ if (className != null) {
+ for (IJaxrsApplication application : this.applications) {
+ if (application.getElementKind() == EnumElementKind.APPLICATION_WEBXML && className.equals(application.getJavaClassName())) {
+ return (JaxrsWebxmlApplication) application;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @return all the JAX-RS Application in the Metamodel
+ * The result is a separate unmodifiable list
+ */
public final List<IJaxrsApplication> getAllApplications() {
- return Collections.unmodifiableList(new ArrayList<IJaxrsApplication>(applications));
+ return Collections.unmodifiableList(new ArrayList<IJaxrsApplication>(this.applications));
}
+
+
+ /**
+ * @return true if the metamodel holds more than 1 <strong>real</strong> applicatio, that is, excluding all
+ * application overrides configured in the web deployment descriptor. Returns false otherwise.
+ */
+ @SuppressWarnings("incomplete-switch")
+ public boolean hasMultipleApplications() {
+ final List<IJaxrsApplication> realApplications = new ArrayList<IJaxrsApplication>();
+ for (IJaxrsApplication application : this.applications) {
+ switch (application.getElementKind()) {
+ case APPLICATION_JAVA:
+ realApplications.add(application);
+ break;
+ case APPLICATION_WEBXML:
+ if (!((JaxrsWebxmlApplication) application).isOverride()) {
+ realApplications.add(application);
+ }
+ break;
+ }
+ }
+ return realApplications.size() > 1;
+ }
+
+ /**
+ * @return the <strong>pure JEE</strong> web.xml based application. There can be only one (at most), defined with the
+ * <code>javax.ws.rs.core.Application</code> class name. Other web.xml application declarations are just to
+ * override the java-based application <code>@ApplicationPath</code> value and <strong>will not be returned</strong> by this method.
+ */
+ public final JaxrsWebxmlApplication getWebxmlApplication() {
+ for (IJaxrsApplication application : this.applications) {
+ if (application.getElementKind() == EnumElementKind.APPLICATION_WEBXML
+ && EnumJaxrsClassname.APPLICATION.qualifiedName.equals(application.getJavaClassName())) {
+ return (JaxrsWebxmlApplication) application;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @return the web.xml based application and all the java-based application overrides, or an empty collection if
+ * none exist in the metamodel.
+ */
+ public final List<JaxrsWebxmlApplication> getWebxmlApplications() {
+ final List<JaxrsWebxmlApplication> webxmlApplications = new ArrayList<JaxrsWebxmlApplication>();
+ for (IJaxrsApplication application : this.applications) {
+ if (application.getElementKind() == EnumElementKind.APPLICATION_WEBXML) {
+ webxmlApplications.add((JaxrsWebxmlApplication) application);
+ }
+ }
+ return Collections.unmodifiableList(webxmlApplications);
+ }
+
+ /**
+ * @return the web.xml based application and all the java-based application overrides, or an empty collection if
+ * none exist in the metamodel.
+ */
+ public final List<JaxrsJavaApplication> getJavaApplications() {
+ final List<JaxrsJavaApplication> javaApplications = new ArrayList<JaxrsJavaApplication>();
+ for (IJaxrsApplication application : this.applications) {
+ if (application.getElementKind() == EnumElementKind.APPLICATION_JAVA) {
+ javaApplications.add((JaxrsJavaApplication) application);
+ }
+ }
+ return Collections.unmodifiableList(javaApplications);
+ }
public final List<IJaxrsProvider> getAllProviders() {
return Collections.unmodifiableList(new ArrayList<IJaxrsProvider>(providers));
}
@@ -336,27 +528,6 @@
}
/**
- * Returns the JAX-RS ElementKind associated with the given java element.
- *
- * @param element
- * the underlying java element (can be IType or IMethod)
- * @return the associated JAX-RS element, or null if none found
- * @throws JavaModelException
- * in case of underlying exception
- */
- public final JaxrsJavaElement<?> find(final IJavaElement element) throws JavaModelException {
- switch (element.getElementType()) {
- case IJavaElement.TYPE:
- // return findElement((IType) element);
- case IJavaElement.METHOD:
- // return findElement((IMethod) element);
- default:
- break;
- }
- return null;
- }
-
- /**
* @param annotation
* (GET, POST, etc..)
* @param metamodel
@@ -368,13 +539,13 @@
IType annotationType = JdtUtils.resolveType(annotationName, javaProject, new NullProgressMonitor());
if (annotationType != null) {
// look for custom HTTP Methods
- JaxrsBaseElement element = getElement(annotationType);
+ IJaxrsElement element = getElement(annotationType);
if (element != null && element.getElementCategory() == EnumElementCategory.HTTP_METHOD) {
return (IJaxrsHttpMethod) element;
}
// if not found, look for built-in HTTP Methods
else if(element == null) {
- element = getElement(annotationType.getFullyQualifiedName());
+ element = getElementByIdentifier(annotationType.getFullyQualifiedName());
if (element != null && element.getElementCategory() == EnumElementCategory.HTTP_METHOD) {
return (IJaxrsHttpMethod) element;
}
@@ -393,58 +564,85 @@
return (getElement(element.getJavaElement()) != null);
}
- public JaxrsBaseElement getElement(IJavaElement element) {
+ /**
+ * Return the JAX-RS element matching the given Java Element
+ * @param element the java element
+ * @return the JAX-RS element or null if none found
+ */
+ public IJaxrsElement getElement(IJavaElement element) {
if (element == null) {
return null;
}
- return getElement(element.getHandleIdentifier());
+ return getElementByIdentifier(element.getHandleIdentifier());
}
- protected JaxrsBaseElement getElement(final String elementName) {
- if (elementName == null) {
+ public List<IJaxrsElement> getElements(final IResource resource) {
+ if (resource == null) {
return null;
}
- final Set<JaxrsBaseElement> elements = elementsIndex.get(elementName);
+ final Set<IJaxrsElement> elements = resourcesIndex.get(resource.getFullPath().toOSString());
if (elements == null || elements.isEmpty()) {
+ return Collections.emptyList();
+ }
+ return new ArrayList<IJaxrsElement>(elements);
+ }
+
+
+ /**
+ * Return the JAX-RS element matching the given Java Element Handle Identifier
+ * @param element the java element handle identifier
+ * @return the JAX-RS element or null if none found
+ */
+ private IJaxrsElement getElementByIdentifier(final String elementHandleIdentifier) {
+ if (elementHandleIdentifier == null) {
return null;
}
+ final Set<IJaxrsElement> elements = elementsIndex.get(elementHandleIdentifier);
+ if(elements == null || elements.isEmpty()) {
+ return null;
+ }
return elements.iterator().next();
}
- public JaxrsBaseElement getElement(Annotation annotation) {
+ /**
+ * Return the JAX-RS element matching the given Java Annotation
+ * @param element the java annotation
+ * @return the JAX-RS element or null if none found
+ */
+ public IJaxrsElement getElement(Annotation annotation) {
return getElement(annotation.getJavaAnnotation());
}
@Override
@SuppressWarnings("unchecked")
public <T> T getElement(IJavaElement element, Class<T> clazz) {
- final JaxrsBaseElement jaxrsElement = getElement(element);
+ final IJaxrsElement jaxrsElement = getElement(element);
if (jaxrsElement != null && clazz.isAssignableFrom(jaxrsElement.getClass())) {
return (T) jaxrsElement;
}
return null;
}
- public List<JaxrsBaseElement> getElements(final IJavaElement javaElement) {
+ public List<IJaxrsElement> getElements(final IJavaElement javaElement) {
if(javaElement == null) {
return Collections.emptyList();
}
final String key = javaElement.getHandleIdentifier();
- final List<JaxrsBaseElement> result = new ArrayList<JaxrsBaseElement>();
+ final List<IJaxrsElement> result = new ArrayList<IJaxrsElement>();
if (elementsIndex.containsKey(key)) {
- final Set<JaxrsBaseElement> indexedElements = elementsIndex.get(key);
+ final Set<IJaxrsElement> indexedElements = elementsIndex.get(key);
result.addAll(indexedElements);
}
return result;
}
@SuppressWarnings("unchecked")
- public <T extends JaxrsBaseElement> List<T> getElements(final IJavaElement javaElement,
+ public <T extends IJaxrsElement> List<T> getElements(final IJavaElement javaElement,
Class<? extends JaxrsBaseElement> T) {
final String key = javaElement.getHandleIdentifier();
final List<T> elements = new ArrayList<T>();
if (elementsIndex.containsKey(key)) {
- for (JaxrsBaseElement element : elementsIndex.get(key)) {
+ for (IJaxrsElement element : elementsIndex.get(key)) {
if (element.getClass().isAssignableFrom(T) || T.isAssignableFrom(element.getClass())) {
elements.add((T) element);
}
@@ -453,7 +651,7 @@
return elements;
}
- public void remove(JaxrsBaseElement element) {
+ public void remove(IJaxrsElement element) {
if (element == null) {
return;
}
@@ -486,7 +684,7 @@
public JaxrsHttpMethod getHttpMethod(Annotation httpMethodAnnotation) {
if (httpMethodAnnotation != null) {
for (IJaxrsHttpMethod httpMethod : httpMethods) {
- final String handleIdentifier1 = httpMethod.getFullyQualifiedName();
+ final String handleIdentifier1 = httpMethod.getJavaClassName();
final String handleIdentifier2 = httpMethodAnnotation.getName();
if (handleIdentifier1.equals(handleIdentifier2)) {
return (JaxrsHttpMethod) httpMethod;
@@ -559,5 +757,10 @@
return javaProject.getProject();
}
+
+
+
+
+
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsResourceMethod.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsResourceMethod.java 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsResourceMethod.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -252,7 +252,7 @@
public Annotation getHttpMethodAnnotation() {
for (IJaxrsHttpMethod httpMethod : getMetamodel().getAllHttpMethods()) {
final Annotation annotation = getAnnotation(httpMethod
- .getFullyQualifiedName());
+ .getJavaClassName());
if (annotation != null) {
return annotation;
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsWebxmlApplication.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsWebxmlApplication.java 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsWebxmlApplication.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -3,6 +3,7 @@
import static org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsElementDelta.F_APPLICATION_PATH_VALUE;
import org.eclipse.core.resources.IResource;
+import org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumElementCategory;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumElementKind;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsApplication;
@@ -11,28 +12,54 @@
private String applicationPath;
+ private String javaClassName;
+
private final IResource webxmlResource;
-
+
/**
* Full constructor.
*
* @param metamodel
*/
- public JaxrsWebxmlApplication(String applicationPath, IResource webxmlResource, JaxrsMetamodel metamodel) {
+ public JaxrsWebxmlApplication(final String applicationClassName, final String applicationPath, final IResource webxmlResource, final JaxrsMetamodel metamodel) {
super(metamodel);
- this.applicationPath = formatApplicationPath(applicationPath);
+ this.applicationPath = normalizeApplicationPath(applicationPath);
this.webxmlResource = webxmlResource;
+ this.javaClassName = applicationClassName;
+
}
+ /**
+ * @return true if the applicationClassName given in the constructor matches an existing Java Application in the
+ * metamodel, false otherwise.
+ */
+ public boolean isOverride() {
+ return (this.javaClassName != null) &&
+ !this.javaClassName.equals(EnumJaxrsClassname.APPLICATION.qualifiedName);
+ }
+
+ /**
+ * @return the Java application whose underlying Java Type fully qualified name matches the given application class
+ * name in the constructor, null otherwise.
+ */
+ public JaxrsJavaApplication getOverridenJaxrsJavaApplication() {
+ return metamodel.getJavaApplication(javaClassName);
+ }
+
@Override
public String getApplicationPath() {
return applicationPath;
}
+ public String getJavaClassName() {
+ return javaClassName;
+ }
+
+
public int update(JaxrsWebxmlApplication eventApplication) {
if (eventApplication != null) {
- String eventApplicationPath = formatApplicationPath(eventApplication.getApplicationPath());
- if ((eventApplicationPath.equals(this.applicationPath))) {
+ String eventApplicationPath = normalizeApplicationPath(eventApplication.getApplicationPath());
+ if (!(eventApplicationPath.equals(this.applicationPath))) {
this.applicationPath = eventApplicationPath;
return F_APPLICATION_PATH_VALUE;
}
@@ -40,7 +67,7 @@
return 0;
}
- private String formatApplicationPath(final String eventApplicationPath) {
+ private String normalizeApplicationPath(final String eventApplicationPath) {
String path = eventApplicationPath.replace("/*", "/");
if (path.length() > 1 && path.endsWith("/")) {
path = path.substring(0, path.length() - 1);
@@ -95,6 +122,7 @@
if (getClass() != obj.getClass()) {
return false;
}
+ // compare resource location
JaxrsWebxmlApplication other = (JaxrsWebxmlApplication) obj;
if (webxmlResource == null && other.webxmlResource != null) {
return false;
@@ -103,7 +131,24 @@
} else if (webxmlResource != null && other.webxmlResource != null && !webxmlResource.getFullPath().equals(other.webxmlResource.getFullPath())) {
return false;
}
+ // compare java class name
+ if (javaClassName == null && other.javaClassName != null) {
+ return false;
+ } else if (javaClassName != null && other.javaClassName == null) {
+ return false;
+ } else if (javaClassName != null && other.javaClassName != null && !javaClassName.equals(other.javaClassName)) {
+ return false;
+ }
+ // don't compare application path, this is something that can change
+
+ //
return true;
}
+
+ @Override
+ public String toString() {
+ return ("WebxmlApplication '" + javaClassName + "': " + getApplicationPath());
+ }
+
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/AbstractJaxrsElementValidatorDelegate.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/AbstractJaxrsElementValidatorDelegate.java 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/AbstractJaxrsElementValidatorDelegate.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -10,15 +10,19 @@
******************************************************************************/
package org.jboss.tools.ws.jaxrs.core.internal.metamodel.validation;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.jboss.tools.common.validation.TempMarkerManager;
-import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsBaseElement;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
/**
+ * Abstract validator delegate with bits of generics for better readability in subclasses
+ *
* @author Xavier Coulon
*
*/
-public abstract class AbstractJaxrsElementValidatorDelegate<T extends JaxrsBaseElement> {
+public abstract class AbstractJaxrsElementValidatorDelegate<T extends Object> {
private final T element;
@@ -35,11 +39,27 @@
return element;
}
- /**
- * @return the validator
- */
- public TempMarkerManager getMarkerManager() {
+ TempMarkerManager getMarkerManager() {
return markerManager;
}
+
+ public IMarker addProblem(String message, String preferenceKey, String[] messageArguments, int length, int offset, IResource target) {
+ Logger.debug("Reporting problem '{}' on resource '{}'", message, target.getFullPath().toString());
+ return markerManager.addProblem(message, preferenceKey, messageArguments, length, offset, target);
+ }
+
+ public IMarker addProblem(String message, String preferenceKey, String[] messageArguments, int length, int offset, IResource target, int quickFixId) {
+ Logger.debug("Reporting problem '{}' on resource '{}'", message, target.getFullPath().toString());
+ return markerManager.addProblem(message, preferenceKey, messageArguments, length, offset, target, quickFixId);
+ }
+
+ public static void deleteJaxrsMarkers(final IResource resource) throws CoreException {
+ if (resource == null) {
+ return;
+ }
+ Logger.debug("Clearing JAX-RS markers for resource " + resource.getName());
+ resource.deleteMarkers(JaxrsMetamodelValidator.JAXRS_PROBLEM_TYPE, true, IResource.DEPTH_ONE);
+ }
+
}
Deleted: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsApplicationValidatorDelegate.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsApplicationValidatorDelegate.java 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsApplicationValidatorDelegate.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -1,22 +0,0 @@
-package org.jboss.tools.ws.jaxrs.core.internal.metamodel.validation;
-
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-import org.jboss.tools.common.validation.TempMarkerManager;
-import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsJavaApplication;
-
-public class JaxrsApplicationValidatorDelegate extends AbstractJaxrsElementValidatorDelegate<JaxrsJavaApplication> {
-
- public JaxrsApplicationValidatorDelegate(TempMarkerManager markerManager, JaxrsJavaApplication element) {
- super(markerManager, element);
- }
-
- @Override
- public void validate() throws CoreException {
- final JaxrsJavaApplication resource = getElement();
- MarkerUtils.clearMarkers(resource.getResource());
- }
-
-
-
-}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsHttpMethodValidatorDelegate.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsHttpMethodValidatorDelegate.java 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsHttpMethodValidatorDelegate.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -22,6 +22,8 @@
import org.jboss.tools.ws.jaxrs.core.preferences.JaxrsPreferences;
/**
+ * HTTP Method validator.
+ *
* @author Xavier Coulon
*
*/
@@ -34,7 +36,7 @@
@Override
public void validate() throws CoreException {
final JaxrsHttpMethod httpMethod = getElement();
- MarkerUtils.clearMarkers(httpMethod.getResource());
+ deleteJaxrsMarkers(httpMethod.getResource());
if (!httpMethod.isBuiltIn()) {
validateHttpMethodAnnotation(httpMethod);
validateRetentionAnnotation(getElement());
@@ -53,9 +55,9 @@
if (annotation != null) { // if annotation is null, the resource is not a JaxrsHttpMethod anymore.
final String httpValue = annotation.getValue("value");
if (httpValue == null || httpValue.isEmpty()) {
- getMarkerManager().addProblem(JaxrsValidationMessages.HTTP_METHOD_INVALID_RETENTION_ANNOTATION_VALUE,
- JaxrsPreferences.HTTP_METHOD_INVALID_RETENTION_ANNOTATION_VALUE, new String[0],
- annotation.getSourceRange().getLength(), annotation.getSourceRange().getOffset(),
+ addProblem(JaxrsValidationMessages.HTTP_METHOD_INVALID_RETENTION_ANNOTATION_VALUE,
+ JaxrsPreferences.HTTP_METHOD_INVALID_RETENTION_ANNOTATION_VALUE, new String[0], annotation
+ .getSourceRange().getLength(), annotation.getSourceRange().getOffset(),
httpMethod.getResource());
}
}
@@ -71,18 +73,17 @@
final Annotation targetAnnotation = httpMethod.getTargetAnnotation();
final Annotation httpMethodAnnotation = httpMethod.getHttpMethodAnnotation();
if (targetAnnotation == null) {
- getMarkerManager().addProblem(JaxrsValidationMessages.HTTP_METHOD_MISSING_TARGET_ANNOTATION,
- JaxrsPreferences.HTTP_METHOD_MISSING_TARGET_ANNOTATION, new String[0],
- httpMethodAnnotation.getSourceRange().getLength(),
- httpMethodAnnotation.getSourceRange().getOffset(), httpMethod.getResource(),
- JaxrsValidationQuickFixes.HTTP_METHOD_MISSING_TARGET_ANNOTATION_ID);
+ addProblem(JaxrsValidationMessages.HTTP_METHOD_MISSING_TARGET_ANNOTATION,
+ JaxrsPreferences.HTTP_METHOD_MISSING_TARGET_ANNOTATION, new String[0], httpMethodAnnotation
+ .getSourceRange().getLength(), httpMethodAnnotation.getSourceRange().getOffset(),
+ httpMethod.getResource(), JaxrsValidationQuickFixes.HTTP_METHOD_MISSING_TARGET_ANNOTATION_ID);
} else {
final String annotationValue = targetAnnotation.getValue("value");
if (annotationValue == null || !annotationValue.equals(ElementType.METHOD.name())) {
- getMarkerManager().addProblem(JaxrsValidationMessages.HTTP_METHOD_INVALID_TARGET_ANNOTATION_VALUE,
+ addProblem(JaxrsValidationMessages.HTTP_METHOD_INVALID_TARGET_ANNOTATION_VALUE,
JaxrsPreferences.HTTP_METHOD_INVALID_TARGET_ANNOTATION_VALUE, new String[0],
- httpMethodAnnotation.getSourceRange().getLength(),
- httpMethodAnnotation.getSourceRange().getOffset(), httpMethod.getResource(),
+ httpMethodAnnotation.getSourceRange().getLength(), httpMethodAnnotation.getSourceRange()
+ .getOffset(), httpMethod.getResource(),
JaxrsValidationQuickFixes.HTTP_METHOD_INVALID_TARGET_ANNOTATION_VALUE_ID);
}
}
@@ -98,18 +99,17 @@
final Annotation retentionAnnotation = httpMethod.getRetentionAnnotation();
final Annotation httpMethodAnnotation = httpMethod.getHttpMethodAnnotation();
if (retentionAnnotation == null) {
- getMarkerManager().addProblem(JaxrsValidationMessages.HTTP_METHOD_MISSING_RETENTION_ANNOTATION,
- JaxrsPreferences.HTTP_METHOD_MISSING_RETENTION_ANNOTATION, new String[0],
- httpMethodAnnotation.getSourceRange().getLength(),
- httpMethodAnnotation.getSourceRange().getOffset(), httpMethod.getResource(),
- JaxrsValidationQuickFixes.HTTP_METHOD_MISSING_RETENTION_ANNOTATION_ID);
+ addProblem(JaxrsValidationMessages.HTTP_METHOD_MISSING_RETENTION_ANNOTATION,
+ JaxrsPreferences.HTTP_METHOD_MISSING_RETENTION_ANNOTATION, new String[0], httpMethodAnnotation
+ .getSourceRange().getLength(), httpMethodAnnotation.getSourceRange().getOffset(),
+ httpMethod.getResource(), JaxrsValidationQuickFixes.HTTP_METHOD_MISSING_RETENTION_ANNOTATION_ID);
} else {
final String annotationValue = retentionAnnotation.getValue("value");
if (annotationValue == null || !annotationValue.equals(RetentionPolicy.RUNTIME.name())) {
- getMarkerManager().addProblem(JaxrsValidationMessages.HTTP_METHOD_INVALID_RETENTION_ANNOTATION_VALUE,
+ addProblem(JaxrsValidationMessages.HTTP_METHOD_INVALID_RETENTION_ANNOTATION_VALUE,
JaxrsPreferences.HTTP_METHOD_INVALID_RETENTION_ANNOTATION_VALUE, new String[0],
- httpMethodAnnotation.getSourceRange().getLength(),
- httpMethodAnnotation.getSourceRange().getOffset(), httpMethod.getResource(),
+ httpMethodAnnotation.getSourceRange().getLength(), httpMethodAnnotation.getSourceRange()
+ .getOffset(), httpMethod.getResource(),
JaxrsValidationQuickFixes.HTTP_METHOD_INVALID_RETENTION_ANNOTATION_VALUE_ID);
}
}
Copied: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsJavaApplicationValidatorDelegate.java (from rev 43794, trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsApplicationValidatorDelegate.java)
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsJavaApplicationValidatorDelegate.java (rev 0)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsJavaApplicationValidatorDelegate.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.ws.jaxrs.core.internal.metamodel.validation;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.ISourceRange;
+import org.eclipse.jdt.core.IType;
+import org.jboss.tools.common.validation.TempMarkerManager;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsJavaApplication;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
+import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
+import org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname;
+import org.jboss.tools.ws.jaxrs.core.metamodel.quickfix.JaxrsValidationQuickFixes;
+import org.jboss.tools.ws.jaxrs.core.preferences.JaxrsPreferences;
+
+/**
+ * Java-based JAX-RS Application validator
+ *
+ * @author Xavier Coulon
+ *
+ */
+public class JaxrsJavaApplicationValidatorDelegate extends AbstractJaxrsElementValidatorDelegate<JaxrsJavaApplication> {
+
+ public JaxrsJavaApplicationValidatorDelegate(TempMarkerManager markerManager, JaxrsJavaApplication application) {
+ super(markerManager, application);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.ws.jaxrs.core.internal.metamodel.validation.AbstractJaxrsElementValidatorDelegate#validate()
+ */
+ @Override
+ public void validate() throws CoreException {
+ final JaxrsJavaApplication application = getElement();
+ deleteJaxrsMarkers(application.getResource());
+
+ final Annotation applicationPathAnnotation = application
+ .getAnnotation(EnumJaxrsClassname.APPLICATION_PATH.qualifiedName);
+ final IType appJavaElement = application.getJavaElement();
+ if (!application.isOverriden() && applicationPathAnnotation == null) {
+ addProblem(JaxrsValidationMessages.JAVA_APPLICATION_MISSING_APPLICATION_PATH_ANNOTATION,
+ JaxrsPreferences.JAVA_APPLICATION_MISSING_APPLICATION_PATH_ANNOTATION, new String[0],
+ appJavaElement.getSourceRange().getLength(), appJavaElement.getSourceRange().getOffset(),
+ application.getResource(),
+ JaxrsValidationQuickFixes.JAVA_APPLICATION_MISSING_APPLICATION_PATH_ANNOTATION_ID);
+ }
+ if (!application.isJaxrsCoreApplicationSubclass()) {
+ addProblem(JaxrsValidationMessages.JAVA_APPLICATION_INVALID_TYPE_HIERARCHY,
+ JaxrsPreferences.JAVA_APPLICATION_INVALID_TYPE_HIERARCHY,
+ new String[] { appJavaElement.getFullyQualifiedName() }, application.getJavaElement()
+ .getSourceRange().getLength(), appJavaElement.getSourceRange().getOffset(),
+ application.getResource(), JaxrsValidationQuickFixes.JAVA_APPLICATION_INVALID_TYPE_HIERARCHY_ID);
+ }
+
+ if (application.getMetamodel().hasMultipleApplications()) {
+ final IResource javaResource = application.getResource();
+ ISourceRange javaNameRange = application.getJavaElement().getNameRange();
+ if (javaNameRange == null) {
+ Logger.warn("Cannot add a problem marker: unable to locate '"
+ + application.getJavaElement().getElementName() + "' in resource '"
+ + application.getJavaElement().getResource().getFullPath().toString() + "'. ");
+ } else {
+ addProblem(JaxrsValidationMessages.APPLICATION_TOO_MANY_OCCURRENCES,
+ JaxrsPreferences.APPLICATION_TOO_MANY_OCCURRENCES, new String[0],
+ javaNameRange.getLength(), javaNameRange.getOffset(), javaResource);
+ }
+ }
+
+ }
+
+}
Property changes on: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsJavaApplicationValidatorDelegate.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/validation/JaxrsMetamodelValidator.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMetamodelValidator.java 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMetamodelValidator.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -11,11 +11,13 @@
package org.jboss.tools.ws.jaxrs.core.internal.metamodel.validation;
import java.util.Collection;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
@@ -34,16 +36,23 @@
import org.jboss.tools.common.validation.internal.SimpleValidatingProjectTree;
import org.jboss.tools.ws.jaxrs.core.configuration.ProjectNatureUtils;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsMetamodelBuilder;
-import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsBaseElement;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsHttpMethod;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsJavaApplication;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsMetamodel;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsResource;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsWebxmlApplication;
import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
-import org.jboss.tools.ws.jaxrs.core.jdt.JdtUtils;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsApplication;
+import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsElement;
import org.jboss.tools.ws.jaxrs.core.metamodel.JaxrsMetamodelLocator;
import org.jboss.tools.ws.jaxrs.core.preferences.JaxrsPreferences;
+/**
+ * JAX-RS Metamodel Validator. Relies on delegates to validate each category of element.
+ *
+ * @author Xavier Coulon
+ *
+ */
@SuppressWarnings("restriction")
public class JaxrsMetamodelValidator extends TempMarkerManager implements IValidator, IAsYouTypeValidator {
@@ -87,26 +96,24 @@
*/
public IStatus validate(Set<IFile> changedFiles, IProject project, ContextValidationHelper validationHelper,
IProjectValidationContext context, ValidatorManager manager, IReporter reporter) throws ValidationException {
- Logger.debug("*** Validating project {} after files {} changed... ***", project.getName(), changedFiles.toString());
+ Logger.debug("*** Validating project {} after files {} changed... ***", project.getName(),
+ changedFiles.toString());
init(project, validationHelper, context, manager, reporter);
setAsYouTypeValidation(false);
try {
if (!changedFiles.isEmpty()) {
- for (IFile changedFile : changedFiles) {
- try {
- final JaxrsMetamodel jaxrsMetamodel = JaxrsMetamodelLocator.get(changedFile.getProject());
- validateJaxrsApplicationDeclarations(jaxrsMetamodel);
- validate(reporter, changedFile, jaxrsMetamodel);
- } catch (CoreException e) {
- Logger.error("Failed to validate changed file " + changedFile.getName() + " in project "
- + changedFile.getProject(), e);
- }
+ final JaxrsMetamodel jaxrsMetamodel = JaxrsMetamodelLocator.get(project);
+ final Set<IResource> allResources = completeValidationSet(jaxrsMetamodel, (IResource[]) changedFiles.toArray());
+ for (IResource changedResource : allResources) {
+ validate(reporter, changedResource, jaxrsMetamodel);
}
- }
+ }
// trigger a full validation instead
else {
validateAll(project, validationHelper, context, manager, reporter);
}
+ } catch (CoreException e) {
+ Logger.error("Failed to validate changed files " + changedFiles + " in project " + project, e);
} finally {
Logger.debug("Validation done.");
}
@@ -114,22 +121,43 @@
}
/**
+ * @param jaxrsMetamodel
+ * @param objects
+ * @return
+ */
+ private Set<IResource> completeValidationSet(JaxrsMetamodel jaxrsMetamodel, final IResource... changedResources) {
+ final Set<IResource> resources = new HashSet<IResource>();
+ for(IResource changedResource : changedResources) {
+ resources.add(changedResource);
+ if(jaxrsMetamodel.getApplication(changedResource) != null) {
+ Logger.debug("Adding all applications and project in the set of files to validate...");
+ for(IJaxrsApplication application : jaxrsMetamodel.getAllApplications()) {
+ resources.add(application.getResource());
+ }
+ resources.add(jaxrsMetamodel.getProject());
+ }
+ }
+ return resources;
+ }
+
+ /**
* @param reporter
- * @param file
+ * @param changedResource
* @throws CoreException
*/
- private void validate(final IReporter reporter, final IFile file, final JaxrsMetamodel jaxrsMetamodel) {
- if (reporter.isCancelled() || !file.isAccessible()) {
+ private void validate(final IReporter reporter, final IResource changedResource, final JaxrsMetamodel jaxrsMetamodel) {
+ if (reporter.isCancelled() || !changedResource.isAccessible()) {
return;
}
displaySubtask(JaxrsValidationMessages.VALIDATING_RESOURCE,
- new String[] { file.getProject().getName(), file.getName() });
+ new String[] { changedResource.getProject().getName(), changedResource.getName() });
try {
if (jaxrsMetamodel != null) {
- List<JaxrsBaseElement> elements = jaxrsMetamodel.getElements(JdtUtils.getCompilationUnit(file));
- for (JaxrsBaseElement element : elements) {
+ List<IJaxrsElement> elements = jaxrsMetamodel.getElements(changedResource);
+ for (IJaxrsElement element : elements) {
validate(element);
}
+
}
} catch (CoreException e) {
Logger.error("Failed to validate the resource change", e);
@@ -139,8 +167,9 @@
@Override
public void validate(org.eclipse.wst.validation.internal.provisional.core.IValidator validatorManager,
IProject rootProject, Collection<IRegion> dirtyRegions, IValidationContext helper, IReporter reporter,
- EditorValidationContext validationContext, IProjectValidationContext projectContext, IFile file) {
- Logger.debug("*** Validating project {} after file {} changed... ***", file.getProject().getName(), file.getFullPath());
+ EditorValidationContext validationContext, IProjectValidationContext projectContext, IFile changedFile) {
+ Logger.debug("*** Validating project {} after file {} changed... ***", changedFile.getProject().getName(),
+ changedFile.getFullPath());
ContextValidationHelper validationHelper = new ContextValidationHelper();
validationHelper.setProject(rootProject);
validationHelper.setValidationContextManager(validationContext);
@@ -148,15 +177,15 @@
setAsYouTypeValidation(false);
this.document = validationContext.getDocument();
displaySubtask(JaxrsValidationMessages.VALIDATING_RESOURCE,
- new String[] { file.getProject().getName(), file.getName() });
+ new String[] { changedFile.getProject().getName(), changedFile.getName() });
try {
- final JaxrsMetamodel jaxrsMetamodel = JaxrsMetamodelLocator.get(file.getProject());
- validateJaxrsApplicationDeclarations(jaxrsMetamodel);
- validate(reporter, file, jaxrsMetamodel);
+ final JaxrsMetamodel jaxrsMetamodel = JaxrsMetamodelLocator.get(changedFile.getProject());
+ final Set<IResource> allResources = completeValidationSet(jaxrsMetamodel, changedFile);
+ for (IResource changedResource : allResources) {
+ validate(reporter, changedResource, jaxrsMetamodel);
+ }
} catch (CoreException e) {
- Logger.error(
- "Failed to validate changed file " + file.getName() + " in project "
- + file.getProject(), e);
+ Logger.error("Failed to validate changed file " + changedFile.getName() + " in project " + changedFile.getProject(), e);
} finally {
Logger.debug("Validation done.");
}
@@ -172,13 +201,11 @@
displaySubtask(JaxrsValidationMessages.VALIDATING_PROJECT, new String[] { project.getName() });
try {
final JaxrsMetamodel jaxrsMetamodel = JaxrsMetamodelLocator.get(project);
- // validate that the number of jax-rs applications (java or web.xml) is 1.
- validateJaxrsApplicationDeclarations(jaxrsMetamodel);
- // validate all other elements
if (jaxrsMetamodel != null) {
- for (JaxrsBaseElement element : jaxrsMetamodel.getAllElements()) {
+ for (IJaxrsElement element : jaxrsMetamodel.getAllElements()) {
validate(element);
}
+ validate(jaxrsMetamodel);
}
} catch (CoreException e) {
Logger.error("Failed to validate project '", e);
@@ -189,24 +216,6 @@
return Status.OK_STATUS;
}
- private void validateJaxrsApplicationDeclarations(JaxrsMetamodel jaxrsMetamodel) throws CoreException {
- if(jaxrsMetamodel == null) {
- return;
- }
- MarkerUtils.clearMarkers(jaxrsMetamodel.getProject());
- final List<IJaxrsApplication> allApplications = jaxrsMetamodel.getAllApplications();
- if(allApplications.isEmpty()) {
- this.addProblem(JaxrsValidationMessages.APPLICATION_NO_OCCURRENCE_FOUND,
- JaxrsPreferences.APPLICATION_NO_OCCURRENCE_FOUND, new String[0],
- 0, 0, jaxrsMetamodel.getProject());
-
- } else if(allApplications.size() > 1) {
- this.addProblem(JaxrsValidationMessages.APPLICATION_TOO_MANY_OCCURRENCES,
- JaxrsPreferences.APPLICATION_TOO_MANY_OCCURRENCES, new String[0],
- 0, 0, jaxrsMetamodel.getProject());
- }
- }
-
/**
* Uses the appropriate validator to validate the given JAX-RS element, or does nothing if no validator could be
* found.
@@ -214,21 +223,35 @@
* @param element
* @throws CoreException
*/
- private void validate(JaxrsBaseElement element) throws CoreException {
- Logger.debug("Validating element {}", element.getName());
- switch (element.getElementCategory()) {
- case APPLICATION:
+ @SuppressWarnings("incomplete-switch")
+ private void validate(IJaxrsElement element) throws CoreException {
+ Logger.debug("Validating element {}", element);
+ switch (element.getElementCategory()) {
+ case METAMODEL:
+ new JaxrsMetamodelValidatorDelegate(this, (JaxrsMetamodel)element).validate();
+ break;
+ case APPLICATION:
+ switch (element.getElementKind()) {
+ case APPLICATION_JAVA:
+ new JaxrsJavaApplicationValidatorDelegate(this, (JaxrsJavaApplication) element).validate();
break;
- case HTTP_METHOD:
- new JaxrsHttpMethodValidatorDelegate(this, (JaxrsHttpMethod) element).validate();
- case PROVIDER:
+ case APPLICATION_WEBXML:
+ new JaxrsWebxmlApplicationValidatorDelegate(this, (JaxrsWebxmlApplication) element).validate();
break;
- case RESOURCE:
- // this validator delegate also deals with ResourceMethods and ResourceFields
- new JaxrsResourceValidatorDelegate(this, (JaxrsResource) element).validate();
- default:
- // skipping other categories of elements at this validator level. (see above)
- break;
+ }
+ break;
+ case HTTP_METHOD:
+ new JaxrsHttpMethodValidatorDelegate(this, (JaxrsHttpMethod) element).validate();
+ break;
+ case PROVIDER:
+ break;
+ case RESOURCE:
+ // this validator delegate also deals with ResourceMethods and ResourceFields
+ new JaxrsResourceValidatorDelegate(this, (JaxrsResource) element).validate();
+ break;
+ default:
+ // skipping other categories of elements at this validator level. (see above)
+ break;
}
}
Copied: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMetamodelValidatorDelegate.java (from rev 43794, trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsApplicationValidatorDelegate.java)
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMetamodelValidatorDelegate.java (rev 0)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMetamodelValidatorDelegate.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.ws.jaxrs.core.internal.metamodel.validation;
+
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.jboss.tools.common.validation.TempMarkerManager;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsMetamodel;
+import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsApplication;
+import org.jboss.tools.ws.jaxrs.core.preferences.JaxrsPreferences;
+
+/**
+ * JAX-RS Metamodel validator: validate the total number of applications (which should be exactly one)
+ *
+ * @author Xavier Coulon
+ *
+ */
+public class JaxrsMetamodelValidatorDelegate extends AbstractJaxrsElementValidatorDelegate<JaxrsMetamodel> {
+
+ public JaxrsMetamodelValidatorDelegate(TempMarkerManager markerManager, JaxrsMetamodel metamodel) {
+ super(markerManager, metamodel);
+ }
+
+ @Override
+ public void validate() throws CoreException {
+ final JaxrsMetamodel metamodel = getElement();
+ final IProject project = metamodel.getProject();
+ deleteJaxrsMarkers(project);
+ final List<IJaxrsApplication> allApplications = metamodel.getAllApplications();
+ if (allApplications.isEmpty()) {
+ addProblem(JaxrsValidationMessages.APPLICATION_NO_OCCURRENCE_FOUND,
+ JaxrsPreferences.APPLICATION_NO_OCCURRENCE_FOUND, new String[0], 0, 0, project);
+
+ }
+ }
+
+}
Property changes on: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMetamodelValidatorDelegate.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/validation/JaxrsResourceMethodValidatorDelegate.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsResourceMethodValidatorDelegate.java 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsResourceMethodValidatorDelegate.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -30,7 +30,7 @@
import org.jboss.tools.ws.jaxrs.core.preferences.JaxrsPreferences;
/**
- * Validates the given JAX-RS resource
+ * JAX-RS Resource Method validator.
*
* @author Xavier Coulon
*
@@ -87,10 +87,7 @@
}
if (counter > 1) {
final ISourceRange nameRange = resourceMethod.getJavaElement().getNameRange();
- Logger.debug("Reporting problem of type {} on ResourceMethod {}.{}",
- JaxrsPreferences.RESOURCE_METHOD_MORE_THAN_ONE_UNANNOTATED_PARAMETER, resourceMethod
- .getParentResource().getName(), resourceMethod.getName());
- getMarkerManager().addProblem(JaxrsValidationMessages.RESOURCE_METHOD_MORE_THAN_ONE_UNANNOTATED_PARAMETER,
+ addProblem(JaxrsValidationMessages.RESOURCE_METHOD_MORE_THAN_ONE_UNANNOTATED_PARAMETER,
JaxrsPreferences.RESOURCE_METHOD_MORE_THAN_ONE_UNANNOTATED_PARAMETER, new String[0],
nameRange.getLength(), nameRange.getOffset(), resourceMethod.getResource());
resourceMethod.hasErrors(true);
@@ -111,10 +108,7 @@
final Annotation contextAnnotation = parameter.getAnnotation(CONTEXT.qualifiedName);
final String typeName = parameter.getTypeName();
if (contextAnnotation != null && typeName != null && !CONTEXT_TYPE_NAMES.contains(typeName)) {
- Logger.debug("Reporting problem of type {} on ResourceMethod {}.{}",
- JaxrsPreferences.RESOURCE_METHOD_ILLEGAL_CONTEXT_ANNOTATION, resourceMethod.getParentResource()
- .getName(), resourceMethod.getName());
- getMarkerManager().addProblem(JaxrsValidationMessages.RESOURCE_METHOD_ILLEGAL_CONTEXT_ANNOTATION,
+ addProblem(JaxrsValidationMessages.RESOURCE_METHOD_ILLEGAL_CONTEXT_ANNOTATION,
JaxrsPreferences.RESOURCE_METHOD_ILLEGAL_CONTEXT_ANNOTATION,
new String[] { CONTEXT_TYPE_NAMES.toString() }, contextAnnotation.getSourceRange().getLength(),
contextAnnotation.getSourceRange().getOffset(), resourceMethod.getResource());
@@ -144,11 +138,7 @@
final ISourceRange nameRange = resourceMethod.getJavaElement().getNameRange();
for (String pathTemplateParameter : pathParamValueProposals) {
if (!pathParamValues.contains(pathTemplateParameter)) {
- Logger.debug("Reporting problem of type {} on ResourceMethod {}.{}",
- JaxrsPreferences.RESOURCE_METHOD_UNBOUND_PATH_ANNOTATION_TEMPLATE_PARAMETER, resourceMethod
- .getParentResource().getName(), resourceMethod.getName());
- getMarkerManager().addProblem(
- JaxrsValidationMessages.RESOURCE_METHOD_UNBOUND_PATH_ANNOTATION_TEMPLATE_PARAMETER,
+ addProblem(JaxrsValidationMessages.RESOURCE_METHOD_UNBOUND_PATH_ANNOTATION_TEMPLATE_PARAMETER,
JaxrsPreferences.RESOURCE_METHOD_UNBOUND_PATH_ANNOTATION_TEMPLATE_PARAMETER,
new String[] { pathTemplateParameter }, nameRange.getLength(), nameRange.getOffset(),
resourceMethod.getResource());
@@ -174,22 +164,14 @@
if (pathParamValue != null) {
if (!pattern.matcher(pathParamValue).matches()) {
final ISourceRange sourceRange = annotation.getSourceRange();
- Logger.debug("Reporting problem of type {} on ResourceMethod {}.{}",
- JaxrsPreferences.RESOURCE_METHOD_INVALID_PATHPARAM_ANNOTATION_VALUE, resourceMethod
- .getParentResource().getName(), resourceMethod.getName());
- getMarkerManager().addProblem(
- JaxrsValidationMessages.RESOURCE_METHOD_UNBOUND_PATHPARAM_ANNOTATION_VALUE,
+ addProblem(JaxrsValidationMessages.RESOURCE_METHOD_UNBOUND_PATHPARAM_ANNOTATION_VALUE,
JaxrsPreferences.RESOURCE_METHOD_UNBOUND_PATHPARAM_ANNOTATION_VALUE,
new String[] { pathParamValue }, sourceRange.getLength(), sourceRange.getOffset(),
resourceMethod.getResource());
resourceMethod.hasErrors(true);
} else if (!pathParamValueProposals.contains(pathParamValue)) {
final ISourceRange sourceRange = annotation.getSourceRange();
- Logger.debug("Reporting problem of type {} on ResourceMethod {}.{}",
- JaxrsPreferences.RESOURCE_METHOD_UNBOUND_PATHPARAM_ANNOTATION_VALUE, resourceMethod
- .getParentResource().getName(), resourceMethod.getName());
- getMarkerManager().addProblem(
- JaxrsValidationMessages.RESOURCE_METHOD_UNBOUND_PATHPARAM_ANNOTATION_VALUE,
+ addProblem(JaxrsValidationMessages.RESOURCE_METHOD_UNBOUND_PATHPARAM_ANNOTATION_VALUE,
JaxrsPreferences.RESOURCE_METHOD_UNBOUND_PATHPARAM_ANNOTATION_VALUE,
new String[] { pathParamValue }, sourceRange.getLength(), sourceRange.getOffset(),
resourceMethod.getResource());
@@ -199,17 +181,15 @@
}
}
}
-
+
private void validatePublicModifierOnJavaMethod(final JaxrsResourceMethod resourceMethod) throws JavaModelException {
final IMethod javaMethod = resourceMethod.getJavaElement();
- if(javaMethod != null && !Flags.isPublic(javaMethod.getFlags())) {
+ if (javaMethod != null && !Flags.isPublic(javaMethod.getFlags())) {
final ISourceRange nameRange = javaMethod.getNameRange();
- getMarkerManager().addProblem(
- JaxrsValidationMessages.RESOURCE_METHOD_NO_PUBLIC_MODIFIER,
- JaxrsPreferences.RESOURCE_METHOD_NO_PUBLIC_MODIFIER,
- new String[0], nameRange.getLength(), nameRange.getOffset(),
- resourceMethod.getResource());
+ addProblem(JaxrsValidationMessages.RESOURCE_METHOD_NO_PUBLIC_MODIFIER,
+ JaxrsPreferences.RESOURCE_METHOD_NO_PUBLIC_MODIFIER, new String[0], nameRange.getLength(),
+ nameRange.getOffset(), resourceMethod.getResource());
}
}
-
+
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsResourceValidatorDelegate.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsResourceValidatorDelegate.java 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsResourceValidatorDelegate.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -1,12 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.jboss.tools.ws.jaxrs.core.internal.metamodel.validation;
-import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.jboss.tools.common.validation.TempMarkerManager;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsResource;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsResourceMethod;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsResourceMethod;
+/**
+ * JAX-RS Resource validator.
+ *
+ * @author Xavier Coulon
+ *
+ */
public class JaxrsResourceValidatorDelegate extends AbstractJaxrsElementValidatorDelegate<JaxrsResource> {
public JaxrsResourceValidatorDelegate(TempMarkerManager markerManager, JaxrsResource element) {
@@ -16,12 +31,13 @@
@Override
public void validate() throws CoreException {
final JaxrsResource resource = getElement();
- MarkerUtils.clearMarkers(resource.getResource());
+ deleteJaxrsMarkers(resource.getResource());
for(IJaxrsResourceMethod resourceMethod : resource.getAllMethods()) {
new JaxrsResourceMethodValidatorDelegate(getMarkerManager(), (JaxrsResourceMethod) resourceMethod).validate();
}
}
+ @SuppressWarnings("unused")
private void validateConstructorParameters() {
//TODO...
}
Deleted: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsValidationErrorManager.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsValidationErrorManager.java 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsValidationErrorManager.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -1,43 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 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:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.ws.jaxrs.core.internal.metamodel.validation;
-
-import org.eclipse.core.resources.IProject;
-import org.jboss.tools.common.preferences.SeverityPreferences;
-import org.jboss.tools.common.validation.TempMarkerManager;
-import org.jboss.tools.ws.jaxrs.core.preferences.JaxrsPreferences;
-
-abstract public class JaxrsValidationErrorManager extends TempMarkerManager {
-
- /*
- * (non-Javadoc)
- * @see org.jboss.tools.jst.web.kb.internal.validation.ValidationErrorManager#getPreference(org.eclipse.core.resources.IProject, java.lang.String)
- */
- @Override
- protected String getPreference(IProject project, String preferenceKey) {
- return severityPreferences.getProjectPreference(project, preferenceKey);
- }
-
- SeverityPreferences severityPreferences = JaxrsPreferences.getInstance();
-
- protected void setSeverityPreferences(SeverityPreferences severityPreferences) {
- this.severityPreferences = (severityPreferences == null) ? JaxrsPreferences.getInstance() : severityPreferences;
- }
-
- /*
- * (non-Javadoc)
- * @see org.jboss.tools.jst.web.kb.internal.validation.ValidationErrorManager#getMaxNumberOfMarkersPerFile(org.eclipse.core.resources.IProject)
- */
- @Override
- public int getMaxNumberOfMarkersPerFile(IProject project) {
- return JaxrsPreferences.getMaxNumberOfProblemMarkersPerFile(project);
- }
-}
\ No newline at end of file
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsValidationMessages.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsValidationMessages.java 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsValidationMessages.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -13,16 +13,26 @@
import org.eclipse.osgi.util.NLS;
/**
- * @author Alexey Kazakov
+ * JAX-RS Validation messages.
+ *
+ * @author Xavier Coulon
*/
public class JaxrsValidationMessages {
private static final String BUNDLE_NAME = JaxrsValidationMessages.class.getName(); //$NON-NLS-1$
+
+
+
public static String SEARCHING_RESOURCES;
public static String VALIDATING_RESOURCE;
public static String VALIDATING_PROJECT;
+ public static String APPLICATION_NO_OCCURRENCE_FOUND;
+ public static String APPLICATION_TOO_MANY_OCCURRENCES;
+ public static String JAVA_APPLICATION_MISSING_APPLICATION_PATH_ANNOTATION;
+ public static String JAVA_APPLICATION_INVALID_TYPE_HIERARCHY;
+
public static String HTTP_METHOD_MISSING_RETENTION_ANNOTATION;
public static String HTTP_METHOD_INVALID_RETENTION_ANNOTATION_VALUE;
public static String HTTP_METHOD_MISSING_TARGET_ANNOTATION;
@@ -35,8 +45,6 @@
public static String RESOURCE_METHOD_INVALID_PATHPARAM_ANNOTATION_VALUE;
public static String RESOURCE_METHOD_NO_PUBLIC_MODIFIER;
- public static String APPLICATION_NO_OCCURRENCE_FOUND;
- public static String APPLICATION_TOO_MANY_OCCURRENCES;
static {
NLS.initializeMessages(BUNDLE_NAME, JaxrsValidationMessages.class);
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsValidationMessages.properties
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsValidationMessages.properties 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsValidationMessages.properties 2012-09-21 21:39:42 UTC (rev 43940)
@@ -1,18 +1,20 @@
-SEARCHING_RESOURCES=project "{0}"; searching resources for validation (JAX-RS Validator).
-VALIDATING_RESOURCE=project "{0}"; resource "{1}" (JAX-RS Validator)
-VALIDATING_PROJECT=project "{0}" (JAX-RS Validator)
+SEARCHING_RESOURCES=project '''{0}'''; searching resources for validation (JAX-RS Validator).
+VALIDATING_RESOURCE=project '''{0}'''; resource '''{1}''' (JAX-RS Validator)
+VALIDATING_PROJECT=project '''{0}''' (JAX-RS Validator)
+APPLICATION_NO_OCCURRENCE_FOUND=No JAX-RS Activator is defined for the project.
+APPLICATION_TOO_MANY_OCCURRENCES=Multiple JAX-RS Activators are defined for the project.
+JAVA_APPLICATION_MISSING_APPLICATION_PATH_ANNOTATION=The Application Path should be configured with an @ApplicationPath annotation or in the web deployment descriptor.
+JAVA_APPLICATION_INVALID_TYPE_HIERARCHY=Type '''{0}''' should extend javax.ws.rs.core.Application.
HTTP_METHOD_MISSING_RETENTION_ANNOTATION=The HTTP Method should have a @Retention(RetentionPolicy.RUNTIME) annotation on its type.
HTTP_METHOD_INVALID_RETENTION_ANNOTATION_VALUE=The @Retention annotation value is not correct. It should be RetentionPolicy.RUNTIME
HTTP_METHOD_MISSING_TARGET_ANNOTATION=The HTTP Method should have a @Target(ElementType.METHOD) annotation on its type.
HTTP_METHOD_INVALID_TARGET_ANNOTATION_VALUE=The @Target annotation value is not correct. It should be ElementType.METHOD
-RESOURCE_METHOD_ILLEGAL_CONTEXT_ANNOTATION=@Context annotation is only allowed on method parameters of type {0}.
+RESOURCE_METHOD_ILLEGAL_CONTEXT_ANNOTATION=@Context annotation is only allowed on method parameters of type '''{0}'''.
RESOURCE_METHOD_MORE_THAN_ONE_UNANNOTATED_PARAMETER=At most one method parameter may be declared without any JAX-RS annotation to map the incoming request entity body.
-RESOURCE_METHOD_UNBOUND_PATHPARAM_ANNOTATION_VALUE=@PathParam value "{0}" does not match any @Path annotation template parameters of the java method and the enclosing java type.
-RESOURCE_METHOD_UNBOUND_PATH_ANNOTATION_TEMPLATE_PARAMETER=The @Path template parameter "{0}" is not bound to any @Path template parameter.
-RESOURCE_METHOD_INVALID_PATHPARAM_ANNOTATION_VALUE=The @PathParam annotation value "{0}" should be alphanumeric.
-RESOURCE_METHOD_NO_PUBLIC_MODIFIER=The method "{0}" should be public.
-APPLICATION_NO_OCCURRENCE_FOUND=No JAX-RS Activator is defined for the project.
-APPLICATION_TOO_MANY_OCCURRENCES=Multiple JAX-RS Activators are defined for the project.
+RESOURCE_METHOD_UNBOUND_PATHPARAM_ANNOTATION_VALUE=@PathParam value '''{0}''' does not match any @Path annotation template parameters of the java method and the enclosing java type.
+RESOURCE_METHOD_UNBOUND_PATH_ANNOTATION_TEMPLATE_PARAMETER=The @Path template parameter '''{0}''' is not bound to any @Path template parameter.
+RESOURCE_METHOD_INVALID_PATHPARAM_ANNOTATION_VALUE=The @PathParam annotation value '''{0}''' should be alphanumeric.
+RESOURCE_METHOD_NO_PUBLIC_MODIFIER=The method '''{0}''' should be public.
Added: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsWebxmlApplicationValidatorDelegate.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsWebxmlApplicationValidatorDelegate.java (rev 0)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsWebxmlApplicationValidatorDelegate.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.ws.jaxrs.core.internal.metamodel.validation;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.ISourceRange;
+import org.jboss.tools.common.validation.TempMarkerManager;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsWebxmlApplication;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.WtpUtils;
+import org.jboss.tools.ws.jaxrs.core.preferences.JaxrsPreferences;
+
+/**
+ * Web.xml based JAX-RS Application validator (includes validation for both <code>javax.ws.rs.core.Application</code>
+ * and project-specific subclasses).
+ *
+ * @author Xavier Coulon
+ *
+ */
+public class JaxrsWebxmlApplicationValidatorDelegate extends
+ AbstractJaxrsElementValidatorDelegate<JaxrsWebxmlApplication> {
+
+ /**
+ * @param markerManager
+ * @param application
+ */
+ public JaxrsWebxmlApplicationValidatorDelegate(TempMarkerManager markerManager, JaxrsWebxmlApplication application) {
+ super(markerManager, application);
+ }
+
+ @Override
+ public void validate() throws CoreException {
+ JaxrsWebxmlApplication webxmlApplication = getElement();
+ deleteJaxrsMarkers(webxmlApplication.getResource());
+
+ if (webxmlApplication.getMetamodel().hasMultipleApplications()) {
+ final IResource webxmlResource = webxmlApplication.getResource();
+ ISourceRange webxmlNameRange = WtpUtils.getApplicationPathLocation(webxmlApplication.getResource(),
+ webxmlApplication.getJavaClassName());
+ if (webxmlNameRange == null) {
+ Logger.warn("Cannot add a problem marker: unable to locate '" + webxmlApplication.getJavaClassName()
+ + "' in resource '" + webxmlApplication.getResource().getFullPath().toString() + "'. ");
+ } else {
+ addProblem(JaxrsValidationMessages.APPLICATION_TOO_MANY_OCCURRENCES,
+ JaxrsPreferences.APPLICATION_TOO_MANY_OCCURRENCES, new String[0], webxmlNameRange.getLength(), webxmlNameRange.getOffset(),
+ webxmlResource);
+ }
+ }
+ }
+
+}
Property changes on: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsWebxmlApplicationValidatorDelegate.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/validation/MarkerUtils.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/MarkerUtils.java 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/MarkerUtils.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -1,31 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012 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:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.ws.jaxrs.core.internal.metamodel.validation;
-
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
-
-/**
- * @author Xavier Coulon
- * The class name says it all.
- */
-public class MarkerUtils {
-
- public static void clearMarkers(final IResource resource) throws CoreException {
- if (resource == null) {
- return;
- }
- Logger.debug("Clearing JAX-RS markers for resource " + resource.getName());
- resource.deleteMarkers(JaxrsMetamodelValidator.JAXRS_PROBLEM_TYPE, true, IResource.DEPTH_ONE);
- }
-
-}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/CollectionUtils.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/CollectionUtils.java 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/CollectionUtils.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -119,5 +119,29 @@
}
return result;
}
+
+ public static <T> T[] append(T[] sourceArray, T extraElement, T[] targetArray) {
+ System.arraycopy(sourceArray, 0, targetArray, 0, sourceArray.length);
+ targetArray[targetArray.length -1] = extraElement;
+ return targetArray;
+ }
+
+ /**
+ * Returns true if the given source contains the given element, false otherwise
+ * @param source the array of elements
+ * @param element the element to find in the array
+ * @return true if found, false otherwise
+ */
+ public static <T> boolean contains(T[] source, T element) {
+ if(element == null || source == null) {
+ return false;
+ }
+ for(T item : source) {
+ if(item.equals(element)) {
+ return true;
+ }
+ }
+ return false;
+ }
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/ConstantUtils.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/ConstantUtils.java 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/ConstantUtils.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -12,6 +12,11 @@
import java.lang.reflect.Field;
+/**
+ * Utility to manipulate constants defined as "static final" attributes in classes
+ * @author Xavier Coulon
+ *
+ */
public class ConstantUtils {
public static String getStaticFieldName(final Class<?> clazz, final int value) {
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/ValidationMessages.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/ValidationMessages.java 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/ValidationMessages.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -13,6 +13,7 @@
import org.eclipse.osgi.util.NLS;
+ at Deprecated
public class ValidationMessages extends NLS {
private static final String BUNDLE_NAME = ValidationMessages.class.getName(); //$NON-NLS-1$
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/WtpUtils.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/WtpUtils.java 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/WtpUtils.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -1,12 +1,25 @@
package org.jboss.tools.ws.jaxrs.core.internal.utils;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringWriter;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
+import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.eclipse.core.resources.IFile;
@@ -15,6 +28,8 @@
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.core.ISourceRange;
+import org.eclipse.jdt.core.SourceRange;
import org.eclipse.jst.j2ee.web.componentcore.util.WebArtifactEdit;
import org.eclipse.wst.common.componentcore.ComponentCore;
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
@@ -22,6 +37,7 @@
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
public class WtpUtils {
@@ -56,14 +72,12 @@
* @return the applicationPath or null if it is not configured.
* @throws CoreException
*/
- public static String getApplicationPath(IProject project, String applicationTypeName) throws CoreException {
- IFolder webInfFolder = getWebInfFolder(project);
- if (webInfFolder == null) {
+ public static String getApplicationPath(IResource webxmlResource, String applicationTypeName) throws CoreException {
+ if(webxmlResource == null) {
return null;
}
- IResource webxmlResource = webInfFolder.findMember("web.xml");
- if (webxmlResource == null || !webxmlResource.exists()) {
- Logger.debug("No deployment descriptor found in project '{}'", project.getName());
+ if (!webxmlResource.exists()) {
+ Logger.debug("No deployment descriptor '{}' does not exists", webxmlResource.getLocation());
return null;
}
if (!webxmlResource.isSynchronized(IResource.DEPTH_INFINITE)) {
@@ -71,43 +85,11 @@
webxmlResource.refreshLocal(IResource.DEPTH_ZERO, new NullProgressMonitor());
}
- /*
- * WebArtifactEdit webArtifactEdit = WebArtifactEdit.getWebArtifactEditForRead(project); // if
- * (!webArtifactEdit.isValid()) { return null; } WebPackageImpl.eINSTANCE.getWebApp(); IModelProvider provider =
- * ModelProviderManager.getModelProvider(project); Object mObj = provider.getModelObject(); if (mObj instanceof
- * org.eclipse.jst.j2ee.webapplication.WebApp) { org.eclipse.jst.j2ee.webapplication.WebApp webApp =
- * (org.eclipse.jst.j2ee.webapplication.WebApp) mObj; } else if (mObj instanceof
- * org.eclipse.jst.javaee.web.WebApp) { org.eclipse.jst.javaee.web.WebApp webApp =
- * (org.eclipse.jst.javaee.web.WebApp) mObj; }
- */
- // final List<Servlet> servlets = webApp.getServlets();
- /*
- * webArtifactEdit.getDeploymentDescriptorRoot().eResource().unload();
- * webArtifactEdit.getDeploymentDescriptorRoot(); WebApp webApp = webArtifactEdit.getWebApp();
- * @SuppressWarnings("unchecked") EList<ServletMapping> servletMappings = webApp.getServletMappings(); for
- * (ServletMapping servletMapping : servletMappings) { if (servletMapping.getName().equals(applicationTypeName))
- * { return servletMapping.getUrlPattern(); } }
- */
- // using a good old xpath expression to scan the file.
-
try {
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- dbf.setNamespaceAware(false); // never forget this!
- dbf.setValidating(false);
- dbf.setFeature("http://xml.org/sax/features/namespaces", false);
- dbf.setFeature("http://xml.org/sax/features/validation", false);
- dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
- dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
- DocumentBuilder builder = dbf.newDocumentBuilder();
- final FileInputStream fileInputStream = new FileInputStream(webxmlResource.getLocation().toFile());
- InputSource inputSource = new InputSource(fileInputStream);
- Document doc = builder.parse(inputSource);
- XPath xpath = XPathFactory.newInstance().newXPath();
- String expression = "//servlet-mapping[servlet-name=\"" + applicationTypeName + "\"]/url-pattern/text()";
- XPathExpression expr = xpath.compile(expression);
- Node urlPattern = (Node) expr.evaluate(doc, XPathConstants.NODE);
+ final String expression = "//servlet-mapping[servlet-name=\"" + applicationTypeName + "\"]/url-pattern/text()";
+ final Node urlPattern = evaluateXPathExpression(webxmlResource, expression);
if (urlPattern != null) {
- Logger.debug("Found matching url-pattern: {}", urlPattern);
+ Logger.debug("Found matching url-pattern: {} for class {}", urlPattern.getTextContent(), applicationTypeName);
return urlPattern.getTextContent();
}
} catch (Exception e) {
@@ -115,12 +97,141 @@
+ "' to find <servlet-mapping> elements", e);
}
- Logger.debug("No servlet mapping found for {} in {}", applicationTypeName,
+ Logger.debug("No servlet mapping found for class '{}' in file '{}'", applicationTypeName,
webxmlResource.getProjectRelativePath());
return null;
}
/**
+ * Attempts to find the <strong>node range</strong> for the applicationPath configured in the application's web deployment description. The
+ * applicationPath is expected to be configured as below: <code>
+ * <servlet-mapping>
+ * <servlet-name>com.acme.MyApplication</servlet-name>
+ * <url-pattern>/hello/*</url-pattern>
+ * </servlet-mapping>
+ * </code> where
+ * <code>com.acme.MyApplication</code> is a subtype of <code>javax.ws.rs.Application</code> and is the given
+ * 'applicationType' parameter of this method. If the webapp does not provide its own subtype of
+ * <code>javax.ws.rs.Application</code>, then the applicationType parameter can be
+ * <code>javax.ws.rs.Application</code> itself.
+ *
+ * @param javaProject
+ * the current java project
+ * @param applicationTypeName
+ * the name of the type/subtype to match in the servlet-mapping
+ * @return the source range or null if it is not configured.
+ * @throws CoreException
+ */
+ public static ISourceRange getApplicationPathLocation(final IResource webxmlResource, final String applicationTypeName) throws CoreException {
+ if(webxmlResource == null) {
+ return null;
+ }
+ if (!webxmlResource.exists()) {
+ Logger.debug("No deployment descriptor '{}' does not exists", webxmlResource.getLocation());
+ return null;
+ }
+ try {
+ final String expression = "//servlet-mapping[servlet-name=\"" + applicationTypeName + "\"]";
+ final Node servletMappingNode = evaluateXPathExpression(webxmlResource, expression);
+ if (servletMappingNode != null) {
+ StringWriter writer = new StringWriter();
+ Transformer transformer = TransformerFactory.newInstance().newTransformer();
+ transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
+ transformer.transform(new DOMSource(servletMappingNode), new StreamResult(writer));
+ String servletMappingXml = writer.toString();
+ Logger.debug("Found matching servlet-mapping: {}", servletMappingXml);
+ final InputStream contents = ((IFile)webxmlResource).getContents();
+ int offset = findLocation(contents, servletMappingXml);
+ if(offset != -1) {
+ int length = servletMappingXml.length();
+ return new SourceRange(offset-length+1, length);
+ }
+ return new SourceRange(0, 0);
+ }
+ } catch (Exception e) {
+ Logger.error("Unable to parse file '" + webxmlResource.getProjectRelativePath().toOSString()
+ + "' to find <servlet-mapping> elements", e);
+ }
+
+ Logger.debug("No servlet mapping found for class '{}' in file '{}'", applicationTypeName,
+ webxmlResource.getProjectRelativePath());
+ return null;
+ }
+
+ /**
+ * Return the searchString location in the input source
+ * @param reader
+ * @param searchString
+ * @return the matching location or -1 if not found
+ * @throws IOException
+ */
+ private static int findLocation(InputStream stream, String searchString) throws IOException {
+ char[] buffer = new char[1024];
+ int location = -1;
+ int numCharsRead;
+ int count = 0;
+ Reader reader = null;
+ try {
+ reader = new InputStreamReader(stream);
+ // reading the stream
+ while ((numCharsRead = reader.read(buffer)) > 0) {
+ // reading the buffer
+ for (int c = 0; c < numCharsRead; c++) {
+ location++;
+ // character matching -> keep counting
+ if (buffer[c] == searchString.charAt(count)) {
+ count++;
+ }
+ // character mismatch -> reset counter
+ else {
+ count = 0;
+ }
+ // whole match -> \o/
+ if (count == searchString.length()) {
+ return location;
+ }
+ }
+ }
+ return -1;
+ } finally {
+ if (reader != null) {
+ reader.close();
+ }
+ }
+ }
+
+
+ /**
+ * @param webxmlResource
+ * @param applicationTypeName
+ * @return
+ * @throws ParserConfigurationException
+ * @throws FileNotFoundException
+ * @throws SAXException
+ * @throws IOException
+ * @throws XPathExpressionException
+ */
+ private static Node evaluateXPathExpression(final IResource webxmlResource, final String expression)
+ throws ParserConfigurationException, FileNotFoundException, SAXException, IOException,
+ XPathExpressionException {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(false); // never forget this!
+ dbf.setValidating(false);
+ dbf.setFeature("http://xml.org/sax/features/namespaces", false);
+ dbf.setFeature("http://xml.org/sax/features/validation", false);
+ dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
+ dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
+ DocumentBuilder builder = dbf.newDocumentBuilder();
+ final FileInputStream fileInputStream = new FileInputStream(webxmlResource.getLocation().toFile());
+ InputSource inputSource = new InputSource(fileInputStream);
+ Document doc = builder.parse(inputSource);
+ XPath xpath = XPathFactory.newInstance().newXPath();
+ XPathExpression expr = xpath.compile(expression);
+ Node servletMapping = (Node) expr.evaluate(doc, XPathConstants.NODE);
+ return servletMapping;
+ }
+
+ /**
* Indicates if the given resource is the web deployment descriptor (or not).
*
* @param resource
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-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JaxrsAnnotationsScanner.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -11,6 +11,7 @@
package org.jboss.tools.ws.jaxrs.core.jdt;
+import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.APPLICATION;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.APPLICATION_PATH;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.HTTP_METHOD;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.PATH;
@@ -25,6 +26,7 @@
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.ITypeHierarchy;
import org.eclipse.jdt.core.search.IJavaSearchConstants;
import org.eclipse.jdt.core.search.IJavaSearchScope;
import org.eclipse.jdt.core.search.SearchEngine;
@@ -44,9 +46,8 @@
/**
* 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).
+ * <code>javax.ws.rs.ApplicationPath</code> annotation and subtypes of
+ * {@link javax.ws.rs.Application} (even if type hirarchy or annotation is missing).
*
*
* @param scope
@@ -61,10 +62,24 @@
*/
public static List<IType> findApplicationTypes(final IJavaElement scope, final IProgressMonitor progressMonitor)
throws CoreException {
+ //FIXME: need correct usage of progressmonitor/subprogress monitor
+
+ // first, search for type annotated with <code>javax.ws.rs.ApplicationPath</code>
IJavaSearchScope searchScope = null;
searchScope = SearchEngine.createJavaSearchScope(new IJavaElement[] { scope }, IJavaSearchScope.SOURCES
| IJavaSearchScope.REFERENCED_PROJECTS);
- return searchForAnnotatedTypes(APPLICATION_PATH.qualifiedName, searchScope, progressMonitor);
+
+ final List<IType> applicationTypes = searchForAnnotatedTypes(APPLICATION_PATH.qualifiedName, searchScope, progressMonitor);
+ // the search result also includes all subtypes of javax.ws.rs.core.Application (while avoiding duplicate results)
+ final IType applicationType = JdtUtils.resolveType(APPLICATION.qualifiedName, scope.getJavaProject(), progressMonitor);
+ final ITypeHierarchy applicationTypeHierarchy = JdtUtils.resolveTypeHierarchy(applicationType, scope, false, progressMonitor);
+ final IType[] allSubtypes = applicationTypeHierarchy.getAllSubtypes(applicationType);
+ for(IType subtype : allSubtypes) {
+ if(subtype.getJavaProject().equals(scope.getJavaProject()) && !applicationTypes.contains(subtype)) {
+ applicationTypes.add(subtype);
+ }
+ }
+ return applicationTypes;
}
/**
@@ -195,7 +210,7 @@
List<String> annotations = new ArrayList<String>(httpMethods.size() + 1);
annotations.add(PATH.qualifiedName);
for (IJaxrsHttpMethod httpMethod : httpMethods) {
- annotations.add(httpMethod.getFullyQualifiedName());
+ annotations.add(httpMethod.getJavaClassName());
}
return searchForAnnotatedMethods(annotations, searchScope, progressMonitor);
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JdtUtils.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JdtUtils.java 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JdtUtils.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -436,7 +436,7 @@
* the underlying CoreException thrown by the manipulated JDT
* APIs
*/
- public static ITypeHierarchy resolveTypeHierarchy(final IType baseType, final boolean includeLibraries,
+ public static ITypeHierarchy resolveTypeHierarchy(final IType baseType, final IJavaElement scope, final boolean includeLibraries,
final IProgressMonitor progressMonitor) throws CoreException {
// create type hierarchy
// FIXME : restrict operation scope to sources only, exclude application
@@ -446,7 +446,7 @@
appLibs = IJavaSearchScope.APPLICATION_LIBRARIES;
}
IJavaSearchScope searchScope = SearchEngine.createJavaSearchScope(
- new IJavaElement[] { baseType.getJavaProject() }, IJavaSearchScope.SOURCES | appLibs
+ new IJavaElement[] { scope }, IJavaSearchScope.SOURCES | appLibs
| IJavaSearchScope.REFERENCED_PROJECTS);
CreateTypeHierarchyOperation operation = new CreateTypeHierarchyOperation(baseType, null, searchScope, true);
ITypeHierarchy hierarchy = operation.getResult();
@@ -603,7 +603,7 @@
if (superType.getHandleIdentifier().equals(subType.getHandleIdentifier())) {
return true;
}
- final ITypeHierarchy hierarchy = JdtUtils.resolveTypeHierarchy(subType, true, new NullProgressMonitor());
+ final ITypeHierarchy hierarchy = JdtUtils.resolveTypeHierarchy(subType, subType.getJavaProject(), true, new NullProgressMonitor());
final List<IType> allSuperclasses = Arrays.asList(hierarchy.getAllSuperclasses(subType));
for (IType type : allSuperclasses) {
if (type.getHandleIdentifier().equals(superType.getHandleIdentifier())) {
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/EnumElementCategory.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/EnumElementCategory.java 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/EnumElementCategory.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -11,6 +11,6 @@
package org.jboss.tools.ws.jaxrs.core.metamodel;
public enum EnumElementCategory {
- APPLICATION, HTTP_METHOD, PROVIDER, RESOURCE, RESOURCE_FIELD, RESOURCE_METHOD
+ APPLICATION, HTTP_METHOD, PROVIDER, RESOURCE, RESOURCE_FIELD, RESOURCE_METHOD, METAMODEL
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/EnumElementKind.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/EnumElementKind.java 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/EnumElementKind.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -20,6 +20,8 @@
* UNDEFINED KIND (when no annotation nor any other java element can define precisely what the element is.
*/
UNDEFINED,
+ /** JAX-RS Project. */
+ METAMODEL,
/** A JAX-RS Application declared in the web deployment descriptor.*/
// must be declared *before* APPLICATION_JAVA constant to enable comparison !
APPLICATION_WEBXML,
@@ -50,5 +52,5 @@
/** QueryParam field. */
QUERY_PARAM_FIELD,
/** MatrixParam field. */
- MATRIX_PARAM_FIELD;
+ MATRIX_PARAM_FIELD;
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/IJaxrsApplication.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/IJaxrsApplication.java 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/IJaxrsApplication.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -10,10 +10,14 @@
******************************************************************************/
package org.jboss.tools.ws.jaxrs.core.metamodel;
+import org.eclipse.core.resources.IResource;
+
public interface IJaxrsApplication extends IJaxrsElement {
public abstract String getApplicationPath();
- public abstract EnumElementKind getElementKind();
+ public abstract String getJavaClassName();
+ public abstract IResource getResource();
+
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/IJaxrsElement.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/IJaxrsElement.java 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/IJaxrsElement.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -1,7 +1,18 @@
package org.jboss.tools.ws.jaxrs.core.metamodel;
+import org.eclipse.core.resources.IResource;
+
public interface IJaxrsElement {
- IJaxrsMetamodel getMetamodel();
+ public abstract IJaxrsMetamodel getMetamodel();
+ public abstract EnumElementKind getElementKind();
+
+ public abstract EnumElementCategory getElementCategory();
+
+ public abstract IResource getResource();
+
+ public abstract String getName();
+
+
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/IJaxrsHttpMethod.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/IJaxrsHttpMethod.java 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/IJaxrsHttpMethod.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -18,7 +18,7 @@
String getHttpVerb();
/** @return the name */
- String getFullyQualifiedName();
+ String getJavaClassName();
IType getJavaElement();
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/IJaxrsMetamodel.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/IJaxrsMetamodel.java 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/IJaxrsMetamodel.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -15,7 +15,7 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.jdt.core.IJavaElement;
-public interface IJaxrsMetamodel {
+public interface IJaxrsMetamodel extends IJaxrsElement {
public abstract List<IJaxrsEndpoint> getAllEndpoints();
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/quickfix/JaxrsValidationQuickFixes.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/quickfix/JaxrsValidationQuickFixes.java 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/quickfix/JaxrsValidationQuickFixes.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -6,5 +6,7 @@
public static final int HTTP_METHOD_INVALID_RETENTION_ANNOTATION_VALUE_ID = 2;
public static final int HTTP_METHOD_MISSING_TARGET_ANNOTATION_ID = 3;
public static final int HTTP_METHOD_INVALID_TARGET_ANNOTATION_VALUE_ID = 4;
+ public static final int JAVA_APPLICATION_MISSING_APPLICATION_PATH_ANNOTATION_ID = 5;
+ public static final int JAVA_APPLICATION_INVALID_TYPE_HIERARCHY_ID = 6;
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/preferences/JaxrsPreferenceInitializer.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/preferences/JaxrsPreferenceInitializer.java 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/preferences/JaxrsPreferenceInitializer.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -36,6 +36,8 @@
}
defaultPreferences.put(JaxrsPreferences.APPLICATION_NO_OCCURRENCE_FOUND, JaxrsPreferences.WARNING);
defaultPreferences.put(JaxrsPreferences.APPLICATION_TOO_MANY_OCCURRENCES, JaxrsPreferences.WARNING);
+ defaultPreferences.put(JaxrsPreferences.JAVA_APPLICATION_MISSING_APPLICATION_PATH_ANNOTATION, JaxrsPreferences.ERROR);
+ defaultPreferences.put(JaxrsPreferences.JAVA_APPLICATION_INVALID_TYPE_HIERARCHY, JaxrsPreferences.ERROR);
defaultPreferences.put(JaxrsPreferences.HTTP_METHOD_MISSING_TARGET_ANNOTATION, JaxrsPreferences.ERROR);
defaultPreferences.put(JaxrsPreferences.HTTP_METHOD_INVALID_TARGET_ANNOTATION_VALUE, JaxrsPreferences.ERROR);
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/preferences/JaxrsPreferences.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/preferences/JaxrsPreferences.java 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/preferences/JaxrsPreferences.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -65,6 +65,14 @@
public static final String APPLICATION_TOO_MANY_OCCURRENCES = INSTANCE
.createSeverityOption("applicationTooManyOccurrencesFound"); //$NON-NLS-1$
+
+ public static final String JAVA_APPLICATION_MISSING_APPLICATION_PATH_ANNOTATION = INSTANCE
+ .createSeverityOption("applicationMissingApplicationPathAnnotation"); //$NON-NLS-1$
+
+ public static final String JAVA_APPLICATION_INVALID_TYPE_HIERARCHY = INSTANCE
+ .createSeverityOption("applicationInvalidTypeHierarchy"); //$NON-NLS-1$
+
+
/**
* @return the only instance of {@link JaxrsPreferences}
*/
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/preferences/JaxrsPreferencesMessages.properties
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/preferences/JaxrsPreferencesMessages.properties 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/preferences/JaxrsPreferencesMessages.properties 2012-09-21 21:39:42 UTC (rev 43940)
@@ -21,6 +21,8 @@
JaxrsValidatorConfigurationBlock_section_applications=JAX-RS Activators
JaxrsValidatorConfigurationBlock_pb_applicationNoOccurrenceFound_label=No JAX-RS Activator configured
JaxrsValidatorConfigurationBlock_pb_applicationTooManyOccurrencesFound_label=Multiple JAX-RS Activators configured
+JaxrsValidatorConfigurationBlock_pb_applicationMissingApplicationPathAnnotation_label=Missing @ApplicationPath annotation
+JaxrsValidatorConfigurationBlock_pb_applicationInvalidTypeHierarchy_label=Invalid type hierarchy
#Section HTTP Methods
JaxrsValidatorConfigurationBlock_section_httpMethods=User-defined HTTP Methods
Copied: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-2_3-with-default-servlet-mapping.xml (from rev 43186, trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-2_3-with-servlet-mapping.xml)
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-2_3-with-default-servlet-mapping.xml (rev 0)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-2_3-with-default-servlet-mapping.xml 2012-09-21 21:39:42 UTC (rev 43940)
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE web-app
+ PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd">
+<!-- A sample web.xml file validated by the web-app DTD in version 2.3 -->
+<web-app>
+ <servlet>
+ <servlet-class></servlet-class>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>javax.ws.rs.core.Application</servlet-name>
+ <url-pattern>/hello/*</url-pattern>
+ </servlet-mapping>
+</web-app>
\ No newline at end of file
Property changes on: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-2_3-with-default-servlet-mapping.xml
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Deleted: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-2_3-with-servlet-mapping.xml
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-2_3-with-servlet-mapping.xml 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-2_3-with-servlet-mapping.xml 2012-09-21 21:39:42 UTC (rev 43940)
@@ -1,14 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE web-app
- PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
- "http://java.sun.com/dtd/web-app_2_3.dtd">
-<!-- A sample web.xml file validated by the web-app DTD in version 2.3 -->
-<web-app>
- <servlet>
- <servlet-class></servlet-class>
- </servlet>
- <servlet-mapping>
- <servlet-name>javax.ws.rs.core.Application</servlet-name>
- <url-pattern>/hello/*</url-pattern>
- </servlet-mapping>
-</web-app>
\ No newline at end of file
Copied: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-2_4-with-default-servlet-mapping.xml (from rev 43186, trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-2_4-with-servlet-mapping.xml)
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-2_4-with-default-servlet-mapping.xml (rev 0)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-2_4-with-default-servlet-mapping.xml 2012-09-21 21:39:42 UTC (rev 43940)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
+ version="2.4">
+ <servlet-mapping>
+ <servlet-name>javax.ws.rs.core.Application</servlet-name>
+ <url-pattern>/hello/*</url-pattern>
+ </servlet-mapping>
+</web-app>
\ No newline at end of file
Property changes on: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-2_4-with-default-servlet-mapping.xml
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Deleted: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-2_4-with-servlet-mapping.xml
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-2_4-with-servlet-mapping.xml 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-2_4-with-servlet-mapping.xml 2012-09-21 21:39:42 UTC (rev 43940)
@@ -1,10 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
- xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
- version="2.4">
- <servlet-mapping>
- <servlet-name>javax.ws.rs.core.Application</servlet-name>
- <url-pattern>/hello/*</url-pattern>
- </servlet-mapping>
-</web-app>
\ No newline at end of file
Copied: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-2_5-with-default-servlet-mapping.xml (from rev 43186, trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-2_5-with-servlet-mapping.xml)
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-2_5-with-default-servlet-mapping.xml (rev 0)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-2_5-with-default-servlet-mapping.xml 2012-09-21 21:39:42 UTC (rev 43940)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+
+ <servlet-mapping>
+ <servlet-name>javax.ws.rs.core.Application</servlet-name>
+ <url-pattern>/hello/*</url-pattern>
+ </servlet-mapping>
+</web-app>
\ No newline at end of file
Property changes on: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-2_5-with-default-servlet-mapping.xml
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Deleted: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-2_5-with-servlet-mapping.xml
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-2_5-with-servlet-mapping.xml 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-2_5-with-servlet-mapping.xml 2012-09-21 21:39:42 UTC (rev 43940)
@@ -1,10 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
-
- <servlet-mapping>
- <servlet-name>javax.ws.rs.core.Application</servlet-name>
- <url-pattern>/hello/*</url-pattern>
- </servlet-mapping>
-</web-app>
\ No newline at end of file
Added: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-3_0-with-custom-servlet-mapping.xml
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-3_0-with-custom-servlet-mapping.xml (rev 0)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-3_0-with-custom-servlet-mapping.xml 2012-09-21 21:39:42 UTC (rev 43940)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ version="3.0">
+ <servlet-mapping>
+ <servlet-name>org.jboss.tools.ws.jaxrs.sample.services.RestApplication</servlet-name>
+ <url-pattern>/hello/*</url-pattern>
+ </servlet-mapping>
+</web-app>
\ No newline at end of file
Property changes on: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-3_0-with-custom-servlet-mapping.xml
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Copied: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-3_0-with-default-servlet-mapping.xml (from rev 43186, trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-3_0-with-servlet-mapping.xml)
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-3_0-with-default-servlet-mapping.xml (rev 0)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-3_0-with-default-servlet-mapping.xml 2012-09-21 21:39:42 UTC (rev 43940)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ version="3.0">
+ <servlet-mapping>
+ <servlet-name>javax.ws.rs.core.Application</servlet-name>
+ <url-pattern>/hello/*</url-pattern>
+ </servlet-mapping>
+</web-app>
\ No newline at end of file
Property changes on: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-3_0-with-default-servlet-mapping.xml
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Deleted: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-3_0-with-servlet-mapping.xml
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-3_0-with-servlet-mapping.xml 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-3_0-with-servlet-mapping.xml 2012-09-21 21:39:42 UTC (rev 43940)
@@ -1,9 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
- version="3.0">
- <servlet-mapping>
- <servlet-name>javax.ws.rs.core.Application</servlet-name>
- <url-pattern>/hello/*</url-pattern>
- </servlet-mapping>
-</web-app>
\ No newline at end of file
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-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/AllTests.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -21,7 +21,7 @@
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.ResourceChangedProcessorTestCase;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsElementFactoryTestCase;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsMetamodelTestCase;
-import org.jboss.tools.ws.jaxrs.core.internal.metamodel.validation.JaxrsMetamodelValidatorTestCase;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.validation.JaxrsApplicationValidatorTestCase;
import org.jboss.tools.ws.jaxrs.core.internal.utils.CollectionUtilsTestCase;
import org.jboss.tools.ws.jaxrs.core.internal.utils.WtpUtilsTestCase;
import org.jboss.tools.ws.jaxrs.core.jdt.CompilationUnitsRepositoryTestCase;
@@ -38,7 +38,7 @@
JavaElementDeltaFilterTestCase.class, JavaElementChangedProcessorTestCase.class,
JaxrsMetamodelChangedProcessorTestCase.class, JaxrsMetamodelTestCase.class,
JaxrsElementFactoryTestCase.class, JaxrsMetamodelBuilderTestCase.class, CollectionUtilsTestCase.class,
- PubSubServiceTestCase.class, JaxrsMetamodelValidatorTestCase.class,
+ PubSubServiceTestCase.class, JaxrsApplicationValidatorTestCase.class,
ResourceChangedProcessorTestCase.class, ResourceChangedListenerTestCase.class,
JaxrsAnnotationScannerTestCase.class, WtpUtilsTestCase.class})
public class AllTests {
Modified: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/WorkbenchUtils.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/WorkbenchUtils.java 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/WorkbenchUtils.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -257,12 +257,22 @@
replaceFirstOccurrenceOfCode(type, content, "", useWorkingCopy);
}
+ /**
+ * Replace the first occurrence of the given old content with the new content. Fails if the old content is not found
+ * (avoids weird side effects in the rest of the test).
+ *
+ * @param compilationUnit
+ * @param oldContent
+ * @param newContent
+ * @param useWorkingCopy
+ * @throws JavaModelException
+ */
public static void replaceFirstOccurrenceOfCode(ICompilationUnit compilationUnit, String oldContent,
String newContent, boolean useWorkingCopy) throws JavaModelException {
ICompilationUnit unit = getCompilationUnit(compilationUnit, useWorkingCopy);
IBuffer buffer = ((IOpenable) unit).getBuffer();
int offset = buffer.getContents().indexOf(oldContent);
- Assert.assertTrue("Old content not found", offset != -1);
+ Assert.assertTrue("Old content '" + oldContent + "' not found", offset != -1);
buffer.replace(offset, oldContent.length(), newContent);
saveAndClose(unit);
}
@@ -278,19 +288,6 @@
return useWorkingCopy ? createWorkingCopy(compilationUnit) : compilationUnit;
}
- public static void replaceFirstOccurrenceOfCode(ICompilationUnit compilationUnit, String[] oldContents,
- String[] newContents) throws JavaModelException {
- ICompilationUnit workingCopy = createWorkingCopy(compilationUnit);
- Assert.assertEquals("Wrong parameters", oldContents.length, newContents.length);
- for (int i = 0; i < oldContents.length; i++) {
- IBuffer buffer = ((IOpenable) workingCopy).getBuffer();
- int offset = buffer.getContents().indexOf(oldContents[i]);
- Assert.assertTrue("Old content not found", offset != -1);
- buffer.replace(offset, oldContents[i].length(), newContents[i]);
- }
- saveAndClose(workingCopy);
- }
-
public static <T extends IMember> T replaceFirstOccurrenceOfCode(T member, String oldContent, String newContent,
boolean useWorkingCopy) throws JavaModelException {
ICompilationUnit compilationUnit = member.getCompilationUnit();
@@ -909,7 +906,6 @@
file.delete(true, new NullProgressMonitor());
}
file.create(stream, true, null);
- LOGGER.debug("Content:");
final InputStream contents = file.getContents();
final char[] buffer = new char[0x10000];
StringBuilder out = new StringBuilder();
@@ -921,7 +917,7 @@
out.append(buffer, 0, read);
}
} while (read >= 0);
- LOGGER.debug(out.toString());
+ LOGGER.debug("Content:\n" + out.toString());
}
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-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedProcessorTestCase.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -273,11 +273,12 @@
// pre-conditions
final IType type = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
javaProject, progressMonitor);
- final JaxrsJavaApplication application = new JaxrsJavaApplication(type, getAnnotation(type, APPLICATION_PATH.qualifiedName), metamodel);
+ final Annotation appPathAnnotation = getAnnotation(type, APPLICATION_PATH.qualifiedName);
+ final JaxrsJavaApplication application = new JaxrsJavaApplication(type, appPathAnnotation, true, metamodel);
metamodel.add(application);
- final Annotation annotation = getAnnotation(type, SuppressWarnings.class.getName());
+ final Annotation suppressWarningAnnotation = getAnnotation(type, SuppressWarnings.class.getName());
// operation
- final JavaElementDelta event = createEvent(annotation, ADDED);
+ final JavaElementDelta event = createEvent(suppressWarningAnnotation, ADDED);
final List<JaxrsElementDelta> impacts = processEvent(event, progressMonitor);
// verifications
assertThat(impacts.size(), equalTo(0));
@@ -290,11 +291,11 @@
// pre-conditions
final IType type = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
javaProject, progressMonitor);
- final Annotation annotation = changeAnnotation(type, APPLICATION_PATH.qualifiedName, "/bar");
- final JaxrsJavaApplication application = new JaxrsJavaApplication(type, annotation, metamodel);
+ final Annotation appPathAnnotation = changeAnnotation(type, APPLICATION_PATH.qualifiedName, "/bar");
+ final JaxrsJavaApplication application = new JaxrsJavaApplication(type, appPathAnnotation, true, metamodel);
metamodel.add(application);
// operation
- final JavaElementDelta event = createEvent(annotation, CHANGED);
+ final JavaElementDelta event = createEvent(appPathAnnotation, CHANGED);
final List<JaxrsElementDelta> impacts = processEvent(event, progressMonitor);
// verifications
assertThat(impacts.size(), equalTo(1));
@@ -309,11 +310,11 @@
// pre-conditions
final IType type = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
javaProject, progressMonitor);
- final Annotation annotation = getAnnotation(type, APPLICATION_PATH.qualifiedName);
- final JaxrsJavaApplication application = new JaxrsJavaApplication(type, annotation, metamodel);
+ final Annotation appPathAnnotation = getAnnotation(type, APPLICATION_PATH.qualifiedName);
+ final JaxrsJavaApplication application = new JaxrsJavaApplication(type, appPathAnnotation, true, metamodel);
metamodel.add(application);
// operation
- final JavaElementDelta event = createEvent(annotation, CHANGED);
+ final JavaElementDelta event = createEvent(appPathAnnotation, CHANGED);
final List<JaxrsElementDelta> impacts = processEvent(event, progressMonitor);
// verifications
assertThat(impacts.size(), equalTo(0));
@@ -325,8 +326,8 @@
// pre-conditions
final IType type = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
javaProject, progressMonitor);
- final Annotation annotation = getAnnotation(type, APPLICATION_PATH.qualifiedName);
- final JaxrsJavaApplication application = new JaxrsJavaApplication(type, annotation, metamodel);
+ final Annotation appPathAnnotation = getAnnotation(type, APPLICATION_PATH.qualifiedName);
+ final JaxrsJavaApplication application = new JaxrsJavaApplication(type, appPathAnnotation, true, metamodel);
metamodel.add(application);
final Annotation suppressWarningsAnnotation = getAnnotation(type, SuppressWarnings.class.getName());
// operation
@@ -342,8 +343,8 @@
// pre-conditions
final IType type = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
javaProject, progressMonitor);
- final Annotation annotation = getAnnotation(type, APPLICATION_PATH.qualifiedName);
- final JaxrsJavaApplication application = new JaxrsJavaApplication(type, annotation, metamodel);
+ final Annotation appPathAnnotation = getAnnotation(type, APPLICATION_PATH.qualifiedName);
+ final JaxrsJavaApplication application = new JaxrsJavaApplication(type, appPathAnnotation, true, metamodel);
metamodel.add(application);
// operation
final JavaElementDelta event = createEvent(type.getCompilationUnit(), REMOVED);
@@ -361,8 +362,8 @@
// pre-conditions
final IType type = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
javaProject, progressMonitor);
- final Annotation annotation = getAnnotation(type, APPLICATION_PATH.qualifiedName);
- final JaxrsJavaApplication application = new JaxrsJavaApplication(type, annotation, metamodel);
+ final Annotation appPathAnnotation = getAnnotation(type, APPLICATION_PATH.qualifiedName);
+ final JaxrsJavaApplication application = new JaxrsJavaApplication(type, appPathAnnotation, true, metamodel);
metamodel.add(application);
// operation
final JavaElementDelta event = createEvent(type, REMOVED);
@@ -376,22 +377,23 @@
}
@Test
- public void shouldRemoveApplicationWhenRemovingAnnotation() throws CoreException {
+ public void shouldNotRemoveApplicationWhenRemovingAnnotation() throws CoreException {
// pre-conditions
final IType type = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
javaProject, progressMonitor);
- final Annotation annotation = getAnnotation(type, APPLICATION_PATH.qualifiedName);
- final JaxrsJavaApplication application = new JaxrsJavaApplication(type, annotation, metamodel);
+ final Annotation appPathAnnotation = getAnnotation(type, APPLICATION_PATH.qualifiedName);
+ final JaxrsJavaApplication application = new JaxrsJavaApplication(type, appPathAnnotation, true, metamodel);
metamodel.add(application);
// operation
- final JavaElementDelta event = createEvent(annotation, REMOVED);
+ final JavaElementDelta event = createEvent(appPathAnnotation, REMOVED);
final List<JaxrsElementDelta> impacts = processEvent(event, progressMonitor);
// verifications
assertThat(impacts.size(), equalTo(1));
assertThat(impacts.get(0).getElement().getElementCategory(), equalTo(EnumElementCategory.APPLICATION));
- assertThat(impacts.get(0).getDeltaKind(), equalTo(REMOVED));
+ assertThat(impacts.get(0).getDeltaKind(), equalTo(CHANGED));
assertThat(impacts.get(0).getElement(), is(notNullValue()));
- assertThat(metamodel.getElements(javaProject).size(), equalTo(0));
+ assertThat(metamodel.getElements(javaProject).size(), equalTo(1));
+ assertThat(application.getApplicationPath(), nullValue());
}
@Test
@@ -399,8 +401,8 @@
// pre-conditions
final IType type = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
javaProject, progressMonitor);
- final Annotation annotation = getAnnotation(type, APPLICATION_PATH.qualifiedName);
- final JaxrsJavaApplication application = new JaxrsJavaApplication(type, annotation, metamodel);
+ final Annotation appPathAnnotation = getAnnotation(type, APPLICATION_PATH.qualifiedName);
+ final JaxrsJavaApplication application = new JaxrsJavaApplication(type, appPathAnnotation, true, metamodel);
metamodel.add(application);
// operation
final JavaElementDelta event = createEvent(getAnnotation(type, SuppressWarnings.class.getName()), REMOVED);
@@ -415,8 +417,8 @@
// pre-conditions
final IType type = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
javaProject, progressMonitor);
- final Annotation annotation = getAnnotation(type, APPLICATION_PATH.qualifiedName);
- final JaxrsJavaApplication application = new JaxrsJavaApplication(type, annotation, metamodel);
+ final Annotation appPathAnnotation = getAnnotation(type, APPLICATION_PATH.qualifiedName);
+ final JaxrsJavaApplication application = new JaxrsJavaApplication(type, appPathAnnotation, true, metamodel);
metamodel.add(application);
final IPackageFragmentRoot sourceFolder = WorkbenchUtils.getPackageFragmentRoot(javaProject, "src/main/java",
progressMonitor);
Modified: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelChangedProcessorTestCase.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelChangedProcessorTestCase.java 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelChangedProcessorTestCase.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -53,6 +53,8 @@
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsResource;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsResourceMethod;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsResourceMethod.Builder;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsWebxmlApplication;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.WtpUtils;
import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
import org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname;
import org.jboss.tools.ws.jaxrs.core.jdt.JavaMethodParameter;
@@ -80,13 +82,21 @@
metamodel = spy(JaxrsMetamodel.create(javaProject));
}
- private JaxrsJavaApplication createApplication(String typeName) throws CoreException, JavaModelException {
+ private JaxrsJavaApplication createJavaApplication(String typeName) throws CoreException, JavaModelException {
final IType applicationType = getType(typeName, javaProject);
+ final Annotation appPathAnnotation = getAnnotation(applicationType, APPLICATION_PATH.qualifiedName);
final JaxrsJavaApplication application = new JaxrsJavaApplication(applicationType,
- getAnnotation(applicationType, APPLICATION_PATH.qualifiedName), metamodel);
+ appPathAnnotation, true, metamodel);
metamodel.add(application);
return application;
}
+
+ private JaxrsWebxmlApplication createWebxmlApplication(String typeName, String applicationPath) throws CoreException, JavaModelException {
+ final JaxrsWebxmlApplication application = new JaxrsWebxmlApplication(typeName,
+ applicationPath, WtpUtils.getWebDeploymentDescriptor(project), metamodel);
+ metamodel.add(application);
+ return application;
+ }
private JaxrsResource createResource(String typeName) throws CoreException, JavaModelException {
final IType resourceType = getType(typeName, javaProject);
@@ -134,7 +144,7 @@
}
private JaxrsEndpoint createEndpoint(JaxrsHttpMethod httpMethod, JaxrsResourceMethod... resourceMethods) {
- JaxrsEndpoint endpoint = new JaxrsEndpoint(null, httpMethod, new LinkedList<JaxrsResourceMethod>(
+ JaxrsEndpoint endpoint = new JaxrsEndpoint(this.metamodel, httpMethod, new LinkedList<JaxrsResourceMethod>(
Arrays.asList(resourceMethods)));
metamodel.add(endpoint);
return endpoint;
@@ -285,7 +295,6 @@
// verifications
assertThat(changes.size(), equalTo(1));
assertThat(changes.get(0).getDeltaKind(), equalTo(ADDED));
-
}
@Test
@@ -310,7 +319,6 @@
@Test
public void shoudChangeUriPathTemplateWhenAddingApplication() throws JavaModelException, CoreException {
- // the subresource becomes a root resource !
// pre-conditions
final JaxrsHttpMethod httpMethod = JaxrsBuiltinHttpMethod.GET;
final JaxrsResource customerResource = createResource("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
@@ -319,7 +327,7 @@
final JaxrsEndpoint endpoint = createEndpoint(httpMethod, customerResourceMethod);
assertThat(endpoint.getUriPathTemplate(), equalTo("/customers/{id}"));
// operation
- final JaxrsJavaApplication application = createApplication("org.jboss.tools.ws.jaxrs.sample.services.RestApplication");
+ final JaxrsJavaApplication application = createJavaApplication("org.jboss.tools.ws.jaxrs.sample.services.RestApplication");
final JaxrsElementDelta event = new JaxrsElementDelta(application, ADDED);
final List<JaxrsEndpointDelta> changes = processEvent(event, progressMonitor);
// verifications
@@ -330,8 +338,50 @@
}
@Test
+ public void shoudChangeUriPathTemplateWhenRemovingApplicationType() throws JavaModelException, CoreException {
+ // pre-conditions
+ final JaxrsHttpMethod httpMethod = JaxrsBuiltinHttpMethod.GET;
+ final JaxrsJavaApplication application = createJavaApplication("org.jboss.tools.ws.jaxrs.sample.services.RestApplication");
+ final JaxrsResource customerResource = createResource("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final JaxrsResourceMethod customerResourceMethod = createResourceMethod("getCustomer", customerResource,
+ GET);
+ final JaxrsEndpoint endpoint = createEndpoint(httpMethod, customerResourceMethod);
+ assertThat(endpoint.getUriPathTemplate(), equalTo("/app/customers/{id}"));
+ // operation
+ metamodel.remove(application);
+ final JaxrsElementDelta event = new JaxrsElementDelta(application, REMOVED);
+ final List<JaxrsEndpointDelta> 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("/customers/{id}"));
+ }
+
+ @Test
+ public void shoudChangeUriPathTemplateWhenRemovingApplicationPathAnnotation() throws JavaModelException, CoreException {
+ // pre-conditions
+ final JaxrsHttpMethod httpMethod = JaxrsBuiltinHttpMethod.GET;
+ final JaxrsJavaApplication application = createJavaApplication("org.jboss.tools.ws.jaxrs.sample.services.RestApplication");
+ final JaxrsResource customerResource = createResource("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final JaxrsResourceMethod customerResourceMethod = createResourceMethod("getCustomer", customerResource,
+ GET);
+ final JaxrsEndpoint endpoint = createEndpoint(httpMethod, customerResourceMethod);
+ assertThat(endpoint.getUriPathTemplate(), equalTo("/app/customers/{id}"));
+ // operation
+ final Annotation appPathAnnotation = application.getAnnotation(EnumJaxrsClassname.APPLICATION_PATH.qualifiedName);
+ application.removeAnnotation(appPathAnnotation);
+ final JaxrsElementDelta event = new JaxrsElementDelta(application, CHANGED);
+ final List<JaxrsEndpointDelta> 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("/customers/{id}"));
+ }
+
+ @Test
public void shoudChangeUriPathTemplateWhenAddingResourcePathAnnotation() throws JavaModelException, CoreException {
- // the subresource becomes a root resource !
// pre-conditions
final JaxrsHttpMethod httpMethod = JaxrsBuiltinHttpMethod.GET;
final JaxrsResource customerResource = createResource("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
@@ -377,7 +427,7 @@
@Test
public void shoudChangeUriPathTemplateWhenChangingApplicationPathAnnotation() throws JavaModelException, CoreException {
// pre-conditions
- final JaxrsJavaApplication application = createApplication("org.jboss.tools.ws.jaxrs.sample.services.RestApplication");
+ final JaxrsJavaApplication application = createJavaApplication("org.jboss.tools.ws.jaxrs.sample.services.RestApplication");
final JaxrsHttpMethod httpMethod = JaxrsBuiltinHttpMethod.GET;
final JaxrsResource customerResource = createResource("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
final JaxrsResourceMethod customerResourceMethod = createResourceMethod("getCustomer", customerResource,
@@ -399,6 +449,106 @@
}
@Test
+ public void shoudChangeUriPathTemplateWhenSwitchingToWebxmlCoreApplication() throws JavaModelException, CoreException {
+ // pre-conditions
+ createJavaApplication("org.jboss.tools.ws.jaxrs.sample.services.RestApplication");
+ final JaxrsHttpMethod httpMethod = JaxrsBuiltinHttpMethod.GET;
+ final JaxrsResource customerResource = createResource("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final JaxrsResourceMethod customerResourceMethod = createResourceMethod("getCustomer", customerResource,
+ GET);
+ final JaxrsEndpoint endpoint = createEndpoint(metamodel, httpMethod, customerResourceMethod);
+ assertThat(endpoint.getUriPathTemplate(), equalTo("/app/customers/{id}"));
+ // operation
+ final JaxrsWebxmlApplication webxmlApplication = createWebxmlApplication("javax.ws.rs.core.Application", "/foo");
+ final JaxrsElementDelta event = new JaxrsElementDelta(webxmlApplication, ADDED);
+ final List<JaxrsEndpointDelta> changes = processEvent(event, progressMonitor);
+ // verifications
+ assertThat(changes.size(), equalTo(1));
+ final JaxrsEndpointDelta 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 shoudChangeUriPathTemplateWhenSwitchingBackToJavaApplication() throws JavaModelException, CoreException {
+ // pre-conditions
+ createJavaApplication("org.jboss.tools.ws.jaxrs.sample.services.RestApplication");
+ final JaxrsHttpMethod httpMethod = JaxrsBuiltinHttpMethod.GET;
+ final JaxrsResource customerResource = createResource("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final JaxrsResourceMethod customerResourceMethod = createResourceMethod("getCustomer", customerResource,
+ GET);
+ final JaxrsWebxmlApplication webxmlApplication = createWebxmlApplication("javax.ws.rs.core.Application", "/foo");
+ final JaxrsEndpoint endpoint = createEndpoint(metamodel, httpMethod, customerResourceMethod);
+ assertThat(endpoint.getUriPathTemplate(), equalTo("/foo/customers/{id}"));
+ // operation
+ metamodel.remove(webxmlApplication);
+ final JaxrsElementDelta event = new JaxrsElementDelta(webxmlApplication, REMOVED);
+ final List<JaxrsEndpointDelta> changes = processEvent(event, progressMonitor);
+ // verifications
+ assertThat(changes.size(), equalTo(1));
+ final JaxrsEndpointDelta 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("/app/customers/{id}"));
+ }
+
+ @Test
+ public void shoudChangeUriPathTemplateWhenOverridingApplication() throws JavaModelException, CoreException {
+ // pre-conditions
+ final JaxrsJavaApplication javaApplication = createJavaApplication("org.jboss.tools.ws.jaxrs.sample.services.RestApplication");
+ final JaxrsHttpMethod httpMethod = JaxrsBuiltinHttpMethod.GET;
+ final JaxrsResource customerResource = createResource("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final JaxrsResourceMethod customerResourceMethod = createResourceMethod("getCustomer", customerResource,
+ GET);
+ final JaxrsEndpoint endpoint = createEndpoint(metamodel, httpMethod, customerResourceMethod);
+ assertThat(endpoint.getUriPathTemplate(), equalTo("/app/customers/{id}"));
+ // operation
+ final JaxrsWebxmlApplication webxmlApplication = createWebxmlApplication(javaApplication.getJavaClassName(), "/foo");
+ List<JaxrsEndpointDelta> changes = processEvent(new JaxrsElementDelta(webxmlApplication, ADDED), progressMonitor);
+ assertThat(changes.size(), equalTo(0));
+ // (at the same time, the JavaApplication is changed since this is an override)
+ javaApplication.setApplicationPathOverride("/foo");
+ changes = processEvent(new JaxrsElementDelta(javaApplication, CHANGED), progressMonitor);
+ // verifications
+ assertThat(changes.size(), equalTo(1));
+ final JaxrsEndpointDelta 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 shoudChangeUriPathTemplateWhenUnoverridingApplication() throws JavaModelException, CoreException {
+ // pre-conditions
+ final JaxrsJavaApplication javaApplication = createJavaApplication("org.jboss.tools.ws.jaxrs.sample.services.RestApplication");
+ final JaxrsHttpMethod httpMethod = JaxrsBuiltinHttpMethod.GET;
+ final JaxrsResource customerResource = createResource("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ final JaxrsResourceMethod customerResourceMethod = createResourceMethod("getCustomer", customerResource,
+ GET);
+ final JaxrsWebxmlApplication webxmlApplication = createWebxmlApplication(javaApplication.getJavaClassName(), "/foo");
+ javaApplication.setApplicationPathOverride("/foo");
+ final JaxrsEndpoint endpoint = createEndpoint(metamodel, httpMethod, customerResourceMethod);
+ assertThat(endpoint.getUriPathTemplate(), equalTo("/foo/customers/{id}"));
+ // operation
+ List<JaxrsEndpointDelta> changes = processEvent(new JaxrsElementDelta(webxmlApplication, REMOVED), progressMonitor);
+ assertThat(changes.size(), equalTo(1)); // FAKE change...
+ // (at the same time, the JavaApplication is changed since this is an override)
+ javaApplication.unsetApplicationPathOverride();
+ changes = processEvent(new JaxrsElementDelta(javaApplication, CHANGED), progressMonitor);
+ // verifications
+ assertThat(changes.size(), equalTo(1));
+ final JaxrsEndpointDelta 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("/app/customers/{id}"));
+ }
+
+ @Test
public void shoudChangeUriPathTemplateWhenChangingResourcePathAnnotation() throws JavaModelException, CoreException {
// pre-conditions
final JaxrsHttpMethod httpMethod = JaxrsBuiltinHttpMethod.GET;
@@ -498,7 +648,7 @@
@Test
public void shoudChangeUriPathTemplateWhenRemovingMetamodelApplication() throws JavaModelException, CoreException {
// pre-conditions
- final JaxrsJavaApplication application = createApplication("org.jboss.tools.ws.jaxrs.sample.services.RestApplication");
+ final JaxrsJavaApplication application = createJavaApplication("org.jboss.tools.ws.jaxrs.sample.services.RestApplication");
final JaxrsHttpMethod httpMethod = JaxrsBuiltinHttpMethod.GET;
final JaxrsResource customerResource = createResource("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
final JaxrsResourceMethod customerResourceMethod = createResourceMethod("getCustomer", customerResource,
@@ -1123,4 +1273,6 @@
assertThat(change.getEndpoint(), isOneOf((IJaxrsEndpoint) bookEndpoint, (IJaxrsEndpoint) gameEndpoint));
}
}
+
+
}
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-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/ResourceChangedProcessorTestCase.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -17,6 +17,7 @@
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.everyItem;
import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.changeAnnotation;
import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.getAnnotation;
import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.getType;
@@ -62,6 +63,7 @@
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsResourceField;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsResourceMethod;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsWebxmlApplication;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.WtpUtils;
import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
import org.jboss.tools.ws.jaxrs.core.jdt.CompilationUnitsRepository;
import org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname;
@@ -105,9 +107,9 @@
* @return
* @throws JavaModelException
*/
- private JaxrsJavaApplication createApplication(IType type) throws JavaModelException {
- final Annotation annotation = getAnnotation(type, APPLICATION_PATH.qualifiedName);
- return new JaxrsJavaApplication(type, annotation, metamodel);
+ private JaxrsJavaApplication createJavaApplication(IType type) throws JavaModelException {
+ final Annotation appPathAnnotation = getAnnotation(type, APPLICATION_PATH.qualifiedName);
+ return new JaxrsJavaApplication(type, appPathAnnotation, true, metamodel);
}
/**
@@ -117,9 +119,9 @@
* @return
* @throws JavaModelException
*/
- private JaxrsJavaApplication createApplication(IType type, String applicationPath) throws JavaModelException {
- final Annotation annotation = changeAnnotation(type, APPLICATION_PATH.qualifiedName, applicationPath);
- return new JaxrsJavaApplication(type, annotation, metamodel);
+ private JaxrsJavaApplication createJavaApplication(IType type, String applicationPath) throws JavaModelException {
+ final Annotation appPathAnnotation = changeAnnotation(type, APPLICATION_PATH.qualifiedName, applicationPath);
+ return new JaxrsJavaApplication(type, appPathAnnotation, true, metamodel);
}
/**
@@ -129,8 +131,9 @@
* @return
* @throws JavaModelException
*/
- private JaxrsWebxmlApplication createApplication(String applicationPath) throws JavaModelException {
- return new JaxrsWebxmlApplication(applicationPath, null, metamodel);
+ private JaxrsWebxmlApplication createWebxmlApplication(final String applicationClassName, final String applicationPath) throws JavaModelException {
+ final IResource webDeploymentDescriptor = WtpUtils.getWebDeploymentDescriptor(project);
+ return new JaxrsWebxmlApplication(applicationClassName, applicationPath, webDeploymentDescriptor, metamodel);
}
/**
@@ -281,7 +284,7 @@
}
@Test
- public void shouldAddApplicationWhenChangingResource() throws CoreException {
+ public void shouldAddJavaApplicationWhenChangingResource() throws CoreException {
// pre-conditions
final IType type = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
javaProject, progressMonitor);
@@ -299,11 +302,11 @@
}
@Test
- public void shouldChangeApplicationWhenChangingResource() throws CoreException {
+ public void shouldChangeJavaApplicationWhenChangingResource() throws CoreException {
// pre-conditions
final IType type = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
javaProject, progressMonitor);
- metamodel.add(createApplication(type, "/bar"));
+ metamodel.add(createJavaApplication(type, "/bar"));
// operation
final ResourceDelta event = createEvent(type.getResource(), CHANGED);
final List<JaxrsElementDelta> affectedElements = processResourceChanges(event, progressMonitor);
@@ -317,11 +320,11 @@
}
@Test
- public void shouldRemoveApplicationWhenChangingResource() throws CoreException {
+ public void shouldChangeJavaApplicationWhenRemovingAnnotation() throws CoreException {
// pre-conditions
final IType type = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
javaProject, progressMonitor);
- metamodel.add(createApplication(type));
+ metamodel.add(createJavaApplication(type));
final Annotation annotation = getAnnotation(type, APPLICATION_PATH.qualifiedName);
// operation
WorkbenchUtils.delete(annotation.getJavaAnnotation(), false);
@@ -329,20 +332,37 @@
final List<JaxrsElementDelta> affectedElements = processResourceChanges(event, progressMonitor);
// verifications
assertThat(affectedElements.size(), equalTo(1));
- assertThat(affectedElements.get(0).getElement().getElementCategory(), equalTo(EnumElementCategory.APPLICATION));
- assertThat(affectedElements.get(0).getDeltaKind(), equalTo(REMOVED));
+ assertThat(affectedElements.get(0).getElement().getElementKind(), equalTo(EnumElementKind.APPLICATION_JAVA));
+ assertThat(affectedElements.get(0).getDeltaKind(), equalTo(CHANGED));
+ assertThat(((IJaxrsApplication) affectedElements.get(0).getElement()).getApplicationPath(), nullValue());
+ assertThat(metamodel.getElements(javaProject).size(), equalTo(1));
+ }
+
+ @Test
+ public void shouldChangeJavaApplicationWhenRemovingSupertype() throws CoreException {
+ // pre-conditions
+ final IType type = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
+ javaProject, progressMonitor);
+ metamodel.add(createJavaApplication(type));
+ // operation
+ WorkbenchUtils.replaceAllOccurrencesOfCode(type.getCompilationUnit(), "extends Application", "", false);
+ final ResourceDelta event = createEvent(type.getResource(), CHANGED);
+ final List<JaxrsElementDelta> affectedElements = processResourceChanges(event, progressMonitor);
+ // verifications
+ assertThat(affectedElements.size(), equalTo(1));
+ assertThat(affectedElements.get(0).getElement().getElementKind(), equalTo(EnumElementKind.APPLICATION_JAVA));
+ assertThat(affectedElements.get(0).getDeltaKind(), equalTo(CHANGED));
assertThat(((IJaxrsApplication) affectedElements.get(0).getElement()).getApplicationPath(), equalTo("/app"));
- verify(metamodel, times(1)).add(any(JaxrsHttpMethod.class));
- assertThat(metamodel.getElements(javaProject).size(), equalTo(0));
+ assertThat(metamodel.getElements(javaProject).size(), equalTo(1));
}
@Test
- public void shouldRemoveApplicationWhenRemovingCompilationUnit() throws CoreException {
+ public void shouldRemoveJavaApplicationWhenRemovingCompilationUnit() 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 JaxrsJavaApplication application = createApplication(type);
+ final JaxrsJavaApplication application = createJavaApplication(type);
metamodel.add(application);
// operation
final ResourceDelta event = createEvent(type.getResource(), REMOVED);
@@ -356,7 +376,7 @@
}
@Test
- public void shouldRemoveApplicationWhenRemovingSourceType() throws CoreException {
+ public void shouldRemoveJavaApplicationWhenRemovingSourceType() throws CoreException {
// pre-conditions
final IType type = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.FOO", javaProject,
progressMonitor);
@@ -376,11 +396,11 @@
}
@Test
- public void shouldRemoveApplicationWhenRemovingSourceFolder() throws CoreException {
+ public void shouldRemoveJavaApplicationWhenRemovingSourceFolder() throws CoreException {
// pre-conditions
final IType type = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
javaProject, progressMonitor);
- final JaxrsJavaApplication application = createApplication(type);
+ final JaxrsJavaApplication application = createJavaApplication(type);
metamodel.add(application);
final IPackageFragmentRoot sourceFolder = WorkbenchUtils.getPackageFragmentRoot(javaProject, "src/main/java",
progressMonitor);
@@ -396,10 +416,10 @@
}
@Test
- public void shouldAddApplicationWhenAddingWebxml() throws Exception {
+ public void shouldAddWebxmlApplicationWhenAddingWebxml() throws Exception {
// pre-conditions
final IResource webxmlResource = WorkbenchUtils.replaceDeploymentDescriptorWith(javaProject,
- "web-3_0-with-servlet-mapping.xml", bundle);
+ "web-3_0-with-default-servlet-mapping.xml", bundle);
// operation
final ResourceDelta event = createEvent(webxmlResource, ADDED);
final List<JaxrsElementDelta> affectedElements = processResourceChanges(event, progressMonitor);
@@ -413,7 +433,7 @@
}
@Test
- public void shouldNotAddApplicationWhenAddingEmptyWebxml() throws Exception {
+ public void shouldNotAddWebxmlApplicationWhenAddingEmptyWebxml() throws Exception {
// pre-conditions
final IResource webxmlResource = WorkbenchUtils.replaceDeploymentDescriptorWith(javaProject,
"web-3_0-without-servlet-mapping.xml", bundle);
@@ -426,16 +446,16 @@
}
@Test
- public void shouldAddApplicationWhenChangingWebxml() throws Exception {
+ public void shouldAddWebxmlApplicationWhenChangingWebxml() throws Exception {
// pre-conditions
final IResource webxmlResource = WorkbenchUtils.replaceDeploymentDescriptorWith(javaProject,
- "web-3_0-with-servlet-mapping.xml", bundle);
+ "web-3_0-with-default-servlet-mapping.xml", bundle);
// operation
final ResourceDelta event = createEvent(webxmlResource, CHANGED);
final List<JaxrsElementDelta> affectedElements = processResourceChanges(event, progressMonitor);
// verifications
assertThat(affectedElements.size(), equalTo(1));
- assertThat(affectedElements.get(0).getElement().getElementCategory(), equalTo(EnumElementCategory.APPLICATION));
+ assertThat(affectedElements.get(0).getElement().getElementKind(), equalTo(EnumElementKind.APPLICATION_WEBXML));
assertThat(affectedElements.get(0).getDeltaKind(), equalTo(ADDED));
assertThat(((JaxrsWebxmlApplication) affectedElements.get(0).getElement()).getApplicationPath(), equalTo("/hello"));
verify(metamodel, times(1)).add(any(JaxrsWebxmlApplication.class));
@@ -443,15 +463,153 @@
}
@Test
- public void shouldOverrideApplicationWhenChangingWebxml() throws Exception {
+ public void shouldOverrideJavaApplicationWhenAddingCustomServletMapping() throws Exception {
+ // in this test, the java-application exists first, and then a web.xml application is added -> it should immediately override the java-one
// pre-conditions
final IType type = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
javaProject, progressMonitor);
- final JaxrsJavaApplication application = createApplication(type);
+ final JaxrsJavaApplication application = createJavaApplication(type);
metamodel.add(application);
final IResource webxmlResource = WorkbenchUtils.replaceDeploymentDescriptorWith(javaProject,
- "web-3_0-with-servlet-mapping.xml", bundle);
+ "web-3_0-with-custom-servlet-mapping.xml", bundle);
// operation
+ final ResourceDelta event = createEvent(webxmlResource, ADDED);
+ final List<JaxrsElementDelta> affectedElements = processResourceChanges(event, progressMonitor);
+ // verifications: the JAVA Application is the sole element to be really changed
+ assertThat(affectedElements.size(), equalTo(2));
+ assertThat(affectedElements.get(0).getDeltaKind(), equalTo(ADDED));
+ assertThat(affectedElements.get(0).getElement().getElementKind(), equalTo(EnumElementKind.APPLICATION_WEBXML));
+ final JaxrsWebxmlApplication webxmlApplication = (JaxrsWebxmlApplication) affectedElements.get(0).getElement();
+ assertThat(webxmlApplication.getElementCategory(), equalTo(EnumElementCategory.APPLICATION));
+ assertThat(webxmlApplication.getApplicationPath(), equalTo("/hello"));
+
+ assertThat(affectedElements.get(1).getElement().getElementKind(), equalTo(EnumElementKind.APPLICATION_JAVA));
+ assertThat(affectedElements.get(1).getDeltaKind(), equalTo(CHANGED));
+ final JaxrsJavaApplication javaApplication = (JaxrsJavaApplication)affectedElements.get(1).getElement();
+ assertThat(metamodel.getApplication(), equalTo((IJaxrsApplication)javaApplication)); // custom web.xml override DOES NOT precede the java based JAX-RS Application element
+ assertThat(javaApplication.getApplicationPath(), equalTo("/hello")); // Java-based application configuration should not be changed
+ assertThat(metamodel.getElements(javaProject).size(), equalTo(2)); // old application (java) + new one (web.xml)
+ verify(metamodel, times(1)).add(any(JaxrsWebxmlApplication.class));
+ }
+
+ /**
+ * in this test, the webxml exists first, and then an annotated Java Application is added -> it should be immediately overriden
+ */
+ @Test
+ public void shouldOverrideJavaApplicationWhenAddingAnnotatedJavaApplication() throws Exception {
+ // precondition
+ final JaxrsWebxmlApplication webxmlApplication = createWebxmlApplication("org.jboss.tools.ws.jaxrs.sample.services.RestApplication", "/hello");
+ metamodel.add(webxmlApplication);
+ final IType type = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
+ javaProject, progressMonitor);
+ // operation
+ final ResourceDelta event = createEvent(type.getResource(), ADDED);
+ final List<JaxrsElementDelta> affectedElements = processResourceChanges(event, progressMonitor);
+ // verifications: the JAVA Application is the sole element to be really changed
+ assertThat(affectedElements.size(), equalTo(1));
+ assertThat(affectedElements.get(0).getDeltaKind(), equalTo(ADDED));
+ assertThat(affectedElements.get(0).getElement().getElementKind(), equalTo(EnumElementKind.APPLICATION_JAVA));
+ final JaxrsJavaApplication javaApplication = (JaxrsJavaApplication) affectedElements.get(0).getElement();
+ assertThat(javaApplication.getElementCategory(), equalTo(EnumElementCategory.APPLICATION));
+ assertThat(javaApplication.getApplicationPath(), equalTo("/hello"));
+ assertThat(metamodel.getElements(javaProject).size(), equalTo(2)); // old application (web.xml) + new one (java)
+ verify(metamodel, times(1)).add(any(JaxrsJavaApplication.class));
+ }
+
+ /**
+ * in this test, the webxml exists first, and then a NOT annotated Java Application is added -> it should be
+ * immediately overriden
+ *
+ * @throws Exception
+ */
+ @Test
+ public void shouldOverrideJavaApplicationWhenAddingUnannotatedJavaApplication() throws Exception {
+ // precondition
+ final JaxrsWebxmlApplication webxmlApplication = createWebxmlApplication("org.jboss.tools.ws.jaxrs.sample.services.RestApplication", "/hello");
+ metamodel.add(webxmlApplication);
+ final IType type = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
+ javaProject, progressMonitor);
+ WorkbenchUtils.replaceFirstOccurrenceOfCode(type.getCompilationUnit(), "@ApplicationPath(\"/app\")", "", false);
+ // operation
+ final ResourceDelta event = createEvent(type.getResource(), ADDED);
+ final List<JaxrsElementDelta> affectedElements = processResourceChanges(event, progressMonitor);
+ // verifications: the JAVA Application is the sole element to be really changed
+ assertThat(affectedElements.size(), equalTo(1));
+ assertThat(affectedElements.get(0).getDeltaKind(), equalTo(ADDED));
+ assertThat(affectedElements.get(0).getElement().getElementKind(), equalTo(EnumElementKind.APPLICATION_JAVA));
+ final JaxrsJavaApplication javaApplication = (JaxrsJavaApplication) affectedElements.get(0).getElement();
+ assertThat(javaApplication.getElementCategory(), equalTo(EnumElementCategory.APPLICATION));
+ assertThat(javaApplication.getApplicationPath(), equalTo("/hello"));
+ assertThat(metamodel.getElements(javaProject).size(), equalTo(2)); // old application (web.xml) + new one (java)
+ verify(metamodel, times(1)).add(any(JaxrsJavaApplication.class));
+ }
+
+ /**
+ * In this test, the java application path override should be removed when the web.xml application is removed from the web.xml file
+ * @throws Exception
+ */
+ @Test
+ public void shouldUnoverrideAnnotatedJavaApplicationWhenRemovingCustomWebxml() throws Exception {
+ // precondition
+ final JaxrsWebxmlApplication webxmlApplication = createWebxmlApplication("org.jboss.tools.ws.jaxrs.sample.services.RestApplication", "/hello");
+ metamodel.add(webxmlApplication);
+ final IType type = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
+ javaProject, progressMonitor);
+ final JaxrsJavaApplication javaApplication = createJavaApplication(type);
+ metamodel.add(javaApplication);
+ assertThat(javaApplication.isOverriden(), equalTo(true));
+ // operation
+ final ResourceDelta event = createEvent(webxmlApplication.getResource(), REMOVED);
+ final List<JaxrsElementDelta> affectedElements = processResourceChanges(event, progressMonitor);
+ // verifications
+ assertThat(affectedElements.size(), equalTo(2));
+ assertThat(affectedElements.get(0).getDeltaKind(), equalTo(REMOVED));
+ assertThat(affectedElements.get(0).getElement().getElementKind(), equalTo(EnumElementKind.APPLICATION_WEBXML));
+ assertThat(affectedElements.get(1).getDeltaKind(), equalTo(CHANGED));
+ assertThat(affectedElements.get(1).getElement().getElementKind(), equalTo(EnumElementKind.APPLICATION_JAVA));
+ final JaxrsJavaApplication application = (JaxrsJavaApplication) affectedElements.get(1).getElement();
+ assertThat(application.getElementCategory(), equalTo(EnumElementCategory.APPLICATION));
+ assertThat(application.getApplicationPath(), equalTo("/app"));
+ assertThat(metamodel.getElements(javaProject).size(), equalTo(1)); // one (java)
+ }
+
+ @Test
+ public void shouldUnoverrideUnannotatedJavaApplicationWhenRemovingCustomWebxml() throws Exception {
+ // precondition
+ final JaxrsWebxmlApplication webxmlApplication = createWebxmlApplication("org.jboss.tools.ws.jaxrs.sample.services.RestApplication", "/hello");
+ metamodel.add(webxmlApplication);
+ final IType type = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
+ javaProject, progressMonitor);
+ WorkbenchUtils.replaceFirstOccurrenceOfCode(type.getCompilationUnit(), "@ApplicationPath(\"/app\")", "", false);
+ final JaxrsJavaApplication javaApplication = createJavaApplication(type);
+ metamodel.add(javaApplication);
+ assertThat(javaApplication.isOverriden(), equalTo(true));
+ // operation
+ final ResourceDelta event = createEvent(webxmlApplication.getResource(), REMOVED);
+ final List<JaxrsElementDelta> affectedElements = processResourceChanges(event, progressMonitor);
+ // verifications
+ assertThat(affectedElements.size(), equalTo(2));
+ assertThat(affectedElements.get(0).getDeltaKind(), equalTo(REMOVED));
+ assertThat(affectedElements.get(0).getElement().getElementKind(), equalTo(EnumElementKind.APPLICATION_WEBXML));
+ assertThat(affectedElements.get(1).getDeltaKind(), equalTo(CHANGED));
+ assertThat(affectedElements.get(1).getElement().getElementKind(), equalTo(EnumElementKind.APPLICATION_JAVA));
+ final JaxrsJavaApplication application = (JaxrsJavaApplication) affectedElements.get(1).getElement();
+ assertThat(application.getElementCategory(), equalTo(EnumElementCategory.APPLICATION));
+ assertThat(application.getApplicationPath(), nullValue());
+ assertThat(metamodel.getElements(javaProject).size(), equalTo(1)); // one (java)
+ }
+
+
+ @Test
+ public void shouldNotOverrideJavaApplicationWhenAddingDefaultServletMapping() throws Exception {
+ // pre-conditions
+ final IType type = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
+ javaProject, progressMonitor);
+ final JaxrsJavaApplication application = createJavaApplication(type);
+ metamodel.add(application);
+ final IResource webxmlResource = WorkbenchUtils.replaceDeploymentDescriptorWith(javaProject,
+ "web-3_0-with-default-servlet-mapping.xml", bundle);
+ // operation
final ResourceDelta event = createEvent(webxmlResource, CHANGED);
final List<JaxrsElementDelta> affectedElements = processResourceChanges(event, progressMonitor);
// verifications
@@ -463,25 +621,108 @@
verify(metamodel, times(1)).add(any(JaxrsWebxmlApplication.class));
assertThat(metamodel.getElements(javaProject).size(), equalTo(2)); // old application (java) + new one (web.xml)
assertThat(metamodel.getApplication(), equalTo((IJaxrsApplication)webxmlApplication)); // web.xml based application precedes any other java based JAX-RS Application element
-
+ assertThat(metamodel.getJavaApplications().get(0).getApplicationPath(), equalTo("/app")); // Java-based application configuration should not be changed
}
-
+
+ /**
+ * In this test, the existing Java Application is not modified when adding a web.xml with default application configuration,
+ * but the resulting webxmlApplication becomes the primary one in the metamodel
+ * @throws Exception
+ */
@Test
- public void shouldChangeApplicationWhenChangingWebxml() throws Exception {
+ public void shouldPreceedJavaApplicationWhenAddingDefaultWebxmlMapping() throws Exception {
+ // in this test, the java-application exists first, and then a web.xml application is added -> it should immediately override the java-one
// pre-conditions
+ final IType type = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
+ javaProject, progressMonitor);
+ final JaxrsJavaApplication javaApplication = createJavaApplication(type);
+ metamodel.add(javaApplication);
final IResource webxmlResource = WorkbenchUtils.replaceDeploymentDescriptorWith(javaProject,
- "web-3_0-with-servlet-mapping.xml", bundle);
- metamodel.add(createApplication("/foo"));
+ "web-3_0-with-default-servlet-mapping.xml", bundle);
// operation
+ final ResourceDelta event = createEvent(webxmlResource, ADDED);
+ final List<JaxrsElementDelta> affectedElements = processResourceChanges(event, progressMonitor);
+ // verifications
+ assertThat(affectedElements.size(), equalTo(1));
+ assertThat(affectedElements.get(0).getDeltaKind(), equalTo(ADDED));
+ assertThat(affectedElements.get(0).getElement().getElementKind(), equalTo(EnumElementKind.APPLICATION_WEBXML));
+ final JaxrsWebxmlApplication webxmlApplication = (JaxrsWebxmlApplication) affectedElements.get(0).getElement();
+ assertThat(webxmlApplication.getElementCategory(), equalTo(EnumElementCategory.APPLICATION));
+ assertThat(webxmlApplication.getApplicationPath(), equalTo("/hello"));
+ assertThat(javaApplication.getApplicationPath(), equalTo("/app")); // Java-based application configuration should not be changed
+ assertThat(metamodel.getElements(javaProject).size(), equalTo(2)); // old application (java) + new one (web.xml)
+ assertThat(metamodel.getApplication(), equalTo((IJaxrsApplication)webxmlApplication)); // old application (java) + new one (web.xml)
+ verify(metamodel, times(1)).add(any(JaxrsWebxmlApplication.class));
+ }
+
+ @Test
+ public void shouldRestoreJavaApplicationWhenRemovingDefaultWebxmlMapping() throws Exception {
+ // in this test, the java-application exists first, and then a web.xml application is added -> it should immediately override the java-one
+ // pre-conditions
+ final IType type = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
+ javaProject, progressMonitor);
+ final JaxrsJavaApplication javaApplication = createJavaApplication(type);
+ metamodel.add(javaApplication);
+ final JaxrsWebxmlApplication webxmlApplication = createWebxmlApplication(EnumJaxrsClassname.APPLICATION.qualifiedName, "/hello");
+ metamodel.add(webxmlApplication);
// operation
+ final ResourceDelta event = createEvent(webxmlApplication.getResource(), REMOVED);
+ final List<JaxrsElementDelta> affectedElements = processResourceChanges(event, progressMonitor);
+ // verifications
+ assertThat(affectedElements.size(), equalTo(1));
+ assertThat(affectedElements.get(0).getDeltaKind(), equalTo(REMOVED));
+ assertThat(affectedElements.get(0).getElement().getElementKind(), equalTo(EnumElementKind.APPLICATION_WEBXML));
+ assertThat(javaApplication.getApplicationPath(), equalTo("/app")); // Java-based application configuration should not be changed
+ assertThat(metamodel.getElements(javaProject).size(), equalTo(1)); // java application
+ assertThat(metamodel.getApplication(), equalTo((IJaxrsApplication)javaApplication)); // old application (java) + new one (web.xml)
+ verify(metamodel, times(1)).add(any(JaxrsWebxmlApplication.class));
+ }
+
+ /**
+ * In this test, the webxml application is changed when the application path is changed, too.
+ * @throws Exception
+ */
+ @Test
+ public void shouldReplaceWebxmlApplicationWhenChangingApplicationClassName() throws Exception {
+ // pre-conditions
+ final IResource webxmlResource = WorkbenchUtils.replaceDeploymentDescriptorWith(javaProject,
+ "web-3_0-with-default-servlet-mapping.xml", bundle);
+ metamodel.add(createWebxmlApplication("bar.foo", "/foo"));
+ // operation
final ResourceDelta event = createEvent(webxmlResource, CHANGED);
final List<JaxrsElementDelta> affectedElements = processResourceChanges(event, progressMonitor);
// verifications
+ assertThat(affectedElements.size(), equalTo(2));
+ assertThat(affectedElements.get(0).getElement().getElementKind(), equalTo(EnumElementKind.APPLICATION_WEBXML));
+ assertThat(affectedElements.get(0).getDeltaKind(), equalTo(ADDED));
+ assertThat(affectedElements.get(1).getElement().getElementCategory(), equalTo(EnumElementCategory.APPLICATION));
+ assertThat(affectedElements.get(1).getElement().getElementKind(), equalTo(EnumElementKind.APPLICATION_WEBXML));
+ assertThat(affectedElements.get(1).getDeltaKind(), equalTo(REMOVED));
+ assertThat(((JaxrsWebxmlApplication) affectedElements.get(0).getElement()).getApplicationPath(), equalTo("/hello"));
+ verify(metamodel, times(2)).add(any(JaxrsWebxmlApplication.class)); // initial app added + new app added, too
+ verify(metamodel, times(1)).remove(any(JaxrsWebxmlApplication.class)); // initial app removed
+ assertThat(metamodel.getElements(javaProject).size(), equalTo(1));
+ }
+
+ /**
+ * In this test, the webxml application is changed when the application path is changed, too.
+ * @throws Exception
+ */
+ @Test
+ public void shouldChangeWebxmlApplicationWhenChangingApplicationPathValue() throws Exception {
+ // pre-conditions
+ final IResource webxmlResource = WorkbenchUtils.replaceDeploymentDescriptorWith(javaProject,
+ "web-3_0-with-default-servlet-mapping.xml", bundle);
+ metamodel.add(createWebxmlApplication(EnumJaxrsClassname.APPLICATION.qualifiedName, "/foo"));
+ // operation
+ // operation
+ final ResourceDelta event = createEvent(webxmlResource, CHANGED);
+ final List<JaxrsElementDelta> affectedElements = processResourceChanges(event, progressMonitor);
+ // verifications
assertThat(affectedElements.size(), equalTo(1));
- assertThat(affectedElements.get(0).getElement().getElementCategory(), equalTo(EnumElementCategory.APPLICATION));
+ assertThat(affectedElements.get(0).getElement().getElementKind(), equalTo(EnumElementKind.APPLICATION_WEBXML));
assertThat(affectedElements.get(0).getDeltaKind(), equalTo(CHANGED));
assertThat(((JaxrsWebxmlApplication) affectedElements.get(0).getElement()).getApplicationPath(), equalTo("/hello"));
- verify(metamodel, times(1)).add(any(JaxrsWebxmlApplication.class));
assertThat(metamodel.getElements(javaProject).size(), equalTo(1));
}
@@ -503,9 +744,9 @@
}
@Test
- public void shouldRemoveApplicationWhenChangingWebxml() throws Exception {
+ public void shouldRemoveWebxmlApplicationWhenChangingWebxml() throws Exception {
// pre-conditions
- metamodel.add(createApplication("/hello"));
+ metamodel.add(createWebxmlApplication(EnumJaxrsClassname.APPLICATION.qualifiedName, "/hello"));
final IResource webxmlResource = WorkbenchUtils.replaceDeploymentDescriptorWith(javaProject,
"web-3_0-without-servlet-mapping.xml", bundle);
// operation
@@ -521,13 +762,13 @@
}
@Test
- public void shouldRemoveApplicationWhenRemovingWebxml() throws Exception {
+ public void shouldRemoveWebxmlApplicationWhenRemovingWebxml() throws Exception {
// pre-conditions
// JaxrsMetamodel metamodel = new JaxrsMetamodel(javaProject);
- final JaxrsWebxmlApplication application = createApplication("/hello");
+ final JaxrsWebxmlApplication application = createWebxmlApplication(EnumJaxrsClassname.APPLICATION.qualifiedName, "/hello");
metamodel.add(application);
final IResource webxmlResource = WorkbenchUtils.replaceDeploymentDescriptorWith(javaProject,
- "web-3_0-with-servlet-mapping.xml", bundle);
+ "web-3_0-with-default-servlet-mapping.xml", bundle);
// operation
webxmlResource.delete(true, progressMonitor);
final ResourceDelta event = createEvent(webxmlResource, REMOVED);
@@ -542,11 +783,11 @@
@Test
@Ignore()
- public void shouldRemoveApplicationWhenRemovingWebInfFolder() throws Exception {
+ public void shouldRemoveWebxmlApplicationWhenRemovingWebInfFolder() throws Exception {
// pre-conditions
final IResource webxmlResource = WorkbenchUtils.replaceDeploymentDescriptorWith(javaProject,
"web-3_0-with-servlet-mapping.xml", bundle);
- final JaxrsWebxmlApplication application = createApplication("/hello");
+ final JaxrsWebxmlApplication application = createWebxmlApplication(EnumJaxrsClassname.APPLICATION.qualifiedName, "/hello");
metamodel.add(application);
// operation
Modified: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsElementFactoryTestCase.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsElementFactoryTestCase.java 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsElementFactoryTestCase.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -16,15 +16,19 @@
import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.getAnnotation;
import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.getMethod;
import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.getType;
+import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.APPLICATION_PATH;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.GET;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.HTTP_METHOD;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.PATH;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.QUERY_PARAM;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.spy;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
@@ -32,9 +36,13 @@
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.WorkbenchUtils;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.WtpUtils;
import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
+import org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname;
import org.jboss.tools.ws.jaxrs.core.jdt.JdtUtils;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumElementKind;
+import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsApplication;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsHttpMethod;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsResource;
import org.junit.Before;
@@ -223,6 +231,87 @@
// verifications
assertNull(element);
}
+
+ @Test
+ public void shouldCreateApplicationFromApplicationAnnotationAndApplicationSubclass() throws CoreException {
+ // pre-conditions
+ final IType type = getType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication", javaProject);
+ final Annotation annotation = getAnnotation(type, APPLICATION_PATH.qualifiedName);
+ // operation
+ final JaxrsJavaElement<?> element = factory.createApplication(annotation,
+ JdtUtils.parse(type, progressMonitor), metamodel);
+ // verifications
+ assertNotNull(element);
+ final IJaxrsApplication application = (IJaxrsApplication) element;
+ // result contains a mix of resource methods and subresource methods since http methods are built-in the metamodel
+ assertThat(application.getApplicationPath(), equalTo("/app"));
+ }
+ @Test
+ public void shouldCreateApplicationFromApplicationSubclassOnly() throws CoreException {
+ // pre-conditions
+ final IType type = getType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication", javaProject);
+ final Annotation annotation = getAnnotation(type, APPLICATION_PATH.qualifiedName);
+ WorkbenchUtils.delete(annotation.getJavaAnnotation(), false);
+ // operation
+ final JaxrsJavaElement<?> element = factory.createApplication(type,
+ JdtUtils.parse(type, progressMonitor), metamodel);
+ // verifications
+ assertNotNull(element);
+ final IJaxrsApplication application = (IJaxrsApplication) element;
+ // result contains a mix of resource methods and subresource methods since http methods are built-in the metamodel
+ assertNull(application.getApplicationPath());
+ }
+ @Test
+ public void shouldCreateApplicationFromApplicationAnnotationOnly() throws CoreException {
+ // pre-conditions
+ final IType initialType = getType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication", javaProject);
+ WorkbenchUtils.replaceFirstOccurrenceOfCode(initialType.getCompilationUnit(), "RestApplication extends Application", "RestApplication", false);
+ final IType type = getType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication", javaProject);
+ final IType applicationType = JdtUtils.resolveType(EnumJaxrsClassname.APPLICATION.qualifiedName, javaProject, progressMonitor);
+ assertFalse(JdtUtils.isTypeOrSuperType(applicationType, type));
+ final Annotation annotation = getAnnotation(type, APPLICATION_PATH.qualifiedName);
+ // operation
+ final JaxrsJavaElement<?> element = factory.createApplication(annotation,
+ JdtUtils.parse(type, progressMonitor), metamodel);
+ // verifications
+ assertNotNull(element);
+ final IJaxrsApplication application = (IJaxrsApplication) element;
+ // result contains a mix of resource methods and subresource methods since http methods are built-in the metamodel
+ assertThat(application.getApplicationPath(), equalTo("/app"));
+ }
+
+ @Test
+ public void shouldCreateApplicationFromApplicationSubclassInWebxml() throws CoreException {
+ // pre-conditions
+ final IType appType = getType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication", javaProject);
+ IFolder webInfFolder = WtpUtils.getWebInfFolder(javaProject.getProject());
+ IResource webxmlResource = webInfFolder.findMember("web.xml");
+ final JaxrsJavaApplication javaApplication = factory.createApplication(appType, JdtUtils.parse(appType, progressMonitor), metamodel);
+ metamodel.add(javaApplication);
+ // operation
+ final JaxrsWebxmlApplication webxmlApplication = factory.createApplication(
+ appType.getFullyQualifiedName(), "/foo", webxmlResource, metamodel);
+ // verifications
+ assertNotNull(webxmlApplication);
+ assertThat(webxmlApplication.getApplicationPath(), equalTo("/foo"));
+ assertThat(webxmlApplication.isOverride(), equalTo(true));
+ assertThat(webxmlApplication.getOverridenJaxrsJavaApplication(), equalTo(javaApplication));
+ }
+
+ @Test
+ public void shouldCreateApplicationFromApplicationClassInWebxml() throws CoreException {
+ // pre-conditions
+ IFolder webInfFolder = WtpUtils.getWebInfFolder(javaProject.getProject());
+ IResource webxmlResource = webInfFolder.findMember("web.xml");
+ // operation
+ final JaxrsWebxmlApplication webxmlApplication = factory.createApplication(
+ EnumJaxrsClassname.APPLICATION.qualifiedName, "/foo", webxmlResource, metamodel);
+ // verifications
+ assertNotNull(webxmlApplication);
+ assertThat(webxmlApplication.getApplicationPath(), equalTo("/foo"));
+ assertThat(webxmlApplication.isOverride(), equalTo(false));
+ assertThat(webxmlApplication.getOverridenJaxrsJavaApplication(), equalTo(null));
+ }
}
Modified: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsMetamodelTestCase.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsMetamodelTestCase.java 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsMetamodelTestCase.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -22,7 +22,6 @@
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.HTTP_METHOD;
import static org.junit.Assert.assertThat;
-import java.lang.annotation.Target;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
@@ -39,7 +38,6 @@
import org.jboss.tools.ws.jaxrs.core.builder.AbstractMetamodelBuilderTestCase;
import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
import org.jboss.tools.ws.jaxrs.core.jdt.JdtUtils;
-import org.jboss.tools.ws.jaxrs.core.metamodel.EnumElementKind;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsEndpoint;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsHttpMethod;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsResource;
@@ -158,8 +156,10 @@
}
}
@Test
- public void shouldRetrieveApplicationPath() throws CoreException {
- assertThat(metamodel.getApplication().getElementKind(), equalTo(EnumElementKind.APPLICATION_WEBXML));
+ public void shouldRetrieveAllApplicationPathes() throws CoreException {
+ assertThat(metamodel.getAllApplications().size(), equalTo(2));
+ assertThat(metamodel.getWebxmlApplications().size(), equalTo(1));
+ assertThat(metamodel.getJavaApplications().size(), equalTo(1));
assertThat(metamodel.getApplication().getApplicationPath(), equalTo("/hello"));
}
Copied: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsApplicationValidatorTestCase.java (from rev 43224, trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMetamodelValidatorTestCase.java)
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsApplicationValidatorTestCase.java (rev 0)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsApplicationValidatorTestCase.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -0,0 +1,217 @@
+/*******************************************************************************
+ * 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.validation;
+
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasSize;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+
+import java.util.List;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.wst.validation.ReporterHelper;
+import org.eclipse.wst.validation.internal.core.ValidationException;
+import org.eclipse.wst.validation.internal.provisional.core.IReporter;
+import org.jboss.tools.common.validation.ContextValidationHelper;
+import org.jboss.tools.common.validation.IProjectValidationContext;
+import org.jboss.tools.common.validation.ValidatorManager;
+import org.jboss.tools.common.validation.internal.ProjectValidationContext;
+import org.jboss.tools.ws.jaxrs.core.WorkbenchUtils;
+import org.jboss.tools.ws.jaxrs.core.builder.AbstractMetamodelBuilderTestCase;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsBaseElement;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsJavaApplication;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsWebxmlApplication;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.WtpUtils;
+import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
+import org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname;
+import org.jboss.tools.ws.jaxrs.core.jdt.JdtUtils;
+import org.jboss.tools.ws.jaxrs.core.metamodel.EnumElementKind;
+import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsApplication;
+import org.junit.Test;
+
+/**
+ * @author Xi
+ *
+ */
+ at SuppressWarnings("restriction")
+public class JaxrsApplicationValidatorTestCase extends AbstractMetamodelBuilderTestCase {
+
+ private final IReporter reporter = new ReporterHelper(new NullProgressMonitor());
+ private final ContextValidationHelper validationHelper = new ContextValidationHelper();
+ private final IProjectValidationContext context = new ProjectValidationContext();
+ private final ValidatorManager validatorManager = new ValidatorManager();
+
+ /**
+ * Creates a web.xml based JAX-RS Application element
+ *
+ * @param applicationPath
+ * @return
+ * @throws JavaModelException
+ */
+ private JaxrsWebxmlApplication createWebxmlApplication(final String applicationClassName, final String applicationPath) throws JavaModelException {
+ final IResource webDeploymentDescriptor = WtpUtils.getWebDeploymentDescriptor(project);
+ return new JaxrsWebxmlApplication(applicationClassName, applicationPath, webDeploymentDescriptor, metamodel);
+ }
+
+ @Test
+ public void shouldNotReportProblemIfOneJavaApplicationExists() throws CoreException, ValidationException {
+ // preconditions
+ final List<IJaxrsApplication> applications = metamodel.getAllApplications();
+ for (IJaxrsApplication application : applications) {
+ if (application.getElementKind() == EnumElementKind.APPLICATION_WEBXML) {
+ metamodel.remove((JaxrsBaseElement) application);
+ }
+ }
+ MarkerUtils.deleteJaxrsMarkers(project);
+ assertThat(metamodel.getAllApplications().size(), equalTo(1));
+ assertThat(metamodel.getApplication().getElementKind(), equalTo(EnumElementKind.APPLICATION_JAVA));
+ // operation
+ new JaxrsMetamodelValidator().validateAll(project, validationHelper, context, validatorManager, reporter);
+ // validation
+ assertThat(project.findMarkers(JaxrsMetamodelValidator.JAXRS_PROBLEM_TYPE, false, 0).length, equalTo(0));
+ }
+
+ @Test
+ public void shouldNotReportProblemIfOneWebxmlApplicationExists() throws CoreException, ValidationException {
+ // preconditions
+ final List<IJaxrsApplication> applications = metamodel.getAllApplications();
+ for (IJaxrsApplication application : applications) {
+ if (application.getElementKind() == EnumElementKind.APPLICATION_JAVA) {
+ metamodel.remove((JaxrsBaseElement) application);
+ }
+ }
+ assertThat(metamodel.getAllApplications().size(), equalTo(1));
+ assertThat(metamodel.getApplication().getElementKind(), equalTo(EnumElementKind.APPLICATION_WEBXML));
+ MarkerUtils.deleteJaxrsMarkers(project);
+ // operation
+ new JaxrsMetamodelValidator().validateAll(project, validationHelper, context, validatorManager, reporter);
+ // validation
+ assertThat(project.findMarkers(JaxrsMetamodelValidator.JAXRS_PROBLEM_TYPE, false, 0).length, equalTo(0));
+ }
+
+ @Test
+ public void shouldReportProblemOnProjectIfNoApplicationExists() throws CoreException, ValidationException {
+ // preconditions
+ final List<IJaxrsApplication> applications = metamodel.getAllApplications();
+ for (IJaxrsApplication application : applications) {
+ metamodel.remove((JaxrsBaseElement) application);
+ }
+ MarkerUtils.deleteJaxrsMarkers(project);
+ // operation
+ new JaxrsMetamodelValidator().validateAll(project, validationHelper, context, validatorManager, reporter);
+ // validation
+ final IMarker[] projectMarkers = project.findMarkers(JaxrsMetamodelValidator.JAXRS_PROBLEM_TYPE, false, 0);
+ assertThat(projectMarkers.length, equalTo(1));
+ }
+
+ @Test
+ public void shouldReportProblemOnApplicationsIfMultipleOnesExist() throws CoreException, ValidationException {
+ // preconditions
+ final List<IJaxrsApplication> applications = metamodel.getAllApplications();
+ assertThat(applications, hasSize(2));
+ MarkerUtils.deleteJaxrsMarkers(project);
+ // operation
+ new JaxrsMetamodelValidator().validateAll(project, validationHelper, context, validatorManager, reporter);
+ // validation
+ final IMarker[] projectMarkers = project.findMarkers(JaxrsMetamodelValidator.JAXRS_PROBLEM_TYPE, false, 0);
+ assertThat(projectMarkers.length, equalTo(0));
+ for (IJaxrsApplication application : metamodel.getAllApplications()) {
+ final IMarker[] appMarkers = ((JaxrsBaseElement) application).getResource().findMarkers(
+ JaxrsMetamodelValidator.JAXRS_PROBLEM_TYPE, true, IResource.DEPTH_INFINITE);
+ assertThat(appMarkers.length, equalTo(1));
+ }
+ }
+
+ @Test
+ public void shouldReportProblemOnJavaApplicationIfMissingApplicationPathAnnotationWithoutOverride()
+ throws CoreException, ValidationException {
+ // preconditions
+ final List<IJaxrsApplication> applications = metamodel.getAllApplications();
+ assertThat(applications, hasSize(2));
+ MarkerUtils.deleteJaxrsMarkers(project);
+ JaxrsJavaApplication javaApplication = null;
+ // remove web.xml-based application and remove @ApplicationPath annotation on java-based application
+ for (IJaxrsApplication application : applications) {
+ if (application.getElementKind() == EnumElementKind.APPLICATION_WEBXML) {
+ metamodel.remove((JaxrsBaseElement) application);
+ } else {
+ javaApplication = (JaxrsJavaApplication) application;
+ final Annotation appPathAnnotation = javaApplication
+ .getAnnotation(EnumJaxrsClassname.APPLICATION_PATH.qualifiedName);
+ javaApplication.removeAnnotation(appPathAnnotation);
+ }
+ }
+ // operation
+ new JaxrsMetamodelValidator().validateAll(project, validationHelper, context, validatorManager, reporter);
+ // validation
+ final IMarker[] projectMarkers = javaApplication.getJavaElement().getResource()
+ .findMarkers(JaxrsMetamodelValidator.JAXRS_PROBLEM_TYPE, false, 0);
+ assertThat(projectMarkers.length, equalTo(1));
+ }
+
+ @Test
+ public void shouldReportProblemOnJavaApplicationIfInvalidTypeHierarchy() throws CoreException, ValidationException {
+ // preconditions
+ final IType type = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication",
+ javaProject, new NullProgressMonitor());
+ WorkbenchUtils.replaceAllOccurrencesOfCode(type.getCompilationUnit(), "extends Application", "", false);
+ final JaxrsJavaApplication javaApplication = metamodel.getJavaApplications().get(0);
+ MarkerUtils.deleteJaxrsMarkers(project);
+ // operation
+ new JaxrsMetamodelValidator().validateAll(project, validationHelper, context, validatorManager, reporter);
+ // validation
+ final IMarker[] projectMarkers = javaApplication.getJavaElement().getResource()
+ .findMarkers(JaxrsMetamodelValidator.JAXRS_PROBLEM_TYPE, false, 0);
+ assertThat(projectMarkers.length, equalTo(1));
+ }
+
+ @Test
+ public void shouldNotReportProblemOnApplicationIfMissingApplicationPathAnnotationWithOverride()
+ throws Exception {
+ // preconditions
+ final JaxrsJavaApplication javaApplication = metamodel.getJavaApplications().get(0);
+ final Annotation appPathAnnotation = javaApplication.getAnnotation(EnumJaxrsClassname.APPLICATION_PATH.qualifiedName);
+ javaApplication.removeAnnotation(appPathAnnotation);
+ final JaxrsWebxmlApplication webxmlDefaultApplication = (JaxrsWebxmlApplication) metamodel.getApplication();
+ metamodel.remove(webxmlDefaultApplication);
+ final JaxrsWebxmlApplication webxmlApplication = createWebxmlApplication(javaApplication.getJavaClassName(), "/foo");
+ metamodel.add(webxmlApplication);
+ MarkerUtils.deleteJaxrsMarkers(project);
+ // operation
+ new JaxrsMetamodelValidator().validateAll(project, validationHelper, context, validatorManager, reporter);
+ // validation
+ final IMarker[] projectMarkers = javaApplication.getJavaElement().getResource()
+ .findMarkers(JaxrsMetamodelValidator.JAXRS_PROBLEM_TYPE, false, 0);
+ assertThat(projectMarkers.length, equalTo(0));
+ }
+
+ @Test
+ public void shouldNotReportProblemOnApplicationIfAnnotationExistsAndHierarchyValid() throws CoreException,
+ ValidationException {
+ // preconditions
+ final JaxrsJavaApplication javaApplication = metamodel.getJavaApplications().get(0);
+ final JaxrsWebxmlApplication webxmlDefaultApplication = (JaxrsWebxmlApplication) metamodel.getApplication();
+ metamodel.remove(webxmlDefaultApplication);
+ MarkerUtils.deleteJaxrsMarkers(project);
+ // operation
+ new JaxrsMetamodelValidator().validateAll(project, validationHelper, context, validatorManager, reporter);
+ // validation
+ final IMarker[] projectMarkers = javaApplication.getJavaElement().getResource()
+ .findMarkers(JaxrsMetamodelValidator.JAXRS_PROBLEM_TYPE, false, 0);
+ assertThat(projectMarkers.length, equalTo(0));
+ }
+}
Property changes on: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsApplicationValidatorTestCase.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsHttpMethodValidatorTestCase.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsHttpMethodValidatorTestCase.java (rev 0)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsHttpMethodValidatorTestCase.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -0,0 +1,154 @@
+/*******************************************************************************
+ * 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.validation;
+
+import static org.hamcrest.Matchers.equalTo;
+import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.changeAnnotation;
+import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.getAnnotation;
+import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.HTTP_METHOD;
+import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.TARGET;
+import static org.junit.Assert.assertThat;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.wst.validation.ReporterHelper;
+import org.eclipse.wst.validation.internal.core.ValidationException;
+import org.eclipse.wst.validation.internal.provisional.core.IReporter;
+import org.jboss.tools.common.validation.ContextValidationHelper;
+import org.jboss.tools.common.validation.IProjectValidationContext;
+import org.jboss.tools.common.validation.ValidatorManager;
+import org.jboss.tools.common.validation.internal.ProjectValidationContext;
+import org.jboss.tools.ws.jaxrs.core.WorkbenchUtils;
+import org.jboss.tools.ws.jaxrs.core.builder.AbstractMetamodelBuilderTestCase;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsBaseElement;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsHttpMethod;
+import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
+import org.junit.Test;
+
+/**
+ * @author Xi
+ *
+ */
+ at SuppressWarnings("restriction")
+public class JaxrsHttpMethodValidatorTestCase extends AbstractMetamodelBuilderTestCase {
+
+ private final IReporter reporter = new ReporterHelper(new NullProgressMonitor());
+ private final ContextValidationHelper validationHelper = new ContextValidationHelper();
+ private final IProjectValidationContext context = new ProjectValidationContext();
+ private final ValidatorManager validatorManager = new ValidatorManager();
+
+ private Set<IFile> toSet(IResource resource) {
+ final Set<IFile> changedFiles = new HashSet<IFile>();
+ changedFiles.add((IFile) resource);
+ return changedFiles;
+ }
+
+ @Test
+ public void shouldValidateHttpMethod() throws CoreException, ValidationException {
+ // preconditions
+ final IType fooType = WorkbenchUtils.getType("org.jboss.tools.ws.jaxrs.sample.services.FOO", javaProject);
+ final JaxrsBaseElement httpMethod = (JaxrsBaseElement) metamodel.getElement(fooType);
+ assertThat(MarkerUtils.findJaxrsMarkers(httpMethod).length, equalTo(0));
+ MarkerUtils.deleteJaxrsMarkers(httpMethod);
+ // operation
+ new JaxrsMetamodelValidator().validate(toSet(httpMethod.getResource()), project, validationHelper, context,
+ validatorManager, reporter);
+ // validation
+ assertThat(MarkerUtils.findJaxrsMarkers(httpMethod).length, equalTo(0));
+ }
+
+ @Test
+ public void shouldReportProblemWhenHttpMethodVerbIsEmpty() throws CoreException, ValidationException {
+ // preconditions
+ final IType fooType = WorkbenchUtils.getType("org.jboss.tools.ws.jaxrs.sample.services.FOO", javaProject);
+ final JaxrsHttpMethod httpMethod = metamodel.getElement(fooType, JaxrsHttpMethod.class);
+ final Annotation httpAnnotation = changeAnnotation(fooType, HTTP_METHOD.qualifiedName, new String[0]);
+ httpMethod.addOrUpdateAnnotation(httpAnnotation);
+ MarkerUtils.deleteJaxrsMarkers(httpMethod);
+ // operation
+ new JaxrsMetamodelValidator().validate(toSet(httpMethod.getResource()), project, validationHelper, context,
+ validatorManager, reporter);
+ // validation
+ final IMarker[] markers = MarkerUtils.findJaxrsMarkers(httpMethod);
+ assertThat(markers.length, equalTo(1));
+ }
+
+ @Test
+ public void shouldReportProblemWhenHttpMethodVerbIsNull() throws CoreException, ValidationException {
+ // preconditions
+ final IType fooType = WorkbenchUtils.getType("org.jboss.tools.ws.jaxrs.sample.services.FOO", javaProject);
+ final JaxrsHttpMethod httpMethod = metamodel.getElement(fooType, JaxrsHttpMethod.class);
+ final Annotation httpAnnotation = changeAnnotation(fooType, HTTP_METHOD.qualifiedName, (String) null);
+ httpMethod.addOrUpdateAnnotation(httpAnnotation);
+ MarkerUtils.deleteJaxrsMarkers(httpMethod);
+ // operation
+ new JaxrsMetamodelValidator().validate(toSet(httpMethod.getResource()), project, validationHelper, context,
+ validatorManager, reporter);
+ // validation
+ assertThat(MarkerUtils.findJaxrsMarkers(httpMethod).length, equalTo(1));
+ }
+
+ @Test
+ public void shouldReportProblemWhenHttpMethodTypeMissesTargetAnnotation() throws CoreException, ValidationException {
+ // preconditions
+ final IType fooType = WorkbenchUtils.getType("org.jboss.tools.ws.jaxrs.sample.services.FOO", javaProject);
+ final JaxrsHttpMethod httpMethod = metamodel.getElement(fooType, JaxrsHttpMethod.class);
+ final Annotation targetAnnotation = getAnnotation(fooType, TARGET.qualifiedName);
+ httpMethod.removeAnnotation(targetAnnotation);
+ MarkerUtils.deleteJaxrsMarkers(httpMethod);
+ // operation
+ new JaxrsMetamodelValidator().validate(toSet(httpMethod.getResource()), project, validationHelper, context,
+ validatorManager, reporter);
+ // validation
+ assertThat(MarkerUtils.findJaxrsMarkers(httpMethod).length, equalTo(1));
+ }
+
+ @Test
+ public void shouldReportProblemWhenHttpMethodTypeTargetAnnotationHasNullValue() throws CoreException,
+ ValidationException {
+ // preconditions
+ final IType fooType = WorkbenchUtils.getType("org.jboss.tools.ws.jaxrs.sample.services.FOO", javaProject);
+ final JaxrsHttpMethod httpMethod = metamodel.getElement(fooType, JaxrsHttpMethod.class);
+ final Annotation targetAnnotation = changeAnnotation(fooType, TARGET.qualifiedName, (String) null);
+ httpMethod.addOrUpdateAnnotation(targetAnnotation);
+ MarkerUtils.deleteJaxrsMarkers(httpMethod);
+ // operation
+ new JaxrsMetamodelValidator().validate(toSet(httpMethod.getResource()), project, validationHelper, context,
+ validatorManager, reporter);
+ // validation
+ assertThat(MarkerUtils.findJaxrsMarkers(httpMethod).length, equalTo(1));
+
+ }
+
+ @Test
+ public void shouldReportProblemWhenHttpMethodTypeTargetAnnotationHasWrongValue() throws CoreException,
+ ValidationException {
+ // preconditions
+ final IType fooType = WorkbenchUtils.getType("org.jboss.tools.ws.jaxrs.sample.services.FOO", javaProject);
+ final JaxrsHttpMethod httpMethod = metamodel.getElement(fooType, JaxrsHttpMethod.class);
+ final Annotation targetAnnotation = changeAnnotation(fooType, TARGET.qualifiedName, "FOO");
+ httpMethod.addOrUpdateAnnotation(targetAnnotation);
+ MarkerUtils.deleteJaxrsMarkers(httpMethod);
+ // operation
+ new JaxrsMetamodelValidator().validate(toSet(httpMethod.getResource()), project, validationHelper, context,
+ validatorManager, reporter);
+ // validation
+ assertThat(MarkerUtils.findJaxrsMarkers(httpMethod).length, equalTo(1));
+ }
+
+}
Property changes on: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsHttpMethodValidatorTestCase.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Deleted: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMetamodelValidatorTestCase.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMetamodelValidatorTestCase.java 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMetamodelValidatorTestCase.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -1,353 +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.validation;
-
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.hasSize;
-import static org.hamcrest.Matchers.is;
-import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.changeAnnotation;
-import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.getAnnotation;
-import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.HTTP_METHOD;
-import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.TARGET;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IMarker;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.jdt.core.ISourceRange;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.wst.validation.ReporterHelper;
-import org.eclipse.wst.validation.internal.core.ValidationException;
-import org.eclipse.wst.validation.internal.provisional.core.IReporter;
-import org.jboss.tools.common.validation.ContextValidationHelper;
-import org.jboss.tools.common.validation.IProjectValidationContext;
-import org.jboss.tools.common.validation.ValidationErrorManager;
-import org.jboss.tools.common.validation.ValidatorManager;
-import org.jboss.tools.common.validation.internal.ProjectValidationContext;
-import org.jboss.tools.ws.jaxrs.core.WorkbenchUtils;
-import org.jboss.tools.ws.jaxrs.core.builder.AbstractMetamodelBuilderTestCase;
-import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsBaseElement;
-import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsHttpMethod;
-import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsResource;
-import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsResourceMethod;
-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.IJaxrsApplication;
-import org.jboss.tools.ws.jaxrs.core.preferences.JaxrsPreferences;
-import org.junit.Test;
-
-/**
- * @author Xi
- *
- */
- at SuppressWarnings("restriction")
-public class JaxrsMetamodelValidatorTestCase extends AbstractMetamodelBuilderTestCase {
-
- private final IReporter reporter = new ReporterHelper(new NullProgressMonitor());
- private final ContextValidationHelper validationHelper = new ContextValidationHelper();
- private final IProjectValidationContext context = new ProjectValidationContext();
- private final ValidatorManager validatorManager = new ValidatorManager();
-
- private Set<IFile> toSet(IResource resource) {
- final Set<IFile> changedFiles = new HashSet<IFile>();
- changedFiles.add((IFile) resource);
- return changedFiles;
- }
-
- /**
- * @param element
- * @return
- * @throws CoreException
- */
- private IMarker[] findJaxrsMarkers(final JaxrsBaseElement element) throws CoreException {
- switch (element.getElementCategory()) {
- case HTTP_METHOD:
- case RESOURCE:
- return element.getResource().findMarkers(JaxrsMetamodelValidator.JAXRS_PROBLEM_TYPE, true,
- IResource.DEPTH_INFINITE);
- case RESOURCE_METHOD:
- final IMarker[] markers = element.getResource().findMarkers(JaxrsMetamodelValidator.JAXRS_PROBLEM_TYPE,
- true, IResource.DEPTH_INFINITE);
- final List<IMarker> resourceMethodMarkers = new ArrayList<IMarker>();
- final ISourceRange methodSourceRange = ((JaxrsResourceMethod) element).getJavaElement().getSourceRange();
-
- for (IMarker marker : markers) {
- final int markerCharStart = marker.getAttribute(IMarker.CHAR_START, -1);
- if (markerCharStart >= methodSourceRange.getOffset()
- && markerCharStart <= (methodSourceRange.getOffset() + methodSourceRange.getLength())) {
- resourceMethodMarkers.add(marker);
- }
- }
- return resourceMethodMarkers.toArray(new IMarker[resourceMethodMarkers.size()]);
- default:
- return new IMarker[0];
- }
- }
-
- /**
- * @param element
- * @throws CoreException
- */
- private void deleteJaxrsMarkers(final JaxrsBaseElement element) throws CoreException {
- element.getResource()
- .deleteMarkers(JaxrsMetamodelValidator.JAXRS_PROBLEM_TYPE, false, IResource.DEPTH_INFINITE);
- }
-
- /**
- * @param element
- * @throws CoreException
- */
- private void deleteJaxrsMarkers(final IProject project) throws CoreException {
- project.deleteMarkers(JaxrsMetamodelValidator.JAXRS_PROBLEM_TYPE, false, IResource.DEPTH_INFINITE);
- }
-
- @Test
- public void shouldValidateHttpMethod() throws CoreException, ValidationException {
- // preconditions
- final IType fooType = WorkbenchUtils.getType("org.jboss.tools.ws.jaxrs.sample.services.FOO", javaProject);
- final JaxrsBaseElement httpMethod = metamodel.getElement(fooType);
- assertThat(findJaxrsMarkers(httpMethod).length, equalTo(0));
- deleteJaxrsMarkers(httpMethod);
- // operation
- new JaxrsMetamodelValidator().validate(toSet(httpMethod.getResource()), project, validationHelper, context,
- validatorManager, reporter);
- // validation
- assertThat(findJaxrsMarkers(httpMethod).length, equalTo(0));
- }
-
- @Test
- public void shouldReportProblemWhenHttpMethodVerbIsEmpty() throws CoreException, ValidationException {
- // preconditions
- final IType fooType = WorkbenchUtils.getType("org.jboss.tools.ws.jaxrs.sample.services.FOO", javaProject);
- final JaxrsHttpMethod httpMethod = metamodel.getElement(fooType, JaxrsHttpMethod.class);
- final Annotation httpAnnotation = changeAnnotation(fooType, HTTP_METHOD.qualifiedName, new String[0]);
- httpMethod.addOrUpdateAnnotation(httpAnnotation);
- deleteJaxrsMarkers(httpMethod);
- // operation
- new JaxrsMetamodelValidator().validate(toSet(httpMethod.getResource()), project, validationHelper, context,
- validatorManager, reporter);
- // validation
- final IMarker[] markers = findJaxrsMarkers(httpMethod);
- assertThat(markers.length, equalTo(1));
- }
-
- @Test
- public void shouldReportProblemWhenHttpMethodVerbIsNull() throws CoreException, ValidationException {
- // preconditions
- final IType fooType = WorkbenchUtils.getType("org.jboss.tools.ws.jaxrs.sample.services.FOO", javaProject);
- final JaxrsHttpMethod httpMethod = metamodel.getElement(fooType, JaxrsHttpMethod.class);
- final Annotation httpAnnotation = changeAnnotation(fooType, HTTP_METHOD.qualifiedName, (String) null);
- httpMethod.addOrUpdateAnnotation(httpAnnotation);
- deleteJaxrsMarkers(httpMethod);
- // operation
- new JaxrsMetamodelValidator().validate(toSet(httpMethod.getResource()), project, validationHelper, context,
- validatorManager, reporter);
- // validation
- assertThat(findJaxrsMarkers(httpMethod).length, equalTo(1));
- }
-
- @Test
- public void shouldReportProblemWhenHttpMethodTypeMissesTargetAnnotation() throws CoreException, ValidationException {
- // preconditions
- final IType fooType = WorkbenchUtils.getType("org.jboss.tools.ws.jaxrs.sample.services.FOO", javaProject);
- final JaxrsHttpMethod httpMethod = metamodel.getElement(fooType, JaxrsHttpMethod.class);
- final Annotation targetAnnotation = getAnnotation(fooType, TARGET.qualifiedName);
- httpMethod.removeAnnotation(targetAnnotation);
- deleteJaxrsMarkers(httpMethod);
- // operation
- new JaxrsMetamodelValidator().validate(toSet(httpMethod.getResource()), project, validationHelper, context,
- validatorManager, reporter);
- // validation
- assertThat(findJaxrsMarkers(httpMethod).length, equalTo(1));
- }
-
- @Test
- public void shouldReportProblemWhenHttpMethodTypeTargetAnnotationHasNullValue() throws CoreException,
- ValidationException {
- // preconditions
- final IType fooType = WorkbenchUtils.getType("org.jboss.tools.ws.jaxrs.sample.services.FOO", javaProject);
- final JaxrsHttpMethod httpMethod = metamodel.getElement(fooType, JaxrsHttpMethod.class);
- final Annotation targetAnnotation = changeAnnotation(fooType, TARGET.qualifiedName, (String) null);
- httpMethod.addOrUpdateAnnotation(targetAnnotation);
- deleteJaxrsMarkers(httpMethod);
- // operation
- new JaxrsMetamodelValidator().validate(toSet(httpMethod.getResource()), project, validationHelper, context,
- validatorManager, reporter);
- // validation
- assertThat(findJaxrsMarkers(httpMethod).length, equalTo(1));
-
- }
-
- @Test
- public void shouldReportProblemWhenHttpMethodTypeTargetAnnotationHasWrongValue() throws CoreException,
- ValidationException {
- // preconditions
- final IType fooType = WorkbenchUtils.getType("org.jboss.tools.ws.jaxrs.sample.services.FOO", javaProject);
- final JaxrsHttpMethod httpMethod = metamodel.getElement(fooType, JaxrsHttpMethod.class);
- final Annotation targetAnnotation = changeAnnotation(fooType, TARGET.qualifiedName, "FOO");
- httpMethod.addOrUpdateAnnotation(targetAnnotation);
- deleteJaxrsMarkers(httpMethod);
- // operation
- new JaxrsMetamodelValidator().validate(toSet(httpMethod.getResource()), project, validationHelper, context,
- validatorManager, reporter);
- // validation
- assertThat(findJaxrsMarkers(httpMethod).length, equalTo(1));
- }
-
- @Test
- public void shouldValidateCustomerResourceMethod() throws CoreException, ValidationException {
- // preconditions
- final IType customerJavaType = WorkbenchUtils.getType(
- "org.jboss.tools.ws.jaxrs.sample.services.CustomerResource", javaProject);
- final JaxrsBaseElement customerResource = metamodel.getElement(customerJavaType);
- deleteJaxrsMarkers(customerResource);
- // operation
- new JaxrsMetamodelValidator().validate(toSet(customerResource.getResource()), project, validationHelper,
- context, validatorManager, reporter);
- // validation
- assertThat(findJaxrsMarkers(customerResource).length, equalTo(0));
- }
-
- @Test
- public void shouldReportProblemsOnBarResourceMethods() throws CoreException, ValidationException {
- // preconditions
- final IType barJavaType = WorkbenchUtils.getType("org.jboss.tools.ws.jaxrs.sample.services.BarResource",
- javaProject);
- final JaxrsResource barResource = metamodel.getElement(barJavaType, JaxrsResource.class);
- deleteJaxrsMarkers(barResource);
- // operation
- new JaxrsMetamodelValidator().validate(toSet(barResource.getResource()), project, validationHelper, context,
- validatorManager, reporter);
- // validation
- final IMarker[] markers = findJaxrsMarkers(barResource);
- assertThat(markers.length, equalTo(8));
- final Map<String, JaxrsResourceMethod> resourceMethods = barResource.getMethods();
- for (Entry<String, JaxrsResourceMethod> entry : resourceMethods.entrySet()) {
- final IMarker[] methodMarkers = findJaxrsMarkers(entry.getValue());
- if (entry.getKey().contains("getContent1")) {
- assertThat(entry.getValue().hasErrors(), is(true));
- assertThat(methodMarkers.length, equalTo(1));
- assertThat(methodMarkers[0].getType(), equalTo(JaxrsMetamodelValidator.JAXRS_PROBLEM_TYPE));
- assertThat(methodMarkers[0].getAttribute(ValidationErrorManager.PREFERENCE_KEY_ATTRIBUTE_NAME, ""),
- equalTo(JaxrsPreferences.RESOURCE_METHOD_UNBOUND_PATH_ANNOTATION_TEMPLATE_PARAMETER));
- } else if (entry.getKey().contains("getContent2")) {
- assertThat(entry.getValue().hasErrors(), is(true));
- assertThat(methodMarkers.length, equalTo(3));
- } else if (entry.getKey().contains("update1")) {
- assertThat(entry.getValue().hasErrors(), is(true));
- assertThat(methodMarkers.length, equalTo(2));
- } else if (entry.getKey().contains("update2")) {
- assertThat(entry.getValue().hasErrors(), is(true));
- assertThat(methodMarkers.length, equalTo(1));
- } else if (entry.getKey().contains("update3")) {
- assertThat(entry.getValue().hasErrors(), is(true));
- assertThat(methodMarkers.length, equalTo(1));
- } else {
- fail("Unexpected method " + entry.getKey());
- }
- }
- }
-
- @Test
- public void shouldReportProblemsOnBazResourceMethods() throws CoreException, ValidationException {
- // preconditions
- final IType barJavaType = WorkbenchUtils.getType("org.jboss.tools.ws.jaxrs.sample.services.BazResource",
- javaProject);
- final JaxrsResource barResource = metamodel.getElement(barJavaType, JaxrsResource.class);
- deleteJaxrsMarkers(barResource);
- // operation
- new JaxrsMetamodelValidator().validate(toSet(barResource.getResource()), project, validationHelper, context,
- validatorManager, reporter);
- // validation
- final IMarker[] markers = findJaxrsMarkers(barResource);
- assertThat(markers.length, equalTo(6));
- final Map<String, JaxrsResourceMethod> resourceMethods = barResource.getMethods();
- for (Entry<String, JaxrsResourceMethod> entry : resourceMethods.entrySet()) {
- final IMarker[] methodMarkers = findJaxrsMarkers(entry.getValue());
- if (entry.getKey().contains("getContent1")) {
- assertThat(entry.getValue().hasErrors(), is(true));
- assertThat(methodMarkers.length, equalTo(1));
- assertThat(methodMarkers[0].getType(), equalTo(JaxrsMetamodelValidator.JAXRS_PROBLEM_TYPE));
- assertThat(methodMarkers[0].getAttribute(ValidationErrorManager.PREFERENCE_KEY_ATTRIBUTE_NAME, ""),
- equalTo(JaxrsPreferences.RESOURCE_METHOD_UNBOUND_PATH_ANNOTATION_TEMPLATE_PARAMETER));
- } else if (entry.getKey().contains("getContent2")) {
- assertThat(entry.getValue().hasErrors(), is(true));
- assertThat(methodMarkers.length, equalTo(2));
- } else if (entry.getKey().contains("update1")) {
- assertThat(entry.getValue().hasErrors(), is(true));
- assertThat(methodMarkers.length, equalTo(2));
- } else if (entry.getKey().contains("update2")) {
- assertThat(entry.getValue().hasErrors(), is(false));
- assertThat(methodMarkers.length, equalTo(0));
- } else if (entry.getKey().contains("update3")) {
- assertThat(entry.getValue().hasErrors(), is(true));
- assertThat(methodMarkers.length, equalTo(1));
- } else {
- fail("Unexpected method " + entry.getKey());
- }
- }
- }
-
- @Test
- public void shouldNotWarnIfOneApplicationExists() throws CoreException, ValidationException {
- // preconditions
- final List<IJaxrsApplication> applications = metamodel.getAllApplications();
- for (IJaxrsApplication application : applications) {
- if (application.getElementKind() == EnumElementKind.APPLICATION_WEBXML) {
- metamodel.remove((JaxrsBaseElement) application);
- }
- }
- deleteJaxrsMarkers(project);
- // operation
- new JaxrsMetamodelValidator().validateAll(project, validationHelper, context, validatorManager, reporter);
- // validation
- assertThat(project.findMarkers(JaxrsMetamodelValidator.JAXRS_PROBLEM_TYPE, false, 0).length, equalTo(0));
- }
-
- @Test
- public void shouldWarnOnProjectIfNoApplicationExists() throws CoreException, ValidationException {
- // preconditions
- final List<IJaxrsApplication> applications = metamodel.getAllApplications();
- for (IJaxrsApplication application : applications) {
- metamodel.remove((JaxrsBaseElement) application);
- }
- deleteJaxrsMarkers(project);
- // operation
- new JaxrsMetamodelValidator().validateAll(project, validationHelper, context, validatorManager, reporter);
- // validation
- final IMarker[] projectMarkers = project.findMarkers(JaxrsMetamodelValidator.JAXRS_PROBLEM_TYPE, false, 0);
- assertThat(projectMarkers.length, equalTo(1));
- }
-
- @Test
- public void shouldWarnOnProjectIfMultipleApplicationsExist() throws CoreException, ValidationException {
- // preconditions
- final List<IJaxrsApplication> applications = metamodel.getAllApplications();
- assertThat(applications, hasSize(2));
- deleteJaxrsMarkers(project);
- // operation
- new JaxrsMetamodelValidator().validateAll(project, validationHelper, context, validatorManager, reporter);
- // validation
- final IMarker[] projectMarkers = project.findMarkers(JaxrsMetamodelValidator.JAXRS_PROBLEM_TYPE, false, 0);
- assertThat(projectMarkers.length, equalTo(1));
- }
-}
Added: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsResourceValidatorTestCase.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsResourceValidatorTestCase.java (rev 0)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsResourceValidatorTestCase.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -0,0 +1,156 @@
+/*******************************************************************************
+ * 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.validation;
+
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.wst.validation.ReporterHelper;
+import org.eclipse.wst.validation.internal.core.ValidationException;
+import org.eclipse.wst.validation.internal.provisional.core.IReporter;
+import org.jboss.tools.common.validation.ContextValidationHelper;
+import org.jboss.tools.common.validation.IProjectValidationContext;
+import org.jboss.tools.common.validation.ValidationErrorManager;
+import org.jboss.tools.common.validation.ValidatorManager;
+import org.jboss.tools.common.validation.internal.ProjectValidationContext;
+import org.jboss.tools.ws.jaxrs.core.WorkbenchUtils;
+import org.jboss.tools.ws.jaxrs.core.builder.AbstractMetamodelBuilderTestCase;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsBaseElement;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsResource;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsResourceMethod;
+import org.jboss.tools.ws.jaxrs.core.preferences.JaxrsPreferences;
+import org.junit.Test;
+
+/**
+ * @author Xi
+ *
+ */
+ at SuppressWarnings("restriction")
+public class JaxrsResourceValidatorTestCase extends AbstractMetamodelBuilderTestCase {
+
+ private final IReporter reporter = new ReporterHelper(new NullProgressMonitor());
+ private final ContextValidationHelper validationHelper = new ContextValidationHelper();
+ private final IProjectValidationContext context = new ProjectValidationContext();
+ private final ValidatorManager validatorManager = new ValidatorManager();
+
+ private Set<IFile> toSet(IResource resource) {
+ final Set<IFile> changedFiles = new HashSet<IFile>();
+ changedFiles.add((IFile) resource);
+ return changedFiles;
+ }
+
+ @Test
+ public void shouldValidateCustomerResourceMethod() throws CoreException, ValidationException {
+ // preconditions
+ final IType customerJavaType = WorkbenchUtils.getType(
+ "org.jboss.tools.ws.jaxrs.sample.services.CustomerResource", javaProject);
+ final JaxrsBaseElement customerResource = (JaxrsBaseElement) metamodel.getElement(customerJavaType);
+ MarkerUtils.deleteJaxrsMarkers(customerResource);
+ // operation
+ new JaxrsMetamodelValidator().validate(toSet(customerResource.getResource()), project, validationHelper,
+ context, validatorManager, reporter);
+ // validation
+ assertThat(MarkerUtils.findJaxrsMarkers(customerResource).length, equalTo(0));
+ }
+
+ @Test
+ public void shouldReportProblemsOnBarResourceMethods() throws CoreException, ValidationException {
+ // preconditions
+ final IType barJavaType = WorkbenchUtils.getType("org.jboss.tools.ws.jaxrs.sample.services.BarResource",
+ javaProject);
+ final JaxrsResource barResource = metamodel.getElement(barJavaType, JaxrsResource.class);
+ MarkerUtils.deleteJaxrsMarkers(barResource);
+ // operation
+ new JaxrsMetamodelValidator().validate(toSet(barResource.getResource()), project, validationHelper, context,
+ validatorManager, reporter);
+ // validation
+ final IMarker[] markers = MarkerUtils.findJaxrsMarkers(barResource);
+ assertThat(markers.length, equalTo(8));
+ final Map<String, JaxrsResourceMethod> resourceMethods = barResource.getMethods();
+ for (Entry<String, JaxrsResourceMethod> entry : resourceMethods.entrySet()) {
+ final IMarker[] methodMarkers = MarkerUtils.findJaxrsMarkers(entry.getValue());
+ if (entry.getKey().contains("getContent1")) {
+ assertThat(entry.getValue().hasErrors(), is(true));
+ assertThat(methodMarkers.length, equalTo(1));
+ assertThat(methodMarkers[0].getType(), equalTo(JaxrsMetamodelValidator.JAXRS_PROBLEM_TYPE));
+ assertThat(methodMarkers[0].getAttribute(ValidationErrorManager.PREFERENCE_KEY_ATTRIBUTE_NAME, ""),
+ equalTo(JaxrsPreferences.RESOURCE_METHOD_UNBOUND_PATH_ANNOTATION_TEMPLATE_PARAMETER));
+ } else if (entry.getKey().contains("getContent2")) {
+ assertThat(entry.getValue().hasErrors(), is(true));
+ assertThat(methodMarkers.length, equalTo(3));
+ } else if (entry.getKey().contains("update1")) {
+ assertThat(entry.getValue().hasErrors(), is(true));
+ assertThat(methodMarkers.length, equalTo(2));
+ } else if (entry.getKey().contains("update2")) {
+ assertThat(entry.getValue().hasErrors(), is(true));
+ assertThat(methodMarkers.length, equalTo(1));
+ } else if (entry.getKey().contains("update3")) {
+ assertThat(entry.getValue().hasErrors(), is(true));
+ assertThat(methodMarkers.length, equalTo(1));
+ } else {
+ fail("Unexpected method " + entry.getKey());
+ }
+ }
+ }
+
+ @Test
+ public void shouldReportProblemsOnBazResourceMethods() throws CoreException, ValidationException {
+ // preconditions
+ final IType barJavaType = WorkbenchUtils.getType("org.jboss.tools.ws.jaxrs.sample.services.BazResource",
+ javaProject);
+ final JaxrsResource barResource = metamodel.getElement(barJavaType, JaxrsResource.class);
+ MarkerUtils.deleteJaxrsMarkers(barResource);
+ // operation
+ new JaxrsMetamodelValidator().validate(toSet(barResource.getResource()), project, validationHelper, context,
+ validatorManager, reporter);
+ // validation
+ final IMarker[] markers = MarkerUtils.findJaxrsMarkers(barResource);
+ assertThat(markers.length, equalTo(6));
+ final Map<String, JaxrsResourceMethod> resourceMethods = barResource.getMethods();
+ for (Entry<String, JaxrsResourceMethod> entry : resourceMethods.entrySet()) {
+ final IMarker[] methodMarkers = MarkerUtils.findJaxrsMarkers(entry.getValue());
+ if (entry.getKey().contains("getContent1")) {
+ assertThat(entry.getValue().hasErrors(), is(true));
+ assertThat(methodMarkers.length, equalTo(1));
+ assertThat(methodMarkers[0].getType(), equalTo(JaxrsMetamodelValidator.JAXRS_PROBLEM_TYPE));
+ assertThat(methodMarkers[0].getAttribute(ValidationErrorManager.PREFERENCE_KEY_ATTRIBUTE_NAME, ""),
+ equalTo(JaxrsPreferences.RESOURCE_METHOD_UNBOUND_PATH_ANNOTATION_TEMPLATE_PARAMETER));
+ } else if (entry.getKey().contains("getContent2")) {
+ assertThat(entry.getValue().hasErrors(), is(true));
+ assertThat(methodMarkers.length, equalTo(2));
+ } else if (entry.getKey().contains("update1")) {
+ assertThat(entry.getValue().hasErrors(), is(true));
+ assertThat(methodMarkers.length, equalTo(2));
+ } else if (entry.getKey().contains("update2")) {
+ assertThat(entry.getValue().hasErrors(), is(false));
+ assertThat(methodMarkers.length, equalTo(0));
+ } else if (entry.getKey().contains("update3")) {
+ assertThat(entry.getValue().hasErrors(), is(true));
+ assertThat(methodMarkers.length, equalTo(1));
+ } else {
+ fail("Unexpected method " + entry.getKey());
+ }
+ }
+ }
+}
Property changes on: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsResourceValidatorTestCase.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/MarkerUtils.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/MarkerUtils.java (rev 0)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/MarkerUtils.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -0,0 +1,67 @@
+package org.jboss.tools.ws.jaxrs.core.internal.metamodel.validation;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.ISourceRange;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsBaseElement;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsResourceMethod;
+
+/**
+ * @author Xavier Coulon
+ * The class name says it all.
+ */
+public class MarkerUtils {
+
+ /**
+ * @param element
+ * @return
+ * @throws CoreException
+ */
+ public static IMarker[] findJaxrsMarkers(final JaxrsBaseElement element) throws CoreException {
+ switch (element.getElementCategory()) {
+ case HTTP_METHOD:
+ case RESOURCE:
+ return element.getResource().findMarkers(JaxrsMetamodelValidator.JAXRS_PROBLEM_TYPE, true,
+ IResource.DEPTH_INFINITE);
+ case RESOURCE_METHOD:
+ final IMarker[] markers = element.getResource().findMarkers(JaxrsMetamodelValidator.JAXRS_PROBLEM_TYPE,
+ true, IResource.DEPTH_INFINITE);
+ final List<IMarker> resourceMethodMarkers = new ArrayList<IMarker>();
+ final ISourceRange methodSourceRange = ((JaxrsResourceMethod) element).getJavaElement().getSourceRange();
+
+ for (IMarker marker : markers) {
+ final int markerCharStart = marker.getAttribute(IMarker.CHAR_START, -1);
+ if (markerCharStart >= methodSourceRange.getOffset()
+ && markerCharStart <= (methodSourceRange.getOffset() + methodSourceRange.getLength())) {
+ resourceMethodMarkers.add(marker);
+ }
+ }
+ return resourceMethodMarkers.toArray(new IMarker[resourceMethodMarkers.size()]);
+ default:
+ return new IMarker[0];
+ }
+ }
+
+ /**
+ * @param element
+ * @throws CoreException
+ */
+ public static void deleteJaxrsMarkers(final JaxrsBaseElement element) throws CoreException {
+ element.getResource()
+ .deleteMarkers(JaxrsMetamodelValidator.JAXRS_PROBLEM_TYPE, false, IResource.DEPTH_INFINITE);
+ }
+
+ /**
+ * @param element
+ * @throws CoreException
+ */
+ public static void deleteJaxrsMarkers(final IProject project) throws CoreException {
+ project.deleteMarkers(JaxrsMetamodelValidator.JAXRS_PROBLEM_TYPE, false, IResource.DEPTH_INFINITE);
+ }
+
+}
\ No newline at end of file
Property changes on: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/MarkerUtils.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/internal/utils/WtpUtilsTestCase.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/utils/WtpUtilsTestCase.java 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/utils/WtpUtilsTestCase.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -1,12 +1,14 @@
package org.jboss.tools.ws.jaxrs.core.internal.utils;
import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.jboss.tools.ws.jaxrs.core.jdt.EnumJaxrsClassname.APPLICATION;
import static org.junit.Assert.assertThat;
import org.eclipse.core.resources.IResource;
+import org.eclipse.jdt.core.ISourceRange;
import org.jboss.tools.ws.jaxrs.core.AbstractCommonTestCase;
import org.jboss.tools.ws.jaxrs.core.WorkbenchUtils;
import org.junit.Test;
@@ -35,9 +37,9 @@
@Test
public void shouldRetrieveApplicationPathFromInWeb23xml() throws Exception {
// pre-conditions
- WorkbenchUtils.replaceDeploymentDescriptorWith(javaProject, "web-2_3-with-servlet-mapping.xml", bundle);
+ final IResource webxmlResource = WorkbenchUtils.replaceDeploymentDescriptorWith(javaProject, "web-2_3-with-default-servlet-mapping.xml", bundle);
// operation
- final String applicationPath = WtpUtils.getApplicationPath(project, APPLICATION.qualifiedName);
+ final String applicationPath = WtpUtils.getApplicationPath(webxmlResource, APPLICATION.qualifiedName);
// verifications
assertThat(applicationPath, equalTo("/hello/*"));
}
@@ -45,9 +47,9 @@
@Test
public void shouldNotRetrieveApplicationPathInWeb23xml() throws Exception {
// pre-conditions
- WorkbenchUtils.replaceDeploymentDescriptorWith(javaProject, "web-2_3-without-servlet-mapping.xml", bundle);
+ final IResource webxmlResource = WorkbenchUtils.replaceDeploymentDescriptorWith(javaProject, "web-2_3-without-servlet-mapping.xml", bundle);
// operation
- final String applicationPath = WtpUtils.getApplicationPath(project, APPLICATION.qualifiedName);
+ final String applicationPath = WtpUtils.getApplicationPath(webxmlResource, APPLICATION.qualifiedName);
// verifications
assertThat(applicationPath, nullValue());
}
@@ -55,72 +57,146 @@
@Test
public void shouldRetrieveApplicationPathInWeb24xml() throws Exception {
// pre-conditions
- WorkbenchUtils.replaceDeploymentDescriptorWith(javaProject, "web-2_4-with-servlet-mapping.xml", bundle);
+ final IResource webxmlResource = WorkbenchUtils.replaceDeploymentDescriptorWith(javaProject, "web-2_4-with-default-servlet-mapping.xml", bundle);
// operation
- final String applicationPath = WtpUtils.getApplicationPath(project, APPLICATION.qualifiedName);
+ final String applicationPath = WtpUtils.getApplicationPath(webxmlResource, APPLICATION.qualifiedName);
// verifications
assertThat(applicationPath, equalTo("/hello/*"));
}
@Test
+ public void shouldRetrieveApplicationPathLocationInWeb24xml() throws Exception {
+ // pre-conditions
+ final IResource webxmlResource = WorkbenchUtils.replaceDeploymentDescriptorWith(javaProject, "web-2_4-with-default-servlet-mapping.xml", bundle);
+ // operation
+ final ISourceRange location = WtpUtils.getApplicationPathLocation(webxmlResource, APPLICATION.qualifiedName);
+ // verifications
+ assertThat(location.getOffset(), not(equalTo(0)));
+ assertThat(location.getLength(), not(equalTo(0)));
+ }
+
+ @Test
public void shouldNotRetrieveApplicationPathInWeb24xml() throws Exception {
// pre-conditions
- WorkbenchUtils.replaceDeploymentDescriptorWith(javaProject, "web-2_4-without-servlet-mapping.xml", bundle);
+ final IResource webxmlResource = WorkbenchUtils.replaceDeploymentDescriptorWith(javaProject, "web-2_4-without-servlet-mapping.xml", bundle);
// operation
- final String applicationPath = WtpUtils.getApplicationPath(project, APPLICATION.qualifiedName);
+ final String applicationPath = WtpUtils.getApplicationPath(webxmlResource, APPLICATION.qualifiedName);
// verifications
assertThat(applicationPath, nullValue());
}
+
+ @Test
+ public void shouldNotRetrieveApplicationPathLocationInWeb24xml() throws Exception {
+ // pre-conditions
+ final IResource webxmlResource = WorkbenchUtils.replaceDeploymentDescriptorWith(javaProject, "web-2_4-without-servlet-mapping.xml", bundle);
+ // operation
+ final ISourceRange location = WtpUtils.getApplicationPathLocation(webxmlResource, APPLICATION.qualifiedName);
+ // verifications
+ assertThat(location, nullValue());
+ }
@Test
public void shouldRetrieveApplicationPathInWeb25xml() throws Exception {
// pre-conditions
- WorkbenchUtils.replaceDeploymentDescriptorWith(javaProject, "web-2_5-with-servlet-mapping.xml", bundle);
+ final IResource webxmlResource = WorkbenchUtils.replaceDeploymentDescriptorWith(javaProject, "web-2_5-with-default-servlet-mapping.xml", bundle);
// operation
- final String applicationPath = WtpUtils.getApplicationPath(project, APPLICATION.qualifiedName);
+ final String applicationPath = WtpUtils.getApplicationPath(webxmlResource, APPLICATION.qualifiedName);
// verifications
assertThat(applicationPath, equalTo("/hello/*"));
}
@Test
+ public void shouldRetrieveApplicationPathLocationInWeb25xml() throws Exception {
+ // pre-conditions
+ final IResource webxmlResource = WorkbenchUtils.replaceDeploymentDescriptorWith(javaProject, "web-2_5-with-default-servlet-mapping.xml", bundle);
+ // operation
+ final ISourceRange location = WtpUtils.getApplicationPathLocation(webxmlResource, APPLICATION.qualifiedName);
+ // verifications
+ assertThat(location.getOffset(), not(equalTo(0)));
+ assertThat(location.getLength(), not(equalTo(0)));
+ }
+
+ @Test
public void shouldNotRetrieveApplicationPathInWeb25xml() throws Exception {
// pre-conditions
- WorkbenchUtils.replaceDeploymentDescriptorWith(javaProject, "web-2_5-without-servlet-mapping.xml", bundle);
+ final IResource webxmlResource = WorkbenchUtils.replaceDeploymentDescriptorWith(javaProject, "web-2_5-without-servlet-mapping.xml", bundle);
// operation
- final String applicationPath = WtpUtils.getApplicationPath(project, APPLICATION.qualifiedName);
+ final String applicationPath = WtpUtils.getApplicationPath(webxmlResource, APPLICATION.qualifiedName);
// verifications
assertThat(applicationPath, nullValue());
}
@Test
+ public void shouldNotRetrieveApplicationPathLocationInWeb25xml() throws Exception {
+ // pre-conditions
+ final IResource webxmlResource = WorkbenchUtils.replaceDeploymentDescriptorWith(javaProject, "web-2_5-without-servlet-mapping.xml", bundle);
+ // operation
+ final ISourceRange location = WtpUtils.getApplicationPathLocation(webxmlResource, APPLICATION.qualifiedName);
+ // verifications
+ assertThat(location, nullValue());
+ }
+
+ @Test
public void shouldRetrieveApplicationPathInWeb30xml() throws Exception {
// pre-conditions
- WorkbenchUtils.replaceDeploymentDescriptorWith(javaProject, "web-3_0-with-servlet-mapping.xml", bundle);
+ final IResource webxmlResource = WorkbenchUtils.replaceDeploymentDescriptorWith(javaProject, "web-3_0-with-default-servlet-mapping.xml", bundle);
// operation
- final String applicationPath = WtpUtils.getApplicationPath(project, APPLICATION.qualifiedName);
+ final String applicationPath = WtpUtils.getApplicationPath(webxmlResource, APPLICATION.qualifiedName);
// verifications
assertThat(applicationPath, equalTo("/hello/*"));
}
@Test
+ public void shouldRetrieveApplicationPathLocationInWeb30xml() throws Exception {
+ // pre-conditions
+ final IResource webxmlResource = WorkbenchUtils.replaceDeploymentDescriptorWith(javaProject, "web-3_0-with-default-servlet-mapping.xml", bundle);
+ // operation
+ final ISourceRange location = WtpUtils.getApplicationPathLocation(webxmlResource, APPLICATION.qualifiedName);
+ // verifications
+ assertThat(location.getOffset(), not(equalTo(0)));
+ assertThat(location.getLength(), not(equalTo(0)));
+ }
+
+ @Test
public void shouldNotRetrieveApplicationPathInWeb30xml() throws Exception {
// pre-conditions
- WorkbenchUtils.replaceDeploymentDescriptorWith(javaProject, "web-3_0-without-servlet-mapping.xml", bundle);
+ final IResource webxmlResource = WorkbenchUtils.replaceDeploymentDescriptorWith(javaProject, "web-3_0-without-servlet-mapping.xml", bundle);
// operation
- final String applicationPath = WtpUtils.getApplicationPath(project, APPLICATION.qualifiedName);
+ final String applicationPath = WtpUtils.getApplicationPath(webxmlResource, APPLICATION.qualifiedName);
// verifications
assertThat(applicationPath, nullValue());
}
@Test
+ public void shouldNotRetrieveApplicationPathLocationInWeb30xml() throws Exception {
+ // pre-conditions
+ final IResource webxmlResource = WorkbenchUtils.replaceDeploymentDescriptorWith(javaProject, "web-3_0-without-servlet-mapping.xml", bundle);
+ // operation
+ final ISourceRange location = WtpUtils.getApplicationPathLocation(webxmlResource, APPLICATION.qualifiedName);
+ // verifications
+ assertThat(location, nullValue());
+ }
+
+ @Test
public void shouldNotRetrieveApplicationPathWhenWebXmlMissing() throws Exception {
// pre-conditions
- WorkbenchUtils.replaceDeploymentDescriptorWith(javaProject, null, bundle);
+ final IResource webxmlResource = WorkbenchUtils.replaceDeploymentDescriptorWith(javaProject, null, bundle);
// operation
- final String applicationPath = WtpUtils.getApplicationPath(project, APPLICATION.qualifiedName);
+ final String applicationPath = WtpUtils.getApplicationPath(webxmlResource, APPLICATION.qualifiedName);
// verifications
assertThat(applicationPath, nullValue());
}
+ @Test
+ public void shouldNotRetrieveApplicationPathLocationWhenWebxmlMissing() throws Exception {
+ // pre-conditions
+ final IResource webxmlResource = WorkbenchUtils.replaceDeploymentDescriptorWith(javaProject, null, bundle);
+ // operation
+ final ISourceRange location = WtpUtils.getApplicationPathLocation(webxmlResource, APPLICATION.qualifiedName);
+ // verifications
+ assertThat(location, nullValue());
+ }
+
+
}
Modified: 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 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/jdt/JaxrsAnnotationScannerTestCase.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -10,8 +10,10 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.IType;
import org.jboss.tools.ws.jaxrs.core.AbstractCommonTestCase;
+import org.jboss.tools.ws.jaxrs.core.WorkbenchUtils;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsHttpMethod;
import org.junit.Ignore;
import org.junit.Test;
@@ -114,7 +116,7 @@
}
@Test
- public void shouldRetrieveOneApplicationsInType() throws CoreException {
+ public void shouldRetrieveOneApplicationInType() throws CoreException {
// pre-conditions
IType restType = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication", javaProject, null);
assertThat(restType, notNullValue());
@@ -126,8 +128,62 @@
}
@Test
- public void shouldNotRetrieveApplicationsInOtherType() throws CoreException {
+ public void shouldRetrieveOneApplicationWithSupertypeOnlyOnScopeType() throws CoreException {
// pre-conditions
+ IType restType = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication", javaProject, null);
+ assertThat(restType, notNullValue());
+ WorkbenchUtils.replaceFirstOccurrenceOfCode(restType.getCompilationUnit(), "@ApplicationPath(\"/app\")", "", false);
+ // operation
+ final List<IType> applications = JaxrsAnnotationsScanner.findApplicationTypes(restType,
+ new NullProgressMonitor());
+ // verifications
+ assertThat(applications.size(), equalTo(1));
+ }
+
+ @Test
+ public void shouldRetrieveOneApplicationWithSupertypeOnlyOnScopeProject() throws CoreException {
+ // pre-conditions
+ IType restType = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication", javaProject, null);
+ assertThat(restType, notNullValue());
+ WorkbenchUtils.replaceFirstOccurrenceOfCode(restType.getCompilationUnit(), "@ApplicationPath(\"/app\")", "", false);
+ // operation
+ final List<IType> applications = JaxrsAnnotationsScanner.findApplicationTypes(restType.getJavaProject(),
+ new NullProgressMonitor());
+ // verifications
+ assertThat(applications.size(), equalTo(1));
+ }
+
+ @Test
+ public void shouldRetrieveOneApplicationWithAnnotationOnly() throws CoreException {
+ // pre-conditions
+ IType restType = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication", javaProject, null);
+ assertThat(restType, notNullValue());
+ WorkbenchUtils.replaceFirstOccurrenceOfCode(restType.getCompilationUnit(), "extends Application", "", false);
+ // operation
+ final List<IType> applications = JaxrsAnnotationsScanner.findApplicationTypes(restType,
+ new NullProgressMonitor());
+ // verifications
+ assertThat(applications.size(), equalTo(1));
+ }
+
+ @Test
+ public void shouldNotRetrieveApplicationsWithSupertypeOnlyOnScopeLibrary() throws CoreException {
+ // pre-conditions
+ final IPackageFragmentRoot lib = WorkbenchUtils.getPackageFragmentRoot(javaProject,
+ "lib/jaxrs-api-2.0.1.GA.jar", new NullProgressMonitor());
+ IType restType = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.RestApplication", javaProject, null);
+ assertThat(restType, notNullValue());
+ WorkbenchUtils.replaceFirstOccurrenceOfCode(restType.getCompilationUnit(), "@ApplicationPath(\"/app\")", "", false);
+ // operation
+ final List<IType> applications = JaxrsAnnotationsScanner.findApplicationTypes(lib,
+ new NullProgressMonitor());
+ // verifications
+ assertThat(applications.size(), equalTo(0));
+ }
+
+ @Test
+ public void shouldNotRetrieveApplicationsOnScopeOtherType() throws CoreException {
+ // pre-conditions
IType fooType = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.FOO", javaProject, null);
assertThat(fooType, notNullValue());
// operation
Modified: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/jdt/JdtUtilsTestCase.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/jdt/JdtUtilsTestCase.java 2012-09-21 19:42:40 UTC (rev 43939)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/jdt/JdtUtilsTestCase.java 2012-09-21 21:39:42 UTC (rev 43940)
@@ -45,6 +45,7 @@
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.ISourceRange;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.ITypeHierarchy;
@@ -72,113 +73,169 @@
@Test
public void shouldResolveTypeByQNameInSourceCode() throws CoreException {
- Assert.assertNotNull("Type not found", JdtUtils.resolveType(
+ // preconditions
+ // operation
+ final IType type = JdtUtils.resolveType(
"org.jboss.tools.ws.jaxrs.sample.services.providers.EntityNotFoundExceptionMapper", javaProject,
- new NullProgressMonitor()));
+ new NullProgressMonitor());
+ // verification
+ Assert.assertNotNull("Type not found", type);
}
@Test
public void shouldResolveTypeByQNameInLibrary() throws CoreException {
- Assert.assertNotNull("Type not found",
- JdtUtils.resolveType("javax.persistence.PersistenceException", javaProject, new NullProgressMonitor()));
+ // preconditions
+ // operation
+ final IType type = JdtUtils.resolveType("javax.persistence.PersistenceException", javaProject,
+ new NullProgressMonitor());
+ // verification
+ Assert.assertNotNull("Type not found", type);
}
@Test
public void shouldNotResolveTypeByUnknownQName() throws CoreException {
+ // preconditions
+ // operation
+ final IType type = JdtUtils.resolveType("unknown.class", javaProject, new NullProgressMonitor());
+ // verification
Assert.assertNull("No Type expected",
- JdtUtils.resolveType("unknown.class", javaProject, new NullProgressMonitor()));
+ type);
}
@Test
public void shouldResolveTypeByVeryQName() throws CoreException {
- Assert.assertNotNull("Type not found", JdtUtils.resolveType(
+ // preconditions
+ // operation
+ final IType type = JdtUtils.resolveType(
"org.jboss.tools.ws.jaxrs.sample.extra.TestQualifiedException.TestException", javaProject,
- new NullProgressMonitor()));
+ new NullProgressMonitor());
+ // verification
+ Assert.assertNotNull("Type not found", type);
}
@Test
public void shouldAssertTypeIsAbstract() throws CoreException {
+ // preconditions
+ // operation
IType type = JdtUtils.resolveType("org.jboss.resteasy.plugins.providers.AbstractEntityProvider", javaProject,
new NullProgressMonitor());
+ // verification
Assert.assertNotNull("Type not found", type);
Assert.assertTrue("Type is abstract", JdtUtils.isAbstractType(type));
}
@Test
public void shouldNotAssertTypeIsAbstract() throws CoreException {
+ // preconditions
+ // operation
IType type = JdtUtils.resolveType(
"org.jboss.tools.ws.jaxrs.sample.services.providers.EntityNotFoundExceptionMapper", javaProject,
new NullProgressMonitor());
+ // verification
Assert.assertNotNull("Type not found", type);
Assert.assertFalse("Type is not abstract", JdtUtils.isAbstractType(type));
}
@Test
public void shouldNotResolveTypeWithNullQName() throws CoreException {
+ // preconditions
+ // operation
IType type = JdtUtils.resolveType(null, javaProject, new NullProgressMonitor());
+ // verification
Assert.assertNull("No type was expected", type);
}
@Test
- public void shouldResolveTypeHierarchyFromClass() throws CoreException {
+ public void shouldResolveTypeHierarchyOnClass() throws CoreException {
+ // preconditions
+ // operation
IType type = JdtUtils.resolveType(
"org.jboss.tools.ws.jaxrs.sample.services.providers.EntityNotFoundExceptionMapper", javaProject,
new NullProgressMonitor());
+ // verification
Assert.assertNotNull("Type not found", type);
Assert.assertNotNull("Type hierarchy not found",
- JdtUtils.resolveTypeHierarchy(type, false, new NullProgressMonitor()));
+ JdtUtils.resolveTypeHierarchy(type, type.getJavaProject(), false, new NullProgressMonitor()));
}
@Test
- public void shouldResolveTypeHierarchyFromInterface() throws CoreException {
+ public void shouldResolveTypeHierarchyOnInterface() throws CoreException {
+ // preconditions
+ // operation
IType type = JdtUtils.resolveType("javax.ws.rs.ext.MessageBodyReader", javaProject, new NullProgressMonitor());
+ // verification
Assert.assertNotNull("Type not found", type);
Assert.assertNotNull("Type hierarchy not found",
- JdtUtils.resolveTypeHierarchy(type, false, new NullProgressMonitor()));
+ JdtUtils.resolveTypeHierarchy(type, type.getJavaProject(), false, new NullProgressMonitor()));
}
@Test
- public void shouldResolveTypeHierarchyWithLibraries() throws CoreException {
- IType type = JdtUtils.resolveType("javax.ws.rs.ext.MessageBodyReader", javaProject, new NullProgressMonitor());
+ public void shouldResolveTypeHierarchyOnLibrariesWithSubclasses() throws CoreException {
+ // preconditions
+ IType type = JdtUtils.resolveType("javax.ws.rs.core.Application", javaProject, new NullProgressMonitor());
Assert.assertNotNull("Type not found", type);
- Assert.assertNotNull("Type hierarchy not found",
- JdtUtils.resolveTypeHierarchy(type, true, new NullProgressMonitor()));
+ // operation
+ final ITypeHierarchy hierarchy = JdtUtils.resolveTypeHierarchy(type, type.getJavaProject(), true, new NullProgressMonitor());
+ // verifications
+ Assert.assertNotNull("Type hierarchy not found", hierarchy);
+ Assert.assertEquals("Type hierarchy incomplete", 1, hierarchy.getSubtypes(type).length);
}
@Test
- public void shouldNotResolveTypeHierarchyOfRemovedClass() throws CoreException {
+ public void shouldResolveTypeHierarchyOnLibrariesWithNoSubclass() throws CoreException {
+ // preconditions
+ IType type = JdtUtils.resolveType("javax.ws.rs.core.Application", javaProject, new NullProgressMonitor());
+ Assert.assertNotNull("Type not found", type);
+ final IPackageFragmentRoot lib = WorkbenchUtils.getPackageFragmentRoot(javaProject,
+ "lib/jaxrs-api-2.0.1.GA.jar", new NullProgressMonitor());
+ Assert.assertNotNull("Lib not found", lib);
+ // operation
+ final ITypeHierarchy hierarchy = JdtUtils.resolveTypeHierarchy(type, lib, true, new NullProgressMonitor());
+ // verifications
+ Assert.assertNotNull("Type hierarchy not found", hierarchy);
+ Assert.assertEquals("Type hierarchy incomplete", 0, hierarchy.getSubtypes(type).length);
+ }
+
+ @Test
+ public void shouldNotResolveTypeHierarchyOnRemovedClass() throws CoreException {
+ // preconditions
IType type = JdtUtils.resolveType(
"org.jboss.tools.ws.jaxrs.sample.services.providers.EntityNotFoundExceptionMapper", javaProject,
new NullProgressMonitor());
Assert.assertNotNull("Type not found", type);
+ // operation
type.delete(true, new NullProgressMonitor());
- Assert.assertNull("No Type hierarchy expected",
- JdtUtils.resolveTypeHierarchy(type, false, new NullProgressMonitor()));
+ final ITypeHierarchy hierarchy = JdtUtils.resolveTypeHierarchy(type, type.getJavaProject(), false, new NullProgressMonitor());
+ // verification
+ Assert.assertNull("No Type hierarchy expected", hierarchy);
}
@Test
public void shouldResolveConcreteTypeArgumentsOnBinaryTypesWithoutSources() throws CoreException,
OperationCanceledException, InterruptedException {
-
+ // preconditions
IType parameterizedType = JdtUtils.resolveType("org.jboss.resteasy.plugins.providers.jaxb.CollectionProvider",
javaProject, progressMonitor);
Assert.assertNotNull("Parameterized Type not found", parameterizedType);
IType matchSuperInterfaceType = JdtUtils.resolveType("javax.ws.rs.ext.MessageBodyReader", javaProject,
progressMonitor);
Assert.assertNotNull("Interface Type not found", matchSuperInterfaceType);
- ITypeHierarchy parameterizedTypeHierarchy = JdtUtils.resolveTypeHierarchy(parameterizedType, false,
+ ITypeHierarchy parameterizedTypeHierarchy = JdtUtils.resolveTypeHierarchy(parameterizedType, parameterizedType.getJavaProject(), false,
progressMonitor);
boolean removedReferencedLibrarySourceAttachment = WorkbenchUtils.removeReferencedLibrarySourceAttachment(
javaProject, "resteasy-jaxb-provider-2.0.1.GA.jar", progressMonitor);
Assert.assertTrue("Source attachment was not removed (not found?)", removedReferencedLibrarySourceAttachment);
+ // operation
CompilationUnit compilationUnit = JdtUtils.parse(parameterizedType, null);
List<IType> resolvedTypeParameters = JdtUtils.resolveTypeArguments(parameterizedType, compilationUnit,
matchSuperInterfaceType, parameterizedTypeHierarchy, progressMonitor);
+ // verification
Assert.assertNull("No type parameters expected", resolvedTypeParameters);
}
@Test
public void shouldNotResolveTypeArgumentsOnBinaryImplementation() throws CoreException {
+ // preconditions
IType parameterizedType = JdtUtils.resolveType(
"org.jboss.resteasy.plugins.providers.jaxb.AbstractJAXBProvider", javaProject,
new NullProgressMonitor());
@@ -186,16 +243,19 @@
IType matchGenericType = JdtUtils.resolveType("org.jboss.resteasy.plugins.providers.AbstractEntityProvider",
javaProject, new NullProgressMonitor());
Assert.assertNotNull("Interface Type not found", matchGenericType);
- ITypeHierarchy parameterizedTypeHierarchy = JdtUtils.resolveTypeHierarchy(parameterizedType, false,
+ // operation
+ ITypeHierarchy parameterizedTypeHierarchy = JdtUtils.resolveTypeHierarchy(parameterizedType, parameterizedType.getJavaProject(), false,
new NullProgressMonitor());
CompilationUnit compilationUnit = JdtUtils.parse(parameterizedType, null);
List<IType> resolvedTypeParameters = JdtUtils.resolveTypeArguments(parameterizedType, compilationUnit,
matchGenericType, parameterizedTypeHierarchy, new NullProgressMonitor());
+ // verification
Assert.assertNull("No type parameters expected", resolvedTypeParameters);
}
@Test
public void shouldResolveMultipleConcreteTypeArgumentsOnSourceImplementation() throws CoreException {
+ // preconditions
IType parameterizedType = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.extra.AnotherDummyProvider",
javaProject, new NullProgressMonitor());
Assert.assertNotNull("Parameterized Type not found", parameterizedType);
@@ -205,7 +265,7 @@
new NullProgressMonitor());
Assert.assertNotNull("Interface Type not found", matchGenericType);
CompilationUnit compilationUnit = JdtUtils.parse(parameterizedType, null);
- ITypeHierarchy parameterizedTypeHierarchy = JdtUtils.resolveTypeHierarchy(parameterizedType, false,
+ ITypeHierarchy parameterizedTypeHierarchy = JdtUtils.resolveTypeHierarchy(parameterizedType, parameterizedType.getJavaProject(), false,
new NullProgressMonitor());
List<IType> resolvedTypeParameters = JdtUtils.resolveTypeArguments(parameterizedType, compilationUnit,
@@ -238,83 +298,118 @@
@Test
public void shouldNotResolveTypeArgumentsOnWrongHierarchy() throws CoreException {
+ // preconditions
IType parameterizedType = JdtUtils.resolveType("org.jboss.resteasy.plugins.providers.jaxb.CollectionProvider",
javaProject, new NullProgressMonitor());
IType unrelatedType = JdtUtils.resolveType("javax.ws.rs.ext.ExceptionMapper", javaProject,
new NullProgressMonitor());
-
Assert.assertNotNull("Parameterized Type not found", parameterizedType);
+ // operation
IType matchSuperInterfaceType = JdtUtils.resolveType("javax.ws.rs.ext.MessageBodyReader", javaProject,
new NullProgressMonitor());
+ // verification
Assert.assertNotNull("Interface Type not found", matchSuperInterfaceType);
- ITypeHierarchy unrelatedTypeHierarchy = JdtUtils.resolveTypeHierarchy(unrelatedType, false,
+ // operation
+ ITypeHierarchy unrelatedTypeHierarchy = JdtUtils.resolveTypeHierarchy(unrelatedType, unrelatedType.getJavaProject(), false,
new NullProgressMonitor());
CompilationUnit compilationUnit = JdtUtils.parse(parameterizedType, null);
- Assert.assertNull(JdtUtils.resolveTypeArguments(parameterizedType, compilationUnit, matchSuperInterfaceType,
- unrelatedTypeHierarchy, new NullProgressMonitor()));
+ final List<IType> typeArgs = JdtUtils.resolveTypeArguments(parameterizedType, compilationUnit, matchSuperInterfaceType,
+ unrelatedTypeHierarchy, new NullProgressMonitor());
+ // verification
+ Assert.assertNull(typeArgs);
}
@Test
public void shouldResolveTopLevelTypeFromSourceType() throws JavaModelException, CoreException {
-
+ // preconditions
IType resourceType = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject, progressMonitor);
Assert.assertNotNull("ResourceType not found", resourceType);
- Assert.assertNotNull("Type not found", JdtUtils.resolveTopLevelType(resourceType.getCompilationUnit()));
+ // operation
+ final IType topLevelType = JdtUtils.resolveTopLevelType(resourceType.getCompilationUnit());
+ // verification
+ Assert.assertNotNull("Type not found", topLevelType);
}
@Test
public void shouldNotResolveTopLevelTypeOnBinaryType() throws JavaModelException, CoreException {
-
+ // preconditions
IType resourceType = JdtUtils.resolveType("org.jboss.resteasy.plugins.providers.jaxb.CollectionProvider",
javaProject, progressMonitor);
Assert.assertNotNull("ResourceType not found", resourceType);
- Assert.assertNull("Type not found", JdtUtils.resolveTopLevelType(resourceType.getCompilationUnit()));
+ // operation
+ final IType topLevelType = JdtUtils.resolveTopLevelType(resourceType.getCompilationUnit());
+ // verification
+ Assert.assertNull("Type not found", topLevelType);
}
@Test
public void shouldGetTopLevelTypeOKNoneInSourceType() throws JavaModelException, CoreException {
+ // preconditions
ICompilationUnit compilationUnit = WorkbenchUtils.createCompilationUnit(javaProject, "Empty.txt",
"org.jboss.tools.ws.jaxrs.sample", "PersistenceExceptionMapper.java", bundle);
Assert.assertNotNull("Resource not found", compilationUnit);
- Assert.assertNull("Type not expected", JdtUtils.resolveTopLevelType(compilationUnit));
+ // operation
+ final IType topLevelType = JdtUtils.resolveTopLevelType(compilationUnit);
+ // verification
+ Assert.assertNull("Type not expected", topLevelType);
}
@Test
public void shouldResolveTopLevelTypeOnSourceWithMultipleTypes() throws JavaModelException, CoreException {
+ // preconditions
ICompilationUnit compilationUnit = WorkbenchUtils.createCompilationUnit(javaProject, "Multi.txt",
"org.jboss.tools.ws.jaxrs.sample", "PersistenceExceptionMapper.java", bundle);
Assert.assertNotNull("Resource not found", compilationUnit);
- Assert.assertNotNull("Type not found", JdtUtils.resolveTopLevelType(compilationUnit));
+ // operation
+ final IType topLevelType = JdtUtils.resolveTopLevelType(compilationUnit);
+ // verification
+ Assert.assertNotNull("Type not found", topLevelType);
}
@Test
public void shouldReturnTrueOnTopLevelTypeDetection() throws JavaModelException, CoreException {
+ // preconditions
IType resourceType = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource",
javaProject, progressMonitor);
Assert.assertNotNull("ResourceType not found", resourceType);
- Assert.assertTrue("Wrong result", JdtUtils.isTopLevelType(resourceType));
+ // operation
+ final boolean isTopLevelType = JdtUtils.isTopLevelType(resourceType);
+ // verification
+ Assert.assertTrue("Wrong result", isTopLevelType);
}
@Test
public void shouldGetCompiltationUnitFromType() throws CoreException {
+ // preconditions
IResource resource = project
.findMember("src/main/java/org/jboss/tools/ws/jaxrs/sample/services/BookResource.java");
Assert.assertNotNull("Resource not found", resource);
- Assert.assertNotNull("CompilationUnit not found", JdtUtils.getCompilationUnit(resource));
+ // operation
+ final ICompilationUnit compilationUnit = JdtUtils.getCompilationUnit(resource);
+ // verification
+ Assert.assertNotNull("CompilationUnit not found", compilationUnit);
}
@Test
public void shouldGetCompiltationUnitFromProject() {
+ // preconditions
IResource resource = project.findMember("src/main/resources/log4j.xml");
Assert.assertNotNull("Resource not found", resource);
- Assert.assertNull("CompilationUnit not expected", JdtUtils.getCompilationUnit(resource));
+ // operation
+ final ICompilationUnit compilationUnit = JdtUtils.getCompilationUnit(resource);
+ // verification
+ Assert.assertNull("CompilationUnit not expected", compilationUnit);
}
@Test
public void shoudNotParseNullMember() throws CoreException {
- Assert.assertNull(JdtUtils.parse((IMember) null, progressMonitor));
+ // preconditions
+ // operation
+ final CompilationUnit compilationUnit = JdtUtils.parse((IMember) null, progressMonitor);
+ // verifications
+ Assert.assertNull(compilationUnit);
}
@Test
@@ -445,6 +540,7 @@
@Test
public void shouldResolveJavaMethodSignatures() throws CoreException {
+ // preconditions
final IType type = getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
// operation
final List<JavaMethodSignature> methodSignatures = JdtUtils.resolveMethodSignatures(type,
@@ -471,6 +567,7 @@
@Test
public void shouldResolveJavaMethodSignaturesForParameterizedType() throws CoreException {
+ // preconditions
final IType type = getType("org.jboss.tools.ws.jaxrs.sample.services.ParameterizedResource");
// operation
final List<JavaMethodSignature> methodSignatures = JdtUtils.resolveMethodSignatures(type,
@@ -481,6 +578,7 @@
@Test
public void shouldResolveJavaMethodSignature() throws CoreException {
+ // preconditions
final IType type = getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
final IMethod method = getMethod(type, "getCustomers");
// operation
@@ -504,6 +602,7 @@
@Test
public void shouldConfirmSuperType() throws CoreException {
+ // preconditions
final IType bookType = getType("org.jboss.tools.ws.jaxrs.sample.services.BookResource");
final IType objectType = getType(Object.class.getName());
assertThat(JdtUtils.isTypeOrSuperType(objectType, bookType), is(true));
@@ -511,6 +610,7 @@
@Test
public void shouldConfirmSuperTypeWhenSameType() throws CoreException {
+ // preconditions
final IType subType = getType("org.jboss.tools.ws.jaxrs.sample.services.BookResource");
final IType superType = getType("org.jboss.tools.ws.jaxrs.sample.services.BookResource");
assertThat(JdtUtils.isTypeOrSuperType(superType, subType), is(true));
@@ -518,6 +618,7 @@
@Test
public void shouldNotConfirmSuperType() throws CoreException {
+ // preconditions
final IType bookType = getType("org.jboss.tools.ws.jaxrs.sample.services.BookResource");
final IType objectType = getType(RESPONSE.qualifiedName);
assertThat(JdtUtils.isTypeOrSuperType(objectType, bookType), is(false));
More information about the jbosstools-commits
mailing list