You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by si...@apache.org on 2019/03/13 15:07:44 UTC

[sling-whiteboard] branch master updated: [cp2fm] added missing resources that have to be included in the final content package and related tests

This is an automated email from the ASF dual-hosted git repository.

simonetripodi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git


The following commit(s) were added to refs/heads/master by this push:
     new a32c8e5  [cp2fm] added missing resources that have to be included in the final content package and related tests
a32c8e5 is described below

commit a32c8e58117136b67b0d4edcd97b95c56e504027
Author: Simo Tripodi <st...@adobe.com>
AuthorDate: Wed Mar 13 16:07:37 2019 +0100

    [cp2fm] added missing resources that have to be included in the final
    content package and related tests
---
 .../ContentPackage2FeatureModelConverter.java      | 21 +++++
 .../resources/org/apache/sling/cp2fm/config.xml    | 95 ++++++++++++++++++++++
 .../org/apache/sling/cp2fm/definition/.content.xml | 19 +++++
 .../resources/org/apache/sling/cp2fm/settings.xml  | 22 +++++
 .../ContentPackage2FeatureModelConverterTest.java  | 15 ++++
 5 files changed, 172 insertions(+)

diff --git a/content-package-2-feature-model/src/main/java/org/apache/sling/cp2fm/ContentPackage2FeatureModelConverter.java b/content-package-2-feature-model/src/main/java/org/apache/sling/cp2fm/ContentPackage2FeatureModelConverter.java
index bb4bd16..cee4622 100644
--- a/content-package-2-feature-model/src/main/java/org/apache/sling/cp2fm/ContentPackage2FeatureModelConverter.java
+++ b/content-package-2-feature-model/src/main/java/org/apache/sling/cp2fm/ContentPackage2FeatureModelConverter.java
@@ -23,6 +23,7 @@ import java.io.FileOutputStream;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.Dictionary;
@@ -84,6 +85,8 @@ public class ContentPackage2FeatureModelConverter {
 
     private static final String JSON_FILE_EXTENSION = ".json";
 
+    private static final String[] INCLUDE_RESOURCES = { "definition/.content.xml", "config.xml", "settings.xml" };
+
     private final Logger logger = LoggerFactory.getLogger(getClass());
 
     private final PackageManager packageManager = new PackageManagerImpl();
@@ -234,6 +237,8 @@ public class ContentPackage2FeatureModelConverter {
                 properties.setProperty(PackageProperties.NAME_PACKAGE_TYPE, PackageType.APPLICATION.name());
                 properties.setProperty(PackageProperties.NAME_AC_HANDLING, AccessControlHandling.MERGE_PRESERVE.name());
 
+                // generate the Vault properties XML file
+
                 File xmlProperties = new File(deflatedDir, VAULT_PROPERTIES_FILE);
                 xmlProperties.getParentFile().mkdirs();
 
@@ -241,6 +246,20 @@ public class ContentPackage2FeatureModelConverter {
                     properties.storeToXML(fos, null);
                 }
 
+                // copy the required resources
+
+                for (String resource : INCLUDE_RESOURCES) {
+                    File targetResource = new File(xmlProperties.getParentFile(), resource);
+                    targetResource.getParentFile().mkdirs();
+
+                    try (InputStream input = getClass().getResourceAsStream(resource);
+                            OutputStream output = new FileOutputStream(targetResource)) {
+                        IOUtils.copy(input, output);
+                    }
+                }
+
+                // create the target archiver
+
                 Archiver archiver = new JarArchiver();
                 archiver.setIncludeEmptyDirs(true);
 
@@ -262,6 +281,8 @@ public class ContentPackage2FeatureModelConverter {
                     destFile.delete();
                 }
 
+                // deploy the new zip content-package to the local mvn bundles dir
+
                 String pomModel = MavenPomSupplier.generatePom(targetFeature.getId().getGroupId(),
                                                                targetFeature.getId().getArtifactId(),
                                                                targetFeature.getId().getVersion(),
diff --git a/content-package-2-feature-model/src/main/resources/org/apache/sling/cp2fm/config.xml b/content-package-2-feature-model/src/main/resources/org/apache/sling/cp2fm/config.xml
new file mode 100644
index 0000000..54a0a38
--- /dev/null
+++ b/content-package-2-feature-model/src/main/resources/org/apache/sling/cp2fm/config.xml
@@ -0,0 +1,95 @@
+<?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.
+-->
+<vaultfs version="1.1">
+  <!--
+    Defines the content aggregation. The order of the defined aggregates
+    is important for finding the correct aggregator.
+  -->
+  <aggregates>
+    <!--
+      Defines an aggregate that handles nt:file and nt:resource nodes.
+    -->
+    <aggregate type="file" title="File Aggregate"/>
+
+    <!--
+      Defines an aggregate that handles file/folder like nodes. It matches
+      all nt:hierarchyNode nodes that have or define a jcr:content
+      child node and excludes child nodes that are nt:hierarchyNodes.
+    -->
+    <aggregate type="filefolder" title="File/Folder Aggregate"/>
+
+    <!--
+      Defines an aggregate that handles nt:nodeType nodes and serializes
+      them into .cnd notation.
+    -->
+    <aggregate type="nodetype" title="Node Type Aggregate" />
+
+    <!--
+      Defines an aggregate that defines full coverage for certain node
+      types that cannot be covered by the default aggregator.
+    -->
+    <aggregate type="full" title="Full Coverage Aggregate">
+      <matches>
+        <include nodeType="rep:AccessControl" respectSupertype="true" />
+        <include nodeType="cq:Widget" respectSupertype="true" />
+        <include nodeType="cq:WidgetCollection" respectSupertype="true" />
+        <include nodeType="cq:EditConfig" respectSupertype="true" />
+        <include nodeType="cq:WorkflowModel" respectSupertype="true" />
+        <include nodeType="vlt:FullCoverage" respectSupertype="true" />
+        <include nodeType="mix:language" respectSupertype="true" />
+        <include nodeType="sling:OsgiConfig" respectSupertype="true" />
+      </matches>
+    </aggregate>
+
+    <!--
+      Defines an aggregate that handles nt:folder like nodes.
+    -->
+    <aggregate type="generic" title="Folder Aggregate">
+      <matches>
+        <include nodeType="nt:folder" respectSupertype="true" />
+      </matches>
+      <contains>
+        <exclude isNode="true" />
+      </contains>
+    </aggregate>
+
+    <!--
+      Defines the default aggregate
+    -->
+    <aggregate type="generic" title="Default Aggregator" isDefault="true">
+      <contains>
+        <exclude nodeType="nt:hierarchyNode" respectSupertype="true" />
+      </contains>
+      <matches>
+        <!-- all -->
+      </matches>
+    </aggregate>
+
+  </aggregates>
+
+  <!--
+    defines the input handlers
+  -->
+  <handlers>
+    <handler type="folder"/>
+    <handler type="file"/>
+    <handler type="nodetype"/>
+    <handler type="generic"/>
+  </handlers>
+
+</vaultfs>
diff --git a/content-package-2-feature-model/src/main/resources/org/apache/sling/cp2fm/definition/.content.xml b/content-package-2-feature-model/src/main/resources/org/apache/sling/cp2fm/definition/.content.xml
new file mode 100644
index 0000000..abf67f1
--- /dev/null
+++ b/content-package-2-feature-model/src/main/resources/org/apache/sling/cp2fm/definition/.content.xml
@@ -0,0 +1,19 @@
+<?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:vlt="http://www.day.com/jcr/vault/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
+  jcr:primaryType="vlt:PackageDefinition" />
diff --git a/content-package-2-feature-model/src/main/resources/org/apache/sling/cp2fm/settings.xml b/content-package-2-feature-model/src/main/resources/org/apache/sling/cp2fm/settings.xml
new file mode 100644
index 0000000..679e6b1
--- /dev/null
+++ b/content-package-2-feature-model/src/main/resources/org/apache/sling/cp2fm/settings.xml
@@ -0,0 +1,22 @@
+<?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.
+  -->
+<vault version="1.0">
+  <ignore name=".git" />
+  <ignore name=".svn" />
+  <ignore name=".DS_Store" />
+</vault>
\ No newline at end of file
diff --git a/content-package-2-feature-model/src/test/java/org/apache/sling/cp2fm/ContentPackage2FeatureModelConverterTest.java b/content-package-2-feature-model/src/test/java/org/apache/sling/cp2fm/ContentPackage2FeatureModelConverterTest.java
index 72834ad..4a36440 100644
--- a/content-package-2-feature-model/src/test/java/org/apache/sling/cp2fm/ContentPackage2FeatureModelConverterTest.java
+++ b/content-package-2-feature-model/src/test/java/org/apache/sling/cp2fm/ContentPackage2FeatureModelConverterTest.java
@@ -30,6 +30,7 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 import java.util.StringTokenizer;
+import java.util.zip.ZipFile;
 
 import org.apache.commons.io.FileUtils;
 import org.apache.jackrabbit.vault.packaging.VaultPackage;
@@ -139,6 +140,20 @@ public class ContentPackage2FeatureModelConverterTest {
                           "org.apache.sling:asd.retail.all:slingosgifeature:cp2fm-converted-feature-publish:0.0.1",
                           Arrays.asList("org.apache.sling:org.apache.sling.models.api:1.3.8"),
                           Arrays.asList("org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.amended-asd-retail"));
+
+        ZipFile zipFile = new ZipFile(new File(outputDirectory, "bundles/org/apache/sling/asd.retail.all/0.0.1/asd.retail.all-0.0.1-cp2fm-converted-feature.zip"));
+        for (String expectedEntry : new String[] {
+                "jcr_root/content/asd/.content.xml",
+                "jcr_root/content/asd/resources.xml",
+                "jcr_root/apps/.content.xml",
+                "META-INF/vault/properties.xml",
+                "META-INF/vault/config.xml",
+                "META-INF/vault/settings.xml",
+                "META-INF/vault/definition/.content.xml"
+                }) {
+            assertNotNull(zipFile.getEntry(expectedEntry));
+        }
+        zipFile.close();
     }
 
     private void verifyFeatureFile(File outputDirectory,