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/10/09 11:16:28 UTC

svn commit: r1630342 - in /sling/trunk/tooling/ide: eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/ eclipse-test/src/org/apache/sling/ide/test/impl/ eclipse-test/src/org/apache/sling/ide/test/impl/helpers/

Author: rombert
Date: Thu Oct  9 09:16:28 2014
New Revision: 1630342

URL: http://svn.apache.org/r1630342
Log:
SLING-4002 - Deleting a file throws a 'Could not publish' error

Try to determine the repository path of a deleted file as it's not
always the same as the Eclipse resource path.

Added:
    sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/com.example.some.Component.xml
Modified:
    sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/ResourceChangeCommandFactory.java
    sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/JcrFullCoverageAggregatesDeploymentTest.java
    sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/RepositoryAccessor.java

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=1630342&r1=1630341&r2=1630342&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 Oct  9 09:16:28 2014
@@ -207,8 +207,19 @@ public class ResourceChangeCommandFactor
         return info;
     }
 
-    private FilterResult getFilterResult(IResource resource, Filter filter, File contentSyncRoot, IFolder syncFolder) throws SerializationException {
+    private FilterResult getFilterResult(IResource resource, Filter filter) throws SerializationException {
 
+        File contentSyncRoot = ProjectUtil.getSyncDirectoryFile(resource.getProject());
+
+        String repositoryPath = getRepositoryPathForDeletedResource(resource, contentSyncRoot);
+
+        Activator.getDefault().getPluginLogger().trace("Filtering by {0} for {1}", repositoryPath, resource);
+
+        return filter.filter(contentSyncRoot, repositoryPath);
+    }
+
+    private String getRepositoryPathForDeletedResource(IResource resource, File contentSyncRoot) {
+        IFolder syncFolder = ProjectUtil.getSyncDirectory(resource.getProject());
         IPath relativePath = resource.getFullPath().makeRelativeTo(syncFolder.getFullPath());
 
         String absFilePath = new File(contentSyncRoot, relativePath.toOSString()).getAbsolutePath();
@@ -216,11 +227,12 @@ public class ResourceChangeCommandFactor
 
         IPath osPath = Path.fromOSString(filePath);
         String repositoryPath = serializationManager.getRepositoryPath(osPath.makeRelativeTo(syncFolder.getLocation())
-                .toPortableString());
+                .makeAbsolute().toPortableString());
 
-        Activator.getDefault().getPluginLogger().trace("Filtering by {0} for {1}", repositoryPath, resource);
+        Activator.getDefault().getPluginLogger()
+                .trace("Repository path for deleted resource {0} is {1}", resource, repositoryPath);
 
-        return filter.filter(contentSyncRoot, repositoryPath);
+        return repositoryPath;
     }
 
     private boolean isFiltered(Filter filter, ResourceProxy resourceProxy, IResource resource) {
@@ -487,20 +499,18 @@ public class ResourceChangeCommandFactor
         }
 
         IFolder syncDirectory = ProjectUtil.getSyncDirectory(resource.getProject());
-        File syncDirectoryAsFile = ProjectUtil.getSyncDirectoryFile(resource.getProject());
-        final IFolder syncFolder = syncDirectory;
 
-        Filter filter = ProjectUtil.loadFilter(syncFolder.getProject());
+        Filter filter = ProjectUtil.loadFilter(syncDirectory.getProject());
 
         if (filter != null) {
-            FilterResult filterResult = getFilterResult(resource, filter, syncDirectoryAsFile, syncDirectory);
+            FilterResult filterResult = getFilterResult(resource, filter);
             if (filterResult == FilterResult.DENY || filterResult == FilterResult.PREREQUISITE) {
                 return null;
             }
         }
         
-        String resourceLocation = '/' + resource.getFullPath().makeRelativeTo(syncDirectory.getFullPath())
-                .toPortableString();
+        String resourceLocation = getRepositoryPathForDeletedResource(resource,
+                ProjectUtil.getSyncDirectoryFile(resource.getProject()));
         
         // make sure that a 'plain' folder being deleted does not signal that the content structure
         // was rearranged under a covering parent aggregate

Modified: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/JcrFullCoverageAggregatesDeploymentTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/JcrFullCoverageAggregatesDeploymentTest.java?rev=1630342&r1=1630341&r2=1630342&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/JcrFullCoverageAggregatesDeploymentTest.java (original)
+++ sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/JcrFullCoverageAggregatesDeploymentTest.java Thu Oct  9 09:16:28 2014
@@ -22,6 +22,7 @@ import static org.apache.sling.ide.test.
 import static org.apache.sling.ide.test.impl.helpers.jcr.JcrMatchers.hasPath;
 import static org.apache.sling.ide.test.impl.helpers.jcr.JcrMatchers.hasPrimaryType;
 import static org.hamcrest.CoreMatchers.allOf;
+import static org.hamcrest.CoreMatchers.equalTo;
 
 import java.io.InputStream;
 import java.util.concurrent.Callable;
@@ -299,6 +300,56 @@ public class JcrFullCoverageAggregatesDe
         }, postConditions);
     }
 
+    @Test
+    public void deleteFullCoverageAggregate() throws Exception {
+
+        wstServer.waitForServerToStart();
+
+        // create faceted project
+        IProject contentProject = projectRule.getProject();
+
+        ProjectAdapter project = new ProjectAdapter(contentProject);
+        project.addNatures("org.eclipse.wst.common.project.facet.core.nature");
+
+        // install content facet
+        project.installFacet("sling.content", "1.0");
+
+        ServerAdapter server = new ServerAdapter(wstServer.getServer());
+        server.installModule(contentProject);
+        
+        final String baseName = "com.example.some.Component";
+
+        // create .content.xml structure
+        InputStream contentXml = getClass().getResourceAsStream(baseName + ".xml");
+        project.createOrUpdateFile(
+                Path.fromPortableString("jcr_root/content/test-root/" + baseName + ".xml"), contentXml);
+
+        Matcher<Node> postConditions = allOf(hasPath("/content/test-root/" + baseName),
+                hasPrimaryType("sling:OsgiConfig"));
+
+        final RepositoryAccessor repo = new RepositoryAccessor(config);
+        Poller poller = new Poller();
+        poller.pollUntil(new Callable<Node>() {
+            @Override
+            public Node call() throws RepositoryException {
+                return repo.getNode("/content/test-root/" + baseName);
+
+            }
+        }, postConditions);
+
+        // Remove file from disk
+        project.deleteMember(Path.fromPortableString("jcr_root/content/test-root/" + baseName + ".xml"));
+
+        // poll until the node no longer exists
+        poller.pollUntil(new Callable<Boolean>() {
+            @Override
+            public Boolean call() throws RepositoryException {
+                return repo.hasNode("/content/test-root/" + baseName);
+
+            }
+        }, equalTo(false));
+    }
+
     @After
     public void cleanup() throws Exception {
         new RepositoryAccessor(config).tryDeleteResource("/content/test-root");

Added: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/com.example.some.Component.xml
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/com.example.some.Component.xml?rev=1630342&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/com.example.some.Component.xml (added)
+++ sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/com.example.some.Component.xml Thu Oct  9 09:16:28 2014
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
+    xmlns:jcr="http://www.jcp.org/jcr/1.0" jcr:primaryType="sling:OsgiConfig"
+    someProp="some.value"/>
\ No newline at end of file

Modified: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/RepositoryAccessor.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/RepositoryAccessor.java?rev=1630342&r1=1630341&r2=1630342&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/RepositoryAccessor.java (original)
+++ sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/RepositoryAccessor.java Thu Oct  9 09:16:28 2014
@@ -115,6 +115,21 @@ public class RepositoryAccessor {
         return login().getNode(nodePath);
     }
 
+    /**
+     * Returns true if a node exists at the specified path
+     * 
+     * @param path the path, in absolute format or relative to the repository root
+     * @return true if the path exists, false otherwise
+     * @throws RepositoryException
+     */
+    public boolean hasNode(String path) throws RepositoryException {
+        if (path.startsWith("/")) {
+            path = path.substring(1);
+        }
+
+        return login().getRootNode().hasNode(path);
+    }
+
     public void createNode(String path, String primaryNodeType) throws RepositoryException {
 
         Session session = login();