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 2013/07/19 17:02:40 UTC

svn commit: r1504896 - /sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadBehaviour.java

Author: rombert
Date: Fri Jul 19 15:02:40 2013
New Revision: 1504896

URL: http://svn.apache.org/r1504896
Log:
SLING-2793 - [Tooling] Align Eclipse tooling to proposed structure

Implement proper resource sync which obeys all delta kinds. Still need
to make a proper implementation of SlingContentModuleDelegate.members

Modified:
    sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadBehaviour.java

Modified: sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadBehaviour.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadBehaviour.java?rev=1504896&r1=1504895&r2=1504896&view=diff
==============================================================================
--- sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadBehaviour.java (original)
+++ sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadBehaviour.java Fri Jul 19 15:02:40 2013
@@ -21,6 +21,7 @@ import java.net.URISyntaxException;
 import java.util.Arrays;
 
 import org.apache.sling.slingclipse.SlingclipsePlugin;
+import org.apache.sling.slingclipse.api.Command;
 import org.apache.sling.slingclipse.api.FileInfo;
 import org.apache.sling.slingclipse.api.Repository;
 import org.apache.sling.slingclipse.api.RepositoryInfo;
@@ -36,7 +37,10 @@ import org.eclipse.debug.core.ILaunch;
 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
 import org.eclipse.wst.server.core.IModule;
 import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.model.IModuleFile;
+import org.eclipse.wst.server.core.model.IModuleFolder;
 import org.eclipse.wst.server.core.model.IModuleResource;
+import org.eclipse.wst.server.core.model.IModuleResourceDelta;
 import org.eclipse.wst.server.core.model.ServerBehaviourDelegate;
 
 public class SlingLaunchpadBehaviour extends ServerBehaviourDelegate {
@@ -132,6 +136,7 @@ public class SlingLaunchpadBehaviour ext
         SlingLaunchpadConfiguration configuration = launchpadServer.getConfiguration();
 
         IModuleResource[] moduleResources = getResources(module);
+
         Repository repository = SlingclipsePlugin.getDefault().getRepository();
         try {
             // TODO configurable scheme?
@@ -145,29 +150,94 @@ public class SlingLaunchpadBehaviour ext
             // TODO handle error
         }
 
-        for (IModuleResource resource : moduleResources) {
-
-            IFile file = (IFile) resource.getAdapter(IFile.class);
-
-            IPath projectPath = file.getProject().getFullPath();
-            IPath filePath = file.getFullPath();
-            IPath relativePath = filePath.makeRelativeTo(projectPath);
-            IPath rootPath = relativePath.removeLastSegments(1); // TODO correct name
+        switch (deltaKind) {
+            case ServerBehaviourDelegate.CHANGED:
+                IModuleResourceDelta[] publishedResourceDelta = getPublishedResourceDelta(module);
+                for (IModuleResourceDelta resourceDelta : publishedResourceDelta) {
+                    if (resourceDelta.getModuleResource() instanceof IModuleFile) {
+                        switch (resourceDelta.getKind()) {
+                            case IModuleResourceDelta.ADDED:
+                            case IModuleResourceDelta.CHANGED:
+                            case IModuleResourceDelta.NO_CHANGE: // TODO is this needed?
+                                Result<?> result = addFileCommand(repository,
+                                        (IModuleFile) resourceDelta.getModuleResource()).execute();
+                                if (!result.isSuccess()) // TODO proper logging
+                                    throw new CoreException(new Status(Status.ERROR, "some.plugin", result.toString()));
+                                break;
+                            case IModuleResourceDelta.REMOVED:
+                                Result<?> deleteResult = removeFileCommand(repository,
+                                        (IModuleFile) resourceDelta.getModuleResource()).execute();
+                                if (!deleteResult.isSuccess()) // TODO proper logging
+                                    throw new CoreException(new Status(Status.ERROR, "some.plugin",
+                                            deleteResult.toString()));
+                                break;
+                        }
+                    }
+                }
+                break;
 
-            FileInfo info = new FileInfo(file.getLocation().toOSString(), rootPath.toOSString(),
-                    file.getName());
+            case ServerBehaviourDelegate.ADDED:
+            case ServerBehaviourDelegate.NO_CHANGE: // TODO is this correct ?
+                for (IModuleResource resource : moduleResources) {
 
-            System.out.println("For " + resource + " build fileInfo " + info);
+                    if (resource instanceof IModuleFile) {
+                        Result<?> result = addFileCommand(repository, (IModuleFile) resource).execute();
+                        if (!result.isSuccess()) // TODO proper logging
+                            throw new CoreException(new Status(Status.ERROR, "some.plugin", result.toString()));
+                    } else {
+                        // TODO log/barf
+                    }
+                }
+                break;
+            case ServerBehaviourDelegate.REMOVED:
+                for (IModuleResource resource : moduleResources) {
 
-            Result<Void> result = repository.newAddNodeCommand(info).execute();
-            if (!result.isSuccess())
-                throw new CoreException(new Status(Status.ERROR, "some.plugin", result.toString()));
+                    if (resource instanceof IModuleFile) {
+                        Result<?> result = removeFileCommand(repository, (IModuleFile) resource).execute();
+                        if (!result.isSuccess()) // TODO proper logging
+                            throw new CoreException(new Status(Status.ERROR, "some.plugin", result.toString()));
+                    } else {
+                        // TODO log/barf
+                    }
+                }
+                break;
         }
 
+
         // set state to published
         super.publishModule(kind, deltaKind, module, monitor);
     }
 
+    private Command<?> addFileCommand(Repository repository, IModuleFile resource) {
+        IFile file = (IFile) resource.getAdapter(IFile.class);
+
+        IPath projectPath = file.getProject().getFullPath();
+        IPath filePath = file.getFullPath();
+        IPath relativePath = filePath.makeRelativeTo(projectPath);
+        IPath rootPath = relativePath.removeLastSegments(1); // TODO correct name
+
+        FileInfo info = new FileInfo(file.getLocation().toOSString(), rootPath.toOSString(), file.getName());
+
+        System.out.println("For " + resource + " build fileInfo " + info);
+
+        return repository.newAddNodeCommand(info);
+    }
+
+    private Command<?> removeFileCommand(Repository repository, IModuleFile resource) {
+        IFile file = (IFile) resource.getAdapter(IFile.class);
+
+        IPath projectPath = file.getProject().getFullPath();
+        IPath filePath = file.getFullPath();
+        IPath relativePath = filePath.makeRelativeTo(projectPath);
+        IPath rootPath = relativePath.removeLastSegments(1); // TODO correct name
+
+        FileInfo info = new FileInfo(file.getLocation().toOSString(), rootPath.toOSString(), file.getName());
+
+        System.out.println("For " + resource + " build fileInfo " + info);
+
+        return repository.newDeleteNodeCommand(info);
+    }
+
     /*
      * (non-Javadoc)
      *