You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by da...@apache.org on 2018/04/27 09:44:04 UTC

[sling-slingfeature-maven-plugin] 05/14: [Feature Model] Support separate phases for reading variables

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

davidb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-slingfeature-maven-plugin.git

commit 420177661c9619f65e4d94404f3e0be13eb6b8b3
Author: David Bosschaert <da...@gmail.com>
AuthorDate: Fri Mar 16 12:01:14 2018 +0000

    [Feature Model] Support separate phases for reading variables
    
    Variables in the feature model must be substituted at different points in
    time, depending on where they reside. Variables in the includes, bundle,
    requirements and capabilities section must be substituted before the
    resolver runs, as they influence the resolver result. They should not be
    substituted at launch time. Other variables, such as configuration and
    framework properties variables must be substituted at launch time.
---
 .../apache/sling/feature/maven/Preprocessor.java   | 27 +++++++++++-----------
 .../apache/sling/feature/maven/ProjectHelper.java  |  5 ++--
 2 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/src/main/java/org/apache/sling/feature/maven/Preprocessor.java b/src/main/java/org/apache/sling/feature/maven/Preprocessor.java
index 1435e4b..3799712 100644
--- a/src/main/java/org/apache/sling/feature/maven/Preprocessor.java
+++ b/src/main/java/org/apache/sling/feature/maven/Preprocessor.java
@@ -16,15 +16,6 @@
  */
 package org.apache.sling.feature.maven;
 
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.Reader;
-import java.io.StringReader;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.stream.Collectors;
-
 import org.apache.maven.model.Dependency;
 import org.apache.maven.project.MavenProject;
 import org.apache.sling.feature.Artifact;
@@ -37,8 +28,18 @@ import org.apache.sling.feature.process.FeatureBuilder;
 import org.apache.sling.feature.process.FeatureProvider;
 import org.apache.sling.feature.support.FeatureUtil;
 import org.apache.sling.feature.support.json.FeatureJSONReader;
+import org.apache.sling.feature.support.json.FeatureJSONReader.Phase;
 import org.codehaus.plexus.logging.Logger;
 
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
 /**
  * The processor processes all feature projects.
  */
@@ -193,7 +194,7 @@ public class Preprocessor {
 
                 // We should pass in an "id" to FeatureJSONReader.read and later on check the id (again, need to handle ref files)
                 try (final FileReader reader = new FileReader(file)) {
-                    final Feature feature = FeatureJSONReader.read(reader, id, file.getAbsolutePath());
+                    final Feature feature = FeatureJSONReader.read(reader, id, file.getAbsolutePath(), Phase.RESOLVE);
 
                     this.checkFeatureId(id, feature);
 
@@ -368,7 +369,7 @@ public class Preprocessor {
         if ( config.getInlinedFeature() != null ) {
             logger.debug("Reading inlined model from project " + project.getId());
             try (final Reader reader = new StringReader(config.getInlinedFeature())) {
-                feature = FeatureJSONReader.read(reader, id, null);
+                feature = FeatureJSONReader.read(reader, id, null, Phase.RESOLVE);
             } catch ( final IOException io) {
                 throw new RuntimeException("Unable to read inlined feature", io);
             }
@@ -379,7 +380,7 @@ public class Preprocessor {
             }
             logger.debug("Reading feature " + featureFile + " in project " + project.getId());
             try (final FileReader reader = new FileReader(featureFile)) {
-                feature = FeatureJSONReader.read(reader, id, featureFile.getAbsolutePath());
+                feature = FeatureJSONReader.read(reader, id, featureFile.getAbsolutePath(), Phase.RESOLVE);
             } catch ( final IOException io) {
                 throw new RuntimeException("Unable to read feature " + featureFile, io);
             }
@@ -502,7 +503,7 @@ public class Preprocessor {
                     // "external" dependency, we can already resolve it
                     final File featureFile = ProjectHelper.getOrResolveArtifact(info.project, env.session, env.artifactHandlerManager, env.resolver, id).getFile();
                     try (final FileReader r = new FileReader(featureFile)) {
-                        return FeatureJSONReader.read(r, featureFile.getAbsolutePath());
+                        return FeatureJSONReader.read(r, featureFile.getAbsolutePath(), Phase.RESOLVE);
                     } catch ( final IOException ioe) {
                         env.logger.error("Unable to read feature file from " + featureFile, ioe);
                     }
diff --git a/src/main/java/org/apache/sling/feature/maven/ProjectHelper.java b/src/main/java/org/apache/sling/feature/maven/ProjectHelper.java
index a314113..2efb69c 100644
--- a/src/main/java/org/apache/sling/feature/maven/ProjectHelper.java
+++ b/src/main/java/org/apache/sling/feature/maven/ProjectHelper.java
@@ -31,6 +31,7 @@ import org.apache.maven.project.MavenProject;
 import org.apache.sling.feature.ArtifactId;
 import org.apache.sling.feature.Feature;
 import org.apache.sling.feature.support.json.FeatureJSONReader;
+import org.apache.sling.feature.support.json.FeatureJSONReader.Phase;
 import org.apache.sling.feature.support.json.FeatureJSONWriter;
 import org.codehaus.plexus.util.xml.Xpp3Dom;
 
@@ -95,7 +96,7 @@ public abstract class ProjectHelper {
                 result = null;
             } else {
                 try ( final StringReader r = new StringReader(text) ) {
-                    result = FeatureJSONReader.read(r, project.getId());
+                    result = FeatureJSONReader.read(r, project.getId(), Phase.RESOLVE);
                     project.setContextValue(cacheKey, result);
                 } catch ( final IOException ioe) {
                     throw new RuntimeException(ioe.getMessage(), ioe);
@@ -124,7 +125,7 @@ public abstract class ProjectHelper {
                         throw new RuntimeException("Unable to get feature from internal store.");
                     }
                     try ( final StringReader r = new StringReader(text) ) {
-                        final Feature feature = FeatureJSONReader.read(r, project.getId());
+                        final Feature feature = FeatureJSONReader.read(r, project.getId(), Phase.RESOLVE);
                         result.add(feature);
                     } catch ( final IOException ioe) {
                         throw new RuntimeException(ioe.getMessage(), ioe);

-- 
To stop receiving notification emails like this one, please contact
davidb@apache.org.