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 2017/02/23 14:29:50 UTC

svn commit: r1784136 - /sling/trunk/tooling/maven/slingstart-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/PreparePackageMojo.java

Author: kwin
Date: Thu Feb 23 14:29:50 2017
New Revision: 1784136

URL: http://svn.apache.org/viewvc?rev=1784136&view=rev
Log:
SLING-6556 allow to reference the main artifact of the build within the model (in case it has been built already)

Modified:
    sling/trunk/tooling/maven/slingstart-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/PreparePackageMojo.java

Modified: sling/trunk/tooling/maven/slingstart-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/PreparePackageMojo.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/maven/slingstart-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/PreparePackageMojo.java?rev=1784136&r1=1784135&r2=1784136&view=diff
==============================================================================
--- sling/trunk/tooling/maven/slingstart-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/PreparePackageMojo.java (original)
+++ sling/trunk/tooling/maven/slingstart-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/PreparePackageMojo.java Thu Feb 23 14:29:50 2017
@@ -42,6 +42,7 @@ import org.apache.maven.MavenExecutionEx
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
 import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.plugin.MojoExecution;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugins.annotations.Component;
@@ -116,6 +117,9 @@ public class PreparePackageMojo extends
     @Component
     private ArtifactResolver resolver;
 
+    @Parameter(defaultValue = "${mojoExecution}", readonly = true, required = true)
+    protected MojoExecution mojoExecution;
+
     @Override
     public void execute() throws MojoExecutionException, MojoFailureException {
         final Model model = ProjectHelper.getEffectiveModel(this.project, getResolverOptions());
@@ -270,8 +274,25 @@ public class PreparePackageMojo extends
                             break;
                         }
                     }
-                    if ( artifact == null ) {
-                        throw new MojoExecutionException("Unable to find artifact from same project: " + a.toMvnUrl());
+                    // check if the artifact is bound already?
+                    if (project.getArtifact().getFile().exists()) {
+                        if (a.getClassifier() != null) {
+                            if (a.getClassifier().equals(project.getArtifact().getClassifier())) {
+                                artifact = project.getArtifact();
+                            } else {
+                                throw new MojoExecutionException(
+                                        "Unable to find artifact from same project with the given classifier: " + a.toMvnUrl());
+                            }
+                        } else {
+                            if (project.getArtifact().getClassifier() == null) {
+                                artifact = project.getArtifact();
+                            } else {
+                                throw new MojoExecutionException("Unable to find artifact with no classifier from same project, because the main artifact is bound to classifier " + project.getArtifact().getClassifier());
+                            }
+                        }
+                    } else {
+                        throw new MojoExecutionException("You must not reference artifact " + a.toMvnUrl()
+                                + " from the model which is not yet available in the phase '" + mojoExecution.getLifecyclePhase()+ ". Make sure to execute this goal after phase 'package'");
                     }
                 } else {
                     artifact = ModelUtils.getArtifact(this.project, this.mavenSession, this.artifactHandlerManager, this.resolver,