sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romb...@apache.org
Subject svn commit: r1608773 - in /sling/trunk/tooling/ide: eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/ eclipse-test/src/org/apache/sling/ide/test/impl/
Date Tue, 08 Jul 2014 13:22:42 GMT
Author: rombert
Date: Tue Jul  8 13:22:42 2014
New Revision: 1608773

URL: http://svn.apache.org/r1608773
Log:
SLING-3741 - When processing deleted folders, check for a covering
aggregate higher in the filesytem hierarchy

When resource data is found in a covering parent on a resource delete,
generate an add/update operation instead.

Added:
    sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/sling-mapping-with-unstructured-child.xml
  (with props)
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/JcrPartialCoverageAggregatesDeploymentTest.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=1608773&r1=1608772&r2=1608773&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
Tue Jul  8 13:22:42 2014
@@ -219,71 +219,95 @@ public class ResourceChangeCommandFactor
         String resourceLocation = '/' + changedResource.getFullPath().makeRelativeTo(syncDirectory.getFullPath())
                 .toPortableString();
         IPath serializationFilePath = Path.fromPortableString(serializationManager.getSerializationFilePath(
-                resourceLocation,
-                serializationKind));
+                resourceLocation, serializationKind));
         IResource serializationResource = syncDirectory.findMember(serializationFilePath);
 
-        // if the serialization resource is null, it's valid to look for a serialization
resource
-        // higher in the filesystem, given that the found serialization resource covers this
resource
-        // TODO - this too should be abstracted in the service layer, rather than in the
Eclipse-specific code
         if (serializationResource == null && changedResource.getType() == IResource.FOLDER)
{
-            PluginLogger logger = Activator.getDefault().getPluginLogger();
-            logger.trace("Found plain nt:folder candidate at {0}, trying to find a covering
resource for it",
-                    changedResource.getProjectRelativePath());
-            while (!serializationFilePath.isRoot()) {
-                serializationFilePath = serializationFilePath.removeLastSegments(1);
-                IFolder folderWithPossibleSerializationFile = (IFolder) syncDirectory.findMember(serializationFilePath);
-                if (folderWithPossibleSerializationFile == null) {
-                    logger.trace("No folder found at {0}, moving up to the next level", serializationFilePath);
+            ResourceProxy dataFromCoveringParent = findSerializationDataFromCoveringParent(changedResource,
+                    syncDirectory, resourceLocation, serializationFilePath);
+
+            if (dataFromCoveringParent != null) {
+                return dataFromCoveringParent;
+            }
+        }
+        return buildResourceProxy(resourceLocation, serializationResource, syncDirectory,
fallbackNodeType);
+    }
+
+    /**
+     * Tries to find serialization data from a resource in a covering parent
+     * 
+     * <p>
+     * If the serialization resource is null, it's valid to look for a serialization resource
higher in the filesystem,
+     * given that the found serialization resource covers this resource
+     * 
+     * @param changedResource the resource which has changed
+     * @param syncDirectory the content sync directory for the resource's project
+     * @param resourceLocation the resource location relative to the sync directory
+     * @param serializationFilePath the location
+     * @return a <tt>ResourceProxy</tt> if there is a covering parent, or null
is there is not
+     * @throws CoreException
+     * @throws IOException
+     */
+    private ResourceProxy findSerializationDataFromCoveringParent(IResource changedResource,
IFolder syncDirectory,
+            String resourceLocation, IPath serializationFilePath) throws CoreException, IOException
{
+
+        // TODO - this too should be abstracted in the service layer, rather than in the
Eclipse-specific code
+
+        PluginLogger logger = Activator.getDefault().getPluginLogger();
+        logger.trace("Found plain nt:folder candidate at {0}, trying to find a covering resource
for it",
+                changedResource.getProjectRelativePath());
+        while (!serializationFilePath.isRoot()) {
+            serializationFilePath = serializationFilePath.removeLastSegments(1);
+            IFolder folderWithPossibleSerializationFile = (IFolder) syncDirectory.findMember(serializationFilePath);
+            if (folderWithPossibleSerializationFile == null) {
+                logger.trace("No folder found at {0}, moving up to the next level", serializationFilePath);
+                continue;
+            }
+
+            // it's safe to use a specific SerializationKind since this scenario is only
valid for METADATA_PARTIAL
+            // coverage
+            String possibleSerializationFilePath = serializationManager.getSerializationFilePath(
+                    ((IFolder) folderWithPossibleSerializationFile).getLocation().toOSString(),
+                    SerializationKind.METADATA_PARTIAL);
+
+            logger.trace("Looking for serialization data in {0}", possibleSerializationFilePath);
+
+            if (serializationManager.isSerializationFile(possibleSerializationFilePath))
{
+
+                IPath parentSerializationFilePath = Path.fromOSString(possibleSerializationFilePath).makeRelativeTo(
+                        syncDirectory.getLocation());
+                IFile possibleSerializationFile = syncDirectory.getFile(parentSerializationFilePath);
+                if (!possibleSerializationFile.exists()) {
+                    logger.trace("Potential serialization data file {0} does not exist, moving
up to the next level",
+                            possibleSerializationFile.getFullPath());
                     continue;
                 }
 
-                // it's safe to use a specific SerializationKind since this scenario is only
valid for METADATA_PARTIAL
-                // coverage
-                String possibleSerializationFilePath = serializationManager.getSerializationFilePath(
-                        ((IFolder) folderWithPossibleSerializationFile).getLocation().toOSString(),
-                        SerializationKind.METADATA_PARTIAL);
-
-                logger.trace("Looking for serialization data in {0}", possibleSerializationFilePath);
-
-                if (serializationManager.isSerializationFile(possibleSerializationFilePath))
{
-
-                    IPath parentSerializationFilePath = Path.fromOSString(possibleSerializationFilePath).makeRelativeTo(
-                            syncDirectory.getLocation());
-                    IFile possibleSerializationFile = syncDirectory.getFile(parentSerializationFilePath);
-                    if (!possibleSerializationFile.exists()) {
-                        logger.trace(
-                                "Potential serialization data file {0} does not exist, moving
up to the next level",
-                                possibleSerializationFile.getFullPath());
-                        continue;
-                    }
-
-                    InputStream contents = possibleSerializationFile.getContents();
-                    ResourceProxy serializationData;
-                    try {
-                        serializationData = serializationManager.readSerializationData(
-                                parentSerializationFilePath.toPortableString(), contents);
-                    } finally {
-                        IOUtils.closeQuietly(contents);
-                    }
-
-                    String repositoryPath = serializationManager.getRepositoryPath(resourceLocation);
-                    String potentialPath = serializationData.getPath();
-                    boolean covered = serializationData
-                            .covers(repositoryPath);
-
-                    logger.trace(
-                            "Found possible serialization data at {0}. Resource :{1} ; our
resource: {2}. Covered: {3}",
-                            parentSerializationFilePath, potentialPath, repositoryPath, covered);
-                    if (covered) {
-                        return serializationData.getChild(repositoryPath);
-                    }
+                InputStream contents = possibleSerializationFile.getContents();
+                ResourceProxy serializationData;
+                try {
+                    serializationData = serializationManager.readSerializationData(
+                            parentSerializationFilePath.toPortableString(), contents);
+                } finally {
+                    IOUtils.closeQuietly(contents);
+                }
 
-                    break;
+                String repositoryPath = serializationManager.getRepositoryPath(resourceLocation);
+                String potentialPath = serializationData.getPath();
+                boolean covered = serializationData.covers(repositoryPath);
+
+                logger.trace(
+                        "Found possible serialization data at {0}. Resource :{1} ; our resource:
{2}. Covered: {3}",
+                        parentSerializationFilePath, potentialPath, repositoryPath, covered);
+                if (covered) {
+                    return serializationData.getChild(repositoryPath);
                 }
+
+                break;
             }
         }
-        return buildResourceProxy(resourceLocation, serializationResource, syncDirectory,
fallbackNodeType);
+
+        return null;
     }
 
     private ResourceProxy buildResourceProxy(String resourceLocation, IResource serializationResource,
@@ -342,9 +366,29 @@ public class ResourceChangeCommandFactor
                 return null;
             }
         }
-
-        ResourceProxy resourceProxy = buildResourceProxyForPlainFileOrFolder(resource, syncDirectory);
         
-        return repository.newDeleteNodeCommand(resourceProxy.getPath());
+        String resourceLocation = '/' + resource.getFullPath().makeRelativeTo(syncDirectory.getFullPath())
+                .toPortableString();
+        
+        // make sure that a 'plain' folder being deleted does not signal that the content
structure
+        // was rearranged under a covering parent aggregate
+        if (resource.getType() == IResource.FOLDER) {
+            IPath serializationFilePath = Path.fromPortableString(serializationManager.getSerializationFilePath(
+                    resourceLocation, SerializationKind.FOLDER));
+
+            ResourceProxy coveringParentData = findSerializationDataFromCoveringParent(resource,
syncDirectory,
+                    resourceLocation, serializationFilePath);
+            if (coveringParentData != null) {
+                Activator
+                        .getDefault()
+                        .getPluginLogger()
+                        .trace("Found covering resource data for resource at {0},  skipping
deletion and performing an update instead",
+                                resource.getFullPath());
+                FileInfo info = createFileInfo(resource, repository);
+                return repository.newAddOrUpdateNodeCommand(info, coveringParentData);
+            }
+        }
+        
+        return repository.newDeleteNodeCommand(serializationManager.getRepositoryPath(resourceLocation));
     }
 }

Modified: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/JcrPartialCoverageAggregatesDeploymentTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/JcrPartialCoverageAggregatesDeploymentTest.java?rev=1608773&r1=1608772&r2=1608773&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/JcrPartialCoverageAggregatesDeploymentTest.java
(original)
+++ sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/JcrPartialCoverageAggregatesDeploymentTest.java
Tue Jul  8 13:22:42 2014
@@ -297,6 +297,68 @@ public class JcrPartialCoverageAggregate
             }
         }, hasPrimaryType("nt:unstructured"));
     }
+    
+    @Test
+    public void deployNodeWithContentXmlInParentFolder_reverse() 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);
+
+        // the expected repository structure is
+        // mapping [sling:Mapping]
+        // \- jcr:content [nt:unstructured]
+        //  \- par [nt:unstructured]
+        //   \- folder [sling:Folder] 
+        
+        // first create the local structure where the content is completely serialized inside
the .content.xml file
+        project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/test-root/mapping/.content.xml"),
+                getClass().getResourceAsStream("sling-mapping-with-folder-child.xml"));
+        // now create the folder and its associated .content.xml file ; this will cause
+        // intermediate folders to be created whose serialization data is present in the
+        // parent's .content.xml file
+        project.createOrUpdateFile(
+                Path.fromPortableString("jcr_root/content/test-root/mapping/_jcr_content/par/folder/.content.xml"),
+                getClass().getResourceAsStream("sling-folder-nodetype.xml"));        
+
+        final RepositoryAccessor repo = new RepositoryAccessor(config);
+        Poller poller = new Poller();
+
+        // wait until the structure is published
+        poller.pollUntil(new Callable<Node>() {
+            @Override
+            public Node call() throws RepositoryException {
+                return repo.getNode("/content/test-root/mapping/jcr:content/par/folder");
+
+            }
+        }, hasPrimaryType("sling:Folder"));
+
+        // change the folder's node type to nt:unstructured and make sure it's covered by
the parent
+        project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/test-root/mapping/.content.xml"),
+                getClass().getResourceAsStream("sling-mapping-with-unstructured-child.xml"));
+        // delete the sling folder node type since the serialization is now completely covered
by
+        // the parent node
+        project.deleteMember(Path.fromPortableString("jcr_root/content/test-root/mapping/_jcr_content"));
+
+        // first wait until the sling:Folder child node is created, to ensure that all changes
are processed
+        poller.pollUntil(new Callable<Node>() {
+            @Override
+            public Node call() throws RepositoryException {
+                return repo.getNode("/content/test-root/mapping/jcr:content/par/folder");
+
+            }
+        }, hasPrimaryType("nt:unstructured"));
+    }    
 
     @Before
     public void ensureCleanState() throws Exception {

Added: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/sling-mapping-with-unstructured-child.xml
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/sling-mapping-with-unstructured-child.xml?rev=1608773&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/sling-mapping-with-unstructured-child.xml
(added)
+++ sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/sling-mapping-with-unstructured-child.xml
Tue Jul  8 13:22:42 2014
@@ -0,0 +1,25 @@
+<?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"
xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
+    jcr:primaryType="sling:Mapping">
+    <jcr:content jcr:primaryType="nt:unstructured">
+        <par jcr:primaryType="nt:unstructured">
+            <folder jcr:primaryType="nt:unstructured"/>
+        </par>
+    </jcr:content>
+</jcr:root>

Propchange: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/sling-mapping-with-unstructured-child.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/sling-mapping-with-unstructured-child.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message