From dev-return-93469-archive-asf-public=cust-asf.ponee.io@sling.apache.org Fri Nov 9 11:21:06 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 1C945180627 for ; Fri, 9 Nov 2018 11:21:05 +0100 (CET) Received: (qmail 66020 invoked by uid 500); 9 Nov 2018 10:21:05 -0000 Mailing-List: contact dev-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list dev@sling.apache.org Received: (qmail 66009 invoked by uid 99); 9 Nov 2018 10:21:05 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 09 Nov 2018 10:21:05 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 88814C5CF9 for ; Fri, 9 Nov 2018 10:21:04 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -109.501 X-Spam-Level: X-Spam-Status: No, score=-109.501 tagged_above=-999 required=6.31 tests=[ENV_AND_HDR_SPF_MATCH=-0.5, KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, USER_IN_DEF_SPF_WL=-7.5, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id iv04alSUAs6I for ; Fri, 9 Nov 2018 10:21:02 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id AF8FB610CD for ; Fri, 9 Nov 2018 10:21:01 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 4772DE0E1D for ; Fri, 9 Nov 2018 10:21:01 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 68B22266D7 for ; Fri, 9 Nov 2018 10:21:00 +0000 (UTC) Date: Fri, 9 Nov 2018 10:21:00 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: dev@sling.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (SLING-8085) Incorporate layering optimizations for cross layer dependencies MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/SLING-8085?page=3Dcom.atlassian= .jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D1668= 1209#comment-16681209 ]=20 ASF GitHub Bot commented on SLING-8085: --------------------------------------- bosschaert closed pull request #4: SLING-8085 - adjusting ContentHandler to= properly incorporating layer=E2=80=A6 URL: https://github.com/apache/sling-org-apache-sling-feature-extension-con= tent/pull/4 =20 =20 =20 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/pom.xml b/pom.xml index e467dcf..a9d4c04 100644 --- a/pom.xml +++ b/pom.xml @@ -112,7 +112,7 @@ org.apache.jackrabbit.vault org.apache.jackrabbit.vault - 3.2.4 + 3.2.5-SNAPSHOT compile diff --git a/src/main/java/org/apache/sling/feature/extension/content/Conte= ntHandler.java b/src/main/java/org/apache/sling/feature/extension/content/C= ontentHandler.java index 1a57118..8f039b7 100644 --- a/src/main/java/org/apache/sling/feature/extension/content/ContentHandl= er.java +++ b/src/main/java/org/apache/sling/feature/extension/content/ContentHandl= er.java @@ -21,9 +21,12 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedHashMap; +import java.util.HashSet; + import java.util.List; import java.util.Map; +import java.util.Set; +import java.util.TreeMap; =20 import org.apache.commons.collections.map.MultiValueMap; import org.apache.jackrabbit.vault.packaging.PackageId; @@ -48,7 +51,7 @@ =20 private static final String REGISTRY_FOLDER =3D "packageregistry"; =20 - private static ExecutionPlanBuilder buildExecutionPlan(Collection artifacts, LauncherPrepareContext prepareContext, File registryHome) = throws Exception { + private static ExecutionPlanBuilder buildExecutionPlan(Collection artifacts, Set satisfiedPackages, LauncherPrepareContext p= repareContext, File registryHome) throws Exception { =20 List packageReferences =3D new ArrayList(); =20 @@ -67,6 +70,7 @@ private static ExecutionPlanBuilder buildExecutionPlan(Co= llection arti FSPackageRegistry registry =3D new FSPackageRegistry(registryHome)= ; =20 ExecutionPlanBuilder builder =3D registry.createExecutionPlan(); + builder.with(satisfiedPackages); =20 for (File pkgFile : packageReferences) { PackageId pid =3D registry.registerExternal(pkgFile, true); @@ -83,6 +87,7 @@ private static ExecutionPlanBuilder buildExecutionPlan(Co= llection arti builder.addTask().with(pid).with(Type.EXTRACT); } builder.validate(); + satisfiedPackages.addAll(builder.preview()); return builder; =20 } @@ -93,7 +98,7 @@ public boolean handle(Extension extension, LauncherPrepar= eContext prepareContext File registryHome =3D getRegistryHomeDir(installationContext); if (extension.getType() =3D=3D ExtensionType.ARTIFACTS && extension.getName().equals(FeatureConstants.EXTENSION_N= AME_CONTENT_PACKAGES)) { - MultiValueMap orderedArtifacts =3D MultiValueMap.decorate(new = LinkedHashMap>()); + MultiValueMap orderedArtifacts =3D MultiValueMap.decorate(new = TreeMap>()); for (final Artifact a : extension.getArtifacts()) { int order; // content-packages without explicit start-order to be ins= talled last @@ -105,10 +110,11 @@ public boolean handle(Extension extension, LauncherPr= epareContext prepareContext orderedArtifacts.put(order, a); } List executionPlans =3D new ArrayList(); + Set satisfiedPackages =3D new HashSet<>(); for (Object key : orderedArtifacts.keySet()) { @SuppressWarnings("unchecked") Collection artifacts =3D orderedArtifacts.getCol= lection(key); - ExecutionPlanBuilder builder =3D buildExecutionPlan(artifa= cts, prepareContext, registryHome); + ExecutionPlanBuilder builder =3D buildExecutionPlan(artifa= cts, satisfiedPackages, prepareContext, registryHome); ByteArrayOutputStream baos =3D new ByteArrayOutputStream()= ; builder.save(baos); executionPlans.add(baos.toString("UTF-8")); diff --git a/src/test/java/org/apache/sling/feature/extension/content/Conte= ntHandlerTest.java b/src/test/java/org/apache/sling/feature/extension/conte= nt/ContentHandlerTest.java new file mode 100644 index 0000000..3e97c18 --- /dev/null +++ b/src/test/java/org/apache/sling/feature/extension/content/ContentHandl= erTest.java @@ -0,0 +1,129 @@ +/* + * 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.extension.content; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.io.File; +import java.net.URL; +import java.util.Dictionary; +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.ExtensionType; +import org.apache.sling.feature.launcher.spi.LauncherPrepareContext; +import org.apache.sling.feature.launcher.spi.extensions.ExtensionInstallat= ionContext; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +@RunWith(MockitoJUnitRunner.class) +public class ContentHandlerTest { + =20 + + @Rule + public TemporaryFolder testFolder =3D new TemporaryFolder(); + =20 + @Mock + LauncherPrepareContext prepareContext; + =20 + @Mock + ExtensionInstallationContext installationContext; + =20 + /** + * Test package A-1.0. Depends on B and C-1.X + */ + private static final String COORDINATES_TEST_PACKAGE_A_10 =3D "my_pack= ages:test_a:1.0"; + private static String TEST_PACKAGE_A_10 =3D "testpackages/test_a-1.0.z= ip"; + private static ArtifactId TEST_PACKAGE_AID_A_10 =3D ArtifactId.fromMvn= Id(COORDINATES_TEST_PACKAGE_A_10); + + /** + * Test package B-1.0. Depends on C + */ + private static final String COORDINATES_TEST_PACKAGE_B_10 =3D "my_pack= ages:test_b:1.0"; + private static String TEST_PACKAGE_B_10 =3D "testpackages/test_b-1.0.z= ip"; + private static ArtifactId TEST_PACKAGE_AID_B_10 =3D ArtifactId.fromMvn= Id(COORDINATES_TEST_PACKAGE_B_10); + + /** + * Test package C-1.0 + */ + private static final String COORDINATES_TEST_PACKAGE_C_10 =3D "my_pack= ages:test_c:1.0"; + private static String TEST_PACKAGE_C_10 =3D "testpackages/test_c-1.0.z= ip"; + private static ArtifactId TEST_PACKAGE_AID_C_10 =3D ArtifactId.fromMvn= Id(COORDINATES_TEST_PACKAGE_C_10); + + @Before + public void setUp() throws Exception { + URL test_a =3D this.getClass().getResource(TEST_PACKAGE_A_10); + when(prepareContext.getArtifactFile(TEST_PACKAGE_AID_A_10)).thenRe= turn(new File(test_a.getFile())); + URL test_b =3D this.getClass().getResource(TEST_PACKAGE_B_10); + when(prepareContext.getArtifactFile(TEST_PACKAGE_AID_B_10)).thenRe= turn(new File(test_b.getFile())); + URL test_c =3D this.getClass().getResource(TEST_PACKAGE_C_10); + when(prepareContext.getArtifactFile(TEST_PACKAGE_AID_C_10)).thenRe= turn(new File(test_c.getFile())); + } + + @Test + public void testMultipleStartOrders() throws Exception { + ContentHandler ch =3D new ContentHandler(); + System.setProperty(ContentHandler.PACKAGEREGISTRY_HOME, testFolder= .getRoot().toString()); + Extension ext =3D new Extension(ExtensionType.ARTIFACTS, "content-= packages", false); + Artifact artifact_a =3D new Artifact(TEST_PACKAGE_AID_A_10); + Artifact artifact_b =3D new Artifact(TEST_PACKAGE_AID_B_10); + Artifact artifact_c =3D new Artifact(TEST_PACKAGE_AID_C_10); + artifact_a.getMetadata().put("start-order", "2"); + artifact_b.getMetadata().put("start-order", "1"); + artifact_c.getMetadata().put("start-order", "1"); + ext.getArtifacts().add(artifact_a); + ext.getArtifacts().add(artifact_b); + ext.getArtifacts().add(artifact_c); + @SuppressWarnings("unchecked") + ArgumentCaptor> executionPlanCaptor =3D= ArgumentCaptor.forClass(Dictionary.class); + =20 + ch.handle(ext, prepareContext, installationContext); + verify(installationContext).addConfiguration(eq("org.apache.sling.= jcr.packageinit.impl.ExecutionPlanRepoInitializer"), any(), executionPlanCa= ptor.capture()); + verify(installationContext).addConfiguration(eq("org.apache.jackra= bbit.vault.packaging.registry.impl.FSPackageRegistry"), any(), any()); + Iterator> dictIt =3D executionPlanCapto= r.getAllValues().iterator(); + final String[] executionplans =3D (String[]) dictIt.next().get("ex= ecutionplans"); + final String expected_0 =3D + "\n" + + "\n" + + " \n" + + " \n" + + "\n"; + + assertEquals(expected_0, executionplans[0]); + final String expected_1 =3D + "\n" + + "\n" + + " \n" + + "\n"; + + assertEquals(expected_1, executionplans[1]); + assertFalse(dictIt.hasNext()); + } +} diff --git a/src/test/resources/org/apache/sling/feature/extension/content/= testpackages/test_a-1.0.zip b/src/test/resources/org/apache/sling/feature/e= xtension/content/testpackages/test_a-1.0.zip new file mode 100644 index 0000000..08df03a Binary files /dev/null and b/src/test/resources/org/apache/sling/feature/ex= tension/content/testpackages/test_a-1.0.zip differ diff --git a/src/test/resources/org/apache/sling/feature/extension/content/= testpackages/test_b-1.0.zip b/src/test/resources/org/apache/sling/feature/e= xtension/content/testpackages/test_b-1.0.zip new file mode 100644 index 0000000..85fac13 Binary files /dev/null and b/src/test/resources/org/apache/sling/feature/ex= tension/content/testpackages/test_b-1.0.zip differ diff --git a/src/test/resources/org/apache/sling/feature/extension/content/= testpackages/test_c-1.0.zip b/src/test/resources/org/apache/sling/feature/e= xtension/content/testpackages/test_c-1.0.zip new file mode 100644 index 0000000..245291a Binary files /dev/null and b/src/test/resources/org/apache/sling/feature/ex= tension/content/testpackages/test_c-1.0.zip differ =20 ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. =20 For queries about this service, please contact Infrastructure at: users@infra.apache.org > Incorporate layering optimizations for cross layer dependencies > --------------------------------------------------------------- > > Key: SLING-8085 > URL: https://issues.apache.org/jira/browse/SLING-8085 > Project: Sling > Issue Type: Improvement > Components: Feature Model > Reporter: Dominik S=C3=BC=C3=9F > Priority: Major > > In case an exeuction plan on a higher level depends on artifacts of a low= er level the exeuctionplan builder currently generates install wrong and un= cessary install tasks to fill the gap. This scenario is covered in JCRVLT-3= 19 and requires adoption of the consumer. > This ticket is to track incorporation of this optimization into the conte= nt extension making use of this new mechanism. -- This message was sent by Atlassian JIRA (v7.6.3#76005)