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

rombert pushed a commit to annotated tag slingstart-maven-plugin-1.3.0
in repository 
https://gitbox.apache.org/repos/asf/sling-slingstart-maven-plugin.git

commit f93e40b7ac3419aa61bf819999eb0a0e9a7cfc99
Author: Carsten Ziegeler <[email protected]>
AuthorDate: Tue Jul 28 12:11:15 2015 +0000

    SLING-4912 : Support inlining the model in the pom
    
    git-svn-id: 
https://svn.apache.org/repos/asf/sling/trunk/tooling/maven/slingstart-maven-plugin@1693076
 13f79535-47bb-0310-9956-ffa450edef68
---
 .../maven/slingstart/AbstractSlingStartMojo.java   | 11 ++++++++
 .../slingstart/DependencyLifecycleParticipant.java | 31 +++++++++++++++++++---
 2 files changed, 38 insertions(+), 4 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/maven/slingstart/AbstractSlingStartMojo.java 
b/src/main/java/org/apache/sling/maven/slingstart/AbstractSlingStartMojo.java
index 8323df6..04af510 100644
--- 
a/src/main/java/org/apache/sling/maven/slingstart/AbstractSlingStartMojo.java
+++ 
b/src/main/java/org/apache/sling/maven/slingstart/AbstractSlingStartMojo.java
@@ -31,9 +31,20 @@ import 
org.apache.sling.provisioning.model.ModelUtility.ResolverOptions;
  */
 public abstract class AbstractSlingStartMojo extends AbstractMojo {
 
+    /**
+     * The model directory
+     * This parameter is evaluated in the DependencyLifecycleParticipant
+     */
     @Parameter(defaultValue="${basedir}/src/main/provisioning")
     private File modelDirectory;
 
+    /**
+     * Inlined model, supported since version 1.3.
+     * This parameter is evaluated in the DependencyLifecycleParticipant
+     */
+    @Parameter
+    private String model;
+
     @Parameter(property = "project", readonly = true, required = true)
     protected MavenProject project;
 
diff --git 
a/src/main/java/org/apache/sling/maven/slingstart/DependencyLifecycleParticipant.java
 
b/src/main/java/org/apache/sling/maven/slingstart/DependencyLifecycleParticipant.java
index 172e3ed..15b71c7 100644
--- 
a/src/main/java/org/apache/sling/maven/slingstart/DependencyLifecycleParticipant.java
+++ 
b/src/main/java/org/apache/sling/maven/slingstart/DependencyLifecycleParticipant.java
@@ -19,6 +19,8 @@ package org.apache.sling.maven.slingstart;
 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.Collections;
 import java.util.HashMap;
@@ -140,12 +142,14 @@ public class DependencyLifecycleParticipant extends 
AbstractMavenLifecyclePartic
         final String directory = nodeValue(info.plugin,
                 "modelDirectory",
                 new File(info.project.getBasedir(), 
"src/main/provisioning").getAbsolutePath());
+        final String inlinedModel = nodeValue(info.plugin,
+                "model", null);
         try {
-            info.localModel = readLocalModel(info.project, new 
File(directory), env.logger);
+            info.localModel = readLocalModel(info.project, inlinedModel, new 
File(directory), env.logger);
         } catch ( final IOException ioe) {
             throw new MavenExecutionException(ioe.getMessage(), ioe);
         }
-        
+
         // prepare resolver options
         ResolverOptions resolverOptions = new ResolverOptions();
         if (nodeBooleanValue(info.plugin, "usePomVariables", false)) {
@@ -386,6 +390,7 @@ public class DependencyLifecycleParticipant extends 
AbstractMavenLifecyclePartic
      */
     private static Model readLocalModel(
             final MavenProject project,
+            final String inlinedModel,
             final File modelDirectory,
             final Logger logger)
     throws MavenExecutionException, IOException {
@@ -400,10 +405,28 @@ public class DependencyLifecycleParticipant extends 
AbstractMavenLifecyclePartic
             }
             Collections.sort(candidates);
         }
-        if ( candidates.size() == 0 ) {
-            throw new MavenExecutionException("No model files found in " + 
modelDirectory, (File)null);
+        if ( candidates.size() == 0 && (inlinedModel == null || 
inlinedModel.trim().length() == 0) ) {
+            throw new MavenExecutionException("No model files found in " + 
modelDirectory + ", and no model inlined in POM.", (File)null);
         }
         final Model result = new Model();
+        if ( inlinedModel != null ) {
+            logger.debug("Reading inlined model from project " + 
project.getId());
+            try {
+                final Reader reader = new StringReader(inlinedModel);
+                try {
+                    final Model current = ModelReader.read(reader, "pom");
+                    final Map<Traceable, String> errors = 
ModelUtility.validate(current);
+                    if (errors != null ) {
+                        throw new MavenExecutionException("Invalid inlined 
model : " + errors, (File)null);
+                    }
+                    ModelUtility.merge(result, current, false);
+                } finally {
+                    IOUtils.closeQuietly(reader);
+                }
+            } catch ( final IOException io) {
+                throw new MavenExecutionException("Unable to read inlined 
model", io);
+            }
+        }
         for(final String name : candidates) {
             logger.debug("Reading model " + name + " in project " + 
project.getId());
             try {

-- 
To stop receiving notification emails like this one, please contact
"[email protected]" <[email protected]>.

Reply via email to