You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ar...@apache.org on 2006/02/03 08:49:57 UTC
svn commit: r374600 -
/maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployFileMojo.java
Author: aramirez
Date: Thu Feb 2 23:49:50 2006
New Revision: 374600
URL: http://svn.apache.org/viewcvs?rev=374600&view=rev
Log:
PR:MDEPLOY-23
Submitted by: Jerome Lacoste
Reviewed by: Allan Ramirez
Modified:
maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployFileMojo.java
Modified: maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployFileMojo.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployFileMojo.java?rev=374600&r1=374599&r2=374600&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 Feb 2 23:49:50 2006
@@ -134,30 +134,14 @@
public void execute()
throws MojoExecutionException
{
- try
- {
- // Process the supplied POM (if there is one)
- if ( pomFile != null )
- {
- if ( !pomFile.exists() )
- {
- throw new MojoExecutionException( "Specified pomFile does not exist" );
- }
- else
- {
- processPom();
- }
- }
- // Verify arguments
- if ( groupId == null || artifactId == null || version == null || packaging == null )
- {
- throw new MojoExecutionException( "Missing group, artifact, version, or packaging information" );
- }
+ initProperties();
+ try
+ {
// Create the artifact
Artifact artifact = artifactFactory.createArtifact( groupId, artifactId, version, null, packaging );
-
+
ArtifactRepository deploymentRepository = repositoryFactory
.createDeploymentArtifactRepository( repositoryId, url, layout, false );
@@ -172,18 +156,18 @@
artifact.addMetadata( metadata );
}
- if ( ! file.exists() )
+ if ( !file.exists() )
{
throw new MojoExecutionException( file.getPath() + " not found." );
}
-
+
String protocol = deploymentRepository.getProtocol();
-
- if( protocol.equals( "" ) || protocol == null )
+
+ if ( protocol.equals( "" ) || protocol == null )
{
throw new MojoExecutionException( "No transfer protocol found." );
}
- getDeployer().deploy( file, artifact, deploymentRepository, getLocalRepository() );
+ getDeployer().deploy( file, artifact, deploymentRepository, getLocalRepository() );
}
catch ( ArtifactDeploymentException e )
{
@@ -191,64 +175,95 @@
}
}
+ void initProperties()
+ throws MojoExecutionException
+ {
+ // Process the supplied POM (if there is one)
+ if ( pomFile != null )
+ {
+ Model model = readModel( pomFile );
+
+ processModel( model );
+ }
+
+ // Verify arguments
+ if ( groupId == null || artifactId == null || version == null || packaging == null )
+ {
+ throw new MojoExecutionException( "Missing group, artifact, version, or packaging information" );
+ }
+ }
+
/**
* Process the supplied pomFile to get groupId, artifactId, version, and packaging
- * @throws MojoExecutionException
- *
+ * @throws NullPointerException if model is <code>null</code>
*/
- private void processPom()
- throws MojoExecutionException
+ void processModel( Model model )
{
- if ( pomFile != null && pomFile.exists() )
- {
- Reader reader = null;
- try
- {
+ Parent parent = model.getParent();
- reader = new FileReader( pomFile );
- MavenXpp3Reader modelReader = new MavenXpp3Reader();
- Model model = modelReader.read( reader );
-
- Parent parent = model.getParent();
-
- if( parent != null && parent.getGroupId() != null )
- {
- this.groupId = parent.getGroupId();
- }
- else if( model.getGroupId() != null )
- {
- this.groupId = model.getGroupId();
- }
- if ( model.getArtifactId() != null )
- {
- this.artifactId = model.getArtifactId();
- }
- if ( model.getVersion() != null )
- {
- this.version = model.getVersion();
- }
- if ( model.getPackaging() != null )
- {
- this.packaging = model.getPackaging();
- }
- }
- catch ( FileNotFoundException e )
- {
- throw new MojoExecutionException( "Error reading specified POM file: " + e.getMessage(), e );
- }
- catch ( IOException e )
- {
- throw new MojoExecutionException( "Error reading specified POM file: " + e.getMessage(), e );
- }
- catch ( XmlPullParserException e )
+ if ( this.groupId == null )
+ {
+ if ( parent != null && parent.getGroupId() != null )
{
- throw new MojoExecutionException( "Error reading specified POM file: " + e.getMessage(), e );
+ this.groupId = parent.getGroupId();
}
- finally
+ if ( model.getGroupId() != null )
{
- IOUtil.close( reader );
+ this.groupId = model.getGroupId();
}
}
+ if ( this.artifactId == null && model.getArtifactId() != null )
+ {
+ this.artifactId = model.getArtifactId();
+ }
+ if ( this.version == null && model.getVersion() != null )
+ {
+ this.version = model.getVersion();
+ }
+ if ( this.packaging == null && model.getPackaging() != null )
+ {
+ this.packaging = model.getPackaging();
+ }
+ }
+
+ /**
+ * Extract the Model from the specified file.
+ * @param pomFile
+ * @return
+ * @throws MojoExecutionException if the file doesn't exist of cannot be read.
+ */
+ protected Model readModel( File pomFile )
+ throws MojoExecutionException
+ {
+
+ if ( !pomFile.exists() )
+ {
+ throw new MojoExecutionException( "Specified pomFile does not exist" );
+ }
+
+ Reader reader = null;
+ try
+ {
+ reader = new FileReader( pomFile );
+ MavenXpp3Reader modelReader = new MavenXpp3Reader();
+ return modelReader.read( reader );
+ }
+ catch ( FileNotFoundException e )
+ {
+ throw new MojoExecutionException( "Error reading specified POM file: " + e.getMessage(), e );
+ }
+ catch ( IOException e )
+ {
+ throw new MojoExecutionException( "Error reading specified POM file: " + e.getMessage(), e );
+ }
+ catch ( XmlPullParserException e )
+ {
+ throw new MojoExecutionException( "Error reading specified POM file: " + e.getMessage(), e );
+ }
+ finally
+ {
+ IOUtil.close( reader );
+ }
}
private void generatePomFile()
@@ -281,5 +296,55 @@
{
IOUtil.close( fw );
}
+ }
+
+ void setGroupId( String groupId )
+ {
+ this.groupId = groupId;
+ }
+
+ void setArtifactId( String artifactId )
+ {
+ this.artifactId = artifactId;
+ }
+
+ void setVersion( String version )
+ {
+ this.version = version;
+ }
+
+ void setPackaging( String packaging )
+ {
+ this.packaging = packaging;
+ }
+
+ void setPomFile( File pomFile )
+ {
+ this.pomFile = pomFile;
+ }
+
+ String getGroupId()
+ {
+ return groupId;
+ }
+
+ String getArtifactId()
+ {
+ return artifactId;
+ }
+
+ String getVersion()
+ {
+ return version;
+ }
+
+ String getPackaging()
+ {
+ return packaging;
+ }
+
+ File getFile()
+ {
+ return file;
}
}