Author: bentmann
Date: Thu Mar 19 22:56:24 2009
New Revision: 756247
URL: http://svn.apache.org/viewvc?rev=756247&view=rev
Log:
[MDEPLOY-88] Artifacts with invalid id can be deployed with deploy:deploy-file.
Added:
maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/
maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/invoker.properties
(with props)
maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/pom.xml
(with props)
maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/setup.bsh
(with props)
maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/test.jar
(with props)
maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/test.properties
(with props)
maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/verify.bsh
(with props)
Modified:
maven/plugins/trunk/maven-deploy-plugin/src/it/external-release-jar/invoker.properties
maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployFileMojo.java
Modified:
maven/plugins/trunk/maven-deploy-plugin/src/it/external-release-jar/invoker.properties
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-deploy-plugin/src/it/external-release-jar/invoker.properties?rev=756247&r1=756246&r2=756247&view=diff
==============================================================================
---
maven/plugins/trunk/maven-deploy-plugin/src/it/external-release-jar/invoker.properties
(original)
+++
maven/plugins/trunk/maven-deploy-plugin/src/it/external-release-jar/invoker.properties
Thu Mar 19 22:56:24 2009
@@ -1 +1 @@
-invoker.goals = deploy:deploy-file
+invoker.goals =
org.apache.maven.plugins:maven-deploy-plugin:${project.version}:deploy-file
Added:
maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/invoker.properties
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/invoker.properties?rev=756247&view=auto
==============================================================================
---
maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/invoker.properties
(added)
+++
maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/invoker.properties
Thu Mar 19 22:56:24 2009
@@ -0,0 +1,2 @@
+invoker.goals =
org.apache.maven.plugins:maven-deploy-plugin:${project.version}:deploy-file
+invoker.buildResult = failure
Propchange:
maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/invoker.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/invoker.properties
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/pom.xml
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/pom.xml?rev=756247&view=auto
==============================================================================
--- maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/pom.xml
(added)
+++ maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/pom.xml Thu
Mar 19 22:56:24 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.deploy.gv</groupId>
+ <artifactId>test</artifactId>
+ <version>1.0</version>
+ <packaging>jar</packaging>
+
+ <description>
+ Tests that the manual installation validates the coordinates of the
artifact just like the model validator would do
+ (MDEPLOY-88).
+ </description>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <version>@project.version@</version>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
Propchange:
maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/pom.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/setup.bsh
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/setup.bsh?rev=756247&view=auto
==============================================================================
--- maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/setup.bsh
(added)
+++ maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/setup.bsh Thu
Mar 19 22:56:24 2009
@@ -0,0 +1,14 @@
+import java.io.*;
+import java.util.*;
+
+import org.codehaus.plexus.util.*;
+
+File file = new File( localRepositoryPath, "org/apache/maven/its/deploy/gv" );
+System.out.println( "Deleting " + file );
+FileUtils.deleteDirectory( file );
+
+file = new File( basedir, "target/repo" );
+System.out.println( "Deleting " + file );
+FileUtils.deleteDirectory( file );
+
+return true;
Propchange:
maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/setup.bsh
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/setup.bsh
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/test.jar
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/test.jar?rev=756247&view=auto
==============================================================================
Binary file - no diff available.
Propchange:
maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/test.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added:
maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/test.properties
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/test.properties?rev=756247&view=auto
==============================================================================
---
maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/test.properties
(added)
+++
maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/test.properties
Thu Mar 19 22:56:24 2009
@@ -0,0 +1,8 @@
+file = test.jar
+url = file:///${basedir}/target/repo
+packaging = jar
+
+# using invalid coordinates should have deploy-file bail out
+groupId = invalid~group
+artifactId = invalid/artifactId
+version = 1+
Propchange:
maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/test.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/test.properties
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/verify.bsh
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/verify.bsh?rev=756247&view=auto
==============================================================================
--- maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/verify.bsh
(added)
+++ maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/verify.bsh
Thu Mar 19 22:56:24 2009
@@ -0,0 +1,19 @@
+import java.io.*;
+import java.util.*;
+
+String[] paths =
+{
+ "org/apache/maven/its/deploy/gv",
+};
+
+for ( String path : paths )
+{
+ File file = new File( new File( basedir, "target/repo" ), path );
+ System.out.println( "Checking for absence of " + file );
+ if ( file.exists() )
+ {
+ throw new Exception( "Existing: " + file.getAbsolutePath() );
+ }
+}
+
+return true;
Propchange:
maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/verify.bsh
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
maven/plugins/trunk/maven-deploy-plugin/src/it/gav-validation/verify.bsh
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified:
maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployFileMojo.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployFileMojo.java?rev=756247&r1=756246&r2=756247&view=diff
==============================================================================
---
maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployFileMojo.java
(original)
+++
maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployFileMojo.java
Thu Mar 19 22:56:24 2009
@@ -32,6 +32,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;
@@ -169,7 +171,14 @@
*/
private boolean uniqueVersion;
- protected void initProperties()
+ /**
+ * The component used to validate the user-supplied artifact coordinates.
+ *
+ * @component
+ */
+ private ModelValidator modelValidator;
+
+ void initProperties()
throws MojoExecutionException
{
// Process the supplied POM (if there is one)
@@ -181,24 +190,6 @@
processModel( model );
}
-
- // Verify arguments
- 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=..." );
- }
}
public void execute()
@@ -206,6 +197,8 @@
{
initProperties();
+ validateArtifactInformation();
+
if ( !file.exists() )
{
throw new MojoExecutionException( file.getPath() + " not found." );
@@ -319,7 +312,7 @@
* @return The model from the POM file, never <code>null</code>.
* @throws MojoExecutionException If the file doesn't exist of cannot be
read.
*/
- protected Model readModel( File pomFile )
+ Model readModel( File pomFile )
throws MojoExecutionException
{
Reader reader = null;
@@ -349,20 +342,14 @@
private File generatePomFile()
throws MojoExecutionException
{
+ Model model = generateModel();
+
Writer fw = null;
try
{
- File tempFile = File.createTempFile( "mvninstall", ".pom" );
+ File tempFile = File.createTempFile( "mvndeploy", ".pom" );
tempFile.deleteOnExit();
- Model model = new Model();
- model.setModelVersion( "4.0.0" );
- model.setGroupId( groupId );
- model.setArtifactId( artifactId );
- model.setVersion( version );
- model.setPackaging( packaging );
- model.setDescription( description );
-
fw = WriterFactory.newXmlWriter( tempFile );
new MavenXpp3Writer().write( fw, model );
@@ -378,6 +365,46 @@
}
}
+ /**
+ * Validates the user-supplied artifact information.
+ *
+ * @throws MojoExecutionException If any artifact coordinate is invalid.
+ */
+ 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( description );
+
+ return model;
+ }
+
void setGroupId( String groupId )
{
this.groupId = groupId;