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/04/11 21:28:50 UTC

[sling-org-apache-sling-feature-cpconverter] branch master updated: added the ability to override the final Features/content-package groupId

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-org-apache-sling-feature-cpconverter.git


The following commit(s) were added to refs/heads/master by this push:
     new cbbdfe9  added the ability to override the final Features/content-package groupId
cbbdfe9 is described below

commit cbbdfe96ad719a4971471e0a8ab3f97eeea8a76a
Author: stripodi <st...@192.168.1.111>
AuthorDate: Thu Apr 11 23:28:44 2019 +0200

    added the ability to override the final Features/content-package groupId
---
 .../ContentPackage2FeatureModelConverter.java      | 56 +++++++++++++---------
 ...ntentPackage2FeatureModelConverterLauncher.java |  6 ++-
 2 files changed, 39 insertions(+), 23 deletions(-)

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 e67b04f..966728c 100644
--- a/src/main/java/org/apache/sling/feature/cpconverter/ContentPackage2FeatureModelConverter.java
+++ b/src/main/java/org/apache/sling/feature/cpconverter/ContentPackage2FeatureModelConverter.java
@@ -92,6 +92,8 @@ public class ContentPackage2FeatureModelConverter {
 
     private VaultPackageAssembler mainPackageAssembler = null;
 
+    private String groupId;
+
     public ContentPackage2FeatureModelConverter setStrictValidation(boolean strictValidation) {
         this.strictValidation = strictValidation;
         return this;
@@ -142,6 +144,11 @@ public class ContentPackage2FeatureModelConverter {
         filter.addFilteringPattern(filteringPattern);
     }
 
+    public ContentPackage2FeatureModelConverter setGroupId(String groupId) {
+        this.groupId = groupId;
+        return this;
+    }
+
     public Feature getRunMode(String runMode) {
         if (getTargetFeature() == null) {
             throw new IllegalStateException("Target Feature not initialized yet, please make sure convert() method was invoked first.");
@@ -164,6 +171,20 @@ public class ContentPackage2FeatureModelConverter {
         return artifactDeployer;
     }
 
+    private static void checkDirectory(File directory, String name) {
+        if (directory == null) {
+            throw new IllegalStateException("Null " + name + " output directory not supported, it must be set before invoking the convert(File) method.");
+        }
+
+        if (!directory.exists() && !directory.mkdirs()) {
+            throw new IllegalStateException("output directory "
+                                            + directory
+                                            + " does not exist and can not be created, please make sure current user '"
+                                            + System.getProperty("user.name")
+                                            + " has enough rights to write on the File System.");
+        }
+    }
+
     public void convert(File contentPackage) throws Exception {
         Objects.requireNonNull(contentPackage , "Null content-package can not be converted.");
 
@@ -173,15 +194,8 @@ public class ContentPackage2FeatureModelConverter {
                                             + " does not exist or it is not a valid file.");
         }
 
-        if (artifactsOutputDirectory == null) {
-            throw new IllegalStateException("Null artifacts output directory not supported, it must be set before invoking the convert(File) method.");
-        }
-
-        if (featureModelsOutputDirectory == null) {
-            throw new IllegalStateException("Null models output directory not supported, it must be set before invoking the convert(File) method.");
-        } else if (!featureModelsOutputDirectory.exists()) {
-            featureModelsOutputDirectory.mkdirs();
-        }
+        checkDirectory(artifactsOutputDirectory, "artifacts");
+        checkDirectory(featureModelsOutputDirectory, "models");
 
         Iterator<BundlesDeployer> artifactDeployerLoader = ServiceLoader.load(BundlesDeployer.class).iterator();
         if (!artifactDeployerLoader.hasNext()) {
@@ -190,14 +204,6 @@ public class ContentPackage2FeatureModelConverter {
             artifactDeployer = artifactDeployerLoader.next();
         }
 
-        if (!artifactsOutputDirectory.exists() && !artifactsOutputDirectory.mkdirs()) {
-            throw new IllegalStateException("output directory "
-                                            + artifactsOutputDirectory
-                                            + " does not exist and can not be created, please make sure current user '"
-                                            + System.getProperty("user.name")
-                                            + " has enough rights to write on the File System.");
-        }
-
         logger.info("Reading content-package '{}'...", contentPackage);
 
         try (VaultPackage vaultPackage = packageManager.open(contentPackage, strictValidation)) {
@@ -206,11 +212,17 @@ public class ContentPackage2FeatureModelConverter {
             mainPackageAssembler = VaultPackageAssembler.create(vaultPackage);
 
             PackageProperties packageProperties = vaultPackage.getProperties();
-            String group = requireNonNull(packageProperties.getProperty(PackageProperties.NAME_GROUP),
-                                          PackageProperties.NAME_GROUP
-                                          + " property not found in content-package "
-                                          + contentPackage
-                                          + ", please check META-INF/vault/properties.xml");
+            String group;
+            if (groupId != null && !groupId.isEmpty()) {
+                group = groupId;
+            } else {
+                group = requireNonNull(packageProperties.getProperty(PackageProperties.NAME_GROUP),
+                                       "'packageGroupId' parameter not specified and "
+                                       + PackageProperties.NAME_GROUP
+                                       + " property not found in content-package "
+                                       + contentPackage
+                                       + ", please check META-INF/vault/properties.xml");
+            }
             String name = requireNonNull(packageProperties.getProperty(PackageProperties.NAME_NAME),
                                          PackageProperties.NAME_NAME
                                          + " property not found in content-package "
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 cba9553..2943f82 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
@@ -67,6 +67,9 @@ public final class ContentPackage2FeatureModelConverterLauncher implements Runna
     @Option(names = { "-o", "--features-output-directory" }, description = "The output directory where the Feature File will be generated.", required = true)
     private File featureModelsOutputDirectory;
 
+    @Option(names = { "-g", "--groupId" }, description = "The output directory where the Feature File will be generated.", required = false)
+    private String groupId;
+
     @Override
     public void run() {
         if (quiet) {
@@ -100,7 +103,8 @@ public final class ContentPackage2FeatureModelConverterLauncher implements Runna
                                                              .setMergeConfigurations(mergeConfigurations)
                                                              .setBundlesStartOrder(bundlesStartOrder)
                                                              .setArtifactsOutputDirectory(artifactsOutputDirectory)
-                                                             .setFeatureModelsOutputDirectory(featureModelsOutputDirectory);
+                                                             .setFeatureModelsOutputDirectory(featureModelsOutputDirectory)
+                                                             .setGroupId(groupId);
 
             if (filteringPatterns != null && filteringPatterns.length > 0) {
                 for (String filteringPattern : filteringPatterns) {