Author: xcoulon
Date: 2012-01-24 16:59:52 -0500 (Tue, 24 Jan 2012)
New Revision: 38122
Added:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-3_0-with-invalid-servlet-mapping.xml
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementDeltaScanner.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuilder.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelChangedProcessor.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/ResourceChangedProcessor.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/WtpUtils.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodSignaturesVisitor.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/JaxrsMetamodelDelta.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/internal/metamodel/builder/JavaElementDeltaScannerTestCase.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/ResourceChangedProcessorTestCase.java
Log:
Fixing JBIDE-10701 - NPE in JaxrsMetamodelBuilder
https://issues.jboss.org/browse/JBIDE-10701
Fixing other NPEs found while using the plugin
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementDeltaScanner.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementDeltaScanner.java 2012-01-24
21:38:42 UTC (rev 38121)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementDeltaScanner.java 2012-01-24
21:59:52 UTC (rev 38122)
@@ -36,6 +36,8 @@
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaElementDelta;
+import org.eclipse.jdt.core.IOpenable;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.compiler.IProblem;
import org.eclipse.jdt.core.dom.CompilationUnit;
@@ -46,9 +48,8 @@
import org.jboss.tools.ws.jaxrs.core.jdt.JdtUtils;
/**
- * Scans and filters the IJavaElementDelta and IResourceDelta (including their
- * children and annotations) and returns a list of JavaElementChangedEvents that
- * match with the JavaElementChangedEventFilter rules.
+ * Scans and filters the IJavaElementDelta and IResourceDelta (including their children
and annotations) and returns a
+ * list of JavaElementChangedEvents that match with the JavaElementChangedEventFilter
rules.
*
* @author xcoulon
* @see @{IJavaElementDelta}
@@ -82,19 +83,25 @@
* @throws CoreException
* @see
https://bugs.eclipse.org/bugs/show_bug.cgi?id=100267
*/
- private List<JavaElementDelta> scanDelta(final IJavaElementDelta delta, final int
eventType)
- throws CoreException {
+ private List<JavaElementDelta> scanDelta(final IJavaElementDelta delta, final int
eventType) throws CoreException {
final List<JavaElementDelta> events = new ArrayList<JavaElementDelta>();
IJavaElement element = delta.getElement();
// skip as the project is closed
if (element == null || (element.getJavaProject() != null &&
!element.getJavaProject().getProject().isOpen())) {
return Collections.emptyList();
+ } else if ((element.getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT)) {
+ final IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot) element;
+ if (!packageFragmentRoot.isExternal()
+ && (packageFragmentRoot.getResource() == null ||
!packageFragmentRoot.getResource().exists())) {
+ return Collections.emptyList();
+ }
+ } else if (element.getResource() == null || !element.getResource().exists()) {
+ return Collections.emptyList();
}
int elementKind = element.getElementType();
int deltaKind = retrieveDeltaKind(delta);
int flags = delta.getFlags();
CompilationUnit compilationUnitAST = getCompilationUnitAST(delta);
-
if (elementKind == COMPILATION_UNIT) {
ICompilationUnit compilationUnit = (ICompilationUnit) element;
// compilationUnitAST is null when the given compilation unit'w
@@ -112,8 +119,8 @@
List<JavaMethodSignature> diffs =
compilationUnitsRepository.mergeAST(compilationUnit,
compilationUnitAST, computeDiffs);
for (JavaMethodSignature diff : diffs) {
- final JavaElementDelta event = new JavaElementDelta(diff.getJavaMethod(), CHANGED,
- eventType, compilationUnitAST, F_SIGNATURE);
+ final JavaElementDelta event = new JavaElementDelta(diff.getJavaMethod(), CHANGED,
eventType,
+ compilationUnitAST, F_SIGNATURE);
if (javaElementChangedEventFilter.apply(event)) {
events.add(event);
}
@@ -125,8 +132,8 @@
problems);
for (Entry<IProblem, IJavaElement> solvedProblem : solvedProblems.entrySet())
{
IJavaElement solvedElement = solvedProblem.getValue();
- final JavaElementDelta event = new JavaElementDelta(solvedElement, CHANGED,
- eventType, compilationUnitAST, F_PROBLEM_SOLVED);
+ final JavaElementDelta event = new JavaElementDelta(solvedElement, CHANGED,
eventType,
+ compilationUnitAST, F_PROBLEM_SOLVED);
if (javaElementChangedEventFilter.apply(event)) {
events.add(event);
}
@@ -134,8 +141,8 @@
}
} else {
- final JavaElementDelta event = new JavaElementDelta(element, deltaKind, eventType,
- compilationUnitAST, flags);
+ final JavaElementDelta event = new JavaElementDelta(element, deltaKind, eventType,
compilationUnitAST,
+ flags);
if (javaElementChangedEventFilter.apply(event)) {
events.add(event);
}
@@ -193,8 +200,7 @@
}
/**
- * Retrieves the appropriate kind of the given delta, with some specific
- * adaptations for some element types.
+ * Retrieves the appropriate kind of the given delta, with some specific adaptations for
some element types.
*
* @param delta
* the delta.
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuilder.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuilder.java 2012-01-24
21:38:42 UTC (rev 38121)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuilder.java 2012-01-24
21:59:52 UTC (rev 38122)
@@ -27,6 +27,7 @@
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.jboss.tools.ws.jaxrs.core.JBossJaxrsCorePlugin;
+import org.jboss.tools.ws.jaxrs.core.configuration.ProjectNatureUtils;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsMetamodel;
import org.jboss.tools.ws.jaxrs.core.internal.utils.ConstantUtils;
import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
@@ -69,12 +70,10 @@
protected final IProject[] build(final int kind, @SuppressWarnings("rawtypes")
final Map args,
final IProgressMonitor monitor) throws CoreException {
IProject project = getProject();
- // if (!ProjectNatureUtils.isProjectNatureInstalled(project,
- // ProjectNatureUtils.JAXRS_NATURE_ID)) {
- // Logger.warn("Project '" + project.getName() +
- // "' is not a JAX-RS project.");
- // return null;
- // }
+ if (!ProjectNatureUtils.isProjectNatureInstalled(project,
ProjectNatureUtils.JAXRS_NATURE_ID)) {
+ Logger.warn("Project '" + project.getName() + "' is not a
JAX-RS project.");
+ return null;
+ }
logBuild(kind, args, project);
switch (kind) {
case CLEAN_BUILD:
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelChangedProcessor.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelChangedProcessor.java 2012-01-24
21:38:42 UTC (rev 38121)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelChangedProcessor.java 2012-01-24
21:59:52 UTC (rev 38122)
@@ -247,28 +247,30 @@
if (returnType != null) {
final ITypeHierarchy returnTypeHierarchy = JdtUtils
.resolveTypeHierarchy(returnType, false, progressMonitor);
- final List<String> subtypesHandlers =
extractHandlers(returnTypeHierarchy.getAllSubtypes(returnType));
- for (Iterator<IJaxrsResource> iterator = metamodel.getAllResources().iterator();
iterator.hasNext();) {
- JaxrsResource resource = (JaxrsResource) iterator.next();
- if (resource.isSubresource()) {
- final String resourceHandleIdentifier =
resource.getJavaElement().getHandleIdentifier();
- if (resourceHandleIdentifier.equals(returnType.getHandleIdentifier())
- || subtypesHandlers.contains(resourceHandleIdentifier)) {
- for (JaxrsResourceMethod resourceMethod : resource.getMethods().values()) {
- switch (resourceMethod.getKind()) {
- case RESOURCE_METHOD:
- case SUBRESOURCE_METHOD:
- final JaxrsHttpMethod httpMethod = metamodel.getHttpMethod(resourceMethod
- .getHttpMethodAnnotation());
- final LinkedList<JaxrsResourceMethod> resourceMethods = new
LinkedList<JaxrsResourceMethod>(
- Arrays.asList(subresourceLocator, resourceMethod));
- final JaxrsEndpoint endpoint = new JaxrsEndpoint(metamodel.getApplication(),
- httpMethod, resourceMethods);
- if (metamodel.add(endpoint)) {
- changes.add(new JaxrsEndpointDelta(endpoint, ADDED));
+ if (returnTypeHierarchy != null) {
+ final List<String> subtypesHandlers =
extractHandlers(returnTypeHierarchy.getAllSubtypes(returnType));
+ for (Iterator<IJaxrsResource> iterator =
metamodel.getAllResources().iterator(); iterator.hasNext();) {
+ JaxrsResource resource = (JaxrsResource) iterator.next();
+ if (resource.isSubresource()) {
+ final String resourceHandleIdentifier =
resource.getJavaElement().getHandleIdentifier();
+ if (resourceHandleIdentifier.equals(returnType.getHandleIdentifier())
+ || subtypesHandlers.contains(resourceHandleIdentifier)) {
+ for (JaxrsResourceMethod resourceMethod : resource.getMethods().values()) {
+ switch (resourceMethod.getKind()) {
+ case RESOURCE_METHOD:
+ case SUBRESOURCE_METHOD:
+ final JaxrsHttpMethod httpMethod = metamodel.getHttpMethod(resourceMethod
+ .getHttpMethodAnnotation());
+ final LinkedList<JaxrsResourceMethod> resourceMethods = new
LinkedList<JaxrsResourceMethod>(
+ Arrays.asList(subresourceLocator, resourceMethod));
+ final JaxrsEndpoint endpoint = new JaxrsEndpoint(metamodel.getApplication(),
+ httpMethod, resourceMethods);
+ if (metamodel.add(endpoint)) {
+ changes.add(new JaxrsEndpointDelta(endpoint, ADDED));
+ }
}
+ break;
}
- break;
}
}
}
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/ResourceChangedProcessor.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/ResourceChangedProcessor.java 2012-01-24
21:38:42 UTC (rev 38121)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/ResourceChangedProcessor.java 2012-01-24
21:59:52 UTC (rev 38122)
@@ -18,6 +18,7 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -199,9 +200,13 @@
private List<JaxrsElementDelta>
processApplicationChangesOnWebxmlAdditionOrChange(IResource resource,
JaxrsMetamodel metamodel, IProgressMonitor progressMonitor) throws CoreException {
- final List<JaxrsElementDelta> results = new
ArrayList<JaxrsElementDelta>();
final IType applicationType = JdtUtils.resolveType(Application.class.getName(),
metamodel.getJavaProject(),
progressMonitor);
+ // occurs when the project has the jax-rs nature (the builder is called), but no jaxrs
library is in the classpath
+ if(applicationType == null) {
+ return Collections.emptyList();
+ }
+ final List<JaxrsElementDelta> results = new
ArrayList<JaxrsElementDelta>();
final ITypeHierarchy applicationTypeHierarchy =
JdtUtils.resolveTypeHierarchy(applicationType, false,
progressMonitor);
final IType[] applicationSubclasses =
applicationTypeHierarchy.getSubclasses(applicationType);
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/WtpUtils.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/WtpUtils.java 2012-01-24
21:38:42 UTC (rev 38121)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/WtpUtils.java 2012-01-24
21:59:52 UTC (rev 38122)
@@ -14,8 +14,6 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jst.j2ee.web.componentcore.util.WebArtifactEdit;
import org.eclipse.wst.common.componentcore.ComponentCore;
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
@@ -82,6 +80,7 @@
* servletMapping.getUrlPattern(); } }
*/
// using a good old xpath expression to scan the file.
+
try {
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
domFactory.setNamespaceAware(false); // never forget this!
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodSignaturesVisitor.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodSignaturesVisitor.java 2012-01-24
21:38:42 UTC (rev 38121)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodSignaturesVisitor.java 2012-01-24
21:59:52 UTC (rev 38122)
@@ -71,7 +71,7 @@
public boolean visit(MethodDeclaration declaration) {
try {
final IJavaElement element =
compilationUnit.getElementAt(declaration.getStartPosition());
- if (element.getElementType() != IJavaElement.METHOD) {
+ if (element == null || element.getElementType() != IJavaElement.METHOD) {
return true;
}
IMethod method = (IMethod) element;
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/JaxrsMetamodelDelta.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/JaxrsMetamodelDelta.java 2012-01-24
21:38:42 UTC (rev 38121)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/JaxrsMetamodelDelta.java 2012-01-24
21:59:52 UTC (rev 38122)
@@ -7,7 +7,9 @@
import java.util.Collections;
import java.util.List;
+import org.eclipse.jdt.core.IJavaElementDelta;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsElementDelta;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.ConstantUtils;
/**
* @author Xavier Coulon
@@ -22,10 +24,10 @@
private final int deltaKind;
/** List of underlying JarxEndpoints change events carried by this event. */
- private final List<JaxrsEndpointDelta> affectedEndpointd;
+ private final List<JaxrsEndpointDelta> affectedEndpoints;
private final List<JaxrsElementDelta> affectedElements;
-
+
/**
* Full constructor.
*
@@ -34,19 +36,19 @@
this.metamodel = metamodel;
this.deltaKind = deltaKind;
this.affectedElements = new ArrayList<JaxrsElementDelta>();
- this.affectedEndpointd = new ArrayList<JaxrsEndpointDelta>();
+ this.affectedEndpoints = new ArrayList<JaxrsEndpointDelta>();
}
/**
* Full constructor.
*
- * @param affectedEndpointd
+ * @param affectedEndpoints
*/
public JaxrsMetamodelDelta(IJaxrsMetamodel metamodel, int deltaKind,
List<JaxrsElementDelta> affectedElements) {
this.metamodel = metamodel;
this.deltaKind = deltaKind;
this.affectedElements = affectedElements;
- this.affectedEndpointd = new ArrayList<JaxrsEndpointDelta>();
+ this.affectedEndpoints = new ArrayList<JaxrsEndpointDelta>();
}
/**
@@ -67,7 +69,7 @@
* @return the endpointDeltas
*/
public final List<JaxrsEndpointDelta> getAffectedEndpoints() {
- return Collections.unmodifiableList(affectedEndpointd);
+ return Collections.unmodifiableList(affectedEndpoints);
}
/**
@@ -80,7 +82,7 @@
public void addAffectedEndpoint(List<JaxrsEndpointDelta> affectedEndpoints) {
if (affectedEndpoints != null) {
- this.affectedEndpointd.addAll(affectedEndpoints);
+ this.affectedEndpoints.addAll(affectedEndpoints);
}
}
@@ -102,4 +104,15 @@
}
}
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return "JaxrsMetamodelDelta [metamodel=" + metamodel + ",
deltaKind=" + ConstantUtils.getStaticFieldName(IJavaElementDelta.class, deltaKind) +
"\n\taffectedEndpoints:"
+ + affectedEndpoints + "\n\taffectedElements=" + affectedElements +
"]";
+ }
+
+
+
}
Added:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-3_0-with-invalid-servlet-mapping.xml
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-3_0-with-invalid-servlet-mapping.xml
(rev 0)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-3_0-with-invalid-servlet-mapping.xml 2012-01-24
21:59:52 UTC (rev 38122)
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
+ <welcome-file-list>
+ <welcome-file>index.html</welcome-file>
+ </welcome-file-list>
+ <servlet>
+ <servlet-name>Faces Servlet</servlet-name>
+ <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>Faces Servlet</servlet-name>
+ <url-pattern>*.jsf</url-pattern>
+ </servlet-mapping>
+ <context-param>
+ <param-name>facelets.DEVELOPMENT</param-name>
+ <param-value>true</param-value>
+ </context-param>
+</web-app>
\ No newline at end of file
Property changes on:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/resources/web-3_0-with-invalid-servlet-mapping.xml
___________________________________________________________________
Added: svn:mime-type
+ text/plain
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 2012-01-24
21:38:42 UTC (rev 38121)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/WorkbenchTasks.java 2012-01-24
21:59:52 UTC (rev 38122)
@@ -51,8 +51,7 @@
*
* @param sourcePath
* @param monitor
- * @return true if ImportOperation to synchronize was performed (ie, was
- * required), false otherwise.
+ * @return true if ImportOperation to synchronize was performed (ie, was required),
false otherwise.
* @throws InvocationTargetException
* @throws InterruptedException
* @throws CoreException
@@ -179,8 +178,9 @@
public static IPackageFragmentRoot addClasspathEntry(IJavaProject javaProject, String
name,
IProgressMonitor progressMonitor) throws CoreException, OperationCanceledException,
InterruptedException {
IPath path =
javaProject.getProject().getLocation().append("lib").addTrailingSeparator().append(name);
- Assert.assertTrue("Following library does not exist or is not readable: " +
path.toFile(), path.toFile()
- .exists() && path.toFile().canRead());
+ if (!path.toFile().exists() || !path.toFile().canRead()) {
+ LOGGER.warn("Following library does not exist or is not readable: {} ",
path.toFile());
+ }
IClasspathEntry[] classpathEntries = javaProject.getRawClasspath();
IClasspathEntry newLibraryEntry = JavaCore.newLibraryEntry(path, null, null);
classpathEntries = (IClasspathEntry[]) ArrayUtils.add(classpathEntries,
newLibraryEntry);
@@ -195,8 +195,7 @@
}
/**
- * Called by subclasses to setup the workspace with project and files (xml,
- * java, etc.)
+ * Called by subclasses to setup the workspace with project and files (xml, java, etc.)
*
* @param projectName
*
Modified:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementDeltaScannerTestCase.java
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementDeltaScannerTestCase.java 2012-01-24
21:38:42 UTC (rev 38121)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementDeltaScannerTestCase.java 2012-01-24
21:59:52 UTC (rev 38122)
@@ -114,7 +114,8 @@
public void resourceChanged(IResourceChangeEvent event) {
try {
final ResourceDeltaScanner scanner = new ResourceDeltaScanner();
- final List<ResourceDelta> affectedResources =
scanner.scanAndFilterEvent(event.getDelta(), new NullProgressMonitor());
+ final List<ResourceDelta> affectedResources =
scanner.scanAndFilterEvent(event.getDelta(),
+ new NullProgressMonitor());
// must explicitly call the add() method to perform verify() on the mocks at the end
of the test.
for (ResourceDelta resourceDelta : affectedResources) {
resourceEvents.add(resourceDelta);
@@ -150,13 +151,18 @@
private void verifyEventNotification(IJavaElement element, int deltaKind, int eventType,
int flags,
VerificationMode numberOfTimes) throws JavaModelException {
LOGGER.info("Verifying method calls..");
- // verify(scanner,
- // numberOfTimes).notifyJavaElementChanged(eq(element),
- // eq(elementKind), eq(deltaKind),
- // any(CompilationUnit.class), eq(flags));
- ICompilationUnit compilationUnit = JdtUtils.getCompilationUnit(element);
- CompilationUnit ast = JdtUtils.parse(compilationUnit, new NullProgressMonitor());
- verify(javaElementEvents, numberOfTimes).add(new JavaElementDelta(element, deltaKind,
eventType, ast, flags));
+ if (element == null) {
+ verify(javaElementEvents, numberOfTimes).add(null);
+ } else {
+ // verify(scanner,
+ // numberOfTimes).notifyJavaElementChanged(eq(element),
+ // eq(elementKind), eq(deltaKind),
+ // any(CompilationUnit.class), eq(flags));
+ ICompilationUnit compilationUnit = JdtUtils.getCompilationUnit(element);
+ CompilationUnit ast = JdtUtils.parse(compilationUnit, new NullProgressMonitor());
+ verify(javaElementEvents, numberOfTimes).add(
+ new JavaElementDelta(element, deltaKind, eventType, ast, flags));
+ }
}
private void verifyEventNotification(IResource resource, int deltaKind, int eventType,
int flags,
@@ -552,6 +558,15 @@
}
@Test
+ public void shouldNotNotifyWhenUnexistingLibraryAddedInClasspath() throws CoreException,
InterruptedException {
+ // operation
+ IPackageFragmentRoot addedEntry = WorkbenchTasks.addClasspathEntry(javaProject,
"slf4j-api-1.5.xyz.jar",
+ new NullProgressMonitor());
+ // verifications
+ verifyEventNotification(addedEntry, ADDED, POST_CHANGE, NO_FLAG, times(0));
+ }
+
+ @Test
public void shouldNotifyWhenLibraryRemovedFromClasspath() throws CoreException,
InterruptedException {
// operation
List<IPackageFragmentRoot> removedEntries =
WorkbenchUtils.removeClasspathEntry(javaProject,
Modified:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/ResourceChangedProcessorTestCase.java
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/ResourceChangedProcessorTestCase.java 2012-01-24
21:38:42 UTC (rev 38121)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/ResourceChangedProcessorTestCase.java 2012-01-24
21:59:52 UTC (rev 38122)
@@ -19,6 +19,7 @@
import static org.hamcrest.Matchers.notNullValue;
import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.getAnnotation;
import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.getType;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.spy;
@@ -494,6 +495,23 @@
verify(metamodel, times(1)).add(any(JaxrsWebxmlApplication.class));
assertThat(metamodel.getElements(javaProject).size(), equalTo(1));
}
+
+ @Test
+ public void shouldNotFailWhenWebxmlWithUnknownServletClass() throws Exception {
+ // pre-conditions
+ List<IPackageFragmentRoot> removedEntries =
WorkbenchUtils.removeClasspathEntry(javaProject,
+ "jaxrs-api-2.0.1.GA.jar", null);
+ assertFalse(removedEntries.isEmpty());
+ final IResource webxmlResource =
WorkbenchUtils.replaceDeploymentDescriptorWith(javaProject,
+ "web-3_0-with-invalid-servlet-mapping.xml", bundle);
+ //metamodel.add(createApplication("/foo"));
+ // operation
+ // operation
+ final ResourceDelta event = createEvent(webxmlResource, CHANGED);
+ final List<JaxrsElementDelta> affectedElements = processResourceChanges(event,
progressMonitor);
+ // verifications
+ assertThat(affectedElements.size(), equalTo(0));
+ }
@Test
public void shouldRemoveApplicationWhenChangingWebxml() throws Exception {