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/26 09:53:16 UTC

[sling-org-apache-sling-feature-cpconverter] branch master updated: always supply the pom file, the extracted one could contain informations than can not be retrieved from the repository

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 b191061  always supply the pom file, the extracted one could contain informations than can not be retrieved from the repository
b191061 is described below

commit b191061b4e43acea5d203ec93cc862f918ac5afe
Author: stripodi <st...@192.168.1.111>
AuthorDate: Fri Apr 26 11:53:07 2019 +0200

    always supply the pom file, the extracted one could contain informations
    than can not be retrieved from the repository
---
 .../ContentPackage2FeatureModelConverter.java      | 36 +++++++---------------
 .../cpconverter/DefaultBundlesDeployer.java        | 36 ++++++++++++++--------
 .../cpconverter/handlers/BundleEntryHandler.java   | 27 ++--------------
 3 files changed, 36 insertions(+), 63 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 378ac20..d4df35c 100644
--- a/src/main/java/org/apache/sling/feature/cpconverter/ContentPackage2FeatureModelConverter.java
+++ b/src/main/java/org/apache/sling/feature/cpconverter/ContentPackage2FeatureModelConverter.java
@@ -25,7 +25,6 @@ import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
-import java.util.Objects;
 import java.util.ServiceLoader;
 
 import org.apache.jackrabbit.vault.fs.io.Archive;
@@ -46,7 +45,6 @@ import org.apache.sling.feature.cpconverter.spi.BundlesDeployer;
 import org.apache.sling.feature.cpconverter.spi.EntryHandler;
 import org.apache.sling.feature.cpconverter.vltpkg.VaultPackageAssembler;
 import org.apache.sling.feature.cpconverter.writers.FileArtifactWriter;
-import org.apache.sling.feature.cpconverter.writers.MavenPomSupplierWriter;
 import org.apache.sling.feature.io.json.FeatureJSONWriter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -55,8 +53,6 @@ public class ContentPackage2FeatureModelConverter {
 
     private static final String CONTENT_PACKAGES = "content-packages";
 
-    public static final String POM_TYPE = "pom";
-
     public static final String ZIP_TYPE = "zip";
 
     public static final String PACKAGE_CLASSIFIER = "cp2fm-converted";
@@ -141,7 +137,7 @@ public class ContentPackage2FeatureModelConverter {
     }
 
     public void addFilteringPattern(String filteringPattern) {
-        Objects.requireNonNull(filteringPattern, "Null pattern to filter resources out is not a valid filtering pattern");
+        requireNonNull(filteringPattern, "Null pattern to filter resources out is not a valid filtering pattern");
         if (filteringPattern.isEmpty()) {
             throw new IllegalArgumentException("Empty pattern to filter resources out is not a valid filtering pattern");
         }
@@ -214,7 +210,7 @@ public class ContentPackage2FeatureModelConverter {
     }
 
     public void convert(File contentPackage) throws Exception {
-        Objects.requireNonNull(contentPackage , "Null content-package can not be converted.");
+        requireNonNull(contentPackage , "Null content-package can not be converted.");
 
         if (!contentPackage.exists() || !contentPackage.isFile()) {
             throw new IllegalArgumentException("Content-package "
@@ -284,21 +280,11 @@ public class ContentPackage2FeatureModelConverter {
             // deploy the new zip content-package to the local mvn bundles dir
 
             artifactDeployer.deploy(new FileArtifactWriter(contentPackageArchive),
-                                                           targetFeature.getId().getGroupId(),
-                                                           targetFeature.getId().getArtifactId(),
-                                                           targetFeature.getId().getVersion(),
-                                                           PACKAGE_CLASSIFIER,
-                                                           ZIP_TYPE);
-
-            artifactDeployer.deploy(new MavenPomSupplierWriter(targetFeature.getId().getGroupId(),
-                                                               targetFeature.getId().getArtifactId(),
-                                                               targetFeature.getId().getVersion(),
-                                                               ZIP_TYPE),
                                     targetFeature.getId().getGroupId(),
                                     targetFeature.getId().getArtifactId(),
                                     targetFeature.getId().getVersion(),
-                                    null,
-                                    POM_TYPE);
+                                    PACKAGE_CLASSIFIER,
+                                    ZIP_TYPE);
 
             attach(null,
                    targetFeature.getId().getGroupId(),
@@ -386,8 +372,8 @@ public class ContentPackage2FeatureModelConverter {
     }
 
     public void processSubPackage(String path, File contentPackage) throws Exception {
-        Objects.requireNonNull(path, "Impossible to process a null vault package");
-        Objects.requireNonNull(contentPackage, "Impossible to process a null vault package");
+        requireNonNull(path, "Impossible to process a null vault package");
+        requireNonNull(contentPackage, "Impossible to process a null vault package");
 
         try (VaultPackage vaultPackage = packageManager.open(contentPackage, strictValidation)) {
             // scan the detected package, first
@@ -403,7 +389,7 @@ public class ContentPackage2FeatureModelConverter {
     }
 
     private void process(VaultPackage vaultPackage) throws Exception {
-        Objects.requireNonNull(vaultPackage, "Impossible to process a null vault package");
+        requireNonNull(vaultPackage, "Impossible to process a null vault package");
 
         if (getTargetFeature() == null) {
             throw new IllegalStateException("Target Feature not initialized yet, please make sure convert() method was invoked first.");
@@ -473,10 +459,10 @@ public class ContentPackage2FeatureModelConverter {
                        String version,
                        String classifier,
                        String type) {
-        Objects.requireNonNull(groupId, "Artifact can not be attached to a feature without specifying a valid 'groupId'.");
-        Objects.requireNonNull(artifactId, "Artifact can not be attached to a feature without specifying a valid 'artifactId'.");
-        Objects.requireNonNull(version, "Artifact can not be attached to a feature without specifying a valid 'version'.");
-        Objects.requireNonNull(type, "Artifact can not be attached to a feature without specifying a valid 'type'.");
+        requireNonNull(groupId, "Artifact can not be attached to a feature without specifying a valid 'groupId'.");
+        requireNonNull(artifactId, "Artifact can not be attached to a feature without specifying a valid 'artifactId'.");
+        requireNonNull(version, "Artifact can not be attached to a feature without specifying a valid 'version'.");
+        requireNonNull(type, "Artifact can not be attached to a feature without specifying a valid 'type'.");
 
         Artifact artifact = new Artifact(new ArtifactId(groupId, artifactId, version, classifier, type));
 
diff --git a/src/main/java/org/apache/sling/feature/cpconverter/DefaultBundlesDeployer.java b/src/main/java/org/apache/sling/feature/cpconverter/DefaultBundlesDeployer.java
index 7921074..8d86b5a 100644
--- a/src/main/java/org/apache/sling/feature/cpconverter/DefaultBundlesDeployer.java
+++ b/src/main/java/org/apache/sling/feature/cpconverter/DefaultBundlesDeployer.java
@@ -16,14 +16,16 @@
  */
 package org.apache.sling.feature.cpconverter;
 
+import static java.util.Objects.requireNonNull;
+
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.util.Objects;
 import java.util.StringTokenizer;
 
 import org.apache.sling.feature.cpconverter.spi.ArtifactWriter;
 import org.apache.sling.feature.cpconverter.spi.BundlesDeployer;
+import org.apache.sling.feature.cpconverter.writers.MavenPomSupplierWriter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -47,16 +49,16 @@ public final class DefaultBundlesDeployer implements BundlesDeployer {
 
     @Override
     public void deploy(ArtifactWriter artifactWriter,
-                              String groupId,
-                              String artifactId,
-                              String version,
-                              String classifier,
-                              String type) throws IOException {
-        Objects.requireNonNull(artifactWriter, "Null ArtifactWriter can not install an artifact to a Maven repository.");
-        Objects.requireNonNull(groupId, "Bundle can not be installed to a Maven repository without specifying a valid 'groupId'.");
-        Objects.requireNonNull(artifactId, "Bundle can not be installed to a Maven repository without specifying a valid 'artifactId'.");
-        Objects.requireNonNull(version, "Bundle can not be installed to a Maven repository without specifying a valid 'version'.");
-        Objects.requireNonNull(type, "Bundle can not be installed to a Maven repository without specifying a valid 'type'.");
+                       String groupId,
+                       String artifactId,
+                       String version,
+                       String classifier,
+                       String type) throws IOException {
+        requireNonNull(artifactWriter, "Null ArtifactWriter can not install an artifact to a Maven repository.");
+        requireNonNull(groupId, "Bundle can not be installed to a Maven repository without specifying a valid 'groupId'.");
+        requireNonNull(artifactId, "Bundle can not be installed to a Maven repository without specifying a valid 'artifactId'.");
+        requireNonNull(version, "Bundle can not be installed to a Maven repository without specifying a valid 'version'.");
+        requireNonNull(type, "Bundle can not be installed to a Maven repository without specifying a valid 'type'.");
 
         File targetDir = artifactsDirectory;
 
@@ -67,11 +69,11 @@ public final class DefaultBundlesDeployer implements BundlesDeployer {
         }
 
         targetDir = new File(targetDir, artifactId);
-
         targetDir = new File(targetDir, version);
-
         targetDir.mkdirs();
 
+        // deploy the main artifact
+
         StringBuilder nameBuilder = new StringBuilder()
                                     .append(artifactId)
                                     .append('-')
@@ -92,6 +94,14 @@ public final class DefaultBundlesDeployer implements BundlesDeployer {
         }
 
         logger.info("Data successfully written to {}.", targetFile);
+
+        // automatically deploy the supplied POM file
+
+        targetFile = new File(targetDir, String.format("%s-%s.pom", artifactId, version));
+
+        try (FileOutputStream targetStream = new FileOutputStream(targetFile)) {
+            new MavenPomSupplierWriter(groupId, artifactId, version, type).write(targetStream);
+        }
     }
 
 }
diff --git a/src/main/java/org/apache/sling/feature/cpconverter/handlers/BundleEntryHandler.java b/src/main/java/org/apache/sling/feature/cpconverter/handlers/BundleEntryHandler.java
index 283cf12..8412eb6 100644
--- a/src/main/java/org/apache/sling/feature/cpconverter/handlers/BundleEntryHandler.java
+++ b/src/main/java/org/apache/sling/feature/cpconverter/handlers/BundleEntryHandler.java
@@ -16,26 +16,21 @@
  */
 package org.apache.sling.feature.cpconverter.handlers;
 
+import static java.util.Objects.requireNonNull;
 import static org.apache.jackrabbit.vault.packaging.PackageProperties.NAME_VERSION;
-import static org.apache.sling.feature.cpconverter.ContentPackage2FeatureModelConverter.POM_TYPE;
 
-import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
-import java.util.Objects;
 import java.util.Properties;
 import java.util.jar.JarEntry;
 import java.util.jar.JarInputStream;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import org.apache.commons.io.IOUtils;
 import org.apache.jackrabbit.vault.fs.io.Archive;
 import org.apache.jackrabbit.vault.fs.io.Archive.Entry;
 import org.apache.sling.feature.cpconverter.ContentPackage2FeatureModelConverter;
-import org.apache.sling.feature.cpconverter.spi.ArtifactWriter;
 import org.apache.sling.feature.cpconverter.writers.InputStreamArtifactWriter;
-import org.apache.sling.feature.cpconverter.writers.MavenPomSupplierWriter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -51,8 +46,6 @@ public final class BundleEntryHandler extends AbstractRegexEntryHandler {
 
     private final Pattern pomPropertiesPattern = Pattern.compile("META-INF/maven/[^/]+/[^/]+/pom.properties");
 
-    private final Pattern pomXmlPattern = Pattern.compile("META-INF/maven/[^/]+/[^/]+/pom.xml");
-
     public BundleEntryHandler() {
         super("(jcr_root)?/apps/[^/]+/install(\\.([^/]+))?/.+\\.jar");
     }
@@ -62,7 +55,6 @@ public final class BundleEntryHandler extends AbstractRegexEntryHandler {
         logger.info("Processing bundle {}...", entry.getName());
 
         Properties properties = new Properties();
-        byte[] pomXml = null;
 
         try (JarInputStream jarInput = new JarInputStream(archive.openInputStream(entry));
                 ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
@@ -74,11 +66,6 @@ public final class BundleEntryHandler extends AbstractRegexEntryHandler {
                     logger.info("Reading '{}' bundle GAV from {}...", entry.getName(), entryName);
 
                     properties.load(jarInput);
-                } else if (pomXmlPattern.matcher(entryName).matches()) {
-                    logger.info("Reading '{}' POM file from {}...", entry.getName(), entryName);
-
-                    IOUtils.copy(jarInput, baos);
-                    pomXml = baos.toByteArray();
                 }
             }
         }
@@ -116,23 +103,13 @@ public final class BundleEntryHandler extends AbstractRegexEntryHandler {
                              null,
                              JAR_TYPE);
         }
-
-        ArtifactWriter pomWriter;
-        if (pomXml == null) {
-            pomWriter = new MavenPomSupplierWriter(groupId, artifactId, version, JAR_TYPE);
-        } else {
-            pomWriter = new InputStreamArtifactWriter(new ByteArrayInputStream(pomXml));
-        }
-
-        converter.getArtifactDeployer().deploy(pomWriter, groupId, artifactId, version, null, POM_TYPE);
     }
 
     private static String getCheckedProperty(Properties properties, String name) {
         String property = properties.getProperty(name).trim();
-        Objects.requireNonNull(property, "Bundle can not be defined as a valid Maven artifact without specifying a valid '"
+        return requireNonNull(property, "Bundle can not be defined as a valid Maven artifact without specifying a valid '"
                                          + name
                                          + "' property.");
-        return property;
     }
 
 }