You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2015/04/22 00:01:29 UTC

svn commit: r1675202 - in /maven/plugins/branches/m-install-p-3.0: ./ src/it/attach-jar-checksum/ src/it/generate-pom-auto-1/ src/it/jar-sources-javadoc/ src/it/pom-checksum/ src/main/java/org/apache/maven/plugin/install/

Author: rfscholte
Date: Tue Apr 21 22:01:29 2015
New Revision: 1675202

URL: http://svn.apache.org/r1675202
Log:
[MINSTALL-114] Plugin shouldn't depend on maven-compat dependency
Give maven-compat the test scope. Can't remove it yet, since maven-plugin-testing-harness depends on a couple of its classes.
Remove IT verification of md5 and sha1 files of maven-metadata files, this is all handled by Aether which doesn't generate these files.
Use org.apache.maven.model.validation.ModelValidator.validateEffectiveModel to validate generated pom of install-file.

Modified:
    maven/plugins/branches/m-install-p-3.0/pom.xml
    maven/plugins/branches/m-install-p-3.0/src/it/attach-jar-checksum/verify.bsh
    maven/plugins/branches/m-install-p-3.0/src/it/generate-pom-auto-1/verify.bsh
    maven/plugins/branches/m-install-p-3.0/src/it/jar-sources-javadoc/verify.bsh
    maven/plugins/branches/m-install-p-3.0/src/it/pom-checksum/verify.bsh
    maven/plugins/branches/m-install-p-3.0/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java

Modified: maven/plugins/branches/m-install-p-3.0/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/branches/m-install-p-3.0/pom.xml?rev=1675202&r1=1675201&r2=1675202&view=diff
==============================================================================
--- maven/plugins/branches/m-install-p-3.0/pom.xml (original)
+++ maven/plugins/branches/m-install-p-3.0/pom.xml Tue Apr 21 22:01:29 2015
@@ -91,11 +91,6 @@ under the License.
       <version>${mavenVersion}</version>
     </dependency>
 
-    <dependency> <!-- TO BE REMOVED -->
-      <groupId>org.apache.maven</groupId>
-      <artifactId>maven-compat</artifactId>
-      <version>${mavenVersion}</version>
-    </dependency>
     <dependency>
       <groupId>org.apache.maven.shared</groupId>
       <artifactId>maven-artifact-transfer</artifactId>
@@ -110,10 +105,28 @@ under the License.
     </dependency>
 
     <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.11</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
       <groupId>org.apache.maven.plugin-testing</groupId>
       <artifactId>maven-plugin-testing-harness</artifactId>
       <version>2.1</version>
       <scope>test</scope>
+      <exclusions>
+        <exclusion>
+          <artifactId>plexus-container-default</artifactId>
+          <groupId>org.codehaus.plexus</groupId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency> <!-- used by maven-plugin-testing-harness, don't give it compile scope -->
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-compat</artifactId>
+      <version>${mavenVersion}</version>
+      <scope>test</scope>
     </dependency>
     <dependency>
       <groupId>org.mockito</groupId>

Modified: maven/plugins/branches/m-install-p-3.0/src/it/attach-jar-checksum/verify.bsh
URL: http://svn.apache.org/viewvc/maven/plugins/branches/m-install-p-3.0/src/it/attach-jar-checksum/verify.bsh?rev=1675202&r1=1675201&r2=1675202&view=diff
==============================================================================
--- maven/plugins/branches/m-install-p-3.0/src/it/attach-jar-checksum/verify.bsh (original)
+++ maven/plugins/branches/m-install-p-3.0/src/it/attach-jar-checksum/verify.bsh Tue Apr 21 22:01:29 2015
@@ -34,11 +34,11 @@ String[] paths =
     "org/apache/maven/its/install/ajc/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT-sources.jar.md5",
     "org/apache/maven/its/install/ajc/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT-sources.jar.sha1",
     "org/apache/maven/its/install/ajc/test/1.0-SNAPSHOT/maven-metadata-local.xml",
-    "org/apache/maven/its/install/ajc/test/1.0-SNAPSHOT/maven-metadata-local.xml.md5",
-    "org/apache/maven/its/install/ajc/test/1.0-SNAPSHOT/maven-metadata-local.xml.sha1",
+//    "org/apache/maven/its/install/ajc/test/1.0-SNAPSHOT/maven-metadata-local.xml.md5",
+//    "org/apache/maven/its/install/ajc/test/1.0-SNAPSHOT/maven-metadata-local.xml.sha1",
     "org/apache/maven/its/install/ajc/test/maven-metadata-local.xml",
-    "org/apache/maven/its/install/ajc/test/maven-metadata-local.xml.md5",
-    "org/apache/maven/its/install/ajc/test/maven-metadata-local.xml.sha1",
+//    "org/apache/maven/its/install/ajc/test/maven-metadata-local.xml.md5",
+//    "org/apache/maven/its/install/ajc/test/maven-metadata-local.xml.sha1",
 };
 
 for ( String path : paths )

Modified: maven/plugins/branches/m-install-p-3.0/src/it/generate-pom-auto-1/verify.bsh
URL: http://svn.apache.org/viewvc/maven/plugins/branches/m-install-p-3.0/src/it/generate-pom-auto-1/verify.bsh?rev=1675202&r1=1675201&r2=1675202&view=diff
==============================================================================
--- maven/plugins/branches/m-install-p-3.0/src/it/generate-pom-auto-1/verify.bsh (original)
+++ maven/plugins/branches/m-install-p-3.0/src/it/generate-pom-auto-1/verify.bsh Tue Apr 21 22:01:29 2015
@@ -25,8 +25,8 @@ import org.apache.maven.plugin.install.*
 String[] paths =
 {
     "org/apache/maven/its/install/gpa1/test/maven-metadata-local.xml",
-    "org/apache/maven/its/install/gpa1/test/maven-metadata-local.xml.md5",
-    "org/apache/maven/its/install/gpa1/test/maven-metadata-local.xml.sha1",
+//    "org/apache/maven/its/install/gpa1/test/maven-metadata-local.xml.md5",
+//    "org/apache/maven/its/install/gpa1/test/maven-metadata-local.xml.sha1",
     "org/apache/maven/its/install/gpa1/test/0.1/test-0.1.jar",
     "org/apache/maven/its/install/gpa1/test/0.1/test-0.1.jar.md5",
     "org/apache/maven/its/install/gpa1/test/0.1/test-0.1.jar.sha1",

Modified: maven/plugins/branches/m-install-p-3.0/src/it/jar-sources-javadoc/verify.bsh
URL: http://svn.apache.org/viewvc/maven/plugins/branches/m-install-p-3.0/src/it/jar-sources-javadoc/verify.bsh?rev=1675202&r1=1675201&r2=1675202&view=diff
==============================================================================
--- maven/plugins/branches/m-install-p-3.0/src/it/jar-sources-javadoc/verify.bsh (original)
+++ maven/plugins/branches/m-install-p-3.0/src/it/jar-sources-javadoc/verify.bsh Tue Apr 21 22:01:29 2015
@@ -25,8 +25,8 @@ import org.apache.maven.plugin.install.*
 String[] paths =
 {
     "org/apache/maven/its/install/jsj/test/maven-metadata-local.xml",
-    "org/apache/maven/its/install/jsj/test/maven-metadata-local.xml.md5",
-    "org/apache/maven/its/install/jsj/test/maven-metadata-local.xml.sha1",
+//    "org/apache/maven/its/install/jsj/test/maven-metadata-local.xml.md5",
+//    "org/apache/maven/its/install/jsj/test/maven-metadata-local.xml.sha1",
     "org/apache/maven/its/install/jsj/test/0.1/test-0.1.jar",
     "org/apache/maven/its/install/jsj/test/0.1/test-0.1.jar.md5",
     "org/apache/maven/its/install/jsj/test/0.1/test-0.1.jar.sha1",

Modified: maven/plugins/branches/m-install-p-3.0/src/it/pom-checksum/verify.bsh
URL: http://svn.apache.org/viewvc/maven/plugins/branches/m-install-p-3.0/src/it/pom-checksum/verify.bsh?rev=1675202&r1=1675201&r2=1675202&view=diff
==============================================================================
--- maven/plugins/branches/m-install-p-3.0/src/it/pom-checksum/verify.bsh (original)
+++ maven/plugins/branches/m-install-p-3.0/src/it/pom-checksum/verify.bsh Tue Apr 21 22:01:29 2015
@@ -28,11 +28,11 @@ String[] paths =
     "org/apache/maven/its/install/pc/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT.pom.md5",
     "org/apache/maven/its/install/pc/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT.pom.sha1",
     "org/apache/maven/its/install/pc/test/1.0-SNAPSHOT/maven-metadata-local.xml",
-    "org/apache/maven/its/install/pc/test/1.0-SNAPSHOT/maven-metadata-local.xml.md5",
-    "org/apache/maven/its/install/pc/test/1.0-SNAPSHOT/maven-metadata-local.xml.sha1",
+//    "org/apache/maven/its/install/pc/test/1.0-SNAPSHOT/maven-metadata-local.xml.md5",
+//    "org/apache/maven/its/install/pc/test/1.0-SNAPSHOT/maven-metadata-local.xml.sha1",
     "org/apache/maven/its/install/pc/test/maven-metadata-local.xml",
-    "org/apache/maven/its/install/pc/test/maven-metadata-local.xml.md5",
-    "org/apache/maven/its/install/pc/test/maven-metadata-local.xml.sha1",
+//    "org/apache/maven/its/install/pc/test/maven-metadata-local.xml.md5",
+//    "org/apache/maven/its/install/pc/test/maven-metadata-local.xml.sha1",
 };
 
 for ( String path : paths )

Modified: maven/plugins/branches/m-install-p-3.0/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/m-install-p-3.0/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java?rev=1675202&r1=1675201&r2=1675202&view=diff
==============================================================================
--- maven/plugins/branches/m-install-p-3.0/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java (original)
+++ maven/plugins/branches/m-install-p-3.0/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java Tue Apr 21 22:01:29 2015
@@ -27,10 +27,12 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.Reader;
 import java.io.Writer;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Enumeration;
 import java.util.LinkedHashSet;
+import java.util.List;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 import java.util.regex.Pattern;
@@ -38,12 +40,19 @@ import java.util.regex.Pattern;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.metadata.ArtifactMetadata;
 import org.apache.maven.execution.MavenSession;
+import org.apache.maven.model.InputLocation;
 import org.apache.maven.model.Model;
 import org.apache.maven.model.Parent;
+import org.apache.maven.model.building.DefaultModelBuildingRequest;
+import org.apache.maven.model.building.ModelBuildingRequest;
+import org.apache.maven.model.building.ModelProblem.Severity;
+import org.apache.maven.model.building.ModelProblemCollector;
 import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
 import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
+import org.apache.maven.model.validation.ModelValidator;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugins.annotations.Component;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.project.ProjectBuildingRequest;
@@ -154,6 +163,13 @@ public class InstallFileMojo
     @Parameter( defaultValue = "${session}", required = true, readonly = true )
     private MavenSession session;
     
+    
+    /**
+    * The component used to validate the user-supplied artifact coordinates.
+    */
+    @Component
+    private ModelValidator modelValidator;
+    
     /**
      * @see org.apache.maven.plugin.Mojo#execute()
      */
@@ -269,6 +285,8 @@ public class InstallFileMojo
             }
         }
 
+        validateArtifactInformation();
+
         Artifact artifact =
             artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, packaging, classifier );
 
@@ -445,6 +463,29 @@ public class InstallFileMojo
     }
 
     /**
+     * Validates the user-supplied artifact information.
+     * 
+     * @throws MojoExecutionException If any artifact coordinate is invalid.
+     */
+    private void validateArtifactInformation()
+        throws MojoExecutionException
+    {
+        Model model = generateModel();
+
+        ModelBuildingRequest buildingRequest = new DefaultModelBuildingRequest();
+        
+        InstallModelProblemCollector problemCollector = new InstallModelProblemCollector();
+        
+        modelValidator.validateEffectiveModel( model, buildingRequest , problemCollector );
+
+        if ( problemCollector.getMessageCount() > 0 )
+        {
+            throw new MojoExecutionException( "The artifact information is incomplete or not valid:\n"
+                + problemCollector.render( "  " ) );
+        }
+    }
+    
+    /**
      * Generates a minimal model from the user-supplied artifact information.
      * 
      * @return The generated model, never <code>null</code>.
@@ -514,4 +555,41 @@ public class InstallFileMojo
         this.localRepositoryPath = theLocalRepositoryPath;
     }
 
+    
+    private static class InstallModelProblemCollector implements ModelProblemCollector
+    {
+        /** */
+        private static final String NEWLINE = System.getProperty( "line.separator" );
+
+        /** */
+        private List<String> messages = new ArrayList<String>();
+        
+        @Override
+        public void add( Severity severity, String message, InputLocation location, Exception cause )
+        {
+            messages.add( message );
+        }
+
+        public int getMessageCount()
+        {
+            return messages.size();
+        }
+
+        public String render( String indentation )
+        {
+            if ( messages.size() == 0 )
+            {
+                return indentation + "There were no validation errors.";
+            }
+
+            StringBuilder message = new StringBuilder();
+
+            for ( int i = 0; i < messages.size(); i++ )
+            {
+                message.append( indentation + "[" + i + "]  " + messages.get( i ).toString() + NEWLINE );
+            }
+
+            return message.toString();
+        }
+    };
 }