Author: rombert Date: Fri Jul 19 21:40:49 2013 New Revision: 1505033 URL: http://svn.apache.org/r1505033 Log: SLING-2973 - [Tooling] Align Eclipse tooling to proposed structure
Obey the location the user selects for the sync directory. Added: sling/whiteboard/asanso/plugins/eclipse/eclipse-core/src/org/apache/sling/ide/eclipse/core/ProjectUtil.java (with props) Removed: sling/whiteboard/asanso/plugins/eclipse/eclipse-core/src/org/apache/sling/ide/eclipse/core/SlingclipseHelper.java Modified: sling/whiteboard/asanso/plugins/eclipse/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingContentModuleFactory.java sling/whiteboard/asanso/plugins/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportWizardPage.java sling/whiteboard/asanso/plugins/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/SlingProjectPropertyPage.java Added: sling/whiteboard/asanso/plugins/eclipse/eclipse-core/src/org/apache/sling/ide/eclipse/core/ProjectUtil.java URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/eclipse-core/src/org/apache/sling/ide/eclipse/core/ProjectUtil.java?rev=1505033&view=auto ============================================================================== --- sling/whiteboard/asanso/plugins/eclipse/eclipse-core/src/org/apache/sling/ide/eclipse/core/ProjectUtil.java (added) +++ sling/whiteboard/asanso/plugins/eclipse/eclipse-core/src/org/apache/sling/ide/eclipse/core/ProjectUtil.java Fri Jul 19 21:40:49 2013 @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.sling.ide.eclipse.core; + +import org.apache.sling.ide.eclipse.core.internal.Activator; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.QualifiedName; +import org.eclipse.core.runtime.Status; + +public abstract class ProjectUtil { + + private static final String PROPERTY_SYNC_ROOT = "sync_root"; + private static final String PROPERTY_SYNC_ROOT_DEFAULT_VALUE = "jcr_root"; + + /** + * Returns the value of the sync directory configured for a project. + * + * <p> + * The value is returned as a relative path to the project's location. If the property value is not set, it defaults + * to {@value #PROPERTY_SYNC_ROOT_DEFAULT_VALUE}. + * </p> + * + * @param project the project, must not be null + * @return the value of the sync directory + */ + public static String getSyncDirectoryValue(IProject project) { + String value = null; + try { + value = project.getPersistentProperty(new QualifiedName(Activator.PLUGIN_ID, PROPERTY_SYNC_ROOT)); + } catch (CoreException e) { + Activator.getDefault().getLog().log(new Status(Status.ERROR, Activator.PLUGIN_ID, e.getMessage(), e)); + } + + // TODO central place for defaults + if (value == null) + value = PROPERTY_SYNC_ROOT_DEFAULT_VALUE; + + return value; + } + + public static IPath getSyncDirectoryFullPath(IProject project) { + + return project.getFolder(getSyncDirectoryValue(project)).getFullPath(); + } + + /** + * Sets the value of the sync directory configured for a project + * + * <p> + * The value must be a path relative to the project's location. + * </p> + * + * @param project the project, must not be null + * @param path the value + */ + public static void setSyncDirectoryPath(IProject project, String path) { + + try { + project.setPersistentProperty(new QualifiedName(Activator.PLUGIN_ID, PROPERTY_SYNC_ROOT), path); + } catch (CoreException e) { + Activator.getDefault().getLog().log(new Status(Status.ERROR, Activator.PLUGIN_ID, e.getMessage(), e)); + } + } + + private ProjectUtil() { + + } +} Propchange: sling/whiteboard/asanso/plugins/eclipse/eclipse-core/src/org/apache/sling/ide/eclipse/core/ProjectUtil.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: sling/whiteboard/asanso/plugins/eclipse/eclipse-core/src/org/apache/sling/ide/eclipse/core/ProjectUtil.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Rev URL Modified: sling/whiteboard/asanso/plugins/eclipse/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingContentModuleFactory.java URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingContentModuleFactory.java?rev=1505033&r1=1505032&r2=1505033&view=diff ============================================================================== --- sling/whiteboard/asanso/plugins/eclipse/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingContentModuleFactory.java (original) +++ sling/whiteboard/asanso/plugins/eclipse/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingContentModuleFactory.java Fri Jul 19 21:40:49 2013 @@ -3,7 +3,7 @@ package org.apache.sling.ide.eclipse.cor import java.util.ArrayList; import java.util.List; -import org.apache.sling.ide.eclipse.core.SlingclipseHelper; +import org.apache.sling.ide.eclipse.core.ProjectUtil; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; @@ -71,6 +71,12 @@ public class SlingContentModuleFactory e public IModuleResource[] members() throws CoreException { IProject project = module.getProject(); final List<IModuleResource> resources = new ArrayList<IModuleResource>(); + final IFolder syncFolder = project.getFolder(ProjectUtil.getSyncDirectoryValue(project)); + + if (!syncFolder.exists()) { + return new IModuleResource[0]; + } + project.accept(new IResourceVisitor() { @Override public boolean visit(IResource resource) throws CoreException { @@ -81,13 +87,18 @@ public class SlingContentModuleFactory e IPath relativePath = resource.getProjectRelativePath(); - // only recurse in the expected content path - // TODO make configurable - if (!SlingclipseHelper.JCR_ROOT.equals(relativePath.segment(0))) { + if (relativePath.isPrefixOf(syncFolder.getProjectRelativePath())) { + // parent directory of our sync location, don't process but recurse + return true; + } + + // urelated resource tree, stop processing + if (!syncFolder.getProjectRelativePath().isPrefixOf(relativePath)) { return false; } - IPath modulePath = relativePath.removeFirstSegments(1); // remove jcr_root + IPath modulePath = relativePath.removeFirstSegments(syncFolder.getProjectRelativePath() + .segmentCount()); // remove sync dir IModuleResource moduleFile = null; Modified: sling/whiteboard/asanso/plugins/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportWizardPage.java URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportWizardPage.java?rev=1505033&r1=1505032&r2=1505033&view=diff ============================================================================== --- sling/whiteboard/asanso/plugins/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportWizardPage.java (original) +++ sling/whiteboard/asanso/plugins/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportWizardPage.java Fri Jul 19 21:40:49 2013 @@ -19,7 +19,8 @@ package org.apache.sling.ide.eclipse.ui. import java.util.List; -import org.apache.sling.ide.eclipse.core.SlingclipseHelper; +import org.apache.sling.ide.eclipse.core.ProjectUtil; +import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.NullProgressMonitor; @@ -72,8 +73,8 @@ public class ImportWizardPage extends Wi setTitle(pageName); // NON-NLS-1 setDescription("Import content from a Sling Repository into the workspace"); // NON-NLS-1 - setContainerFieldValue(getProject(selection).getFullPath() - .append(SlingclipseHelper.JCR_ROOT).toOSString()); + IProject project = getProject(selection); + setContainerFieldValue(project.getFullPath().append(ProjectUtil.getSyncDirectoryValue(project)).toOSString()); } private IProject getProject(IStructuredSelection selection) { @@ -194,8 +195,13 @@ public class ImportWizardPage extends Wi return false; } - if (!getResourcePath().toOSString().endsWith(SlingclipseHelper.JCR_ROOT)) { - setErrorMessage("Please enter a valid Sling project folder (e.g. jcr_root)"); + IProject project = getProject(selection); + 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; } Modified: sling/whiteboard/asanso/plugins/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/SlingProjectPropertyPage.java URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/SlingProjectPropertyPage.java?rev=1505033&r1=1505032&r2=1505033&view=diff ============================================================================== --- sling/whiteboard/asanso/plugins/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/SlingProjectPropertyPage.java (original) +++ sling/whiteboard/asanso/plugins/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/SlingProjectPropertyPage.java Fri Jul 19 21:40:49 2013 @@ -1,10 +1,9 @@ package org.apache.sling.ide.eclipse.ui.internal; +import org.apache.sling.ide.eclipse.core.ProjectUtil; 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.QualifiedName; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; @@ -24,7 +23,7 @@ import org.eclipse.ui.dialogs.PropertyPa public class SlingProjectPropertyPage extends PropertyPage { - private static final String PROPERTY_SYNC_ROOT = "sync_root"; + private Text folderText; @Override @@ -37,7 +36,7 @@ public class SlingProjectPropertyPage ex new Label(c, SWT.NONE).setText("Folder to sync"); folderText = new Text(c, SWT.BORDER); folderText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); - folderText.setText(getValueWithDefault()); + folderText.setText(ProjectUtil.getSyncDirectoryValue(getProject())); folderText.addModifyListener(new ModifyListener() { @@ -90,21 +89,6 @@ public class SlingProjectPropertyPage ex return c; } - private String getValueWithDefault() { - - String value = null; - try { - value = getProject().getPersistentProperty(new QualifiedName(Constants.PLUGIN_ID, PROPERTY_SYNC_ROOT)); - } catch (CoreException e) { - // TODO error handling - } - - // TODO central place for defaults - if (value == null) - value = "jcr_root"; - return value; - } - @Override public boolean isValid() { @@ -119,19 +103,15 @@ public class SlingProjectPropertyPage ex return false; } + setErrorMessage(null); + return true; } @Override public boolean performOk() { - IProject project = getProject(); - - try { - project.setPersistentProperty(new QualifiedName(Constants.PLUGIN_ID, PROPERTY_SYNC_ROOT), folderText.getText()); - } catch (CoreException e) { - setErrorMessage(e.getMessage()); - } + ProjectUtil.setSyncDirectoryPath(getProject(), folderText.getText()); return super.performOk(); }