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/22 22:57:29 UTC
svn commit: r1505811 - in /sling/whiteboard/asanso/plugins/eclipse:
api/META-INF/ api/src/org/apache/sling/ide/util/ eclipse-ui/META-INF/
eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/
impl-resource/src/org/apache/sling/ide/impl/resource/tran...
Author: rombert
Date: Mon Jul 22 20:57:28 2013
New Revision: 1505811
URL: http://svn.apache.org/r1505811
Log:
SLING-2973 - [Tooling] Align Eclipse tooling to proposed structure
The ImportWizard now uses filters when importing content.
Added:
sling/whiteboard/asanso/plugins/eclipse/api/src/org/apache/sling/ide/util/
sling/whiteboard/asanso/plugins/eclipse/api/src/org/apache/sling/ide/util/PathUtil.java (with props)
Modified:
sling/whiteboard/asanso/plugins/eclipse/api/META-INF/MANIFEST.MF
sling/whiteboard/asanso/plugins/eclipse/eclipse-ui/META-INF/MANIFEST.MF
sling/whiteboard/asanso/plugins/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/Activator.java
sling/whiteboard/asanso/plugins/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportWizard.java
sling/whiteboard/asanso/plugins/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportWizardPage.java
sling/whiteboard/asanso/plugins/eclipse/impl-resource/src/org/apache/sling/ide/impl/resource/transport/RepositoryImpl.java
Modified: sling/whiteboard/asanso/plugins/eclipse/api/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/api/META-INF/MANIFEST.MF?rev=1505811&r1=1505810&r2=1505811&view=diff
==============================================================================
--- sling/whiteboard/asanso/plugins/eclipse/api/META-INF/MANIFEST.MF (original)
+++ sling/whiteboard/asanso/plugins/eclipse/api/META-INF/MANIFEST.MF Mon Jul 22 20:57:28 2013
@@ -7,6 +7,7 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
-Export-Package: org.apache.sling.ide.serialization,
+Export-Package: org.apache.sling.ide.filter,
+ org.apache.sling.ide.serialization,
org.apache.sling.ide.transport,
- org.apache.sling.ide.filter
+ org.apache.sling.ide.util
Added: sling/whiteboard/asanso/plugins/eclipse/api/src/org/apache/sling/ide/util/PathUtil.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/api/src/org/apache/sling/ide/util/PathUtil.java?rev=1505811&view=auto
==============================================================================
--- sling/whiteboard/asanso/plugins/eclipse/api/src/org/apache/sling/ide/util/PathUtil.java (added)
+++ sling/whiteboard/asanso/plugins/eclipse/api/src/org/apache/sling/ide/util/PathUtil.java Mon Jul 22 20:57:28 2013
@@ -0,0 +1,35 @@
+/*
+ * 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.util;
+
+public class PathUtil {
+
+ public static String join(String first, String second) {
+
+ boolean repoUrlHasTrailingSlash = first.endsWith("/");
+ boolean relativePathHasLeadingSlash = !second.isEmpty() && second.charAt(0) == '/';
+
+ if (repoUrlHasTrailingSlash ^ relativePathHasLeadingSlash)
+ return first + second;
+ if (!repoUrlHasTrailingSlash && !relativePathHasLeadingSlash)
+ return first + '/' + second;
+ if (repoUrlHasTrailingSlash && relativePathHasLeadingSlash)
+ return first + second.substring(1);
+
+ throw new AssertionError("unreachable");
+ }
+}
Propchange: sling/whiteboard/asanso/plugins/eclipse/api/src/org/apache/sling/ide/util/PathUtil.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/whiteboard/asanso/plugins/eclipse/api/src/org/apache/sling/ide/util/PathUtil.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Modified: sling/whiteboard/asanso/plugins/eclipse/eclipse-ui/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/eclipse-ui/META-INF/MANIFEST.MF?rev=1505811&r1=1505810&r2=1505811&view=diff
==============================================================================
--- sling/whiteboard/asanso/plugins/eclipse/eclipse-ui/META-INF/MANIFEST.MF (original)
+++ sling/whiteboard/asanso/plugins/eclipse/eclipse-ui/META-INF/MANIFEST.MF Mon Jul 22 20:57:28 2013
@@ -7,8 +7,10 @@ Bundle-Version: 0.0.1.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ClassPath: .
Import-Package: org.apache.sling.ide.eclipse.core,
+ org.apache.sling.ide.filter,
org.apache.sling.ide.serialization,
org.apache.sling.ide.transport,
+ org.apache.sling.ide.util,
org.eclipse.core.commands,
org.eclipse.core.commands.operations,
org.eclipse.core.resources,
Modified: sling/whiteboard/asanso/plugins/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/Activator.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/Activator.java?rev=1505811&r1=1505810&r2=1505811&view=diff
==============================================================================
--- sling/whiteboard/asanso/plugins/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/Activator.java (original)
+++ sling/whiteboard/asanso/plugins/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/Activator.java Mon Jul 22 20:57:28 2013
@@ -17,6 +17,7 @@
package org.apache.sling.ide.eclipse.ui.internal;
import org.apache.sling.ide.eclipse.core.ServiceUtil;
+import org.apache.sling.ide.filter.FilterLocator;
import org.apache.sling.ide.serialization.SerializationManager;
import org.eclipse.core.runtime.Plugin;
import org.osgi.framework.BundleContext;
@@ -28,6 +29,7 @@ public class Activator extends Plugin {
public static Activator INSTANCE;
private ServiceTracker<SerializationManager, SerializationManager> serializationManager;
+ private ServiceTracker<FilterLocator, FilterLocator> filterLocator;
public static Activator getDefault() {
@@ -42,6 +44,9 @@ public class Activator extends Plugin {
SerializationManager.class, null);
serializationManager.open();
+ filterLocator = new ServiceTracker<FilterLocator, FilterLocator>(context, FilterLocator.class, null);
+ filterLocator.open();
+
INSTANCE = this;
}
@@ -49,6 +54,7 @@ public class Activator extends Plugin {
public void stop(BundleContext context) throws Exception {
INSTANCE = null;
serializationManager.close();
+ filterLocator.close();
super.stop(context);
}
@@ -56,4 +62,8 @@ public class Activator extends Plugin {
public SerializationManager getSerializationManager() {
return ServiceUtil.getNotNull(serializationManager);
}
+
+ public FilterLocator getFilterLocator() {
+ return ServiceUtil.getNotNull(filterLocator);
+ }
}
Modified: sling/whiteboard/asanso/plugins/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportWizard.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportWizard.java?rev=1505811&r1=1505810&r2=1505811&view=diff
==============================================================================
--- sling/whiteboard/asanso/plugins/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportWizard.java (original)
+++ sling/whiteboard/asanso/plugins/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportWizard.java Mon Jul 22 20:57:28 2013
@@ -17,18 +17,24 @@
package org.apache.sling.ide.eclipse.ui.internal;
import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.nio.charset.Charset;
import java.util.Iterator;
import org.apache.sling.ide.eclipse.core.ISlingLaunchpadServer;
import org.apache.sling.ide.eclipse.core.ServerUtil;
+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.SerializationManager;
import org.apache.sling.ide.transport.Command;
import org.apache.sling.ide.transport.Repository;
import org.apache.sling.ide.transport.RepositoryException;
import org.apache.sling.ide.transport.ResponseType;
import org.apache.sling.ide.transport.Result;
+import org.apache.sling.ide.util.PathUtil;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
@@ -74,16 +80,15 @@ public class ImportWizard extends Wizard
if (!mainPage.isPageComplete()) {
return false;
}
-
- 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);
- final String repositoryPath = mainPage.getRepositoryPath();
-
+ 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);
+ final String repositoryPath = mainPage.getRepositoryPath();
+ final IFile filterFile = mainPage.getFilterFile();
try {
getContainer().run(false, true, new IRunnableWithProgress() {
@@ -92,7 +97,6 @@ public class ImportWizard extends Wizard
Repository repository = ServerUtil.getRepository(server, monitor);
monitor.setTaskName("Loading configuration...");
- monitor.worked(5);
ISlingLaunchpadServer launchpad = (ISlingLaunchpadServer) server.loadAdapter(
ISlingLaunchpadServer.class, monitor);
@@ -104,6 +108,29 @@ public class ImportWizard extends Wizard
launchpad.setPublishState(ISlingLaunchpadServer.PUBLISH_STATE_NEVER);
}
+ Filter filter = null;
+ if (filterFile != null) {
+ FilterLocator filterLocator = Activator.getDefault().getFilterLocator();
+ InputStream contents = null;
+ try {
+ contents = filterFile.getContents();
+ filter = filterLocator.loadFilter(contents);
+ } catch (IOException e) {
+ throw new InvocationTargetException(e);
+ } catch (CoreException e) {
+ throw new InvocationTargetException(e);
+ } finally {
+ if (contents != null) {
+ try {
+ contents.close();
+ } catch (IOException e) {
+ // don't care
+ }
+ }
+ }
+ }
+ monitor.worked(5);
+
try {
// TODO: We should try to make this give 'nice' progress feedback (aka here's what I'm
@@ -114,7 +141,7 @@ public class ImportWizard extends Wizard
// we create the root node and assume this is a folder
createRoot(project, projectRelativePath, repositoryPath);
- crawlChildrenAndImport(repository, repositoryPath, project, projectRelativePath);
+ crawlChildrenAndImport(repository, filter, repositoryPath, project, projectRelativePath);
monitor.setTaskName("Import Complete");
monitor.worked(100);
@@ -178,20 +205,22 @@ public class ImportWizard extends Wizard
createFolder(project, rootImportPath.removeLastSegments(i));
}
- /**
- * Crawls the repository and recursively imports founds resources
- *
- * @param repository the sling repository to import from
- * @param path the current path to import from
- * @param project the project to create resources in
- * @param projectRelativePath the path, relative to the project root, where the resources should be created
- * @param tracer
- * @throws JSONException
- * @throws RepositoryException
- * @throws CoreException
- */
+ /**
+ * Crawls the repository and recursively imports founds resources
+ *
+ * @param repository the sling repository to import from
+ * @param filter
+ * @param path the current path to import from
+ * @param project the project to create resources in
+ * @param projectRelativePath the path, relative to the project root, where the resources should be created
+ * @param tracer
+ * @throws JSONException
+ * @throws RepositoryException
+ * @throws CoreException
+ */
// TODO: This probably should be pushed into the service layer
- private void crawlChildrenAndImport(Repository repository, String path, IProject project, IPath projectRelativePath)
+ private void crawlChildrenAndImport(Repository repository, Filter filter, String path, IProject project,
+ IPath projectRelativePath)
throws JSONException, RepositoryException, CoreException {
System.out.println("crawlChildrenAndImport(" + repository + ", " + path + ", " + project + ", "
@@ -211,16 +240,23 @@ public class ImportWizard extends Wizard
createFolder(project, projectRelativePath.append(path));
String content = executeCommand(repository.newGetNodeContentCommand(path, ResponseType.JSON));
JSONObject jsonContent = new JSONObject(content);
- String contentXml = JSONML.toString(jsonContent);
+ jsonContent.put("tagName", Repository.JCR_ROOT); // TODO this is required by JSONML, not sure why
+ String contentXml = JSONML.toString(jsonContent);
createFile(project, projectRelativePath.append(serializationManager.getSerializationFilePath(path)),
contentXml.getBytes(Charset.forName("UTF-8") /* TODO is this enough? */));
}
for (Iterator<?> keys = json.keys(); keys.hasNext();) {
String key = (String) keys.next();
+ if (filter != null) {
+ FilterResult filterResult = filter.filter(key);
+ if (filterResult == FilterResult.DENY) {
+ continue;
+ }
+ }
JSONObject innerjson=json.optJSONObject(key);
if (innerjson!=null){
- crawlChildrenAndImport(repository, path + "/" + key, project, projectRelativePath);
+ crawlChildrenAndImport(repository, filter, PathUtil.join(path, key), project, projectRelativePath);
}
}
}
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=1505811&r1=1505810&r2=1505811&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 Mon Jul 22 20:57:28 2013
@@ -17,13 +17,19 @@
package org.apache.sling.ide.eclipse.ui.internal;
+import java.io.File;
import java.util.List;
import org.apache.sling.ide.eclipse.core.ProjectUtil;
+import org.apache.sling.ide.filter.FilterLocator;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.swt.SWT;
@@ -55,6 +61,7 @@ public class ImportWizardPage extends Wi
}
};
private Combo repositoryCombo;
+ private Label importLabel;
/**
* Creates an import wizard page for importing from a Sling Repository. If
@@ -95,6 +102,14 @@ public class ImportWizardPage extends Wi
@Override
protected void createOptionsGroup(Composite parent) {
+ // not really options but to placement is good enough
+ Composite container = new Composite(parent, SWT.NONE);
+ container.setLayout(new GridLayout());
+ GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
+ container.setLayoutData(gridData);
+
+ importLabel = new Label(container, SWT.NONE);
+
}
@Override
@@ -208,6 +223,53 @@ public class ImportWizardPage extends Wi
return true;
}
+ @Override
+ protected void updateWidgetEnablements() {
+ super.updateWidgetEnablements();
+
+ // called too early
+ if (importLabel == null) {
+ return;
+ }
+
+ IResource syncLocation = getProject(selection).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;
+ }
+
+ IFile filterFile = getFilter(syncLocation);
+
+ if (filterFile.exists()) {
+ importLabel.setText("Will apply import filter from /" + filterFile.getProjectRelativePath() + ".");
+ } else {
+ importLabel.setText("No filter found at /" + filterFile.getProjectRelativePath()
+ + ", will import all resources.");
+ }
+ importLabel.setVisible(true);
+ importLabel.getParent().layout();
+ }
+
+ public IFile getFilterFile() {
+
+ IResource syncLocation = getProject(selection).getWorkspace().getRoot().findMember(getResourcePath());
+ if (syncLocation == null) {
+ return null;
+ }
+
+ return getFilter(syncLocation);
+ }
+
+ private IFile getFilter(IResource syncLocation) {
+
+ FilterLocator filterLocator = Activator.getDefault().getFilterLocator();
+ File filterLocation = filterLocator.findFilterLocation(syncLocation.getLocation().toFile());
+ IPath filterPath = Path.fromOSString(filterLocation.getAbsolutePath());
+ return ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(filterPath);
+ }
+
/*
* (non-Javadoc)
*
Modified: sling/whiteboard/asanso/plugins/eclipse/impl-resource/src/org/apache/sling/ide/impl/resource/transport/RepositoryImpl.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/impl-resource/src/org/apache/sling/ide/impl/resource/transport/RepositoryImpl.java?rev=1505811&r1=1505810&r2=1505811&view=diff
==============================================================================
--- sling/whiteboard/asanso/plugins/eclipse/impl-resource/src/org/apache/sling/ide/impl/resource/transport/RepositoryImpl.java (original)
+++ sling/whiteboard/asanso/plugins/eclipse/impl-resource/src/org/apache/sling/ide/impl/resource/transport/RepositoryImpl.java Mon Jul 22 20:57:28 2013
@@ -35,6 +35,7 @@ import org.apache.sling.ide.transport.Fi
import org.apache.sling.ide.transport.RepositoryException;
import org.apache.sling.ide.transport.ResponseType;
import org.apache.sling.ide.transport.Result;
+import org.apache.sling.ide.util.PathUtil;
public class RepositoryImpl extends AbstractRepository{
@@ -202,17 +203,7 @@ public class RepositoryImpl extends Abst
private String createFullPath(String relativePath) {
- boolean repoUrlHasTrailingSlash = repositoryInfo.getUrl().endsWith("/");
- boolean relativePathHasLeadingSlash = !relativePath.isEmpty() && relativePath.charAt(0) == '/';
-
- if (repoUrlHasTrailingSlash ^ relativePathHasLeadingSlash)
- return repositoryInfo.getUrl() + relativePath;
- if (!repoUrlHasTrailingSlash && !relativePathHasLeadingSlash)
- return repositoryInfo.getUrl() + '/' + relativePath;
- if (repoUrlHasTrailingSlash && relativePathHasLeadingSlash)
- return repositoryInfo.getUrl() + relativePath.substring(1);
-
- throw new AssertionError("unreachable");
+ return PathUtil.join(repositoryInfo.getUrl(), relativePath);
}
@Override