Author: xcoulon
Date: 2012-10-18 06:55:20 -0400 (Thu, 18 Oct 2012)
New Revision: 44576
Modified:
branches/jbosstools-4.0.0.Beta1/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementDeltaFilter.java
branches/jbosstools-4.0.0.Beta1/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementDeltaFilterTestCase.java
branches/jbosstools-4.0.0.Beta1/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementDeltaScannerTestCase.java
Log:
Fixed - JBIDE-12887
JAX-RS should not analyse jars in the project's classpath
Modified:
branches/jbosstools-4.0.0.Beta1/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementDeltaFilter.java
===================================================================
---
branches/jbosstools-4.0.0.Beta1/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementDeltaFilter.java 2012-10-18
10:34:04 UTC (rev 44575)
+++
branches/jbosstools-4.0.0.Beta1/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementDeltaFilter.java 2012-10-18
10:55:20 UTC (rev 44576)
@@ -41,6 +41,7 @@
import org.eclipse.jdt.core.ElementChangedEvent;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaElementDelta;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.jboss.tools.ws.jaxrs.core.internal.utils.ConstantUtils;
import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
import org.jboss.tools.ws.jaxrs.core.jdt.JdtUtils;
@@ -104,27 +105,23 @@
return new RuleBuilder();
}
+
/**
- * Attempts to retrieve the CompilationUnitContext value matching the given
- * parameters.
- *
- * @param elementKind
- * the kind of Java element that changed.
- * @param deltaKind
- * the kind of change.
- * @param workingCopy
- * @return the scope defined by the rules, or PRIMARY_COPY if nothing was
- * set.
- * @see IJavaElementDelta, IJavaElementKind
+ * Applies the configured rules to see if the given JavaElementDelta needs to be
processed or should be ignored.
+ * @param event the Java Element Delta
+ * @return true if the event should be processed, false otherwise
*/
-
public boolean apply(JavaElementDelta event) {
+ if(event.getElement() == null) {
+ return false;
+ }
int elementKind = event.getElement().getElementType();
int deltaKind = event.getDeltaKind();
IJavaElement element = event.getElement();
// prevent processing java elements in a closed java project
// prevent processing of any file named 'package-info.java'
- if (isProjectClosed(element) || isPackageInfoFile(element)) {
+ // prevent processing of any jar file
+ if (isProjectClosed(element) || isPackageInfoFile(element) || isJarArchive(element)) {
return false;
}
int flags = event.getFlags();
@@ -142,6 +139,16 @@
}
/**
+ *
+ * @param element
+ * @return true if the given java element is a Jar archive.
+ */
+ private boolean isJarArchive(IJavaElement element) {
+ return (element.getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT &&
((IPackageFragmentRoot)element).isArchive());
+
+ }
+
+ /**
* Returns true if the element resource is a file named 'package-info.java'
(whatever the containing folder)
* @param element
* @return
Modified:
branches/jbosstools-4.0.0.Beta1/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementDeltaFilterTestCase.java
===================================================================
---
branches/jbosstools-4.0.0.Beta1/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementDeltaFilterTestCase.java 2012-10-18
10:34:04 UTC (rev 44575)
+++
branches/jbosstools-4.0.0.Beta1/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementDeltaFilterTestCase.java 2012-10-18
10:55:20 UTC (rev 44576)
@@ -13,7 +13,7 @@
import static org.eclipse.core.resources.IResourceDelta.REMOVED;
import static org.eclipse.jdt.core.ElementChangedEvent.POST_CHANGE;
import static org.eclipse.jdt.core.ElementChangedEvent.POST_RECONCILE;
-import static org.eclipse.jdt.core.IJavaElement.ANNOTATION;
+import static org.eclipse.jdt.core.IJavaElement.*;
import static org.eclipse.jdt.core.IJavaElement.COMPILATION_UNIT;
import static org.eclipse.jdt.core.IJavaElement.METHOD;
import static org.eclipse.jdt.core.IJavaElement.TYPE;
@@ -30,6 +30,7 @@
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.junit.Before;
@@ -117,4 +118,18 @@
assertFalse("Wrong result", filter.apply(createEvent(element, REMOVED,
POST_CHANGE, NO_FLAG)));
}
+ @Test
+ public void shouldNotAcceptChangesInJarFile() {
+ IPackageFragmentRoot element = createMock(IPackageFragmentRoot.class,
PACKAGE_FRAGMENT_ROOT);
+ IResource resource = mock(IResource.class);
+ when(element.getResource()).thenReturn(resource);
+ when(element.isArchive()).thenReturn(true);
+ when(resource.getType()).thenReturn(IResource.FILE);
+ assertFalse("Wrong result", filter.apply(createEvent(element, ADDED,
POST_RECONCILE, NO_FLAG)));
+ assertFalse("Wrong result", filter.apply(createEvent(element, ADDED,
POST_CHANGE, NO_FLAG)));
+ assertFalse("Wrong result", filter.apply(createEvent(element, CHANGED,
POST_RECONCILE, NO_FLAG)));
+ assertFalse("Wrong result", filter.apply(createEvent(element, CHANGED,
POST_CHANGE, NO_FLAG)));
+ assertFalse("Wrong result", filter.apply(createEvent(element, REMOVED,
POST_RECONCILE, NO_FLAG)));
+ assertFalse("Wrong result", filter.apply(createEvent(element, REMOVED,
POST_CHANGE, NO_FLAG)));
+ }
}
Modified:
branches/jbosstools-4.0.0.Beta1/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementDeltaScannerTestCase.java
===================================================================
---
branches/jbosstools-4.0.0.Beta1/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementDeltaScannerTestCase.java 2012-10-18
10:34:04 UTC (rev 44575)
+++
branches/jbosstools-4.0.0.Beta1/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementDeltaScannerTestCase.java 2012-10-18
10:55:20 UTC (rev 44576)
@@ -549,12 +549,12 @@
}
@Test
- public void shouldNotifyWhenLibraryAddedInClasspath() throws CoreException,
InterruptedException {
+ public void shouldNotNotifyWhenLibraryAddedInClasspath() throws CoreException,
InterruptedException {
// operation
IPackageFragmentRoot addedEntry = WorkbenchTasks.addClasspathEntry(javaProject,
"slf4j-api-1.5.2.jar",
new NullProgressMonitor());
// verifications
- verifyEventNotification(addedEntry, ADDED, POST_CHANGE, NO_FLAG, times(1));
+ verifyEventNotification(addedEntry, ADDED, POST_CHANGE, NO_FLAG, times(0));
}
@Test
@@ -567,13 +567,13 @@
}
@Test
- public void shouldNotifyWhenLibraryRemovedFromClasspath() throws CoreException,
InterruptedException {
+ public void shouldNotNotifyWhenLibraryRemovedFromClasspath() throws CoreException,
InterruptedException {
// operation
List<IPackageFragmentRoot> removedEntries =
WorkbenchUtils.removeClasspathEntry(javaProject,
"jaxrs-api-2.0.1.GA.jar", null);
// verifications
for (IPackageFragmentRoot removedEntry : removedEntries) {
- verifyEventNotification(removedEntry, REMOVED, POST_CHANGE, F_REMOVED_FROM_CLASSPATH,
times(1));
+ verifyEventNotification(removedEntry, REMOVED, POST_CHANGE, F_REMOVED_FROM_CLASSPATH,
times(0));
}
}