Author: kwin
Date: Thu Dec 29 16:02:21 2016
New Revision: 1776444
URL: http://svn.apache.org/viewvc?rev=1776444&view=rev
Log:
SLING-6344 disable syncing if no filter.xml can be found
simplify FilterLocator service
Modified:
sling/trunk/tooling/ide/api/META-INF/MANIFEST.MF
sling/trunk/tooling/ide/api/src/org/apache/sling/ide/filter/FilterLocator.java
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/ProjectUtil.java
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/ResourceChangeCommandFactory.java
sling/trunk/tooling/ide/impl-resource/META-INF/MANIFEST.MF
sling/trunk/tooling/ide/impl-resource/src/org/apache/sling/ide/impl/resource/filer/SimpleFilterLocator.java
sling/trunk/tooling/ide/impl-vlt/META-INF/MANIFEST.MF
sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/filter/VltFilterLocator.java
Modified: sling/trunk/tooling/ide/api/META-INF/MANIFEST.MF
URL:
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/api/META-INF/MANIFEST.MF?rev=1776444&r1=1776443&r2=1776444&view=diff
==============================================================================
--- sling/trunk/tooling/ide/api/META-INF/MANIFEST.MF (original)
+++ sling/trunk/tooling/ide/api/META-INF/MANIFEST.MF Thu Dec 29 16:02:21 2016
@@ -18,6 +18,8 @@ Import-Package: javax.jcr.nodetype,
org.apache.commons.httpclient.methods.multipart;version="3.1.0",
org.apache.commons.httpclient.params;version="3.1.0",
org.apache.commons.io;version="2.0.1",
+ org.eclipse.core.resources,
+ org.eclipse.jdt.annotation,
org.json,
org.osgi.framework;version="1.6.0",
org.osgi.service.event
Modified:
sling/trunk/tooling/ide/api/src/org/apache/sling/ide/filter/FilterLocator.java
URL:
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/api/src/org/apache/sling/ide/filter/FilterLocator.java?rev=1776444&r1=1776443&r2=1776444&view=diff
==============================================================================
---
sling/trunk/tooling/ide/api/src/org/apache/sling/ide/filter/FilterLocator.java
(original)
+++
sling/trunk/tooling/ide/api/src/org/apache/sling/ide/filter/FilterLocator.java
Thu Dec 29 16:02:21 2016
@@ -16,25 +16,19 @@
*/
package org.apache.sling.ide.filter;
-import java.io.File;
import java.io.IOException;
-import java.io.InputStream;
-public interface FilterLocator {
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jdt.annotation.NonNull;
- // TODO - should be File[] to allow multiple lookups, see {filter-vlt.xml,
filter.xml}
- File findFilterLocation(File syncDirectory);
+public interface FilterLocator {
/**
- * Loads a filter based on the raw <tt>filterFileContents</tt>
- *
- * <p>
- * If the <tt>filterFileContents</tt> is null it returns a default filter
- * </p>
+ * Loads a filter for the given project (which determines which parts of
the repository should be overwritten)
*
- * @param filterFileContents the raw contents of the filter file, possibly
null
- * @return
- * @throws IOException
+ * @param IProject the Eclipse project from which to retrieve the filter
+ * @return the filter
+ * @throws IOException, IllegalStateException in case the filter could not
be retrieved from the project
*/
- Filter loadFilter(InputStream filterFileContents) throws IOException;
+ @NonNull Filter loadFilter(@NonNull IProject project) throws IOException,
IllegalStateException;
}
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=1776444&r1=1776443&r2=1776444&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 Dec 29 16:02:21 2016
@@ -160,57 +160,6 @@ 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 {
-
- FilterLocator filterLocator =
Activator.getDefault().getFilterLocator();
-
- IPath filterPath = findFilterPath(project);
- if (filterPath == null) {
- return null;
- }
-
- IFile filterFile =
ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(filterPath);
- Filter filter = null;
- if (filterFile != null && filterFile.exists()) {
- try ( InputStream contents = filterFile.getContents() ) {
- filter = filterLocator.loadFilter(contents);
- } catch (IOException e) {
- throw new CoreException(new Status(IStatus.ERROR,
Activator.PLUGIN_ID,
- "Failed loading filter file for project " +
project.getName()
- + " from location " + filterFile, e));
- }
- }
- 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);
- if (syncFolder == null) {
- return null;
- }
- File filterLocation =
filterLocator.findFilterLocation(syncFolder.getLocation().toFile());
- if (filterLocation == null) {
- return null;
- }
- return Path.fromOSString(filterLocation.getAbsolutePath());
- }
/**
* Verifies if a resource is inside the content sync root for its defined
project
Modified:
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/ResourceChangeCommandFactory.java
URL:
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/ResourceChangeCommandFactory.java?rev=1776444&r1=1776443&r2=1776444&view=diff
==============================================================================
---
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/ResourceChangeCommandFactory.java
(original)
+++
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/ResourceChangeCommandFactory.java
Thu Dec 29 16:02:21 2016
@@ -31,6 +31,7 @@ import java.util.Set;
import org.apache.sling.ide.eclipse.core.ProjectUtil;
import org.apache.sling.ide.eclipse.core.ResourceUtil;
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.log.Logger;
import org.apache.sling.ide.serialization.SerializationDataBuilder;
@@ -93,7 +94,7 @@ public class ResourceChangeCommandFactor
return null;
}
- CommandContext context = new
CommandContext(ProjectUtil.loadFilter(resource.getProject()));
+ CommandContext context = new
CommandContext(Activator.getDefault().getFilterLocator().loadFilter(resource.getProject()));
if (rai.isOnlyWhenMissing()) {
return repository.newAddOrUpdateNodeCommand(context,
rai.getInfo(), rai.getResource(),
@@ -139,7 +140,8 @@ public class ResourceChangeCommandFactor
File syncDirectoryAsFile =
ProjectUtil.getSyncDirectoryFullPath(resource.getProject()).toFile();
IFolder syncDirectory =
ProjectUtil.getSyncDirectory(resource.getProject());
- Filter filter = ProjectUtil.loadFilter(resource.getProject());
+ FilterLocator filterLocator =
Activator.getDefault().getFilterLocator();
+ Filter filter = filterLocator.loadFilter(resource.getProject());
ResourceProxy resourceProxy = null;
@@ -240,7 +242,7 @@ public class ResourceChangeCommandFactor
* The resourceProxy may be null, typically when a resource is already
deleted.
*
* <p>
- * The filter may be null, in which case all combinations are included in
the filed, i.e. allowed.
+ * In case the filter is {@code null} no resource should be added, i.e.
{@link FilterResult#DENY} is returned
*
* @param resource the resource to filter for, must not be
<code>null</code>
* @param resourceProxy the resource proxy to filter for, possibly
<code>null</code>
@@ -250,7 +252,7 @@ public class ResourceChangeCommandFactor
private FilterResult getFilterResult(IResource resource, ResourceProxy
resourceProxy, Filter filter) {
if (filter == null) {
- return FilterResult.ALLOW;
+ return FilterResult.DENY;
}
File contentSyncRoot =
ProjectUtil.getSyncDirectoryFile(resource.getProject());
@@ -524,10 +526,9 @@ public class ResourceChangeCommandFactor
return null;
}
+ Filter filter =
Activator.getDefault().getFilterLocator().loadFilter(resource.getProject());
IFolder syncDirectory =
ProjectUtil.getSyncDirectory(resource.getProject());
- Filter filter = ProjectUtil.loadFilter(syncDirectory.getProject());
-
FilterResult filterResult = getFilterResult(resource, null, filter);
if (filterResult == FilterResult.DENY || filterResult ==
FilterResult.PREREQUISITE) {
return null;
Modified: sling/trunk/tooling/ide/impl-resource/META-INF/MANIFEST.MF
URL:
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/impl-resource/META-INF/MANIFEST.MF?rev=1776444&r1=1776443&r2=1776444&view=diff
==============================================================================
--- sling/trunk/tooling/ide/impl-resource/META-INF/MANIFEST.MF (original)
+++ sling/trunk/tooling/ide/impl-resource/META-INF/MANIFEST.MF Thu Dec 29
16:02:21 2016
@@ -13,4 +13,6 @@ Bundle-RequiredExecutionEnvironment: Jav
Service-Component: OSGI-INF/RepositoryFactoryImpl.xml,
OSGI-INF/SimpleXmlSerializationManager.xml,
OSGI-INF/SimpleFilterLocator.xml
-Import-Package: org.json
+Import-Package: org.apache.sling.ide.eclipse.core,
+ org.eclipse.core.resources,
+ org.json
Modified:
sling/trunk/tooling/ide/impl-resource/src/org/apache/sling/ide/impl/resource/filer/SimpleFilterLocator.java
URL:
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/impl-resource/src/org/apache/sling/ide/impl/resource/filer/SimpleFilterLocator.java?rev=1776444&r1=1776443&r2=1776444&view=diff
==============================================================================
---
sling/trunk/tooling/ide/impl-resource/src/org/apache/sling/ide/impl/resource/filer/SimpleFilterLocator.java
(original)
+++
sling/trunk/tooling/ide/impl-resource/src/org/apache/sling/ide/impl/resource/filer/SimpleFilterLocator.java
Thu Dec 29 16:02:21 2016
@@ -18,14 +18,17 @@ package org.apache.sling.ide.impl.resour
import java.io.BufferedReader;
import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
+import org.apache.sling.ide.eclipse.core.ProjectUtil;
import org.apache.sling.ide.filter.Filter;
import org.apache.sling.ide.filter.FilterLocator;
+import org.eclipse.core.resources.IProject;
/**
* The <tt>SimpleFilterLocator</tt> looks for a file named {@value
#FILTERS_FILE_NAME} in the parent folder of the
@@ -42,15 +45,7 @@ public class SimpleFilterLocator impleme
private static final String FILTERS_FILE_NAME = "filters.txt";
- @Override
- public File findFilterLocation(File syncDirectory) {
- String parent = syncDirectory.getParent();
-
- return new File(parent, FILTERS_FILE_NAME);
- }
-
- @Override
- public Filter loadFilter(InputStream filterFileContents) throws
IOException {
+ private Filter loadFilter(InputStream filterFileContents) throws
IOException {
List<String> filters = new ArrayList<>();
if (filterFileContents != null) {
@@ -65,4 +60,20 @@ public class SimpleFilterLocator impleme
return new SimpleFilter(filters);
}
+
+ @Override
+ public Filter loadFilter(IProject project) throws IOException,
IllegalStateException {
+ File syncDirectory = ProjectUtil.getSyncDirectoryFile(project);
+ if (syncDirectory == null) {
+ throw new IllegalStateException("Could not determine sync
directory for project " + project);
+ }
+ File syncDirectoryParent = syncDirectory.getParentFile();
+ if (syncDirectoryParent == null) {
+ throw new IllegalStateException("Sync directory at " +
syncDirectory + " does not have a parent!");
+ }
+ File filterFile = new File(syncDirectory.getParentFile(),
FILTERS_FILE_NAME);
+ try (InputStream inputStream = new FileInputStream(filterFile)) {
+ return loadFilter(inputStream);
+ }
+ }
}
Modified: sling/trunk/tooling/ide/impl-vlt/META-INF/MANIFEST.MF
URL:
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/impl-vlt/META-INF/MANIFEST.MF?rev=1776444&r1=1776443&r2=1776444&view=diff
==============================================================================
--- sling/trunk/tooling/ide/impl-vlt/META-INF/MANIFEST.MF (original)
+++ sling/trunk/tooling/ide/impl-vlt/META-INF/MANIFEST.MF Thu Dec 29 16:02:21
2016
@@ -25,6 +25,7 @@ Import-Package: javax.jcr,
org.apache.sling.ide.serialization,
org.apache.sling.ide.transport,
org.apache.sling.ide.util,
+ org.eclipse.core.resources,
org.eclipse.core.runtime;version="3.4.0",
org.osgi.framework;version="1.7.0",
org.osgi.service.event;version="1.3.0",
Modified:
sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/filter/VltFilterLocator.java
URL:
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/filter/VltFilterLocator.java?rev=1776444&r1=1776443&r2=1776444&view=diff
==============================================================================
---
sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/filter/VltFilterLocator.java
(original)
+++
sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/filter/VltFilterLocator.java
Thu Dec 29 16:02:21 2016
@@ -17,13 +17,16 @@
package org.apache.sling.ide.impl.vlt.filter;
import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.jackrabbit.vault.fs.config.ConfigurationException;
+import org.apache.sling.ide.eclipse.core.ProjectUtil;
import org.apache.sling.ide.filter.Filter;
import org.apache.sling.ide.filter.FilterLocator;
import org.apache.sling.ide.impl.vlt.VaultFsLocator;
+import org.eclipse.core.resources.IProject;
public class VltFilterLocator implements FilterLocator {
@@ -38,19 +41,17 @@ public class VltFilterLocator implements
}
@Override
- public File findFilterLocation(File syncDirectory) {
-
- return fsLocator.findFilterFile(syncDirectory);
- }
-
- @Override
- public Filter loadFilter(InputStream filterFileContents) throws
IOException {
-
- try {
- return new VltFilter(filterFileContents);
+ public Filter loadFilter(IProject project) throws IOException,
IllegalStateException {
+ File syncDirectory = ProjectUtil.getSyncDirectoryFile(project);
+ if (syncDirectory == null) {
+ throw new IllegalStateException("Could not determine sync
directory for project " + project);
+ }
+ // TODO: also consider filter rules being configured through the
maven-content-package-plugin
+ File filterFile = fsLocator.findFilterFile(syncDirectory);
+ try (InputStream contents = new FileInputStream(filterFile)) {
+ return new VltFilter(contents);
} catch (ConfigurationException e) {
- // TODO proper error handling
- throw new IOException(e);
+ throw new IllegalStateException("Invalid filter file at " +
filterFile, e);
}
}