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

kwin pushed a commit to branch feature/optionally-keep-modified-content-packages
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-cpconverter.git

commit 45e3ced301fd406dab60add70c44ef10fbe01e50
Author: Konrad Windszus <[email protected]>
AuthorDate: Mon Apr 12 12:02:03 2021 +0200

    SLING-10127 emit all converted packages to the local Maven repository
    
    expose "dropContent" as CLI option
    improve readme
---
 README.md                                               | 17 ++++++++++++-----
 .../ContentPackage2FeatureModelConverter.java           |  8 ++++----
 .../ContentPackage2FeatureModelConverterLauncher.java   |  5 ++++-
 .../ContentPackage2FeatureModelConverterTest.java       | 15 ++++++++++++---
 4 files changed, 32 insertions(+), 13 deletions(-)

diff --git a/README.md b/README.md
index 66def18..954f327 100644
--- a/README.md
+++ b/README.md
@@ -6,11 +6,11 @@ This tool aims to provide to Apache Sling users an 
easy-to-use conversion tool w
 
 ## Introduction
 
-`content-package`s are zipped archives containing OSGi bundles, OSGi 
configurations and resources (and nested `content-package`s as well), aside 
metadata, that can be used to install content into a _JCR_ repository using the 
[Apache Jackrabbit FileVault](http://jackrabbit.apache.org/filevault/) 
packaging runtime.
+`content-package`s are zipped archives containing OSGi bundles, OSGi 
configurations, JCR nodes/properties and nested `content-package`s as well, 
aside [metadata](http://jackrabbit.apache.org/filevault/metadata.html), that 
can be used to install content into a _JCR_ repository using the [Apache 
Jackrabbit FileVault](http://jackrabbit.apache.org/filevault/) packaging 
runtime.
 
 OTOH, [Apache Sling 
Feature](https://github.com/apache/sling-org-apache-sling-feature) allows users 
to describe an entire OSGi-based application based on reusable components and 
includes everything related to this application, including bundles, 
configuration, framework properties, capabilities, requirements and custom 
artifacts.
 
-The _Apache Sling Content Package to Feature Model converter_ (referred as 
_cp2fm_) is a tool able to extract OSGI bundles, OSGi configurations, resources 
and iteratively scan nested `content-package`s from an input `content-package` 
and create one (or more) _Apache Sling Feature_ model files and deploy the 
extracted OSGi bundles in a directory which structure is compliant the _Apache 
Maven_ repository conventions.
+The _Apache Sling Content Package to Feature Model converter_ (referred as 
_cp2fm_) is a tool able to extract OSGI bundles, OSGi configurations and 
iteratively scan nested `content-package`s from an input `content-package` and 
create one (or more) _Apache Sling Feature_ model files and deploy the 
extracted OSGi bundles in a directory which structure is compliant the _Apache 
Maven_ repository conventions. The remaining JCR nodes/properties are kept in 
content packages which are either ref [...]
 
 ## Understanding the Input
 
@@ -147,9 +147,14 @@ Archive:  test-content.zip
     39481                     22 files
 ```
 
+### Package Types
+
+`content-package`s have one of the 4 types defined at [Package 
Types](http://jackrabbit.apache.org/filevault/packagetypes.html).
+By default type `content` is never referenced inside the feature model (to 
work with Oak Composite Node Stores), while `application` and `mixed` type's 
are referenced in the generated feature models. `container` packages are 
dissolved and all sub packages are flattened (i.e. extracted as individual 
packages).
+
 ## Mapping and the Output
 
-All metadata are mainly collected inside one or more, depending by declared 
run modes in the installation and configuration paths, _Feature_ model files:
+All metadata are mainly collected inside one or more _Feature_ model files, 
depending on declared run modes in the installation and configuration paths:
 
 ```json
 $ cat asd.retail.all.json 
@@ -201,7 +206,9 @@ $ cat asd.retail.all-publish.json
 }
 ```
 
-### Binaries
+### OSGi Bundles and Content Packages
+
+All nodes and properties which are not OSGi configurations or bundles are kept 
in (stripped) content packages. Depending on the location of the nodes they are 
either referenced inside the Feature Model (evaluated by [Content 
Handler](https://github.com/apache/sling-org-apache-sling-feature-extension-content/blob/master/src/main/java/org/apache/sling/feature/extension/content/ContentHandler.java))
 or left completely separate from the generated Feature models. This depends on 
the package t [...]
 
 All detected bundles are collected in an _Apache Maven repository_ compliant 
directory, all other resources are collected in a new `content-package`, 
usually classified as `cp2fm-converted-feature`, created while scanning the 
packages, which contains _content only_.
 
@@ -232,7 +239,7 @@ artifacts/
 12 directories, 8 files
 ```
 
-### Supported configurations
+### OSGi Configurations
 
 All OSGi configuration formats are supported:
 
diff --git 
a/src/main/java/org/apache/sling/feature/cpconverter/ContentPackage2FeatureModelConverter.java
 
b/src/main/java/org/apache/sling/feature/cpconverter/ContentPackage2FeatureModelConverter.java
index 84bc7ac..02335bb 100644
--- 
a/src/main/java/org/apache/sling/feature/cpconverter/ContentPackage2FeatureModelConverter.java
+++ 
b/src/main/java/org/apache/sling/feature/cpconverter/ContentPackage2FeatureModelConverter.java
@@ -366,14 +366,14 @@ public class ContentPackage2FeatureModelConverter extends 
BaseVaultPackageScanne
                                     + " is of MIXED type");
             }
 
-            // don't deploy & add content-packages of type content to 
featuremodel if dropContent is set
+            // deploy the new content-package to the local mvn bundles dir
+            artifactsDeployer.deploy(new 
FileArtifactWriter(contentPackageArchive), mvnPackageId);
+            // don't add content-packages of type content to featuremodel if 
dropContent is set
             if (PackageType.CONTENT != packageType || !dropContent) {
-                // deploy the new content-package to the local mvn bundles dir 
and attach it to the feature
-                artifactsDeployer.deploy(new 
FileArtifactWriter(contentPackageArchive), mvnPackageId);
                 featuresManager.addArtifact(runMode, mvnPackageId);
             } else {
                 mutableContentsIds.put(originalPackageId, 
getDependencies(vaultPackage));
-                logger.info("Dropping package of PackageType.CONTENT {} 
(content-package id: {})",
+                logger.info("Don't reference package of PackageType.CONTENT {} 
(content-package id: {}) in feature model",
                             mvnPackageId.getArtifactId(), originalPackageId);
             }
         }
diff --git 
a/src/main/java/org/apache/sling/feature/cpconverter/cli/ContentPackage2FeatureModelConverterLauncher.java
 
b/src/main/java/org/apache/sling/feature/cpconverter/cli/ContentPackage2FeatureModelConverterLauncher.java
index 023aade..5018e2a 100644
--- 
a/src/main/java/org/apache/sling/feature/cpconverter/cli/ContentPackage2FeatureModelConverterLauncher.java
+++ 
b/src/main/java/org/apache/sling/feature/cpconverter/cli/ContentPackage2FeatureModelConverterLauncher.java
@@ -109,6 +109,9 @@ public final class 
ContentPackage2FeatureModelConverterLauncher implements Runna
 
     @Option(names = { "--remove-install-hooks" }, description = "Removes both 
internal and external hooks from processed packages", required = false)
     private boolean removeInstallHooks = false;
+    
+    @Option(names = { "--include-content-type-packages" }, description = 
"Includes content packages of package type 'content' in the resulting feature 
model", required = false)
+    private boolean includeContentTypePackages = false;
 
     @Override
     public void run() {
@@ -171,7 +174,7 @@ public final class 
ContentPackage2FeatureModelConverterLauncher implements Runna
                                                                 
.setAclManager(new DefaultAclManager(enforcePrincipalBasedSupportedPath))
                                                                 
.setEmitter(DefaultPackagesEventsEmitter.open(featureModelsOutputDirectory))
                                                                 
.setFailOnMixedPackages(failOnMixedPackages)
-                                                                
.setDropContent(true);
+                                                                
.setDropContent(!includeContentTypePackages);
 
                 try {
                     if (filteringPatterns != null && filteringPatterns.length 
> 0) {
diff --git 
a/src/test/java/org/apache/sling/feature/cpconverter/ContentPackage2FeatureModelConverterTest.java
 
b/src/test/java/org/apache/sling/feature/cpconverter/ContentPackage2FeatureModelConverterTest.java
index 8df90bc..749fd90 100644
--- 
a/src/test/java/org/apache/sling/feature/cpconverter/ContentPackage2FeatureModelConverterTest.java
+++ 
b/src/test/java/org/apache/sling/feature/cpconverter/ContentPackage2FeatureModelConverterTest.java
@@ -271,9 +271,18 @@ public class ContentPackage2FeatureModelConverterTest {
                                 "META-INF/vault/config.xml",
                                 "META-INF/vault/filter.xml",
                                 "META-INF/vault/filter-plugin-generated.xml");
-            // in contrast to previous test when dropping content packages the 
cases below would be filtered out and files wouldn'T be in cache
-            assertFalse(new File(outputDirectory, 
"asd/sample/Asd.Retail.ui.content/0.0.1/Asd.Retail.ui.content-0.0.1-cp2fm-converted.zip").exists());
-            assertFalse(new File(outputDirectory, 
"asd/sample/asd.retail.all/0.0.1/asd.retail.all-0.0.1-cp2fm-converted.zip").exists());
+            // converted packages still there, but no longer referenced
+            verifyContentPackage(new File(outputDirectory, 
"asd/sample/asd.retail.apps/0.0.1/asd.retail.apps-0.0.1-cp2fm-converted.zip"),
+                    "META-INF/vault/settings.xml",
+                    "META-INF/vault/properties.xml",
+                    "META-INF/vault/config.xml",
+                    "META-INF/vault/filter.xml",
+                    "META-INF/vault/filter-plugin-generated.xml");
+            verifyContentPackage(new File(outputDirectory, 
"asd/sample/asd.retail.all/0.0.1/asd.retail.all-0.0.1-cp2fm-converted.zip"),
+                    "META-INF/vault/settings.xml",
+                    "META-INF/vault/properties.xml",
+                    "META-INF/vault/config.xml",
+                    "META-INF/vault/filter.xml");
 
         } finally {
             deleteDirTree(outputDirectory);

Reply via email to