You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2020/11/13 16:16:52 UTC

[sling-org-apache-sling-feature-extension-content] branch master updated: SLING-9909 : Check/minimize embedded/shaded classes

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

cziegeler 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 8242984  SLING-9909 : Check/minimize embedded/shaded classes
8242984 is described below

commit 82429844414e672cf5adffd673766eda3f43f780
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Fri Nov 13 17:16:29 2020 +0100

    SLING-9909 : Check/minimize embedded/shaded classes
---
 pom.xml                                            | 104 +++++----------------
 .../feature/extension/content/ContentHandler.java  |  16 +---
 .../extension/content/ContentHandlerTest.java      |   5 +-
 3 files changed, 32 insertions(+), 93 deletions(-)

diff --git a/pom.xml b/pom.xml
index 4be7295..ebed496 100644
--- a/pom.xml
+++ b/pom.xml
@@ -56,43 +56,17 @@
                         </goals>
                         <configuration>
                           <minimizeJar>true</minimizeJar>
-                          <filters>
-                            <filter>
-                              <includes>
-                                <include>org.apache.commons:collections:*</include>
-                              </includes>
-                            </filter>
-                          </filters>
                           <relocations>
                             <relocation>
-                              <pattern>javax.jcr</pattern>
-                              <shadedPattern>shaded.javax.jcr</shadedPattern>
-                              <includes>
-                                <include>javax.jcr.**</include>
-                              </includes>
+                              <pattern>org.apache.jackrabbit</pattern>
+                              <shadedPattern>shaded.org.apache.jackrabbit</shadedPattern>
                             </relocation>
                             <relocation>
-                              <pattern>org.slf4j</pattern>
-                              <shadedPattern>shaded.org.slf4j</shadedPattern>
-                              <includes>
-                                <include>org.slf4j.**</include>
-                              </includes>
+                              <pattern>org.apache.commons</pattern>
+                              <shadedPattern>shaded.org.apache.commons</shadedPattern>
                             </relocation>
-                            <relocation>
-                              <pattern>org.osgi</pattern>
-                              <shadedPattern>shaded.org.osgi</shadedPattern>
-                              <includes>
-                                <include>org.osgi.util.**</include>
-                              </includes>
-                            </relocation>
-                            <relocation>
-                              <pattern>org.apache</pattern>
-                              <shadedPattern>shaded.org.apache</shadedPattern>
-                              <excludes>
-                                <exclude>org.apache.sling.feature.**</exclude>
-                              </excludes>
-                            </relocation>
-                            <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>
@@ -114,15 +88,8 @@
     </build>
     <dependencies>
         <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>osgi.core</artifactId>
-            <version>6.0.0</version>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.jackrabbit.vault</groupId>
-            <artifactId>org.apache.jackrabbit.vault</artifactId>
-            <version>3.2.6</version>
+            <groupId>javax.jcr</groupId>
+            <artifactId>jcr</artifactId>
             <scope>compile</scope>
         </dependency>
         <dependency>
@@ -132,68 +99,45 @@
             <scope>provided</scope>
         </dependency>
         <dependency>
-            <groupId>org.apache.sling</groupId>
-            <artifactId>org.apache.sling.feature.launcher</artifactId>
-            <version>1.1.10</version>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.slf4j</groupId>
-            <artifactId>slf4j-api</artifactId>
-            <scope>compile</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.slf4j</groupId>
-            <artifactId>slf4j-nop</artifactId>
-            <version>1.7.25</version>
-            <scope>compile</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.sling</groupId>
-            <artifactId>org.apache.sling.commons.johnzon</artifactId>
-            <version>1.0.0</version>
-            <scope>compile</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.converter</artifactId>
-            <version>1.0.0</version>
+            <groupId>org.apache.jackrabbit.vault</groupId>
+            <artifactId>org.apache.jackrabbit.vault</artifactId>
+            <version>3.2.6</version>
             <scope>compile</scope>
         </dependency>
         <dependency>
             <groupId>org.apache.sling</groupId>
-            <artifactId>org.apache.sling.jcr.jcr-wrapper</artifactId>
-            <version>2.0.0</version>
-            <scope>compile</scope>
+            <artifactId>org.apache.sling.feature.launcher</artifactId>
+            <version>1.1.10</version>
+            <scope>provided</scope>
         </dependency>
         <dependency>
+            <groupId>org.apache.jackrabbit</groupId>
             <artifactId>jackrabbit-spi-commons</artifactId>
             <version>2.17.3</version>
-            <groupId>org.apache.jackrabbit</groupId>
             <scope>compile</scope>
         </dependency>
         <dependency>
+            <groupId>commons-io</groupId>
             <artifactId>commons-io</artifactId>
             <version>2.6</version>
-            <groupId>commons-io</groupId>
             <scope>compile</scope>
         </dependency>
         <dependency>
-            <artifactId>jackrabbit-jcr-commons</artifactId>
-            <version>2.17.3</version>
-            <groupId>org.apache.jackrabbit</groupId>
+            <groupId>commons-collections</groupId>
+            <artifactId>commons-collections</artifactId>
+            <version>3.2.2</version>
             <scope>compile</scope>
         </dependency>
         <dependency>
-            <artifactId>jackrabbit-spi</artifactId>
-            <version>2.17.3</version>
             <groupId>org.apache.jackrabbit</groupId>
+            <artifactId>jackrabbit-jcr-commons</artifactId>
+            <version>2.17.3</version>
             <scope>compile</scope>
         </dependency>
         <dependency>
-            <groupId>commons-cli</groupId>
-            <artifactId>commons-cli</artifactId>
-            <version>1.3.1</version>
+            <groupId>org.apache.jackrabbit</groupId>
+            <artifactId>jackrabbit-spi</artifactId>
+            <version>2.17.3</version>
             <scope>compile</scope>
         </dependency>
         <!-- Testing -->
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 bd7bdad..5bfe091 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,10 +18,7 @@ package org.apache.sling.feature.extension.content;
 
 import java.io.ByteArrayOutputStream;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.InputStream;
 import java.net.URL;
 import java.nio.file.Paths;
 import java.util.ArrayList;
@@ -32,7 +29,6 @@ import java.util.Map;
 import java.util.Set;
 import java.util.TreeMap;
 
-import org.apache.commons.collections.map.MultiValueMap;
 import org.apache.jackrabbit.vault.packaging.PackageId;
 import org.apache.jackrabbit.vault.packaging.SubPackageHandling;
 import org.apache.jackrabbit.vault.packaging.registry.ExecutionPlanBuilder;
@@ -109,7 +105,7 @@ public class ContentHandler implements ExtensionHandler {
         File registryHome = getRegistryHomeDir(context);
         if (extension.getType() == ExtensionType.ARTIFACTS
                 && extension.getName().equals(Extension.EXTENSION_NAME_CONTENT_PACKAGES)) {
-            MultiValueMap orderedArtifacts = MultiValueMap.decorate(new TreeMap<Integer, Collection<Artifact>>());
+            Map<Integer, Collection<Artifact>> orderedArtifacts = new TreeMap<>();
             for (final Artifact a : extension.getArtifacts()) {
                 int order;
                 // content-packages without explicit start-order to be installed last
@@ -118,20 +114,19 @@ public class ContentHandler implements ExtensionHandler {
                 } else {
                     order = Integer.MAX_VALUE;
                 }
-                orderedArtifacts.put(order, a);
+                orderedArtifacts.computeIfAbsent(order, id -> new ArrayList<>()).add(a);
             }
             List<String> executionPlans = new ArrayList<String>();
             Set<PackageId> satisfiedPackages = new HashSet<>();
             for (Object key : orderedArtifacts.keySet()) {
-                @SuppressWarnings("unchecked")
-                Collection<Artifact> artifacts = orderedArtifacts.getCollection(key);
+                Collection<Artifact> artifacts = orderedArtifacts.get(key);
                 ExecutionPlanBuilder builder = buildExecutionPlan(artifacts, satisfiedPackages, context, registryHome);
                 ByteArrayOutputStream baos = new ByteArrayOutputStream();
                 builder.save(baos);
                 executionPlans.add(baos.toString("UTF-8"));
             }
             // Workaround for too bold relocation mechanism - corresponding details at https://issues.apache.org/jira/browse/MSHADE-156
-            final Configuration initcfg = new Configuration("org.UNSHADE.apache.sling.jcr.packageinit.impl.ExecutionPlanRepoInitializer");
+            final Configuration initcfg = new Configuration("org.apache.sling.jcr.packageinit.impl.ExecutionPlanRepoInitializer");
             initcfg.getProperties().put("executionplans", executionPlans.toArray(new String[executionPlans.size()]));
             initcfg.getProperties().put("statusfilepath", registryHome.getAbsolutePath() + "/executedplans.file");
             context.addConfiguration(initcfg.getPid(), null, initcfg.getProperties());
@@ -141,8 +136,7 @@ public class ContentHandler implements ExtensionHandler {
             context.addConfiguration(registrycfg.getPid(), null, registrycfg.getProperties());
 
             return true;
-        }
-        else {
+        } else {
             return false;
         }
     }
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 7e65070..e52a138 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
@@ -31,6 +31,7 @@ import java.util.Iterator;
 import org.apache.sling.feature.Artifact;
 import org.apache.sling.feature.ArtifactId;
 import org.apache.sling.feature.Extension;
+import org.apache.sling.feature.ExtensionState;
 import org.apache.sling.feature.ExtensionType;
 import org.apache.sling.feature.launcher.spi.extensions.ExtensionContext;
 import org.junit.Before;
@@ -87,7 +88,7 @@ public class ContentHandlerTest {
     public void testMultipleStartOrders() throws Exception {
         ContentHandler ch = new ContentHandler();
         System.setProperty(ContentHandler.PACKAGEREGISTRY_HOME, testFolder.getRoot().toString());
-        Extension ext = new Extension(ExtensionType.ARTIFACTS, "content-packages", false);
+        Extension ext = new Extension(ExtensionType.ARTIFACTS, "content-packages", ExtensionState.OPTIONAL);
         Artifact artifact_a = new Artifact(TEST_PACKAGE_AID_A_10);
         Artifact artifact_b = new Artifact(TEST_PACKAGE_AID_B_10);
         Artifact artifact_c = new Artifact(TEST_PACKAGE_AID_C_10);
@@ -101,7 +102,7 @@ public class ContentHandlerTest {
         ArgumentCaptor<Dictionary<String, Object>> executionPlanCaptor = ArgumentCaptor.forClass(Dictionary.class);
 
         ch.handle(extensionContext, ext);
-        verify(extensionContext).addConfiguration(eq("org.UNSHADE.apache.sling.jcr.packageinit.impl.ExecutionPlanRepoInitializer"), any(), executionPlanCaptor.capture());
+        verify(extensionContext).addConfiguration(eq("org.apache.sling.jcr.packageinit.impl.ExecutionPlanRepoInitializer"), any(), executionPlanCaptor.capture());
         verify(extensionContext).addConfiguration(eq("org.UNSHADE.apache.jackrabbit.vault.packaging.registry.impl.FSPackageRegistry"), any(), any());
         Iterator<Dictionary<String, Object>> dictIt = executionPlanCaptor.getAllValues().iterator();
         Dictionary<String, Object> dict = dictIt.next();