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/15 14:24:21 UTC
svn commit: r1594890 - in /sling/trunk/tooling/ide:
eclipse-core/src/org/apache/sling/ide/eclipse/core/
eclipse-test/src/org/apache/sling/ide/test/impl/
eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/
Author: rombert
Date: Thu May 15 12:24:20 2014
New Revision: 1594890
URL: http://svn.apache.org/r1594890
Log:
SLING-2651 - Manually trigger sync on files/directories
Move more filter finding/loading related logic to FilterUtil and reuse
this in other places.
Added:
sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/ProjectUtilTest.java (with props)
Modified:
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/ProjectUtil.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
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=1594890&r1=1594889&r2=1594890&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 Thu May 15 12:24:20 2014
@@ -116,15 +116,22 @@ public abstract class ProjectUtil {
}
}
+ /**
+ * Loads a filter for the specified project
+ *
+ * @param project the project to find a filter for
+ * @return the found filter or null
+ * @throws CoreException
+ */
public static Filter loadFilter(final IProject project) throws CoreException {
- IFolder syncFolder = ProjectUtil.getSyncDirectory(project);
FilterLocator filterLocator = Activator.getDefault().getFilterLocator();
- File filterLocation = filterLocator.findFilterLocation(syncFolder.getLocation().toFile());
- if (filterLocation == null) {
+
+ IPath filterPath = findFilterPath(project);
+ if (filterPath == null) {
return null;
}
- IPath filterPath = Path.fromOSString(filterLocation.getAbsolutePath());
+
IFile filterFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(filterPath);
Filter filter = null;
if (filterFile != null && filterFile.exists()) {
@@ -133,7 +140,7 @@ public abstract class ProjectUtil {
filter = filterLocator.loadFilter(contents);
} catch (IOException e) {
throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
- "Failed loading filter file for project " + syncFolder.getProject().getName()
+ "Failed loading filter file for project " + project.getName()
+ " from location " + filterFile, e));
} finally {
IOUtils.closeQuietly(contents);
@@ -142,6 +149,24 @@ public abstract class ProjectUtil {
return filter;
}
+ /**
+ * Finds the path to a filter defined for the project
+ *
+ * @param project the project
+ * @return the path to the filter defined in the project, or null if no filter is found
+ */
+ public static IPath findFilterPath(final IProject project) {
+
+ FilterLocator filterLocator = Activator.getDefault().getFilterLocator();
+
+ IFolder syncFolder = ProjectUtil.getSyncDirectory(project);
+ File filterLocation = filterLocator.findFilterLocation(syncFolder.getLocation().toFile());
+ if (filterLocation == null) {
+ return null;
+ }
+ return Path.fromOSString(filterLocation.getAbsolutePath());
+ }
+
private ProjectUtil() {
Added: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/ProjectUtilTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/ProjectUtilTest.java?rev=1594890&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/ProjectUtilTest.java (added)
+++ sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/ProjectUtilTest.java Thu May 15 12:24:20 2014
@@ -0,0 +1,64 @@
+/*
+ * 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.test.impl;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+import java.io.ByteArrayInputStream;
+
+import org.apache.sling.ide.eclipse.core.ProjectUtil;
+import org.apache.sling.ide.test.impl.helpers.ProjectAdapter;
+import org.apache.sling.ide.test.impl.helpers.TemporaryProject;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.junit.Rule;
+import org.junit.Test;
+
+public class ProjectUtilTest {
+
+ @Rule
+ public TemporaryProject projectRule = new TemporaryProject();
+
+ @Test
+ public void slingContentProjectSyncedResourcesAreExportable() throws CoreException, InterruptedException {
+
+ // create faceted project
+ IProject contentProject = projectRule.getProject();
+
+ ProjectAdapter project = new ProjectAdapter(contentProject);
+ project.addNatures("org.eclipse.wst.common.project.facet.core.nature");
+
+ // install bundle facet
+ project.installFacet("sling.content", "1.0");
+
+ project.createOrUpdateFile(Path.fromPortableString("jcr_root/test/hello.txt"), new ByteArrayInputStream(
+ "goodbye, world".getBytes()));
+
+ project.createOrUpdateFile(Path.fromPortableString("META-INF/vault/filter.xml"), new ByteArrayInputStream(
+ "<workspaceFilter version=\"1.0\"/>".getBytes()));
+
+ IPath filterPath = ProjectUtil.findFilterPath(contentProject);
+ assertThat("filterPath.absolute", filterPath.isAbsolute(), equalTo(true));
+
+ assertThat("filterPath", filterPath.makeRelativeTo(contentProject.getLocation()).toPortableString(),
+ equalTo("META-INF/vault/filter.xml"));
+
+ }
+}
Propchange: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/ProjectUtilTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/ProjectUtilTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
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=1594890&r1=1594889&r2=1594890&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 Thu May 15 12:24:20 2014
@@ -58,7 +58,6 @@ import org.eclipse.wst.server.core.IServ
public class ImportRepositoryContentAction {
private final IServer server;
- private final IFile filterFile;
private final IPath projectRelativePath;
private final IProject project;
private final PluginLogger logger;
@@ -68,22 +67,21 @@ public class ImportRepositoryContentActi
/**
* @param server
- * @param filterFile
* @param projectRelativePath
* @param project
* @throws SerializationException
*/
- public ImportRepositoryContentAction(IServer server, IFile filterFile, IPath projectRelativePath,
- IProject project, SerializationManager serializationManager) throws SerializationException {
+ public ImportRepositoryContentAction(IServer server, IPath projectRelativePath, IProject project,
+ SerializationManager serializationManager) throws SerializationException {
this.logger = Activator.getDefault().getPluginLogger();
this.server = server;
- this.filterFile = filterFile;
this.projectRelativePath = projectRelativePath;
this.project = project;
this.serializationManager = serializationManager;
}
- public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException, SerializationException {
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException,
+ SerializationException, CoreException {
Repository repository;
try {
repository = ServerUtil.getRepository(server, monitor);
@@ -115,29 +113,7 @@ public class ImportRepositoryContentActi
throw new InvocationTargetException(e1);
}
- Filter filter = null;
-
- FilterLocator filterLocator = Activator.getDefault().getFilterLocator();
- InputStream contents = null;
-
- if (filterFile != null && filterFile.exists()) {
- try {
- contents = filterFile.getContents();
- filter = filterLocator.loadFilter(contents);
- } catch (CoreException e) {
- throw new InvocationTargetException(e);
- } catch (IOException e) {
- throw new InvocationTargetException(e);
- } finally {
- if (contents != null) {
- try {
- contents.close();
- } catch (IOException e) {
- // don't care
- }
- }
- }
- }
+ Filter filter = ProjectUtil.loadFilter(project);
monitor.worked(5);
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=1594890&r1=1594889&r2=1594890&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 Thu May 15 12:24:20 2014
@@ -20,12 +20,11 @@ import java.lang.reflect.InvocationTarge
import org.apache.sling.ide.serialization.SerializationException;
import org.apache.sling.ide.serialization.SerializationManager;
-import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.Status;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
@@ -68,16 +67,16 @@ public class ImportWizard extends Wizard
final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(destinationPath.segments()[0]);
final IPath projectRelativePath = destinationPath.removeFirstSegments(1);
- final IFile filterFile = mainPage.getFilterFile();
IRunnableWithProgress runnable = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
- new ImportRepositoryContentAction(server, filterFile, projectRelativePath, project,
- serializationManager).run(monitor);
+ new ImportRepositoryContentAction(server, projectRelativePath, project, serializationManager).run(monitor);
} catch (SerializationException e) {
throw new InvocationTargetException(e);
+ } catch (CoreException e) {
+ throw new InvocationTargetException(e);
} finally {
serializationManager.destroy();
}
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=1594890&r1=1594889&r2=1594890&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 Thu May 15 12:24:20 2014
@@ -16,10 +16,8 @@
*/
package org.apache.sling.ide.eclipse.ui.internal;
-import java.io.File;
import org.apache.sling.ide.eclipse.core.ProjectUtil;
-import org.apache.sling.ide.filter.FilterLocator;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
@@ -29,7 +27,6 @@ import org.eclipse.core.resources.IWorks
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.preference.PreferenceDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.SWT;
@@ -85,8 +82,7 @@ public class ImportWizardPage extends Wi
}
IPath getResourcePath() {
- String resourcePath = project.getFullPath().append(ProjectUtil.getSyncDirectoryValue(project)).toOSString();
- return new Path(resourcePath);
+ return ProjectUtil.getSyncDirectory(project).getFullPath();
}
/*
@@ -327,25 +323,9 @@ public class ImportWizardPage extends Wi
importLabel.getParent().layout();
}
- public IFile getFilterFile() {
-
- IResource syncLocation = project.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());
- if (filterLocation == null) {
- return null;
- }
- IPath filterPath = Path.fromOSString(filterLocation.getAbsolutePath());
- return ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(filterPath);
+ return ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(ProjectUtil.findFilterPath(project));
}
/*