You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2020/04/29 10:44:25 UTC

[sling-org-apache-sling-installer-factory-feature] 06/08: Use OSGi configuration for repoinit to avoid dependencies to all the JCR services

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

cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-installer-factory-feature.git

commit 07037cacbd5efa4c5bdb5e0037360a782b888f88
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Mon Apr 20 15:41:51 2020 +0200

    Use OSGi configuration for repoinit to avoid dependencies to all the JCR services
---
 .../model/impl/FeatureModelInstallerPlugin.java     | 20 ++++++++------------
 .../factory/model/impl/InstallContext.java          | 21 +++++++++------------
 .../factory/model/impl/InstallFeatureModelTask.java | 19 ++++++++++---------
 3 files changed, 27 insertions(+), 33 deletions(-)

diff --git a/src/main/java/org/apache/sling/installer/factory/model/impl/FeatureModelInstallerPlugin.java b/src/main/java/org/apache/sling/installer/factory/model/impl/FeatureModelInstallerPlugin.java
index 3023feb..fb34de2 100644
--- a/src/main/java/org/apache/sling/installer/factory/model/impl/FeatureModelInstallerPlugin.java
+++ b/src/main/java/org/apache/sling/installer/factory/model/impl/FeatureModelInstallerPlugin.java
@@ -50,13 +50,9 @@ import org.apache.sling.installer.api.tasks.ResourceTransformer;
 import org.apache.sling.installer.api.tasks.TaskResource;
 import org.apache.sling.installer.api.tasks.TaskResourceGroup;
 import org.apache.sling.installer.api.tasks.TransformationResult;
-import org.apache.sling.jcr.api.SlingRepository;
-import org.apache.sling.jcr.repoinit.JcrRepoInitOpsProcessor;
-import org.apache.sling.repoinit.parser.RepoInitParser;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
-import org.osgi.service.component.annotations.Reference;
 import org.osgi.service.metatype.annotations.AttributeDefinition;
 import org.osgi.service.metatype.annotations.Designate;
 import org.osgi.service.metatype.annotations.ObjectClassDefinition;
@@ -98,14 +94,14 @@ public class FeatureModelInstallerPlugin implements InstallTaskFactory, Resource
     /** Logger. */
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
 
-    @Reference
-    private SlingRepository repository;
+//    @Reference
+//    private SlingRepository repository;
 
-    @Reference
-    private JcrRepoInitOpsProcessor repoInitProcessor;
+//    @Reference
+//    private JcrRepoInitOpsProcessor repoInitProcessor;
 
-    @Reference
-    private RepoInitParser repoInitParser;
+//    @Reference
+//    private RepoInitParser repoInitParser;
 
     private final BundleContext bundleContext;
 
@@ -158,7 +154,7 @@ public class FeatureModelInstallerPlugin implements InstallTaskFactory, Resource
                 logger.info("Unable to read feature model from " + resource.getURL(), ioe);
             }
         }
-        if (resource.getType().equals(InstallableResource.TYPE_FILE) && resource.getURL().endsWith(".zip")) {
+        if (resource.getType().equals(InstallableResource.TYPE_FILE) && resource.getURL().endsWith(".far")) {
             try (final InputStream is = resource.getInputStream()) {
                 features.addAll(ArchiveReader.read(is, null));
             } catch (final IOException ioe) {
@@ -238,7 +234,7 @@ public class FeatureModelInstallerPlugin implements InstallTaskFactory, Resource
         if (rsrc.getState() == ResourceState.UNINSTALL ) {
             return new UninstallFeatureModelTask(group, bundleContext);
         }
-        final InstallContext ctx = new InstallContext(this.repository, this.repoInitProcessor, this.repoInitParser,
+        final InstallContext ctx = new InstallContext(//this.repository, this.repoInitProcessor, this.repoInitParser,
                 this.artifactManager, this.storageDirectory);
         return new InstallFeatureModelTask(group,
                 ctx, this.bundleContext);
diff --git a/src/main/java/org/apache/sling/installer/factory/model/impl/InstallContext.java b/src/main/java/org/apache/sling/installer/factory/model/impl/InstallContext.java
index 0af42fa..9f7f42f 100644
--- a/src/main/java/org/apache/sling/installer/factory/model/impl/InstallContext.java
+++ b/src/main/java/org/apache/sling/installer/factory/model/impl/InstallContext.java
@@ -21,29 +21,26 @@ package org.apache.sling.installer.factory.model.impl;
 import java.io.File;
 
 import org.apache.sling.feature.io.artifacts.ArtifactManager;
-import org.apache.sling.jcr.api.SlingRepository;
-import org.apache.sling.jcr.repoinit.JcrRepoInitOpsProcessor;
-import org.apache.sling.repoinit.parser.RepoInitParser;
 
 public class InstallContext {
 
-    public final SlingRepository repository;
+//    public final SlingRepository repository;
 
-    public final JcrRepoInitOpsProcessor repoInitProcessor;
+//    public final JcrRepoInitOpsProcessor repoInitProcessor;
 
-    public final RepoInitParser repoInitParser;
+//    public final RepoInitParser repoInitParser;
 
     public final ArtifactManager artifactManager;
 
     public final File storageDirectory;
 
-    public InstallContext(final SlingRepository repository,
-            final JcrRepoInitOpsProcessor repoInitProcessor,
-            final RepoInitParser repoInitParser,
+    public InstallContext(//final SlingRepository repository,
+//            final JcrRepoInitOpsProcessor repoInitProcessor,
+//            final RepoInitParser repoInitParser,
             final ArtifactManager artifactManager, final File storageDirectory) {
-        this.repository = repository;
-        this.repoInitProcessor = repoInitProcessor;
-        this.repoInitParser = repoInitParser;
+//        this.repository = repository;
+//        this.repoInitProcessor = repoInitProcessor;
+//        this.repoInitParser = repoInitParser;
         this.artifactManager = artifactManager;
         this.storageDirectory = storageDirectory;
     }
diff --git a/src/main/java/org/apache/sling/installer/factory/model/impl/InstallFeatureModelTask.java b/src/main/java/org/apache/sling/installer/factory/model/impl/InstallFeatureModelTask.java
index 5e97d54..efce876 100644
--- a/src/main/java/org/apache/sling/installer/factory/model/impl/InstallFeatureModelTask.java
+++ b/src/main/java/org/apache/sling/installer/factory/model/impl/InstallFeatureModelTask.java
@@ -32,9 +32,6 @@ import java.util.Dictionary;
 import java.util.Hashtable;
 import java.util.List;
 
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-
 import org.apache.sling.feature.Artifact;
 import org.apache.sling.feature.ArtifactId;
 import org.apache.sling.feature.Configuration;
@@ -50,8 +47,6 @@ import org.apache.sling.installer.api.tasks.InstallationContext;
 import org.apache.sling.installer.api.tasks.ResourceState;
 import org.apache.sling.installer.api.tasks.TaskResource;
 import org.apache.sling.installer.api.tasks.TaskResourceGroup;
-import org.apache.sling.repoinit.parser.RepoInitParsingException;
-import org.apache.sling.repoinit.parser.operations.Operation;
 import org.osgi.framework.BundleContext;
 
 /**
@@ -85,7 +80,7 @@ public class InstallFeatureModelTask extends AbstractFeatureModelTask {
                     this.getResourceGroup().setFinishState(ResourceState.IGNORED);
                 } else {
                     // repo init first
-                    if (result.repoinit != null) {
+/*                    if (result.repoinit != null) {
                         List<Operation> ops = null;
                         try (final Reader r = new StringReader(result.repoinit)) {
                             ops = this.installContext.repoInitParser.parse(r);
@@ -115,7 +110,7 @@ public class InstallFeatureModelTask extends AbstractFeatureModelTask {
                                 session.logout();
                             }
                         }
-                    }
+                    }*/
                     if (!result.resources.isEmpty()) {
                         final OsgiInstaller installer = this.getService(OsgiInstaller.class);
                         if (installer != null) {
@@ -143,7 +138,7 @@ public class InstallFeatureModelTask extends AbstractFeatureModelTask {
 
     public static final class Result {
         public final List<InstallableResource> resources = new ArrayList<>();
-        public String repoinit;
+//        public String repoinit;
     }
 
     private File getArtifactFile(final File baseDir, final ArtifactId id) {
@@ -210,7 +205,13 @@ public class InstallFeatureModelTask extends AbstractFeatureModelTask {
 
         final Extension repoInit = feature.getExtensions().getByName(Extension.EXTENSION_NAME_REPOINIT);
         if (repoInit != null && repoInit.getType() == ExtensionType.TEXT) {
-            result.repoinit = repoInit.getText();
+//            result.repoinit = repoInit.getText();
+            final String configPid = "org.apache.sling.jcr.repoinit.RepositoryInitializer~".concat(feature.getId().toMvnName().replace('-', '_'));
+            final Dictionary<String, Object> props = new Hashtable<>();
+            props.put("scripts", repoInit.getText());
+
+            result.resources.add(new InstallableResource("/".concat(configPid).concat(".config"), null,
+                    props, null, InstallableResource.TYPE_CONFIG, null));
         }
         return result;
     }