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 2013/09/19 14:20:48 UTC

svn commit: r1524708 - in /sling/branches/tooling-ide-vlt/tooling/ide: ./ api-test/ api-test/src/ api-test/src/test/ api-test/src/test/java/ api-test/src/test/java/org/ api-test/src/test/java/org/apache/ api-test/src/test/java/org/apache/sling/ api-tes...

Author: rombert
Date: Thu Sep 19 12:20:47 2013
New Revision: 1524708

URL: http://svn.apache.org/r1524708
Log:
SLING-2989 - [Tooling] integrate with vlt once available

Take into account the node's mixinTypes when deciding how to serialize
it to disk.

Added:
    sling/branches/tooling-ide-vlt/tooling/ide/api-test/
    sling/branches/tooling-ide-vlt/tooling/ide/api-test/pom.xml   (with props)
    sling/branches/tooling-ide-vlt/tooling/ide/api-test/src/
    sling/branches/tooling-ide-vlt/tooling/ide/api-test/src/test/
    sling/branches/tooling-ide-vlt/tooling/ide/api-test/src/test/java/
    sling/branches/tooling-ide-vlt/tooling/ide/api-test/src/test/java/org/
    sling/branches/tooling-ide-vlt/tooling/ide/api-test/src/test/java/org/apache/
    sling/branches/tooling-ide-vlt/tooling/ide/api-test/src/test/java/org/apache/sling/
    sling/branches/tooling-ide-vlt/tooling/ide/api-test/src/test/java/org/apache/sling/ide/
    sling/branches/tooling-ide-vlt/tooling/ide/api-test/src/test/java/org/apache/sling/ide/serialization/
    sling/branches/tooling-ide-vlt/tooling/ide/api-test/src/test/java/org/apache/sling/ide/serialization/NodeTypeResourceBuilder.java   (with props)
    sling/branches/tooling-ide-vlt/tooling/ide/api-test/src/test/java/org/apache/sling/ide/serialization/SerializationKindManagerTest.java   (with props)
    sling/branches/tooling-ide-vlt/tooling/ide/api-test/src/test/java/org/apache/sling/ide/serialization/StubRepository.java   (with props)
Modified:
    sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/serialization/SerializationKindManager.java
    sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/VltSerializationDataBuilder.java
    sling/branches/tooling-ide-vlt/tooling/ide/pom.xml

Added: sling/branches/tooling-ide-vlt/tooling/ide/api-test/pom.xml
URL: http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/api-test/pom.xml?rev=1524708&view=auto
==============================================================================
--- sling/branches/tooling-ide-vlt/tooling/ide/api-test/pom.xml (added)
+++ sling/branches/tooling-ide-vlt/tooling/ide/api-test/pom.xml Thu Sep 19 12:20:47 2013
@@ -0,0 +1,38 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.sling.ide</groupId>
+    <artifactId>reactor</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+  </parent>
+  <artifactId>org.apache.sling.ide.api-test</artifactId>
+  <name>Sling IDE Tools: API Tests</name>
+  <dependencies>
+      <dependency>
+          <groupId>junit</groupId>
+          <artifactId>junit</artifactId>
+          <version>4.11</version>
+          <scope>test</scope>
+      </dependency>
+      <dependency>
+          <groupId>org.apache.sling.ide</groupId>
+          <artifactId>org.apache.sling.ide.api</artifactId>
+          <version>${project.version}</version>
+          <type>eclipse-plugin</type>
+      </dependency>
+  </dependencies>
+  
+  <build>
+      <plugins>
+          <plugin>
+              <groupId>org.apache.maven.plugins</groupId>
+              <artifactId>maven-compiler-plugin</artifactId>
+              <configuration>
+                <!-- Tycho targets 1.6 by default, so we need that as well -->
+                <source>1.6</source>
+                <target>1.6</target>
+              </configuration>
+          </plugin>
+      </plugins>
+  </build>
+</project>

Propchange: sling/branches/tooling-ide-vlt/tooling/ide/api-test/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/branches/tooling-ide-vlt/tooling/ide/api-test/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: sling/branches/tooling-ide-vlt/tooling/ide/api-test/src/test/java/org/apache/sling/ide/serialization/NodeTypeResourceBuilder.java
URL: http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/api-test/src/test/java/org/apache/sling/ide/serialization/NodeTypeResourceBuilder.java?rev=1524708&view=auto
==============================================================================
--- sling/branches/tooling-ide-vlt/tooling/ide/api-test/src/test/java/org/apache/sling/ide/serialization/NodeTypeResourceBuilder.java (added)
+++ sling/branches/tooling-ide-vlt/tooling/ide/api-test/src/test/java/org/apache/sling/ide/serialization/NodeTypeResourceBuilder.java Thu Sep 19 12:20:47 2013
@@ -0,0 +1,66 @@
+/*
+ * 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.serialization;
+
+import org.apache.sling.ide.transport.ResourceProxy;
+
+public class NodeTypeResourceBuilder {
+
+    public static NodeTypeResourceBuilder newBuilder(ResourceProxy parent, String name) {
+
+        String path;
+
+        if (parent.getPath().endsWith("/")) {
+            path = parent.getPath() + name;
+        } else {
+            path = parent.getPath() + "/" + name;
+        }
+
+        ResourceProxy resourceProxy = new ResourceProxy(path);
+        // set defaults
+        resourceProxy.addProperty("jcr:nodeTypeName", name);
+        resourceProxy.addProperty("jcr:primaryType", "nt:nodeType");
+        resourceProxy.addProperty("jcr:isMixin", false);
+        resourceProxy.addProperty("jcr:mixinTypes", new String[] {});
+        return new NodeTypeResourceBuilder(resourceProxy);
+    }
+
+    private ResourceProxy resource;
+
+    private NodeTypeResourceBuilder(ResourceProxy resource) {
+
+        this.resource = resource;
+    }
+
+    public NodeTypeResourceBuilder setSupertypes(String[] supertypes) {
+
+        this.resource.addProperty("jcr:supertypes", supertypes);
+
+        return this;
+    }
+
+    public NodeTypeResourceBuilder setIsMixin(boolean isMixin) {
+        this.resource.addProperty("jcr:isMixin", true);
+
+        return this;
+    }
+
+    public ResourceProxy build() {
+
+        return resource;
+    }
+}
\ No newline at end of file

Propchange: sling/branches/tooling-ide-vlt/tooling/ide/api-test/src/test/java/org/apache/sling/ide/serialization/NodeTypeResourceBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/branches/tooling-ide-vlt/tooling/ide/api-test/src/test/java/org/apache/sling/ide/serialization/NodeTypeResourceBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: sling/branches/tooling-ide-vlt/tooling/ide/api-test/src/test/java/org/apache/sling/ide/serialization/SerializationKindManagerTest.java
URL: http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/api-test/src/test/java/org/apache/sling/ide/serialization/SerializationKindManagerTest.java?rev=1524708&view=auto
==============================================================================
--- sling/branches/tooling-ide-vlt/tooling/ide/api-test/src/test/java/org/apache/sling/ide/serialization/SerializationKindManagerTest.java (added)
+++ sling/branches/tooling-ide-vlt/tooling/ide/api-test/src/test/java/org/apache/sling/ide/serialization/SerializationKindManagerTest.java Thu Sep 19 12:20:47 2013
@@ -0,0 +1,75 @@
+/*
+ * 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.serialization;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import java.util.Collections;
+
+import org.apache.sling.ide.transport.RepositoryException;
+import org.junit.Before;
+import org.junit.Test;
+
+public class SerializationKindManagerTest {
+
+    private SerializationKindManager skm;
+
+    @Before
+    public void init() throws RepositoryException {
+
+        skm = new SerializationKindManager();
+        skm.init(new StubRepository());
+    }
+
+    @Test
+    public void ntFile() {
+
+        assertThat(skm.getSerializationKind("nt:file", Collections.<String> emptyList()), is(SerializationKind.FILE));
+    }
+
+    @Test
+    public void ntFolder() {
+
+        assertThat(skm.getSerializationKind("nt:folder", Collections.<String> emptyList()), is(SerializationKind.FOLDER));
+    }
+
+    @Test
+    public void ntUnstructured() {
+
+        assertThat(skm.getSerializationKind("nt:unstructured", Collections.<String> emptyList()), is(SerializationKind.METADATA_PARTIAL));
+    }
+
+    @Test
+    public void osgiConfig() {
+
+        assertThat(skm.getSerializationKind("sling:OsgiConfig", Collections.<String> emptyList()), is(SerializationKind.METADATA_FULL));
+    }
+
+    @Test
+    public void slingFolder() {
+
+        assertThat(skm.getSerializationKind("sling:Folder", Collections.<String> emptyList()), is(SerializationKind.FOLDER));
+    }
+
+    @Test
+    public void slingFolderWithFullCoverageMixin() {
+
+        assertThat(skm.getSerializationKind("sling:Folder", Collections.singletonList("vlt:FullCoverage")),
+                is(SerializationKind.METADATA_FULL));
+    }
+}

Propchange: sling/branches/tooling-ide-vlt/tooling/ide/api-test/src/test/java/org/apache/sling/ide/serialization/SerializationKindManagerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/branches/tooling-ide-vlt/tooling/ide/api-test/src/test/java/org/apache/sling/ide/serialization/SerializationKindManagerTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: sling/branches/tooling-ide-vlt/tooling/ide/api-test/src/test/java/org/apache/sling/ide/serialization/StubRepository.java
URL: http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/api-test/src/test/java/org/apache/sling/ide/serialization/StubRepository.java?rev=1524708&view=auto
==============================================================================
--- sling/branches/tooling-ide-vlt/tooling/ide/api-test/src/test/java/org/apache/sling/ide/serialization/StubRepository.java (added)
+++ sling/branches/tooling-ide-vlt/tooling/ide/api-test/src/test/java/org/apache/sling/ide/serialization/StubRepository.java Thu Sep 19 12:20:47 2013
@@ -0,0 +1,136 @@
+/*
+ * 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.serialization;
+
+import org.apache.sling.ide.transport.Command;
+import org.apache.sling.ide.transport.FileInfo;
+import org.apache.sling.ide.transport.Repository;
+import org.apache.sling.ide.transport.RepositoryException;
+import org.apache.sling.ide.transport.RepositoryInfo;
+import org.apache.sling.ide.transport.ResourceProxy;
+import org.apache.sling.ide.transport.Result;
+
+public class StubRepository implements Repository {
+    @Override
+    public void setRepositoryInfo(RepositoryInfo repositoryInfo) {
+    }
+
+    @Override
+    public Command<Void> newUpdateContentNodeCommand(FileInfo fileInfo, ResourceProxy resourceProxy) {
+        return null;
+    }
+
+    @Override
+    public Command<ResourceProxy> newListChildrenNodeCommand(final String path) {
+
+        if ("/jcr:system/jcr:nodeTypes".equals(path)) {
+            return new Command<ResourceProxy>() {
+
+                @Override
+                public Result<ResourceProxy> execute() {
+
+                    final ResourceProxy root = new ResourceProxy(path);
+                    root.addProperty("jcr:primaryType", "rep:nodeTypes");
+
+                    // nt:file
+                    ResourceProxy ntFile = NodeTypeResourceBuilder.newBuilder(root, "nt:file")
+                            .setSupertypes(new String[] { "nt:hierarchyNode" }).build();
+                    
+                    // nt:folder
+                    ResourceProxy ntFolder = NodeTypeResourceBuilder.newBuilder(root, "nt:folder")
+                            .setSupertypes(new String[] { "nt:hierarchyNode" }).build();
+
+                    // nt:hierarchyNode
+                    ResourceProxy ntHierarchyNode = NodeTypeResourceBuilder.newBuilder(root, "nt:hierarchyNode")
+                            .setSupertypes(new String[] { "mix:created", "nt:base" }).build();
+
+                    // nt:unstructured
+                    ResourceProxy ntUnstructured = NodeTypeResourceBuilder.newBuilder(root, "nt:unstructured")
+                            .setSupertypes(new String[] {"nt:base" }).build();
+
+                    // nt:base
+                    ResourceProxy ntBase = NodeTypeResourceBuilder.newBuilder(root, "nt:base")
+                            .setSupertypes(new String[] { }).build();
+                    
+                    // sling:OsgiConfig
+                    ResourceProxy slingOsgiConfig = NodeTypeResourceBuilder.newBuilder(root, "sling:OsgiConfig")
+                            .setSupertypes(new String[] {"nt:hierarchyNode", "nt:unstructured" }).build();
+                    
+                    // sling:Folder
+                    ResourceProxy slingFolder = NodeTypeResourceBuilder.newBuilder(root, "sling:Folder")
+                            .setSupertypes(new String[] {"nt:folder" }).build();
+                    
+                    // vlt:FullCoverage
+                    ResourceProxy vltFullCoverage = NodeTypeResourceBuilder.newBuilder(root, "vlt:FullCoverage")
+                            .setIsMixin(true).setSupertypes(new String[] {}).build();
+
+                    root.addChild(ntFile);
+                    root.addChild(ntFolder);
+                    root.addChild(ntHierarchyNode);
+                    root.addChild(ntUnstructured);
+                    root.addChild(ntBase);
+                    root.addChild(slingOsgiConfig);
+                    root.addChild(slingFolder);
+                    root.addChild(vltFullCoverage);
+
+                    return new Result<ResourceProxy>() {
+                        public ResourceProxy get() throws RepositoryException {
+                            return root;
+                        }
+
+                        @Override
+                        public boolean isSuccess() {
+                            return true;
+                        };
+                    };
+                }
+
+                @Override
+                public String getPath() {
+                    return path;
+                }
+            };
+        }
+
+        return null;
+    }
+
+    @Override
+    public Command<ResourceProxy> newGetNodeContentCommand(String path) {
+        return null;
+    }
+
+    @Override
+    public Command<byte[]> newGetNodeCommand(String path) {
+        return null;
+    }
+
+    @Override
+    public Command<Void> newDeleteNodeCommand(FileInfo fileInfo) {
+        return null;
+    }
+
+    @Override
+    public Command<Void> newAddNodeCommand(FileInfo fileInfo) {
+        return null;
+    }
+
+    @Override
+    public RepositoryInfo getRepositoryInfo() {
+        return null;
+    }
+}
\ No newline at end of file

Propchange: sling/branches/tooling-ide-vlt/tooling/ide/api-test/src/test/java/org/apache/sling/ide/serialization/StubRepository.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/branches/tooling-ide-vlt/tooling/ide/api-test/src/test/java/org/apache/sling/ide/serialization/StubRepository.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/serialization/SerializationKindManager.java
URL: http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/serialization/SerializationKindManager.java?rev=1524708&r1=1524707&r2=1524708&view=diff
==============================================================================
--- sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/serialization/SerializationKindManager.java (original)
+++ sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/serialization/SerializationKindManager.java Thu Sep 19 12:20:47 2013
@@ -18,6 +18,7 @@ package org.apache.sling.ide.serializati
 
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -48,10 +49,6 @@ public class SerializationKindManager {
             String nodeType = PathUtil.getName(child.getPath());
             String[] superTypes = (String[]) child.getProperties().get("jcr:supertypes");
 
-            if (superTypes.length == 0) {
-                continue;
-            }
-
             nodeTypesToParentNodeTypes.put(nodeType, superTypes);
         }
 
@@ -109,20 +106,42 @@ public class SerializationKindManager {
         return null;
     }
 
-    public SerializationKind getSerializationKind(String nodeTypeName) {
+    public SerializationKind getSerializationKind(String nodeTypeName, List<String> mixinNodeTypeNames) {
 
-        if (fileNodeTypes.contains(nodeTypeName)) {
-            return SerializationKind.FILE;
+        SerializationKind kind = null;
+
+        // 1. check mixins
+        for (String mixinNodeType : mixinNodeTypeNames) {
+            kind = getSerializationKind0(mixinNodeType);
+            if (kind != null) {
+                return kind;
+            }
         }
 
-        if (folderNodeTypes.contains(nodeTypeName)) {
-            return SerializationKind.FOLDER;
+        // 2. check node type
+        kind = getSerializationKind0(nodeTypeName);
+        if (kind != null) {
+            return kind;
         }
 
+        // 3. default to partial
+        return SerializationKind.METADATA_PARTIAL;
+    }
+
+    private SerializationKind getSerializationKind0(String nodeTypeName) {
+
         if (fullMetadataNodeTypes.contains(nodeTypeName)) {
             return SerializationKind.METADATA_FULL;
         }
 
-        return SerializationKind.METADATA_PARTIAL;
+        if (fileNodeTypes.contains(nodeTypeName)) {
+            return SerializationKind.FILE;
+        }
+
+        if (folderNodeTypes.contains(nodeTypeName)) {
+            return SerializationKind.FOLDER;
+        }
+
+        return null;
     }
 }

Modified: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/VltSerializationDataBuilder.java
URL: http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/VltSerializationDataBuilder.java?rev=1524708&r1=1524707&r2=1524708&view=diff
==============================================================================
--- sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/VltSerializationDataBuilder.java (original)
+++ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/VltSerializationDataBuilder.java Thu Sep 19 12:20:47 2013
@@ -21,12 +21,15 @@ import static org.apache.sling.ide.util.
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
 
 import javax.jcr.Credentials;
 import javax.jcr.Node;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.nodetype.NodeType;
 
 import org.apache.jackrabbit.vault.fs.api.Aggregate;
 import org.apache.jackrabbit.vault.fs.api.Aggregator;
@@ -139,8 +142,13 @@ public class VltSerializationDataBuilder
             if (aggregate == null)
                 throw new IllegalArgumentException("No aggregate found for path " + resource.getPath());
 
+            NodeType[] mixinNodeTypes = aggregate.getNode().getMixinNodeTypes();
+            List<String> mixinNodeTypeNames = new ArrayList<String>(mixinNodeTypes.length);
+            for (NodeType nodeType : mixinNodeTypes)
+                mixinNodeTypeNames.add(nodeType.getName());
+
             SerializationKind serializationKind = skm.getSerializationKind(aggregate.getNode().getPrimaryNodeType()
-                    .getName());
+                    .getName(), mixinNodeTypeNames);
 
             if (resource.getPath().equals("/") || serializationKind == SerializationKind.METADATA_PARTIAL
                     || serializationKind == SerializationKind.FILE || serializationKind == SerializationKind.FOLDER) {

Modified: sling/branches/tooling-ide-vlt/tooling/ide/pom.xml
URL: http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/pom.xml?rev=1524708&r1=1524707&r2=1524708&view=diff
==============================================================================
--- sling/branches/tooling-ide-vlt/tooling/ide/pom.xml (original)
+++ sling/branches/tooling-ide-vlt/tooling/ide/pom.xml Thu Sep 19 12:20:47 2013
@@ -11,6 +11,7 @@
 	<modules>
 		<module>target-definition</module>
 		<module>api</module>
+		<module>api-test</module>
 		<module>impl-resource</module>
         <module>impl-resource-test</module>
 		<module>vlt-wrapper</module>