sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject [sling-org-apache-sling-feature-cpconverter] branch multiple-packages-conversion updated: SLING-8390 - Converter not handling serviceusers and acls spread across multiple packages
Date Mon, 06 May 2019 08:51:36 GMT
This is an automated email from the ASF dual-hosted git repository.

simonetripodi pushed a commit to branch multiple-packages-conversion
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-cpconverter.git


The following commit(s) were added to refs/heads/multiple-packages-conversion by this push:
     new 15a1c64  SLING-8390 - Converter not handling serviceusers and acls spread across
multiple packages
15a1c64 is described below

commit 15a1c649ca6c8e2feaed1a19da8aa6af471db5fb
Author: stripodi <stripodi@simos-mbp>
AuthorDate: Mon May 6 10:51:29 2019 +0200

    SLING-8390 - Converter not handling serviceusers and acls spread across
    multiple packages
    
    added missing license header
    minor format
---
 ...ntentPackage2FeatureModelConverterLauncher.java | 31 ++++++++--------
 ...tPackage2FeatureModelConverterLauncherTest.java | 43 ++++++++++++++++------
 2 files changed, 46 insertions(+), 28 deletions(-)

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 f0e811c..22834bf 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
@@ -152,45 +152,44 @@ public final class ContentPackage2FeatureModelConverterLauncher implements
Runna
         logger.info( "+-----------------------------------------------------+" );
     }
 
-    protected List<File> order(List<File> contentPackages, final Logger logger)
throws CyclicDependencyException {
-        
-        LinkedHashMap<PackageId, File> idFileMap = new LinkedHashMap<>();
-        
+    protected List<File> order(List<File> contentPackages, final Logger logger)
throws Exception {
+        Map<PackageId, File> idFileMap = new LinkedHashMap<>();
         Map<ZipVaultPackage, File> packageFileMapping = new HashMap<>();
         Map<PackageId, ZipVaultPackage> idPackageMapping = new HashMap<>();
-        
+
         for (File file : contentPackages) {
             try {
                 ZipVaultPackage pack = new ZipVaultPackage(file, false, true);
                 packageFileMapping.put(pack, file);
                 idPackageMapping.put(pack.getId(), pack);
             } catch (IOException e) {
-                String msg = String.format("Package couldn't be parsed as ZipVaultPackage
%s", file.getAbsolutePath());
-                logger.error(msg);
-                System.exit(1);
+                String errorMessage = String.format("Package couldn't be parsed as ZipVaultPackage
%s", file.getAbsolutePath());
+                throw new Exception(errorMessage);
             }
         }
-        
 
         for (ZipVaultPackage pack : packageFileMapping.keySet()) {
             orderDependencies(idFileMap, packageFileMapping, idPackageMapping, pack, new
HashSet<PackageId>());
         }
-        
+
         return new LinkedList<>(idFileMap.values());
     }
 
-    private void orderDependencies(LinkedHashMap<PackageId, File> idFileMap,
-            Map<ZipVaultPackage, File> packageFileMapping, Map<PackageId, ZipVaultPackage>
idPackageMapping,
-            ZipVaultPackage pack, Set<PackageId> visited) throws CyclicDependencyException
{
-        if(visited.contains(pack.getId())) {
-            throw new CyclicDependencyException();
+    private void orderDependencies(Map<PackageId, File> idFileMap,
+                                   Map<ZipVaultPackage, File> packageFileMapping,
+                                   Map<PackageId, ZipVaultPackage> idPackageMapping,
+                                   ZipVaultPackage pack,
+                                   Set<PackageId> visited) throws CyclicDependencyException
{
+        if (visited.contains(pack.getId())) {
+            throw new CyclicDependencyException("Cyclic dependency detected, " + pack.getId()
+ " was previously visited already");
         }
         visited.add(pack.getId());
         Dependency[] deps = pack.getDependencies();
         for (Dependency dep : deps) {
             for (PackageId id : new HashSet<>(idPackageMapping.keySet())) {
                 if (dep.matches(id)) {
-                    orderDependencies(idFileMap, packageFileMapping, idPackageMapping, idPackageMapping.get(id),
visited);
+                    orderDependencies(idFileMap, packageFileMapping, idPackageMapping, idPackageMapping.get(id),
+                            visited);
                     break;
                 }
             }
diff --git a/src/test/java/org/apache/sling/feature/cpconverter/cli/ContentPackage2FeatureModelConverterLauncherTest.java
b/src/test/java/org/apache/sling/feature/cpconverter/cli/ContentPackage2FeatureModelConverterLauncherTest.java
index 24f4696..d269c4c 100644
--- a/src/test/java/org/apache/sling/feature/cpconverter/cli/ContentPackage2FeatureModelConverterLauncherTest.java
+++ b/src/test/java/org/apache/sling/feature/cpconverter/cli/ContentPackage2FeatureModelConverterLauncherTest.java
@@ -1,3 +1,19 @@
+/*
+ * 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.feature.cpconverter.cli;
 
 import static org.junit.Assert.assertEquals;
@@ -15,23 +31,27 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class ContentPackage2FeatureModelConverterLauncherTest {
-    
+
     /**
      * Test package A-1.0. Depends on B and C-1.X
      * Test package B-1.0. Depends on C
      */
-    private static String[] TEST_PACKAGES_INPUT = {"test_c-1.0.zip","test_a-1.0.zip","test_b-1.0.zip"};

-    private static String[] TEST_PACKAGES_OUTPUT = {"test_c-1.0.zip","test_b-1.0.zip","test_a-1.0.zip"};

-    
-    private static String[] TEST_PACKAGES_CYCLIC_DEPENDENCY = {"test_d-1.0.zip","test_c-1.0.zip","test_a-1.0.zip","test_b-1.0.zip","test_e-1.0.zip"};

-    
+    private static String[] TEST_PACKAGES_INPUT = { "test_c-1.0.zip", "test_a-1.0.zip", "test_b-1.0.zip"
}; 
+
+    private static String[] TEST_PACKAGES_OUTPUT = { "test_c-1.0.zip", "test_b-1.0.zip",
"test_a-1.0.zip" }; 
+
+    private static String[] TEST_PACKAGES_CYCLIC_DEPENDENCY = { "test_d-1.0.zip",
+                                                                "test_c-1.0.zip",
+                                                                "test_a-1.0.zip",
+                                                                "test_b-1.0.zip",
+                                                                "test_e-1.0.zip" }; 
 
     @Test
-    public void testPackageOrdering() throws CyclicDependencyException {
+    public void testPackageOrdering() throws Exception {
         ContentPackage2FeatureModelConverterLauncher launcher = new ContentPackage2FeatureModelConverterLauncher();
         Logger logger = LoggerFactory.getLogger("test");
         List<File> contentPackages = new ArrayList<File>();
-        
+
         for (String pkgName : TEST_PACKAGES_INPUT) {
             URL packageUrl = getClass().getResource(pkgName);
             contentPackages.add(FileUtils.toFile(packageUrl));
@@ -42,15 +62,14 @@ public class ContentPackage2FeatureModelConverterLauncherTest {
             File next = fileIt.next();
             assertEquals(expected, next.getName());
         }
-        
     }
-    
+
     @Test(expected = CyclicDependencyException.class)
-    public void testDependencyCycle() throws CyclicDependencyException {
+    public void testDependencyCycle() throws Exception {
         ContentPackage2FeatureModelConverterLauncher launcher = new ContentPackage2FeatureModelConverterLauncher();
         Logger logger = LoggerFactory.getLogger("test");
         List<File> contentPackages = new ArrayList<File>();
-        
+
         for (String pkgName : TEST_PACKAGES_CYCLIC_DEPENDENCY) {
             URL packageUrl = getClass().getResource(pkgName);
             contentPackages.add(FileUtils.toFile(packageUrl));


Mime
View raw message