You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by kw...@apache.org on 2021/05/31 16:05:02 UTC

[sling-org-apache-sling-feature-extension-content] branch master updated: SLING-10405 update FileVault to 3.5.0 (#16)

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

kwin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-extension-content.git


The following commit(s) were added to refs/heads/master by this push:
     new a175727  SLING-10405 update FileVault to 3.5.0 (#16)
a175727 is described below

commit a17572730f020bda83d32f2e76a3a43656fac15f
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Mon May 31 18:04:55 2021 +0200

    SLING-10405 update FileVault to 3.5.0 (#16)
    
    SLING-10417 always install packages in strict mode
    Get rid of subpackage handling, as dealt with transparently during
    package extraction
    Shade and relocate everything not provided by launcher
---
 pom.xml                                            | 139 +++++++++++++++------
 .../feature/extension/content/ContentHandler.java  |  42 +++----
 .../extension/content/ContentHandlerTest.java      |  27 +++-
 3 files changed, 139 insertions(+), 69 deletions(-)

diff --git a/pom.xml b/pom.xml
index 09cc84a..aff5be3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -40,6 +40,9 @@
     <properties>
         <jdk.version>8</jdk.version>
         <surefire.plugin.version>3.0.0-M3</surefire.plugin.version>
+        <jackrabbit.version>2.18.0</jackrabbit.version>
+        <!-- must be unique to prevent classloader clashes in the loader -->
+        <relocated.package.prefix>relocated-for-contentpackage.</relocated.package.prefix>
     </properties>
 
 
@@ -55,22 +58,62 @@
                             <goal>shade</goal>
                         </goals>
                         <configuration>
-                          <minimizeJar>true</minimizeJar>
-                          <relocations>
-                            <relocation>
-                              <pattern>org.apache.jackrabbit</pattern>
-                              <shadedPattern>shaded.org.apache.jackrabbit</shadedPattern>
-                            </relocation>
-                            <relocation>
-                              <pattern>org.apache.commons</pattern>
-                              <shadedPattern>shaded.org.apache.commons</shadedPattern>
-                            </relocation>
-			    <!-- This is required for the OSGi configuration PIDs used in the code, otherwise they get shaded as well -->
-			    <relocation>
-                              <pattern>org.UNSHADE.apache</pattern>
-                              <shadedPattern>org.apache</shadedPattern>
-                            </relocation>
-                          </relocations>
+                            <relocations>
+                                <!-- shade and relocate all "compile" scope dependencies (which are not coming with the launcher) -->
+                                <relocation>
+                                    <pattern>org.apache.jackrabbit</pattern>
+                                    <shadedPattern>${relocated.package.prefix}org.apache.jackrabbit</shadedPattern>
+                                </relocation>
+                                <relocation>
+                                    <pattern>org.apache.commons</pattern>
+                                    <shadedPattern>${relocated.package.prefix}org.apache.commons</shadedPattern>
+                                </relocation>
+                                <relocation>
+                                    <pattern>org.apache.commons</pattern>
+                                    <shadedPattern>${relocated.package.prefix}org.apache.commons</shadedPattern>
+                                </relocation>
+                                <relocation>
+                                    <pattern>org.apache.http</pattern>
+                                    <shadedPattern>${relocated.package.prefix}org.apache.http</shadedPattern>
+                                </relocation>
+                                <relocation>
+                                    <pattern>org.apache.maven.artifact</pattern>
+                                    <shadedPattern>${relocated.package.prefix}org.apache.maven.artifact</shadedPattern>
+                                </relocation>
+                                <relocation>
+                                    <pattern>org.apache.maven.repository</pattern>
+                                    <shadedPattern>${relocated.package.prefix}org.apache.maven.repository</shadedPattern>
+                                </relocation>
+                                <relocation>
+                                    <pattern>org.codehaus.plexus.util</pattern>
+                                    <shadedPattern>${relocated.package.prefix}org.codehaus.plexus.util</shadedPattern>
+                                </relocation>
+                                <relocation>
+                                    <pattern>org.codehaus.stax2</pattern>
+                                    <shadedPattern>${relocated.package.prefix}org.codehaus.stax2</shadedPattern>
+                                </relocation>
+                                <relocation>
+                                    <pattern>org.codehaus.stax2</pattern>
+                                    <shadedPattern>${relocated.package.prefix}org.codehaus.stax2</shadedPattern>
+                                </relocation>
+                                <relocation>
+                                    <pattern>com.ctc.wstx</pattern>
+                                    <shadedPattern>${relocated.package.prefix}com.ctc.wstx</shadedPattern>
+                                </relocation>
+                                <relocation>
+                                    <pattern>com.sun.xml.txw2</pattern>
+                                    <shadedPattern>${relocated.package.prefix}com.sun.xml.txw2</shadedPattern>
+                                </relocation>
+                                <relocation>
+                                    <pattern>javax.jcr</pattern>
+                                    <shadedPattern>${relocated.package.prefix}javax.jcr</shadedPattern>
+                                </relocation>
+                                <!-- This is required for the OSGi configuration PIDs used in the code, otherwise they get shaded as well -->
+                                <relocation>
+                                    <pattern>org.UNSHADE.apache</pattern>
+                                    <shadedPattern>org.apache</shadedPattern>
+                                </relocation>
+                            </relocations>
                         </configuration>
                     </execution>
                 </executions>
@@ -88,11 +131,6 @@
     </build>
     <dependencies>
         <dependency>
-            <groupId>javax.jcr</groupId>
-            <artifactId>jcr</artifactId>
-            <scope>compile</scope>
-        </dependency>
-        <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.feature</artifactId>
             <version>1.2.14</version>
@@ -101,45 +139,68 @@
         <dependency>
             <groupId>org.apache.jackrabbit.vault</groupId>
             <artifactId>org.apache.jackrabbit.vault</artifactId>
-            <version>3.2.6</version>
+            <version>3.5.0</version>
             <scope>compile</scope>
         </dependency>
+        <!-- START: transitive dependencies with scope "provided" of vault -->
+        <!-- jackrabbit -->
         <dependency>
-            <groupId>org.apache.sling</groupId>
-            <artifactId>org.apache.sling.feature.launcher</artifactId>
-            <version>1.1.10</version>
-            <scope>provided</scope>
+            <groupId>org.apache.jackrabbit</groupId>
+            <artifactId>oak-jackrabbit-api</artifactId>
+            <version>1.38.0</version>
+            <scope>compile</scope>
         </dependency>
         <dependency>
             <groupId>org.apache.jackrabbit</groupId>
-            <artifactId>jackrabbit-spi-commons</artifactId>
-            <version>2.17.3</version>
+            <artifactId>jackrabbit-jcr-commons</artifactId>
+            <version>${jackrabbit.version}</version>
             <scope>compile</scope>
         </dependency>
         <dependency>
-            <groupId>commons-io</groupId>
-            <artifactId>commons-io</artifactId>
-            <version>2.6</version>
+            <groupId>org.apache.jackrabbit</groupId>
+            <artifactId>jackrabbit-spi-commons</artifactId>
+            <version>${jackrabbit.version}</version>
             <scope>compile</scope>
         </dependency>
         <dependency>
-            <groupId>commons-collections</groupId>
-            <artifactId>commons-collections</artifactId>
-            <version>3.2.2</version>
+            <groupId>org.apache.jackrabbit</groupId>
+            <artifactId>jackrabbit-spi</artifactId>
+            <version>${jackrabbit.version}</version>
             <scope>compile</scope>
         </dependency>
         <dependency>
             <groupId>org.apache.jackrabbit</groupId>
-            <artifactId>jackrabbit-jcr-commons</artifactId>
-            <version>2.17.3</version>
+            <artifactId>jackrabbit-spi2dav</artifactId>
+            <version>${jackrabbit.version}</version>
             <scope>compile</scope>
         </dependency>
         <dependency>
-            <groupId>org.apache.jackrabbit</groupId>
-            <artifactId>jackrabbit-spi</artifactId>
-            <version>2.17.3</version>
+            <groupId>javax.jcr</groupId>
+            <artifactId>jcr</artifactId>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.framework</artifactId>
+            <version>1.8.0</version>
+            <!-- provided by launcher -->
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+            <version>2.6</version>
             <scope>compile</scope>
         </dependency>
+        <!-- END: transitive dependencies with scope "provided" of vault -->
+
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.feature.launcher</artifactId>
+            <version>1.1.10</version>
+            <scope>provided</scope>
+        </dependency>
+        
         <!-- Testing -->
         <dependency>
             <groupId>junit</groupId>
diff --git a/src/main/java/org/apache/sling/feature/extension/content/ContentHandler.java b/src/main/java/org/apache/sling/feature/extension/content/ContentHandler.java
index 3ed80d9..80e2553 100644
--- a/src/main/java/org/apache/sling/feature/extension/content/ContentHandler.java
+++ b/src/main/java/org/apache/sling/feature/extension/content/ContentHandler.java
@@ -18,7 +18,6 @@ package org.apache.sling.feature.extension.content;
 
 import java.io.ByteArrayOutputStream;
 import java.io.File;
-import java.io.IOException;
 import java.net.URL;
 import java.nio.file.Paths;
 import java.util.ArrayList;
@@ -29,12 +28,16 @@ import java.util.Map;
 import java.util.Set;
 import java.util.TreeMap;
 
-import org.apache.jackrabbit.vault.packaging.PackageId;
+import org.apache.jackrabbit.vault.fs.io.ImportOptions;
 import org.apache.jackrabbit.vault.packaging.PackageExistsException;
-import org.apache.jackrabbit.vault.packaging.SubPackageHandling;
+import org.apache.jackrabbit.vault.packaging.PackageId;
 import org.apache.jackrabbit.vault.packaging.registry.ExecutionPlanBuilder;
 import org.apache.jackrabbit.vault.packaging.registry.PackageTask.Type;
+import org.apache.jackrabbit.vault.packaging.registry.PackageTaskOptions;
+import org.apache.jackrabbit.vault.packaging.registry.impl.AbstractPackageRegistry.SecurityConfig;
 import org.apache.jackrabbit.vault.packaging.registry.impl.FSPackageRegistry;
+import org.apache.jackrabbit.vault.packaging.registry.impl.InstallationScope;
+import org.apache.jackrabbit.vault.packaging.registry.taskoption.ImportOptionsPackageTaskOption;
 import org.apache.sling.feature.Artifact;
 import org.apache.sling.feature.Configuration;
 import org.apache.sling.feature.Extension;
@@ -58,18 +61,16 @@ public class ContentHandler implements ExtensionHandler {
         for (final Artifact a : artifacts) {
             final URL file = prepareContext.getArtifactFile(a.getId());
             File tmp = IOUtils.getFileFromURL(file, true, null);
-
-            if (tmp.length() > 0)
-            {
+            if (tmp != null) {
                 packageReferences.add(tmp);
             }
         }
 
-        if(!registryHome.exists()) {
+        if (!registryHome.exists()) {
             registryHome.mkdirs();
         }
 
-        FSPackageRegistry registry = new FSPackageRegistry(registryHome);
+        FSPackageRegistry registry = new FSPackageRegistry(registryHome, InstallationScope.UNSCOPED, new SecurityConfig(null, null), true);
 
         ExecutionPlanBuilder builder = registry.createExecutionPlan();
         builder.with(satisfiedPackages);
@@ -77,9 +78,10 @@ public class ContentHandler implements ExtensionHandler {
         for (File pkgFile : packageReferences) {
             try {
                 PackageId pid = registry.registerExternal(pkgFile, false);
-                extractSubPackages(registry, builder, pid);
-
-                builder.addTask().with(pid).with(Type.EXTRACT);
+                ImportOptions importOptions = new ImportOptions();
+                importOptions.setStrict(true);
+                PackageTaskOptions options = new ImportOptionsPackageTaskOption(importOptions);
+                builder.addTask().with(pid).withOptions(options).with(Type.EXTRACT);
             } catch (PackageExistsException ex) {
                 // Expected - the package is already present
             }
@@ -90,20 +92,6 @@ public class ContentHandler implements ExtensionHandler {
 
     }
 
-    private static void extractSubPackages(FSPackageRegistry registry, ExecutionPlanBuilder builder, PackageId pid)
-            throws IOException {
-        Map<PackageId, SubPackageHandling.Option> subPkgs = registry.getInstallState(pid).getSubPackages();
-        if (!subPkgs.isEmpty()) {
-            for (PackageId subId : subPkgs.keySet()) {
-                SubPackageHandling.Option opt = subPkgs.get(subId);
-                if (opt != SubPackageHandling.Option.IGNORE) {
-                    builder.addTask().with(subId).with(Type.EXTRACT);
-                    extractSubPackages(registry, builder, subId);
-                }
-            }
-        }
-    }
-
     @Override
     public boolean handle(ExtensionContext context, Extension extension) throws Exception {
         File registryHome = getRegistryHomeDir(context);
@@ -120,7 +108,7 @@ public class ContentHandler implements ExtensionHandler {
                 }
                 orderedArtifacts.computeIfAbsent(order, id -> new ArrayList<>()).add(a);
             }
-            List<String> executionPlans = new ArrayList<String>();
+            List<String> executionPlans = new ArrayList<>();
             Set<PackageId> satisfiedPackages = new HashSet<>();
             for (Object key : orderedArtifacts.keySet()) {
                 Collection<Artifact> artifacts = orderedArtifacts.get(key);
@@ -163,7 +151,7 @@ public class ContentHandler implements ExtensionHandler {
             registryHome.mkdirs();
         }
         if (!registryHome.isDirectory()) {
-            throw new IllegalStateException("Registry but points to file - must be directory");
+            throw new IllegalStateException("Registry home points to file - must be directory: " + registryHome);
         }
         return registryHome;
     }
diff --git a/src/test/java/org/apache/sling/feature/extension/content/ContentHandlerTest.java b/src/test/java/org/apache/sling/feature/extension/content/ContentHandlerTest.java
index e52a138..64ae766 100644
--- a/src/test/java/org/apache/sling/feature/extension/content/ContentHandlerTest.java
+++ b/src/test/java/org/apache/sling/feature/extension/content/ContentHandlerTest.java
@@ -113,15 +113,36 @@ public class ContentHandlerTest {
         final String expected_0 =
                 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                         "<executionPlan version=\"1.0\">\n" +
-                        "    <task cmd=\"extract\" packageId=\"my_packages:test_c:1.0\"/>\n" +
-                        "    <task cmd=\"extract\" packageId=\"my_packages:test_b:1.0\"/>\n" +
+                        "    <task cmd=\"extract\" packageId=\"my_packages:test_c:1.0\">\n" +
+                        "        <options type=\"ImportOptions\">\n" +
+                        "            <isStrict>true</isStrict>\n" +
+                        "            <autoSaveThreshold>-1</autoSaveThreshold>\n" +
+                        "            <nonRecursive>false</nonRecursive>\n" +
+                        "            <dryRun>false</dryRun>\n" +
+                        "        </options>\n" +
+                        "    </task>\n" +
+                        "    <task cmd=\"extract\" packageId=\"my_packages:test_b:1.0\">\n" +
+                        "        <options type=\"ImportOptions\">\n" +
+                        "            <isStrict>true</isStrict>\n" +
+                        "            <autoSaveThreshold>-1</autoSaveThreshold>\n" +
+                        "            <nonRecursive>false</nonRecursive>\n" +
+                        "            <dryRun>false</dryRun>\n" +
+                        "        </options>\n" +
+                        "    </task>\n" +
                         "</executionPlan>\n";
 
         assertEquals(expected_0, executionplans[0]);
         final String expected_1 =
                 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                         "<executionPlan version=\"1.0\">\n" +
-                        "    <task cmd=\"extract\" packageId=\"my_packages:test_a:1.0\"/>\n" +
+                        "    <task cmd=\"extract\" packageId=\"my_packages:test_a:1.0\">\n" +
+                        "        <options type=\"ImportOptions\">\n" +
+                        "            <isStrict>true</isStrict>\n" +
+                        "            <autoSaveThreshold>-1</autoSaveThreshold>\n" +
+                        "            <nonRecursive>false</nonRecursive>\n" +
+                        "            <dryRun>false</dryRun>\n" +
+                        "        </options>\n" +
+                        "    </task>\n" +
                         "</executionPlan>\n";
 
         assertEquals(expected_1, executionplans[1]);