You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2014/10/11 00:17:35 UTC

svn commit: r1630999 - in /sling/trunk/tooling/ide: eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/ResourceChangeCommandFactory.java eclipse-test/src/org/apache/sling/ide/test/impl/helpers/FailOnModificationEventsRule.java

Author: rombert
Date: Fri Oct 10 22:17:35 2014
New Revision: 1630999

URL: http://svn.apache.org/r1630999
Log:
SLING-4020 - Importing content from the repository triggers publish
operations

Actually ignore the imported resources when applicable. Also made the
event listening test helper more resilient to late events.

Modified:
    sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/ResourceChangeCommandFactory.java
    sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/FailOnModificationEventsRule.java

Modified: sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/ResourceChangeCommandFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/ResourceChangeCommandFactory.java?rev=1630999&r1=1630998&r2=1630999&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/ResourceChangeCommandFactory.java (original)
+++ sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/ResourceChangeCommandFactory.java Fri Oct 10 22:17:35 2014
@@ -117,15 +117,11 @@ public class ResourceChangeCommandFactor
 
         Long modificationTimestamp = (Long) resource.getSessionProperty(ResourceUtil.QN_IMPORT_MODIFICATION_TIMESTAMP);
 
-        if (modificationTimestamp != null) {
-            if (modificationTimestamp >= resource.getModificationStamp()) {
-                Activator.getDefault().getPluginLogger()
-                        .trace("Change for resource {0} ignored as the import timestamp {1} >= modification timestamp {2}",
-                                resource, modificationTimestamp, resource.getModificationStamp());
-            } else {
-                // clear the import modification timestamp since this is a more recent change
-                resource.setSessionProperty(ResourceUtil.QN_IMPORT_MODIFICATION_TIMESTAMP, null);
-            }
+        if (modificationTimestamp != null && modificationTimestamp >= resource.getModificationStamp()) {
+            Activator.getDefault().getPluginLogger()
+                    .trace("Change for resource {0} ignored as the import timestamp {1} >= modification timestamp {2}",
+                            resource, modificationTimestamp, resource.getModificationStamp());
+            return null;
         }
 
         if (resource.isTeamPrivateMember(IResource.CHECK_ANCESTORS)) {

Modified: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/FailOnModificationEventsRule.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/FailOnModificationEventsRule.java?rev=1630999&r1=1630998&r2=1630999&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/FailOnModificationEventsRule.java (original)
+++ sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/FailOnModificationEventsRule.java Fri Oct 10 22:17:35 2014
@@ -18,10 +18,10 @@ package org.apache.sling.ide.test.impl.h
 
 import static org.junit.Assert.fail;
 
-import java.util.ArrayList;
 import java.util.Dictionary;
 import java.util.Hashtable;
 import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
 
 import org.apache.sling.ide.eclipse.core.internal.Activator;
 import org.apache.sling.ide.transport.CommandExecutionProperties;
@@ -39,8 +39,10 @@ import org.osgi.service.event.EventHandl
  */
 public class FailOnModificationEventsRule implements EventHandler, TestRule {
 
+    private static final int SETTLE_TIMEOUT_MILLIS = 100;
+    
     private ServiceRegistration<EventHandler> registration;
-    private List<Event> unexpectedEvents = new ArrayList<Event>();
+    private List<Event> unexpectedEvents = new CopyOnWriteArrayList<Event>();
 
     public Statement apply(Statement base, Description description) {
         return statement(base);
@@ -69,12 +71,14 @@ public class FailOnModificationEventsRul
 
     }
 
-    protected void after() {
+    protected void after() throws InterruptedException {
 
         if (registration != null) {
             registration.unregister();
         }
 
+        waitForEventsToSettle();
+
         if (unexpectedEvents.isEmpty()) {
             return;
         }
@@ -93,6 +97,35 @@ public class FailOnModificationEventsRul
         fail(desc.toString());
     }
 
+    /**
+     * Clears the list of unexpected events after the event firing settles
+     * 
+     * <p>
+     * This can be useful for instance when you want to validate that no import events take place after a certain point
+     * in time.
+     * </p>
+     * 
+     * <p>
+     * Event firing settling is defined as no unexpected events being recorded for {@value #SETTLE_TIMEOUT_MILLIS}
+     * milliseconds
+     * </p>
+     */
+    public void clearUnexpectedEventsAfterSettling() throws InterruptedException {
+
+        waitForEventsToSettle();
+
+        unexpectedEvents.clear();
+    }
+
+    private void waitForEventsToSettle() throws InterruptedException {
+
+        int currentSize;
+        do {
+            currentSize = unexpectedEvents.size();
+            Thread.sleep(SETTLE_TIMEOUT_MILLIS);
+        } while (currentSize != unexpectedEvents.size());
+    }
+
     @Override
     public void handleEvent(Event event) {