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/01/27 10:21:30 UTC

[sling-org-apache-sling-jcr-packageinit] branch master updated (6a17f8d -> 7424e1b)

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

kwin pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-packageinit.git.


    from 6a17f8d  Adding sonarqube badges as per SLING-9682
     new d314ede  SLING-10089 - adding logic & test to consider failing on error in executionplan execution
     new afaa1a1  SLING-10089 - spawning packageTask exceptions as errors & enhancing tests to check for corresponding logentries
     new ee9561d  SLING-10089 - updating to latest parent pom including switch to bnd plugin
     new 2c3933c  SLING-10089 - incorporating suggestions of review (cleaning up pom & adding suppressed exceptions to IllegalStateException over logging individually)
     new 7424e1b  Merge pull request #3 from DominikSuess/issue/SLING-10089

The 25 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 pom.xml                                            | 40 +----------
 .../impl/ExecutionPlanRepoInitializer.java         | 10 +++
 .../ExecutionPlanRepoInitializerTest.java          | 81 ++++++++++++++++------
 3 files changed, 71 insertions(+), 60 deletions(-)


[sling-org-apache-sling-jcr-packageinit] 13/25: Merge pull request #2 from DominikSuess/SLING-8222

Posted by kw...@apache.org.
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-jcr-packageinit.git

commit 45d59b9c92591bd93cb60580ad7a69ae6a3d41f6
Merge: 9173507 eb3ccfd
Author: Karl Pauls <pa...@apache.org>
AuthorDate: Thu Jan 17 13:48:53 2019 +0100

    Merge pull request #2 from DominikSuess/SLING-8222
    
    SLING-8222 - adjusting cases to reflect valid cases on restart when h…

 .../impl/ExecutionPlanRepoInitializer.java         | 24 ++++++++++++++--------
 1 file changed, 15 insertions(+), 9 deletions(-)


[sling-org-apache-sling-jcr-packageinit] 24/25: SLING-10089 - incorporating suggestions of review (cleaning up pom & adding suppressed exceptions to IllegalStateException over logging individually)

Posted by kw...@apache.org.
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-jcr-packageinit.git

commit 2c3933c053ae4a3c8d4edc212f97a8ee5cca5b1c
Author: Dominik Suess <su...@adobe.com>
AuthorDate: Wed Jan 27 11:18:06 2021 +0100

    SLING-10089 - incorporating suggestions of review (cleaning up pom & adding suppressed exceptions to IllegalStateException over logging individually)
---
 pom.xml                                                      | 12 ------------
 .../jcr/packageinit/impl/ExecutionPlanRepoInitializer.java   |  5 +++--
 .../jcr/packageinit/ExecutionPlanRepoInitializerTest.java    |  7 ++++---
 3 files changed, 7 insertions(+), 17 deletions(-)

diff --git a/pom.xml b/pom.xml
index 9ff07d3..ea927a6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -39,18 +39,6 @@
         <url>https://gitbox.apache.org/repos/asf?p=sling-org-apache-sling-jcr-packageinit.git</url>
         <tag>HEAD</tag>
     </scm>
-    <build>
-        <plugins>
-         <plugin>
-                <groupId>biz.aQute.bnd</groupId>
-                <artifactId>bnd-maven-plugin</artifactId>
-            </plugin>
-            <plugin>
-                <groupId>biz.aQute.bnd</groupId>
-                <artifactId>bnd-baseline-maven-plugin</artifactId>
-            </plugin>
-        </plugins>
-    </build>
 
     <dependencies>
         <dependency>
diff --git a/src/main/java/org/apache/sling/jcr/packageinit/impl/ExecutionPlanRepoInitializer.java b/src/main/java/org/apache/sling/jcr/packageinit/impl/ExecutionPlanRepoInitializer.java
index 1018631..4d88d8a 100644
--- a/src/main/java/org/apache/sling/jcr/packageinit/impl/ExecutionPlanRepoInitializer.java
+++ b/src/main/java/org/apache/sling/jcr/packageinit/impl/ExecutionPlanRepoInitializer.java
@@ -165,12 +165,13 @@ public class ExecutionPlanRepoInitializer implements SlingRepositoryInitializer
                         ExecutionPlan xplan = builder.execute();
                         if (xplan.getTasks().size() > 0) {
                             if (xplan.hasErrors()) {
+                                IllegalStateException ex = new IllegalStateException("Excecutionplan execution contained errors - cannot complete repository initialization.");
                                 for (PackageTask task : xplan.getTasks()) {
                                     if (PackageTask.State.ERROR.equals(task.getState())){
-                                        logger.error("Error during installation of {}: {}", task.getPackageId().toString(), task.getError().toString());
+                                        ex.addSuppressed(task.getError());
                                     }
                                 }
-                                throw new IllegalStateException("Excecutionplan execution contained errors - cannot complete repository initialization.");
+                                throw ex;
                             }
                             logger.info("executionplan executed with {} entries", xplan.getTasks().size());
                         } else {
diff --git a/src/test/java/org/apache/sling/jcr/packageinit/ExecutionPlanRepoInitializerTest.java b/src/test/java/org/apache/sling/jcr/packageinit/ExecutionPlanRepoInitializerTest.java
index acdb656..123a3cd 100644
--- a/src/test/java/org/apache/sling/jcr/packageinit/ExecutionPlanRepoInitializerTest.java
+++ b/src/test/java/org/apache/sling/jcr/packageinit/ExecutionPlanRepoInitializerTest.java
@@ -207,7 +207,8 @@ public class ExecutionPlanRepoInitializerTest {
         PackageTask pt = mock(PackageTask.class);
         when(pt.getPackageId()).thenReturn(PackageId.fromString("test:test:1.0"));
         when(pt.getState()).thenReturn(State.ERROR);
-        when(pt.getError()).thenReturn(new Throwable("expectedException"));
+        Throwable testEx = new Throwable("expectedException");
+        when(pt.getError()).thenReturn(testEx);
         ptl.add(pt);
         when(xplan.getTasks()).thenReturn(ptl);
         when(xplan.hasErrors()).thenReturn(true);
@@ -218,13 +219,13 @@ public class ExecutionPlanRepoInitializerTest {
         cdl.await(20500, TimeUnit.MILLISECONDS);
         verify(builder, times(1)).load(captor.capture());
         assertTrue("Expected IllegalStateException.",foundExceptions.get(0) instanceof IllegalStateException);
-        
+        assertEquals(testEx.getMessage(), foundExceptions.get(0).getSuppressed()[0].getMessage());
+
         List<ILoggingEvent> logsList = listAppender.list;
         assertEquals("Waiting for PackageRegistry.", logsList.get(0)
                                       .getMessage());
         assertEquals("PackageRegistry found - starting execution of executionplan", logsList.get(1)
             .getMessage());
-        assertEquals("Error during installation of test:test:1.0: java.lang.Throwable: expectedException", logsList.get(2).getFormattedMessage());
     }
 
 


[sling-org-apache-sling-jcr-packageinit] 25/25: Merge pull request #3 from DominikSuess/issue/SLING-10089

Posted by kw...@apache.org.
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-jcr-packageinit.git

commit 7424e1b1f47758c12b6161e8689d6f9022257ce0
Merge: 6a17f8d 2c3933c
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Wed Jan 27 11:21:22 2021 +0100

    Merge pull request #3 from DominikSuess/issue/SLING-10089
    
    SLING-10089 - adding logic & test to consider failing on error in exe…

 pom.xml                                            | 40 +----------
 .../impl/ExecutionPlanRepoInitializer.java         | 10 +++
 .../ExecutionPlanRepoInitializerTest.java          | 81 ++++++++++++++++------
 3 files changed, 71 insertions(+), 60 deletions(-)


[sling-org-apache-sling-jcr-packageinit] 20/25: Adding sonarqube badges as per SLING-9682

Posted by kw...@apache.org.
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-jcr-packageinit.git

commit 6a17f8d2a9a74f05d1291b39ff60edce01eab80f
Author: Dan Klco <dk...@apache.org>
AuthorDate: Mon Aug 24 17:18:34 2020 -0400

    Adding sonarqube badges as per SLING-9682
---
 README.md | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md
index dbefd4b..255b9e7 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
-[<img src="https://sling.apache.org/res/logos/sling.png"/>](https://sling.apache.org)
+[![Apache Sling](https://sling.apache.org/res/logos/sling.png)](https://sling.apache.org)
 
- [![Build Status](https://ci-builds.apache.org/job/Sling/job/modules/job/sling-org-apache-sling-jcr-packageinit/job/master/badge/icon)](https://ci-builds.apache.org/job/Sling/job/modules/job/sling-org-apache-sling-jcr-packageinit/job/master/) [![Test Status](https://img.shields.io/jenkins/tests.svg?jobUrl=https://ci-builds.apache.org/job/Sling/job/modules/job/sling-org-apache-sling-jcr-packageinit/job/master/)](https://ci-builds.apache.org/job/Sling/job/modules/job/sling-org-apache-sling [...]
+&#32;[![Build Status](https://ci-builds.apache.org/job/Sling/job/modules/job/sling-org-apache-sling-jcr-packageinit/job/master/badge/icon)](https://ci-builds.apache.org/job/Sling/job/modules/job/sling-org-apache-sling-jcr-packageinit/job/master/)&#32;[![Test Status](https://img.shields.io/jenkins/tests.svg?jobUrl=https://ci-builds.apache.org/job/Sling/job/modules/job/sling-org-apache-sling-jcr-packageinit/job/master/)](https://ci-builds.apache.org/job/Sling/job/modules/job/sling-org-apac [...]
 
 # Apache Sling JCR Package Initializer module
 


[sling-org-apache-sling-jcr-packageinit] 15/25: Updating badges for org-apache-sling-jcr-packageinit

Posted by kw...@apache.org.
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-jcr-packageinit.git

commit f728547156d0e7529f3a7568bcb993578b358534
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Thu Jan 31 13:16:23 2019 +0100

    Updating badges for org-apache-sling-jcr-packageinit
---
 README.md | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/README.md b/README.md
index 500d38e..6ada88a 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,7 @@
+[<img src="https://sling.apache.org/res/logos/sling.png"/>](https://sling.apache.org)
+
+ [![Build Status](https://builds.apache.org/buildStatus/icon?job=Sling/sling-org-apache-sling-jcr-packageinit/master)](https://builds.apache.org/job/Sling/job/sling-org-apache-sling-jcr-packageinit/job/master) [![Test Status](https://img.shields.io/jenkins/t/https/builds.apache.org/job/Sling/job/sling-org-apache-sling-jcr-packageinit/job/master.svg)](https://builds.apache.org/job/Sling/job/sling-org-apache-sling-jcr-packageinit/job/master/test_results_analyzer/) [![License](https://img.s [...]
+
 # Apache Sling JCR Package Initializer module
 
 This module is part of the [Apache Sling](https://sling.apache.org) project.


[sling-org-apache-sling-jcr-packageinit] 08/25: Add scm info

Posted by kw...@apache.org.
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-jcr-packageinit.git

commit 7109c46c8513253d84c89c04cd0867c5725291ff
Author: Karl Pauls <kp...@adobe.com>
AuthorDate: Wed Oct 10 13:08:34 2018 +0200

    Add scm info
---
 pom.xml | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 73cd312..3e973f4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -34,7 +34,12 @@
   <description>
 	  Installs packages into a JCR repository as SlingRepositoryInitializer based on a FileVault ExecutionPlan
   </description>
-
+    <scm>
+        <connection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-packageinit.git</connection>
+        <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-packageinit.git</developerConnection>
+        <url>https://gitbox.apache.org/repos/asf?p=sling-org-apache-sling-jcr-packageinit.git</url>
+        <tag>HEAD</tag>
+    </scm>
     <build>
         <plugins>
             <plugin>


[sling-org-apache-sling-jcr-packageinit] 23/25: SLING-10089 - updating to latest parent pom including switch to bnd plugin

Posted by kw...@apache.org.
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-jcr-packageinit.git

commit ee9561d7f629a2a91036bcfa82f3147081873c02
Author: Dominik Suess <su...@adobe.com>
AuthorDate: Tue Jan 26 16:24:34 2021 +0100

    SLING-10089 - updating to latest parent pom including switch to bnd plugin
---
 pom.xml | 40 ++++++++--------------------------------
 1 file changed, 8 insertions(+), 32 deletions(-)

diff --git a/pom.xml b/pom.xml
index f897480..9ff07d3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,13 +22,12 @@
 
   <parent>
     <groupId>org.apache.sling</groupId>
-    <artifactId>sling</artifactId>
-    <version>34</version>
+    <artifactId>sling-bundle-parent</artifactId>
+    <version>40</version>
     <relativePath />
   </parent>
 
   <artifactId>org.apache.sling.jcr.packageinit</artifactId>
-  <packaging>bundle</packaging>
   <version>1.0.1-SNAPSHOT</version>
   <name>Apache Sling JCR Package Initializer module</name>
   <description>
@@ -42,37 +41,14 @@
     </scm>
     <build>
         <plugins>
+         <plugin>
+                <groupId>biz.aQute.bnd</groupId>
+                <artifactId>bnd-maven-plugin</artifactId>
+            </plugin>
             <plugin>
-                <groupId>org.apache.felix</groupId>
-                <artifactId>maven-bundle-plugin</artifactId>
-                <extensions>true</extensions>
-                <executions>
-                    <!-- Configure extra execution of 'manifest' in process-classes phase to make sure SCR metadata is generated before unit test runs -->
-                    <execution>
-                        <id>scr-metadata</id>
-                        <goals>
-                            <goal>manifest</goal>
-                        </goals>
-                        <configuration>
-                            <supportIncrementalBuild>true</supportIncrementalBuild>
-                        </configuration>
-                    </execution>
-                </executions>
-                <configuration>
-                    <!-- Export SCR metadata to classpath to have them available in unit tests -->
-                    <exportScr>true</exportScr>
-                    <instructions>
-                        <!-- Enable processing of OSGI DS component annotations -->
-                        <_dsannotations>*</_dsannotations>
-                        <!-- Enable processing of OSGI metatype annotations -->
-                        <_metatypeannotations>*</_metatypeannotations>
-                        <Private-Package>
-                            org.apache.sling.jcr.packageinit.impl
-                        </Private-Package>
-                    </instructions>
-                 </configuration>
+                <groupId>biz.aQute.bnd</groupId>
+                <artifactId>bnd-baseline-maven-plugin</artifactId>
             </plugin>
-          
         </plugins>
     </build>
 


[sling-org-apache-sling-jcr-packageinit] 17/25: [maven-release-plugin] prepare release org.apache.sling.jcr.packageinit-1.0.0

Posted by kw...@apache.org.
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-jcr-packageinit.git

commit 669826a51935e4e3e4752b33bcf5b873cded4630
Author: Andreas Schaefer <sc...@iMac.local>
AuthorDate: Tue Jan 28 12:20:10 2020 -0800

    [maven-release-plugin] prepare release org.apache.sling.jcr.packageinit-1.0.0
---
 pom.xml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/pom.xml b/pom.xml
index 4543a69..aa4df1c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -29,7 +29,7 @@
 
   <artifactId>org.apache.sling.jcr.packageinit</artifactId>
   <packaging>bundle</packaging>
-  <version>0.0.1-SNAPSHOT</version>
+  <version>1.0.0</version>
   <name>Apache Sling JCR Package Initializer module</name>
   <description>
 	  Installs packages into a JCR repository as SlingRepositoryInitializer based on a FileVault ExecutionPlan
@@ -38,7 +38,7 @@
         <connection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-packageinit.git</connection>
         <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-packageinit.git</developerConnection>
         <url>https://gitbox.apache.org/repos/asf?p=sling-org-apache-sling-jcr-packageinit.git</url>
-        <tag>HEAD</tag>
+        <tag>org.apache.sling.jcr.packageinit-1.0.0</tag>
     </scm>
     <build>
         <plugins>


[sling-org-apache-sling-jcr-packageinit] 05/25: SLING-7871 - switching to commons-lang3 (adding missing changes)

Posted by kw...@apache.org.
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-jcr-packageinit.git

commit e6099f915167b4c7f63f646e758df3b1debfd077
Author: Dominik Suess <su...@adobe.com>
AuthorDate: Thu Sep 6 16:52:45 2018 +0200

    SLING-7871 - switching to commons-lang3 (adding missing changes)
---
 packageinit/pom.xml                                                 | 6 ------
 .../sling/jcr/packageinit/impl/ExecutionPlanRepoInitializer.java    | 3 +--
 2 files changed, 1 insertion(+), 8 deletions(-)

diff --git a/packageinit/pom.xml b/packageinit/pom.xml
index a697003..9cdcbd4 100644
--- a/packageinit/pom.xml
+++ b/packageinit/pom.xml
@@ -100,12 +100,6 @@
             <artifactId>slf4j-api</artifactId>
         </dependency>
         <dependency>
-            <groupId>commons-lang</groupId>
-            <artifactId>commons-lang</artifactId>
-            <version>2.6</version>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.jcr.api</artifactId>
             <version>2.4.0</version>
diff --git a/packageinit/src/main/java/org/apache/sling/jcr/packageinit/impl/ExecutionPlanRepoInitializer.java b/packageinit/src/main/java/org/apache/sling/jcr/packageinit/impl/ExecutionPlanRepoInitializer.java
index 58633f7..8631cf7 100644
--- a/packageinit/src/main/java/org/apache/sling/jcr/packageinit/impl/ExecutionPlanRepoInitializer.java
+++ b/packageinit/src/main/java/org/apache/sling/jcr/packageinit/impl/ExecutionPlanRepoInitializer.java
@@ -16,8 +16,7 @@
  */
 package org.apache.sling.jcr.packageinit.impl;
 
-
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.jackrabbit.vault.packaging.registry.ExecutionPlan;
 import org.apache.jackrabbit.vault.packaging.registry.ExecutionPlanBuilder;
 import org.apache.jackrabbit.vault.packaging.registry.PackageRegistry;


[sling-org-apache-sling-jcr-packageinit] 09/25: Add license

Posted by kw...@apache.org.
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-jcr-packageinit.git

commit 51674eb408238c0284171759496139c6b4f5bc79
Author: Karl Pauls <kp...@adobe.com>
AuthorDate: Wed Oct 10 13:49:01 2018 +0200

    Add license
---
 LICENSE | 202 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 202 insertions(+)

diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..d645695
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,202 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed 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.


[sling-org-apache-sling-jcr-packageinit] 01/25: SLING-7871 - Proposal for RepositoryInitializer installing precalculated execution plans from FSRegistry into repository

Posted by kw...@apache.org.
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-jcr-packageinit.git

commit 001844045b171596647acba31b76bf01592ac3b3
Author: Dominik Suess <su...@adobe.com>
AuthorDate: Thu Sep 6 12:07:29 2018 +0200

    SLING-7871 - Proposal for RepositoryInitializer installing precalculated execution plans from FSRegistry into repository
---
 packageinit/pom.xml                                | 143 ++++++++++++++++
 .../impl/ExecutionPlanRepoInitializer.java         | 183 ++++++++++++++++++++
 .../ExecutionPlanRepoInitializerTest.java          | 184 +++++++++++++++++++++
 3 files changed, 510 insertions(+)

diff --git a/packageinit/pom.xml b/packageinit/pom.xml
new file mode 100644
index 0000000..92116dc
--- /dev/null
+++ b/packageinit/pom.xml
@@ -0,0 +1,143 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+  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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.sling</groupId>
+    <artifactId>sling</artifactId>
+    <version>34</version>
+    <relativePath />
+  </parent>
+
+  <artifactId>org.apache.sling.jcr.packageinit</artifactId>
+  <packaging>bundle</packaging>
+  <version>0.0.1-SNAPSHOT</version>
+  <name>Apache Sling JCR Package Initializer module</name>
+  <description>
+	  Installs packages into a JCR repository as SlingRepositoryInitializer based on a FileVault ExecutionPlan
+  </description>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
+                <executions>
+                    <!-- Configure extra execution of 'manifest' in process-classes phase to make sure SCR metadata is generated before unit test runs -->
+                    <execution>
+                        <id>scr-metadata</id>
+                        <goals>
+                            <goal>manifest</goal>
+                        </goals>
+                        <configuration>
+                            <supportIncrementalBuild>true</supportIncrementalBuild>
+                        </configuration>
+                    </execution>
+                </executions>
+                <configuration>
+                    <!-- Export SCR metadata to classpath to have them available in unit tests -->
+                    <exportScr>true</exportScr>
+                    <instructions>
+                        <!-- Enable processing of OSGI DS component annotations -->
+                        <_dsannotations>*</_dsannotations>
+                        <!-- Enable processing of OSGI metatype annotations -->
+                        <_metatypeannotations>*</_metatypeannotations>
+                        <Private-Package>
+                            org.apache.sling.jcr.packageinit.impl
+                        </Private-Package>
+                    </instructions>
+                 </configuration>
+            </plugin>
+          
+        </plugins>
+    </build>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>osgi.core</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+             <groupId>org.osgi</groupId>
+             <artifactId>osgi.cmpn</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.service.component.annotations</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.service.metatype.annotations</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>javax.jcr</groupId>
+            <artifactId>jcr</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.jcr.api</artifactId>
+            <version>2.4.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.launchpad.api</artifactId>
+            <version>1.1.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.installer.core</artifactId>
+            <version>3.5.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.jackrabbit.vault</groupId>
+            <artifactId>org.apache.jackrabbit.vault</artifactId>
+            <version>3.2.1-SNAPSHOT</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.testing.sling-mock.junit4</artifactId>
+            <version>2.3.2</version>
+            <scope>testing</scope>
+        </dependency>
+              <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <version>2.21.0</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+</project>
diff --git a/packageinit/src/main/java/org/apache/sling/jcr/packageinit/impl/ExecutionPlanRepoInitializer.java b/packageinit/src/main/java/org/apache/sling/jcr/packageinit/impl/ExecutionPlanRepoInitializer.java
new file mode 100644
index 0000000..58633f7
--- /dev/null
+++ b/packageinit/src/main/java/org/apache/sling/jcr/packageinit/impl/ExecutionPlanRepoInitializer.java
@@ -0,0 +1,183 @@
+/*
+ * 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.jcr.packageinit.impl;
+
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.jackrabbit.vault.packaging.registry.ExecutionPlan;
+import org.apache.jackrabbit.vault.packaging.registry.ExecutionPlanBuilder;
+import org.apache.jackrabbit.vault.packaging.registry.PackageRegistry;
+import org.apache.sling.jcr.api.SlingRepository;
+import org.apache.sling.jcr.api.SlingRepositoryInitializer;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.Designate;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
+import org.osgi.util.tracker.ServiceTracker;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jcr.Session;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+@Component(service = {SlingRepositoryInitializer.class},
+        property = {"service.ranking:Integer=200"})
+@Designate(ocd = ExecutionPlanRepoInitializer.Config.class)
+public class ExecutionPlanRepoInitializer implements SlingRepositoryInitializer {
+
+    private static final String EXECUTEDPLANS_FILE = "executedplans.file";
+    private List<String> executionPlans = new ArrayList<>();
+    
+    private File statusFile;
+
+    @ObjectClassDefinition(
+            name = "Executionplan based Repository Initializer"
+    )
+    @interface Config {
+        
+        @AttributeDefinition
+        String statusfilepath() default "";
+
+        @AttributeDefinition
+        String[] executionplans() default {};
+    }
+
+    /**
+     * The logger.
+     */
+    private final Logger logger = LoggerFactory.getLogger(getClass());
+    private BundleContext context;
+
+    @Activate
+    private void activate(BundleContext context, Config config) throws FileNotFoundException, IOException {
+        List<String> epCandidates = Arrays.asList(config.executionplans());
+        if (!epCandidates.isEmpty()) {
+            if(StringUtils.isEmpty(config.statusfilepath())) {
+                // if no  path is configured lookup default file in bundledata
+                statusFile = context.getDataFile(EXECUTEDPLANS_FILE);
+            } else {
+                Path statusFilePath = Paths.get(config.statusfilepath());
+                if (statusFilePath.isAbsolute()) {
+                    // only absolute references are considered for lookup of
+                    // external statusfile
+                    statusFile = statusFilePath.toFile();
+                } else {
+                    throw new IllegalStateException("Only absolute paths supported");
+                }
+            }
+            if (statusFile.exists()) {
+                // in case statusFile already exists read all hashes
+                List<Integer> executedHashes = new ArrayList<>();
+                try (BufferedReader br = new BufferedReader(new FileReader(statusFile))) {
+                    for (String line; (line = br.readLine()) != null;) {
+                        executedHashes.add(Integer.parseInt(line));
+                    }
+                }
+                processCandidates(epCandidates, executedHashes);
+            } else {
+               this.executionPlans.addAll(epCandidates);
+            }
+        }
+        this.context = context;
+    }
+
+    private void processCandidates(List<String> epCandidates, List<Integer> executedHashes) {
+        Iterator<String> candidateIt = epCandidates.iterator();
+        Iterator<Integer> executedHashesIt = executedHashes.iterator();
+        // iterate over candidates and crosscheck next found hash
+        while (candidateIt.hasNext()) {
+            String candidate = candidateIt.next();
+            if (!executedHashesIt.hasNext()) {
+                // if no further hashes are present add candidate
+                // (will iterate over rest and add rest)
+                executionPlans.add(candidate);
+            } else {
+                // if another hash was found check if it matches the
+                // next candidate
+                Integer executedHash = executedHashesIt.next();
+                if (isCandidateProcessed(candidate, executedHash)) {
+                    // already processed so no need to add - check
+                    // next plan
+                    continue;
+                } else {
+                    String msg = "Different content installed then configured - repository needs to be reset.";
+                    logger.error(msg);
+                    throw new IllegalStateException(msg);
+                }
+            }
+        }
+    }
+
+    private boolean isCandidateProcessed(String candidate, Integer executedHash) {
+        return executedHash.equals(Integer.valueOf(candidate.hashCode()));
+    }
+
+    @Override
+    public void processRepository(SlingRepository slingRepository) throws Exception {
+        if (executionPlans != null) {
+            ServiceTracker<PackageRegistry, ?> st = new ServiceTracker<>(context, PackageRegistry.class, null);
+            try {
+                st.open();
+                logger.info("Waiting for PackageRegistry.");
+                PackageRegistry registry = (PackageRegistry) st.waitForService(0);
+                logger.info("PackageRegistry found - starting execution of executionplan");
+                
+                @SuppressWarnings("deprecation")
+                Session session = slingRepository.loginAdministrative(null);
+                ExecutionPlanBuilder builder = registry.createExecutionPlan();
+                BufferedWriter writer = null;
+                try {
+                    writer = new BufferedWriter(new FileWriter(statusFile));
+                    for (String plan : executionPlans) {
+                        builder.load(new ByteArrayInputStream(plan.getBytes("UTF-8")));
+                        builder.with(session);
+                        ExecutionPlan xplan = builder.execute();
+                        logger.info("executionplan executed with {} entries", xplan.getTasks().size());
+                        // save hashes to file for crosscheck on subsequent startup to avoid double processing
+                        writer.write(String.valueOf(plan.hashCode()));
+                        writer.newLine();
+
+                    }
+                } finally {
+                    if (writer != null) {
+                        writer.close();
+                    }
+                }
+            } finally {
+                st.close();
+            }
+        } else {
+            logger.info("No executionplans configured skipping init.");
+        }
+    }
+}
diff --git a/packageinit/src/test/java/org/apache/sling/jcr/packageinit/ExecutionPlanRepoInitializerTest.java b/packageinit/src/test/java/org/apache/sling/jcr/packageinit/ExecutionPlanRepoInitializerTest.java
new file mode 100644
index 0000000..5dd457a
--- /dev/null
+++ b/packageinit/src/test/java/org/apache/sling/jcr/packageinit/ExecutionPlanRepoInitializerTest.java
@@ -0,0 +1,184 @@
+/*
+ * 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.jcr.packageinit;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.UUID;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.jackrabbit.vault.packaging.PackageException;
+import org.apache.jackrabbit.vault.packaging.registry.ExecutionPlan;
+import org.apache.jackrabbit.vault.packaging.registry.ExecutionPlanBuilder;
+import org.apache.jackrabbit.vault.packaging.registry.PackageRegistry;
+import org.apache.jackrabbit.vault.packaging.registry.impl.FSPackageRegistry;
+import org.apache.sling.jcr.api.SlingRepository;
+import org.apache.sling.jcr.packageinit.impl.ExecutionPlanRepoInitializer;
+import org.apache.sling.testing.mock.osgi.MockOsgi;
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
+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.Spy;
+import org.mockito.junit.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ExecutionPlanRepoInitializerTest {
+    
+    static String EXECUTIONPLAN_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" +
+                    "</executionPlan>\n";
+    
+    static String EXECUTIONPLAN_2 =
+            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+                    "<executionPlan version=\"1.0\">\n" +
+                    "    <task cmd=\"extract\" packageId=\"my_packages:test_b:1.0\"/>\n" +
+                    "</executionPlan>\n";
+    
+    static String[] EXECUTIONSPLANS = {EXECUTIONPLAN_1, EXECUTIONPLAN_2};
+    
+    static String STATUSFILE_NAME = "executedplans.file";
+
+    @Rule
+    public final SlingContext context = new SlingContext();
+    
+    @Rule
+    public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+
+    @Mock
+    SlingRepository slingRepo;
+
+    @Spy
+    PackageRegistry registry = new FSPackageRegistry();
+
+    @Mock
+    ExecutionPlanBuilder builder;
+    
+    @Mock
+    ExecutionPlanBuilder builder2;
+
+
+    @Mock
+    ExecutionPlan xplan;
+
+    private File statusFile;
+    
+
+    @Before
+    public void setup() throws IOException, PackageException {
+        when(registry.createExecutionPlan()).thenReturn(builder);
+        when(builder.execute()).thenReturn(xplan);
+        when(builder2.execute()).thenReturn(xplan);
+        this.statusFile = temporaryFolder.newFile(STATUSFILE_NAME + UUID.randomUUID());
+    }
+
+    @Test
+    public void waitForRegistryAndInstall() throws Exception {
+        ExecutionPlanRepoInitializer initializer = registerRepoInitializer();
+
+        CountDownLatch cdl = new CountDownLatch(1);
+        processRepository(initializer, cdl);
+
+        assertTrue("processRespository() should not be completed before FSRegistry is available", cdl.getCount() > 0);
+        ArgumentCaptor<InputStream> captor = ArgumentCaptor.forClass(InputStream.class);
+
+        context.bundleContext().registerService(PackageRegistry.class.getName(), registry, null);
+        cdl.await(500, TimeUnit.MILLISECONDS);
+        verify(builder, times(2)).load(captor.capture());
+
+        Iterator<InputStream> isIt = captor.getAllValues().iterator();
+        for (String ep : EXECUTIONSPLANS) {
+            StringWriter writer = new StringWriter();
+            IOUtils.copy(isIt.next(), writer, "UTF-8");
+            assertEquals(writer.toString(), ep);
+        }
+    }
+
+    @Test
+    public void doubleExecute() throws Exception {
+        ExecutionPlanRepoInitializer initializer = registerRepoInitializer();
+
+        CountDownLatch cdl = new CountDownLatch(1);
+        processRepository(initializer, cdl);
+
+        assertTrue("processRespository() should not be completed before FSRegistry is available", cdl.getCount() > 0);
+        ArgumentCaptor<InputStream> captor = ArgumentCaptor.forClass(InputStream.class);
+
+        context.bundleContext().registerService(PackageRegistry.class.getName(), registry, null);
+        cdl.await(500, TimeUnit.MILLISECONDS);
+        verify(builder, times(2)).load(captor.capture());
+        
+        // use different builder to reset captor
+        when(registry.createExecutionPlan()).thenReturn(builder2);
+        
+        MockOsgi.deactivate(initializer, context.bundleContext());
+        initializer = registerRepoInitializer();
+        processRepository(initializer, cdl);;
+        
+        cdl.await(500, TimeUnit.MILLISECONDS);
+        verify(builder2, never()).load(captor.capture());
+
+    }
+
+    private ExecutionPlanRepoInitializer registerRepoInitializer() {
+        ExecutionPlanRepoInitializer initializer = new ExecutionPlanRepoInitializer();
+        Dictionary<String, Object> props = new Hashtable<String, Object>();
+        props.put("executionplans", EXECUTIONSPLANS);
+        props.put("statusfilepath", statusFile.getAbsolutePath());
+        context.registerInjectActivateService(initializer, props);
+        return initializer;
+    }
+    
+
+    private void processRepository(ExecutionPlanRepoInitializer initializer, CountDownLatch cdl) {
+        new Thread(new Runnable() {
+            @Override
+            public void run() {
+                try {
+                    initializer.processRepository(slingRepo);
+                    cdl.countDown();
+                } catch (Exception e) {
+                    fail("Should not have thrown any exception");
+                }
+
+            }
+        }).start();
+    }
+
+}


[sling-org-apache-sling-jcr-packageinit] 03/25: SLING-7871 - fixing mistakes introduced on cleaning up for whiteboard

Posted by kw...@apache.org.
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-jcr-packageinit.git

commit 97cba040eccc156625d618af90402394715be945
Author: Dominik Suess <su...@adobe.com>
AuthorDate: Thu Sep 6 15:35:32 2018 +0200

    SLING-7871 - fixing mistakes introduced on cleaning up for whiteboard
---
 packageinit/pom.xml                                          | 12 ++++++++++++
 .../jcr/packageinit/ExecutionPlanRepoInitializerTest.java    |  1 -
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/packageinit/pom.xml b/packageinit/pom.xml
index 92116dc..c49aefb 100644
--- a/packageinit/pom.xml
+++ b/packageinit/pom.xml
@@ -100,6 +100,12 @@
             <artifactId>slf4j-api</artifactId>
         </dependency>
         <dependency>
+            <groupId>commons-lang</groupId>
+            <artifactId>commons-lang</artifactId>
+            <version>2.6</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.jcr.api</artifactId>
             <version>2.4.0</version>
@@ -124,6 +130,12 @@
             <scope>provided</scope>
         </dependency>
         <dependency>
+            <groupId>commons-lang</groupId>
+            <artifactId>commons-lang</artifactId>
+            <version>2.6</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
         </dependency>
diff --git a/packageinit/src/test/java/org/apache/sling/jcr/packageinit/ExecutionPlanRepoInitializerTest.java b/packageinit/src/test/java/org/apache/sling/jcr/packageinit/ExecutionPlanRepoInitializerTest.java
index 5dd457a..40f4157 100644
--- a/packageinit/src/test/java/org/apache/sling/jcr/packageinit/ExecutionPlanRepoInitializerTest.java
+++ b/packageinit/src/test/java/org/apache/sling/jcr/packageinit/ExecutionPlanRepoInitializerTest.java
@@ -104,7 +104,6 @@ public class ExecutionPlanRepoInitializerTest {
     public void setup() throws IOException, PackageException {
         when(registry.createExecutionPlan()).thenReturn(builder);
         when(builder.execute()).thenReturn(xplan);
-        when(builder2.execute()).thenReturn(xplan);
         this.statusFile = temporaryFolder.newFile(STATUSFILE_NAME + UUID.randomUUID());
     }
 


[sling-org-apache-sling-jcr-packageinit] 04/25: SLING-7871 - switching to commons-lang3

Posted by kw...@apache.org.
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-jcr-packageinit.git

commit 0051da8a83fdcb4804295fbbbd1af7df56de1833
Author: Dominik Suess <su...@adobe.com>
AuthorDate: Thu Sep 6 15:45:18 2018 +0200

    SLING-7871 - switching to commons-lang3
---
 packageinit/pom.xml | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/packageinit/pom.xml b/packageinit/pom.xml
index c49aefb..a697003 100644
--- a/packageinit/pom.xml
+++ b/packageinit/pom.xml
@@ -130,9 +130,9 @@
             <scope>provided</scope>
         </dependency>
         <dependency>
-            <groupId>commons-lang</groupId>
-            <artifactId>commons-lang</artifactId>
-            <version>2.6</version>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-lang3</artifactId>
+            <version>3.6</version>
             <scope>provided</scope>
         </dependency>
         <dependency>


[sling-org-apache-sling-jcr-packageinit] 22/25: SLING-10089 - spawning packageTask exceptions as errors & enhancing tests to check for corresponding logentries

Posted by kw...@apache.org.
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-jcr-packageinit.git

commit afaa1a17afcd3239476985510a3b4341f520b70a
Author: Dominik Suess <su...@adobe.com>
AuthorDate: Tue Jan 26 15:28:51 2021 +0100

    SLING-10089 - spawning packageTask exceptions as errors & enhancing tests to check for corresponding logentries
---
 .../impl/ExecutionPlanRepoInitializer.java         |  6 ++++
 .../ExecutionPlanRepoInitializerTest.java          | 38 +++++++++++++---------
 2 files changed, 29 insertions(+), 15 deletions(-)

diff --git a/src/main/java/org/apache/sling/jcr/packageinit/impl/ExecutionPlanRepoInitializer.java b/src/main/java/org/apache/sling/jcr/packageinit/impl/ExecutionPlanRepoInitializer.java
index 42f851a..1018631 100644
--- a/src/main/java/org/apache/sling/jcr/packageinit/impl/ExecutionPlanRepoInitializer.java
+++ b/src/main/java/org/apache/sling/jcr/packageinit/impl/ExecutionPlanRepoInitializer.java
@@ -20,6 +20,7 @@ import org.apache.commons.lang3.StringUtils;
 import org.apache.jackrabbit.vault.packaging.registry.ExecutionPlan;
 import org.apache.jackrabbit.vault.packaging.registry.ExecutionPlanBuilder;
 import org.apache.jackrabbit.vault.packaging.registry.PackageRegistry;
+import org.apache.jackrabbit.vault.packaging.registry.PackageTask;
 import org.apache.sling.jcr.api.SlingRepository;
 import org.apache.sling.jcr.api.SlingRepositoryInitializer;
 import org.osgi.framework.BundleContext;
@@ -164,6 +165,11 @@ public class ExecutionPlanRepoInitializer implements SlingRepositoryInitializer
                         ExecutionPlan xplan = builder.execute();
                         if (xplan.getTasks().size() > 0) {
                             if (xplan.hasErrors()) {
+                                for (PackageTask task : xplan.getTasks()) {
+                                    if (PackageTask.State.ERROR.equals(task.getState())){
+                                        logger.error("Error during installation of {}: {}", task.getPackageId().toString(), task.getError().toString());
+                                    }
+                                }
                                 throw new IllegalStateException("Excecutionplan execution contained errors - cannot complete repository initialization.");
                             }
                             logger.info("executionplan executed with {} entries", xplan.getTasks().size());
diff --git a/src/test/java/org/apache/sling/jcr/packageinit/ExecutionPlanRepoInitializerTest.java b/src/test/java/org/apache/sling/jcr/packageinit/ExecutionPlanRepoInitializerTest.java
index 5493d45..acdb656 100644
--- a/src/test/java/org/apache/sling/jcr/packageinit/ExecutionPlanRepoInitializerTest.java
+++ b/src/test/java/org/apache/sling/jcr/packageinit/ExecutionPlanRepoInitializerTest.java
@@ -41,10 +41,12 @@ import java.util.concurrent.TimeUnit;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.jackrabbit.vault.packaging.PackageException;
+import org.apache.jackrabbit.vault.packaging.PackageId;
 import org.apache.jackrabbit.vault.packaging.registry.ExecutionPlan;
 import org.apache.jackrabbit.vault.packaging.registry.ExecutionPlanBuilder;
 import org.apache.jackrabbit.vault.packaging.registry.PackageRegistry;
 import org.apache.jackrabbit.vault.packaging.registry.PackageTask;
+import org.apache.jackrabbit.vault.packaging.registry.PackageTask.State;
 import org.apache.jackrabbit.vault.packaging.registry.impl.FSPackageRegistry;
 import org.apache.sling.jcr.api.SlingRepository;
 import org.apache.sling.jcr.packageinit.impl.ExecutionPlanRepoInitializer;
@@ -57,7 +59,6 @@ import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.junit.runner.RunWith;
 import org.mockito.ArgumentCaptor;
-import org.mockito.Captor;
 import org.mockito.Mock;
 import org.mockito.Spy;
 import org.mockito.junit.MockitoJUnitRunner;
@@ -65,8 +66,7 @@ import org.slf4j.LoggerFactory;
 
 import ch.qos.logback.classic.Logger;
 import ch.qos.logback.classic.spi.ILoggingEvent;
-import ch.qos.logback.classic.spi.LoggingEvent;
-import ch.qos.logback.core.Appender;
+import ch.qos.logback.core.read.ListAppender;
 
 @RunWith(MockitoJUnitRunner.Silent.class)
 public class ExecutionPlanRepoInitializerTest {
@@ -109,11 +109,7 @@ public class ExecutionPlanRepoInitializerTest {
     @Mock
     ExecutionPlan xplan;
 
-    @Mock
-    private Appender<ILoggingEvent> mockAppender;
-    
-    @Captor
-    private ArgumentCaptor<LoggingEvent> captorLoggingEvent;
+    private ListAppender<ILoggingEvent> listAppender;
 
     private File statusFile;
     
@@ -126,14 +122,16 @@ public class ExecutionPlanRepoInitializerTest {
         when(builder.execute()).thenReturn(xplan);
         this.statusFile = temporaryFolder.newFile(STATUSFILE_NAME + UUID.randomUUID());
         final Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
-        logger.addAppender(mockAppender);
+        listAppender = new ListAppender<>();
+        listAppender.start();
+        logger.addAppender(listAppender);
         foundExceptions = new ArrayList<Exception>();
     }
 
     @After
     public void teardown() {
         final Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
-        logger.detachAppender(mockAppender);
+        logger.detachAppender(listAppender);
     }
 
     @Test
@@ -141,9 +139,8 @@ public class ExecutionPlanRepoInitializerTest {
         ExecutionPlanRepoInitializer initializer = registerRepoInitializer(new String[]{});
 
         initializer.processRepository(slingRepo);
-        verify(mockAppender).doAppend(captorLoggingEvent.capture());
-        final LoggingEvent loggingEvent = captorLoggingEvent.getValue();
-        assertThat(loggingEvent.getFormattedMessage(),
+        List<ILoggingEvent> logsList = listAppender.list;
+        assertThat(logsList.get(0).getFormattedMessage(),
                 is("No executionplans configured skipping init."));
     }
 
@@ -207,16 +204,27 @@ public class ExecutionPlanRepoInitializerTest {
         ArgumentCaptor<InputStream> captor = ArgumentCaptor.forClass(InputStream.class);
         
         List<PackageTask> ptl = new ArrayList<>();
-        ptl.add(mock(PackageTask.class));
+        PackageTask pt = mock(PackageTask.class);
+        when(pt.getPackageId()).thenReturn(PackageId.fromString("test:test:1.0"));
+        when(pt.getState()).thenReturn(State.ERROR);
+        when(pt.getError()).thenReturn(new Throwable("expectedException"));
+        ptl.add(pt);
         when(xplan.getTasks()).thenReturn(ptl);
         when(xplan.hasErrors()).thenReturn(true);
 
         processRepository(initializer, cdl, foundExceptions);
         
         context.bundleContext().registerService(PackageRegistry.class.getName(), registry, null);
-        cdl.await(500, TimeUnit.MILLISECONDS);
+        cdl.await(20500, TimeUnit.MILLISECONDS);
         verify(builder, times(1)).load(captor.capture());
         assertTrue("Expected IllegalStateException.",foundExceptions.get(0) instanceof IllegalStateException);
+        
+        List<ILoggingEvent> logsList = listAppender.list;
+        assertEquals("Waiting for PackageRegistry.", logsList.get(0)
+                                      .getMessage());
+        assertEquals("PackageRegistry found - starting execution of executionplan", logsList.get(1)
+            .getMessage());
+        assertEquals("Error during installation of test:test:1.0: java.lang.Throwable: expectedException", logsList.get(2).getFormattedMessage());
     }
 
 


[sling-org-apache-sling-jcr-packageinit] 12/25: SLING-8222 - adjusting cases to reflect valid cases on restart when hashes might vary

Posted by kw...@apache.org.
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-jcr-packageinit.git

commit eb3ccfd2a8efe8af8cc5c6c9ea9f3b71d9e1c54f
Author: Dominik Suess <su...@adobe.com>
AuthorDate: Thu Jan 17 13:38:47 2019 +0100

    SLING-8222 - adjusting cases to reflect valid cases on restart when hashes might vary
---
 .../impl/ExecutionPlanRepoInitializer.java         | 24 ++++++++++++++--------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/src/main/java/org/apache/sling/jcr/packageinit/impl/ExecutionPlanRepoInitializer.java b/src/main/java/org/apache/sling/jcr/packageinit/impl/ExecutionPlanRepoInitializer.java
index 9d5346f..ed61786 100644
--- a/src/main/java/org/apache/sling/jcr/packageinit/impl/ExecutionPlanRepoInitializer.java
+++ b/src/main/java/org/apache/sling/jcr/packageinit/impl/ExecutionPlanRepoInitializer.java
@@ -81,8 +81,8 @@ public class ExecutionPlanRepoInitializer implements SlingRepositoryInitializer
     private void activate(BundleContext context, Config config) throws FileNotFoundException, IOException {
         List<String> epCandidates = Arrays.asList(config.executionplans());
         if (!epCandidates.isEmpty()) {
-            if(StringUtils.isEmpty(config.statusfilepath())) {
-                // if no  path is configured lookup default file in bundledata
+            if (StringUtils.isEmpty(config.statusfilepath())) {
+                // if no path is configured lookup default file in bundledata
                 statusFile = context.getDataFile(EXECUTEDPLANS_FILE);
             } else {
                 Path statusFilePath = Paths.get(config.statusfilepath());
@@ -116,22 +116,23 @@ public class ExecutionPlanRepoInitializer implements SlingRepositoryInitializer
         // iterate over candidates and crosscheck next found hash
         while (candidateIt.hasNext()) {
             String candidate = candidateIt.next();
-            if (!executedHashesIt.hasNext()) {
+            boolean foundDifference = false;
+            if (!executedHashesIt.hasNext() || foundDifference) {
                 // if no further hashes are present add candidate
                 // (will iterate over rest and add rest)
                 executionPlans.add(candidate);
             } else {
-                // if another hash was found check if it matches the
-                // next candidate
+                // another hash was found & no difference 
                 Integer executedHash = executedHashesIt.next();
                 if (isCandidateProcessed(candidate, executedHash)) {
                     // already processed so no need to add - check
                     // next plan
                     continue;
                 } else {
-                    String msg = "Different content installed then configured - repository needs to be reset.";
-                    logger.error(msg);
-                    throw new IllegalStateException(msg);
+                    executionPlans.add(candidate);
+                    String msg = "Found difference in hashed executionplans - queueing executionplan for processing.";
+                    logger.info(msg);
+                    foundDifference = true;
                 }
             }
         }
@@ -161,7 +162,12 @@ public class ExecutionPlanRepoInitializer implements SlingRepositoryInitializer
                         builder.load(new ByteArrayInputStream(plan.getBytes("UTF-8")));
                         builder.with(session);
                         ExecutionPlan xplan = builder.execute();
-                        logger.info("executionplan executed with {} entries", xplan.getTasks().size());
+                        if (xplan.getTasks().size() > 0) {
+                            logger.info("executionplan executed with {} entries", xplan.getTasks().size());
+                        } else {
+                            logger.info("No tasks found in executionplan - no additional packages installed.");
+                        }
+                        
                         // save hashes to file for crosscheck on subsequent startup to avoid double processing
                         writer.write(String.valueOf(plan.hashCode()));
                         writer.newLine();


[sling-org-apache-sling-jcr-packageinit] 14/25: SLING-7245 - Validate pull requests using Jenkins

Posted by kw...@apache.org.
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-jcr-packageinit.git

commit aafe97884fa612139c9d552d882f4a48a52b72e8
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Tue Jan 29 23:10:25 2019 +0100

    SLING-7245 - Validate pull requests using Jenkins
---
 Jenkinsfile | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/Jenkinsfile b/Jenkinsfile
new file mode 100644
index 0000000..f582519
--- /dev/null
+++ b/Jenkinsfile
@@ -0,0 +1,20 @@
+/**
+ * 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.
+ */
+
+slingOsgiBundleBuild()


[sling-org-apache-sling-jcr-packageinit] 19/25: Updating badges for org-apache-sling-jcr-packageinit

Posted by kw...@apache.org.
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-jcr-packageinit.git

commit 81867ee3b3772e60e1ba0aad9870ebb4d460eee1
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Mon Aug 24 18:48:57 2020 +0200

    Updating badges for org-apache-sling-jcr-packageinit
---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 6ada88a..dbefd4b 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
 [<img src="https://sling.apache.org/res/logos/sling.png"/>](https://sling.apache.org)
 
- [![Build Status](https://builds.apache.org/buildStatus/icon?job=Sling/sling-org-apache-sling-jcr-packageinit/master)](https://builds.apache.org/job/Sling/job/sling-org-apache-sling-jcr-packageinit/job/master) [![Test Status](https://img.shields.io/jenkins/t/https/builds.apache.org/job/Sling/job/sling-org-apache-sling-jcr-packageinit/job/master.svg)](https://builds.apache.org/job/Sling/job/sling-org-apache-sling-jcr-packageinit/job/master/test_results_analyzer/) [![License](https://img.s [...]
+ [![Build Status](https://ci-builds.apache.org/job/Sling/job/modules/job/sling-org-apache-sling-jcr-packageinit/job/master/badge/icon)](https://ci-builds.apache.org/job/Sling/job/modules/job/sling-org-apache-sling-jcr-packageinit/job/master/) [![Test Status](https://img.shields.io/jenkins/tests.svg?jobUrl=https://ci-builds.apache.org/job/Sling/job/modules/job/sling-org-apache-sling-jcr-packageinit/job/master/)](https://ci-builds.apache.org/job/Sling/job/modules/job/sling-org-apache-sling [...]
 
 # Apache Sling JCR Package Initializer module
 


[sling-org-apache-sling-jcr-packageinit] 21/25: SLING-10089 - adding logic & test to consider failing on error in executionplan execution

Posted by kw...@apache.org.
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-jcr-packageinit.git

commit d314ede4e3a8ea63dec8bb910d067c88ac3700c1
Author: Dominik Suess <su...@adobe.com>
AuthorDate: Mon Jan 25 19:03:31 2021 +0100

    SLING-10089 - adding logic & test to consider failing on error in executionplan execution
---
 .../impl/ExecutionPlanRepoInitializer.java         |  3 ++
 .../ExecutionPlanRepoInitializerTest.java          | 46 +++++++++++++++++-----
 2 files changed, 40 insertions(+), 9 deletions(-)

diff --git a/src/main/java/org/apache/sling/jcr/packageinit/impl/ExecutionPlanRepoInitializer.java b/src/main/java/org/apache/sling/jcr/packageinit/impl/ExecutionPlanRepoInitializer.java
index ed61786..42f851a 100644
--- a/src/main/java/org/apache/sling/jcr/packageinit/impl/ExecutionPlanRepoInitializer.java
+++ b/src/main/java/org/apache/sling/jcr/packageinit/impl/ExecutionPlanRepoInitializer.java
@@ -163,6 +163,9 @@ public class ExecutionPlanRepoInitializer implements SlingRepositoryInitializer
                         builder.with(session);
                         ExecutionPlan xplan = builder.execute();
                         if (xplan.getTasks().size() > 0) {
+                            if (xplan.hasErrors()) {
+                                throw new IllegalStateException("Excecutionplan execution contained errors - cannot complete repository initialization.");
+                            }
                             logger.info("executionplan executed with {} entries", xplan.getTasks().size());
                         } else {
                             logger.info("No tasks found in executionplan - no additional packages installed.");
diff --git a/src/test/java/org/apache/sling/jcr/packageinit/ExecutionPlanRepoInitializerTest.java b/src/test/java/org/apache/sling/jcr/packageinit/ExecutionPlanRepoInitializerTest.java
index 46ee6a8..5493d45 100644
--- a/src/test/java/org/apache/sling/jcr/packageinit/ExecutionPlanRepoInitializerTest.java
+++ b/src/test/java/org/apache/sling/jcr/packageinit/ExecutionPlanRepoInitializerTest.java
@@ -20,7 +20,7 @@ import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
@@ -30,9 +30,11 @@ import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.StringWriter;
+import java.util.ArrayList;
 import java.util.Dictionary;
 import java.util.Hashtable;
 import java.util.Iterator;
+import java.util.List;
 import java.util.UUID;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
@@ -42,6 +44,7 @@ import org.apache.jackrabbit.vault.packaging.PackageException;
 import org.apache.jackrabbit.vault.packaging.registry.ExecutionPlan;
 import org.apache.jackrabbit.vault.packaging.registry.ExecutionPlanBuilder;
 import org.apache.jackrabbit.vault.packaging.registry.PackageRegistry;
+import org.apache.jackrabbit.vault.packaging.registry.PackageTask;
 import org.apache.jackrabbit.vault.packaging.registry.impl.FSPackageRegistry;
 import org.apache.sling.jcr.api.SlingRepository;
 import org.apache.sling.jcr.packageinit.impl.ExecutionPlanRepoInitializer;
@@ -114,6 +117,8 @@ public class ExecutionPlanRepoInitializerTest {
 
     private File statusFile;
     
+    private List<Exception> foundExceptions;
+    
 
     @Before
     public void setup() throws IOException, PackageException {
@@ -122,6 +127,7 @@ public class ExecutionPlanRepoInitializerTest {
         this.statusFile = temporaryFolder.newFile(STATUSFILE_NAME + UUID.randomUUID());
         final Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
         logger.addAppender(mockAppender);
+        foundExceptions = new ArrayList<Exception>();
     }
 
     @After
@@ -147,7 +153,7 @@ public class ExecutionPlanRepoInitializerTest {
         ExecutionPlanRepoInitializer initializer = registerRepoInitializer(EXECUTIONSPLANS);
 
         CountDownLatch cdl = new CountDownLatch(1);
-        processRepository(initializer, cdl);
+        processRepository(initializer, cdl, foundExceptions);
 
         assertTrue("processRespository() should not be completed before FSRegistry is available", cdl.getCount() > 0);
         ArgumentCaptor<InputStream> captor = ArgumentCaptor.forClass(InputStream.class);
@@ -169,7 +175,7 @@ public class ExecutionPlanRepoInitializerTest {
         ExecutionPlanRepoInitializer initializer = registerRepoInitializer(EXECUTIONSPLANS);
 
         CountDownLatch cdl = new CountDownLatch(1);
-        processRepository(initializer, cdl);
+        processRepository(initializer, cdl, foundExceptions);
 
         assertTrue("processRespository() should not be completed before FSRegistry is available", cdl.getCount() > 0);
         ArgumentCaptor<InputStream> captor = ArgumentCaptor.forClass(InputStream.class);
@@ -183,12 +189,36 @@ public class ExecutionPlanRepoInitializerTest {
         
         MockOsgi.deactivate(initializer, context.bundleContext());
         initializer = registerRepoInitializer(EXECUTIONSPLANS);
-        processRepository(initializer, cdl);;
+        processRepository(initializer, cdl, foundExceptions);
         
         cdl.await(500, TimeUnit.MILLISECONDS);
         verify(builder2, never()).load(captor.capture());
 
     }
+    
+
+    @Test
+    public void failOnError() throws Exception {
+        ExecutionPlanRepoInitializer initializer = registerRepoInitializer(EXECUTIONSPLANS);
+
+        CountDownLatch cdl = new CountDownLatch(1);
+
+        assertTrue("processRespository() should not be completed before FSRegistry is available", cdl.getCount() > 0);
+        ArgumentCaptor<InputStream> captor = ArgumentCaptor.forClass(InputStream.class);
+        
+        List<PackageTask> ptl = new ArrayList<>();
+        ptl.add(mock(PackageTask.class));
+        when(xplan.getTasks()).thenReturn(ptl);
+        when(xplan.hasErrors()).thenReturn(true);
+
+        processRepository(initializer, cdl, foundExceptions);
+        
+        context.bundleContext().registerService(PackageRegistry.class.getName(), registry, null);
+        cdl.await(500, TimeUnit.MILLISECONDS);
+        verify(builder, times(1)).load(captor.capture());
+        assertTrue("Expected IllegalStateException.",foundExceptions.get(0) instanceof IllegalStateException);
+    }
+
 
     private ExecutionPlanRepoInitializer registerRepoInitializer(String[] executionPlans) {
         ExecutionPlanRepoInitializer initializer = new ExecutionPlanRepoInitializer();
@@ -198,19 +228,17 @@ public class ExecutionPlanRepoInitializerTest {
         context.registerInjectActivateService(initializer, props);
         return initializer;
     }
-    
 
-    private void processRepository(ExecutionPlanRepoInitializer initializer, CountDownLatch cdl) {
+    private void processRepository(ExecutionPlanRepoInitializer initializer, CountDownLatch cdl, List<Exception> foundExceptions) {
         new Thread(new Runnable() {
             @Override
             public void run() {
                 try {
                     initializer.processRepository(slingRepo);
-                    cdl.countDown();
                 } catch (Exception e) {
-                    fail("Should not have thrown any exception");
+                    foundExceptions.add(e);
                 }
-
+                cdl.countDown();
             }
         }).start();
     }


[sling-org-apache-sling-jcr-packageinit] 16/25: Fixed an issue with the wrong scrop and ignored some files / folders

Posted by kw...@apache.org.
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-jcr-packageinit.git

commit a3cba29198389b86544ded28893d3d9a2401ff56
Author: Andreas Schaefer <sc...@iMac.local>
AuthorDate: Tue Jan 28 12:16:55 2020 -0800

    Fixed an issue with the wrong scrop and ignored some files / folders
---
 .gitignore | 2 ++
 pom.xml    | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/.gitignore b/.gitignore
index 7aba5f8..bd98a28 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,5 @@
 .settings
 .classpath
 .project
+*.iml
+target
diff --git a/pom.xml b/pom.xml
index 588e418..4543a69 100644
--- a/pom.xml
+++ b/pom.xml
@@ -142,7 +142,7 @@
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.testing.sling-mock.junit4</artifactId>
             <version>2.3.2</version>
-            <scope>testing</scope>
+            <scope>test</scope>
         </dependency>
               <dependency>
             <groupId>org.mockito</groupId>


[sling-org-apache-sling-jcr-packageinit] 06/25: Update dependencies to o.a.jackrabbit.vault 3.2.4

Posted by kw...@apache.org.
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-jcr-packageinit.git

commit aa4cc56324029ed1dbdf10391f3895df8dac7333
Author: Karl Pauls <ka...@gmail.com>
AuthorDate: Thu Sep 27 12:34:05 2018 +0200

    Update dependencies to o.a.jackrabbit.vault 3.2.4
---
 packageinit/pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/packageinit/pom.xml b/packageinit/pom.xml
index 9cdcbd4..73cd312 100644
--- a/packageinit/pom.xml
+++ b/packageinit/pom.xml
@@ -120,7 +120,7 @@
         <dependency>
             <groupId>org.apache.jackrabbit.vault</groupId>
             <artifactId>org.apache.jackrabbit.vault</artifactId>
-            <version>3.2.1-SNAPSHOT</version>
+            <version>3.2.4</version>
             <scope>provided</scope>
         </dependency>
         <dependency>


[sling-org-apache-sling-jcr-packageinit] 10/25: SLING-8010 - replacing nullcheck by check for empty list as it is always initialized

Posted by kw...@apache.org.
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-jcr-packageinit.git

commit 3c89f7fa5943a024fc88f54b9e0853d128201d14
Author: Dominik Suess <su...@adobe.com>
AuthorDate: Fri Oct 12 14:25:52 2018 +0200

    SLING-8010 - replacing nullcheck by check for empty list as it is always initialized
---
 .gitignore                                         |  3 ++
 .../impl/ExecutionPlanRepoInitializer.java         |  2 +-
 .../ExecutionPlanRepoInitializerTest.java          | 47 +++++++++++++++++++---
 3 files changed, 45 insertions(+), 7 deletions(-)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..7aba5f8
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+.settings
+.classpath
+.project
diff --git a/src/main/java/org/apache/sling/jcr/packageinit/impl/ExecutionPlanRepoInitializer.java b/src/main/java/org/apache/sling/jcr/packageinit/impl/ExecutionPlanRepoInitializer.java
index 8631cf7..9d5346f 100644
--- a/src/main/java/org/apache/sling/jcr/packageinit/impl/ExecutionPlanRepoInitializer.java
+++ b/src/main/java/org/apache/sling/jcr/packageinit/impl/ExecutionPlanRepoInitializer.java
@@ -143,7 +143,7 @@ public class ExecutionPlanRepoInitializer implements SlingRepositoryInitializer
 
     @Override
     public void processRepository(SlingRepository slingRepository) throws Exception {
-        if (executionPlans != null) {
+        if (!executionPlans.isEmpty()) {
             ServiceTracker<PackageRegistry, ?> st = new ServiceTracker<>(context, PackageRegistry.class, null);
             try {
                 st.open();
diff --git a/src/test/java/org/apache/sling/jcr/packageinit/ExecutionPlanRepoInitializerTest.java b/src/test/java/org/apache/sling/jcr/packageinit/ExecutionPlanRepoInitializerTest.java
index 40f4157..822ae8b 100644
--- a/src/test/java/org/apache/sling/jcr/packageinit/ExecutionPlanRepoInitializerTest.java
+++ b/src/test/java/org/apache/sling/jcr/packageinit/ExecutionPlanRepoInitializerTest.java
@@ -16,7 +16,9 @@
  */
 package org.apache.sling.jcr.packageinit;
 
+import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 import static org.mockito.Mockito.never;
@@ -45,15 +47,23 @@ import org.apache.sling.jcr.api.SlingRepository;
 import org.apache.sling.jcr.packageinit.impl.ExecutionPlanRepoInitializer;
 import org.apache.sling.testing.mock.osgi.MockOsgi;
 import org.apache.sling.testing.mock.sling.junit.SlingContext;
+import org.junit.After;
 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.Captor;
 import org.mockito.Mock;
 import org.mockito.Spy;
 import org.mockito.junit.MockitoJUnitRunner;
+import org.slf4j.LoggerFactory;
+
+import ch.qos.logback.classic.Logger;
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.classic.spi.LoggingEvent;
+import ch.qos.logback.core.Appender;
 
 @RunWith(MockitoJUnitRunner.class)
 public class ExecutionPlanRepoInitializerTest {
@@ -93,10 +103,15 @@ public class ExecutionPlanRepoInitializerTest {
     @Mock
     ExecutionPlanBuilder builder2;
 
-
     @Mock
     ExecutionPlan xplan;
 
+    @Mock
+    private Appender<ILoggingEvent> mockAppender;
+    
+    @Captor
+    private ArgumentCaptor<LoggingEvent> captorLoggingEvent;
+
     private File statusFile;
     
 
@@ -105,11 +120,31 @@ public class ExecutionPlanRepoInitializerTest {
         when(registry.createExecutionPlan()).thenReturn(builder);
         when(builder.execute()).thenReturn(xplan);
         this.statusFile = temporaryFolder.newFile(STATUSFILE_NAME + UUID.randomUUID());
+        final Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
+        logger.addAppender(mockAppender);
     }
 
+    @After
+    public void teardown() {
+        final Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
+        logger.detachAppender(mockAppender);
+    }
+
+    @Test
+    public void skipWithoutExecution() throws Exception {
+        ExecutionPlanRepoInitializer initializer = registerRepoInitializer(new String[]{});
+
+        initializer.processRepository(slingRepo);
+        verify(mockAppender).doAppend(captorLoggingEvent.capture());
+        final LoggingEvent loggingEvent = captorLoggingEvent.getValue();
+        assertThat(loggingEvent.getFormattedMessage(),
+                is("No executionplans configured skipping init."));
+    }
+
+
     @Test
     public void waitForRegistryAndInstall() throws Exception {
-        ExecutionPlanRepoInitializer initializer = registerRepoInitializer();
+        ExecutionPlanRepoInitializer initializer = registerRepoInitializer(EXECUTIONSPLANS);
 
         CountDownLatch cdl = new CountDownLatch(1);
         processRepository(initializer, cdl);
@@ -131,7 +166,7 @@ public class ExecutionPlanRepoInitializerTest {
 
     @Test
     public void doubleExecute() throws Exception {
-        ExecutionPlanRepoInitializer initializer = registerRepoInitializer();
+        ExecutionPlanRepoInitializer initializer = registerRepoInitializer(EXECUTIONSPLANS);
 
         CountDownLatch cdl = new CountDownLatch(1);
         processRepository(initializer, cdl);
@@ -147,7 +182,7 @@ public class ExecutionPlanRepoInitializerTest {
         when(registry.createExecutionPlan()).thenReturn(builder2);
         
         MockOsgi.deactivate(initializer, context.bundleContext());
-        initializer = registerRepoInitializer();
+        initializer = registerRepoInitializer(EXECUTIONSPLANS);
         processRepository(initializer, cdl);;
         
         cdl.await(500, TimeUnit.MILLISECONDS);
@@ -155,10 +190,10 @@ public class ExecutionPlanRepoInitializerTest {
 
     }
 
-    private ExecutionPlanRepoInitializer registerRepoInitializer() {
+    private ExecutionPlanRepoInitializer registerRepoInitializer(String[] executionPlans) {
         ExecutionPlanRepoInitializer initializer = new ExecutionPlanRepoInitializer();
         Dictionary<String, Object> props = new Hashtable<String, Object>();
-        props.put("executionplans", EXECUTIONSPLANS);
+        props.put("executionplans", executionPlans);
         props.put("statusfilepath", statusFile.getAbsolutePath());
         context.registerInjectActivateService(initializer, props);
         return initializer;


[sling-org-apache-sling-jcr-packageinit] 18/25: [maven-release-plugin] prepare for next development iteration

Posted by kw...@apache.org.
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-jcr-packageinit.git

commit 7a5d00a66ed1f555301ef3129f8af68e2cf6d5f8
Author: Andreas Schaefer <sc...@iMac.local>
AuthorDate: Tue Jan 28 12:20:30 2020 -0800

    [maven-release-plugin] prepare for next development iteration
---
 pom.xml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/pom.xml b/pom.xml
index aa4df1c..f897480 100644
--- a/pom.xml
+++ b/pom.xml
@@ -29,7 +29,7 @@
 
   <artifactId>org.apache.sling.jcr.packageinit</artifactId>
   <packaging>bundle</packaging>
-  <version>1.0.0</version>
+  <version>1.0.1-SNAPSHOT</version>
   <name>Apache Sling JCR Package Initializer module</name>
   <description>
 	  Installs packages into a JCR repository as SlingRepositoryInitializer based on a FileVault ExecutionPlan
@@ -38,7 +38,7 @@
         <connection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-packageinit.git</connection>
         <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-packageinit.git</developerConnection>
         <url>https://gitbox.apache.org/repos/asf?p=sling-org-apache-sling-jcr-packageinit.git</url>
-        <tag>org.apache.sling.jcr.packageinit-1.0.0</tag>
+        <tag>HEAD</tag>
     </scm>
     <build>
         <plugins>


[sling-org-apache-sling-jcr-packageinit] 11/25: Fix the tests

Posted by kw...@apache.org.
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-jcr-packageinit.git

commit 9173507f3ea9af45990d75f466347a004d98c82b
Author: Karl Pauls <kp...@adobe.com>
AuthorDate: Fri Oct 12 17:03:35 2018 +0200

    Fix the tests
---
 pom.xml                                                             | 6 ++++++
 .../sling/jcr/packageinit/ExecutionPlanRepoInitializerTest.java     | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 3e973f4..588e418 100644
--- a/pom.xml
+++ b/pom.xml
@@ -150,5 +150,11 @@
             <version>2.21.0</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+           <groupId>ch.qos.logback</groupId>
+           <artifactId>logback-classic</artifactId>
+           <version>1.2.3</version>
+           <scope>test</scope>
+       </dependency>
     </dependencies>
 </project>
diff --git a/src/test/java/org/apache/sling/jcr/packageinit/ExecutionPlanRepoInitializerTest.java b/src/test/java/org/apache/sling/jcr/packageinit/ExecutionPlanRepoInitializerTest.java
index 822ae8b..46ee6a8 100644
--- a/src/test/java/org/apache/sling/jcr/packageinit/ExecutionPlanRepoInitializerTest.java
+++ b/src/test/java/org/apache/sling/jcr/packageinit/ExecutionPlanRepoInitializerTest.java
@@ -65,7 +65,7 @@ import ch.qos.logback.classic.spi.ILoggingEvent;
 import ch.qos.logback.classic.spi.LoggingEvent;
 import ch.qos.logback.core.Appender;
 
-@RunWith(MockitoJUnitRunner.class)
+@RunWith(MockitoJUnitRunner.Silent.class)
 public class ExecutionPlanRepoInitializerTest {
     
     static String EXECUTIONPLAN_1 =


[sling-org-apache-sling-jcr-packageinit] 07/25: Move content to top-level

Posted by kw...@apache.org.
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-jcr-packageinit.git

commit b0f41a19d112815f764612d738ab437ec5b44651
Author: Karl Pauls <kp...@adobe.com>
AuthorDate: Wed Oct 10 12:30:13 2018 +0200

    Move content to top-level
---
 packageinit/README.md => README.md                                        | 0
 packageinit/pom.xml => pom.xml                                            | 0
 .../apache/sling/jcr/packageinit/impl/ExecutionPlanRepoInitializer.java   | 0
 .../apache/sling/jcr/packageinit/ExecutionPlanRepoInitializerTest.java    | 0
 4 files changed, 0 insertions(+), 0 deletions(-)

diff --git a/packageinit/README.md b/README.md
similarity index 100%
rename from packageinit/README.md
rename to README.md
diff --git a/packageinit/pom.xml b/pom.xml
similarity index 100%
rename from packageinit/pom.xml
rename to pom.xml
diff --git a/packageinit/src/main/java/org/apache/sling/jcr/packageinit/impl/ExecutionPlanRepoInitializer.java b/src/main/java/org/apache/sling/jcr/packageinit/impl/ExecutionPlanRepoInitializer.java
similarity index 100%
rename from packageinit/src/main/java/org/apache/sling/jcr/packageinit/impl/ExecutionPlanRepoInitializer.java
rename to src/main/java/org/apache/sling/jcr/packageinit/impl/ExecutionPlanRepoInitializer.java
diff --git a/packageinit/src/test/java/org/apache/sling/jcr/packageinit/ExecutionPlanRepoInitializerTest.java b/src/test/java/org/apache/sling/jcr/packageinit/ExecutionPlanRepoInitializerTest.java
similarity index 100%
rename from packageinit/src/test/java/org/apache/sling/jcr/packageinit/ExecutionPlanRepoInitializerTest.java
rename to src/test/java/org/apache/sling/jcr/packageinit/ExecutionPlanRepoInitializerTest.java


[sling-org-apache-sling-jcr-packageinit] 02/25: SLING-7871 - adding README

Posted by kw...@apache.org.
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-jcr-packageinit.git

commit 47e2ea8fa36f20bca4a8d330668c8f84945796c5
Author: Dominik Suess <su...@adobe.com>
AuthorDate: Thu Sep 6 12:19:09 2018 +0200

    SLING-7871 - adding README
---
 packageinit/README.md | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/packageinit/README.md b/packageinit/README.md
new file mode 100644
index 0000000..500d38e
--- /dev/null
+++ b/packageinit/README.md
@@ -0,0 +1,5 @@
+# Apache Sling JCR Package Initializer module
+
+This module is part of the [Apache Sling](https://sling.apache.org) project.
+
+This project is about creating a SlingRepositoryInitializer initializing the JCR Repository from a given FSPackageRegistry with precalculated ExecutionPlans.