JBoss Tools SVN: r31892 - in trunk/ws: plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel and 4 other directories.
by jbosstools-commits@lists.jboss.org
Author: xcoulon
Date: 2011-06-07 18:25:07 -0400 (Tue, 07 Jun 2011)
New Revision: 31892
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/CollectionFilterUtils.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/ObjectUtils.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/EnumElementChange.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMapping.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMethodMapping.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMethodNode.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Route.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/RouteEndpoint.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Routes.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/icons/systemprocess.gif
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/WaitWhileBuildingElement.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/metamodel/
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/metamodel/MediaTypeCapabilitiesTestCase.java
Log:
Added missing files...
Added: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/CollectionFilterUtils.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/CollectionFilterUtils.java (rev 0)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/CollectionFilterUtils.java 2011-06-07 22:25:07 UTC (rev 31892)
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * 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.utils;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.jdt.core.IMember;
+import org.jboss.tools.ws.jaxrs.core.metamodel.BaseElement;
+import org.jboss.tools.ws.jaxrs.core.metamodel.BaseElement.EnumKind;
+
+/**
+ * Collection filter utility class.
+ * @author xcoulon
+ *
+ */
+public final class CollectionFilterUtils {
+
+ /**
+ * Private constructor of the utility class.
+ */
+ private CollectionFilterUtils() {
+
+ }
+
+ /**
+ * Filter elements in the given collection, given their JAX-RS kind.
+ * @param <T> the java type of the elements in the collection
+ * @param elements > the collection of elements to filter
+ * @param kind the JAX-RS kind to match in the filter
+ * @return the matching elements
+ */
+ public static <T extends BaseElement<? extends IMember>> List<T> filterElementsByKind(final Collection<T> elements,
+ final BaseElement.EnumKind... kind) {
+ List<T> matches = new ArrayList<T>();
+ List<EnumKind> kinds = Arrays.asList(kind);
+ for (T element : elements) {
+ if (kinds.contains(element.getKind())) {
+ matches.add(element);
+ }
+ }
+ return Collections.unmodifiableList(matches);
+ }
+
+}
Added: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/ObjectUtils.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/ObjectUtils.java (rev 0)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/ObjectUtils.java 2011-06-07 22:25:07 UTC (rev 31892)
@@ -0,0 +1,20 @@
+package org.jboss.tools.ws.jaxrs.core.internal.utils;
+
+public class ObjectUtils {
+
+ private ObjectUtils() {
+
+ }
+
+ /**
+ * @param nextHTTPMethod
+ * @return
+ */
+ public static boolean compare(Object o1, Object o2) {
+ if ((o1 != null && !o1.equals(o2)) || (o2 != null && !o2.equals(o1))) {
+ Logger.debug(" Value changed: " + o1 + " -> " + o2);
+ return true;
+ }
+ return false;
+ }
+}
Added: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/EnumElementChange.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/EnumElementChange.java (rev 0)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/EnumElementChange.java 2011-06-07 22:25:07 UTC (rev 31892)
@@ -0,0 +1,7 @@
+package org.jboss.tools.ws.jaxrs.core.metamodel;
+
+public enum EnumElementChange {
+
+ NONE, KIND, MAPPING;
+
+}
Added: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMapping.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMapping.java (rev 0)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMapping.java 2011-06-07 22:25:07 UTC (rev 31892)
@@ -0,0 +1,174 @@
+package org.jboss.tools.ws.jaxrs.core.metamodel;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.jboss.tools.ws.jaxrs.core.internal.builder.JAXRSAnnotationsScanner;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.ObjectUtils;
+import org.jboss.tools.ws.jaxrs.core.utils.JdtUtils;
+import org.jboss.tools.ws.jaxrs.core.utils.ResourceMethodAnnotatedParameter;
+
+public class ResourceMapping {
+
+ private final Resource resource;
+
+ /**
+ * the default consumed media type capabilities offered by this resource.
+ * May be overridden at method level
+ */
+ private final MediaTypeCapabilities consumedMediaTypes;
+
+ /**
+ * the default produced media type capabilities offered by this resource.
+ * May be overridden at method level
+ */
+ private final MediaTypeCapabilities producedMediaTypes;
+
+ /**
+ * The URI Path Template Fragment resolve from the type-level
+ * <code>javax.ws.rs.Path</code> annotation.
+ */
+ private String uriPathTemplateFragment = null;
+
+ private final List<ResourceMethodAnnotatedParameter> pathParams = null;
+
+ private final List<ResourceMethodAnnotatedParameter> queryParams = null;
+
+ /**
+ * Full constructor using the inner 'MediaTypeCapabilitiesBuilder' static
+ * class.
+ *
+ * @param builder
+ */
+ public ResourceMapping(final Resource resource) {
+ this.resource = resource;
+ this.consumedMediaTypes = new MediaTypeCapabilities(resource.getJavaElement());
+ this.producedMediaTypes = new MediaTypeCapabilities(resource.getJavaElement());
+ }
+
+ /**
+ * @return the resourceMethod
+ */
+ public Resource getResource() {
+ return resource;
+ }
+
+ /**
+ * @param javaMethod
+ * @param compilationUnit
+ * @throws JavaModelException
+ * @throws CoreException
+ */
+ public Set<EnumElementChange> merge(CompilationUnit compilationUnit) throws JavaModelException, CoreException {
+ Set<EnumElementChange> changes = new HashSet<EnumElementChange>();
+ IType javaType = resource.getJavaElement();
+ // resource method
+ String newValue = (String) JdtUtils.resolveAnnotationAttributeValue(javaType, compilationUnit, Path.class,
+ "value");
+ if (ObjectUtils.compare(uriPathTemplateFragment, newValue)) {
+ if (uriPathTemplateFragment == null || newValue == null) {
+ changes.add(EnumElementChange.KIND);
+ } else {
+ changes.add(EnumElementChange.MAPPING);
+ }
+ this.uriPathTemplateFragment = newValue;
+ }
+ if (this.consumedMediaTypes.merge(JAXRSAnnotationsScanner.resolveMediaTypeCapabilities(javaType,
+ compilationUnit, Consumes.class))) {
+ changes.add(EnumElementChange.MAPPING);
+ }
+ if (this.producedMediaTypes.merge(JAXRSAnnotationsScanner.resolveMediaTypeCapabilities(javaType,
+ compilationUnit, Produces.class))) {
+ changes.add(EnumElementChange.MAPPING);
+ }
+ return changes;
+ }
+
+ /*
+ * private static final String resolveBaseURIPathTemplate(Resource resource)
+ * { if (resource.isRootResource()) { return uriPathTemplateBufferTemplate;
+ * } return new StringBuffer(resolveBaseURIPathTemplate(resource.get));
+ * uriPathTemplateBuffer.append("/").append(resourceUriPathTemplate); return
+ * uriPathTemplateBuffer.toString(); }
+ *
+ * private static String computeFullUriPathTemplate(ResourceMethodMapping
+ * mapping) { String uriPathTemplate = mapping.getUriPathTemplateFragment();
+ * List<ResourceMethodAnnotatedParameter> queryParams =
+ * mapping.getQueryParams(); String baseURIPathTemplate =
+ * resolveBaseURIPathTemplate
+ * (mapping.getResourceMethod().getParentResource()); StringBuffer
+ * uriPathTemplateBuffer = new StringBuffer(baseURIPathTemplate);
+ * uriPathTemplateBuffer.append(uriPathTemplate); if (queryParams != null &&
+ * !queryParams.isEmpty()) { uriPathTemplateBuffer.append("?"); for
+ * (Iterator<ResourceMethodAnnotatedParameter> queryParamIterator =
+ * queryParams.iterator(); queryParamIterator .hasNext();) {
+ * ResourceMethodAnnotatedParameter queryParam = queryParamIterator.next();
+ * uriPathTemplateBuffer
+ * .append(queryParam.getAnnotationValue()).append("={")
+ * .append(queryParam.getParameterType()).append("}"); if
+ * (queryParamIterator.hasNext()) { uriPathTemplateBuffer.append("&"); }
+ *
+ * }
+ *
+ * } return uriPathTemplateBuffer.toString().replaceAll("/\\*",
+ * "/").replaceAll("///", "/").replaceAll("//", "/"); }
+ */
+
+ /**
+ * @return the uriPathTemplateFragment
+ */
+ public final String getUriPathTemplateFragment() {
+ return uriPathTemplateFragment;
+ }
+
+ @Override
+ public final String toString() {
+ StringBuffer buffer = new StringBuffer();
+ String uriPathTemplate = getUriPathTemplateFragment();
+ if (uriPathTemplate != null) {
+ buffer.append(uriPathTemplate);
+ buffer.append(" ");
+ }
+ buffer.append("{consumes:").append(consumedMediaTypes).append(" produces:").append(producedMediaTypes)
+ .append("}");
+ return buffer.toString();
+ }
+
+ /**
+ * @return the Consumed MediaTypes
+ */
+ public final MediaTypeCapabilities getConsumedMediaTypes() {
+ return consumedMediaTypes;
+ }
+
+ /**
+ * @return the Produced MediaTypes
+ */
+ public final MediaTypeCapabilities getProcucedMediaTypes() {
+ return producedMediaTypes;
+ }
+
+ /**
+ * @return the queryParams
+ */
+ public final List<ResourceMethodAnnotatedParameter> getQueryParams() {
+ return queryParams;
+ }
+
+ /**
+ * @return the pathParams
+ */
+ public final List<ResourceMethodAnnotatedParameter> getPathParams() {
+ return pathParams;
+ }
+
+}
Added: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMethodMapping.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMethodMapping.java (rev 0)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMethodMapping.java 2011-06-07 22:25:07 UTC (rev 31892)
@@ -0,0 +1,364 @@
+/*******************************************************************************
+ * 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.metamodel;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.IAnnotationBinding;
+import org.eclipse.osgi.util.NLS;
+import org.jboss.tools.ws.jaxrs.core.internal.builder.JAXRSAnnotationsScanner;
+import org.jboss.tools.ws.jaxrs.core.internal.builder.JaxrsMetamodelBuilder;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.ObjectUtils;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.ValidationMessages;
+import org.jboss.tools.ws.jaxrs.core.utils.JdtUtils;
+import org.jboss.tools.ws.jaxrs.core.utils.ResourceMethodAnnotatedParameter;
+
+public class ResourceMethodMapping {
+
+ private final ResourceMethod resourceMethod;
+
+ private HTTPMethod httpMethod;
+
+ private final MediaTypeCapabilities consumedMediaTypes;
+
+ private final MediaTypeCapabilities producedMediaTypes;
+
+ private String uriPathTemplateFragment = null;
+
+ private List<ResourceMethodAnnotatedParameter> pathParams = null;
+
+ private List<ResourceMethodAnnotatedParameter> queryParams = null;
+
+ /**
+ * Full constructor using the inner 'MediaTypeCapabilitiesBuilder' static
+ * class.
+ *
+ * @param builder
+ */
+ public ResourceMethodMapping(final ResourceMethod resourceMethod) {
+ this.resourceMethod = resourceMethod;
+ this.consumedMediaTypes = new MediaTypeCapabilities(resourceMethod.getJavaElement());
+ this.producedMediaTypes = new MediaTypeCapabilities(resourceMethod.getJavaElement());
+ }
+
+ /**
+ * @return the resourceMethod
+ */
+ public ResourceMethod getResourceMethod() {
+ return resourceMethod;
+ }
+
+ /**
+ * @param javaMethod
+ * @param compilationUnit
+ * @throws JavaModelException
+ * @throws CoreException
+ * @throws InvalidModelElementException
+ */
+ public boolean merge(CompilationUnit compilationUnit) throws JavaModelException, CoreException,
+ InvalidModelElementException {
+ boolean changed = false;
+ IMethod javaMethod = resourceMethod.getJavaElement();
+ HTTPMethod nextHTTPMethod = resolveHTTPMethod(compilationUnit);
+ if (ObjectUtils.compare(this.httpMethod, nextHTTPMethod)) {
+ this.httpMethod = nextHTTPMethod;
+ changed = true;
+ }
+ // resource method
+ String nextValue = (String) JdtUtils.resolveAnnotationAttributeValue(javaMethod, compilationUnit, Path.class,
+ "value");
+ if (ObjectUtils.compare(this.uriPathTemplateFragment, nextValue)) {
+ this.uriPathTemplateFragment = nextValue;
+ changed = true;
+ }
+ List<ResourceMethodAnnotatedParameter> nextPathParams = JdtUtils.resolveMethodParameters(javaMethod,
+ compilationUnit, PathParam.class);
+ if (ObjectUtils.compare(this.pathParams, nextPathParams)) {
+ this.pathParams = nextPathParams;
+ changed = true;
+ }
+ List<ResourceMethodAnnotatedParameter> nextQueryParams = JdtUtils.resolveMethodParameters(javaMethod,
+ compilationUnit, QueryParam.class);
+ if (ObjectUtils.compare(this.queryParams, nextQueryParams)) {
+ this.queryParams = nextQueryParams;
+ changed = true;
+ }
+ changed = (changed | this.consumedMediaTypes.merge(JAXRSAnnotationsScanner.resolveMediaTypeCapabilities(
+ javaMethod, compilationUnit, Consumes.class)));
+ changed = (changed | this.producedMediaTypes.merge(JAXRSAnnotationsScanner.resolveMediaTypeCapabilities(
+ javaMethod, compilationUnit, Produces.class)));
+ return changed;
+ }
+
+ /*
+ * private static final String resolveBaseURIPathTemplate(Resource resource)
+ * { String resourceUriPathTemplate =
+ * resource.getMapping().getUriPathTemplateFragment(); if
+ * (resource.isRootResource()) { return resourceUriPathTemplate; }
+ * StringBuffer uriPathTemplateBuffer = new
+ * StringBuffer(resolveBaseURIPathTemplate());
+ * uriPathTemplateBuffer.append("/").append(resourceUriPathTemplate); return
+ * uriPathTemplateBuffer.toString(); }
+ *
+ * private static String computeFullUriPathTemplate(ResourceMethodMapping
+ * mapping) { String uriPathTemplate = mapping.getUriPathTemplateFragment();
+ * List<ResourceMethodAnnotatedParameter> queryParams =
+ * mapping.getQueryParams(); String baseURIPathTemplate =
+ * resolveBaseURIPathTemplate
+ * (mapping.getResourceMethod().getParentResource()); StringBuffer
+ * uriPathTemplateBuffer = new StringBuffer(baseURIPathTemplate);
+ * uriPathTemplateBuffer.append(uriPathTemplate); if (queryParams != null &&
+ * !queryParams.isEmpty()) { uriPathTemplateBuffer.append("?"); for
+ * (Iterator<ResourceMethodAnnotatedParameter> queryParamIterator =
+ * queryParams.iterator(); queryParamIterator .hasNext();) {
+ * ResourceMethodAnnotatedParameter queryParam = queryParamIterator.next();
+ * uriPathTemplateBuffer
+ * .append(queryParam.getAnnotationValue()).append("={")
+ * .append(queryParam.getParameterType()).append("}"); if
+ * (queryParamIterator.hasNext()) { uriPathTemplateBuffer.append("&"); }
+ *
+ * }
+ *
+ * } return uriPathTemplateBuffer.toString().replaceAll("/\\*",
+ * "/").replaceAll("///", "/").replaceAll("//", "/"); }
+ */
+ private HTTPMethod resolveHTTPMethod(CompilationUnit compilationUnit) {
+ for (String httpMethodName : resourceMethod.getMetamodel().getHttpMethods().getTypeNames()) {
+ IAnnotationBinding httpMethodAnnotationBinding = JdtUtils.resolveAnnotationBinding(
+ resourceMethod.getJavaElement(), compilationUnit, httpMethodName);
+ if (httpMethodAnnotationBinding != null) {
+ // stop iterating
+ return resourceMethod.getMetamodel().getHttpMethods().getByTypeName(httpMethodName);
+ }
+ }
+ return null;
+ }
+
+ /*
+ * private static final MediaTypeCapabilities resolveMediaTypes(final
+ * MediaTypeCapabilities resourceMediaTypes, final MediaTypeCapabilities
+ * methodMediaTypes) { if (!methodMediaTypes.isEmpty()) { return
+ * methodMediaTypes; } else if (resourceMediaTypes != null) { return
+ * resourceMediaTypes; } return null; }
+ */
+
+ /**
+ * Validates the URI Mapping by checking that all
+ * <code>javax.ws.rs.PathParam</code> annotation values match a parameter in
+ * the URI Path Template fragment defined by the value of the
+ * <code>java.ws.rs.Path</code> annotation value.
+ *
+ * @throws CoreException
+ *
+ */
+ public void validate() throws CoreException {
+ if (uriPathTemplateFragment != null) {
+ List<String> uriTemplateParams = extractParamsFromUriTemplateFragment(uriPathTemplateFragment);
+ for (ResourceMethodAnnotatedParameter pathParam : pathParams) {
+ String param = pathParam.getAnnotationValue();
+ if (!uriTemplateParams.contains(param)) {
+ IMarker marker = resourceMethod.getJavaElement().getResource()
+ .createMarker(JaxrsMetamodelBuilder.JAXRS_PROBLEM);
+ marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
+ String message = NLS.bind(ValidationMessages.unbound_parameter, "'" + param + "'"); //$NON-NLS-1$
+ marker.setAttribute(IMarker.MESSAGE, message);
+ marker.setAttribute(IMarker.LINE_NUMBER, pathParam.getLineNumber());
+ marker.setAttribute(IMarker.CHAR_START, pathParam.getCharStart());
+ marker.setAttribute(IMarker.CHAR_END, pathParam.getCharEnd());
+ }
+ }
+ }
+ }
+
+ private static List<String> extractParamsFromUriTemplateFragment(String fragment) {
+ List<String> params = new ArrayList<String>();
+ int beginIndex = -1;
+ while ((beginIndex = fragment.indexOf("{", beginIndex + 1)) != -1) {
+ int semicolonIndex = fragment.indexOf(":", beginIndex);
+ int closingCurlyBraketIndex = fragment.indexOf("}", beginIndex);
+ int endIndex = semicolonIndex != -1 ? semicolonIndex : closingCurlyBraketIndex;
+ params.add(fragment.substring(beginIndex + 1, endIndex).trim());
+ }
+ return params;
+ }
+
+ /**
+ * @return the httpMethod
+ */
+ public final HTTPMethod getHTTPMethod() {
+ return httpMethod;
+ }
+
+ /**
+ * @return the uriPathTemplateFragment
+ */
+ public final String getUriPathTemplateFragment() {
+ return uriPathTemplateFragment;
+ }
+
+ public boolean matches(HTTPMethod httpMethod, String uriPathTemplateFragment, String consumes, String produces) {
+ if (httpMethod != null && !httpMethod.equals(this.httpMethod)) {
+ return false;
+ }
+ if (this.httpMethod != null && !this.httpMethod.equals(httpMethod)) {
+ return false;
+ }
+ if (uriPathTemplateFragment != null && !uriPathTemplateFragment.equals(this.uriPathTemplateFragment)) {
+ return false;
+ }
+ if (this.uriPathTemplateFragment != null && !this.uriPathTemplateFragment.equals(uriPathTemplateFragment)) {
+ return false;
+ }
+ if (consumedMediaTypes != null && consumes != null && !consumedMediaTypes.contains(consumes)) {
+ return false;
+ }
+ if (producedMediaTypes != null && produces != null && !producedMediaTypes.contains(produces)) {
+ return false;
+ }
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public final String toString() {
+ StringBuffer buffer = new StringBuffer();
+ if (httpMethod != null) {
+ buffer.append(httpMethod.getHttpVerb());
+ buffer.append(" ");
+ }
+ String uriPathTemplate = getUriPathTemplateFragment();
+ if (uriPathTemplate != null) {
+ buffer.append(uriPathTemplate);
+ buffer.append(" ");
+ }
+ buffer.append("{Accept:").append(consumedMediaTypes).append(" Content-type: ").append(producedMediaTypes)
+ .append("}");
+ return buffer.toString();
+ }
+
+ /**
+ * @return the Consumed MediaTypes
+ */
+ public final MediaTypeCapabilities getConsumedMediaTypes() {
+ return consumedMediaTypes;
+ }
+
+ /**
+ * @return the Produced MediaTypes
+ */
+ public final MediaTypeCapabilities getProcucedMediaTypes() {
+ return producedMediaTypes;
+ }
+
+ /**
+ * @return the queryParams
+ */
+ public final List<ResourceMethodAnnotatedParameter> getQueryParams() {
+ return queryParams;
+ }
+
+ /**
+ * @return the pathParams
+ */
+ public final List<ResourceMethodAnnotatedParameter> getPathParams() {
+ return pathParams;
+ }
+
+ /**
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public final int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((httpMethod == null) ? 0 : httpMethod.hashCode());
+ result = prime * result + ((consumedMediaTypes == null) ? 0 : consumedMediaTypes.hashCode());
+ result = prime * result + ((producedMediaTypes == null) ? 0 : producedMediaTypes.hashCode());
+ result = prime * result + ((queryParams == null) ? 0 : queryParams.hashCode());
+ result = prime * result + ((uriPathTemplateFragment == null) ? 0 : uriPathTemplateFragment.hashCode());
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public final boolean equals(final Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ ResourceMethodMapping other = (ResourceMethodMapping) obj;
+ if (httpMethod == null) {
+ if (other.httpMethod != null) {
+ return false;
+ }
+ } else if (!httpMethod.equals(other.httpMethod)) {
+ return false;
+ }
+ if (producedMediaTypes == null) {
+ if (other.producedMediaTypes != null) {
+ return false;
+ }
+ } else if (!producedMediaTypes.equals(other.producedMediaTypes)) {
+ return false;
+ }
+ if (consumedMediaTypes == null) {
+ if (other.consumedMediaTypes != null) {
+ return false;
+ }
+ } else if (!consumedMediaTypes.equals(other.consumedMediaTypes)) {
+ return false;
+ }
+ if (queryParams == null) {
+ if (other.queryParams != null) {
+ return false;
+ }
+ } else if (!queryParams.equals(other.queryParams)) {
+ return false;
+ }
+ if (uriPathTemplateFragment == null) {
+ if (other.uriPathTemplateFragment != null) {
+ return false;
+ }
+ } else if (!uriPathTemplateFragment.equals(other.uriPathTemplateFragment)) {
+ return false;
+ }
+ return true;
+ }
+
+}
Added: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMethodNode.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMethodNode.java (rev 0)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMethodNode.java 2011-06-07 22:25:07 UTC (rev 31892)
@@ -0,0 +1,92 @@
+/**
+ *
+ */
+package org.jboss.tools.ws.jaxrs.core.metamodel;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @author xcoulon
+ *
+ */
+public class ResourceMethodNode {
+
+ private final ResourceMethod element;
+
+ private final ResourceMethodNode parent;
+
+ private final List<ResourceMethodNode> children = new ArrayList<ResourceMethodNode>();
+
+ public ResourceMethodNode(ResourceMethodNode parent, ResourceMethod element) {
+ this.parent = parent;
+ this.element = element;
+ }
+
+ /**
+ * @return the element
+ */
+ public ResourceMethod getElement() {
+ return element;
+ }
+
+ /**
+ * @return the parent
+ */
+ public ResourceMethodNode getParent() {
+ return parent;
+ }
+
+ /**
+ * @return the children
+ */
+ public List<ResourceMethodNode> getChildren() {
+ return children;
+ }
+
+ /**
+ * @return true if this node is a Leaf (ie, it has no child node).
+ */
+ public boolean isLeaf() {
+ return children.isEmpty();
+ }
+
+ /**
+ * @return True if this node is is the root node (ie, it has no parent
+ * node).
+ */
+ public boolean isRoot() {
+ return (parent == null);
+ }
+
+ public Set<ResourceMethodNode> remove() {
+ Set<ResourceMethodNode> removedNodes = new HashSet<ResourceMethodNode>();
+ removedNodes.add(this);
+ for (Iterator<ResourceMethodNode> iterator = children.iterator(); iterator.hasNext();) {
+ ResourceMethodNode child = iterator.next();
+ removedNodes.addAll(child.remove());
+ iterator.remove();
+ }
+ return removedNodes;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ StringBuilder buffer = new StringBuilder(element.toString());
+ if (!children.isEmpty()) {
+ buffer.append("\nchildren:\n");
+ for (ResourceMethodNode child : children) {
+ buffer.append(" ").append(child).append("\n");
+ }
+ }
+ return buffer.toString();
+ }
+}
Added: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Route.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Route.java (rev 0)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Route.java 2011-06-07 22:25:07 UTC (rev 31892)
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * 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.metamodel;
+
+import java.util.LinkedList;
+import java.util.List;
+
+public class Route implements Comparable<Route> {
+
+ private final LinkedList<ResourceMethod> resourceMethods = new LinkedList<ResourceMethod>();
+
+ private final RouteEndpoint routeEndpoint;
+
+ /**
+ * Full constructor
+ *
+ * @throws InvalidModelElementException
+ */
+ public Route(List<ResourceMethod> resourceMethods) throws InvalidModelElementException {
+ super();
+ this.resourceMethods.addAll(resourceMethods);
+ this.routeEndpoint = new RouteEndpoint(this);
+ }
+
+ /**
+ * @return the resourceMethods
+ */
+ public LinkedList<ResourceMethod> getResourceMethods() {
+ return resourceMethods;
+ }
+
+ /**
+ * @return the routeEndpoint
+ */
+ public RouteEndpoint getEndpoint() {
+ return routeEndpoint;
+ }
+
+ /**
+ * {inheritDoc
+ */
+ @Override
+ public final String toString() {
+ return new StringBuffer().append(routeEndpoint.toString()).append("\n").append(this.resourceMethods.getLast())
+ .toString();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((resourceMethods == null) ? 0 : resourceMethods.hashCode());
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Route other = (Route) obj;
+ if (resourceMethods == null) {
+ if (other.resourceMethods != null)
+ return false;
+ } else if (!resourceMethods.equals(other.resourceMethods))
+ return false;
+ return true;
+ }
+
+ @Override
+ public int compareTo(Route other) {
+ return routeEndpoint.compareTo(other.getEndpoint());
+ }
+
+}
Added: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/RouteEndpoint.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/RouteEndpoint.java (rev 0)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/RouteEndpoint.java 2011-06-07 22:25:07 UTC (rev 31892)
@@ -0,0 +1,199 @@
+package org.jboss.tools.ws.jaxrs.core.metamodel;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.jboss.tools.ws.jaxrs.core.utils.ResourceMethodAnnotatedParameter;
+
+public class RouteEndpoint implements Comparable<RouteEndpoint> {
+
+ private HTTPMethod httpMethod = null;
+
+ private String uriPathTemplate = null;
+
+ private final MediaTypeCapabilities consumedMediaTypes;
+
+ private final MediaTypeCapabilities producedMediaTypes;
+
+ private final Route route;
+
+ public RouteEndpoint(Route route) throws InvalidModelElementException {
+ this.route = route;
+ consumedMediaTypes = new MediaTypeCapabilities(null);
+ producedMediaTypes = new MediaTypeCapabilities(null);
+ merge();
+ }
+
+ public void merge() throws InvalidModelElementException {
+ this.httpMethod = computeHttpMethod(route.getResourceMethods());
+ this.uriPathTemplate = computeUriPathTemplate(route.getResourceMethods());
+ this.consumedMediaTypes.merge(computeConsumedMediaTypes(route.getResourceMethods()));
+ this.producedMediaTypes.merge(computeProducedMediaTypes(route.getResourceMethods()));
+ }
+
+ /**
+ * @return the httpMethod
+ */
+ public HTTPMethod getHttpMethod() {
+ return httpMethod;
+ }
+
+ /**
+ * @return the uriPathTemplate
+ */
+ public String getUriPathTemplate() {
+ return uriPathTemplate;
+ }
+
+ /**
+ * @return the consumedMediaTypes
+ */
+ public MediaTypeCapabilities getConsumedMediaTypes() {
+ return consumedMediaTypes;
+ }
+
+ /**
+ * @return the producedMediaTypes
+ */
+ public MediaTypeCapabilities getProducedMediaTypes() {
+ return producedMediaTypes;
+ }
+
+ public boolean matches(HTTPMethod otherHttpMethod, String otherUriPathTemplate, String otherConsumes,
+ String otherProduces) {
+ if (otherHttpMethod != null && !this.httpMethod.getHttpVerb().equals(otherHttpMethod.getHttpVerb())) {
+ return false;
+ }
+ if (otherUriPathTemplate != null && !this.uriPathTemplate.equals(otherUriPathTemplate)) {
+ return false;
+ }
+ if (otherConsumes != null && !otherConsumes.equals("*/*") && !this.consumedMediaTypes.contains(otherConsumes)) {
+ return false;
+ }
+ if (otherProduces != null && !otherProduces.equals("*/*") && !this.producedMediaTypes.contains(otherProduces)) {
+ return false;
+ }
+
+ return true;
+ }
+
+ private static HTTPMethod computeHttpMethod(LinkedList<ResourceMethod> resourceMethods)
+ throws InvalidModelElementException {
+ for (Iterator<ResourceMethod> iterator = resourceMethods.descendingIterator(); iterator.hasNext();) {
+ ResourceMethod resourceMethod = iterator.next();
+ HTTPMethod h = resourceMethod.getMapping().getHTTPMethod();
+ if (h != null) {
+ return h;
+ }
+ }
+ throw new InvalidModelElementException("No HttpMethod annotation found for this endpoint: " + resourceMethods);
+ }
+
+ private static String computeUriPathTemplate(LinkedList<ResourceMethod> resourceMethods) {
+ StringBuffer templateBuffer = new StringBuffer();
+ for (Iterator<ResourceMethod> iterator = resourceMethods.iterator(); iterator.hasNext();) {
+ ResourceMethod resourceMethod = iterator.next();
+ Resource resource = resourceMethod.getParentResource();
+ if (resource.isRootResource()) {
+ templateBuffer.append("/").append(resource.getMetamodel().getServiceUri());
+ }
+ if (resource.getMapping().getUriPathTemplateFragment() != null) {
+ templateBuffer.append("/").append(resource.getMapping().getUriPathTemplateFragment());
+ }
+ if (resourceMethod.getMapping().getUriPathTemplateFragment() != null) {
+ templateBuffer.append("/").append(resourceMethod.getMapping().getUriPathTemplateFragment());
+ }
+ }
+ ResourceMethod lastMethod = resourceMethods.getLast();
+ List<ResourceMethodAnnotatedParameter> queryParams = lastMethod.getMapping().getQueryParams();
+ if (queryParams != null && !queryParams.isEmpty()) {
+ templateBuffer.append("?");
+ for (Iterator<ResourceMethodAnnotatedParameter> queryParamIterator = queryParams.iterator(); queryParamIterator
+ .hasNext();) {
+ ResourceMethodAnnotatedParameter queryParam = queryParamIterator.next();
+ templateBuffer.append(queryParam.getAnnotationValue()).append("={")
+ .append(queryParam.getParameterType()).append("}");
+ if (queryParamIterator.hasNext()) {
+ templateBuffer.append("&");
+ }
+
+ }
+
+ }
+ return templateBuffer.toString().replaceAll("/\\*", "/").replaceAll("///", "/").replaceAll("//", "/");
+
+ }
+
+ private static MediaTypeCapabilities computeConsumedMediaTypes(LinkedList<ResourceMethod> resourceMethods) {
+ for (Iterator<ResourceMethod> iterator = resourceMethods.descendingIterator(); iterator.hasNext();) {
+ ResourceMethod resourceMethod = iterator.next();
+ MediaTypeCapabilities mediaTypeCapabilities = resourceMethod.getMapping().getConsumedMediaTypes();
+ if (!mediaTypeCapabilities.isEmpty()) {
+ return mediaTypeCapabilities;
+ }
+
+ Resource parentResource = resourceMethod.getParentResource();
+ mediaTypeCapabilities = parentResource.getMapping().getConsumedMediaTypes();
+ if (!mediaTypeCapabilities.isEmpty()) {
+ return mediaTypeCapabilities;
+ }
+ }
+ return new MediaTypeCapabilities(resourceMethods.getLast().getJavaElement(), Arrays.asList("*/*"));
+ }
+
+ private static MediaTypeCapabilities computeProducedMediaTypes(LinkedList<ResourceMethod> resourceMethods) {
+ for (Iterator<ResourceMethod> iterator = resourceMethods.descendingIterator(); iterator.hasNext();) {
+ ResourceMethod resourceMethod = iterator.next();
+ MediaTypeCapabilities mediaTypeCapabilities = resourceMethod.getMapping().getProcucedMediaTypes();
+ if (!mediaTypeCapabilities.isEmpty()) {
+ return mediaTypeCapabilities;
+ }
+
+ Resource parentResource = resourceMethod.getParentResource();
+ mediaTypeCapabilities = parentResource.getMapping().getProcucedMediaTypes();
+ if (!mediaTypeCapabilities.isEmpty()) {
+ return mediaTypeCapabilities;
+ }
+ }
+ return new MediaTypeCapabilities(resourceMethods.getLast().getJavaElement(), Arrays.asList("*/*"));
+ }
+
+ @Override
+ public final int compareTo(final RouteEndpoint other) {
+ int u = uriPathTemplate.compareTo(other.getUriPathTemplate());
+ if (u != 0) {
+ return u;
+ }
+ int h = httpMethod.compareTo(other.getHttpMethod());
+ if (h != 0) {
+ return h;
+ }
+ int c = consumedMediaTypes.compareTo(other.getConsumedMediaTypes());
+ if (c != 0) {
+ return c;
+ }
+ return producedMediaTypes.compareTo(other.getProducedMediaTypes());
+ }
+
+ /**
+ * {inheritDoc
+ */
+ @Override
+ public final String toString() {
+ StringBuffer buffer = new StringBuffer();
+ if (httpMethod != null) {
+ buffer.append(httpMethod.getHttpVerb());
+ buffer.append(" ");
+ }
+ if (uriPathTemplate != null) {
+ buffer.append(uriPathTemplate);
+ buffer.append(" ");
+ }
+ buffer.append("{Consumes:").append(consumedMediaTypes).append(" Produces: ").append(producedMediaTypes)
+ .append("}");
+ return buffer.toString();
+ }
+
+}
Added: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Routes.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Routes.java (rev 0)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Routes.java 2011-06-07 22:25:07 UTC (rev 31892)
@@ -0,0 +1,216 @@
+/**
+ *
+ */
+package org.jboss.tools.ws.jaxrs.core.metamodel;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.ITypeHierarchy;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
+import org.jboss.tools.ws.jaxrs.core.metamodel.BaseElement.EnumKind;
+import org.jboss.tools.ws.jaxrs.core.utils.JdtUtils;
+
+/**
+ * @author xcoulon
+ *
+ */
+public class Routes {
+
+ /** The JAX-RS metamodel. */
+ private final Metamodel metamodel;
+
+ /**
+ * The set of trees. A tree has a root node and has some children. Each path
+ * of the tree is a route.
+ */
+ // private final Set<ResourceMethodNode> trees = new
+ // HashSet<ResourceMethodNode>();
+
+ private final List<Route> routes = new ArrayList<Route>();
+
+ private final Map<ResourceMethod, List<Route>> routesIndex = new HashMap<ResourceMethod, List<Route>>();
+
+ private final Map<ResourceMethod, ResourceMethodNode> nodesIndex = new HashMap<ResourceMethod, ResourceMethodNode>();
+
+ /**
+ * @param m
+ */
+ public Routes(Metamodel metamodel) {
+ this.metamodel = metamodel;
+ }
+
+ public void addFrom(ResourceMethod resourceMethod, IProgressMonitor progressMonitor) throws CoreException {
+ switch (resourceMethod.getParentResource().getKind()) {
+ case ROOT_RESOURCE:
+ computeNodes(null, resourceMethod, progressMonitor);
+ break;
+ case SUBRESOURCE:
+ List<ResourceMethod> subresourceLocators = metamodel.getResources().findSubresourceLocators(
+ resourceMethod.getParentResource().getJavaElement(), progressMonitor);
+ for (ResourceMethod subresourceLocator : subresourceLocators) {
+ ResourceMethodNode subresourceLocatorNode = nodesIndex.get(subresourceLocator);
+ if (subresourceLocatorNode != null) {
+ computeNodes(subresourceLocatorNode, resourceMethod, progressMonitor);
+ // trees.addAll(addedNodes);
+ }
+ }
+ break;
+ }
+ }
+
+ public void merge(ResourceMethod resourceMethod, IProgressMonitor progressMonitor) throws CoreException {
+ removeFrom(resourceMethod, progressMonitor);
+ addFrom(resourceMethod, progressMonitor);
+ }
+
+ public void removeFrom(Resource removedResource, IProgressMonitor progressMonitor) {
+ if (removedResource == null) {
+ return;
+ }
+ for (ResourceMethod removedResourceMethod : removedResource.getAllMethods()) {
+ removeFrom(removedResourceMethod, progressMonitor);
+ }
+ }
+
+ public void removeFrom(ResourceMethod removedResourceMethod, IProgressMonitor progressMonitor) {
+ if (removedResourceMethod == null) {
+ return;
+ }
+ if (this.routesIndex.containsKey(removedResourceMethod)) {
+ List<Route> routesToRemove = routesIndex.get(removedResourceMethod);
+ for (Route route : routesToRemove) {
+ this.routes.remove(route);
+ }
+ this.routesIndex.remove(removedResourceMethod);
+ }
+
+ if (this.nodesIndex.containsKey(removedResourceMethod)) {
+ ResourceMethodNode resourceMethodNode = this.nodesIndex.get(removedResourceMethod);
+ Set<ResourceMethodNode> removedNodes = resourceMethodNode.remove();
+ for (ResourceMethodNode removedNode : removedNodes) {
+ this.nodesIndex.remove(removedNode.getElement());
+ }
+ }
+
+ }
+
+ private List<ResourceMethodNode> computeNodes(final ResourceMethodNode parent, final ResourceMethod resourceMethod,
+ final IProgressMonitor progressMonitor) throws CoreException {
+ List<ResourceMethodNode> childrenNodes = new ArrayList<ResourceMethodNode>();
+ ResourceMethodNode node = new ResourceMethodNode(parent, resourceMethod);
+ childrenNodes.add(node);
+ nodesIndex.put(resourceMethod, node);
+ switch (resourceMethod.getKind()) {
+ // leaf node: can compute route from this node back to root parent node
+ case RESOURCE_METHOD:
+ case SUBRESOURCE_METHOD:
+ computeRoute(node);
+ break;
+ case SUBRESOURCE_LOCATOR:
+ IType returnType = resourceMethod.getReturnType();
+ if (returnType == null) {
+ Logger.warn("No return type defined for subresource locator method "
+ + resourceMethod.getJavaElement().getElementName());
+ break;
+ }
+ ITypeHierarchy subresourceTypeHierarchy = JdtUtils.resolveTypeHierarchy(returnType, false, progressMonitor);
+ for (IType subresourceType : subresourceTypeHierarchy.getSubtypes(returnType)) {
+ Resource subresource = metamodel.getResources().getByType(subresourceType);
+ if (subresource != null && !subresource.equals(resourceMethod.getParentResource())
+ && subresource.getKind() == EnumKind.SUBRESOURCE) {
+ for (ResourceMethod subresourceMethod : subresource.getAllMethods()) {
+ node.getChildren().addAll(computeNodes(node, subresourceMethod, progressMonitor));
+ }
+ }
+ }
+ childrenNodes.add(node);
+ }
+ return childrenNodes;
+ }
+
+ /**
+ * Compute the route from the given leaf node.
+ */
+ private Route computeRoute(final ResourceMethodNode leafNode) {
+ LinkedList<ResourceMethod> resourceMethods = new LinkedList<ResourceMethod>();
+ ResourceMethodNode node = leafNode;
+ while (node != null) {
+ resourceMethods.addFirst(node.getElement());
+ node = node.getParent();
+ }
+ try {
+ Route route = new Route(resourceMethods);
+ if (!routes.contains(route)) {
+ routes.add(route);
+ }
+ for (ResourceMethod rm : resourceMethods) {
+ // avoid duplicates
+ if (!this.routesIndex.containsKey(rm)) {
+ this.routesIndex.put(rm, new ArrayList<Route>());
+ }
+ if (!this.routesIndex.get(rm).contains(route)) {
+ Logger.debug("Added route " + route.toString());
+ this.routesIndex.get(rm).add(route);
+ }
+ }
+ return route;
+ } catch (InvalidModelElementException e) {
+ Logger.error("Failed to compute route", e);
+ }
+ return null;
+ }
+
+ /**
+ * @return the routesIndex
+ */
+ public List<Route> getAll() {
+ Collections.sort(routes);
+ return routes;
+ }
+
+ /**
+ * @return the routes that contain this method or null if none found.
+ */
+ public List<Route> getByResourceMethod(ResourceMethod resourceMethod) {
+ return routesIndex.get(resourceMethod);
+ }
+
+ public final ResourceMethod getByMapping(final HTTPMethod httpMethod, final String uriPathTemplateFragment,
+ final String consumes, final String produces) {
+ for (Entry<ResourceMethod, List<Route>> entry : routesIndex.entrySet()) {
+ for (Route route : entry.getValue()) {
+ if (route.getEndpoint().matches(httpMethod, uriPathTemplateFragment, consumes, produces)) {
+ return route.getResourceMethods().getLast();
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @return the metamodel
+ */
+ public Metamodel getMetamodel() {
+ return metamodel;
+ }
+
+ /**
+ * Clears all data.
+ */
+ public void reset() {
+ this.routes.clear();
+ this.routesIndex.clear();
+ this.nodesIndex.clear();
+ }
+
+}
Added: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/icons/systemprocess.gif
===================================================================
(Binary files differ)
Property changes on: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/icons/systemprocess.gif
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/WaitWhileBuildingElement.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/WaitWhileBuildingElement.java (rev 0)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/WaitWhileBuildingElement.java 2011-06-07 22:25:07 UTC (rev 31892)
@@ -0,0 +1,15 @@
+/**
+ *
+ */
+package org.jboss.tools.ws.jaxrs.ui.cnf;
+
+
+/**
+ * Element displayed while the project's metamodel is built in background.
+ *
+ * @author xcoulon
+ *
+ */
+public class WaitWhileBuildingElement {
+
+}
Added: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/metamodel/MediaTypeCapabilitiesTestCase.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/metamodel/MediaTypeCapabilitiesTestCase.java (rev 0)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/metamodel/MediaTypeCapabilitiesTestCase.java 2011-06-07 22:25:07 UTC (rev 31892)
@@ -0,0 +1,25 @@
+package org.jboss.tools.ws.jaxrs.core.metamodel;
+
+import static org.junit.Assert.fail;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class MediaTypeCapabilitiesTestCase {
+
+ @Before
+ public void setup() {
+
+ }
+
+ @Test
+ public void shouldMerge() {
+ MediaTypeCapabilities capabilities = new MediaTypeCapabilities(null);
+ }
+
+ @Test
+ public void testCompareTo() {
+ fail("Not yet implemented");
+ }
+
+}
14 years, 10 months
JBoss Tools SVN: r31891 - trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/builder.
by jbosstools-commits@lists.jboss.org
Author: xcoulon
Date: 2011-06-07 17:51:49 -0400 (Tue, 07 Jun 2011)
New Revision: 31891
Modified:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/builder/ResourceMethodChangesTestCase.java
Log:
Marking test as Ignored
Modified: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/builder/ResourceMethodChangesTestCase.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/builder/ResourceMethodChangesTestCase.java 2011-06-07 21:44:52 UTC (rev 31890)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/builder/ResourceMethodChangesTestCase.java 2011-06-07 21:51:49 UTC (rev 31891)
@@ -29,6 +29,7 @@
import org.jboss.tools.ws.jaxrs.core.metamodel.Resources;
import org.jboss.tools.ws.jaxrs.core.metamodel.Route;
import org.junit.Assert;
+import org.junit.Ignore;
import org.junit.Test;
/**
@@ -246,6 +247,7 @@
}
@Test
+ @Ignore
public void shouldBecomeSubresourceLocatorWhenRemovingHTTPMethodAnnotation() throws CoreException {
// pre-conditions
Resource resource = metamodel.getResources().getByTypeName(
14 years, 10 months
JBoss Tools SVN: r31890 - trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/icons.
by jbosstools-commits@lists.jboss.org
Author: xcoulon
Date: 2011-06-07 17:44:52 -0400 (Tue, 07 Jun 2011)
New Revision: 31890
Removed:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/icons/Thumbs.db
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/icons/
Log:
Removing unused file
Property changes on: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/icons
___________________________________________________________________
Modified: svn:ignore
- unused
+ Thumbs.db
unused
Deleted: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/icons/Thumbs.db
===================================================================
(Binary files differ)
14 years, 10 months
JBoss Tools SVN: r31889 - in trunk/ws: plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/builder and 12 other directories.
by jbosstools-commits@lists.jboss.org
Author: xcoulon
Date: 2011-06-07 17:43:35 -0400 (Tue, 07 Jun 2011)
New Revision: 31889
Removed:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/icons/unused/
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/configuration/ProjectBuilderConfigurer.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/configuration/ProjectBuilderUtils.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/builder/JAXRSAnnotationsScanner.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/builder/JaxrsMetamodelBuilder.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Application.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Applications.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/BaseElement.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/BaseElementContainer.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/HTTPMethod.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/HTTPMethods.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/MediaTypeCapabilities.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Mergeable.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Metamodel.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Provider.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Providers.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Resource.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMethod.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Resources.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/utils/JdtUtils.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/icons/
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/icons/Thumbs.db
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/plugin.xml
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriMappingsContentProvider.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriMappingsLabelProvider.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriPathTemplateCategory.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriPathTemplateElement.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriPathTemplateElementsSorter.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriPathTemplateMediaTypeMappingElement.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriPathTemplateMethodMappingElement.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriPathTemplatesSorter.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/action/CopyToClipboardAction.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/action/OpenJavaEditorAction.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/action/OpenJavaEditorActionProvider.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/internal/utils/Logger.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/pom.xml
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/projects/org.jboss.tools.ws.jaxrs.tests.sampleproject/src/main/java/org/jboss/tools/ws/jaxrs/sample/services/GameResource.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/AbstractCommonTestCase.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/WorkbenchTasks.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/builder/AbstractMetamodelBuilderTestCase.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/builder/FullBuilderTestCase.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/builder/JaxrsAnnotationScannerTestCase.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/builder/ProviderChangesTestCase.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/builder/ResourceChangesTestCase.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/builder/ResourceMethodChangesTestCase.java
Log:
Modeling the resolved JAX-RS URI Path Templates, removing unused icons, fixing bugs, adding more tests.
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/configuration/ProjectBuilderConfigurer.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/configuration/ProjectBuilderConfigurer.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/configuration/ProjectBuilderConfigurer.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -17,7 +17,7 @@
import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
/**
- * Class to configure (add/remove) the JAX-RS Builder on a project.
+ * Class to configure (add/remove) the JAX-RS MediaTypeCapabilitiesBuilder on a project.
*
* @author xcoulon
*
@@ -34,9 +34,9 @@
}
// project nature installation triggers the project builder installation, by configuration/association in the plugin.xml file.
if (ProjectBuilderUtils.installProjectBuilder(project, ProjectBuilderUtils.JAXRS_BUILDER_ID)) {
- Logger.info("JAX-RS Builder is now installed.");
+ Logger.info("JAX-RS MediaTypeCapabilitiesBuilder is now installed.");
} else {
- Logger.info("JAX-RS Builder was already installed.");
+ Logger.info("JAX-RS MediaTypeCapabilitiesBuilder was already installed.");
}
}
@@ -46,9 +46,9 @@
return;
}
if (ProjectBuilderUtils.uninstallProjectBuilder(project, ProjectBuilderUtils.JAXRS_BUILDER_ID)) {
- Logger.info("JAX-RS Builder is now uninstalled.");
+ Logger.info("JAX-RS MediaTypeCapabilitiesBuilder is now uninstalled.");
} else {
- Logger.info("JAX-RS Builder was not installed.");
+ Logger.info("JAX-RS MediaTypeCapabilitiesBuilder was not installed.");
}
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/configuration/ProjectBuilderUtils.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/configuration/ProjectBuilderUtils.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/configuration/ProjectBuilderUtils.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -26,7 +26,7 @@
//TODO : replace with javabuilder, add jaxrs builder after this one.
public static final String VALIDATION_BUILDER_ID = "org.eclipse.wst.validation.validationbuilder";
- /** The JAX-RS Builder Id. */
+ /** The JAX-RS MediaTypeCapabilitiesBuilder Id. */
public static final String JAXRS_BUILDER_ID = "org.jboss.tools.ws.jaxrs.metamodelBuilder";
/**
@@ -42,8 +42,8 @@
* @param project
* the project to look into
* @param builderId
- * the Builder ID to look up in the project's builders
- * @return true if the Builder is installed (ie, declared)
+ * the MediaTypeCapabilitiesBuilder ID to look up in the project's builders
+ * @return true if the MediaTypeCapabilitiesBuilder is installed (ie, declared)
* @throws CoreException
* in case of exception
*/
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/builder/JAXRSAnnotationsScanner.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/builder/JAXRSAnnotationsScanner.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/builder/JAXRSAnnotationsScanner.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -28,11 +28,13 @@
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.IAnnotationBinding;
import org.eclipse.jdt.core.search.IJavaSearchConstants;
import org.eclipse.jdt.core.search.IJavaSearchScope;
import org.eclipse.jdt.core.search.SearchEngine;
import org.eclipse.jdt.core.search.SearchParticipant;
import org.eclipse.jdt.core.search.SearchPattern;
+import org.jboss.tools.ws.jaxrs.core.metamodel.MediaTypeCapabilities;
import org.jboss.tools.ws.jaxrs.core.utils.JdtUtils;
/**
@@ -236,15 +238,23 @@
* the fully qualified name of the annotation (should be
* <code>javax.ws.rs.Consumes</code> or
* <code>javax.ws.rs.Produces</code>)
- * @return a list of media types capabilities with bindings resolution
+ * @return a list of media types capabilities along with their corresponding
+ * (or source) annotation, or null if the given member does not have
+ * the expected annotation
* @throws CoreException
* in case of underlying exception
*/
- public static List<String> resolveMediaTypeCapabilities(final IMember annotatedMember,
- final CompilationUnit compilationUnit, final Class<?> annotationClass) throws CoreException {
- Object capabilities = JdtUtils.resolveAnnotationAttributeValue(annotatedMember, compilationUnit,
- annotationClass, "value");
- return asList(capabilities);
+ public static MediaTypeCapabilities resolveMediaTypeCapabilities(final IMember annotatedMember,
+ final CompilationUnit compilationUnit, Class<?> annotationName) throws CoreException {
+ IAnnotationBinding annotationBinding = JdtUtils.resolveAnnotationBinding(annotatedMember, compilationUnit,
+ annotationName);
+ if (annotationBinding != null) {
+ return new MediaTypeCapabilities(annotationBinding.getJavaElement(),
+ asList(JdtUtils.resolveAnnotationAttributeValue(annotationBinding, "value")));
+ } else {
+ return new MediaTypeCapabilities(annotatedMember);
+ }
+
}
/**
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/builder/JaxrsMetamodelBuilder.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/builder/JaxrsMetamodelBuilder.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/builder/JaxrsMetamodelBuilder.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -14,6 +14,7 @@
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Date;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -47,7 +48,8 @@
* @author xcoulon
*
*/
-// FIXME : add constraint : this builder must run after JDT Builder.
+// FIXME : add constraint : this builder must run after JDT
+// MediaTypeCapabilitiesBuilder.
public class JaxrsMetamodelBuilder extends IncrementalProjectBuilder implements IResourceDeltaVisitor {
/** The number of steps to fully build the JAX-RS Metamodel. */
@@ -78,7 +80,7 @@
Logger.warn("Project '" + project.getName() + "' is not a JAX-RS project.");
return null;
}
- logBuild(kind, project);
+ logBuild(kind, args, project);
switch (kind) {
case CLEAN_BUILD:
case FULL_BUILD:
@@ -181,12 +183,12 @@
metamodel.setServiceUri("/*");
metamodel.addElements(javaProject, monitor);
metamodel.validate(monitor);
+ } catch (CoreException e) {
+ Logger.error("Failed to load metamodel from project '" + project.getName() + "''s session properties", e);
+ } finally {
long endTime = new Date().getTime();
Logger.info("JAX-RS Metamodel for project '" + project.getName() + "' fully built in "
+ (endTime - startTime) + "ms.");
- } catch (CoreException e) {
- Logger.error("Failed to load metamodel from project '" + project.getName() + "''s session properties", e);
- } finally {
monitor.done();
}
}
@@ -196,10 +198,11 @@
*
* @param kind
* the build kind
+ * @param args
* @param project
* the project being built
*/
- private void logBuild(final int kind, final IProject project) {
+ private void logBuild(final int kind, @SuppressWarnings("rawtypes") final Map args, final IProject project) {
StringBuilder sb = new StringBuilder("'");
for (Field field : IncrementalProjectBuilder.class.getDeclaredFields()) {
String name = field.getName();
@@ -216,6 +219,17 @@
}
}
sb.append("' on project ").append(project.getName());
+ if (args != null && !args.isEmpty()) {
+ sb.append(" (");
+ for (Iterator<?> iterator = args.keySet().iterator(); iterator.hasNext();) {
+ Object key = iterator.next();
+ sb.append(key).append("=").append(args.get(key));
+ if (iterator.hasNext()) {
+ sb.append(", ");
+ }
+ }
+ sb.append(")");
+ }
Logger.debug(sb.toString());
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Application.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Application.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Application.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -10,6 +10,9 @@
******************************************************************************/
package org.jboss.tools.ws.jaxrs.core.metamodel;
+import java.util.HashSet;
+import java.util.Set;
+
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.IType;
@@ -57,14 +60,15 @@
* @throws CoreException
*/
public Application build(IProgressMonitor progressMonitor) throws CoreException {
- Application httpMethod = new Application(this);
- httpMethod.merge(javaType, progressMonitor);
- return httpMethod;
+ Application app = new Application(this);
+ app.merge(javaType, progressMonitor);
+ return app;
}
}
/**
- * Full constructor using the inner 'Builder' static class.
+ * Full constructor using the inner 'MediaTypeCapabilitiesBuilder' static
+ * class.
*
* @param builder
*/
@@ -73,13 +77,21 @@
}
@Override
- public void merge(IType element, IProgressMonitor progressMonitor) throws CoreException {
- CompilationUnit compilationUnit = getCompilationUnit(progressMonitor);
- String appPath = (String) JdtUtils.resolveAnnotationAttributeValue(getJavaElement(), compilationUnit,
- javax.ws.rs.ApplicationPath.class, "value");
- if (appPath != null) {
- getMetamodel().setServiceUri(appPath);
+ public Set<EnumElementChange> merge(IType element, IProgressMonitor progressMonitor) throws CoreException {
+ Set<EnumElementChange> changes = new HashSet<EnumElementChange>();
+ if (getJavaElement() != null) {
+ CompilationUnit compilationUnit = getCompilationUnit(progressMonitor);
+ String appPath = (String) JdtUtils.resolveAnnotationAttributeValue(getJavaElement(), compilationUnit,
+ javax.ws.rs.ApplicationPath.class, "value");
+ if (appPath != null) {
+ getMetamodel().setServiceUri(appPath);
+ } else {
+ getMetamodel().setServiceUri("/");
+ }
+ } else {
+ getMetamodel().setServiceUri("/");
}
+ return changes;
}
@Override
@@ -89,7 +101,7 @@
}
@Override
- public org.jboss.tools.ws.jaxrs.core.metamodel.BaseElement.EnumType getKind() {
+ public org.jboss.tools.ws.jaxrs.core.metamodel.BaseElement.EnumKind getKind() {
// TODO Auto-generated method stub
return null;
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Applications.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Applications.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Applications.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -34,15 +34,18 @@
/**
* {@inheritDoc}
*
+ * @return
+ *
* @throws InvalidModelElementException
*/
@Override
- public void addFrom(IJavaElement scope, IProgressMonitor progressMonitor) throws CoreException {
+ public List<Application> addFrom(IJavaElement scope, IProgressMonitor progressMonitor) throws CoreException {
IType applicationType = JdtUtils.resolveType(javax.ws.rs.core.Application.class.getName(),
metamodel.getJavaProject(), progressMonitor);
ITypeHierarchy applicationTypeHierarchy = JdtUtils
.resolveTypeHierarchy(applicationType, false, progressMonitor);
IType[] subtypes = applicationTypeHierarchy.getAllSubtypes(applicationType);
+ List<Application> addedApps = new ArrayList<Application>();
if (subtypes.length > 1) {
List<String> s = new ArrayList<String>();
for (IType t : subtypes) {
@@ -54,7 +57,8 @@
for (IType t : subtypes) {
Application application = new Application.Builder(t, metamodel).build(progressMonitor);
elements.put(t.getElementName(), application);
+ addedApps.add(application);
}
-
+ return addedApps;
}
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/BaseElement.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/BaseElement.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/BaseElement.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -28,7 +28,7 @@
public abstract class BaseElement<T extends IMember> implements Mergeable<T>, Validable {
/** The functional type of the JAX-RS Element. */
- public enum EnumType {
+ public enum EnumKind {
/** An application */
APPLICATION,
/** A root resource. */
@@ -47,24 +47,6 @@
HTTP_METHOD;
}
- /**
- * The state of the instance.
- *
- * @author xcoulon
- *
- */
- enum EnumState {
- /** unknown state (before initialization). */
- UNKNOWN,
- /** During initilization. */
- CREATING,
- /** After initialization. */
- CREATED;
- }
-
- /** The current instance state. */
- EnumState state = EnumState.UNKNOWN;
-
/** The associated metamodel. */
private final Metamodel metamodel;
@@ -106,7 +88,7 @@
/**
* @return the functional kind of the JAX-RS element.
*/
- public abstract EnumType getKind();
+ public abstract EnumKind getKind();
/**
* Sets a flag of whether the underlying java element has compilation errors
@@ -147,4 +129,5 @@
public final Metamodel getMetamodel() {
return metamodel;
}
+
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/BaseElementContainer.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/BaseElementContainer.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/BaseElementContainer.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -36,10 +36,12 @@
/**
* Adding elements from the given scope.
*
+ * @return
+ *
* @throws InvalidModelElementException
*
*/
- public abstract void addFrom(final IJavaElement scope, final IProgressMonitor progressMonitor)
+ public abstract List<T> addFrom(final IJavaElement scope, final IProgressMonitor progressMonitor)
throws CoreException, InvalidModelElementException;
/**
@@ -49,14 +51,15 @@
* @param removedResource
* @param progressMonitor
*/
- public final void removeElement(final IResource removedResource, final IProgressMonitor progressMonitor) {
+ public T removeElement(final IResource removedResource, final IProgressMonitor progressMonitor) {
for (Iterator<T> iterator = elements.values().iterator(); iterator.hasNext();) {
T element = iterator.next();
if (removedResource.equals(element.getJavaElement().getResource())) {
iterator.remove();
- return;
+ return element;
}
}
+ return null;
}
/*
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/HTTPMethod.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/HTTPMethod.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/HTTPMethod.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -11,6 +11,9 @@
package org.jboss.tools.ws.jaxrs.core.metamodel;
+import java.util.HashSet;
+import java.util.Set;
+
import javax.ws.rs.HttpMethod;
import org.eclipse.core.runtime.CoreException;
@@ -133,7 +136,8 @@
}
/**
- * Full constructor using the inner 'Builder' static class.
+ * Full constructor using the inner 'MediaTypeCapabilitiesBuilder' static
+ * class.
*
* @param builder
*/
@@ -142,14 +146,15 @@
}
@Override
- public final void merge(final IType javaType, final IProgressMonitor progressMonitor)
+ public final Set<EnumElementChange> merge(final IType javaType, final IProgressMonitor progressMonitor)
throws InvalidModelElementException, CoreException {
-
+ Set<EnumElementChange> changes = new HashSet<EnumElementChange>();
+ setJavaElement(javaType);
// not much to validate on binary types..
if (javaType instanceof BinaryType) {
this.httpVerb = (String) javaType.getAnnotation(HttpMethod.class.getName()).getMemberValuePairs()[0]
.getValue();
- return;
+ return changes;
}
if (!JdtUtils.isTopLevelType(javaType)) {
@@ -161,6 +166,7 @@
if (this.httpVerb == null) {
throw new InvalidModelElementException("Annotation binding not found : missing 'import' statement ?");
}
+ return changes;
}
@@ -173,8 +179,8 @@
}
@Override
- public final BaseElement.EnumType getKind() {
- return BaseElement.EnumType.HTTP_METHOD;
+ public final BaseElement.EnumKind getKind() {
+ return BaseElement.EnumKind.HTTP_METHOD;
}
/**
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/HTTPMethods.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/HTTPMethods.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/HTTPMethods.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -11,6 +11,7 @@
package org.jboss.tools.ws.jaxrs.core.metamodel;
+import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
@@ -48,7 +49,8 @@
* org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
- public final void addFrom(final IJavaElement scope, final IProgressMonitor progressMonitor) throws CoreException {
+ public final List<HTTPMethod> addFrom(final IJavaElement scope, final IProgressMonitor progressMonitor)
+ throws CoreException {
try {
progressMonitor.beginTask("HTTP Methods registration", 2);
// call the scanner
@@ -56,17 +58,20 @@
httpMethodTypes = JAXRSAnnotationsScanner.findHTTPMethodTypes(scope, progressMonitor);
progressMonitor.worked(1);
// HTTPMethods
+ List<HTTPMethod> addedHttpMethods = new ArrayList<HTTPMethod>();
for (IType httpMethodType : httpMethodTypes) {
try {
// FIXME : must retrieve java errors somewhere around here
- elements.put(httpMethodType.getFullyQualifiedName(), new HTTPMethod.Builder(httpMethodType,
- metamodel).build(progressMonitor));
+ HTTPMethod httpMethod = new HTTPMethod.Builder(httpMethodType, metamodel).build(progressMonitor);
+ elements.put(httpMethodType.getFullyQualifiedName(), httpMethod);
+ addedHttpMethods.add(httpMethod);
} catch (InvalidModelElementException e) {
Logger.warn("Type '" + httpMethodType.getFullyQualifiedName()
+ "' is not a valid JAX-RS HTTP ResourceMethod: " + e.getMessage());
}
}
progressMonitor.worked(1);
+ return addedHttpMethods;
} finally {
progressMonitor.done();
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/MediaTypeCapabilities.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/MediaTypeCapabilities.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/MediaTypeCapabilities.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -1,165 +1,148 @@
-/*******************************************************************************
- * 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.metamodel;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Application classes can declare the supported request and response media
- * types using the @Consumes and @Produces annotations respectively. These
- * annotations MAY be applied to a resource method, a resource class, or to an
- * entity provider. Use of these annotations on a resource method overrides any
- * on the resource class or on an entity provider for a method argument or
- * return type. In the absence of either of these annotations, support for any
- * media type is assumed.
- *
- * @author xcoulon
- *
- */
-public class MediaTypeCapabilities implements Comparable<MediaTypeCapabilities> {
-
- private final List<String> consumedMimeTypes = new ArrayList<String>();
-
- private final List<String> producedMimeTypes = new ArrayList<String>();
-
- /**
- * Constructor with default values.
- *
- * @param consumedMimeTypes
- * @param producedMimeTypes
- */
- public MediaTypeCapabilities() {
- }
-
- /**
- * Constructor with specific values.
- *
- * @param consumedMimeTypes
- * @param producedMimeTypes
- */
- public MediaTypeCapabilities(final List<String> consumedMimeTypes, final List<String> producedMimeTypes) {
- if (consumedMimeTypes != null) {
- this.consumedMimeTypes.addAll(consumedMimeTypes);
- }
- if (producedMimeTypes != null) {
- this.producedMimeTypes.addAll(producedMimeTypes);
- }
- }
-
- /**
- * @return the consumedMimeTypes
- */
- public final List<String> getConsumedMimeTypes() {
- return consumedMimeTypes;
- }
-
- /**
- * @return the producedMimeTypes. Never null, size can be 0
- */
- public final List<String> getProducedMimeTypes() {
- return producedMimeTypes;
- }
-
-
- public void merge(MediaTypeCapabilities mediaTypeCapabilities) {
- setConsumedMimeTypes(mediaTypeCapabilities.getConsumedMimeTypes());
- setProducedMimeTypes(mediaTypeCapabilities.getProducedMimeTypes());
- }
-
-
- /**
- * Clears the previous consumed types and replaces with the one given in parametets.
- * @param consumes the list of new consumed mediatypes
- */
- public final void setConsumedMimeTypes(final List<String> consumes) {
- this.consumedMimeTypes.clear();
- if (consumes != null) {
- this.consumedMimeTypes.addAll(consumes);
- }
- }
-
- public final void setProducedMimeTypes(final List<String> produces) {
- this.producedMimeTypes.clear();
- if (produces != null) {
- this.producedMimeTypes.addAll(produces);
- }
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#hashCode()
- */
- @Override
- public final int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((consumedMimeTypes == null) ? 0 : consumedMimeTypes.hashCode());
- result = prime * result + ((producedMimeTypes == null) ? 0 : producedMimeTypes.hashCode());
- return result;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#equals(java.lang.Object)
- */
- @Override
- public final boolean equals(final Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- MediaTypeCapabilities other = (MediaTypeCapabilities) obj;
- if (consumedMimeTypes == null) {
- if (other.consumedMimeTypes != null) {
- return false;
- }
- } else if (!consumedMimeTypes.equals(other.consumedMimeTypes)) {
- return false;
- }
- if (producedMimeTypes == null) {
- if (other.producedMimeTypes != null) {
- return false;
- }
- } else if (!producedMimeTypes.equals(other.producedMimeTypes)) {
- return false;
- }
- return true;
- }
-
- @Override
- public final int compareTo(final MediaTypeCapabilities other) {
- int comp = compare(this.getConsumedMimeTypes(), other.getConsumedMimeTypes());
- if(comp != 0) {
- return comp;
- }
- return compare(this.getProducedMimeTypes(), other.getProducedMimeTypes());
- }
-
- private static int compare(final List<String> oneList, final List<String> otherList) {
- for(int i = 0; i < oneList.size(); i++) {
- if(i >= otherList.size()) {
- return 1; // 'this' is greater than 'other'
- }
- int comp = oneList.get(i).compareTo(otherList.get(i));
- if(comp != 0) {
- return comp;
- }
- }
- return 0;
- }
-
-
-}
+package org.jboss.tools.ws.jaxrs.core.metamodel;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jdt.core.IJavaElement;
+
+/**
+ * Application classes can declare the supported request and response media
+ * types using the @Consumes and @Produces annotations respectively. These
+ * annotations MAY be applied to a resource method, a resource class, or to an
+ * entity provider. Use of these annotations on a resource method overrides any
+ * on the resource class or on an entity provider for a method argument or retu
+ * import java.util.Iterator; rn type. In the absence of either of these
+ * annotations, support for any media type is assumed.
+ *
+ * @author xcoulon
+ *
+ */
+public class MediaTypeCapabilities implements Comparable<MediaTypeCapabilities> {
+
+ /** The Java Element that carries the media types. */
+ private IJavaElement element;
+
+ private final List<String> mediatypes = new ArrayList<String>();
+
+ /*
+ * public static class MediaTypeCapabilitiesBuilder {
+ *
+ * private List<String> mediaTypes;
+ *
+ * private IAnnotation annotation;
+ *
+ * private IMember annotatedMember;
+ *
+ * public MediaTypeCapabilitiesBuilder(IMember annotatedMember) {
+ * this.annotatedMember = annotatedMember; }
+ *
+ * public MediaTypeCapabilitiesBuilder annotation(IAnnotation annotation) {
+ * this.annotation = annotation; return this; }
+ *
+ * public MediaTypeCapabilitiesBuilder mediaTypes(List<String> mediaTypes) {
+ * this.mediaTypes = mediaTypes; return this; }
+ *
+ * public MediaTypeCapabilities build() { IJavaElement element = (annotation
+ * != null) ? annotation : annotatedMember;
+ *
+ * if (mediaTypes == null || mediaTypes.isEmpty()) { this.mediaTypes =
+ * Collections.emptyList(); } return new MediaTypeCapabilities(mediaTypes,
+ * element); } }
+ */
+
+ /**
+ * Full constructor, used in conjunction with its
+ * MediaTypeCapabilitiesBuilder private MediaTypeCapabilities(List<String>
+ * mediaTypes, IJavaElement element) { super(mediaTypes); this.element =
+ * element; }
+ */
+
+ /**
+ * Full constructor.
+ */
+ public MediaTypeCapabilities(IJavaElement element) {
+ this.element = element;
+ }
+
+ /**
+ * Full constructor with mediatypes
+ */
+ public MediaTypeCapabilities(IJavaElement element, List<String> mediatypes) {
+ this.element = element;
+ this.mediatypes.addAll(mediatypes);
+ }
+
+ /**
+ * Replace the current media types capabilities with the ones given in
+ * parameter
+ *
+ * @param mediaTypes
+ * the new supported media types
+ * @return true if changed were made
+ */
+ public boolean merge(MediaTypeCapabilities capabilities) {
+ boolean changed = false;
+ // remove obsolete values
+ changed = mediatypes.retainAll(capabilities.getMediatypes());
+ // avoid duplicates
+ mediatypes.removeAll(capabilities.getMediatypes());
+ changed = changed | mediatypes.addAll(capabilities.getMediatypes());
+ this.element = capabilities.getElement();
+ return changed;
+ }
+
+ /**
+ * @return the annotation
+ */
+ public IJavaElement getElement() {
+ return element;
+ }
+
+ /**
+ * @return the mediatypes
+ */
+ public List<String> getMediatypes() {
+ return mediatypes;
+ }
+
+ @Override
+ public int compareTo(MediaTypeCapabilities otherMediaTypes) {
+ for (int i = 0; i < mediatypes.size(); i++) {
+ if (i >= otherMediaTypes.size()) {
+ return 1; // 'this' is greater than 'other'
+ }
+ int comp = mediatypes.get(i).compareTo(otherMediaTypes.get(i));
+ if (comp != 0) {
+ return comp;
+ }
+ }
+ return 0;
+ }
+
+ public String get(int i) {
+ return mediatypes.get(i);
+ }
+
+ public int size() {
+ return mediatypes.size();
+ }
+
+ public boolean contains(String mediatype) {
+ return mediatypes.contains(mediatype);
+ }
+
+ public boolean isEmpty() {
+ return mediatypes.isEmpty();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return "MediaTypeCapabilities [element=" + element + ", mediatypes=" + mediatypes + "]";
+ }
+
+}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Mergeable.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Mergeable.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Mergeable.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -11,19 +11,28 @@
package org.jboss.tools.ws.jaxrs.core.metamodel;
+import java.util.Set;
+
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
public interface Mergeable<T> {
/**
- * Merge of the current JAX-RS element with the java element given in parameter.
- * @param element the java element that changed
- * @param progressMonitor the progress monitor
- * @throws InvalidModelElementException in case of underlying exception
- * @throws CoreException in case of underlying exception
+ * Merge of the current JAX-RS element with the java element given in
+ * parameter.
+ *
+ * @param element
+ * the java element that changed
+ * @param progressMonitor
+ * the progress monitor
+ * @return a list of changes
+ * @throws InvalidModelElementException
+ * in case of underlying exception
+ * @throws CoreException
+ * in case of underlying exception
*/
- abstract void merge(T element, IProgressMonitor progressMonitor) throws InvalidModelElementException, CoreException;
+ abstract Set<EnumElementChange> merge(T element, IProgressMonitor progressMonitor)
+ throws InvalidModelElementException, CoreException;
-
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Metamodel.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Metamodel.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Metamodel.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -13,6 +13,7 @@
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Date;
import java.util.List;
import javax.ws.rs.Consumes;
@@ -90,6 +91,8 @@
/** The HTTP ResourceMethod elements container. */
private final HTTPMethods httpMethods;
+ private final Routes routes;
+
/**
* Full constructor.
*
@@ -101,9 +104,10 @@
public Metamodel(final IJavaProject javaProject) throws CoreException {
this.javaProject = javaProject;
applications = new Applications(this);
- providers = new Providers(javaProject, this);
+ providers = new Providers.Builder(javaProject, this).build();
resources = new Resources(this);
httpMethods = new HTTPMethods(this);
+ routes = new Routes(this);
jaxrsAnnotationNames.addAll(Arrays.asList(new String[] { Provider.class.getName(), Consumes.class.getName(),
Produces.class.getName(), Path.class.getName(), HttpMethod.class.getName() }));
javaProject.getProject().setSessionProperty(METAMODEL_QUALIFIED_NAME, this);
@@ -156,6 +160,13 @@
/**
* @return the httpMethods
*/
+ public final Application getApplication() {
+ return applications.size() == 1 ? applications.iterator().next().getValue() : null;
+ }
+
+ /**
+ * @return the httpMethods
+ */
public final HTTPMethods getHttpMethods() {
return httpMethods;
}
@@ -196,17 +207,26 @@
public final void addElements(final IJavaElement scope, final IProgressMonitor progressMonitor)
throws CoreException {
try {
- progressMonitor.beginTask("Computing JAX-RS metamodel", 4);
- applications.addFrom(scope, progressMonitor);
+ progressMonitor.beginTask("Computing JAX-RS metamodel", 5);
+ applications.addFrom(scope, new SubProgressMonitor(progressMonitor, 1,
+ SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK));
progressMonitor.worked(1);
- httpMethods.addFrom(scope, progressMonitor);
+ httpMethods.addFrom(scope, new SubProgressMonitor(progressMonitor, 1,
+ SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK));
progressMonitor.worked(1);
providers.addFrom(scope, new SubProgressMonitor(progressMonitor, 1,
SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK));
progressMonitor.worked(1);
- resources.addFrom(scope, new SubProgressMonitor(progressMonitor, 1,
+ @SuppressWarnings("unused")
+ List<Resource> addedResources = resources.addFrom(scope, new SubProgressMonitor(progressMonitor, 1,
SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK));
progressMonitor.worked(1);
+ /*
+ * routes.addFrom(addedResources, new
+ * SubProgressMonitor(progressMonitor, 1,
+ * SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK));
+ */
+ progressMonitor.worked(1);
} finally {
progressMonitor.done();
}
@@ -220,18 +240,26 @@
* the resource to which the JAX-RS element is mapped
* @param progressMonitor
* the progress monitor
+ * @throws CoreException
*/
- public final void remove(final IResource resource, final IProgressMonitor progressMonitor) {
+ public final void remove(final IResource resource, final IProgressMonitor progressMonitor) throws CoreException {
try {
- progressMonitor.beginTask("Computing JAX-RS metamodel", 4);
- applications.removeElement(resource, progressMonitor);
+ progressMonitor.beginTask("Computing JAX-RS metamodel", 5);
+ applications.removeElement(resource, new SubProgressMonitor(progressMonitor, 1,
+ SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK));
progressMonitor.worked(1);
- httpMethods.removeElement(resource, progressMonitor);
+ httpMethods.removeElement(resource, new SubProgressMonitor(progressMonitor, 1,
+ SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK));
progressMonitor.worked(1);
- resources.removeElement(resource, progressMonitor);
+ Resource removedResource = resources.removeElement(resource, new SubProgressMonitor(progressMonitor, 1,
+ SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK));
progressMonitor.worked(1);
- providers.removeElement(resource, progressMonitor);
+ providers.removeElement(resource, new SubProgressMonitor(progressMonitor, 1,
+ SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK));
progressMonitor.worked(1);
+ routes.removeFrom(removedResource, new SubProgressMonitor(progressMonitor, 1,
+ SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK));
+ progressMonitor.worked(1);
} finally {
progressMonitor.done();
}
@@ -309,30 +337,36 @@
*/
public final void applyDelta(final IResourceDelta delta, final IProgressMonitor progressMonitor)
throws CoreException {
- IResource resource = delta.getResource();
- ICompilationUnit compilationUnit = JdtUtils.getCompilationUnit(resource);
- if (resource.exists()) {
- IMarker[] markers = resource
- .findMarkers(JaxrsMetamodelBuilder.JAVA_PROBLEM, true, IResource.DEPTH_INFINITE);
- if (reportErrors(compilationUnit, markers)) {
- Logger.warn("Resource '" + resource.getName() + "' contains errors.");
- return;
+ long startTime = new Date().getTime();
+ try {
+ IResource resource = delta.getResource();
+ ICompilationUnit compilationUnit = JdtUtils.getCompilationUnit(resource);
+ if (resource.exists()) {
+ IMarker[] markers = resource.findMarkers(JaxrsMetamodelBuilder.JAVA_PROBLEM, true,
+ IResource.DEPTH_INFINITE);
+ if (reportErrors(compilationUnit, markers)) {
+ Logger.warn("Resource '" + resource.getName() + "' contains errors.");
+ return;
+ }
}
- }
- switch (delta.getKind()) {
- case IResourceDelta.ADDED:
- addElements(compilationUnit, progressMonitor);
- break;
- case IResourceDelta.REMOVED:
- remove(resource, progressMonitor);
- break;
- case IResourceDelta.CHANGED:
- if ((delta.getFlags() & IResourceDelta.CONTENT) != 0) {
- mergeElement(compilationUnit, progressMonitor);
+ switch (delta.getKind()) {
+ case IResourceDelta.ADDED:
+ addElements(compilationUnit, progressMonitor);
break;
+ case IResourceDelta.REMOVED:
+ remove(resource, progressMonitor);
+ break;
+ case IResourceDelta.CHANGED:
+ if ((delta.getFlags() & IResourceDelta.CONTENT) != 0) {
+ mergeElement(compilationUnit, progressMonitor);
+ break;
+ }
}
- default:
- break;
+ } finally {
+ long endTime = new Date().getTime();
+ Logger.info("JAX-RS Metamodel delta for project '" + javaProject.getElementName() + "' applied in "
+ + (endTime - startTime) + "ms.");
+
}
}
@@ -421,7 +455,11 @@
this.httpMethods.reset();
this.providers.reset();
this.resources.reset();
+ this.routes.reset();
+ }
+ public Routes getRoutes() {
+ return routes;
}
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Provider.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Provider.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Provider.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -12,6 +12,7 @@
package org.jboss.tools.ws.jaxrs.core.metamodel;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -48,7 +49,7 @@
// the mime-types the the provider consumes or produces. May be null for an
// ExceptionMapper
- private final Map<EnumProviderKind, List<String>> mediaTypeCapabilities = new HashMap<EnumProviderKind, List<String>>();
+ private final Map<EnumProviderKind, MediaTypeCapabilities> mediaTypeCapabilities = new HashMap<EnumProviderKind, MediaTypeCapabilities>();
private final Map<EnumProviderKind, IType> providedKinds = new HashMap<EnumProviderKind, IType>();
@@ -95,7 +96,8 @@
}
/**
- * Full constructor using the inner 'Builder' static class.
+ * Full constructor using the inner 'MediaTypeCapabilitiesBuilder' static
+ * class.
*
* @param builder
*/
@@ -106,20 +108,23 @@
/**
* @param javaType
+ * @return
* @throws InvalidModelElementException
* @throws CoreException
*/
@Override
- public final void merge(final IType javaType, final IProgressMonitor progressMonitor)
+ public final Set<EnumElementChange> merge(final IType javaType, final IProgressMonitor progressMonitor)
throws InvalidModelElementException, CoreException {
if (!JdtUtils.isTopLevelType(javaType)) {
throw new InvalidModelElementException("Type is not a top-level type");
}
+ Set<EnumElementChange> changes = new HashSet<EnumElementChange>();
+
CompilationUnit compilationUnit = getCompilationUnit(progressMonitor);
Set<IProblem> problems = JdtUtils.resolveErrors(javaType, compilationUnit);
if (problems != null && problems.size() > 0) {
// metamodel.reportErrors(javaType, problems);
- return;
+ return changes;
}
IAnnotationBinding annotationBinding = JdtUtils.resolveAnnotationBinding(javaType, compilationUnit,
javax.ws.rs.ext.Provider.class);
@@ -147,12 +152,12 @@
// annotations
if (providerKinds != null) {
for (Entry<EnumProviderKind, IType> entry : providerKinds.entrySet()) {
- List<String> mediaTypes = resolveMediaTypeCapabilities(getJavaElement(), compilationUnit,
+ MediaTypeCapabilities mediaTypes = resolveMediaTypeCapabilities(getJavaElement(), compilationUnit,
entry.getKey());
- this.addProvidedKind(entry.getKey(), entry.getValue(), mediaTypes);
+ addProviderKind(entry.getKey(), entry.getValue(), mediaTypes);
}
}
-
+ return changes;
}
/**
@@ -163,7 +168,7 @@
}
- public static List<String> resolveMediaTypeCapabilities(final IType javaType,
+ public static MediaTypeCapabilities resolveMediaTypeCapabilities(final IType javaType,
final CompilationUnit compilationUnit, final EnumProviderKind key) throws CoreException {
if (key == EnumProviderKind.PRODUCER) {
return JAXRSAnnotationsScanner.resolveMediaTypeCapabilities(javaType, compilationUnit, Produces.class);
@@ -173,8 +178,8 @@
return null;
}
- public final BaseElement.EnumType getKind() {
- return BaseElement.EnumType.PROVIDER;
+ public final BaseElement.EnumKind getKind() {
+ return BaseElement.EnumKind.PROVIDER;
}
/**
@@ -187,9 +192,9 @@
}
/**
- * @return the mimetype
+ * @return the media type capabilities
*/
- public final List<String> getMediaTypeCapabilities(final EnumProviderKind providerKind) {
+ public final MediaTypeCapabilities getMediaTypeCapabilities(final EnumProviderKind providerKind) {
return mediaTypeCapabilities.get(providerKind);
}
@@ -200,10 +205,19 @@
return providedKinds;
}
- public final void addProvidedKind(final EnumProviderKind providerKind, final IType providedType,
- final List<String> mediaTypes) {
- this.providedKinds.put(providerKind, providedType);
- this.mediaTypeCapabilities.put(providerKind, mediaTypes);
+ private final void addProviderKind(final EnumProviderKind providerKind, final IType providedType,
+ final MediaTypeCapabilities mediaTypes) {
+ switch (providerKind) {
+ case CONSUMER:
+ case PRODUCER:
+ if (mediaTypeCapabilities.containsKey(providerKind)) {
+ this.mediaTypeCapabilities.get(providerKind).merge(mediaTypes);
+ } else {
+ this.mediaTypeCapabilities.put(providerKind, mediaTypes);
+ }
+ case EXCEPTION_MAPPER:
+ this.providedKinds.put(providerKind, providedType);
+ }
}
/*
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Providers.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Providers.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Providers.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -39,23 +39,38 @@
/** The interfaces that a provider can implement, indexed by kind */
private final Map<EnumProviderKind, IType> providerInterfaces;
+ public static class Builder {
+
+ private final IJavaProject javaProject;
+ private final Metamodel metamodel;
+
+ public Builder(final IJavaProject javaProject, final Metamodel metamodel) {
+ this.javaProject = javaProject;
+ this.metamodel = metamodel;
+ }
+
+ public Providers build() throws CoreException {
+ Map<EnumProviderKind, IType> providerInterfaces = new HashMap<EnumProviderKind, IType>();
+ providerInterfaces.put(EnumProviderKind.CONSUMER,
+ JdtUtils.resolveType("javax.ws.rs.ext.MessageBodyReader", javaProject.getJavaProject(), null));
+ providerInterfaces.put(EnumProviderKind.PRODUCER,
+ JdtUtils.resolveType("javax.ws.rs.ext.MessageBodyWriter", javaProject.getJavaProject(), null));
+ providerInterfaces.put(EnumProviderKind.EXCEPTION_MAPPER,
+ JdtUtils.resolveType("javax.ws.rs.ext.ExceptionMapper", javaProject.getJavaProject(), null));
+ return new Providers(metamodel, providerInterfaces);
+ }
+
+ }
+
/**
* Full constructor
*
* @param javaProject
- * @param metamodel
- * @throws CoreException
+ * @param providerInterfaces
*/
- // TODO : use the Builder pattern here ?
- public Providers(final IJavaProject javaProject, final Metamodel metamodel) throws CoreException {
+ private Providers(final Metamodel metamodel, final Map<EnumProviderKind, IType> providerInterfaces) {
super(metamodel);
- providerInterfaces = new HashMap<EnumProviderKind, IType>();
- providerInterfaces.put(EnumProviderKind.CONSUMER,
- JdtUtils.resolveType("javax.ws.rs.ext.MessageBodyReader", javaProject.getJavaProject(), null));
- providerInterfaces.put(EnumProviderKind.PRODUCER,
- JdtUtils.resolveType("javax.ws.rs.ext.MessageBodyWriter", javaProject.getJavaProject(), null));
- providerInterfaces.put(EnumProviderKind.EXCEPTION_MAPPER,
- JdtUtils.resolveType("javax.ws.rs.ext.ExceptionMapper", javaProject.getJavaProject(), null));
+ this.providerInterfaces = providerInterfaces;
}
public final Map<EnumProviderKind, IType> getProviderInterfaces() {
@@ -91,7 +106,8 @@
* @throws CoreException
*/
@Override
- public final void addFrom(final IJavaElement scope, final IProgressMonitor progressMonitor) throws CoreException {
+ public final List<Provider> addFrom(final IJavaElement scope, final IProgressMonitor progressMonitor)
+ throws CoreException {
progressMonitor.beginTask("Adding providers", 1);
try {
// FIXME : add support for javax.ws.rs.ext.ContextResolver(s) (most
@@ -101,16 +117,19 @@
List<IType> providerTypes = JAXRSAnnotationsScanner.findProviderTypes(scope, false, progressMonitor);
// FIXME : should check type is a top level and annotation binding
// exists. Throw an exception in constructor ?
+ List<Provider> addedProviders = new ArrayList<Provider>();
for (IType providerType : providerTypes) {
try {
- elements.put(providerType.getFullyQualifiedName(), new Provider.Builder(providerType, metamodel,
- this).build(progressMonitor));
+ Provider provider = new Provider.Builder(providerType, metamodel, this).build(progressMonitor);
+ elements.put(providerType.getFullyQualifiedName(), provider);
+ addedProviders.add(provider);
} catch (InvalidModelElementException e) {
Logger.warn("Type '" + providerType.getFullyQualifiedName() + "' is not a valid JAX-RS Provider : "
+ e.getMessage());
}
}
progressMonitor.worked(1);
+ return addedProviders;
} finally {
progressMonitor.done();
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Resource.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Resource.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Resource.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -11,17 +11,15 @@
package org.jboss.tools.ws.jaxrs.core.metamodel;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -33,7 +31,7 @@
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.jboss.tools.ws.jaxrs.core.internal.builder.JAXRSAnnotationsScanner;
import org.jboss.tools.ws.jaxrs.core.internal.builder.JaxrsMetamodelBuilder;
-import org.jboss.tools.ws.jaxrs.core.internal.utils.CollectionFilterUtil;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.CollectionFilterUtils;
import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
import org.jboss.tools.ws.jaxrs.core.utils.JdtUtils;
@@ -48,21 +46,6 @@
public class Resource extends BaseElement<IType> {
/**
- * indicates if the resource is a root resource (type annotated with @Path)
- * or not. Can change
- */
- boolean isRootResource = false;
-
- /** The URI path template. As with annotations, it can change */
- private String uriPathTemplate;
-
- /**
- * the default media type capabilities offered by this resource. May be
- * overridden at method level
- */
- final MediaTypeCapabilities mediaTypeCapabilities = new MediaTypeCapabilities();
-
- /**
* A map of all JAX-RS resourceMethods this resource has, including
* <ul>
* <li>the subresource resourceMethods (ie, annotated with both an @Path and
@@ -77,13 +60,19 @@
*/
final Map<String, ResourceMethod> resourceMethods = new HashMap<String, ResourceMethod>();
+ /** The resource mapping. */
+ private final ResourceMapping resourceMapping;
+
+ /** Optional Application. */
+ private Application application = null;
+
/**
* Internal 'Resource' element builder.
*
* @author xcoulon
*
*/
- public static class Builder {
+ public static class ResourceBuilder {
private final Metamodel metamodel;
private final IType javaType;
@@ -94,7 +83,7 @@
* @param javaType
* @param metamodel
*/
- public Builder(final IType javaType, final Metamodel metamodel) {
+ public ResourceBuilder(final IType javaType, final Metamodel metamodel) {
this.javaType = javaType;
this.metamodel = metamodel;
}
@@ -115,77 +104,66 @@
}
/**
- * Full constructor using the inner 'Builder' static class.
+ * Full constructor using the inner 'MediaTypeCapabilitiesBuilder' static
+ * class.
*
* @param builder
*/
- private Resource(Builder builder) {
+ private Resource(ResourceBuilder builder) {
super(builder.javaType, builder.metamodel);
+ this.resourceMapping = new ResourceMapping(this);
}
+ public final ResourceMapping getMapping() {
+ return resourceMapping;
+ }
+
public final boolean isRootResource() {
- return isRootResource;
+ return getKind() == EnumKind.ROOT_RESOURCE;
}
+ /**
+ * {@inheritDoc}
+ */
@Override
- public final EnumType getKind() {
- if (isRootResource) {
- return EnumType.ROOT_RESOURCE;
+ public final EnumKind getKind() {
+ if (this.resourceMapping.getUriPathTemplateFragment() != null) {
+ return EnumKind.ROOT_RESOURCE;
}
- return EnumType.SUBRESOURCE;
+ return EnumKind.SUBRESOURCE;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @return
+ *
+ * @throws CoreException
+ */
@Override
- public final void merge(final IType javaType, final IProgressMonitor progressMonitor) throws CoreException,
- InvalidModelElementException {
+ public final Set<EnumElementChange> merge(final IType javaType, final IProgressMonitor progressMonitor)
+ throws CoreException, InvalidModelElementException {
if (!JdtUtils.isTopLevelType(javaType)) {
throw new InvalidModelElementException("Type is not a top-level type");
}
+ Set<EnumElementChange> changes = new HashSet<EnumElementChange>();
CompilationUnit compilationUnit = getCompilationUnit(progressMonitor);
// TODO : base64.decode()
- // if (state == EnumState.CREATED) {
Set<IProblem> problems = JdtUtils.resolveErrors(javaType, compilationUnit);
if (problems != null && problems.size() > 0) {
- return;
+ for (IProblem problem : problems) {
+ Logger.debug("Problem found: " + problem.getMessage());
+ }
+ return changes;
}
- // }
-
- // String serviceURI = container.getMetamodel().getServiceURI();
- this.uriPathTemplate = (String) JdtUtils.resolveAnnotationAttributeValue(javaType, compilationUnit, Path.class,
- "value");
- if (uriPathTemplate != null) {
- isRootResource = true;
- } else {
- isRootResource = false;
- }
-
- mediaTypeCapabilities.setConsumedMimeTypes(JAXRSAnnotationsScanner.resolveMediaTypeCapabilities(javaType,
- compilationUnit, Consumes.class));
- mediaTypeCapabilities.setProducedMimeTypes(JAXRSAnnotationsScanner.resolveMediaTypeCapabilities(javaType,
- compilationUnit, Produces.class));
-
- mergeMethods(javaType, compilationUnit, progressMonitor);
+ Set<EnumElementChange> resourceChanges = this.resourceMapping.merge(compilationUnit);
+ mergeMethods(javaType, compilationUnit, resourceChanges, progressMonitor);
+ return changes;
}
- /**
- * {@inheritDoc}
- *
- * @throws CoreException
- */
- @Override
- public void validate(IProgressMonitor progressMonitor) throws CoreException {
- Logger.debug("Validating " + super.getJavaElement().getFullyQualifiedName());
- super.getJavaElement().getResource()
- .deleteMarkers(JaxrsMetamodelBuilder.JAXRS_PROBLEM, true, IResource.DEPTH_INFINITE);
- for (Entry<String, ResourceMethod> entry : resourceMethods.entrySet()) {
- entry.getValue().validate(progressMonitor);
- }
- Logger.debug("Validation done.");
- }
-
// FIXME deal with interfaces/implementations
- public final void mergeMethods(final IJavaElement scope, final CompilationUnit compilationUnit,
- final IProgressMonitor progressMonitor) throws CoreException {
+ private final void mergeMethods(final IJavaElement scope, final CompilationUnit compilationUnit,
+ final Set<EnumElementChange> resourceChanges, final IProgressMonitor progressMonitor) throws CoreException {
Set<String> httpMethodNames = getMetamodel().getHttpMethods().getTypeNames();
List<IMethod> javaMethods = JAXRSAnnotationsScanner
.findResourceMethods(scope, httpMethodNames, progressMonitor);
@@ -197,7 +175,10 @@
for (Iterator<String> iterator = resourceMethods.keySet().iterator(); iterator.hasNext();) {
String key = iterator.next();
if (!keys.containsValue(key)) {
+ ResourceMethod resourceMethod = resourceMethods.get(key);
+ Logger.debug("Removed " + resourceMethod.toString());
iterator.remove();
+ getMetamodel().getRoutes().removeFrom(resourceMethod, progressMonitor);
}
}
for (IMethod javaMethod : javaMethods) {
@@ -205,12 +186,32 @@
String key = keys.get(javaMethod);
if (resourceMethods.containsKey(key)) {
ResourceMethod resourceMethod = resourceMethods.get(key);
- resourceMethod.merge(javaMethod, progressMonitor);
+
+ Set<EnumElementChange> resourceMethodChanges = resourceMethod.merge(javaMethod, progressMonitor);
+ Set<EnumElementChange> changes = new HashSet<EnumElementChange>();
+ changes.addAll(resourceChanges);
+ changes.addAll(resourceMethodChanges);
+ for (EnumElementChange change : changes) {
+ switch (change) {
+ case KIND:
+ getMetamodel().getRoutes().merge(resourceMethod, progressMonitor);
+ break;
+ case MAPPING:
+ List<Route> routes = this.getMetamodel().getRoutes().getByResourceMethod(resourceMethod);
+ if (routes != null) {
+ for (Route route : routes) {
+ route.getEndpoint().merge();
+ }
+ }
+ break;
+ }
+ }
Logger.debug("Updated " + resourceMethod.toString());
} else {
- ResourceMethod resourceMethod = new ResourceMethod.Builder(javaMethod, this, getMetamodel())
- .build(progressMonitor);
+ ResourceMethod resourceMethod = new ResourceMethod(javaMethod, this, getMetamodel(),
+ progressMonitor);
resourceMethods.put(key, resourceMethod);
+ getMetamodel().getRoutes().merge(resourceMethod, progressMonitor);
Logger.debug("Added " + resourceMethod.toString());
}
} catch (InvalidModelElementException e) {
@@ -220,7 +221,26 @@
}
}
+ /**
+ * {@inheritDoc}
+ *
+ * @throws CoreException
+ */
@Override
+ public void validate(IProgressMonitor progressMonitor) throws CoreException {
+ Logger.debug("Validating " + super.getJavaElement().getFullyQualifiedName());
+ super.getJavaElement().getResource()
+ .deleteMarkers(JaxrsMetamodelBuilder.JAXRS_PROBLEM, true, IResource.DEPTH_INFINITE);
+ for (Entry<String, ResourceMethod> entry : resourceMethods.entrySet()) {
+ entry.getValue().validate(progressMonitor);
+ }
+ Logger.debug("Validation done.");
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public final void hasErrors(final boolean hasErrors) {
super.hasErrors(hasErrors);
if (!hasErrors) {
@@ -238,34 +258,24 @@
return key.append(')').toString();
}
- /**
- * @return the mediaTypeCapabilities
- */
- public final MediaTypeCapabilities getMediaTypeCapabilities() {
- return mediaTypeCapabilities;
- }
-
public final String getName() {
return getJavaElement().getElementName();
}
- /**
- * @return the uriPathTemplate
- */
- public final String getUriPathTemplate() {
- return uriPathTemplate;
- }
-
public final ResourceMethod getByJavaMethod(final IMethod javaMethod) throws JavaModelException {
return resourceMethods.get(computeKey(javaMethod));
}
+ public final Application getApplication() {
+ return application;
+ }
+
public final List<ResourceMethod> getResourceMethods() {
- return CollectionFilterUtil.filterElementsByKind(resourceMethods.values(), EnumType.RESOURCE_METHOD);
+ return CollectionFilterUtils.filterElementsByKind(resourceMethods.values(), EnumKind.RESOURCE_METHOD);
}
public final List<ResourceMethod> getSubresourceMethods() {
- return CollectionFilterUtil.filterElementsByKind(resourceMethods.values(), EnumType.SUBRESOURCE_METHOD);
+ return CollectionFilterUtils.filterElementsByKind(resourceMethods.values(), EnumKind.SUBRESOURCE_METHOD);
}
/**
@@ -275,25 +285,33 @@
* SUBRESOURCE_METHOD
*/
public final List<ResourceMethod> getAllMethods() {
- return CollectionFilterUtil.filterElementsByKind(resourceMethods.values(), EnumType.RESOURCE_METHOD,
- EnumType.SUBRESOURCE_METHOD);
+ // return
+ // CollectionFilterUtils.filterElementsByKind(resourceMethods.values(),
+ // EnumKind.RESOURCE_METHOD,
+ // EnumKind.SUBRESOURCE_METHOD);
+ return new ArrayList<ResourceMethod>(resourceMethods.values());
}
/**
* @return the subresourceLocators
*/
public final List<ResourceMethod> getSubresourceLocators() {
- return CollectionFilterUtil.filterElementsByKind(resourceMethods.values(), EnumType.SUBRESOURCE_LOCATOR);
+ return CollectionFilterUtils.filterElementsByKind(resourceMethods.values(), EnumKind.SUBRESOURCE_LOCATOR);
}
- public final ResourceMethod getByURIMapping(final HTTPMethod httpMethod, final String uriPathTemplateFragment,
+ public final ResourceMethod getByMapping(final HTTPMethod httpMethod, final String uriPathTemplateFragment,
final String consumes, final String produces) {
for (ResourceMethod resourceMethod : resourceMethods.values()) {
- if (resourceMethod.getUriMapping().matches(httpMethod, uriPathTemplateFragment, consumes, produces)) {
+ if (resourceMethod.getMapping().matches(httpMethod, uriPathTemplateFragment, consumes, produces)) {
return resourceMethod;
}
}
return null;
}
+ @Override
+ public String toString() {
+ return new StringBuffer().append(getName()).append(" (root:").append(isRootResource()).append(") ")
+ .append(resourceMapping).toString();
+ }
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMethod.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMethod.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMethod.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -11,13 +11,13 @@
package org.jboss.tools.ws.jaxrs.core.metamodel;
+import java.util.HashSet;
import java.util.Set;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.compiler.IProblem;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.IMethodBinding;
import org.eclipse.jdt.core.dom.ITypeBinding;
@@ -27,13 +27,16 @@
* @author xcoulon
*
*/
+// FIXME : Use protected vs public methods to retrieve resolved/internal
+// mappings ?
+
public class ResourceMethod extends BaseElement<IMethod> {
private final Resource parentResource;
- private UriMapping uriMapping = null;
+ private final ResourceMethodMapping resourceMethodMapping;
- private EnumType kind = null;
+ private EnumKind kind = null;
/**
* return type of the java method. Null if this is not a subresource
@@ -42,92 +45,69 @@
private IType returnType = null;
/**
- * Internal 'Resource' element builder.
+ * Full constructor.
*
- * @author xcoulon
- *
+ * @throws CoreException
+ * @throws InvalidModelElementException
*/
- public static class Builder {
-
- private final Metamodel metamodel;
- private final IMethod javaMethod;
- private final Resource parentResource;
-
- /**
- * Mandatory attributes of the enclosing 'ResourceMethod' element.
- *
- * @param javaMethod
- * @param metamodel
- * @param parentResource
- */
- public Builder(final IMethod javaMethod, final Resource parentResource, final Metamodel metamodel) {
- this.javaMethod = javaMethod;
- this.metamodel = metamodel;
- this.parentResource = parentResource;
- }
-
- /**
- * Builds and returns the elements. Internally calls the merge() method.
- *
- * @param progressMonitor
- * @return
- * @throws InvalidModelElementException
- * @throws CoreException
- */
- public ResourceMethod build(IProgressMonitor progressMonitor) throws InvalidModelElementException,
- CoreException {
- ResourceMethod resourceMethod = new ResourceMethod(this);
- resourceMethod.merge(javaMethod, progressMonitor);
- return resourceMethod;
- }
+ public ResourceMethod(final IMethod javaMethod, final Resource parentResource, final Metamodel metamodel,
+ final IProgressMonitor progressMonitor) throws InvalidModelElementException, CoreException {
+ super(javaMethod, metamodel);
+ this.parentResource = parentResource;
+ this.resourceMethodMapping = new ResourceMethodMapping(this);
+ merge(javaMethod, progressMonitor);
}
/**
- * Full constructor using the inner 'Builder' static class.
- *
- * @param builder
- */
- public ResourceMethod(final Builder builder) throws InvalidModelElementException, CoreException {
- super(builder.javaMethod, builder.metamodel);
- this.parentResource = builder.parentResource;
- }
-
- /**
* {@inheritDoc}
*/
@Override
- public final void merge(final IMethod javaMethod, final IProgressMonitor progressMonitor)
+ // FIXME : always returning at least MAPPING ??
+ public final Set<EnumElementChange> merge(final IMethod javaMethod, final IProgressMonitor progressMonitor)
throws InvalidModelElementException, CoreException {
CompilationUnit compilationUnit = getCompilationUnit(progressMonitor);
- if (state == EnumState.CREATED) {
- Set<IProblem> problems = JdtUtils.resolveErrors(javaMethod, compilationUnit);
- if (problems != null && problems.size() > 0) {
- // metamodel.reportErrors(javaMethod, problems);
- return;
- }
+ Set<EnumElementChange> changes = new HashSet<EnumElementChange>();
+
+ if (this.resourceMethodMapping.merge(compilationUnit)) {
+ changes.add(EnumElementChange.MAPPING);
}
- IMethodBinding methodBinding = JdtUtils.resolveMethodBinding(javaMethod, compilationUnit);
- if (uriMapping == null) {
- this.uriMapping = new UriMapping.Builder(javaMethod, getMetamodel()).build(compilationUnit);
- } else {
- this.uriMapping.merge(compilationUnit);
- }
- HTTPMethod httpMethod = uriMapping.getHTTPMethod();
- String uriPathTemplateFragment = uriMapping.getUriPathTemplateFragment();
+ /*
+ * Set<IProblem> problems = JdtUtils.resolveErrors(javaMethod,
+ * compilationUnit); if (problems != null && problems.size() > 0) { //
+ * metamodel.reportErrors(javaMethod, problems); return; }
+ */
+ HTTPMethod httpMethod = resourceMethodMapping.getHTTPMethod();
+ String uriPathTemplateFragment = resourceMethodMapping.getUriPathTemplateFragment();
+ EnumKind nextKind = null;
if (uriPathTemplateFragment == null && httpMethod != null) {
- this.kind = EnumType.RESOURCE_METHOD;
+ nextKind = EnumKind.RESOURCE_METHOD;
} else if (uriPathTemplateFragment != null && httpMethod != null) {
- this.kind = EnumType.SUBRESOURCE_METHOD;
+ nextKind = EnumKind.SUBRESOURCE_METHOD;
} else if (uriPathTemplateFragment != null && httpMethod == null) {
- this.kind = EnumType.SUBRESOURCE_LOCATOR;
+ nextKind = EnumKind.SUBRESOURCE_LOCATOR;
} else {
throw new InvalidModelElementException(
"ResourceMethod has no valid @Path annotation and no HTTP ResourceMethod annotation");
}
+ if (this.kind != nextKind) {
+ if (this.kind == EnumKind.SUBRESOURCE_LOCATOR || nextKind == EnumKind.SUBRESOURCE_LOCATOR) {
+ changes.add(EnumElementChange.KIND);
+ } else {
+ changes.add(EnumElementChange.MAPPING);
+ }
+ this.kind = nextKind;
+ }
+ IMethodBinding methodBinding = JdtUtils.resolveMethodBinding(javaMethod, compilationUnit);
+
ITypeBinding javaReturnType = methodBinding.getReturnType();
- if (javaReturnType != null) {
- this.returnType = (IType) javaReturnType.getJavaElement();
+ IType nextReturnType = javaReturnType != null ? (IType) javaReturnType.getJavaElement() : null;
+ if ((nextReturnType != null && !nextReturnType.equals(this.returnType))
+ || (this.returnType != null && !this.returnType.equals(nextReturnType))) {
+ changes.add(EnumElementChange.KIND);
+ this.returnType = nextReturnType;
}
+
+ return changes;
}
/**
@@ -137,11 +117,11 @@
*/
@Override
public void validate(IProgressMonitor progressMonitor) throws CoreException {
- getUriMapping().validate();
+ getMapping().validate();
}
@Override
- public final BaseElement.EnumType getKind() {
+ public final BaseElement.EnumKind getKind() {
return kind;
}
@@ -153,10 +133,10 @@
}
/**
- * @return the uriMapping
+ * @return the resourceMethodMapping
*/
- public final UriMapping getUriMapping() {
- return uriMapping;
+ public final ResourceMethodMapping getMapping() {
+ return resourceMethodMapping;
}
/**
@@ -174,22 +154,30 @@
@Override
public final String toString() {
return "ResourceMethod [" + parentResource.getName() + "." + getJavaElement().getElementName() + "] -> "
- + uriMapping.toString() + ", kind=" + kind + "]";
+ + resourceMethodMapping.toString() + ", kind=" + kind + "]";
}
/*
- * private static UriMapping computeUriMapping(IMethod javaMethod,
- * CompilationUnit compilationUnit, List<HTTPMethod> httpMethods,
- * IProgressMonitor progressMonitor) throws JavaModelException,
- * CoreException { // look for any @HTTPMethod annotation HTTPMethod
- * httpMethod = lookupHTTPMethod(httpMethods, javaMethod, compilationUnit,
- * progressMonitor); // look for @Path annotation String
- * methodLevelUriPathTemplate = (String)
- * JdtUtils.resolveAnnotationAttributeValue(javaMethod, compilationUnit,
- * ANNOTATION_PATH, "value"); MediaTypeCapabilities mediaTypeCapabilities =
- * JAXRSAnnotationsScanner.resolveMediaTypeCapabilities(javaMethod,
- * compilationUnit, progressMonitor); return new UriMapping(httpMethod,
- * methodLevelUriPathTemplate, mediaTypeCapabilities); }
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#hashCode()
*/
+ @Override
+ public int hashCode() {
+ return getJavaElement().hashCode();
+ }
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof ResourceMethod) {
+ return getJavaElement().equals(((ResourceMethod) obj).getJavaElement());
+ }
+ return false;
+ }
+
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Resources.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Resources.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Resources.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -11,11 +11,9 @@
package org.jboss.tools.ws.jaxrs.core.metamodel;
-import java.util.HashMap;
+import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
import java.util.Map.Entry;
-import java.util.Stack;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
@@ -24,9 +22,10 @@
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.ITypeHierarchy;
import org.jboss.tools.ws.jaxrs.core.internal.builder.JAXRSAnnotationsScanner;
-import org.jboss.tools.ws.jaxrs.core.internal.utils.CollectionFilterUtil;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.CollectionFilterUtils;
import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
-import org.jboss.tools.ws.jaxrs.core.metamodel.BaseElement.EnumType;
+import org.jboss.tools.ws.jaxrs.core.metamodel.BaseElement.EnumKind;
+import org.jboss.tools.ws.jaxrs.core.metamodel.Resource.ResourceBuilder;
import org.jboss.tools.ws.jaxrs.core.utils.JdtUtils;
public class Resources extends BaseElementContainer<Resource> {
@@ -42,122 +41,33 @@
// FIXME deal with interfaces/implementations
@Override
- public final void addFrom(final IJavaElement scope, final IProgressMonitor progressMonitor) throws CoreException {
+ public List<Resource> addFrom(final IJavaElement scope, final IProgressMonitor progressMonitor)
+ throws CoreException {
progressMonitor.beginTask("Adding resources and resourceMethods", 1);
HTTPMethods httpMethods = metamodel.getHttpMethods();
List<IType> javaTypes = JAXRSAnnotationsScanner.findResources(scope, httpMethods.getTypeNames(),
progressMonitor);
+ List<Resource> addedResources = new ArrayList<Resource>();
for (IType javaType : javaTypes) {
try {
- elements.put(javaType.getFullyQualifiedName(),
- new Resource.Builder(javaType, metamodel).build(progressMonitor));
+ Resource addedResource = new ResourceBuilder(javaType, metamodel).build(progressMonitor);
+ elements.put(javaType.getFullyQualifiedName(), addedResource);
+ addedResources.add(addedResource);
+ // TODO: update the resolved mappings from here
} catch (InvalidModelElementException e) {
Logger.warn("Type '" + javaType.getFullyQualifiedName() + "' is not a valid JAX-RS Resource: "
+ e.getMessage());
}
}
+ return addedResources;
}
- /**
- * Resolve the URI Mappings in the model, given all root resources,
- * subresources , resource resourceMethods , subresource resourceMethods and
- * subresource locators
- *
- * @throws CoreException
- */
- public final Map<ResolvedUriMapping, Stack<ResourceMethod>> resolveUriMappings(
- final IProgressMonitor progressMonitor) throws CoreException {
- Map<ResolvedUriMapping, Stack<ResourceMethod>> uriMappings = new HashMap<ResolvedUriMapping, Stack<ResourceMethod>>();
- for (Resource resource : getRootResources()) {
- resolveResourcesUriMappings(resource, metamodel.getServiceUri(), uriMappings, new Stack<ResourceMethod>(),
- progressMonitor);
- }
- return uriMappings;
+ @Override
+ public Resource removeElement(final IResource removedResource, final IProgressMonitor progressMonitor) {
+ Resource resource = super.removeElement(removedResource, progressMonitor);
+ return resource;
}
- /**
- * @param progressMonitor
- * @param uriMappings
- * @param resource
- * @param methodsStack
- * @throws CoreException
- */
- private void resolveResourcesUriMappings(final Resource resource, final String uriTemplateFragment,
- final Map<ResolvedUriMapping, Stack<ResourceMethod>> uriMappings, final Stack<ResourceMethod> methodsStack,
- final IProgressMonitor progressMonitor) throws CoreException {
- // resource resourceMethods and subresources resourceMethods are treated
- // the same way
- for (ResourceMethod resourceMethod : resource.getAllMethods()) {
- String uriPathTemplate = resolveURIPathTemplate(uriTemplateFragment, resource, resourceMethod);
- MediaTypeCapabilities mediaTypeCapabilities = resolveMediaTypeCapabilities(resource, resourceMethod);
- UriMapping resourceUriMapping = resourceMethod.getUriMapping();
- ResolvedUriMapping uriMapping = new ResolvedUriMapping(resourceUriMapping.getHTTPMethod(), uriPathTemplate,
- resourceUriMapping.getQueryParams(), mediaTypeCapabilities);
- @SuppressWarnings("unchecked")
- Stack<ResourceMethod> stack = (Stack<ResourceMethod>) methodsStack.clone();
- stack.add(resourceMethod);
- uriMappings.put(uriMapping, stack);
- }
- // TODO : verify support chain of subresource locators
- // TODO : stack resourceMethods and detect+prevent cycles
- for (ResourceMethod resourceMethod : resource.getSubresourceLocators()) {
- String uriPathTemplate = resolveURIPathTemplate(uriTemplateFragment, resource, resourceMethod);
- IType returnType = resourceMethod.getReturnType();
- if (returnType == null) {
- continue;
- }
- ITypeHierarchy subresourceTypeHierarchy = JdtUtils.resolveTypeHierarchy(returnType, false, progressMonitor);
- for (IType subresourceType : subresourceTypeHierarchy.getSubtypes(returnType)) {
- Resource subresource = getByType(subresourceType);
- if (subresource != null && !subresource.isRootResource()) {
- @SuppressWarnings("unchecked")
- Stack<ResourceMethod> stack = (Stack<ResourceMethod>) methodsStack.clone();
- stack.add(resourceMethod);
- resolveResourcesUriMappings(subresource, uriPathTemplate, uriMappings, stack, progressMonitor);
- }
- }
- }
- }
-
- // FIXME : include method parameters if annotated with @QueryParam
- private static final String resolveURIPathTemplate(final String uriTemplateFragment, final Resource resource,
- final ResourceMethod resourceMethod) {
- StringBuffer uriTemplateBuffer = new StringBuffer(uriTemplateFragment);
- String resourceUriPathTemplate = resource.getUriPathTemplate();
- String methodUriPathTemplate = resourceMethod.getUriMapping().getUriPathTemplateFragment();
- if (resourceUriPathTemplate != null) {
- uriTemplateBuffer.append("/").append(resourceUriPathTemplate);
- }
- if (methodUriPathTemplate != null) {
- uriTemplateBuffer.append("/").append(methodUriPathTemplate);
- }
- return uriTemplateBuffer.toString().replaceAll("/\\*", "/").replaceAll("///", "/").replaceAll("//", "/");
- }
-
- private static final MediaTypeCapabilities resolveMediaTypeCapabilities(final Resource resource,
- final ResourceMethod resourceMethod) {
- MediaTypeCapabilities resourceMediaTypeCapabilities = resource.getMediaTypeCapabilities();
- MediaTypeCapabilities methodMediaTypeCapabilities = resourceMethod.getUriMapping().getMediaTypeCapabilities();
- MediaTypeCapabilities mediaTypeCapabilities = new MediaTypeCapabilities();
- if (!methodMediaTypeCapabilities.getConsumedMimeTypes().isEmpty()) {
- mediaTypeCapabilities.setConsumedMimeTypes(methodMediaTypeCapabilities.getConsumedMimeTypes());
- } else if (!resourceMediaTypeCapabilities.getConsumedMimeTypes().isEmpty()) {
- mediaTypeCapabilities.setConsumedMimeTypes(resourceMediaTypeCapabilities.getConsumedMimeTypes());
- } else {
- // leave empty collection
- // mediaTypeCapabilities.setConsumedMimeTypes(Arrays.asList("*/*"));
- }
- if (!methodMediaTypeCapabilities.getProducedMimeTypes().isEmpty()) {
- mediaTypeCapabilities.setProducedMimeTypes(methodMediaTypeCapabilities.getProducedMimeTypes());
- } else if (!resourceMediaTypeCapabilities.getProducedMimeTypes().isEmpty()) {
- mediaTypeCapabilities.setProducedMimeTypes(resourceMediaTypeCapabilities.getProducedMimeTypes());
- } else {
- // leave empty collection
- // mediaTypeCapabilities.setProducedMimeTypes(Arrays.asList("*/*"));
- }
- return mediaTypeCapabilities;
- }
-
public Resource getByResource(IResource resource) {
if (resource == null) {
return null;
@@ -180,7 +90,8 @@
public final Resource getByPath(final String path) {
for (Entry<String, Resource> entry : elements.entrySet()) {
Resource resource = entry.getValue();
- if (resource.isRootResource() && resource.getUriPathTemplate().endsWith(path)) {
+ if (resource.getKind() == EnumKind.ROOT_RESOURCE
+ && resource.getMapping().getUriPathTemplateFragment().endsWith(path)) {
return resource;
}
}
@@ -188,12 +99,33 @@
return null;
}
+ /**
+ * @return The Subresource locators that match the given return type.
+ * @param returnType
+ * the return type.
+ * @throws CoreException
+ */
+ public final List<ResourceMethod> findSubresourceLocators(IType returnType, IProgressMonitor progressMonitor)
+ throws CoreException {
+ List<ResourceMethod> locators = new ArrayList<ResourceMethod>();
+ for (Resource resource : getAll()) {
+ for (ResourceMethod locator : resource.getSubresourceLocators()) {
+ ITypeHierarchy returnTypeHierarchy = JdtUtils.resolveTypeHierarchy(locator.getReturnType(), true,
+ progressMonitor);
+ if (returnTypeHierarchy.contains(returnType)) {
+ locators.add(locator);
+ }
+ }
+ }
+ return locators;
+ }
+
public final List<Resource> getRootResources() {
- return CollectionFilterUtil.filterElementsByKind(elements.values(), EnumType.ROOT_RESOURCE);
+ return CollectionFilterUtils.filterElementsByKind(elements.values(), EnumKind.ROOT_RESOURCE);
}
public final List<Resource> getSubresources() {
- return CollectionFilterUtil.filterElementsByKind(elements.values(), EnumType.SUBRESOURCE);
+ return CollectionFilterUtils.filterElementsByKind(elements.values(), EnumKind.SUBRESOURCE);
}
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/utils/JdtUtils.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/utils/JdtUtils.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/utils/JdtUtils.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -386,10 +386,7 @@
* @throws CoreException
* the underlying CoreException thrown by the manipulated JDT
* APIs
- * @deprecated use resolveAnnotationAttributeValue(IMember, CompilationUnit,
- * Class<?>, String) instead.
*/
- @Deprecated
public static Object resolveAnnotationAttributeValue(final IAnnotationBinding annotationBinding,
final String attributeName) throws CoreException {
if (annotationBinding != null) {
@@ -422,14 +419,7 @@
final Class<?> annotationClass, final String attributeName) throws CoreException {
IAnnotationBinding annotationBinding = JdtUtils.resolveAnnotationBinding(member, compilationUnit,
annotationClass);
- if (annotationBinding != null) {
- for (IMemberValuePairBinding binding : annotationBinding.getAllMemberValuePairs()) {
- if (binding.getName().equals(attributeName)) {
- return binding.getValue();
- }
- }
- }
- return null;
+ return resolveAnnotationAttributeValue(annotationBinding, attributeName);
}
/**
Property changes on: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/icons
___________________________________________________________________
Added: svn:ignore
+ unused
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/icons/Thumbs.db
===================================================================
(Binary files differ)
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/plugin.xml
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/plugin.xml 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/plugin.xml 2011-06-07 21:43:35 UTC (rev 31889)
@@ -1,22 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
-
-<extension
- id="org.jboss.tools.ws.jaxrs.ui.javaCompetionProposalComputer"
- point="org.eclipse.jdt.ui.javaCompletionProposalComputer">
- <javaCompletionProposalComputer
- activate="true"
- categoryId="org.eclipse.jdt.ui.defaultProposalCategory"
- class="org.jboss.tools.ws.jaxrs.ui.contentassist.PathParamAnnotationValueCompletionProposalComputer">
- <partition
- type="__dftl_partition_content_type">
- </partition>
- <partition
- type="__java_string">
- </partition>
- </javaCompletionProposalComputer>
- </extension>
<extension
point="org.eclipse.ui.navigator.viewer">
@@ -187,6 +171,9 @@
<instanceof
value="org.jboss.tools.ws.jaxrs.ui.cnf.UriPathTemplateMethodMappingElement">
</instanceof>
+ <instanceof
+ value="org.jboss.tools.ws.jaxrs.ui.cnf.UriPathTemplateMediaTypeMappingElement">
+ </instanceof>
</or>
</enablement>
</actionProvider>
@@ -262,7 +249,6 @@
eventTypes="POST_INSTALL,POST_UNINSTALL">
</listener>
</extension>
- <!-- see https://bugs.eclipse.org/bugs/show_bug.cgi?id=338898 -->
<extension
id="id1"
point="org.eclipse.jst.ws.jaxrs.core.jaxrsLibraryProvider">
@@ -273,4 +259,21 @@
</jaxrsLibraryprovider>
</extension>
+<extension
+ id="org.jboss.tools.ws.jaxrs.ui.javaCompetionProposalComputer"
+ point="org.eclipse.jdt.ui.javaCompletionProposalComputer">
+ <javaCompletionProposalComputer
+ activate="true"
+ categoryId="org.eclipse.jdt.ui.defaultProposalCategory"
+ class="org.jboss.tools.ws.jaxrs.ui.contentassist.PathParamAnnotationValueCompletionProposalComputer">
+ <partition
+ type="__dftl_partition_content_type">
+ </partition>
+ <partition
+ type="__java_string">
+ </partition>
+ </javaCompletionProposalComputer>
+ </extension>
+ <!-- see https://bugs.eclipse.org/bugs/show_bug.cgi?id=338898 -->
+
</plugin>
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriMappingsContentProvider.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriMappingsContentProvider.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriMappingsContentProvider.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -11,6 +11,7 @@
package org.jboss.tools.ws.jaxrs.ui.cnf;
+import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@@ -20,6 +21,8 @@
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jdt.internal.ui.util.CoreUtility;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.viewers.TreeViewer;
@@ -28,36 +31,69 @@
import org.jboss.tools.ws.jaxrs.core.metamodel.Metamodel;
import org.jboss.tools.ws.jaxrs.ui.internal.utils.Logger;
+@SuppressWarnings("restriction")
public class UriMappingsContentProvider implements ITreeContentProvider, IResourceChangeListener {
private TreeViewer viewer;
- private Map<IProject, Metamodel> metamodels = new HashMap<IProject, Metamodel>();
+ private Map<IProject, Object> uriPathTemplateCategories = new HashMap<IProject, Object>();
- private Map<IProject, UriPathTemplateCategory> uriPathTemplateCategories = new HashMap<IProject, UriPathTemplateCategory>();
-
public UriMappingsContentProvider() {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
workspace.addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE);
}
+ @Override
public Object[] getChildren(Object parentElement) {
+
if (parentElement instanceof IProject) {
+ long startTime = new Date().getTime();
IProject project = (IProject) parentElement;
try {
if (!uriPathTemplateCategories.containsKey(project)) {
Metamodel metamodel = Metamodel.get(project);
if (metamodel == null) {
- return null;
+ // trigger background build and immediately return a
+ // temporary element to the UI
+ Job[] jobs = Job.getJobManager().find(null);
+ if (jobs != null) {
+ for (Job job : jobs) {
+ if (job.belongsTo(ResourcesPlugin.FAMILY_AUTO_BUILD)
+ || job.belongsTo(ResourcesPlugin.FAMILY_AUTO_REFRESH)
+ || job.belongsTo(ResourcesPlugin.FAMILY_MANUAL_BUILD)
+ || job.belongsTo(ResourcesPlugin.FAMILY_MANUAL_REFRESH)) {
+ // joining running job
+ Logger.debug("Joining Running job: " + job.getName());
+ job.join();
+ Logger.debug("Job finished: " + job.getName());
+ }
+ }
+ }
+ // after running job is done, check if the metamodel
+ // was
+ // built, otherwise, force it.
+ metamodel = Metamodel.get(project);
+ if (metamodel == null) {
+ Logger.debug("Metamodel is (still) null for project '" + project.getName() + "'");
+ CoreUtility.startBuildInBackground(project);
+ return new Object[] { new WaitWhileBuildingElement() };
+ }
}
UriPathTemplateCategory uriPathTemplateCategory = new UriPathTemplateCategory(this, metamodel,
project);
- metamodels.put(project, metamodel);
uriPathTemplateCategories.put(project, uriPathTemplateCategory);
}
return new Object[] { uriPathTemplateCategories.get(project) };
} catch (CoreException e) {
Logger.error("Failed to retrieve JAX-RS Metamodel in project '" + project.getName() + "'", e);
+ } catch (InterruptedException e) {
+ Logger.error(
+ "Failed to join currently running job while building or retrieving metamodel for project '"
+ + project.getName() + "'", e);
+ } finally {
+ long endTime = new Date().getTime();
+ Logger.debug("JAX-RS Metamodel UI for project '" + project.getName() + "' refreshed in "
+ + (endTime - startTime) + "ms.");
}
} else if (parentElement instanceof ITreeContentProvider) {
return ((ITreeContentProvider) parentElement).getChildren(parentElement);
@@ -65,10 +101,12 @@
return null;
}
+ @Override
public Object getParent(Object element) {
return null;
}
+ @Override
public boolean hasChildren(Object element) {
if (element instanceof ITreeContentProvider) {
return ((ITreeContentProvider) element).hasChildren(element);
@@ -76,6 +114,7 @@
return false;
}
+ @Override
public Object[] getElements(Object inputElement) {
return getChildren(inputElement);
}
@@ -106,6 +145,7 @@
}
} else {
Display.getDefault().asyncExec(new Runnable() {
+ @Override
public void run() {
if (viewer != null) {
TreePath[] treePaths = viewer.getExpandedTreePaths();
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriMappingsLabelProvider.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriMappingsLabelProvider.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriMappingsLabelProvider.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -19,8 +19,8 @@
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.StyledString;
import org.eclipse.swt.graphics.Image;
-import org.jboss.tools.ws.jaxrs.core.metamodel.ResolvedUriMapping;
import org.jboss.tools.ws.jaxrs.core.metamodel.ResourceMethod;
+import org.jboss.tools.ws.jaxrs.core.metamodel.Route;
import org.jboss.tools.ws.jaxrs.ui.JBossJaxrsUIPlugin;
/**
@@ -34,29 +34,26 @@
*
* @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
*/
+ @Override
public Image getImage(Object element) {
if (element instanceof UriPathTemplateCategory) {
return JBossJaxrsUIPlugin.getDefault().createImage("wsdl_file_obj.gif");
- }
-
- if (element instanceof UriPathTemplateElement) {
- if(((UriPathTemplateElement)element).hasErrors()) {
+ } else if (element instanceof UriPathTemplateElement) {
+ if (((UriPathTemplateElement) element).hasErrors()) {
return JBossJaxrsUIPlugin.getDefault().createImage("url_mapping_error.gif");
}
return JBossJaxrsUIPlugin.getDefault().createImage("url_mapping.gif");
- }
-
- if (element instanceof UriPathTemplateMediaTypeMappingElement) {
- switch (((UriPathTemplateMediaTypeMappingElement) element).getMediaType()) {
+ } else if (element instanceof UriPathTemplateMediaTypeMappingElement) {
+ switch (((UriPathTemplateMediaTypeMappingElement) element).getType()) {
case CONSUMES:
return JBossJaxrsUIPlugin.getDefault().createImage("filter_mapping_in.gif");
- case PROVIDES:
+ case PRODUCES:
return JBossJaxrsUIPlugin.getDefault().createImage("filter_mapping_out.gif");
}
- }
-
- if (element instanceof UriPathTemplateMethodMappingElement) {
+ } else if (element instanceof UriPathTemplateMethodMappingElement) {
return JBossJaxrsUIPlugin.getDefault().createImage("servlet_mapping.gif");
+ } else if (element instanceof WaitWhileBuildingElement) {
+ return JBossJaxrsUIPlugin.getDefault().createImage("systemprocess.gif");
}
return null;
@@ -69,6 +66,7 @@
* org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.
* jface.viewers.ILabelProviderListener)
*/
+ @Override
public void addListener(ILabelProviderListener listener) {
// TODO Auto-generated method stub
@@ -79,6 +77,7 @@
*
* @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
*/
+ @Override
public void dispose() {
// TODO Auto-generated method stub
@@ -91,6 +90,7 @@
* org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang
* .Object, java.lang.String)
*/
+ @Override
public boolean isLabelProperty(Object element, String property) {
// TODO Auto-generated method stub
return false;
@@ -103,6 +103,7 @@
* org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse
* .jface.viewers.ILabelProviderListener)
*/
+ @Override
public void removeListener(ILabelProviderListener listener) {
// TODO Auto-generated method stub
@@ -115,10 +116,10 @@
}
if (element instanceof UriPathTemplateElement) {
- ResolvedUriMapping uriMapping = ((UriPathTemplateElement) element).getResolvedUriMapping();
+ Route route = ((UriPathTemplateElement) element).getResolvedUriMapping();
StringBuilder sb = new StringBuilder();
- String httpVerb = uriMapping.getHTTPMethod().getHttpVerb();
- String uriTemplate = uriMapping.getFullUriPathTemplate();
+ String httpVerb = route.getEndpoint().getHttpMethod().getHttpVerb();
+ String uriTemplate = route.getEndpoint().getUriPathTemplate();
sb.append(httpVerb);
sb.append(" ");
sb.append(uriTemplate);
@@ -130,16 +131,29 @@
if (element instanceof UriPathTemplateMediaTypeMappingElement) {
UriPathTemplateMediaTypeMappingElement mappingElement = ((UriPathTemplateMediaTypeMappingElement) element);
StringBuilder sb = new StringBuilder();
+ int offset = 0;
+ switch (((UriPathTemplateMediaTypeMappingElement) element).getType()) {
+ case CONSUMES:
+ sb.append("consumes: ");
+ offset = sb.length();
+ break;
+ case PRODUCES:
+ sb.append("produces: ");
+ offset = sb.length();
+ break;
+ }
for (Iterator<String> iterator = mappingElement.getMediaTypes().iterator(); iterator.hasNext();) {
sb.append(iterator.next());
if (iterator.hasNext()) {
sb.append(",");
}
}
- return new StyledString(sb.toString());
+ StyledString styledString = new StyledString(sb.toString());
+ styledString.setStyle(0, offset, StyledString.QUALIFIER_STYLER);
+ return styledString;
}
if (element instanceof UriPathTemplateMethodMappingElement) {
- ResourceMethod lastMethod = ((UriPathTemplateMethodMappingElement) element).getLastMethod();
+ ResourceMethod lastMethod = ((UriPathTemplateMethodMappingElement) element).getResourceMethod();
StringBuilder sb = new StringBuilder();
IMethod javaMethod = lastMethod.getJavaElement();
// TODO : add method parameters from signature
@@ -147,6 +161,12 @@
.append("(...)");
return new StyledString(sb.toString());
}
+ if (element instanceof WaitWhileBuildingElement) {
+ String message = "Building RESTful Web Services...";
+ StyledString styledString = new StyledString(message);
+ styledString.setStyle(0, message.length(), StyledString.DECORATIONS_STYLER);
+ return new StyledString(message);
+ }
return null;
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriPathTemplateCategory.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriPathTemplateCategory.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriPathTemplateCategory.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -13,18 +13,16 @@
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-import java.util.Stack;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.jboss.tools.ws.jaxrs.core.metamodel.Metamodel;
-import org.jboss.tools.ws.jaxrs.core.metamodel.ResolvedUriMapping;
import org.jboss.tools.ws.jaxrs.core.metamodel.ResourceMethod;
+import org.jboss.tools.ws.jaxrs.core.metamodel.Route;
import org.jboss.tools.ws.jaxrs.ui.internal.utils.Logger;
public class UriPathTemplateCategory implements ITreeContentProvider {
@@ -32,10 +30,10 @@
private final Metamodel metamodel;
private final IProject project;
-
+
private final UriMappingsContentProvider parent;
- private Map<ResolvedUriMapping, UriPathTemplateElement> wrapperCache = new HashMap<ResolvedUriMapping, UriPathTemplateElement>();
+ private final Map<Route, UriPathTemplateElement> wrapperCache = new HashMap<Route, UriPathTemplateElement>();
public UriPathTemplateCategory(UriMappingsContentProvider parent, Metamodel metamodel, IProject project) {
super();
@@ -44,44 +42,51 @@
this.project = project;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public Object[] getChildren(Object parentElement) {
- try {
- Map<ResolvedUriMapping, Stack<ResourceMethod>> resolvedUriMappings = metamodel.getResources().resolveUriMappings(
- new NullProgressMonitor());
- List<UriPathTemplateElement> uriPathTemplateElements = new ArrayList<UriPathTemplateElement>();
- List<ResolvedUriMapping> uriMappings = new ArrayList<ResolvedUriMapping>(resolvedUriMappings.keySet());
- // Collections.sort(uriMappings);
- for (ResolvedUriMapping entry : uriMappings) {
- UriPathTemplateElement element = wrapperCache.get(entry);
- Stack<ResourceMethod> resourceMethods = resolvedUriMappings.get(entry);
- if (element == null || !element.getLastMethod().equals(resourceMethods.lastElement())) {
- element = new UriPathTemplateElement(entry, resourceMethods, this);
- wrapperCache.put(entry, element);
- }
- if (element != null) {
- uriPathTemplateElements.add(element);
- } // else ignore the entry
+ if (metamodel == null) {
+ return new Object[0];
+ }
+ List<Route> routes = metamodel.getRoutes().getAll();
+ List<UriPathTemplateElement> uriPathTemplateElements = new ArrayList<UriPathTemplateElement>();
+ // Collections.sort(uriMappings);
+ for (Route entry : routes) {
+ UriPathTemplateElement element = wrapperCache.get(entry);
+ LinkedList<ResourceMethod> resourceMethods = entry.getResourceMethods();
+ if (element == null || !element.getLastMethod().equals(resourceMethods.getLast())) {
+ element = new UriPathTemplateElement(entry, this);
+ wrapperCache.put(entry, element);
+ }
+ if (element != null) {
+ uriPathTemplateElements.add(element);
+ } // else ignore the entry
- }
- return uriPathTemplateElements.toArray();
- } catch (CoreException e) {
- Logger.error("Error while resolving project URI Mappings", e);
}
- return null;
+ return uriPathTemplateElements.toArray();
}
+ @Override
public Object getParent(Object element) {
return project;
}
+ @Override
public boolean hasChildren(Object element) {
+ if (metamodel == null) {
+ return false;
+ }
return (metamodel.getResources().getAll().size() > 0);
}
+ @Override
public Object[] getElements(Object inputElement) {
return getChildren(inputElement);
}
+ @Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
Logger.debug("Input changed in UriPathTemplateCategory");
}
@@ -89,11 +94,9 @@
@Override
public void dispose() {
}
-
+
public void refreshContent() {
parent.refreshContent();
}
-
-
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriPathTemplateElement.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriPathTemplateElement.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriPathTemplateElement.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -13,84 +13,92 @@
import java.util.ArrayList;
import java.util.List;
-import java.util.Stack;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
-import org.jboss.tools.ws.jaxrs.core.metamodel.ResolvedUriMapping;
import org.jboss.tools.ws.jaxrs.core.metamodel.ResourceMethod;
-import org.jboss.tools.ws.jaxrs.ui.cnf.UriPathTemplateMediaTypeMappingElement.EnumMediaType;
+import org.jboss.tools.ws.jaxrs.core.metamodel.Route;
+import org.jboss.tools.ws.jaxrs.ui.cnf.UriPathTemplateMediaTypeMappingElement.EnumCapabilityType;
public class UriPathTemplateElement implements ITreeContentProvider {
- private final ResolvedUriMapping resolvedUriMapping;
-
- private final Stack<ResourceMethod> resourceMethods;
-
+ private final Route route;
+
private final UriPathTemplateCategory uriPathTemplateCategory;
- public UriPathTemplateElement(ResolvedUriMapping uriMapping, Stack<ResourceMethod> resourceMethods,
- UriPathTemplateCategory uriPathTemplateCategory) {
+ public UriPathTemplateElement(Route route, UriPathTemplateCategory uriPathTemplateCategory) {
super();
- this.resolvedUriMapping = uriMapping;
- this.resourceMethods = resourceMethods;
+ this.route = route;
this.uriPathTemplateCategory = uriPathTemplateCategory;
}
+ @Override
public Object[] getChildren(Object parentElement) {
List<Object> elements = new ArrayList<Object>(3);
- elements.add(new UriPathTemplateMediaTypeMappingElement(resolvedUriMapping.getMediaTypeCapabilities().getConsumedMimeTypes(), EnumMediaType.CONSUMES));
- elements.add(new UriPathTemplateMediaTypeMappingElement(resolvedUriMapping.getMediaTypeCapabilities().getProducedMimeTypes(), EnumMediaType.PROVIDES));
- elements.add(new UriPathTemplateMethodMappingElement(resourceMethods));
+ elements.add(new UriPathTemplateMediaTypeMappingElement(route.getEndpoint().getConsumedMediaTypes(),
+ EnumCapabilityType.CONSUMES));
+ elements.add(new UriPathTemplateMediaTypeMappingElement(route.getEndpoint().getProducedMediaTypes(),
+ EnumCapabilityType.PRODUCES));
+ elements.add(new UriPathTemplateMethodMappingElement(route.getResourceMethods()));
return elements.toArray();
}
+ @Override
public Object getParent(Object element) {
return uriPathTemplateCategory;
}
+ @Override
public boolean hasChildren(Object element) {
return (getChildren(element).length > 0);
}
+ @Override
public Object[] getElements(Object inputElement) {
return getChildren(inputElement);
}
+ @Override
public void dispose() {
}
+ @Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
// TODO Auto-generated method stub
}
public boolean hasErrors() {
- return resourceMethods.lastElement().hasErrors();
+ return getLastMethod().hasErrors();
}
+
/**
* @return the uriMapping
*/
- public ResolvedUriMapping getResolvedUriMapping() {
- return resolvedUriMapping;
+ public Route getResolvedUriMapping() {
+ return route;
}
-
+
public ResourceMethod getLastMethod() {
- return resourceMethods.lastElement();
+ return route.getResourceMethods().getLast();
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + ((resolvedUriMapping == null) ? 0 : resolvedUriMapping.hashCode());
+ result = prime * result + ((route == null) ? 0 : route.hashCode());
return result;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
@@ -102,13 +110,12 @@
if (getClass() != obj.getClass())
return false;
UriPathTemplateElement other = (UriPathTemplateElement) obj;
- if (resolvedUriMapping == null) {
- if (other.resolvedUriMapping != null)
+ if (route == null) {
+ if (other.route != null)
return false;
- } else if (!resolvedUriMapping.equals(other.resolvedUriMapping))
+ } else if (!route.equals(other.route))
return false;
return true;
}
-
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriPathTemplateElementsSorter.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriPathTemplateElementsSorter.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriPathTemplateElementsSorter.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -15,7 +15,7 @@
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerSorter;
-import org.jboss.tools.ws.jaxrs.ui.cnf.UriPathTemplateMediaTypeMappingElement.EnumMediaType;
+import org.jboss.tools.ws.jaxrs.ui.cnf.UriPathTemplateMediaTypeMappingElement.EnumCapabilityType;
import org.jboss.tools.ws.jaxrs.ui.internal.utils.Logger;
public class UriPathTemplateElementsSorter extends ViewerSorter {
@@ -27,23 +27,30 @@
super(collator);
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.
+ * viewers.Viewer, java.lang.Object, java.lang.Object)
*/
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
- if(e1 instanceof UriPathTemplateMediaTypeMappingElement && e2 instanceof UriPathTemplateMediaTypeMappingElement) {
+ if (e1 instanceof UriPathTemplateMediaTypeMappingElement
+ && e2 instanceof UriPathTemplateMediaTypeMappingElement) {
UriPathTemplateMediaTypeMappingElement element1 = (UriPathTemplateMediaTypeMappingElement) e1;
- if(element1.getMediaType() == EnumMediaType.CONSUMES) {
+ if (element1.getType() == EnumCapabilityType.CONSUMES) {
return -1;
}
return 1;
- } else if (e1 instanceof UriPathTemplateMethodMappingElement && e2 instanceof UriPathTemplateMediaTypeMappingElement) {
+ } else if (e1 instanceof UriPathTemplateMethodMappingElement
+ && e2 instanceof UriPathTemplateMediaTypeMappingElement) {
return 1;
- } else if (e1 instanceof UriPathTemplateMediaTypeMappingElement && e2 instanceof UriPathTemplateMethodMappingElement) {
+ } else if (e1 instanceof UriPathTemplateMediaTypeMappingElement
+ && e2 instanceof UriPathTemplateMethodMappingElement) {
return -1;
}
- Logger.warn("Unexpected comparison: " +e1.getClass().getSimpleName() + " vs " + e2.getClass().getSimpleName());
+ Logger.warn("Unexpected comparison: " + e1.getClass().getSimpleName() + " vs " + e2.getClass().getSimpleName());
return 0;
}
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriPathTemplateMediaTypeMappingElement.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriPathTemplateMediaTypeMappingElement.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriPathTemplateMediaTypeMappingElement.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -11,41 +11,37 @@
package org.jboss.tools.ws.jaxrs.ui.cnf;
-import java.util.Arrays;
import java.util.List;
+import org.eclipse.jdt.core.IJavaElement;
+import org.jboss.tools.ws.jaxrs.core.metamodel.MediaTypeCapabilities;
+
public class UriPathTemplateMediaTypeMappingElement {
- public enum EnumMediaType {
- CONSUMES, PROVIDES;
+ public enum EnumCapabilityType {
+ CONSUMES, PRODUCES;
}
- private final List<String> mediaTypes;
+ private final EnumCapabilityType type;
- private final EnumMediaType mediaType;
+ private final MediaTypeCapabilities mediaTypeCapabilities;
- public UriPathTemplateMediaTypeMappingElement(List<String> mediaTypes, EnumMediaType mediaType) {
+ public UriPathTemplateMediaTypeMappingElement(final MediaTypeCapabilities mediaTypes, final EnumCapabilityType type) {
super();
- this.mediaType = mediaType;
- if (mediaTypes != null && !mediaTypes.isEmpty()) {
- this.mediaTypes = mediaTypes;
- } else {
- this.mediaTypes = Arrays.asList("*/*");
- }
+ this.mediaTypeCapabilities = mediaTypes;
+ this.type = type;
}
- /**
- * @return the mediaTypes
- */
- public List<String> getMediaTypes() {
- return mediaTypes;
+ public EnumCapabilityType getType() {
+ return type;
}
- /**
- * @return the mediaType
- */
- public EnumMediaType getMediaType() {
- return mediaType;
+ public IJavaElement getElement() {
+ return mediaTypeCapabilities.getElement();
}
+ public List<String> getMediaTypes() {
+ return mediaTypeCapabilities.getMediatypes();
+ }
+
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriPathTemplateMethodMappingElement.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriPathTemplateMethodMappingElement.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriPathTemplateMethodMappingElement.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -11,23 +11,21 @@
package org.jboss.tools.ws.jaxrs.ui.cnf;
-import java.util.Stack;
+import java.util.LinkedList;
import org.jboss.tools.ws.jaxrs.core.metamodel.ResourceMethod;
public class UriPathTemplateMethodMappingElement {
- private final Stack<ResourceMethod> resourceMethods;
+ private final LinkedList<ResourceMethod> resourceMethods;
- public UriPathTemplateMethodMappingElement(Stack<ResourceMethod> resourceMethods) {
+ public UriPathTemplateMethodMappingElement(LinkedList<ResourceMethod> resourceMethods) {
super();
this.resourceMethods = resourceMethods;
}
-
- public ResourceMethod getLastMethod() {
- return resourceMethods.lastElement();
+ public ResourceMethod getResourceMethod() {
+ return resourceMethods.getLast();
}
-
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriPathTemplatesSorter.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriPathTemplatesSorter.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/UriPathTemplatesSorter.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -25,15 +25,18 @@
super(collator);
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.
+ * viewers.Viewer, java.lang.Object, java.lang.Object)
*/
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
UriPathTemplateElement element1 = (UriPathTemplateElement) e1;
UriPathTemplateElement element2 = (UriPathTemplateElement) e2;
- return element1.getResolvedUriMapping().compareTo(element2.getResolvedUriMapping());
+ return element1.getResolvedUriMapping().getEndpoint().compareTo(element2.getResolvedUriMapping().getEndpoint());
}
-
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/action/CopyToClipboardAction.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/action/CopyToClipboardAction.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/action/CopyToClipboardAction.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -32,8 +32,7 @@
private ISelection selection = null;
public CopyToClipboardAction() {
- super("Copy URI Path Template", JBossJaxrsUIPlugin.getDefault().createImageDescriptor(
- "copyqualifiedname.gif"));
+ super("Copy URI Path Template", JBossJaxrsUIPlugin.getDefault().createImageDescriptor("copyqualifiedname.gif"));
}
/*
@@ -52,9 +51,10 @@
Object selectedObject = selections.get(0);
try {
if (selectedObject instanceof UriPathTemplateElement) {
- String uriPathTemplate = ((UriPathTemplateElement) selectedObject).getResolvedUriMapping().getFullUriPathTemplate();
+ String uriPathTemplate = ((UriPathTemplateElement) selectedObject).getResolvedUriMapping()
+ .getEndpoint().getUriPathTemplate();
Clipboard clipboard = new Clipboard(Display.getCurrent());
- clipboard.setContents(new Object[]{uriPathTemplate}, new Transfer[]{TextTransfer.getInstance()});
+ clipboard.setContents(new Object[] { uriPathTemplate }, new Transfer[] { TextTransfer.getInstance() });
}
} catch (Exception e) {
Logger.error("Failed to open Java editor", e);
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/action/OpenJavaEditorAction.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/action/OpenJavaEditorAction.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/action/OpenJavaEditorAction.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -22,6 +22,7 @@
import org.eclipse.ui.navigator.CommonViewer;
import org.jboss.tools.ws.jaxrs.core.metamodel.ResourceMethod;
import org.jboss.tools.ws.jaxrs.ui.cnf.UriPathTemplateElement;
+import org.jboss.tools.ws.jaxrs.ui.cnf.UriPathTemplateMediaTypeMappingElement;
import org.jboss.tools.ws.jaxrs.ui.cnf.UriPathTemplateMethodMappingElement;
import org.jboss.tools.ws.jaxrs.ui.internal.utils.Logger;
@@ -41,16 +42,19 @@
@Override
public void run() {
ITreeSelection treeSelection = ((ITreeSelection) selection);
- for (Object o : treeSelection.toList()) {
+ for (Object selection : treeSelection.toList()) {
try {
- if (o instanceof UriPathTemplateElement) {
- ResourceMethod lastMethod = ((UriPathTemplateElement) o).getLastMethod();
+ if (selection instanceof UriPathTemplateElement) {
+ ResourceMethod lastMethod = ((UriPathTemplateElement) selection).getLastMethod();
IMethod javaMethod = lastMethod.getJavaElement();
JavaUI.revealInEditor(JavaUI.openInEditor(javaMethod), (IJavaElement) javaMethod);
- } else if (o instanceof UriPathTemplateMethodMappingElement) {
- ResourceMethod lastMethod = ((UriPathTemplateMethodMappingElement) o).getLastMethod();
+ } else if (selection instanceof UriPathTemplateMethodMappingElement) {
+ ResourceMethod lastMethod = ((UriPathTemplateMethodMappingElement) selection).getResourceMethod();
IMethod javaMethod = lastMethod.getJavaElement();
JavaUI.revealInEditor(JavaUI.openInEditor(javaMethod), (IJavaElement) javaMethod);
+ } else if (selection instanceof UriPathTemplateMediaTypeMappingElement) {
+ IJavaElement element = ((UriPathTemplateMediaTypeMappingElement) selection).getElement();
+ JavaUI.revealInEditor(JavaUI.openInEditor(element), element);
}
} catch (Exception e) {
Logger.error("Failed to open Java editor", e);
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/action/OpenJavaEditorActionProvider.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/action/OpenJavaEditorActionProvider.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/action/OpenJavaEditorActionProvider.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -38,17 +38,8 @@
@Override
public void init(ICommonActionExtensionSite aSite) {
- /*
- * ICompilationUnit cu = member.getCompilationUnit(); IEditorPart
- * javaEditor = JavaUI.openInEditor(cu);
- * JavaUI.revealInEditor(javaEditor, (IJavaElement)member);
- */
-
ICommonViewerSite viewSite = aSite.getViewSite();
if (viewSite instanceof ICommonViewerWorkbenchSite) {
- //ICommonViewerWorkbenchSite commonViewerWorkbenchSite = (ICommonViewerWorkbenchSite) viewSite;
- //JavaUI.revealInEditor(JavaUI.openInEditor(element), element)
- //JavaUI.openInEditor(null)
openJavaEditorAction = new OpenJavaEditorAction();
openJavaEditorAction.setSelection(aSite.getStructuredViewer().getSelection());
aSite.getStructuredViewer().addSelectionChangedListener(openJavaEditorAction);
@@ -66,8 +57,11 @@
@Override
public void fillActionBars(IActionBars actionBars) {
super.fillActionBars(actionBars);
- actionBars.setGlobalActionHandler("org.bytesparadise.tools.jaxrs.ui.cnf.openJavaEditorActionProvider", openJavaEditorAction);
- actionBars.setGlobalActionHandler(ICommonActionConstants.OPEN,openJavaEditorAction);
+ // enables java editor opening on double-click
+ actionBars.setGlobalActionHandler("org.jboss.tools.ws.jaxrs.ui.cnf.openJavaEditorActionProvider",
+ openJavaEditorAction);
+ actionBars.setGlobalActionHandler(ICommonActionConstants.OPEN, openJavaEditorAction);
+
}
/*
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/internal/utils/Logger.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/internal/utils/Logger.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/internal/utils/Logger.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -41,8 +41,7 @@
* the throwable cause
*/
public static void error(String message) {
- JBossJaxrsUIPlugin.getDefault().getLog()
- .log(new Status(Status.ERROR, JBossJaxrsUIPlugin.PLUGIN_ID, message));
+ JBossJaxrsUIPlugin.getDefault().getLog().log(new Status(Status.ERROR, JBossJaxrsUIPlugin.PLUGIN_ID, message));
}
/**
@@ -65,14 +64,18 @@
* the message to log
*/
public static void warn(final String message) {
- JBossJaxrsUIPlugin.getDefault().getLog()
- .log(new Status(Status.WARNING, JBossJaxrsUIPlugin.PLUGIN_ID, message));
+ JBossJaxrsUIPlugin.getDefault().getLog().log(new Status(Status.WARNING, JBossJaxrsUIPlugin.PLUGIN_ID, message));
}
public static void warn(String message, Throwable cause) {
JBossJaxrsUIPlugin.getDefault().getLog()
- .log(new Status(Status.WARNING, JBossJaxrsUIPlugin.PLUGIN_ID, message, cause));
+ .log(new Status(Status.WARNING, JBossJaxrsUIPlugin.PLUGIN_ID, message, cause));
}
+
+ public static void info(String message) {
+ JBossJaxrsUIPlugin.getDefault().getLog().log(new Status(Status.INFO, JBossJaxrsUIPlugin.PLUGIN_ID, message));
+ }
+
/**
* Outputs a debug message in the trace file (not the error view of the
* runtime workbench). Traces must be activated for this plugin in order to
@@ -89,5 +92,4 @@
}
-
}
Modified: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/pom.xml
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/pom.xml 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/pom.xml 2011-06-07 21:43:35 UTC (rev 31889)
@@ -9,7 +9,7 @@
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>org.jboss.tools.ws.tests</groupId>
- <artifactId>org.jboss.tools.ws.jaxrs.core.tests</artifactId>
+ <artifactId>org.jboss.tools.ws.jaxrs.core.test</artifactId>
<version>1.2.0-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
Modified: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/projects/org.jboss.tools.ws.jaxrs.tests.sampleproject/src/main/java/org/jboss/tools/ws/jaxrs/sample/services/GameResource.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/projects/org.jboss.tools.ws.jaxrs.tests.sampleproject/src/main/java/org/jboss/tools/ws/jaxrs/sample/services/GameResource.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/projects/org.jboss.tools.ws.jaxrs.tests.sampleproject/src/main/java/org/jboss/tools/ws/jaxrs/sample/services/GameResource.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -12,6 +12,7 @@
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.jboss.tools.ws.jaxrs.sample.domain.Game;
Modified: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/AbstractCommonTestCase.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/AbstractCommonTestCase.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/AbstractCommonTestCase.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -12,6 +12,7 @@
package org.jboss.tools.ws.jaxrs.core;
import java.lang.reflect.InvocationTargetException;
+import java.util.Date;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
@@ -62,37 +63,55 @@
@BeforeClass
public static void setupWorkspace() throws Exception {
- IWorkspace workspace = ResourcesPlugin.getWorkspace();
- if (workspace.isAutoBuilding()) {
- IWorkspaceDescription description = workspace.getDescription();
- description.setAutoBuilding(false);
- workspace.setDescription(description);
+ long startTime = new Date().getTime();
+ try {
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ if (workspace.isAutoBuilding()) {
+ IWorkspaceDescription description = workspace.getDescription();
+ description.setAutoBuilding(false);
+ workspace.setDescription(description);
+ }
+
+ workspace.getRoot().refreshLocal(IResource.DEPTH_INFINITE, null);
+ LOGGER.info("Initial Synchronization (@BeforeClass)");
+ WorkbenchTasks.syncSampleProject(DEFAULT_SAMPLE_PROJECT_NAME);
+ } finally {
+ long endTime = new Date().getTime();
+ LOGGER.info("Initial Workspace setup in " + (endTime - startTime) + "ms.");
}
-
- workspace.getRoot().refreshLocal(IResource.DEPTH_INFINITE, null);
- LOGGER.info("Initial Synchronization (@BeforeClass)");
- WorkbenchTasks.syncSampleProject(DEFAULT_SAMPLE_PROJECT_NAME);
}
@Before
public void bindSampleProject() throws Exception {
- projectName = WorkbenchUtils.retrieveSampleProjectName(this.getClass());
- project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
- javaProject = JavaCore.create(project);
- Assert.assertNotNull("JavaProject not found", javaProject.exists());
- Assert.assertNotNull("Project not found", javaProject.getProject().exists());
- Assert.assertTrue("Project is not a JavaProject", JavaProject.hasJavaNature(javaProject.getProject()));
- synchronizor = new ProjectSynchronizator();
- IWorkspace workspace = ResourcesPlugin.getWorkspace();
- workspace.addResourceChangeListener(synchronizor);
+ long startTime = new Date().getTime();
+ try {
+ projectName = WorkbenchUtils.retrieveSampleProjectName(this.getClass());
+ project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ javaProject = JavaCore.create(project);
+ Assert.assertNotNull("JavaProject not found", javaProject.exists());
+ Assert.assertNotNull("Project not found", javaProject.getProject().exists());
+ Assert.assertTrue("Project is not a JavaProject", JavaProject.hasJavaNature(javaProject.getProject()));
+ synchronizor = new ProjectSynchronizator();
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ workspace.addResourceChangeListener(synchronizor);
+ } finally {
+ long endTime = new Date().getTime();
+ LOGGER.info("Test Workspace setup in " + (endTime - startTime) + "ms.");
+ }
}
@After
public void removeListener() throws CoreException, InvocationTargetException, InterruptedException {
- // remove listener before sync' to avoid desync...
- IWorkspace workspace = ResourcesPlugin.getWorkspace();
- workspace.removeResourceChangeListener(synchronizor);
- synchronizor.resync();
+ long startTime = new Date().getTime();
+ try {
+ // remove listener before sync' to avoid desync...
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ workspace.removeResourceChangeListener(synchronizor);
+ synchronizor.resync();
+ } finally {
+ long endTime = new Date().getTime();
+ LOGGER.info("Test Workspace sync'd in " + (endTime - startTime) + "ms.");
+ }
}
}
Modified: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/WorkbenchTasks.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/WorkbenchTasks.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/WorkbenchTasks.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -88,12 +88,14 @@
LOGGER.info("Target workspace location: " + targetWorkspace.getRoot().getRawLocation());
SyncFileSystemStructureProvider syncFileSystemStructureProvider = new SyncFileSystemStructureProvider(
projectSourcePath, project.getLocation());
+ syncFileSystemStructureProvider.ignoreRelativeSourcePath(new Path(".svn"));
syncFileSystemStructureProvider.ignoreRelativeSourcePath(new Path("target"));
syncFileSystemStructureProvider.ignoreRelativeSourcePath(new Path("bin"));
List<File> filesToImport = syncFileSystemStructureProvider.getChildren(projectSourcePath.toFile());
if (filesToImport != null && filesToImport.size() > 0) {
ImportOperation operation = new ImportOperation(project.getFullPath(), projectSourcePath.toFile(),
syncFileSystemStructureProvider, new IOverwriteQuery() {
+ @Override
public String queryOverwrite(String pathString) {
return IOverwriteQuery.YES;
}
@@ -136,6 +138,7 @@
}
ImportOperation operation = new ImportOperation(containerPath, new FileSystemStructureProvider(),
new IOverwriteQuery() {
+ @Override
public String queryOverwrite(String pathString) {
return IOverwriteQuery.YES;
}
@@ -242,9 +245,9 @@
* @param javaProject
* @param name
* @param progressMonitor
- * @throws CoreException
- * @throws InterruptedException
- * @throws OperationCanceledException
+ * @throws CoreException
+ * @throws InterruptedException
+ * @throws OperationCanceledException
*/
public static boolean removeReferencedLibrary(IJavaProject javaProject, String name,
IProgressMonitor progressMonitor) throws CoreException, OperationCanceledException, InterruptedException {
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 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/WorkbenchUtils.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -259,7 +259,7 @@
ISourceRange sourceRange = method.getSourceRange();
IBuffer buffer = ((IOpenable) workingCopy).getBuffer();
int offset = buffer.getContents().indexOf(oldContent, sourceRange.getOffset());
- Assert.assertTrue("Old content not found", offset != -1);
+ Assert.assertTrue("Old content not found: '" + oldContent + "'", offset != -1);
buffer.replace(offset, oldContent.length(), newContent);
saveAndClose(workingCopy);
}
@@ -339,10 +339,10 @@
saveAndClose(workingCopy);
// return the last method of the java type, assuming it is the one given
// in parameter
- return javaType.getMethods()[javaType.getMethods().length - 1];
+ return javaType.getMethods()[0];
}
- public static void addMethodAnnotion(IMethod method, String annotation) throws JavaModelException {
+ public static void addMethodAnnotation(IMethod method, String annotation) throws JavaModelException {
ICompilationUnit compilationUnit = method.getCompilationUnit();
ICompilationUnit workingCopy = createWorkingCopy(compilationUnit);
ISourceRange sourceRange = method.getSourceRange();
Modified: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/builder/AbstractMetamodelBuilderTestCase.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/builder/AbstractMetamodelBuilderTestCase.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/builder/AbstractMetamodelBuilderTestCase.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -30,7 +30,7 @@
public abstract class AbstractMetamodelBuilderTestCase extends AbstractCommonTestCase {
- private static final Logger LOGGER = LoggerFactory.getLogger(AbstractMetamodelBuilderTestCase.class);
+ protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractMetamodelBuilderTestCase.class);
protected Bundle bundle = JBossJaxrsCoreTestsPlugin.getDefault().getBundle();
@@ -38,19 +38,20 @@
@Before
public void buildMetamodel() throws CoreException, OperationCanceledException, InterruptedException {
- // WARNING : Avoid project with "Dynamic Web project" facet version "2.5" as it triggers NPE (see Bugzilla 317766 at eclipse.org)
- //ProjectFacetUtils.installFacet(project, "jst.jaxrs");
+ // WARNING : Avoid project with "Dynamic Web project" facet version
+ // "2.5" as it triggers NPE (see Bugzilla 317766 at eclipse.org)
+ // ProjectFacetUtils.installFacet(project, "jst.jaxrs");
ProjectNatureUtils.installProjectNature(project, ProjectNatureUtils.JAXRS_NATURE_ID);
WorkbenchUtils.setAutoBuild(ResourcesPlugin.getWorkspace(), false);
- //project.build(FULL_BUILD, new NullProgressMonitor());
+ // project.build(FULL_BUILD, new NullProgressMonitor());
WorkbenchTasks.buildProject(project, new NullProgressMonitor());
metamodel = Metamodel.get(project);
}
@After
public void removeNatureAndBuilder() throws CoreException {
- WorkbenchUtils.setAutoBuild(ResourcesPlugin.getWorkspace(),false);
- //ProjectFacetUtils.uninstallFacet(project, "jst.jaxrs");
+ WorkbenchUtils.setAutoBuild(ResourcesPlugin.getWorkspace(), false);
+ // ProjectFacetUtils.uninstallFacet(project, "jst.jaxrs");
ProjectNatureUtils.uninstallProjectNature(project, ProjectNatureUtils.JAXRS_NATURE_ID);
}
Modified: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/builder/FullBuilderTestCase.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/builder/FullBuilderTestCase.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/builder/FullBuilderTestCase.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -11,26 +11,24 @@
package org.jboss.tools.ws.jaxrs.core.builder;
-import java.util.ArrayList;
-import java.util.Collections;
import java.util.HashSet;
import java.util.List;
-import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
-import java.util.Stack;
-import org.eclipse.core.resources.IncrementalProjectBuilder;
+import javax.ws.rs.core.MediaType;
+
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.jboss.tools.ws.jaxrs.core.metamodel.BaseElement;
+import org.jboss.tools.ws.jaxrs.core.metamodel.BaseElement.EnumKind;
import org.jboss.tools.ws.jaxrs.core.metamodel.HTTPMethod;
import org.jboss.tools.ws.jaxrs.core.metamodel.Metamodel;
import org.jboss.tools.ws.jaxrs.core.metamodel.Provider;
import org.jboss.tools.ws.jaxrs.core.metamodel.Provider.EnumProviderKind;
-import org.jboss.tools.ws.jaxrs.core.metamodel.ResolvedUriMapping;
import org.jboss.tools.ws.jaxrs.core.metamodel.Resource;
-import org.jboss.tools.ws.jaxrs.core.metamodel.ResourceMethod;
+import org.jboss.tools.ws.jaxrs.core.metamodel.Route;
+import org.jboss.tools.ws.jaxrs.core.metamodel.RouteEndpoint;
import org.jboss.tools.ws.jaxrs.core.utils.JdtUtils;
import org.junit.Assert;
import org.junit.Before;
@@ -46,7 +44,7 @@
@Before
public void setupMetamodel() throws CoreException {
- metamodel = buildMetamodel(IncrementalProjectBuilder.FULL_BUILD);
+ metamodel = Metamodel.get(project);
}
@Test
@@ -71,8 +69,11 @@
Assert.assertEquals(2, metamodel.getProviders().getConsumers().size());
for (Provider p : metamodel.getProviders().getConsumers()) {
Assert.assertNotNull("Missing provided type", p.getProvidedKinds().containsKey(EnumProviderKind.CONSUMER));
- /*Assert.assertNotNull("Missing mime-type: " + p.getJavaType().getFullyQualifiedName(),
- p.getMediaTypes(EnumProviderKind.CONSUMER));*/
+ /*
+ * Assert.assertNotNull("Missing mime-type: " +
+ * p.getJavaType().getFullyQualifiedName(),
+ * p.getMediaTypes(EnumProviderKind.CONSUMER));
+ */
Assert.assertFalse("Provider type shouldn't be abstract: " + p.getJavaElement().getFullyQualifiedName(),
JdtUtils.isAbstractType(p.getJavaElement()));
}
@@ -80,8 +81,11 @@
Assert.assertEquals(3, metamodel.getProviders().getProducers().size());
for (Provider p : metamodel.getProviders().getProducers()) {
Assert.assertNotNull("Missing provided type", p.getProvidedKinds().containsKey(EnumProviderKind.PRODUCER));
- /*Assert.assertNotNull("Missing mime-type: " + p.getJavaType().getFullyQualifiedName(),
- p.getMediaTypes(EnumProviderKind.PRODUCER));*/
+ /*
+ * Assert.assertNotNull("Missing mime-type: " +
+ * p.getJavaType().getFullyQualifiedName(),
+ * p.getMediaTypes(EnumProviderKind.PRODUCER));
+ */
Assert.assertFalse("Provider type shouldn't be abstract: " + p.getJavaElement().getFullyQualifiedName(),
JdtUtils.isAbstractType(p.getJavaElement()));
}
@@ -105,36 +109,51 @@
Assert.assertEquals(5, metamodel.getResources().getAll().size());
for (Resource resource : metamodel.getResources().getRootResources()) {
Assert.assertNotNull("JavaType not found", resource.getJavaElement());
- Assert.assertTrue("Wrong kind", resource.isRootResource());
- Assert.assertEquals("Wrong kind", BaseElement.EnumType.ROOT_RESOURCE, resource.getKind());
- Assert.assertNotNull("UriPathTemplate not found", resource.getUriPathTemplate());
- Assert.assertFalse("Wrong UriPathTemplate format", resource.getUriPathTemplate().contains("null"));
- Assert.assertFalse("Wrong UriPathTemplate format", resource.getUriPathTemplate().contains("*"));
- Assert.assertNotNull("MediaTypeCapabilities not found", resource.getMediaTypeCapabilities());
+ Assert.assertTrue("Wrong kind", resource.getKind() == EnumKind.ROOT_RESOURCE);
+ Assert.assertEquals("Wrong kind", BaseElement.EnumKind.ROOT_RESOURCE, resource.getKind());
+ Assert.assertNotNull("UriPathTemplate not found", resource.getMapping().getUriPathTemplateFragment());
+ Assert.assertFalse("Wrong UriPathTemplate format", resource.getMapping().getUriPathTemplateFragment()
+ .contains("null"));
+ Assert.assertFalse("Wrong UriPathTemplate format", resource.getMapping().getUriPathTemplateFragment()
+ .contains("*"));
+ Assert.assertNotNull("MediaTypeCapabilities not found on resource " + resource.getName(), resource
+ .getMapping().getConsumedMediaTypes());
}
for (Resource resource : metamodel.getResources().getRootResources()) {
Assert.assertNotNull("JavaType not found", resource.getJavaElement());
- Assert.assertTrue("Wrong kind", resource.isRootResource());
- Assert.assertEquals("Wrong kind", BaseElement.EnumType.ROOT_RESOURCE, resource.getKind());
+ Assert.assertTrue("Wrong kind", resource.getKind() == EnumKind.ROOT_RESOURCE);
+ Assert.assertEquals("Wrong kind", BaseElement.EnumKind.ROOT_RESOURCE, resource.getKind());
}
+ }
- Map<ResolvedUriMapping, Stack<ResourceMethod>> resolveUriMappings = metamodel.getResources().resolveUriMappings(new NullProgressMonitor());
+ @Test
+ public void shouldAssertResolvedRoutes() throws CoreException {
+ List<Route> resolveUriMappings = metamodel.getRoutes().getAll();
Assert.assertEquals("Wrong result", 10, resolveUriMappings.size());
- for(Entry<ResolvedUriMapping, Stack<ResourceMethod>> entry : resolveUriMappings.entrySet()) {
- ResolvedUriMapping key = entry.getKey();
- Stack<ResourceMethod> value = entry.getValue();
- Assert.assertFalse("Found some '//' in the uri path template in " + key, key.getFullUriPathTemplate().contains("//"));
- //Assert.assertFalse("Missing consumed media types in " + key, key.getMediaTypeCapabilities().getConsumedMimeTypes().isEmpty());
- //Assert.assertFalse("Missing produced media types in " + key, key.getMediaTypeCapabilities().getProducedMimeTypes().isEmpty());
- Assert.assertTrue("Empty list of stacks of resourceMethods", !value.isEmpty());
- Assert.assertFalse("Empty stack of resourceMethods", value.isEmpty());
+ for (Route entry : resolveUriMappings) {
+ Assert.assertFalse("Empty list of resourceMethods", entry.getResourceMethods().isEmpty());
+ RouteEndpoint endpoint = entry.getEndpoint();
+ Assert.assertNotNull("No endpoint", endpoint);
+ Assert.assertNotNull("No URI Path template", endpoint.getUriPathTemplate());
+ Assert.assertFalse("No URI Path template:" + endpoint.getUriPathTemplate(), endpoint.getUriPathTemplate()
+ .contains("null"));
+ Assert.assertFalse("Found some '//' in the uri path template in " + endpoint.getUriPathTemplate(), endpoint
+ .getUriPathTemplate().contains("//"));
+ Assert.assertNotNull("No Http Method", endpoint.getHttpMethod());
+ Assert.assertFalse("No consumed media types", endpoint.getConsumedMediaTypes().isEmpty());
+ Assert.assertFalse("No produced media types", endpoint.getProducedMediaTypes().isEmpty());
}
- List<ResolvedUriMapping> uriMappings = new ArrayList<ResolvedUriMapping>(resolveUriMappings.keySet());
- Collections.sort(uriMappings);
- Assert.assertEquals("Wrong result", "/customers?start={int}&size={int}", uriMappings.get(0).getFullUriPathTemplate());
- Assert.assertEquals("Wrong result", "GET", uriMappings.get(0).getHTTPMethod().getHttpVerb());
- Assert.assertEquals("Wrong result", "/products/{type}/{id}", uriMappings.get(9).getFullUriPathTemplate());
+ /*
+ * List<Route> uriMappings = new
+ * ArrayList<Route>(resolveUriMappings.keySet());
+ * Collections.sort(uriMappings); Assert.assertEquals("Wrong result",
+ * "/customers?start={int}&size={int}", uriMappings.get(0)
+ * .getFullUriPathTemplate()); Assert.assertEquals("Wrong result",
+ * "GET", uriMappings.get(0).getHTTPMethod().getHttpVerb());
+ * Assert.assertEquals("Wrong result", "/products/{type}/{id}",
+ * uriMappings.get(9).getFullUriPathTemplate());
+ */
}
@Test
@@ -143,19 +162,30 @@
JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource", javaProject,
new NullProgressMonitor()));
Assert.assertNotNull("CustomerResource not found", customerResource);
- Assert.assertEquals("Wrong result", "/customers", customerResource.getUriPathTemplate());
+ Assert.assertEquals("Wrong result", "/customers", customerResource.getMapping().getUriPathTemplateFragment());
Assert.assertEquals("Wrong result", customerResource, metamodel.getResources().getByPath("/customers"));
Assert.assertArrayEquals("Wrong mediatype capabilities", new String[] { "application/xml" }, customerResource
- .getMediaTypeCapabilities().getConsumedMimeTypes().toArray());
+ .getMapping().getConsumedMediaTypes().getMediatypes().toArray());
Assert.assertArrayEquals("Wrong mediatype capabilities", new String[] {
"application/vnd.bytesparadise.customer+xml", "application/xml", "application/json" }, customerResource
- .getMediaTypeCapabilities().getProducedMimeTypes().toArray());
+ .getMapping().getProcucedMediaTypes().getMediatypes().toArray());
Assert.assertEquals("Wrong number of resource resourceMethods", 2, customerResource.getResourceMethods().size());
- Assert.assertEquals("Wrong number of resource resourceMethods", 4, customerResource.getSubresourceMethods().size());
- Assert.assertEquals("Wrong number of resource resourceMethods", 0, customerResource.getSubresourceLocators().size());
+ Assert.assertEquals("Wrong number of resource resourceMethods", 4, customerResource.getSubresourceMethods()
+ .size());
+ Assert.assertEquals("Wrong number of resource resourceMethods", 0, customerResource.getSubresourceLocators()
+ .size());
HTTPMethod httpMethod = metamodel.getHttpMethods().getByVerb("GET");
- ResourceMethod vcardMethod = customerResource.getByURIMapping(httpMethod, "{id}", null, "text/x-vcard");
- Assert.assertNotNull("ResourceMethod not found", vcardMethod);
+ Assert.assertNotNull("ResourceMethod not found",
+ customerResource.getByMapping(httpMethod, "{id}", null, "text/x-vcard"));
+
+ Assert.assertNotNull(
+ "ResourceMethod not found",
+ customerResource
+ .getMetamodel()
+ .getRoutes()
+ .getByMapping(httpMethod, "/customers/{id}", MediaType.APPLICATION_XML,
+ MediaType.APPLICATION_JSON));
+
}
}
Modified: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/builder/JaxrsAnnotationScannerTestCase.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/builder/JaxrsAnnotationScannerTestCase.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/builder/JaxrsAnnotationScannerTestCase.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -28,6 +28,7 @@
import org.jboss.tools.ws.jaxrs.core.JBossJaxrsCoreTestsPlugin;
import org.jboss.tools.ws.jaxrs.core.WorkbenchTasks;
import org.jboss.tools.ws.jaxrs.core.WorkbenchUtils;
+import org.jboss.tools.ws.jaxrs.core.metamodel.MediaTypeCapabilities;
import org.jboss.tools.ws.jaxrs.core.utils.JdtUtils;
import org.junit.Assert;
import org.junit.Test;
@@ -157,12 +158,12 @@
}
}
Assert.assertNotNull("ResourceMethod not found", method);
- List<String> mediaTypes = JAXRSAnnotationsScanner.resolveMediaTypeCapabilities(method, compilationUnit,
- Produces.class);
- Assert.assertEquals("Wrong result", 3, mediaTypes.size());
- Assert.assertEquals("Wrong result", "application/vnd.bytesparadise.order+xml", mediaTypes.get(0));
- Assert.assertEquals("Wrong result", "application/xml", mediaTypes.get(1));
- Assert.assertEquals("Wrong result", "application/json", mediaTypes.get(2));
+ MediaTypeCapabilities mediaTypesCapabilities = JAXRSAnnotationsScanner.resolveMediaTypeCapabilities(method,
+ compilationUnit, Produces.class);
+ Assert.assertEquals("Wrong result", 3, mediaTypesCapabilities.size());
+ Assert.assertEquals("Wrong result", "application/vnd.bytesparadise.order+xml", mediaTypesCapabilities.get(0));
+ Assert.assertEquals("Wrong result", "application/xml", mediaTypesCapabilities.get(1));
+ Assert.assertEquals("Wrong result", "application/json", mediaTypesCapabilities.get(2));
}
@Test
@@ -171,11 +172,11 @@
new NullProgressMonitor());
Assert.assertNotNull("Type not found", type);
CompilationUnit compilationUnit = JdtUtils.parse(type, null);
- List<String> mediaTypes = JAXRSAnnotationsScanner.resolveMediaTypeCapabilities(type, compilationUnit,
- Produces.class);
- Assert.assertEquals("Wrong result", 2, mediaTypes.size());
- Assert.assertEquals("Wrong result", "application/xml", mediaTypes.get(0));
- Assert.assertEquals("Wrong result", "application/json", mediaTypes.get(1));
+ MediaTypeCapabilities mediaTypesCapabilities = JAXRSAnnotationsScanner.resolveMediaTypeCapabilities(type,
+ compilationUnit, Produces.class);
+ Assert.assertEquals("Wrong result", 2, mediaTypesCapabilities.size());
+ Assert.assertEquals("Wrong result", "application/xml", mediaTypesCapabilities.get(0));
+ Assert.assertEquals("Wrong result", "application/json", mediaTypesCapabilities.get(1));
}
@Test
@@ -184,9 +185,9 @@
new NullProgressMonitor());
Assert.assertNotNull("Type not found", type);
CompilationUnit compilationUnit = JdtUtils.parse(type, null);
- List<String> mediaTypes = JAXRSAnnotationsScanner.resolveMediaTypeCapabilities(type, compilationUnit,
- Consumes.class);
- Assert.assertNull("Wrong result", mediaTypes);
+ MediaTypeCapabilities mediaTypeCapabilities = JAXRSAnnotationsScanner.resolveMediaTypeCapabilities(type,
+ compilationUnit, Consumes.class);
+ Assert.assertTrue("Wrong result", mediaTypeCapabilities.isEmpty());
}
@Test
@@ -203,11 +204,11 @@
}
}
Assert.assertNotNull("ResourceMethod not found", method);
- List<String> mediaTypes = JAXRSAnnotationsScanner.resolveMediaTypeCapabilities(method, compilationUnit,
- Produces.class);
- Assert.assertEquals("Wrong result", "application/vnd.bytesparadise.book+xml", mediaTypes.get(0));
- Assert.assertEquals("Wrong result", "application/xml", mediaTypes.get(1));
- Assert.assertEquals("Wrong result", "application/json", mediaTypes.get(2));
+ MediaTypeCapabilities mediaTypesCapabilities = JAXRSAnnotationsScanner.resolveMediaTypeCapabilities(method,
+ compilationUnit, Produces.class);
+ Assert.assertEquals("Wrong result", "application/vnd.bytesparadise.book+xml", mediaTypesCapabilities.get(0));
+ Assert.assertEquals("Wrong result", "application/xml", mediaTypesCapabilities.get(1));
+ Assert.assertEquals("Wrong result", "application/json", mediaTypesCapabilities.get(2));
}
@Test
@@ -224,13 +225,14 @@
}
}
Assert.assertNotNull("ResourceMethod not found", method);
- List<String> mediaTypes = JAXRSAnnotationsScanner.resolveMediaTypeCapabilities(method, compilationUnit,
- Consumes.class);
- Assert.assertNull("Wrong result", mediaTypes);
+ MediaTypeCapabilities mediaTypeCapabilities = JAXRSAnnotationsScanner.resolveMediaTypeCapabilities(method,
+ compilationUnit, Consumes.class);
+ Assert.assertTrue("Wrong result", mediaTypeCapabilities.isEmpty());
}
@Test
- public void shouldStillResolvedMimeTypesAfterLibraryRemoved() throws JavaModelException, CoreException, OperationCanceledException, InterruptedException {
+ public void shouldStillResolvedMimeTypesAfterLibraryRemoved() throws JavaModelException, CoreException,
+ OperationCanceledException, InterruptedException {
NullProgressMonitor progressMonitor = new NullProgressMonitor();
try {
IType type = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.services.BookResource", javaProject,
@@ -240,11 +242,11 @@
boolean removed = WorkbenchTasks.removeReferencedLibrary(javaProject, "jaxrs-api-2.0.1.GA.jar",
progressMonitor);
Assert.assertTrue("Referenced library not removed", removed);
- List<String> mediaTypes = JAXRSAnnotationsScanner.resolveMediaTypeCapabilities(type, compilationUnit,
- Produces.class);
+ MediaTypeCapabilities mediaTypesCapabilities = JAXRSAnnotationsScanner.resolveMediaTypeCapabilities(type,
+ compilationUnit, Produces.class);
// works even if the library was removed (does not take compilation
// error into account)
- Assert.assertEquals("Wrong result", 2, mediaTypes.size());
+ Assert.assertEquals("Wrong result", 2, mediaTypesCapabilities.size());
} finally {
WorkbenchTasks.addJavaProjectLibrary(javaProject, "jaxrs-api-2.0.1.GA.jar", progressMonitor);
Modified: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/builder/ProviderChangesTestCase.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/builder/ProviderChangesTestCase.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/builder/ProviderChangesTestCase.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -13,6 +13,8 @@
import java.util.List;
+import javax.ws.rs.core.MediaType;
+
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.ICompilationUnit;
@@ -20,6 +22,7 @@
import org.eclipse.jdt.core.IType;
import org.jboss.tools.ws.jaxrs.core.WorkbenchUtils;
import org.jboss.tools.ws.jaxrs.core.builder.AbstractMetamodelBuilderTestCase;
+import org.jboss.tools.ws.jaxrs.core.metamodel.MediaTypeCapabilities;
import org.jboss.tools.ws.jaxrs.core.metamodel.Provider;
import org.jboss.tools.ws.jaxrs.core.metamodel.Provider.EnumProviderKind;
import org.jboss.tools.ws.jaxrs.core.utils.JdtUtils;
@@ -163,12 +166,11 @@
+ "import org.jboss.tools.ws.jaxrs.sample.TestQualifiedException;");
// post-conditions
actualExceptionType = provider.getProvidedKinds().get(EnumProviderKind.EXCEPTION_MAPPER);
- exceptionType = JdtUtils.resolveType(
- "org.jboss.tools.ws.jaxrs.sample.TestQualifiedException.TestException", javaProject, null);
+ exceptionType = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.TestQualifiedException.TestException",
+ javaProject, null);
Assert.assertEquals("Wrong java type", exceptionType.getFullyQualifiedName(),
actualExceptionType.getFullyQualifiedName());
- Assert.assertEquals("Wrong pkg name",
- "org.jboss.tools.ws.jaxrs.sample.TestQualifiedException$TestException",
+ Assert.assertEquals("Wrong pkg name", "org.jboss.tools.ws.jaxrs.sample.TestQualifiedException$TestException",
actualExceptionType.getFullyQualifiedName());
}
@@ -294,44 +296,51 @@
IType providerType = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.extra.AnotherDummyProvider",
javaProject, new NullProgressMonitor());
Provider provider = metamodel.getProviders().getByType(providerType);
- Assert.assertNull("No mediatype expected", provider.getMediaTypeCapabilities(EnumProviderKind.PRODUCER));
+ MediaTypeCapabilities mediaTypeCapabilities = provider.getMediaTypeCapabilities(EnumProviderKind.PRODUCER);
+ Assert.assertNotNull("No media types capabilities expected", mediaTypeCapabilities);
+ Assert.assertTrue("Wrong result", mediaTypeCapabilities.isEmpty());
// operation
WorkbenchUtils.addImport(providerType, "javax.ws.rs.Produces");
WorkbenchUtils.addTypeAnnotation(providerType, "@Produces(MediaType.APPLICATION_JSON)");
// post-conditions
Assert.assertEquals(5, metamodel.getProviders().size());
- Assert.assertEquals("Wrong mediatype", "application/json",
- provider.getMediaTypeCapabilities(EnumProviderKind.PRODUCER).get(0));
+ Assert.assertEquals("Wrong mediatype", MediaType.APPLICATION_JSON, mediaTypeCapabilities.get(0));
}
@Test
public void shouldChangeWhenChangingProducesAnnotation() throws CoreException {
Assert.assertEquals(5, metamodel.getProviders().size());
- IType providerType = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.extra.DummyProvider",
- javaProject, new NullProgressMonitor());
+ IType providerType = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.extra.DummyProvider", javaProject,
+ new NullProgressMonitor());
+ Provider provider = metamodel.getProviders().getByType(providerType);
+ MediaTypeCapabilities producerMediaTypeCapabilities = provider
+ .getMediaTypeCapabilities(EnumProviderKind.PRODUCER);
+ MediaTypeCapabilities consumerMediaTypeCapabilities = provider
+ .getMediaTypeCapabilities(EnumProviderKind.CONSUMER);
+ Assert.assertEquals("Wrong mediatype", MediaType.APPLICATION_XML, producerMediaTypeCapabilities.get(0));
+ Assert.assertEquals("Wrong mediatype", MediaType.APPLICATION_XML, consumerMediaTypeCapabilities.get(0));
// operation
WorkbenchUtils.replaceFirstOccurrenceOfCode(providerType, "@Produces(MediaType.APPLICATION_XML)",
"@Produces(MediaType.APPLICATION_JSON)");
// post-conditions
Assert.assertEquals(5, metamodel.getProviders().size());
- Provider provider = metamodel.getProviders().getByType(providerType);
- Assert.assertEquals("Wrong mediatype", "application/json",
- provider.getMediaTypeCapabilities(EnumProviderKind.PRODUCER).get(0));
- Assert.assertEquals("Wrong mediatype", "application/xml",
- provider.getMediaTypeCapabilities(EnumProviderKind.CONSUMER).get(0));
+ Assert.assertEquals("Wrong mediatype", MediaType.APPLICATION_JSON, producerMediaTypeCapabilities.get(0));
+ Assert.assertEquals("Wrong mediatype", MediaType.APPLICATION_XML, consumerMediaTypeCapabilities.get(0));
}
@Test
public void shouldChangeWhenRemovingProducesAnnotation() throws CoreException {
Assert.assertEquals(5, metamodel.getProviders().size());
- IType providerType = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.extra.DummyProvider",
- javaProject, new NullProgressMonitor());
+ IType providerType = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.extra.DummyProvider", javaProject,
+ new NullProgressMonitor());
// operation
WorkbenchUtils.removeFirstOccurrenceOfCode(providerType, "@Produces(MediaType.APPLICATION_XML)");
// post-conditions
Assert.assertEquals(5, metamodel.getProviders().size());
Provider provider = metamodel.getProviders().getByType(providerType);
- Assert.assertNull("No mediatype expected", provider.getMediaTypeCapabilities(EnumProviderKind.PRODUCER));
+ MediaTypeCapabilities mediaTypeCapabilities = provider.getMediaTypeCapabilities(EnumProviderKind.PRODUCER);
+ Assert.assertNotNull("No media types capabilities expected", mediaTypeCapabilities);
+ Assert.assertTrue("Wrong result", mediaTypeCapabilities.isEmpty());
}
@Test
@@ -340,44 +349,51 @@
IType providerType = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.extra.AnotherDummyProvider",
javaProject, new NullProgressMonitor());
Provider provider = metamodel.getProviders().getByType(providerType);
- Assert.assertNull("No mediatype expected", provider.getMediaTypeCapabilities(EnumProviderKind.PRODUCER));
+ MediaTypeCapabilities mediaTypeCapabilities = provider.getMediaTypeCapabilities(EnumProviderKind.CONSUMER);
+ Assert.assertNotNull("No media types capabilities expected", mediaTypeCapabilities);
+ Assert.assertTrue("Wrong result", mediaTypeCapabilities.isEmpty());
// operation
WorkbenchUtils.addImport(providerType, "javax.ws.rs.Consumes");
WorkbenchUtils.addTypeAnnotation(providerType, "@Consumes(MediaType.APPLICATION_JSON)");
// post-conditions
Assert.assertEquals(5, metamodel.getProviders().size());
- Assert.assertEquals("Wrong mediatype", "application/json",
- provider.getMediaTypeCapabilities(EnumProviderKind.CONSUMER).get(0));
+ Assert.assertEquals("Wrong mediatype", MediaType.APPLICATION_JSON, mediaTypeCapabilities.get(0));
}
@Test
public void shouldChangeWhenChangingConsumesAnnotation() throws CoreException {
Assert.assertEquals(5, metamodel.getProviders().size());
- IType providerType = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.extra.DummyProvider",
- javaProject, new NullProgressMonitor());
+ IType providerType = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.extra.DummyProvider", javaProject,
+ new NullProgressMonitor());
+ Provider provider = metamodel.getProviders().getByType(providerType);
+ MediaTypeCapabilities consumesMediaTypeCapabilities = provider
+ .getMediaTypeCapabilities(EnumProviderKind.CONSUMER);
+ MediaTypeCapabilities producesMediaTypeCapabilities = provider
+ .getMediaTypeCapabilities(EnumProviderKind.PRODUCER);
// operation
WorkbenchUtils.replaceFirstOccurrenceOfCode(providerType, "@Consumes(MediaType.APPLICATION_XML)",
"@Consumes(MediaType.APPLICATION_JSON)");
// post-conditions
+ Assert.assertEquals("Wrong mediatype", MediaType.APPLICATION_JSON, consumesMediaTypeCapabilities.get(0));
+ Assert.assertEquals("Wrong mediatype", MediaType.APPLICATION_XML, producesMediaTypeCapabilities.get(0));
Assert.assertEquals(5, metamodel.getProviders().size());
- Provider provider = metamodel.getProviders().getByType(providerType);
- Assert.assertEquals("Wrong mediatype", "application/json",
- provider.getMediaTypeCapabilities(EnumProviderKind.CONSUMER).get(0));
- Assert.assertEquals("Wrong mediatype", "application/xml",
- provider.getMediaTypeCapabilities(EnumProviderKind.PRODUCER).get(0));
}
@Test
public void shouldChangeWhenRemovingConsumesAnnotation() throws CoreException {
Assert.assertEquals(5, metamodel.getProviders().size());
- IType providerType = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.extra.DummyProvider",
- javaProject, new NullProgressMonitor());
+ IType providerType = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.extra.DummyProvider", javaProject,
+ new NullProgressMonitor());
+ Provider provider = metamodel.getProviders().getByType(providerType);
+ MediaTypeCapabilities mediaTypeCapabilities = provider.getMediaTypeCapabilities(EnumProviderKind.CONSUMER);
+ Assert.assertNotNull("No media types capabilities expected", mediaTypeCapabilities);
+ Assert.assertEquals("Wrong result", MediaType.APPLICATION_XML, mediaTypeCapabilities.get(0));
// operation
WorkbenchUtils.removeFirstOccurrenceOfCode(providerType, "@Consumes(MediaType.APPLICATION_XML)");
// post-conditions
Assert.assertEquals(5, metamodel.getProviders().size());
- Provider provider = metamodel.getProviders().getByType(providerType);
- Assert.assertNull("No mediatype expected", provider.getMediaTypeCapabilities(EnumProviderKind.CONSUMER));
+ Assert.assertNotNull("No media types capabilities expected", mediaTypeCapabilities);
+ Assert.assertTrue("Wrong result", mediaTypeCapabilities.isEmpty());
}
@Test
@@ -387,13 +403,15 @@
"SimpleMessageBodyWriter.txt", "org.jboss.tools.ws.jaxrs.sample.services.providers",
"SimpleMessageBodyWriter.java", bundle);
Assert.assertEquals(6, metamodel.getProviders().size());
+ IType providerType = JdtUtils.resolveTopLevelType(compilationUnit);
+ Provider provider = metamodel.getProviders().getByType(providerType);
+ MediaTypeCapabilities mediaTypeCapabilities = provider.getMediaTypeCapabilities(EnumProviderKind.PRODUCER);
+ Assert.assertTrue("Wrong result", mediaTypeCapabilities.isEmpty());
// operation
- IType providerType = JdtUtils.resolveTopLevelType(compilationUnit);
WorkbenchUtils.addTypeAnnotation(providerType, "@Consumes(MediaType.APPLICATION_JSON)");
// post-conditions
Assert.assertEquals(6, metamodel.getProviders().size());
- Provider provider = metamodel.getProviders().getByType(providerType);
- Assert.assertNull("No mediatype expected", provider.getMediaTypeCapabilities(EnumProviderKind.PRODUCER));
+ Assert.assertTrue("Wrong result", mediaTypeCapabilities.isEmpty());
Assert.assertNull("No mediatype expected here: provider is not a MessageBodyReader !",
provider.getMediaTypeCapabilities(EnumProviderKind.CONSUMER));
}
@@ -405,13 +423,15 @@
"SimpleMessageBodyReader.txt", "org.jboss.tools.ws.jaxrs.sample.services.providers",
"SimpleMessageBodyReader.java", bundle);
Assert.assertEquals(6, metamodel.getProviders().size());
+ IType providerType = JdtUtils.resolveTopLevelType(compilationUnit);
+ Provider provider = metamodel.getProviders().getByType(providerType);
+ MediaTypeCapabilities mediaTypeCapabilities = provider.getMediaTypeCapabilities(EnumProviderKind.CONSUMER);
+ Assert.assertTrue("Wrong result", mediaTypeCapabilities.isEmpty());
// operation
- IType providerType = JdtUtils.resolveTopLevelType(compilationUnit);
WorkbenchUtils.addTypeAnnotation(providerType, "@Produces(MediaType.APPLICATION_JSON)");
// post-conditions
Assert.assertEquals(6, metamodel.getProviders().size());
- Provider provider = metamodel.getProviders().getByType(providerType);
- Assert.assertNull("No mediatype expected", provider.getMediaTypeCapabilities(EnumProviderKind.CONSUMER));
+ Assert.assertTrue("Wrong result", mediaTypeCapabilities.isEmpty());
Assert.assertNull("No mediatype expected here: provider is not a MessageBodyWriter !",
provider.getMediaTypeCapabilities(EnumProviderKind.PRODUCER));
}
@@ -423,13 +443,15 @@
"SimpleMessageBodyReader.txt", "org.jboss.tools.ws.jaxrs.sample.services.providers",
"SimpleMessageBodyReader.java", bundle);
Assert.assertEquals(6, metamodel.getProviders().size());
+ IType providerType = JdtUtils.resolveTopLevelType(compilationUnit);
+ Provider provider = metamodel.getProviders().getByType(providerType);
+ MediaTypeCapabilities mediaTypeCapabilities = provider.getMediaTypeCapabilities(EnumProviderKind.CONSUMER);
+ Assert.assertTrue("Wrong result", mediaTypeCapabilities.isEmpty());
// operation
- IType providerType = JdtUtils.resolveTopLevelType(compilationUnit);
WorkbenchUtils.removeFirstOccurrenceOfCode(providerType, "import java.io.IOException;");
// post-conditions
Assert.assertEquals(6, metamodel.getProviders().size());
- Provider provider = metamodel.getProviders().getByType(providerType);
- Assert.assertNull("No mediatype expected", provider.getMediaTypeCapabilities(EnumProviderKind.CONSUMER));
+ Assert.assertTrue("Wrong result", mediaTypeCapabilities.isEmpty());
Assert.assertNull("No mediatype expected here: provider is not a MessageBodyWriter !",
provider.getMediaTypeCapabilities(EnumProviderKind.PRODUCER));
}
@@ -437,15 +459,15 @@
@Test
public void shouldReportErrorWhenSettingInvalidMediaTypeOnProducesAnnotation() throws CoreException {
Assert.assertEquals(5, metamodel.getProviders().size());
- IType providerType = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.extra.DummyProvider",
- javaProject, new NullProgressMonitor());
+ IType providerType = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.extra.DummyProvider", javaProject,
+ new NullProgressMonitor());
// operation
WorkbenchUtils.replaceFirstOccurrenceOfCode(providerType, "@Produces(MediaType.APPLICATION_XML)",
"@Produces(FOO)");
// post-conditions
Assert.assertEquals(5, metamodel.getProviders().size());
Provider provider = metamodel.getProviders().getByType(providerType);
- List<String> mediaTypes = provider.getMediaTypeCapabilities(EnumProviderKind.PRODUCER);
+ List<String> mediaTypes = provider.getMediaTypeCapabilities(EnumProviderKind.PRODUCER).getMediatypes();
Assert.assertTrue("No error reported", provider.hasErrors());
Assert.assertEquals("Wrong number of mediatypes", 1, mediaTypes.size());
Assert.assertEquals("Wrong mediatype", "application/xml", mediaTypes.get(0));
@@ -455,8 +477,8 @@
@Test
public void shouldReportErrorWhenSettingInvalidMediaTypeOnConsumesAnnotation() throws CoreException {
Assert.assertEquals(5, metamodel.getProviders().size());
- IType providerType = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.extra.DummyProvider",
- javaProject, new NullProgressMonitor());
+ IType providerType = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.extra.DummyProvider", javaProject,
+ new NullProgressMonitor());
// operation
WorkbenchUtils.replaceFirstOccurrenceOfCode(providerType, "@Consumes(MediaType.APPLICATION_XML)",
"@Consumes(FOO)");
@@ -474,8 +496,8 @@
public void shouldReportErrorWhenRemovingProviderAnnotationImport() throws CoreException {
// pre-conditions
Assert.assertEquals(5, metamodel.getProviders().size());
- IType providerType = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.extra.DummyProvider",
- javaProject, new NullProgressMonitor());
+ IType providerType = JdtUtils.resolveType("org.jboss.tools.ws.jaxrs.sample.extra.DummyProvider", javaProject,
+ new NullProgressMonitor());
// operation
WorkbenchUtils.removeImport(providerType.getCompilationUnit(), javax.ws.rs.ext.Provider.class.getName());
// post-conditions : 1 HTTPMethod less
@@ -496,8 +518,7 @@
String[] oldContents = new String[] { "import javax.persistence.PersistenceException;",
"public class PersistenceExceptionMapper implements ExceptionMapper<PersistenceException>",
"public Response toResponse(PersistenceException exception)" };
- String[] newContents = new String[] {
- "import javax.persistence.EntityExistsException;",
+ String[] newContents = new String[] { "import javax.persistence.EntityExistsException;",
"@Provider public class PersistenceExceptionMapper implements ExceptionMapper<EntityExistsException>",
"public Response toResponse(EntityExistsException exception)" };
Modified: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/builder/ResourceChangesTestCase.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/builder/ResourceChangesTestCase.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/builder/ResourceChangesTestCase.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -12,6 +12,7 @@
package org.jboss.tools.ws.jaxrs.core.internal.builder;
import javax.ws.rs.Path;
+import javax.ws.rs.core.MediaType;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.ICompilationUnit;
@@ -19,6 +20,8 @@
import org.eclipse.jdt.core.JavaModelException;
import org.jboss.tools.ws.jaxrs.core.WorkbenchUtils;
import org.jboss.tools.ws.jaxrs.core.builder.AbstractMetamodelBuilderTestCase;
+import org.jboss.tools.ws.jaxrs.core.metamodel.BaseElement.EnumKind;
+import org.jboss.tools.ws.jaxrs.core.metamodel.MediaTypeCapabilities;
import org.jboss.tools.ws.jaxrs.core.metamodel.Resource;
import org.jboss.tools.ws.jaxrs.core.metamodel.Resources;
import org.junit.Assert;
@@ -35,11 +38,13 @@
// pre-conditions
Resources resources = metamodel.getResources();
Assert.assertEquals(5, resources.getAll().size());
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
// operation
WorkbenchUtils.createCompilationUnit(javaProject, "FooResource.txt",
"org.jboss.tools.ws.jaxrs.sample.services", "FooResource.java", bundle);
// post-conditions
Assert.assertEquals(6, resources.getAll().size());
+ Assert.assertEquals("Wrong number of routes", 12, metamodel.getRoutes().getAll().size());
}
@Test
@@ -55,6 +60,8 @@
// root resource (not a public class)
Assert.assertEquals("Wrong result : the total number of root resources shouldn't have changed", 5, resources
.getAll().size());
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
+
// TODO: there should be a warning on the added type :
// "type is not public and thus, it is not reachable"
}
@@ -70,7 +77,7 @@
IType fooType = fooCompilationUnit.getType("FooResource");
WorkbenchUtils.addTypeAnnotation(fooType, "@Path(\"/foo\") ");
WorkbenchUtils.addImport(fooCompilationUnit, "javax.ws.rs.Path");
-
+
// post-conditions
// The total number should have increased even the type is not a valid
@@ -80,10 +87,11 @@
.size());
Resource foo = resources.getByType(fooCompilationUnit.findPrimaryType());
Assert.assertNotNull("Resource not found", foo);
- Assert.assertTrue("Wrong resource kind", foo.isRootResource());
+ Assert.assertTrue("Wrong resource kind", foo.getKind() == EnumKind.ROOT_RESOURCE);
Assert.assertEquals("No resource method expected", 0, foo.getResourceMethods().size());
Assert.assertEquals("No subresource method expected", 0, foo.getSubresourceMethods().size());
Assert.assertEquals("No subresource locator expected", 0, foo.getSubresourceLocators().size());
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
// TODO: there should be a warning on the added type :
// "type has no request method designator"
}
@@ -102,6 +110,7 @@
// post-conditions : switch
Assert.assertEquals(4, resources.getRootResources().size());
Assert.assertEquals(1, resources.getSubresources().size());
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
}
@Test
@@ -110,12 +119,14 @@
Resources resources = metamodel.getResources();
Assert.assertEquals(3, resources.getRootResources().size());
Assert.assertEquals(2, resources.getSubresources().size());
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
IType customerResourceType = resources.getByPath("/customers").getJavaElement();
// operation : add @Path("/foo") annotation on type level
WorkbenchUtils.removeFirstOccurrenceOfCode(customerResourceType, "@Path(CustomerResource.URI_BASE)");
// post-conditions : switch
Assert.assertEquals(2, resources.getRootResources().size());
Assert.assertEquals(3, resources.getSubresources().size());
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
}
@Test
@@ -127,6 +138,7 @@
WorkbenchUtils.delete(resource.getJavaElement().getCompilationUnit());
// post-conditions
Assert.assertEquals(4, metamodel.getResources().getAll().size());
+ Assert.assertEquals("Wrong number of routes", 4, metamodel.getRoutes().getAll().size());
}
@Test
@@ -138,6 +150,7 @@
WorkbenchUtils.delete(resource.getJavaElement().getCompilationUnit());
// post-conditions
Assert.assertEquals(4, metamodel.getResources().getAll().size());
+ Assert.assertEquals("Wrong number of routes", 4, metamodel.getRoutes().getAll().size());
}
@Test
@@ -147,11 +160,14 @@
// operation
Resource customersResource = metamodel.getResources().getByPath("/customers");
Assert.assertNotNull("CustomerResource not found", customersResource);
- WorkbenchUtils.removeFirstOccurrenceOfCode(customersResource.getJavaElement(), "@Path(CustomerResource.URI_BASE)");
+ WorkbenchUtils.removeFirstOccurrenceOfCode(customersResource.getJavaElement(),
+ "@Path(CustomerResource.URI_BASE)");
WorkbenchUtils.addTypeAnnotation(customersResource.getJavaElement(), "@Path(\"/foo\")");
// post-conditions
Assert.assertEquals(5, metamodel.getResources().getAll().size());
- Assert.assertEquals("Wrong uri path template", "/foo", customersResource.getUriPathTemplate());
+ Assert.assertEquals("Wrong uri path template", "/foo", customersResource.getMapping()
+ .getUriPathTemplateFragment());
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
}
@Test
@@ -160,15 +176,15 @@
Assert.assertEquals(5, metamodel.getResources().getAll().size());
Resource ordersResource = metamodel.getResources().getByPath("/orders");
Assert.assertNotNull("OrdersResource not found", ordersResource);
- Assert.assertTrue("Wrong mediatype capabilities", ordersResource.getMediaTypeCapabilities()
- .getProducedMimeTypes().isEmpty());
+ MediaTypeCapabilities procucedMediaTypes = ordersResource.getMapping().getProcucedMediaTypes();
+ Assert.assertTrue("Wrong mediatype capabilities", procucedMediaTypes.isEmpty());
// operation
WorkbenchUtils.addTypeAnnotation(ordersResource.getJavaElement(),
"import javax.ws.rs.Produces;\n@Produces(\"foo/bar\")");
// post-conditions
Assert.assertEquals(5, metamodel.getResources().getAll().size());
- Assert.assertEquals("Wrong mediatype capabilities", "foo/bar", ordersResource.getMediaTypeCapabilities()
- .getProducedMimeTypes().get(0));
+ Assert.assertEquals("Wrong mediatype capabilities", "foo/bar", procucedMediaTypes.get(0));
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
}
@Test
@@ -177,14 +193,17 @@
Assert.assertEquals(5, metamodel.getResources().getAll().size());
Resource customersResource = metamodel.getResources().getByPath("/customers");
Assert.assertNotNull("CustomersResource not found", customersResource);
+ MediaTypeCapabilities procucedMediaTypes = customersResource.getMapping().getProcucedMediaTypes();
+ Assert.assertEquals("Wrong mediatype capabilities", "application/vnd.bytesparadise.customer+xml",
+ procucedMediaTypes.get(0));
// operation
WorkbenchUtils.replaceFirstOccurrenceOfCode(customersResource.getJavaElement(),
"{ \"application/vnd.bytesparadise.customer+xml\", "
+ "MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }", "\"foo/bar\"");
// post-conditions
Assert.assertEquals(5, metamodel.getResources().getAll().size());
- Assert.assertEquals("Wrong mediatype capabilities", "foo/bar", customersResource.getMediaTypeCapabilities()
- .getProducedMimeTypes().get(0));
+ Assert.assertEquals("Wrong mediatype capabilities", "foo/bar", procucedMediaTypes.get(0));
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
}
@Test
@@ -193,14 +212,17 @@
Assert.assertEquals(5, metamodel.getResources().getAll().size());
Resource customersResource = metamodel.getResources().getByPath("/customers");
Assert.assertNotNull("CustomersResource not found", customersResource);
+ MediaTypeCapabilities procucedMediaTypes = customersResource.getMapping().getProcucedMediaTypes();
+ Assert.assertEquals("Wrong mediatype capabilities", "application/vnd.bytesparadise.customer+xml",
+ procucedMediaTypes.get(0));
// operation
WorkbenchUtils.removeFirstOccurrenceOfCode(customersResource.getJavaElement(),
"@Produces({ \"application/vnd.bytesparadise.customer+xml\", "
+ "MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })");
// post-conditions
Assert.assertEquals(5, metamodel.getResources().getAll().size());
- Assert.assertTrue("Wrong mediatype capabilities", customersResource.getMediaTypeCapabilities()
- .getProducedMimeTypes().isEmpty());
+ Assert.assertTrue("Wrong mediatype capabilities", procucedMediaTypes.isEmpty());
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
}
@Test
@@ -209,15 +231,15 @@
Assert.assertEquals(5, metamodel.getResources().getAll().size());
Resource ordersResource = metamodel.getResources().getByPath("/orders");
Assert.assertNotNull("OrdersResource not found", ordersResource);
- Assert.assertTrue("Wrong mediatype capabilities", ordersResource.getMediaTypeCapabilities()
- .getConsumedMimeTypes().isEmpty());
+ MediaTypeCapabilities consumedMediaTypes = ordersResource.getMapping().getConsumedMediaTypes();
+ Assert.assertTrue("Wrong mediatype capabilities", consumedMediaTypes.isEmpty());
// operation
WorkbenchUtils.addTypeAnnotation(ordersResource.getJavaElement(),
"import javax.ws.rs.Consumes;\n@Consumes(\"foo/bar\")");
// post-conditions
Assert.assertEquals(5, metamodel.getResources().getAll().size());
- Assert.assertEquals("Wrong mediatype capabilities", "foo/bar", ordersResource.getMediaTypeCapabilities()
- .getConsumedMimeTypes().get(0));
+ Assert.assertEquals("Wrong mediatype capabilities", "foo/bar", consumedMediaTypes.get(0));
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
}
@Test
@@ -226,13 +248,15 @@
Assert.assertEquals(5, metamodel.getResources().getAll().size());
Resource customersResource = metamodel.getResources().getByPath("/customers");
Assert.assertNotNull("CustomersResource not found", customersResource);
+ MediaTypeCapabilities consumedMediaTypes = customersResource.getMapping().getConsumedMediaTypes();
+ Assert.assertEquals("Wrong mediatype capabilities", MediaType.APPLICATION_XML, consumedMediaTypes.get(0));
// operation
WorkbenchUtils.replaceFirstOccurrenceOfCode(customersResource.getJavaElement(), "MediaType.APPLICATION_XML",
"\"foo/bar\"");
// post-conditions
Assert.assertEquals(5, metamodel.getResources().getAll().size());
- Assert.assertEquals("Wrong mediatype capabilities", "foo/bar", customersResource.getMediaTypeCapabilities()
- .getConsumedMimeTypes().get(0));
+ Assert.assertEquals("Wrong mediatype capabilities", "foo/bar", consumedMediaTypes.get(0));
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
}
@Test
@@ -241,13 +265,15 @@
Assert.assertEquals(5, metamodel.getResources().getAll().size());
Resource customersResource = metamodel.getResources().getByPath("/customers");
Assert.assertNotNull("CustomersResource not found", customersResource);
+ MediaTypeCapabilities consumedMediaTypes = customersResource.getMapping().getConsumedMediaTypes();
+ Assert.assertEquals("Wrong mediatype capabilities", MediaType.APPLICATION_XML, consumedMediaTypes.get(0));
// operation
WorkbenchUtils.removeFirstOccurrenceOfCode(customersResource.getJavaElement(),
"@Consumes(MediaType.APPLICATION_XML)");
// post-conditions
Assert.assertEquals(5, metamodel.getResources().getAll().size());
- Assert.assertTrue("Wrong mediatype capabilities", customersResource.getMediaTypeCapabilities()
- .getConsumedMimeTypes().isEmpty());
+ Assert.assertTrue("Wrong mediatype capabilities", consumedMediaTypes.isEmpty());
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
}
@Test
@@ -268,5 +294,6 @@
// post-conditions 2: errors reported (import is missing)
Assert.assertEquals(6, metamodel.getHttpMethods().size());
Assert.assertFalse("Resource still marked with errors", fooResource.hasErrors());
+ Assert.assertEquals("Wrong number of routes", 12, metamodel.getRoutes().getAll().size());
}
}
Modified: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/builder/ResourceMethodChangesTestCase.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/builder/ResourceMethodChangesTestCase.java 2011-06-07 21:36:55 UTC (rev 31888)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/builder/ResourceMethodChangesTestCase.java 2011-06-07 21:43:35 UTC (rev 31889)
@@ -27,6 +27,7 @@
import org.jboss.tools.ws.jaxrs.core.metamodel.Resource;
import org.jboss.tools.ws.jaxrs.core.metamodel.ResourceMethod;
import org.jboss.tools.ws.jaxrs.core.metamodel.Resources;
+import org.jboss.tools.ws.jaxrs.core.metamodel.Route;
import org.junit.Assert;
import org.junit.Test;
@@ -42,12 +43,13 @@
Resources resources = metamodel.getResources();
Resource resource = resources.getByTypeName("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
Assert.assertNotNull("Resource not found");
- Assert.assertEquals("Wrong number of resourceMethods", 6, resource.getAllMethods().size());
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
// operation
WorkbenchUtils.removeMethod(resource.getJavaElement(), "createCustomer");
// post-condition
Assert.assertEquals("Wrong number of resourceMethods : should have decreased:", 5, resource.getAllMethods()
.size());
+ Assert.assertEquals("Wrong number of routes", 9, metamodel.getRoutes().getAll().size());
}
@Test
@@ -61,6 +63,7 @@
WorkbenchUtils.addMethod(resource.getJavaElement(), contents);
// post-conditions
Assert.assertEquals("Wrong number of resourceMethods", 7, resource.getAllMethods().size());
+ Assert.assertEquals("Wrong number of routes", 11, metamodel.getRoutes().getAll().size());
}
@Test
@@ -74,6 +77,7 @@
WorkbenchUtils.addMethod(resource.getJavaElement(), contents);
// post-conditions
Assert.assertEquals("Wrong number of resourceMethods", 6, resource.getAllMethods().size());
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
}
@Test
@@ -86,6 +90,7 @@
WorkbenchUtils.removeMethod(resource.getJavaElement().getCompilationUnit(), "getEntityManager");
// post-conditions
Assert.assertEquals("Wrong number of resourceMethods", 6, resource.getAllMethods().size());
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
}
@Test
@@ -93,18 +98,19 @@
// pre-conditions
Resource resource = metamodel.getResources().getByTypeName(
"org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
- Assert.assertEquals("Wrong number of resourceMethods", 6, resource.getAllMethods().size());
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
Assert.assertEquals("Wrong number of resource resourceMethods", 2, resource.getResourceMethods().size());
Assert.assertEquals("Wrong number of subresource resourceMethods", 4, resource.getSubresourceMethods().size());
Assert.assertEquals("Wrong number of subresource locators", 0, resource.getSubresourceLocators().size());
// operation
HTTPMethod httpMethod = metamodel.getHttpMethods().getByVerb("POST");
- ResourceMethod resourceMethod = resource.getByURIMapping(httpMethod, null, null, null);
- WorkbenchUtils.addMethodAnnotion(resourceMethod.getJavaElement(), "@Path(\"/foo\")");
+ ResourceMethod resourceMethod = resource.getByMapping(httpMethod, null, null, null);
+ WorkbenchUtils.addMethodAnnotation(resourceMethod.getJavaElement(), "@Path(\"/foo\")");
// post-conditions
Assert.assertEquals("Wrong number of resource resourceMethods", 1, resource.getResourceMethods().size());
Assert.assertEquals("Wrong number of subresource resourceMethods", 5, resource.getSubresourceMethods().size());
Assert.assertEquals("Wrong number of subresource locators", 0, resource.getSubresourceLocators().size());
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
}
@Test
@@ -114,22 +120,26 @@
"org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
IMethod method = WorkbenchUtils.addMethod(resource.getJavaElement(),
"public Object fooLocator() { return null; }");
- Assert.assertEquals("Wrong number of resourceMethods", 6, resource.getAllMethods().size());
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
Assert.assertEquals("Wrong number of resource resourceMethods", 2, resource.getResourceMethods().size());
Assert.assertEquals("Wrong number of subresource resourceMethods", 4, resource.getSubresourceMethods().size());
List<ResourceMethod> subresourceLocators = resource.getSubresourceLocators();
Assert.assertEquals("Wrong number of subresource locators", 0, subresourceLocators.size());
// operation
- WorkbenchUtils.addMethodAnnotion(method, "@Path(\"/foo\")");
+ WorkbenchUtils.addMethodAnnotation(method, "@Path(\"/foo\")");
// post-conditions
subresourceLocators = resource.getSubresourceLocators();
Assert.assertEquals("Wrong number of resource resourceMethods", 2, resource.getResourceMethods().size());
Assert.assertEquals("Wrong number of subresource resourceMethods", 4, resource.getSubresourceMethods().size());
Assert.assertEquals("Wrong number of subresource locators", 1, subresourceLocators.size());
- Assert.assertNotNull("PathParam mapping not found", subresourceLocators.get(0).getUriMapping().getPathParams());
- Assert.assertNull("HTTP Method mapping not expected", subresourceLocators.get(0).getUriMapping()
- .getHTTPMethod());
+ Assert.assertNotNull("PathParam mapping not found", subresourceLocators.get(0).getMapping().getPathParams());
+ Assert.assertNull("HTTP Method mapping not expected", subresourceLocators.get(0).getMapping().getHTTPMethod());
+ Assert.assertEquals("Wrong number of routes", 13, metamodel.getRoutes().getAll().size());
+ Resource gameResource = metamodel.getResources().getByTypeName(
+ "org.jboss.tools.ws.jaxrs.sample.services.GameResource");
+ Assert.assertEquals("Wrong number", 2,
+ metamodel.getRoutes().getByResourceMethod(gameResource.getAllMethods().get(0)).size());
}
@Test
@@ -137,6 +147,7 @@
// pre-conditions
Resource resource = metamodel.getResources().getByTypeName(
"org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator");
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
Assert.assertEquals("Wrong number of resource resourceMethods", 0, resource.getResourceMethods().size());
Assert.assertEquals("Wrong number of subresource resourceMethods", 0, resource.getSubresourceMethods().size());
Assert.assertEquals("Wrong number of subresource locators", 1, resource.getSubresourceLocators().size());
@@ -146,6 +157,7 @@
Assert.assertEquals("Wrong number of resource resourceMethods", 0, resource.getResourceMethods().size());
Assert.assertEquals("Wrong number of subresource resourceMethods", 0, resource.getSubresourceMethods().size());
Assert.assertEquals("Wrong number of subresource locators", 0, resource.getSubresourceLocators().size());
+ Assert.assertEquals("Wrong number of routes", 7, metamodel.getRoutes().getAll().size());
}
@Test
@@ -153,7 +165,7 @@
// pre-conditions
Resource resource = metamodel.getResources().getByTypeName(
"org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
- Assert.assertEquals("Wrong number of resourceMethods", 6, resource.getAllMethods().size());
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
Assert.assertEquals("Wrong number of resource resourceMethods", 2, resource.getResourceMethods().size());
Assert.assertEquals("Wrong number of subresource resourceMethods", 4, resource.getSubresourceMethods().size());
Assert.assertEquals("Wrong number of subresource locators", 0, resource.getSubresourceLocators().size());
@@ -163,6 +175,7 @@
Assert.assertEquals("Wrong number of resource resourceMethods", 3, resource.getResourceMethods().size());
Assert.assertEquals("Wrong number of subresource resourceMethods", 3, resource.getSubresourceMethods().size());
Assert.assertEquals("Wrong number of subresource locators", 0, resource.getSubresourceLocators().size());
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
}
@Test
@@ -170,36 +183,66 @@
// pre-conditions
Resource resource = metamodel.getResources().getByTypeName(
"org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
- Assert.assertEquals("Wrong number of resourceMethods", 6, resource.getAllMethods().size());
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
Assert.assertEquals("Wrong number of resource resourceMethods", 2, resource.getResourceMethods().size());
Assert.assertEquals("Wrong number of subresource resourceMethods", 4, resource.getSubresourceMethods().size());
Assert.assertEquals("Wrong number of subresource locators", 0, resource.getSubresourceLocators().size());
// operation
- WorkbenchUtils.addMethodAnnotion(resource.getJavaElement().getMethod("getEntityManager", null), "@GET");
+ WorkbenchUtils.addMethodAnnotation(resource.getJavaElement().getMethod("getEntityManager", null), "@GET");
// post-conditions
- Assert.assertEquals("Wrong number of resourceMethods", 7, resource.getAllMethods().size());
Assert.assertEquals("Wrong number of resource resourceMethods", 3, resource.getResourceMethods().size());
Assert.assertEquals("Wrong number of subresource resourceMethods", 4, resource.getSubresourceMethods().size());
Assert.assertEquals("Wrong number of subresource locators", 0, resource.getSubresourceLocators().size());
+ Assert.assertEquals("Wrong number of routes", 11, metamodel.getRoutes().getAll().size());
}
@Test
+ public void shouldChangeWhenModifyingHTTPMethodAnnotation() throws CoreException {
+ // pre-conditions
+ Resource resource = metamodel.getResources().getByTypeName(
+ "org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
+ Assert.assertEquals("Wrong number of resource resourceMethods", 2, resource.getResourceMethods().size());
+ Assert.assertEquals("Wrong number of subresource resourceMethods", 4, resource.getSubresourceMethods().size());
+ Assert.assertEquals("Wrong number of subresource locators", 0, resource.getSubresourceLocators().size());
+ ResourceMethod resourceMethod = null;
+ for (ResourceMethod r : resource.getResourceMethods()) {
+ if (r.getMapping().getHTTPMethod().getHttpVerb().equals("POST")) {
+ resourceMethod = r;
+ }
+ }
+ Route route = metamodel.getRoutes().getByResourceMethod(resourceMethod).get(0);
+ Assert.assertEquals("Wrong HttpMethod", "POST", route.getEndpoint().getHttpMethod().getHttpVerb());
+ // operation
+ WorkbenchUtils.replaceFirstOccurrenceOfCode(resourceMethod.getJavaElement(), "@POST", "@DELETE");
+ // post-conditions
+ Assert.assertEquals("Wrong number of resource resourceMethods", 2, resource.getResourceMethods().size());
+ Assert.assertEquals("Wrong number of subresource resourceMethods", 4, resource.getSubresourceMethods().size());
+ Assert.assertEquals("Wrong number of subresource locators", 0, resource.getSubresourceLocators().size());
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
+ Assert.assertEquals("Wrong HttpMethod", "DELETE", route.getEndpoint().getHttpMethod().getHttpVerb());
+ }
+
+ @Test
public void shouldBecomeSubresourceMethodWhenAddingHTTPMethodAnnotation() throws CoreException {
// pre-conditions
Resource resource = metamodel.getResources().getByTypeName(
"org.jboss.tools.ws.jaxrs.sample.services.ProductResourceLocator");
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
Assert.assertEquals("Wrong number of resource resourceMethods", 0, resource.getResourceMethods().size());
Assert.assertEquals("Wrong number of subresource resourceMethods", 0, resource.getSubresourceMethods().size());
Assert.assertEquals("Wrong number of subresource locators", 1, resource.getSubresourceLocators().size());
- ResourceMethod resourceMethod = resource.getByURIMapping(null, "/{type}", null, null);
+ ResourceMethod resourceMethod = resource.getByMapping(null, "/{type}", null, null);
Assert.assertNotNull("ResourceMethod not found", resourceMethod);
// operation
WorkbenchUtils.addImport(resourceMethod.getJavaElement().getCompilationUnit(), GET.class.getName());
- WorkbenchUtils.addMethodAnnotion(resourceMethod.getJavaElement(), "@GET");
+ WorkbenchUtils.addMethodAnnotation(resourceMethod.getJavaElement(), "@GET");
// post-conditions
Assert.assertEquals("Wrong number of resource resourceMethods", 0, resource.getResourceMethods().size());
Assert.assertEquals("Wrong number of subresource resourceMethods", 1, resource.getSubresourceMethods().size());
Assert.assertEquals("Wrong number of subresource locators", 0, resource.getSubresourceLocators().size());
+ // -3, +1
+ Assert.assertEquals("Wrong number of routes", 8, metamodel.getRoutes().getAll().size());
}
@Test
@@ -207,16 +250,20 @@
// pre-conditions
Resource resource = metamodel.getResources().getByTypeName(
"org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
- Assert.assertEquals("Wrong number of resourceMethods", 6, resource.getAllMethods().size());
Assert.assertEquals("Wrong number of resource resourceMethods", 2, resource.getResourceMethods().size());
Assert.assertEquals("Wrong number of subresource resourceMethods", 4, resource.getSubresourceMethods().size());
Assert.assertEquals("Wrong number of subresource locators", 0, resource.getSubresourceLocators().size());
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
// operation
WorkbenchUtils.removeMethodAnnotation(resource.getJavaElement(), "getCustomerAsVCard", "@GET");
// post-conditions
Assert.assertEquals("Wrong number of resource resourceMethods", 2, resource.getResourceMethods().size());
Assert.assertEquals("Wrong number of subresource resourceMethods", 3, resource.getSubresourceMethods().size());
Assert.assertEquals("Wrong number of subresource locators", 1, resource.getSubresourceLocators().size());
+ // -1, but nothing more as the subresource locator does not match with
+ // any resource (returning Response type!)
+ LOGGER.debug("Remaing routes:\n{}", metamodel.getRoutes().getAll());
+ Assert.assertEquals("Wrong number of routes", 9, metamodel.getRoutes().getAll().size());
}
@Test
@@ -224,7 +271,7 @@
// pre-conditions
Resource resource = metamodel.getResources().getByTypeName(
"org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
- Assert.assertEquals("Wrong number of resourceMethods", 6, resource.getAllMethods().size());
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
Assert.assertEquals("Wrong number of resource resourceMethods", 2, resource.getResourceMethods().size());
Assert.assertEquals("Wrong number of subresource resourceMethods", 4, resource.getSubresourceMethods().size());
Assert.assertEquals("Wrong number of subresource locators", 0, resource.getSubresourceLocators().size());
@@ -234,185 +281,393 @@
Assert.assertEquals("Wrong number of resource resourceMethods", 1, resource.getResourceMethods().size());
Assert.assertEquals("Wrong number of subresource resourceMethods", 4, resource.getSubresourceMethods().size());
Assert.assertEquals("Wrong number of subresource locators", 0, resource.getSubresourceLocators().size());
+ Assert.assertEquals("Wrong number of routes", 9, metamodel.getRoutes().getAll().size());
}
- public void shouldChangeWhenModifyingPathAnnotationValue() throws CoreException {
+ @Test
+ public void shouldChangeWhenAddingPathAnnotationValueAtTypeLevel() throws CoreException {
+ Resource resource = metamodel.getResources().getByTypeName(
+ "org.jboss.tools.ws.jaxrs.sample.services.GameResource");
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
+ Route route = metamodel.getRoutes().getByResourceMethod(resource.getSubresourceMethods().get(0)).get(0);
+ Assert.assertEquals("Wrong mediatypes", "/products/{type}/{id}", route.getEndpoint().getUriPathTemplate());
+ // operation
+ WorkbenchUtils.addTypeAnnotation(resource.getJavaElement(), "@Path(\"/foo\")");
+ // post-conditions
+ Assert.assertTrue(resource.isRootResource());
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
+ route = metamodel.getRoutes().getByResourceMethod(resource.getSubresourceMethods().get(0)).get(0);
+ Assert.assertEquals("Wrong URI Path Template", "/foo/{id}", route.getEndpoint().getUriPathTemplate());
+ }
+
+ @Test
+ public void shouldChangeWhenModifyingPathAnnotationValueAtTypeLevel() throws CoreException {
// pre-conditions
Resource resource = metamodel.getResources().getByTypeName(
"org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
- Assert.assertEquals("Wrong number of resourceMethods", 6, resource.getAllMethods().size());
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
HTTPMethod httpMethod = metamodel.getHttpMethods().getByVerb("GET");
- ResourceMethod resourceMethod = resource.getByURIMapping(httpMethod, "{id}", null, null);
+ ResourceMethod resourceMethod = resource.getByMapping(httpMethod, "{id}", null, null);
Assert.assertNotNull("ResourceMethod not found", resourceMethod);
+ Route route = resourceMethod.getMetamodel().getRoutes().getByResourceMethod(resourceMethod).get(0);
+ Assert.assertEquals("Wrong template", "/customers/{id}", route.getEndpoint().getUriPathTemplate());
// operation
+ WorkbenchUtils.replaceFirstOccurrenceOfCode(resourceMethod.getParentResource().getJavaElement(),
+ "@Path(CustomerResource.URI_BASE)", "@Path(\"/foo\")");
+ // post-conditions
+ Assert.assertNotNull("No result expected", resource.getByMapping(httpMethod, "{id}", null, null));
+ Assert.assertEquals("Wrong template", "/foo/{id}", route.getEndpoint().getUriPathTemplate());
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
+ }
+
+ @Test
+ public void shouldChangeWhenRemovingPathAnnotationValueAtTypeLevel() throws CoreException {
+ Resource resource = metamodel.getResources().getByTypeName(
+ "org.jboss.tools.ws.jaxrs.sample.services.PurchaseOrderResource");
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
+ Route route = metamodel.getRoutes().getByResourceMethod(resource.getSubresourceMethods().get(0)).get(0);
+ Assert.assertEquals("Wrong mediatypes", "/orders/{id}", route.getEndpoint().getUriPathTemplate());
+ // operation
+ WorkbenchUtils.removeFirstOccurrenceOfCode(resource.getJavaElement(), "@Path(\"/orders\")");
+ // post-conditions
+ Assert.assertFalse(resource.isRootResource());
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
+ route = metamodel.getRoutes().getByResourceMethod(resource.getSubresourceMethods().get(0)).get(0);
+ Assert.assertEquals("Wrong URI Path Template", "/products/{type}/{id}", route.getEndpoint()
+ .getUriPathTemplate());
+ }
+
+ @Test
+ public void shouldChangeWhenAddingPathAnnotationAtMethodLevel() throws CoreException {
+ // pre-conditions
+ Resource resource = metamodel.getResources().getByTypeName(
+ "org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
+ HTTPMethod httpMethod = metamodel.getHttpMethods().getByVerb("POST");
+ ResourceMethod resourceMethod = resource.getByMapping(httpMethod, null, null, null);
+ Assert.assertNotNull("ResourceMethod not found", resourceMethod);
+ Route route = resourceMethod.getMetamodel().getRoutes().getByResourceMethod(resourceMethod).get(0);
+ Assert.assertEquals("Wrong template", "/customers", route.getEndpoint().getUriPathTemplate());
+ // operation
+ WorkbenchUtils.addMethodAnnotation(resourceMethod.getJavaElement(), "@Path(\"{id}\")");
+ // post-conditions
+ Assert.assertNotNull("No result expected", resource.getByMapping(httpMethod, "{id}", null, null));
+ Assert.assertEquals("Wrong template", "/customers/{id}", route.getEndpoint().getUriPathTemplate());
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
+ }
+
+ public void shouldChangeWhenModifyingPathAnnotationValueAtMethodLevel() throws CoreException {
+ // pre-conditions
+ Resource resource = metamodel.getResources().getByTypeName(
+ "org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
+ HTTPMethod httpMethod = metamodel.getHttpMethods().getByVerb("GET");
+ ResourceMethod resourceMethod = resource.getByMapping(httpMethod, "{id}", null, null);
+ Assert.assertNotNull("ResourceMethod not found", resourceMethod);
+ Route route = resourceMethod.getMetamodel().getRoutes().getByResourceMethod(resourceMethod).get(0);
+ Assert.assertEquals("Wrong template", "/customers/{id}", route.getEndpoint().getUriPathTemplate());
+ // operation
WorkbenchUtils.replaceFirstOccurrenceOfCode(resourceMethod.getJavaElement(), "@Path(\"{id}\")",
"@Path(\"{idCustomer}\")");
// post-conditions
- Assert.assertNull("No result expected", resource.getByURIMapping(httpMethod, "{id}", null, null));
- Assert.assertNotNull("No result found", resource.getByURIMapping(httpMethod, "{idCustomer}", null, null));
+ Assert.assertNull("No result expected", resource.getByMapping(httpMethod, "{id}", null, null));
+ Assert.assertNotNull("No result found", resource.getByMapping(httpMethod, "{idCustomer}", null, null));
+ Assert.assertEquals("Wrong template", "/customers/{idCustomer}", route.getEndpoint().getUriPathTemplate());
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
}
@Test
- public void shouldChangeWhenAddingProducesAnnotation() throws CoreException {
+ public void shouldChangeWhenRemovingPathAnnotationAtMethodLevel() throws CoreException {
// pre-conditions
Resource resource = metamodel.getResources().getByTypeName(
"org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
- Assert.assertEquals("Wrong number of resourceMethods", 6, resource.getAllMethods().size());
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
+ HTTPMethod httpMethod = metamodel.getHttpMethods().getByVerb("DELETE");
+ ResourceMethod resourceMethod = resource.getByMapping(httpMethod, "{id}", null, null);
+ Assert.assertNotNull("ResourceMethod not found", resourceMethod);
+ Route route = resourceMethod.getMetamodel().getRoutes().getByResourceMethod(resourceMethod).get(0);
+ Assert.assertEquals("Wrong template", "/customers/{id}", route.getEndpoint().getUriPathTemplate());
+ // operation
+ WorkbenchUtils.removeMethodAnnotation(resourceMethod.getJavaElement(), "@Path(\"{id}\")");
+ // post-conditions
+ Assert.assertNull("No result expected", resource.getByMapping(httpMethod, "{id}", null, null));
+ Assert.assertEquals("Wrong template", "/customers", route.getEndpoint().getUriPathTemplate());
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
+ }
+
+ @Test
+ public void shouldChangeWhenAddingProducesAnnotationAtMethodLevel() throws CoreException {
+ // pre-conditions
+ Resource resource = metamodel.getResources().getByTypeName(
+ "org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
HTTPMethod httpMethod = metamodel.getHttpMethods().getByVerb("GET");
- ResourceMethod resourceMethod = resource.getByURIMapping(httpMethod, "{id}", null, null);
+ ResourceMethod resourceMethod = resource.getByMapping(httpMethod, "{id}", null, null);
Assert.assertNotNull("ResourceMethod not found", resourceMethod);
- Assert.assertTrue("No result expected", resourceMethod.getUriMapping().getMediaTypeCapabilities()
- .getProducedMimeTypes().isEmpty());
+ MediaTypeCapabilities methodMediaTypes = resourceMethod.getMapping().getProcucedMediaTypes();
+ Assert.assertTrue("Wrong result", methodMediaTypes.isEmpty());
+ Route route = resourceMethod.getMetamodel().getRoutes().getByResourceMethod(resourceMethod).get(0);
+ Assert.assertEquals("Wrong mediatypes", 3, route.getEndpoint().getProducedMediaTypes().size());
// operation
- WorkbenchUtils.addMethodAnnotion(resourceMethod.getJavaElement(), "@Produces(\"foo/bar\")");
+ WorkbenchUtils.addMethodAnnotation(resourceMethod.getJavaElement(), "@Produces(\"foo/bar\")");
// post-conditions
- Assert.assertEquals("No result found", "foo/bar", resourceMethod.getUriMapping().getMediaTypeCapabilities()
- .getProducedMimeTypes().get(0));
+ Assert.assertEquals("No result found", "foo/bar", methodMediaTypes.get(0));
+ Assert.assertEquals("Wrong mediatypes", "foo/bar", route.getEndpoint().getProducedMediaTypes().get(0));
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
}
@Test
- public void shouldChangeWhenModifyingProducesAnnotation() throws CoreException {
+ public void shouldChangeWhenAddingProducesAnnotationAtTypeLevel() throws CoreException {
// pre-conditions
Resource resource = metamodel.getResources().getByTypeName(
+ "org.jboss.tools.ws.jaxrs.sample.services.PurchaseOrderResource");
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
+ String contents = WorkbenchUtils.getResourceContent("FooResourceMethod.txt", bundle);
+ WorkbenchUtils.addImport(resource.getJavaElement(), "javax.ws.rs.POST");
+ WorkbenchUtils.addImport(resource.getJavaElement(), "javax.ws.rs.core.Response");
+ WorkbenchUtils.addMethod(resource.getJavaElement(), contents);
+ HTTPMethod httpMethod = metamodel.getHttpMethods().getByVerb("POST");
+ ResourceMethod resourceMethod = resource.getByMapping(httpMethod, null, null, null);
+ Assert.assertNotNull("ResourceMethod not found", resourceMethod);
+ MediaTypeCapabilities methodMediaTypes = resourceMethod.getMapping().getProcucedMediaTypes();
+ Assert.assertTrue("Wrong result", methodMediaTypes.isEmpty());
+ Route route = resourceMethod.getMetamodel().getRoutes().getByResourceMethod(resourceMethod).get(0);
+ MediaTypeCapabilities resolvedMediaTypes = route.getEndpoint().getProducedMediaTypes();
+ Assert.assertEquals("Wrong mediatypes", "*/*", resolvedMediaTypes.get(0));
+ // operation
+ WorkbenchUtils.addTypeAnnotation(resourceMethod.getParentResource().getJavaElement(), "@Produces(\"foo/bar\")");
+ // post-conditions
+ Assert.assertTrue("Wrong result", methodMediaTypes.isEmpty());
+ route = resourceMethod.getMetamodel().getRoutes().getByResourceMethod(resourceMethod).get(0);
+ resolvedMediaTypes = route.getEndpoint().getProducedMediaTypes();
+ Assert.assertEquals("Wrong mediatypes", "foo/bar", resolvedMediaTypes.get(0));
+ Assert.assertEquals("Wrong number of routes", 11, metamodel.getRoutes().getAll().size());
+ }
+
+ @Test
+ public void shouldNotChangeWhenModifyingProducesAnnotationAtTypeLevel() throws CoreException {
+ // pre-conditions
+ Resource resource = metamodel.getResources().getByTypeName(
"org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
Assert.assertEquals("Wrong number of resourceMethods", 6, resource.getAllMethods().size());
HTTPMethod httpMethod = metamodel.getHttpMethods().getByVerb("GET");
- ResourceMethod resourceMethod = resource.getByURIMapping(httpMethod, "{id}", null, "text/x-vcard");
+ ResourceMethod resourceMethod = resource.getByMapping(httpMethod, "{id}", null, "text/x-vcard");
Assert.assertNotNull("ResourceMethod not found", resourceMethod);
- Assert.assertEquals("Wrong result:", "text/x-vcard", resourceMethod.getUriMapping().getMediaTypeCapabilities()
- .getProducedMimeTypes().get(0));
+ MediaTypeCapabilities methodMediaTypes = resourceMethod.getMapping().getProcucedMediaTypes();
+ Assert.assertEquals("Wrong result:", "text/x-vcard", methodMediaTypes.get(0));
+ Route route = resourceMethod.getMetamodel().getRoutes().getByResourceMethod(resourceMethod).get(0);
+ MediaTypeCapabilities resolvedMediaTypes = route.getEndpoint().getProducedMediaTypes();
+ Assert.assertEquals("Wrong mediatypes", "text/x-vcard", resolvedMediaTypes.get(0));
+
// operation
+ WorkbenchUtils
+ .replaceFirstOccurrenceOfCode(
+ resourceMethod.getJavaElement().getDeclaringType(),
+ "@Produces({ \"application/vnd.bytesparadise.customer+xml\", MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })",
+ "@Produces(\"foo/bar\")");
+ // post-conditions
+ Assert.assertEquals("Wrong result:", "text/x-vcard", methodMediaTypes.get(0));
+ Assert.assertEquals("Wrong mediatypes", "text/x-vcard", resolvedMediaTypes.get(0));
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
+ }
+
+ @Test
+ public void shouldChangeWhenModifyingProducesAnnotationAtMethodLevel() throws CoreException {
+ // pre-conditions
+ Resource resource = metamodel.getResources().getByTypeName(
+ "org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
+ HTTPMethod httpMethod = metamodel.getHttpMethods().getByVerb("GET");
+ ResourceMethod resourceMethod = resource.getByMapping(httpMethod, "{id}", null, "text/x-vcard");
+ Assert.assertNotNull("ResourceMethod not found", resourceMethod);
+ MediaTypeCapabilities methodMediaTypes = resourceMethod.getMapping().getProcucedMediaTypes();
+ Assert.assertEquals("Wrong result:", "text/x-vcard", methodMediaTypes.get(0));
+ Route route = resourceMethod.getMetamodel().getRoutes().getByResourceMethod(resourceMethod).get(0);
+ MediaTypeCapabilities resolvedMediaTypes = route.getEndpoint().getProducedMediaTypes();
+ Assert.assertEquals("Wrong mediatypes", "text/x-vcard", resolvedMediaTypes.get(0));
+ // operation
WorkbenchUtils.replaceFirstOccurrenceOfCode(resourceMethod.getJavaElement(), "@Produces({ \"text/x-vcard\" })",
"@Produces(\"foo/bar\")");
// post-conditions
- Assert.assertEquals("Wrong result:", "foo/bar", resourceMethod.getUriMapping().getMediaTypeCapabilities()
- .getProducedMimeTypes().get(0));
+ Assert.assertEquals("Wrong result:", "foo/bar", methodMediaTypes.get(0));
+ Assert.assertEquals("Wrong mediatypes", "foo/bar", resolvedMediaTypes.get(0));
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
}
@Test
- public void shouldChangeWhenRemovingProducesAnnotation() throws CoreException {
+ public void shouldChangeWhenRemovingProducesAnnotationAtMethodLevel() throws CoreException {
// pre-conditions
Resource resource = metamodel.getResources().getByTypeName(
"org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
- Assert.assertEquals("Wrong number of resourceMethods", 6, resource.getAllMethods().size());
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
HTTPMethod httpMethod = metamodel.getHttpMethods().getByVerb("GET");
- ResourceMethod resourceMethod = resource.getByURIMapping(httpMethod, "{id}", null, "text/x-vcard");
+ ResourceMethod resourceMethod = resource.getByMapping(httpMethod, "{id}", null, "text/x-vcard");
Assert.assertNotNull("ResourceMethod not found", resourceMethod);
- List<String> producedMimeTypes = resourceMethod.getUriMapping().getMediaTypeCapabilities()
- .getProducedMimeTypes();
- Assert.assertEquals("No result found", "text/x-vcard", producedMimeTypes.get(0));
+ List<String> producedMimeTypes = resourceMethod.getMapping().getProcucedMediaTypes().getMediatypes();
+ Assert.assertEquals("Wrong result", "text/x-vcard", producedMimeTypes.get(0));
+ Route route = resourceMethod.getMetamodel().getRoutes().getByResourceMethod(resourceMethod).get(0);
+ MediaTypeCapabilities resolvedMediaTypes = route.getEndpoint().getProducedMediaTypes();
+ Assert.assertEquals("Wrong mediatypes", "text/x-vcard", resolvedMediaTypes.get(0));
// operation
WorkbenchUtils.removeMethodAnnotation(resourceMethod.getJavaElement(), "@Produces({ \"text/x-vcard\" })");
- // post-conditions
- Assert.assertTrue("No result expected:" + producedMimeTypes, producedMimeTypes.isEmpty());
+ // post-conditions: type-level annotation value applies
+ Assert.assertTrue("Wrong mediatype capabilities", producedMimeTypes.isEmpty());
+ Assert.assertEquals("Wrong mediatypes", 3, resolvedMediaTypes.size());
+ Assert.assertEquals("Wrong mediatypes", "application/vnd.bytesparadise.customer+xml", resolvedMediaTypes.get(0));
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
}
@Test
- public void shouldChangeWhenAddingConsumesAnnotation() throws CoreException {
+ public void shouldChangeWhenAddingConsumesAnnotationAtMethodLevel() throws CoreException {
// pre-conditions
Resource resource = metamodel.getResources().getByTypeName(
"org.jboss.tools.ws.jaxrs.sample.services.GameResource");
HTTPMethod httpMethod = metamodel.getHttpMethods().getByVerb("GET");
- ResourceMethod resourceMethod = resource.getByURIMapping(httpMethod, "/{id}", null, null);
+ ResourceMethod resourceMethod = resource.getByMapping(httpMethod, "/{id}", null, null);
Assert.assertNotNull("ResourceMethod not found", resourceMethod);
- Assert.assertTrue("No result expected", resourceMethod.getUriMapping().getMediaTypeCapabilities()
- .getConsumedMimeTypes().isEmpty());
+ MediaTypeCapabilities consumedMediaTypes = resourceMethod.getMapping().getConsumedMediaTypes();
+ Assert.assertTrue("Wrong result", consumedMediaTypes.isEmpty());
+ Route route = resourceMethod.getMetamodel().getRoutes().getByResourceMethod(resourceMethod).get(0);
+ MediaTypeCapabilities resolvedMediaTypes = route.getEndpoint().getConsumedMediaTypes();
+ Assert.assertEquals("Wrong mediatypes", "application/xml", resolvedMediaTypes.get(0));
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
// operation
- WorkbenchUtils.addMethodAnnotion(resourceMethod.getJavaElement(), "@Consumes(\"foo/bar\")");
+ WorkbenchUtils.addMethodAnnotation(resourceMethod.getJavaElement(), "@Consumes(\"foo/bar\")");
// post-conditions
- Assert.assertEquals("No result found", "foo/bar", resourceMethod.getUriMapping().getMediaTypeCapabilities()
- .getConsumedMimeTypes().get(0));
+ Assert.assertEquals("No result found", "foo/bar", consumedMediaTypes.get(0));
+ Assert.assertEquals("Wrong mediatypes", "foo/bar", resolvedMediaTypes.get(0));
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
}
@Test
- public void shouldChangeWhenModifyingConsumesAnnotation() throws CoreException {
+ public void shouldChangeWhenAddingConsumesAnnotationAtTypeLevel() throws CoreException {
// pre-conditions
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
Resource resource = metamodel.getResources().getByTypeName(
+ "org.jboss.tools.ws.jaxrs.sample.services.BookResource");
+ HTTPMethod httpMethod = metamodel.getHttpMethods().getByVerb("GET");
+ ResourceMethod resourceMethod = resource.getByMapping(httpMethod, "/{id}", null, null);
+ Assert.assertNotNull("ResourceMethod not found", resourceMethod);
+ MediaTypeCapabilities consumedMediaTypes = resourceMethod.getMapping().getConsumedMediaTypes();
+ Assert.assertTrue("Wrong result", consumedMediaTypes.isEmpty());
+ Route route = resourceMethod.getMetamodel().getRoutes().getByResourceMethod(resourceMethod).get(0);
+ MediaTypeCapabilities resolvedMediaTypes = route.getEndpoint().getConsumedMediaTypes();
+ Assert.assertEquals("Wrong mediatypes", "*/*", resolvedMediaTypes.get(0));
+ // operation
+ WorkbenchUtils.addImport(resourceMethod.getJavaElement().getDeclaringType(), "javax.ws.rs.Consumes");
+ WorkbenchUtils.addTypeAnnotation(resourceMethod.getJavaElement().getDeclaringType(), "@Consumes(\"foo/bar\")");
+ // post-conditions
+ Assert.assertTrue("Wrong result", consumedMediaTypes.isEmpty());
+ Assert.assertEquals("Wrong mediatypes", "foo/bar", resolvedMediaTypes.get(0));
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
+ }
+
+ @Test
+ public void shouldChangeWhenModifyingConsumesAnnotationAtMethodLevel() throws CoreException {
+ // pre-conditions
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
+ Resource resource = metamodel.getResources().getByTypeName(
"org.jboss.tools.ws.jaxrs.sample.services.GameResource");
HTTPMethod httpMethod = metamodel.getHttpMethods().getByVerb("POST");
- ResourceMethod resourceMethod = resource.getByURIMapping(httpMethod, null, null, null);
+ ResourceMethod resourceMethod = resource.getByMapping(httpMethod, null, null, null);
Assert.assertNotNull("ResourceMethod not found", resourceMethod);
- MediaTypeCapabilities mediaTypeCapabilities = resourceMethod.getUriMapping().getMediaTypeCapabilities();
- Assert.assertEquals("No result found", "application/vnd.bytesparadise.game+xml", mediaTypeCapabilities
- .getConsumedMimeTypes().get(0));
- Assert.assertEquals("No result found", "application/xml", mediaTypeCapabilities.getConsumedMimeTypes().get(1));
- Assert.assertEquals("No result found", "application/json", mediaTypeCapabilities.getConsumedMimeTypes().get(2));
+ MediaTypeCapabilities mediaTypeCapabilities = resourceMethod.getMapping().getConsumedMediaTypes();
+ Assert.assertEquals("No result found", "application/vnd.bytesparadise.game+xml", mediaTypeCapabilities.get(0));
+ Assert.assertEquals("No result found", "application/xml", mediaTypeCapabilities.get(1));
+ Assert.assertEquals("No result found", "application/json", mediaTypeCapabilities.get(2));
+ Route route = resourceMethod.getMetamodel().getRoutes().getByResourceMethod(resourceMethod).get(0);
+ MediaTypeCapabilities resolvedMediaTypes = route.getEndpoint().getConsumedMediaTypes();
+ Assert.assertEquals("Wrong mediatypes", 3, resolvedMediaTypes.size());
// operation
WorkbenchUtils.replaceFirstOccurrenceOfCode(resourceMethod.getJavaElement(),
"@Consumes({ \"application/vnd.bytesparadise.game+xml\", \"application/xml\", \"application/json\" })",
"@Consumes(\"foo/bar\")");
// post-conditions
- Assert.assertEquals("No result found", 1, mediaTypeCapabilities.getConsumedMimeTypes().size());
- Assert.assertEquals("No result found", "foo/bar", mediaTypeCapabilities.getConsumedMimeTypes().get(0));
+ Assert.assertEquals("No result found", 1, mediaTypeCapabilities.size());
+ Assert.assertEquals("No result found", "foo/bar", mediaTypeCapabilities.get(0));
+ Assert.assertEquals("Wrong mediatypes", "foo/bar", resolvedMediaTypes.get(0));
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
}
@Test
- public void shouldChangeWhenRemovingConsumesAnnotation() throws CoreException {
+ public void shouldChangeWhenRemovingConsumesAnnotationAtMethodLevel() throws CoreException {
// pre-conditions
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
Resource resource = metamodel.getResources().getByTypeName(
"org.jboss.tools.ws.jaxrs.sample.services.GameResource");
HTTPMethod httpMethod = metamodel.getHttpMethods().getByVerb("POST");
- ResourceMethod resourceMethod = resource.getByURIMapping(httpMethod, null, null, null);
+ ResourceMethod resourceMethod = resource.getByMapping(httpMethod, null, null, null);
Assert.assertNotNull("ResourceMethod not found", resourceMethod);
- MediaTypeCapabilities mediaTypeCapabilities = resourceMethod.getUriMapping().getMediaTypeCapabilities();
- Assert.assertEquals("No result found", "application/vnd.bytesparadise.game+xml", mediaTypeCapabilities
- .getConsumedMimeTypes().get(0));
- Assert.assertEquals("No result found", "application/xml", mediaTypeCapabilities.getConsumedMimeTypes().get(1));
- Assert.assertEquals("No result found", "application/json", mediaTypeCapabilities.getConsumedMimeTypes().get(2));
+ MediaTypeCapabilities mediaTypeCapabilities = resourceMethod.getMapping().getConsumedMediaTypes();
+ Assert.assertEquals("No result found", "application/vnd.bytesparadise.game+xml", mediaTypeCapabilities.get(0));
+ Assert.assertEquals("No result found", "application/xml", mediaTypeCapabilities.get(1));
+ Assert.assertEquals("No result found", "application/json", mediaTypeCapabilities.get(2));
+ Route route = resourceMethod.getMetamodel().getRoutes().getByResourceMethod(resourceMethod).get(0);
+ MediaTypeCapabilities resolvedMediaTypes = route.getEndpoint().getConsumedMediaTypes();
+ Assert.assertEquals("Wrong mediatypes", 3, resolvedMediaTypes.size());
// operation
WorkbenchUtils.removeMethodAnnotation(resourceMethod.getJavaElement(),
"@Consumes({ \"application/vnd.bytesparadise.game+xml\", \"application/xml\", \"application/json\" })");
// post-conditions
- Assert.assertEquals("No result found", 0, mediaTypeCapabilities.getConsumedMimeTypes().size());
+ Assert.assertTrue("No result found", mediaTypeCapabilities.isEmpty());
+ Assert.assertEquals("Wrong mediatypes", "application/xml", resolvedMediaTypes.get(0));
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
}
@Test
public void shouldNotChangeWhenRenamingMethodName() throws CoreException {
// pre-conditions
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
Resource resource = metamodel.getResources().getByTypeName(
"org.jboss.tools.ws.jaxrs.sample.services.GameResource");
Assert.assertEquals("Wrong number of resourceMethods", 2, resource.getAllMethods().size());
HTTPMethod httpMethod = metamodel.getHttpMethods().getByVerb("POST");
- ResourceMethod resourceMethod = resource.getByURIMapping(httpMethod, null, null, null);
+ ResourceMethod resourceMethod = resource.getByMapping(httpMethod, null, null, null);
Assert.assertNotNull("ResourceMethod not found", resourceMethod);
// operation
WorkbenchUtils.rename(resourceMethod.getJavaElement(), "createProductPOST");
// post-conditions
Assert.assertEquals("Wrong number of resourceMethods", 2, resource.getAllMethods().size());
- resourceMethod = resource.getByURIMapping(httpMethod, null, null, null);
+ resourceMethod = resource.getByMapping(httpMethod, null, null, null);
Assert.assertNotNull("ResourceMethod not found", resourceMethod);
Assert.assertEquals("Wrong java method name", "createProductPOST", resourceMethod.getJavaElement()
.getElementName());
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
}
@Test
public void shouldNotChangeWhenChangingParameters() throws CoreException {
// pre-conditions
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
Resource resource = metamodel.getResources().getByTypeName(
"org.jboss.tools.ws.jaxrs.sample.services.GameResource");
Assert.assertEquals("Wrong number of resourceMethods", 2, resource.getAllMethods().size());
HTTPMethod httpMethod = metamodel.getHttpMethods().getByVerb("GET");
- ResourceMethod resourceMethod = resource.getByURIMapping(httpMethod, "/{id}", null, null);
+ ResourceMethod resourceMethod = resource.getByMapping(httpMethod, "/{id}", null, null);
Assert.assertNotNull("ResourceMethod not found", resourceMethod);
- Assert.assertTrue("No query param expected", resourceMethod.getUriMapping().getQueryParams().isEmpty());
+ Assert.assertTrue("No query param expected", resourceMethod.getMapping().getQueryParams().isEmpty());
// operation
WorkbenchUtils.addImport(resourceMethod.getJavaElement().getCompilationUnit(), QueryParam.class.getName());
WorkbenchUtils.addMethodParameter(resourceMethod.getJavaElement(), "@QueryParam(\"start\") int start");
// post-conditions
Assert.assertEquals("Wrong number of resourceMethods", 2, resource.getAllMethods().size());
- resourceMethod = resource.getByURIMapping(httpMethod, "/{id}", null, null);
+ resourceMethod = resource.getByMapping(httpMethod, "/{id}", null, null);
Assert.assertNotNull("ResourceMethod not found", resourceMethod);
- Assert.assertEquals("No query param found", 1, resourceMethod.getUriMapping().getQueryParams().size());
+ Assert.assertEquals("No query param found", 1, resourceMethod.getMapping().getQueryParams().size());
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
}
@Test
public void shouldReportErrorWhenRemovingImport() throws JavaModelException {
+ // preconditions
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
Resource resource = metamodel.getResources().getByTypeName(
"org.jboss.tools.ws.jaxrs.sample.services.GameResource");
List<ResourceMethod> allMethods = resource.getAllMethods();
Assert.assertEquals("Wrong number of resourceMethods", 2, allMethods.size());
HTTPMethod httpMethod = metamodel.getHttpMethods().getByVerb("GET");
- ResourceMethod resourceMethod = resource.getByURIMapping(httpMethod, "/{id}", null, null);
+ ResourceMethod resourceMethod = resource.getByMapping(httpMethod, "/{id}", null, null);
// operation 1
WorkbenchUtils.removeImport(resourceMethod.getJavaElement().getCompilationUnit(), Path.class.getName());
// post-conditions 1 : errors reported (import is missing)
@@ -423,23 +678,29 @@
// post-conditions 2 : no error reported (missing import was restored)
Assert.assertEquals("Wrong number of resourceMethods", 2, allMethods.size());
Assert.assertFalse("Error still reported", resourceMethod.hasErrors());
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
}
@Test
public void shouldUpdateResourceMethodModelWhenChangingPathParamAnnotation() throws CoreException {
+ // preconditions
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
Resource resource = metamodel.getResources().getByTypeName(
"org.jboss.tools.ws.jaxrs.sample.services.CustomerResource");
Assert.assertEquals("Wrong number of resourceMethods", 6, resource.getAllMethods().size());
HTTPMethod httpMethod = metamodel.getHttpMethods().getByVerb("GET");
- ResourceMethod resourceMethod = resource.getByURIMapping(httpMethod, "{id}", null, "text/x-vcard");
+ ResourceMethod resourceMethod = resource.getByMapping(httpMethod, "{id}", null, "text/x-vcard");
Assert.assertNotNull("ResourceMethod not found", resourceMethod);
- Assert.assertEquals("Invalid PathParam", "id", resourceMethod.getUriMapping().getPathParams().get(0).getAnnotationValue());
+ Assert.assertEquals("Invalid PathParam", "id", resourceMethod.getMapping().getPathParams().get(0)
+ .getAnnotationValue());
// operation
WorkbenchUtils.replaceAllOccurrencesOfCode(resource.getJavaElement().getCompilationUnit(),
"@PathParam(\"id\")", "@PathParam(\"ide\")");
// post-conditions
- Assert.assertEquals("Invalid PathParam", "ide", resourceMethod.getUriMapping().getPathParams().get(0).getAnnotationValue());
+ Assert.assertEquals("Invalid PathParam", "ide", resourceMethod.getMapping().getPathParams().get(0)
+ .getAnnotationValue());
+ Assert.assertEquals("Wrong number of routes", 10, metamodel.getRoutes().getAll().size());
}
}
14 years, 10 months
JBoss Tools SVN: r31888 - in trunk/as: tests/org.jboss.ide.eclipse.as.archives.integration.test/src/org/jboss/ide/eclipse/as/archives/integration/test and 1 other directory.
by jbosstools-commits@lists.jboss.org
Author: adietish
Date: 2011-06-07 17:36:55 -0400 (Tue, 07 Jun 2011)
New Revision: 31888
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/AltMethodZippedJSTPublisher.java
trunk/as/tests/org.jboss.ide.eclipse.as.archives.integration.test/src/org/jboss/ide/eclipse/as/archives/integration/test/SingleFileZippedDeploymentIntegrationTest.java
Log:
[JBIDE-9091] testing now if a folder with the same name already exists. removing the folder if it's present
Modified: trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/AltMethodZippedJSTPublisher.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/AltMethodZippedJSTPublisher.java 2011-06-07 21:35:59 UTC (rev 31887)
+++ trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/AltMethodZippedJSTPublisher.java 2011-06-07 21:36:55 UTC (rev 31888)
@@ -12,6 +12,8 @@
******************************************************************************/
package org.jboss.ide.eclipse.archives.webtools.modules;
+import java.io.File;
+
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -82,13 +84,18 @@
String name = sourcePath.lastSegment();
IStatus result = null;
-
- /*
- * always completely remove prior deployment (prior deployfailed marker, deployed folder etc.)
- * this is needed since we might have switched from exploded to war
- */
- result = removeRemoteDeployment(sourcePath, destination.removeLastSegments(1), name, monitor);
- if( publishType != IJBossServerPublisher.REMOVE_PUBLISH){
+ DeploymentMarkerUtils.removeDeployFailedMarker(method, server, destination, monitor);
+
+ if(publishType == IJBossServerPublisher.REMOVE_PUBLISH) {
+ result = removeRemoteDeployment(sourcePath, destination.removeLastSegments(1), name, monitor);
+ } else if (publishType != IJBossServerPublisher.NO_PUBLISH) {
+ /*
+ * remove prior exploded deployment (prior deployfailed marker, deployed folder etc.)
+ * and redeploy
+ */
+ if (isDeployedExploded(destination)) {
+ removeRemoteDeployment(sourcePath, destination.removeLastSegments(1), name, monitor);
+ }
// Locally zip it up into the remote tmp folder
result = super.publishModule(method, server, module, publishType, delta,
AbstractServerToolsPublisher.getSubMon(monitor, 50));
@@ -96,7 +103,7 @@
result = remoteFullPublish(sourcePath, destination.removeLastSegments(1), name,
AbstractServerToolsPublisher.getSubMon(monitor, 150));
}
- }
+ }
if( result == null ) {
result = Status.OK_STATUS;
@@ -107,6 +114,13 @@
monitor.done();
}
}
+
+ private boolean isDeployedExploded(IPath destination) {
+ File file = destination.toFile();
+ return file != null
+ && file.exists()
+ && file.isDirectory();
+ }
private IStatus remoteFullPublish(IPath sourcePath,
IPath destFolder, String name, IProgressMonitor monitor) {
@@ -123,7 +137,7 @@
}
return Status.OK_STATUS;
}
-
+
private IStatus removeRemoteDeployment( IPath sourcePath,
IPath destFolder, String name, IProgressMonitor monitor) throws CoreException {
try {
@@ -136,7 +150,7 @@
return ce.getStatus();
}
}
-
+
/**
* Removes the resource with the given name from the given parent folder. Either files or folders are removed.
* @param sourcePath
Modified: trunk/as/tests/org.jboss.ide.eclipse.as.archives.integration.test/src/org/jboss/ide/eclipse/as/archives/integration/test/SingleFileZippedDeploymentIntegrationTest.java
===================================================================
--- trunk/as/tests/org.jboss.ide.eclipse.as.archives.integration.test/src/org/jboss/ide/eclipse/as/archives/integration/test/SingleFileZippedDeploymentIntegrationTest.java 2011-06-07 21:35:59 UTC (rev 31887)
+++ trunk/as/tests/org.jboss.ide.eclipse.as.archives.integration.test/src/org/jboss/ide/eclipse/as/archives/integration/test/SingleFileZippedDeploymentIntegrationTest.java 2011-06-07 21:36:55 UTC (rev 31888)
@@ -50,8 +50,7 @@
int changed = MockPublishMethod.getChanged().length;
int removed = MockPublishMethod.getRemoved().length;
assertEquals(2,changed);
- // always removing the prior deployment since we could be switching from exploded to war
- assertEquals(2,removed);
+ assertEquals(1,removed);
MockPublishMethod.reset();
// make workspace change, repeat
@@ -62,8 +61,7 @@
changed = MockPublishMethod.getChanged().length;
removed = MockPublishMethod.getRemoved().length;
assertEquals(2,changed);
- // always removing the prior deployment since we could be switching from exploded to war
- assertEquals(2,removed);
+ assertEquals(1,removed);
MockPublishMethod.reset();
server = ServerRuntimeUtils.removeModule(server, mods[0]);
@@ -72,8 +70,8 @@
changed = MockPublishMethod.getChanged().length;
removed = MockPublishMethod.getRemoved().length;
assertEquals(0,changed);
- // removing deployment + .deployed marker
- assertEquals(2,removed);
+ // removing deployment + .deployed + .failed marker
+ assertEquals(3,removed);
MockPublishMethod.reset();
}
14 years, 10 months
JBoss Tools SVN: r31887 - trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7.
by jbosstools-commits@lists.jboss.org
Author: adietish
Date: 2011-06-07 17:35:59 -0400 (Tue, 07 Jun 2011)
New Revision: 31887
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7/DeploymentMarkerUtils.java
Log:
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7/DeploymentMarkerUtils.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7/DeploymentMarkerUtils.java 2011-06-07 20:53:44 UTC (rev 31886)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7/DeploymentMarkerUtils.java 2011-06-07 21:35:59 UTC (rev 31887)
@@ -198,8 +198,11 @@
IProgressMonitor monitor) throws CoreException {
IPath folder = depPath.removeLastSegments(1);
IPublishCopyCallbackHandler callback = method.getCallbackHandler(folder, server);
- IPath file = new Path(depPath.lastSegment() + suffix);
- callback.deleteResource(file, monitor);
+ String deploymentName = depPath.lastSegment();
+ if (deploymentName != null) {
+ IPath file = new Path(deploymentName + suffix);
+ callback.deleteResource(file, monitor);
+ }
return Status.OK_STATUS;
}
14 years, 10 months
JBoss Tools SVN: r31886 - trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7.
by jbosstools-commits@lists.jboss.org
Author: adietish
Date: 2011-06-07 16:53:44 -0400 (Tue, 07 Jun 2011)
New Revision: 31886
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7/DeploymentMarkerUtils.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7/JBoss7JSTPublisher.java
Log:
[JBIDE-9090] corrected methods signatures so that required parameters have consistent ordering
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7/DeploymentMarkerUtils.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7/DeploymentMarkerUtils.java 2011-06-07 20:46:51 UTC (rev 31885)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7/DeploymentMarkerUtils.java 2011-06-07 20:53:44 UTC (rev 31886)
@@ -105,7 +105,7 @@
return p.toFile();
}
- public static IStatus removeDeployFailedMarker(IServer server, IPath depPath, IJBossServerPublishMethod method,
+ public static IStatus removeDeployFailedMarker(IJBossServerPublishMethod method, IServer server, IPath depPath,
IProgressMonitor monitor) throws CoreException {
return removeFile(FAILED_DEPLOY, server, depPath, method, monitor);
}
@@ -125,7 +125,7 @@
IModule[] module, IProgressMonitor monitor) throws CoreException {
IDeployableServer deployableServer = ServerConverter.getDeployableServer(server);
IPath deployPath = PublishUtil.getDeployPath(method, module, deployableServer);
- return removeDeployedMarkerIfExists(server, deployPath, method, monitor);
+ return removeDeployedMarkerIfExists(method, server, deployPath, monitor);
}
/**
@@ -143,7 +143,7 @@
IModule[] moduleTree, IProgressMonitor monitor)
throws CoreException {
IPath deployPath = PublishUtil.getDeployPath(method, moduleTree, jbServer);
- return removeDeployedMarkerIfExists(jbServer.getServer(), deployPath, method, monitor);
+ return removeDeployedMarkerIfExists(method, jbServer.getServer(), deployPath, monitor);
}
/**
@@ -157,7 +157,7 @@
* @return the result of the removal operation
* @throws CoreException
*/
- public static IStatus removeDeployedMarkerIfExists(IServer server, IPath depPath, IJBossServerPublishMethod method,
+ public static IStatus removeDeployedMarkerIfExists(IJBossServerPublishMethod method, IServer server, IPath depPath,
IProgressMonitor monitor) throws CoreException {
try {
return removeFile(DEPLOYED, server, depPath, method, monitor);
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7/JBoss7JSTPublisher.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7/JBoss7JSTPublisher.java 2011-06-07 20:46:51 UTC (rev 31885)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7/JBoss7JSTPublisher.java 2011-06-07 20:53:44 UTC (rev 31886)
@@ -43,7 +43,7 @@
IProgressMonitor monitor) throws CoreException {
IDeployableServer ds = ServerConverter.getDeployableServer(server);
- DeploymentMarkerUtils.removeDeployFailedMarker(server, PublishUtil.getDeployPath(method, module, ds), method, monitor);
+ DeploymentMarkerUtils.removeDeployFailedMarker(method, server, PublishUtil.getDeployPath(method, module, ds), monitor);
if( publishType == IJBossServerPublisher.REMOVE_PUBLISH) {
DeploymentMarkerUtils.removeDeployedMarkerIfExists(method, ds, module, monitor);
14 years, 10 months
JBoss Tools SVN: r31885 - trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7.
by jbosstools-commits@lists.jboss.org
Author: adietish
Date: 2011-06-07 16:46:51 -0400 (Tue, 07 Jun 2011)
New Revision: 31885
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7/DeploymentMarkerUtils.java
Log:
[JBIDE-9089] fixed erroneous call to remove .deployed marker in method that should remove .failed marker
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7/DeploymentMarkerUtils.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7/DeploymentMarkerUtils.java 2011-06-07 19:29:19 UTC (rev 31884)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7/DeploymentMarkerUtils.java 2011-06-07 20:46:51 UTC (rev 31885)
@@ -180,7 +180,8 @@
public static IStatus removeDeployFailedMarkerIfExists(IJBossServerPublishMethod method, IServer server,
IModule[] module, IProgressMonitor monitor) throws CoreException {
IDeployableServer deployableServer = ServerConverter.getDeployableServer(server);
- return removeDeployedMarkerIfExists(method, deployableServer, module, monitor);
+ IPath deployPath = PublishUtil.getDeployPath(method, module, deployableServer);
+ return removeFile(FAILED_DEPLOY, server, deployPath, method, monitor);
}
/**
14 years, 10 months
JBoss Tools SVN: r31884 - in trunk/download.jboss.org/jbosstools/updates: requirements/m2eclipse and 1 other directory.
by jbosstools-commits@lists.jboss.org
Author: nickboldt
Date: 2011-06-07 15:29:19 -0400 (Tue, 07 Jun 2011)
New Revision: 31884
Modified:
trunk/download.jboss.org/jbosstools/updates/indigo/RC2/compositeArtifacts...
trunk/download.jboss.org/jbosstools/updates/indigo/RC2/compositeContent.xml
trunk/download.jboss.org/jbosstools/updates/requirements/m2eclipse/build.xml
Log:
pull new m2e bits for 1.0 / 0.13 (https://issues.jboss.org/browse/JBIDE-8833, https://issues.jboss.org/browse/JBIDE-9083)
Modified: trunk/download.jboss.org/jbosstools/updates/indigo/RC2/compositeArtifacts...
===================================================================
--- trunk/download.jboss.org/jbosstools/updates/indigo/RC2/compositeArtifacts... 2011-06-07 19:00:52 UTC (rev 31883)
+++ trunk/download.jboss.org/jbosstools/updates/indigo/RC2/compositeArtifacts... 2011-06-07 19:29:19 UTC (rev 31884)
@@ -12,9 +12,9 @@
endfun
nnoremap <Leader>ts :call ReplaceTimestamp()<CR>
-->
-<property name='p2.timestamp' value='1306811742000'/>
+<property name='p2.timestamp' value='1307472655000'/>
</properties>
-<children size='18'>
+<children size='20'>
<child location='../../requirements/indigo/201105270900-RC2/'/>
<child location='../../requirements/birt/3.7RC2/'/>
<child location='../../requirements/eclipse/3.7RC3/'/>
@@ -22,18 +22,19 @@
<child location='../../requirements/webtools/3.3RC2/'/>
<child location='../../requirements/m2eclipse/0.13.0.201105260005/'/>
+<child location='../../requirements/m2eclipse/20110607-1445/'/>
+<child location='../../requirements/m2eclipse-wtp-e37/'/>
<child location='../../requirements/mylyn/3.6-I20110526-2115/'/>
<child location='../../requirements/orbit/R20110523182458/'/>
<child location='../../requirements/ecf/3.5/'/>
<child location='../../requirements/egit/0.11/'/>
-
<child location='../../requirements/findbugs/1.3.9/'/>
<child location='../../requirements/jslint/1.5/'/>
<child location='../../requirements/pmd/3.2.6/'/>
+
<child location='../../requirements/springide/2.6.0.201103160035/'/>
<child location='../../requirements/subclipse/1.6_1.3/'/>
-
<child location='../../requirements/swtbot/2.0.4/'/>
<child location='../../requirements/testng/6.0.1.20110418_1444/'/>
<child location='../../requirements/xulrunner-1.9.2/'/>
Modified: trunk/download.jboss.org/jbosstools/updates/indigo/RC2/compositeContent.xml
===================================================================
--- trunk/download.jboss.org/jbosstools/updates/indigo/RC2/compositeContent.xml 2011-06-07 19:00:52 UTC (rev 31883)
+++ trunk/download.jboss.org/jbosstools/updates/indigo/RC2/compositeContent.xml 2011-06-07 19:29:19 UTC (rev 31884)
@@ -12,7 +12,7 @@
endfun
nnoremap <Leader>ts :call ReplaceTimestamp()<CR>
-->
-<property name='p2.timestamp' value='1306811742000'/>
+<property name='p2.timestamp' value='1307472655000'/>
</properties>
<children size='18'>
<child location='../../requirements/indigo/201105270900-RC2/'/>
@@ -22,18 +22,19 @@
<child location='../../requirements/webtools/3.3RC2/'/>
<child location='../../requirements/m2eclipse/0.13.0.201105260005/'/>
+<child location='../../requirements/m2eclipse/20110607-1445/'/>
+<child location='../../requirements/m2eclipse-wtp-e37/'/>
<child location='../../requirements/mylyn/3.6-I20110526-2115/'/>
<child location='../../requirements/orbit/R20110523182458/'/>
<child location='../../requirements/ecf/3.5/'/>
<child location='../../requirements/egit/0.11/'/>
-
<child location='../../requirements/findbugs/1.3.9/'/>
<child location='../../requirements/jslint/1.5/'/>
<child location='../../requirements/pmd/3.2.6/'/>
+
<child location='../../requirements/springide/2.6.0.201103160035/'/>
<child location='../../requirements/subclipse/1.6_1.3/'/>
-
<child location='../../requirements/swtbot/2.0.4/'/>
<child location='../../requirements/testng/6.0.1.20110418_1444/'/>
<child location='../../requirements/xulrunner-1.9.2/'/>
Modified: trunk/download.jboss.org/jbosstools/updates/requirements/m2eclipse/build.xml
===================================================================
--- trunk/download.jboss.org/jbosstools/updates/requirements/m2eclipse/build.xml 2011-06-07 19:00:52 UTC (rev 31883)
+++ trunk/download.jboss.org/jbosstools/updates/requirements/m2eclipse/build.xml 2011-06-07 19:29:19 UTC (rev 31884)
@@ -16,12 +16,18 @@
-f ~/RHDS/updates/requirements/m2eclipse/build.xml -Ddestination=/tmp/m2eclipse-repo
-->
<target name="mirror">
-
+ <property name="URL1" value="http://download.eclipse.org/technology/m2e/milestones/1.0/"/>
+ <property name="URL2" value="http://m2eclipse.sonatype.org/sites/m2e"/>
+ <property name="URL3" value="http://m2eclipse.sonatype.org/sites/m2e-extras/"/>
+
+ <property name="URL4" value="http://download.jboss.org/jbosstools/updates/requirements/m2eclipse-wtp-e36/"/>
+ <property name="URL5" value="http://download.jboss.org/jbosstools/updates/requirements/m2eclipse-wtp-e37/"/>
+
+ <!--
<property name="URL1" value="https://repository.sonatype.org/content/sites/forge-sites/m2e/0.13.0/N/0...."/>
<property name="URL2" value="https://repository.sonatype.org/content/sites/forge-sites/m2e-extras/0.13..."/>
<property name="URL3" value="https://repository.sonatype.org/content/sites/forge-sites/m2eclipse-wtp/0..."/>
- <!--
<property name="URL1" value="https://repository.sonatype.org/content/sites/forge-sites/m2e/0.13.0/N/0...."/>
<property name="URL2" value="https://repository.sonatype.org/content/sites/forge-sites/m2e-extras/0.13..."/>
<property name="URL3" value="https://repository.sonatype.org/content/sites/forge-sites/m2eclipse-wtp/0..."/>
@@ -39,17 +45,19 @@
<property name="compress" value="true" />
<p2.mirror>
- <repository location="file:${destination}/0.13.0.201105260005/" name="m2eclipse 0.13.0.201105260005 plugins for Eclipse 3.6 - 3.7" />
+ <repository location="file:${destination}/20110607-1445" name="m2eclipse 0.13 (1.0) for Eclipse 3.6 - 3.7 (mirrored 20110607-1445" />
<source>
<repository location="${URL1}" />
<repository location="${URL2}" />
<repository location="${URL3}" />
+ <repository location="${URL4}" />
+ <repository location="${URL5}" />
</source>
<slicingOptions includeFeatures="true" followStrict="true" />
</p2.mirror>
- <p2.publish.featuresAndBundles metadataRepository="file:${destination}/0.13.0.201105260005/" artifactRepository="file:${destination}/0.13.0.201105260005/"
- publishartifacts="true" source="${destination}/0.13.0.201105260005/" compress="${compress}" />
+ <p2.publish.featuresAndBundles metadataRepository="file:${destination}/20110607-1445/" artifactRepository="file:${destination}/20110607-1445/"
+ publishartifacts="true" source="${destination}/20110607-1445/" compress="${compress}" />
</target>
</project>
14 years, 10 months
JBoss Tools SVN: r31883 - trunk/jsf/tests/org.jboss.tools.jsf.text.ext.test/src/org/jboss/tools/jsf/text/ext/test.
by jbosstools-commits@lists.jboss.org
Author: scabanovich
Date: 2011-06-07 15:00:52 -0400 (Tue, 07 Jun 2011)
New Revision: 31883
Added:
trunk/jsf/tests/org.jboss.tools.jsf.text.ext.test/src/org/jboss/tools/jsf/text/ext/test/JSF2CompositeLibOpenOnTest.java
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.text.ext.test/src/org/jboss/tools/jsf/text/ext/test/JsfTextExtAllTests.java
Log:
JBIDE-9070
https://issues.jboss.org/browse/JBIDE-9070
Added: trunk/jsf/tests/org.jboss.tools.jsf.text.ext.test/src/org/jboss/tools/jsf/text/ext/test/JSF2CompositeLibOpenOnTest.java
===================================================================
--- trunk/jsf/tests/org.jboss.tools.jsf.text.ext.test/src/org/jboss/tools/jsf/text/ext/test/JSF2CompositeLibOpenOnTest.java (rev 0)
+++ trunk/jsf/tests/org.jboss.tools.jsf.text.ext.test/src/org/jboss/tools/jsf/text/ext/test/JSF2CompositeLibOpenOnTest.java 2011-06-07 19:00:52 UTC (rev 31883)
@@ -0,0 +1,119 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.jsf.text.ext.test;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.FindReplaceDocumentAdapter;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.text.hyperlink.IHyperlink;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.jboss.tools.common.text.ext.hyperlink.HyperlinkDetector;
+import org.jboss.tools.jsf.text.ext.hyperlink.JsfJSPTagNameHyperlinkDetector;
+import org.jboss.tools.jst.jsp.jspeditor.JSPMultiPageEditor;
+import org.jboss.tools.test.util.JobUtils;
+import org.jboss.tools.test.util.WorkbenchUtils;
+
+/**
+ *
+ * @author Viacheslav Kabanovich
+ *
+ */
+public class JSF2CompositeLibOpenOnTest extends TestCase {
+ private static final String PROJECT_NAME = "JSF2CompositeOpenOn";
+ private static final String PAGE_NAME = PROJECT_NAME+"/WebContent/pages/inputname.xhtml";
+ public IProject project = null;
+
+ protected void setUp() {
+ project = ResourcesPlugin.getWorkspace().getRoot().getProject(
+ PROJECT_NAME);
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeAllEditors(false);
+ JobUtils.waitForIdle();
+ }
+
+ protected void tearDown() {
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeAllEditors(false);
+ }
+
+ public JSF2CompositeLibOpenOnTest() {
+ super("JSF2 OpenOn of composite library test");
+ }
+
+ public void testAttribute() throws Exception {
+ testOpenon("<ez:input", "label", "input.xhtml", "<composite:attribute name=\"label\"/>");
+ testOpenon("<ez:input", "value", "input.xhtml", "<composite:attribute name=\"value\" required=\"true\"/>");
+ testOpenon("<ez:input", "action", "input.xhtml", "<composite:attribute name=\"action\" required=\"true\" method-signature=\"java.lang.String f()\"/>");
+ }
+
+ public void testTag() throws Exception {
+ testOpenon("<ez:input", "input", "input.xhtml", null);
+ }
+
+ private void testOpenon(String text, String subtext, String editorName, String targetSelection) throws PartInitException, BadLocationException {
+ IEditorPart editor = WorkbenchUtils.openEditor(PAGE_NAME);
+ assertTrue(editor instanceof JSPMultiPageEditor);
+ JobUtils.waitForIdle();
+ JSPMultiPageEditor jspMultyPageEditor = (JSPMultiPageEditor) editor;
+ ISourceViewer viewer = jspMultyPageEditor.getSourceEditor().getTextViewer();
+
+ IDocument document = viewer.getDocument();
+ int i = document.get().indexOf(text);
+ assertTrue(i > 0);
+ IRegion reg = new FindReplaceDocumentAdapter(document).find(i,
+ subtext, true, true, false, false);
+
+ assertNotNull("Region for " + subtext +" not found", reg);
+
+ IHyperlink[] links = new JsfJSPTagNameHyperlinkDetector().detectHyperlinks(viewer, reg, false);
+ //IHyperlink[] links = HyperlinkDetector.getInstance().detectHyperlinks(viewer, reg, true);
+
+ assertNotNull("Hyperlinks for :" + subtext + " are not found",links);
+
+ assertTrue("Hyperlinks for tag:" + subtext + " are not found",links.length!=0);
+
+ boolean found = false;
+ for(IHyperlink link : links){
+ assertNotNull(link.toString());
+
+ link.open();
+ JobUtils.waitForIdle(2000);
+
+ IEditorPart resultEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
+ if(editorName.equals(resultEditor.getTitle())){
+ found = true;
+ if(targetSelection != null) {
+ ISelection selection = resultEditor.getSite().getSelectionProvider().getSelection();
+ assertTrue(selection instanceof ITextSelection);
+ ITextSelection textSelection = (ITextSelection)selection;
+ JSPMultiPageEditor jspMultyPageEditor2 = (JSPMultiPageEditor) resultEditor;
+ ISourceViewer viewer2 = jspMultyPageEditor2.getSourceEditor().getTextViewer();
+ IDocument document2 = viewer2.getDocument();
+ String selectedText = document2.get().substring(textSelection.getOffset(), textSelection.getOffset() + textSelection.getLength());
+ assertEquals(selectedText, targetSelection);
+ }
+ }
+ }
+ if(!found) {
+ assertTrue("OpenOn have not opened "+editorName+" editor",found);
+ }
+ }
+
+}
+
Property changes on: trunk/jsf/tests/org.jboss.tools.jsf.text.ext.test/src/org/jboss/tools/jsf/text/ext/test/JSF2CompositeLibOpenOnTest.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/jsf/tests/org.jboss.tools.jsf.text.ext.test/src/org/jboss/tools/jsf/text/ext/test/JsfTextExtAllTests.java
===================================================================
--- trunk/jsf/tests/org.jboss.tools.jsf.text.ext.test/src/org/jboss/tools/jsf/text/ext/test/JsfTextExtAllTests.java 2011-06-07 18:40:14 UTC (rev 31882)
+++ trunk/jsf/tests/org.jboss.tools.jsf.text.ext.test/src/org/jboss/tools/jsf/text/ext/test/JsfTextExtAllTests.java 2011-06-07 19:00:52 UTC (rev 31883)
@@ -23,7 +23,9 @@
"org.jboss.tools.jsf.text.ext.test",
new String[]{"projects/HiperlinksTestProject"},
new String[]{"HiperlinksTestProject"}));
- suite.addTest(new ProjectImportTestSetup(new TestSuite(JSF2CompositeOpenOnTest.class),
+ suite.addTest(new ProjectImportTestSetup(new TestSuite(
+ JSF2CompositeOpenOnTest.class,
+ JSF2CompositeLibOpenOnTest.class),
"org.jboss.tools.jsf.text.ext.test",
new String[]{"projects/JSF2CompositeOpenOn"},
new String[]{"JSF2CompositeOpenOn"}));
14 years, 10 months