sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From k...@apache.org
Subject svn commit: r1777010 - in /sling/trunk/tooling/ide: api/META-INF/ api/src/org/apache/sling/ide/filter/ eclipse-core/src/org/apache/sling/ide/eclipse/core/ eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/ impl-resource/META-INF/ impl-resourc...
Date Mon, 02 Jan 2017 20:28:17 GMT
Author: kwin
Date: Mon Jan  2 20:28:17 2017
New Revision: 1777010

URL: http://svn.apache.org/viewvc?rev=1777010&view=rev
Log:
SLING-6344 revert r1776444

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=1777010&r1=1777009&r2=1777010&view=diff
==============================================================================
--- sling/trunk/tooling/ide/api/META-INF/MANIFEST.MF (original)
+++ sling/trunk/tooling/ide/api/META-INF/MANIFEST.MF Mon Jan  2 20:28:17 2017
@@ -18,8 +18,6 @@ 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=1777010&r1=1777009&r2=1777010&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 Mon Jan
 2 20:28:17 2017
@@ -16,19 +16,25 @@
  */
 package org.apache.sling.ide.filter;
 
+import java.io.File;
 import java.io.IOException;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.jdt.annotation.NonNull;
+import java.io.InputStream;
 
 public interface FilterLocator {
 
+    // TODO - should be File[] to allow multiple lookups, see {filter-vlt.xml, filter.xml}
+    File findFilterLocation(File syncDirectory);
+
     /**
-     * Loads a filter for the given project (which determines which parts of the repository
should be overwritten)
+     * Loads a filter based on the raw <tt>filterFileContents</tt>
+     * 
+     * <p>
+     * If the <tt>filterFileContents</tt> is null it returns a default filter
+     * </p>
      * 
-     * @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
+     * @param filterFileContents the raw contents of the filter file, possibly null
+     * @return
+     * @throws IOException
      */
-    @NonNull Filter loadFilter(@NonNull IProject project) throws IOException, IllegalStateException;
+    Filter loadFilter(InputStream filterFileContents) throws IOException;
 }

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=1777010&r1=1777009&r2=1777010&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
Mon Jan  2 20:28:17 2017
@@ -160,6 +160,57 @@ 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=1777010&r1=1777009&r2=1777010&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
Mon Jan  2 20:28:17 2017
@@ -31,7 +31,6 @@ 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;
@@ -94,7 +93,7 @@ public class ResourceChangeCommandFactor
             return null;
         }
         
-        CommandContext context = new CommandContext(Activator.getDefault().getFilterLocator().loadFilter(resource.getProject()));
+        CommandContext context = new CommandContext(ProjectUtil.loadFilter(resource.getProject()));
 
         if (rai.isOnlyWhenMissing()) {
             return repository.newAddOrUpdateNodeCommand(context, rai.getInfo(), rai.getResource(),
@@ -140,8 +139,7 @@ public class ResourceChangeCommandFactor
         File syncDirectoryAsFile = ProjectUtil.getSyncDirectoryFullPath(resource.getProject()).toFile();
         IFolder syncDirectory = ProjectUtil.getSyncDirectory(resource.getProject());
 
-        FilterLocator filterLocator = Activator.getDefault().getFilterLocator();
-        Filter filter = filterLocator.loadFilter(resource.getProject());
+        Filter filter = ProjectUtil.loadFilter(resource.getProject());
 
         ResourceProxy resourceProxy = null;
 
@@ -242,7 +240,7 @@ public class ResourceChangeCommandFactor
      * The resourceProxy may be null, typically when a resource is already deleted.
      * 
      * <p>
-     * In case the filter is {@code null} no resource should be added, i.e. {@link FilterResult#DENY}
is returned
+     * The filter may be null, in which case all combinations are included in the filed,
i.e. allowed.
      * 
      * @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>
@@ -252,7 +250,7 @@ public class ResourceChangeCommandFactor
     private FilterResult getFilterResult(IResource resource, ResourceProxy resourceProxy,
Filter filter) {
 
         if (filter == null) {
-            return FilterResult.DENY;
+            return FilterResult.ALLOW;
         }
 
         File contentSyncRoot = ProjectUtil.getSyncDirectoryFile(resource.getProject());
@@ -526,9 +524,10 @@ 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=1777010&r1=1777009&r2=1777010&view=diff
==============================================================================
--- sling/trunk/tooling/ide/impl-resource/META-INF/MANIFEST.MF (original)
+++ sling/trunk/tooling/ide/impl-resource/META-INF/MANIFEST.MF Mon Jan  2 20:28:17 2017
@@ -13,6 +13,4 @@ Bundle-RequiredExecutionEnvironment: Jav
 Service-Component: OSGI-INF/RepositoryFactoryImpl.xml,
  OSGI-INF/SimpleXmlSerializationManager.xml,
  OSGI-INF/SimpleFilterLocator.xml
-Import-Package: org.apache.sling.ide.eclipse.core,
- org.eclipse.core.resources,
- org.json
+Import-Package: 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=1777010&r1=1777009&r2=1777010&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
Mon Jan  2 20:28:17 2017
@@ -18,17 +18,14 @@ 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
@@ -45,7 +42,15 @@ public class SimpleFilterLocator impleme
 
     private static final String FILTERS_FILE_NAME = "filters.txt";
 
-    private Filter loadFilter(InputStream filterFileContents) throws IOException {
+    @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 {
 
         List<String> filters = new ArrayList<>();
         if (filterFileContents != null) {
@@ -60,20 +65,4 @@ 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=1777010&r1=1777009&r2=1777010&view=diff
==============================================================================
--- sling/trunk/tooling/ide/impl-vlt/META-INF/MANIFEST.MF (original)
+++ sling/trunk/tooling/ide/impl-vlt/META-INF/MANIFEST.MF Mon Jan  2 20:28:17 2017
@@ -25,7 +25,6 @@ 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=1777010&r1=1777009&r2=1777010&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
Mon Jan  2 20:28:17 2017
@@ -17,16 +17,13 @@
 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 {
 
@@ -41,17 +38,19 @@ public class VltFilterLocator implements
     }
 
     @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);
-        }
-        // 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);
+    public File findFilterLocation(File syncDirectory) {
+
+        return fsLocator.findFilterFile(syncDirectory);
+    }
+
+    @Override
+    public Filter loadFilter(InputStream filterFileContents) throws IOException {
+
+        try {
+            return new VltFilter(filterFileContents);
         } catch (ConfigurationException e) {
-            throw new IllegalStateException("Invalid filter file at " + filterFile, e);
+            // TODO proper error handling
+            throw new IOException(e);
         }
     }
 



Mime
View raw message