Author: bentmann
Date: Thu Mar 19 20:52:21 2009
New Revision: 756189
URL: http://svn.apache.org/viewvc?rev=756189&view=rev
Log:
[MINSTALL-59] Validate artifact id
Added:
maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/ (with
props)
maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/invoker.properties
(with props)
maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/pom.xml
(with props)
maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/setup.bsh
(with props)
maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/test.jar
(with props)
maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/test.properties
(with props)
maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/verify.bsh
(with props)
Modified:
maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java
Propchange: maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/
------------------------------------------------------------------------------
--- bugtraq:logregex (added)
+++ bugtraq:logregex Thu Mar 19 20:52:21 2009
@@ -0,0 +1 @@
+MINSTALL-\d+
Propchange: maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/
------------------------------------------------------------------------------
bugtraq:url = http://jira.codehaus.org/browse/%BUGID%
Added:
maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/invoker.properties
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/invoker.properties?rev=756189&view=auto
==============================================================================
---
maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/invoker.properties
(added)
+++
maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/invoker.properties
Thu Mar 19 20:52:21 2009
@@ -0,0 +1,2 @@
+invoker.goals = install:install-file
+invoker.buildResult = failure
Propchange:
maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/invoker.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/invoker.properties
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/pom.xml
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/pom.xml?rev=756189&view=auto
==============================================================================
--- maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/pom.xml
(added)
+++ maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/pom.xml Thu
Mar 19 20:52:21 2009
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.its.install.gv</groupId>
+ <artifactId>test</artifactId>
+ <version>1.0</version>
+ <packaging>jar</packaging>
+
+ <description>
+ Tests the manual installation validates the coordinates of the artifact
just like the model validator would
+ (MINSTALL-59).
+ </description>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-install-plugin</artifactId>
+ <version>@project.version@</version>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
Propchange:
maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/pom.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/setup.bsh
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/setup.bsh?rev=756189&view=auto
==============================================================================
--- maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/setup.bsh
(added)
+++ maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/setup.bsh
Thu Mar 19 20:52:21 2009
@@ -0,0 +1,10 @@
+import java.io.*;
+import java.util.*;
+
+import org.codehaus.plexus.util.*;
+
+File file = new File( localRepositoryPath, "org/apache/maven/its/install/gv" );
+System.out.println( "Deleting " + file );
+FileUtils.deleteDirectory( file );
+
+return true;
Propchange:
maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/setup.bsh
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/setup.bsh
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/test.jar
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/test.jar?rev=756189&view=auto
==============================================================================
Binary file - no diff available.
Propchange:
maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/test.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added:
maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/test.properties
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/test.properties?rev=756189&view=auto
==============================================================================
---
maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/test.properties
(added)
+++
maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/test.properties
Thu Mar 19 20:52:21 2009
@@ -0,0 +1,7 @@
+file = test.jar
+packaging = jar
+
+# using invalid coordinates should have install-file bail out
+groupId = invalid~group
+artifactId = invalid/artifactId
+version =
Propchange:
maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/test.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/test.properties
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/verify.bsh
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/verify.bsh?rev=756189&view=auto
==============================================================================
--- maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/verify.bsh
(added)
+++ maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/verify.bsh
Thu Mar 19 20:52:21 2009
@@ -0,0 +1,19 @@
+import java.io.*;
+import java.util.*;
+
+String[] paths =
+{
+ "org/apache/maven/its/install/gv",
+};
+
+for ( String path : paths )
+{
+ File file = new File( localRepositoryPath, path );
+ System.out.println( "Checking for absence of " + file );
+ if ( file.exists() )
+ {
+ throw new FileNotFoundException( "Existing: " + file.getAbsolutePath()
);
+ }
+}
+
+return true;
Propchange:
maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/verify.bsh
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
maven/plugins/trunk/maven-install-plugin/src/it/gav-validation/verify.bsh
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified:
maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java?rev=756189&r1=756188&r2=756189&view=diff
==============================================================================
---
maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java
(original)
+++
maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java
Thu Mar 19 20:52:21 2009
@@ -31,6 +31,8 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.artifact.ProjectArtifactMetadata;
+import org.apache.maven.project.validation.ModelValidationResult;
+import org.apache.maven.project.validation.ModelValidator;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.StringUtils;
@@ -172,6 +174,13 @@
private String localRepositoryId;
/**
+ * The component used to validate the user-supplied artifact coordinates.
+ *
+ * @component
+ */
+ private ModelValidator modelValidator;
+
+ /**
* @see org.apache.maven.plugin.Mojo#execute()
*/
public void execute()
@@ -201,22 +210,7 @@
processModel( readModel( pomFile ) );
}
- if ( StringUtils.isEmpty( groupId ) )
- {
- throw new MojoExecutionException( "Missing group identifier,
please specify -DgroupId=..." );
- }
- if ( StringUtils.isEmpty( artifactId ) )
- {
- throw new MojoExecutionException( "Missing artifact identifier,
please specify -DartifactId=..." );
- }
- if ( StringUtils.isEmpty( version ) )
- {
- throw new MojoExecutionException( "Missing version, please specify
-Dversion=..." );
- }
- if ( StringUtils.isEmpty( packaging ) )
- {
- throw new MojoExecutionException( "Missing packaging type, please
specify -Dpackaging=..." );
- }
+ validateArtifactInformation();
Artifact artifact =
artifactFactory.createArtifactWithClassifier( groupId, artifactId,
version, packaging, classifier );
@@ -372,23 +366,57 @@
}
/**
- * Generates a (temporary) POM file from the plugin configuration. It's
the responsibility of the caller to delete
- * the generated file when no longer needed.
- *
- * @return The path to the generated POM file, never <code>null</code>.
- * @throws MojoExecutionException If the POM file could not be generated.
+ * Validates the user-supplied artifact information.
+ *
+ * @throws MojoExecutionException If any artifact coordinate is invalid.
*/
- private File generatePomFile()
+ private void validateArtifactInformation()
throws MojoExecutionException
{
+ Model model = generateModel();
+
+ ModelValidationResult result = modelValidator.validate( model );
+
+ if ( result.getMessageCount() > 0 )
+ {
+ throw new MojoExecutionException( "The artifact information is
incomplete or not valid:\n"
+ + result.render( " " ) );
+ }
+ }
+
+ /**
+ * Generates a minimal model from the user-supplied artifact information.
+ *
+ * @return The generated model, never <code>null</code>.
+ */
+ private Model generateModel()
+ {
Model model = new Model();
+
model.setModelVersion( "4.0.0" );
+
model.setGroupId( groupId );
model.setArtifactId( artifactId );
model.setVersion( version );
model.setPackaging( packaging );
+
model.setDescription( "POM was created from install:install-file" );
+ return model;
+ }
+
+ /**
+ * Generates a (temporary) POM file from the plugin configuration. It's
the responsibility of the caller to delete
+ * the generated file when no longer needed.
+ *
+ * @return The path to the generated POM file, never <code>null</code>.
+ * @throws MojoExecutionException If the POM file could not be generated.
+ */
+ private File generatePomFile()
+ throws MojoExecutionException
+ {
+ Model model = generateModel();
+
Writer writer = null;
try
{