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/05/16 13:48:05 UTC

svn commit: r1595168 - in /sling/trunk/tooling/ide: eclipse-core/src/org/apache/sling/ide/eclipse/core/ eclipse-ui/ eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/

Author: rombert
Date: Fri May 16 11:48:05 2014
New Revision: 1595168

URL: http://svn.apache.org/r1595168
Log:
SLING-3568 - Allow importing content from arbitrary locations

Allow the ImportWizard to select arbitrary locations for importing.

Modified:
    sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/ProjectUtil.java
    sling/trunk/tooling/ide/eclipse-ui/plugin.xml
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportContentAction.java
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportRepositoryContentAction.java
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportWizard.java
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportWizardPage.java
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/SlingLaunchpadCombo.java

Modified: sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/ProjectUtil.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/ProjectUtil.java?rev=1595168&r1=1595167&r2=1595168&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/ProjectUtil.java (original)
+++ sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/ProjectUtil.java Fri May 16 11:48:05 2014
@@ -160,6 +160,9 @@ public abstract class ProjectUtil {
         FilterLocator filterLocator = Activator.getDefault().getFilterLocator();
 
         IFolder syncFolder = ProjectUtil.getSyncDirectory(project);
+        if (syncFolder == null) {
+            return null;
+        }
         File filterLocation = filterLocator.findFilterLocation(syncFolder.getLocation().toFile());
         if (filterLocation == null) {
             return null;

Modified: sling/trunk/tooling/ide/eclipse-ui/plugin.xml
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/plugin.xml?rev=1595168&r1=1595167&r2=1595168&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/plugin.xml (original)
+++ sling/trunk/tooling/ide/eclipse-ui/plugin.xml Fri May 16 11:48:05 2014
@@ -78,7 +78,7 @@
          <!-- Import. 
          	I prefer to do this outside the import wizard section since I can restrict the destination -->
          <objectContribution id="org.apache.sling.ide.menu.import"
-         	objectClass="org.eclipse.core.resources.IProject">
+         	objectClass="org.eclipse.core.resources.IResource">
          	
          <action
                class="org.apache.sling.ide.eclipse.ui.internal.ImportContentAction"
@@ -88,20 +88,10 @@
                menubarPath="org.apache.sling.ide.menu/sling"
                style="push">
          </action>
-         <visibility>
-               <objectState
-                     name="open"
-                     value="true">
-               </objectState>
-         </visibility>
          <enablement>
 			<or>
 			    <test 
-		            property="org.eclipse.wst.common.project.facet.core.projectFacet" 
-		            value="sling.content"/>
-			    <test 
-		            property="org.eclipse.wst.common.project.facet.core.projectFacet" 
-		            value="sling.bundle"/>
+		            property="org.apache.sling.ide.eclipse.canBeImported"/>
 		    </or>         
          </enablement>
 		</objectContribution>

Modified: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportContentAction.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportContentAction.java?rev=1595168&r1=1595167&r2=1595168&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportContentAction.java (original)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportContentAction.java Fri May 16 11:48:05 2014
@@ -18,10 +18,12 @@ package org.apache.sling.ide.eclipse.ui.
 
 import java.util.Iterator;
 
+import org.apache.sling.ide.eclipse.core.internal.ProjectHelper;
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IConfigurationElement;
 import org.eclipse.core.runtime.IExecutableExtension;
@@ -59,16 +61,16 @@ public class ImportContentAction extends
 
         for (Iterator<?> it = structuredSelection.iterator(); it.hasNext();) {
             Object selected = it.next();
-            if (selected instanceof IProject) {
-                IProject project = (IProject) selected;
+            if (selected instanceof IResource) {
+                IProject project = (IProject) (((IResource) selected).getProject());
 
-                IModule module = ServerUtil.getModule(project);
-
-                if (module == null) {
+                if (!ProjectHelper.isContentProject(project)) {
                     continue;
                 }
 
-                if (!module.getModuleType().getId().equals("sling.content")) {
+                IModule module = ServerUtil.getModule(project);
+
+                if (module == null) {
                     continue;
                 }
 

Modified: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportRepositoryContentAction.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportRepositoryContentAction.java?rev=1595168&r1=1595167&r2=1595168&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportRepositoryContentAction.java (original)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportRepositoryContentAction.java Fri May 16 11:48:05 2014
@@ -19,7 +19,6 @@ package org.apache.sling.ide.eclipse.ui.
 import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.IOException;
-import java.io.InputStream;
 import java.lang.reflect.InvocationTargetException;
 import java.util.Iterator;
 import java.util.LinkedList;
@@ -31,7 +30,6 @@ import org.apache.sling.ide.eclipse.core
 import org.apache.sling.ide.eclipse.core.ServerUtil;
 import org.apache.sling.ide.eclipse.core.debug.PluginLogger;
 import org.apache.sling.ide.filter.Filter;
-import org.apache.sling.ide.filter.FilterLocator;
 import org.apache.sling.ide.filter.FilterResult;
 import org.apache.sling.ide.serialization.SerializationData;
 import org.apache.sling.ide.serialization.SerializationDataBuilder;
@@ -124,7 +122,18 @@ public class ImportRepositoryContentActi
             monitor.setTaskName("Importing...");
             monitor.worked(10);
 
-            crawlChildrenAndImport(repository, filter, "/", project, projectRelativePath);
+            IFolder syncDir = ProjectUtil.getSyncDirectory(project);
+            IPath repositoryImportRoot = projectRelativePath.makeRelativeTo(syncDir.getProjectRelativePath())
+                    .makeAbsolute();
+
+            Activator
+                    .getDefault()
+                    .getPluginLogger()
+                    .trace("Starting import; repository start point is {0}, workspace start point is {1}",
+                            repositoryImportRoot, projectRelativePath);
+
+            crawlChildrenAndImport(repository, filter, repositoryImportRoot.toPortableString(), project,
+                    projectRelativePath);
 
             monitor.setTaskName("Import Complete");
             monitor.worked(100);
@@ -164,6 +173,7 @@ public class ImportRepositoryContentActi
             throws RepositoryException, CoreException, IOException, SerializationException {
 
         File contentSyncRoot = ProjectUtil.getSyncDirectoryFullPath(project).toFile();
+        IFolder contentSyncRootDir = ProjectUtil.getSyncDirectory(project);
 
         logger.trace("crawlChildrenAndImport({0},  {1}, {2}, {3}", repository, path, project, projectRelativePath);
 
@@ -176,7 +186,8 @@ public class ImportRepositoryContentActi
         final List<ResourceProxy> resourceChildren = new LinkedList<ResourceProxy>(resource.getChildren());
 		if (serializationData != null) {
 	
-	        IPath fileOrFolderPath = projectRelativePath.append(serializationData.getFileOrFolderNameHint());
+            IPath fileOrFolderPath = contentSyncRootDir.getProjectRelativePath().append(
+                    serializationData.getFileOrFolderNameHint());
 	
 	        switch (serializationData.getSerializationKind()) {
 	            case FILE: {
@@ -259,6 +270,8 @@ public class ImportRepositoryContentActi
         if (destinationFolder.exists())
             return;
 
+        logger.trace("Creating folder {0}", destinationFolder.getFullPath());
+
         destinationFolder.create(true, true, null /* TODO progress monitor */);
 
         destinationFolder.setSessionProperty(ResourceUtil.QN_IGNORE_NEXT_CHANGE, Boolean.TRUE.toString());

Modified: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportWizard.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportWizard.java?rev=1595168&r1=1595167&r2=1595168&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportWizard.java (original)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportWizard.java Fri May 16 11:48:05 2014
@@ -21,7 +21,7 @@ import java.lang.reflect.InvocationTarge
 import org.apache.sling.ide.serialization.SerializationException;
 import org.apache.sling.ide.serialization.SerializationManager;
 import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.IProgressMonitor;
@@ -63,10 +63,9 @@ public class ImportWizard extends Wizard
 
         final IServer server = mainPage.getServer();
 
-        IPath destinationPath = mainPage.getResourcePath();
-
-        final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(destinationPath.segments()[0]);
-        final IPath projectRelativePath = destinationPath.removeFirstSegments(1);
+        IResource resource = mainPage.getResource();
+        final IProject project = resource.getProject();
+        final IPath projectRelativePath = resource.getProjectRelativePath();
         IRunnableWithProgress runnable = new IRunnableWithProgress() {
             @Override
             public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {

Modified: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportWizardPage.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportWizardPage.java?rev=1595168&r1=1595167&r2=1595168&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportWizardPage.java (original)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportWizardPage.java Fri May 16 11:48:05 2014
@@ -18,6 +18,7 @@ package org.apache.sling.ide.eclipse.ui.
 
 
 import org.apache.sling.ide.eclipse.core.ProjectUtil;
+import org.apache.sling.ide.eclipse.core.internal.ProjectHelper;
 import org.eclipse.core.resources.IContainer;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IFolder;
@@ -56,9 +57,11 @@ public class ImportWizardPage extends Wi
     private SlingLaunchpadCombo repositoryCombo;
     private Label importLabel;
 	private Button containerBrowseButton;
-	private IProject project;
+    private IProject project;
 	private Text containerNameField;
 	private Label adjustJcrRootText;
+    private IFolder importRoot;
+    private Composite adjustComposite;
 
 	/**
 	 * Creates an import wizard page for importing from a Sling Repository. If
@@ -76,13 +79,25 @@ public class ImportWizardPage extends Wi
 		setTitle(pageName); // NON-NLS-1
 		setDescription("Import content from a Sling Repository into the workspace"); // NON-NLS-1
 
-		if (selection!=null && selection.getFirstElement()!=null && (selection.getFirstElement() instanceof IProject)) {
-			this.project = (IProject) selection.getFirstElement();
-		}
+        Object selectedResource = selection.getFirstElement();
+        if (selectedResource instanceof IProject) {
+            importRoot = ProjectUtil.getSyncDirectory((IProject) selectedResource);
+        } else if (selectedResource instanceof IFile) {
+            // the selection dialog does not support files, so we force this to be the parent folder
+            // also, since the content sync root must be a folder, the parent must be a folder, can't
+            // be a project
+            importRoot = (IFolder) ((IFile) selectedResource).getParent();
+        } else if (selectedResource instanceof IFolder) {
+            importRoot = (IFolder) selectedResource;
+        }
+
+        if (importRoot != null) {
+            project = importRoot.getProject();
+        }
 	}
 	
-    IPath getResourcePath() {
-        return ProjectUtil.getSyncDirectory(project).getFullPath();
+    public IResource getResource() {
+        return importRoot;
 	}
 
 	/*
@@ -163,20 +178,20 @@ public class ImportWizardPage extends Wi
         containerNameField.setFont(composite.getFont());
 
         containerBrowseButton = new Button(containerGroup, SWT.PUSH);
-        containerBrowseButton.setText("Select Project...");
+        containerBrowseButton.setText("Select location...");
         containerBrowseButton.setLayoutData(new GridData(
                 GridData.HORIZONTAL_ALIGN_FILL));
         containerBrowseButton.addListener(SWT.Selection, this);
         containerBrowseButton.setFont(composite.getFont());
         setButtonLayoutData(containerBrowseButton);
         
-        if (project!=null) {
-        	containerNameField.setText(project.getName());
+        if (importRoot != null) {
+            containerNameField.setText(importRoot.getFullPath().toPortableString());
         } else {
-        	setErrorMessage("Select a project first");
+            setErrorMessage("Select an import location");
         }
         
-        Composite adjustComposite = new Composite(composite, SWT.NONE);
+        adjustComposite = new Composite(composite, SWT.NONE);
         adjustComposite.setLayout(new RowLayout());
 
         adjustJcrRootText = new Label(adjustComposite, SWT.NONE);
@@ -207,10 +222,11 @@ public class ImportWizardPage extends Wi
 			handleContainerBrowseButtonPressed();
 		}
 		
+        updateWidgetEnablements();
 		determinePageCompletion();
 	}
 
-    protected IPath queryForProject(IProject initialSelection, String msg,
+    protected IPath queryForLocation(IProject initialSelection, String msg,
             String title) {
         ContainerSelectionDialog dialog = new ContainerSelectionDialog(
                 getControl().getShell(), initialSelection,
@@ -224,16 +240,24 @@ public class ImportWizardPage extends Wi
 			@Override
 			public String isValid(Object selection) {
 				if (!(selection instanceof IPath)) {
-					return "You must select a project";
+                    return "Please select a valid import location";
 				} 
 				IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
-		        IContainer container = (IContainer) root
-		                .findMember((IPath) selection);
+                IContainer container = (IContainer) root.findMember((IPath) selection);
 				if (container instanceof IProject) {
-					return null;
-				} else {
-					return "You must select a project";
+					return "Please select a folder inside the project";
 				}
+				
+                if (!ProjectHelper.isContentProject(container.getProject())) {
+                    return "Project " + container.getProject().getName() + " is not a a Sling content project";
+                }
+
+				if ( ! ProjectUtil.isInsideContentSyncRoot(container) ) {
+                    return "Please select a folder inside the content sync root folder "
+                            + ProjectUtil.getSyncDirectory(container.getProject()).getProjectRelativePath();
+				}
+				
+                return null;
 			}
 		});
         dialog.open();
@@ -245,13 +269,14 @@ public class ImportWizardPage extends Wi
     }
 
     private void handleContainerBrowseButtonPressed() {
-    	IPath result = queryForProject(project, "Select a project to import data to", "Select project");
+        IPath result = queryForLocation(project, "Select a location to import data to", "Select location");
     	if (result!=null) {
 			IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
-	        project = root
-	                .findMember(result).getProject();
+            importRoot = (IFolder) root.findMember(result);
+            project = importRoot.getProject();
 	        
-        	containerNameField.setText(project.getName());
+            containerNameField.setText(importRoot.getFullPath().toPortableString());
+            repositoryCombo.setProject(project);
             repositoryCombo.refreshRepositoryList(new NullProgressMonitor());
     	}
 	}
@@ -272,20 +297,12 @@ public class ImportWizardPage extends Wi
 			// still under construction
 			return true;
 		}
+
         if (this.repositoryCombo == null || this.repositoryCombo.getServer() == null) {
             setErrorMessage("Please select a Sling launchpad instance");
 			return false;
 		}
 
-        String syncDirectoryPath = ProjectUtil.getSyncDirectoryValue(project);
-        IFolder syncFolder = project.getFolder(syncDirectoryPath);
-
-        if (!syncFolder.getFullPath().isPrefixOf(getResourcePath())) {
-            setErrorMessage("The destination directory must be " + syncFolder.getFullPath().toPortableString()
-                    + " or one of its descendants.");
-			return false;
-		}
-		
 		return true;
 	}
 
@@ -304,28 +321,30 @@ public class ImportWizardPage extends Wi
             return;
         }
 
-        IResource syncLocation = project.getWorkspace().getRoot().findMember(getResourcePath());
-        // error message will be displayed, no need for the info label
-        if (syncLocation == null) {
-            importLabel.setVisible(false);
-            importLabel.getParent().layout();
-            return;
-        }
+        adjustComposite.setVisible(project != null);
+        adjustComposite.getParent().layout();
 
-        IFile filterFile = getFilter(syncLocation);
+        if (importRoot != null) {
+            IFile filterFile = getFilter();
 
-        if (filterFile!=null && filterFile.exists()) {
-            importLabel.setText("Will apply import filter from /" + filterFile.getProjectRelativePath() + ".");
-        } else {
-            importLabel.setText("No filter definition found, will import all resources.");
+            if (filterFile != null && filterFile.exists()) {
+                importLabel.setText("Will apply import filter from /" + filterFile.getProjectRelativePath() + ".");
+            } else {
+                importLabel.setText("No filter definition found, will import all resources.");
+            }
+            importLabel.setVisible(true);
         }
-        importLabel.setVisible(true);
+        importLabel.setVisible(importRoot != null);
         importLabel.getParent().layout();
     }
 
-    private IFile getFilter(IResource syncLocation) {
+    private IFile getFilter() {
 
-        return ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(ProjectUtil.findFilterPath(project));
+        IPath filterPath = ProjectUtil.findFilterPath(project);
+        if (filterPath == null) {
+            return null;
+        }
+        return ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(filterPath);
     }
 
 	/*
@@ -339,11 +358,16 @@ public class ImportWizardPage extends Wi
 			// still under construction
 			return true;
 		}
-        if (project!=null && adjustJcrRootText!=null) {
+        if (adjustJcrRootText != null) {
             adjustJcrRootText();
             adjustJcrRootText.getParent().pack();
         }
 
+        if (project == null || importRoot == null) {
+            setErrorMessage("Please select a location to import to");
+            return false;
+        }
+
         String repositoryError = repositoryCombo.getErrorMessage();
         if (repositoryError != null) {
             setErrorMessage(repositoryError);
@@ -354,6 +378,9 @@ public class ImportWizardPage extends Wi
 	}
 
 	private void adjustJcrRootText() {
-		adjustJcrRootText.setText("Content will be stored under: "+project.getName()+"/"+ProjectUtil.getSyncDirectoryValue(project));
+        if (project != null) {
+            adjustJcrRootText.setText("Content sync root is: " + project.getName() + "/"
+                    + ProjectUtil.getSyncDirectoryValue(project));
+        }
 	}
 }

Modified: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/SlingLaunchpadCombo.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/SlingLaunchpadCombo.java?rev=1595168&r1=1595167&r2=1595168&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/SlingLaunchpadCombo.java (original)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/SlingLaunchpadCombo.java Fri May 16 11:48:05 2014
@@ -34,7 +34,7 @@ import org.eclipse.wst.server.core.Serve
 public class SlingLaunchpadCombo {
 
     private final Combo repositoryCombo;
-    private final IProject project;
+    private IProject project;
 
     public SlingLaunchpadCombo(Composite parent, IProject project) {
         repositoryCombo = new Combo(parent, SWT.DROP_DOWN);
@@ -43,6 +43,10 @@ public class SlingLaunchpadCombo {
         this.project = project;
     }
 
+    public void setProject(IProject project) {
+        this.project = project;
+    }
+
     public Combo getWidget() {
         return repositoryCombo;
     }