You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by br...@apache.org on 2005/06/01 07:04:15 UTC
svn commit: r179356 - in
/maven/maven-1/plugins/trunk/artifact/src/main/org/apache/maven/artifact/deployer:
DefaultArtifactDeployer.java RepositoryBuilder.java
Author: brett
Date: Tue May 31 22:04:14 2005
New Revision: 179356
URL: http://svn.apache.org/viewcvs?rev=179356&view=rev
Log:
PR: MPARTIFACT-19
Automatically deploy as a snapshot when the version contains SNAPSHOT
Modified:
maven/maven-1/plugins/trunk/artifact/src/main/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java
maven/maven-1/plugins/trunk/artifact/src/main/org/apache/maven/artifact/deployer/RepositoryBuilder.java
Modified: maven/maven-1/plugins/trunk/artifact/src/main/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java
URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/artifact/src/main/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java?rev=179356&r1=179355&r2=179356&view=diff
==============================================================================
--- maven/maven-1/plugins/trunk/artifact/src/main/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java (original)
+++ maven/maven-1/plugins/trunk/artifact/src/main/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java Tue May 31 22:04:14 2005
@@ -44,6 +44,7 @@
import java.io.File;
import java.net.MalformedURLException;
+import java.security.NoSuchAlgorithmException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -52,7 +53,6 @@
import java.util.Iterator;
import java.util.List;
import java.util.TimeZone;
-import java.security.NoSuchAlgorithmException;
/**
* Default implementation of Artifact Deployer interface.
@@ -66,42 +66,12 @@
private static final String POM_TYPE = "pom";
- /**
- * Indicate if POM of given artifact should be also deployed
- * to remote repository
- */
- public static final boolean DEPLOY_POM = true;
-
- /**
- * Indicate if POM of given artifact should be also deployed
- * in local repository
- */
- public static final boolean INSTALL_POM = true;
-
- /**
- * Indicate if snapshot version of
- * POM of given artifact should be also deployed
- * to remote repository
- */
- public static final boolean DEPLOY_POM_SNAPSHOT = true;
-
- /**
- * Indicate if POM of given artifact should be also installed
- * in local repository
- */
- public static final boolean INSTALL_POM_SNAPSHOT = true;
-
private static final ArtifactTypeHandler POM_ARTIFACT_TYPE_HANDLER = new DefaultArtifactTypeHandler();
/**
* Date/time stamp which is appended to snapshot filenames
*/
- public final static DateFormat SNAPSHOT_SIGNATURE_FMT = new SimpleDateFormat( "yyyyMMdd.HHmmss" );
-
- static
- {
- SNAPSHOT_SIGNATURE_FMT.setTimeZone( TimeZone.getTimeZone( "GMT" ) );
- }
+ private final static String SNAPSHOT_FORMAT = "yyyyMMdd.HHmmss";
private static final Log LOG = LogFactory.getLog( DefaultArtifactDeployer.class );
@@ -111,24 +81,7 @@
public void deploy( String artifact, String type, Project project, ArtifactTypeHandler handler )
throws MavenException
{
- File file;
- if ( POM_TYPE.equals( type ) )
- {
- file = project.getFile();
- }
- else
- {
- file = getFileForArtifact( artifact );
- }
-
- String repositoryPath = handler.constructRepositoryFullPath( type, project, project.getCurrentVersion() );
-
- //do not deploy POM twice
- if ( DEPLOY_POM && !POM_TYPE.equals( type ) )
- {
- deploy( artifact, POM_TYPE, project, POM_ARTIFACT_TYPE_HANDLER );
- }
- doDeploy( Collections.singletonList( file ), Collections.singletonList( repositoryPath ), project );
+ handleDeploy( type, project, artifact, handler, project.getCurrentVersion() );
}
/**
@@ -137,8 +90,13 @@
public void deploySnapshot( String artifact, String type, Project project, ArtifactTypeHandler handler )
throws MavenException
{
+ handleDeploy( type, project, artifact, handler, MavenConstants.SNAPSHOT_SIGNIFIER );
+ }
- String snapshotSignature = getSnapshotSignature();
+ private void handleDeploy( String type, Project project, String artifact, ArtifactTypeHandler handler,
+ String version )
+ throws MavenException
+ {
File file;
if ( POM_TYPE.equals( type ) )
{
@@ -148,39 +106,14 @@
{
file = getFileForArtifact( artifact );
}
- File snapshotVersionFile = createSnapshotVersionFile( file, snapshotSignature, project, type );
- try
- {
- List srcFiles = new ArrayList();
- srcFiles.add( file );
- srcFiles.add( file );
-
- String snapshotFilename = handler.constructRepositoryFullPath( type, project,
- MavenConstants.SNAPSHOT_SIGNIFIER );
- String timestampedFilename = handler.constructRepositoryFullPath( type, project, snapshotSignature );
-
- List destFiles = new ArrayList();
- destFiles.add( snapshotFilename );
- destFiles.add( timestampedFilename );
-
- srcFiles.add( snapshotVersionFile );
-
- String snapshotVersionsFilename = handler.constructRepositoryDirectoryPath( type, project ) +
- project.getArtifactId() + "-snapshot-version";
- destFiles.add( snapshotVersionsFilename );
- // do not deploy POM twice
- if ( DEPLOY_POM_SNAPSHOT && !POM_TYPE.equals( type ) )
- {
- deploySnapshot( artifact, POM_TYPE, project, POM_ARTIFACT_TYPE_HANDLER );
- }
-
- doDeploy( srcFiles, destFiles, project );
- }
- finally
+ // do not deploy POM twice
+ if ( !POM_TYPE.equals( type ) )
{
- snapshotVersionFile.delete();
+ doDeploy( project.getFile(), project, POM_ARTIFACT_TYPE_HANDLER, version, POM_TYPE );
}
+
+ doDeploy( file, project, handler, version, type );
}
/**
@@ -189,21 +122,7 @@
public void install( String artifact, String type, Project project, ArtifactTypeHandler handler )
throws MavenException
{
- File file;
- if ( POM_TYPE.equals( type ) )
- {
- file = project.getFile();
- }
- else
- {
- file = getFileForArtifact( artifact );
- }
- doInstall( file, type, project, project.getCurrentVersion(), handler );
- // do not install twice
- if ( INSTALL_POM && !POM_TYPE.equals( type ) )
- {
- doInstall( project.getFile(), POM_TYPE, project, project.getCurrentVersion(), POM_ARTIFACT_TYPE_HANDLER );
- }
+ handleInstall( type, project, artifact, handler, project.getCurrentVersion() );
}
/**
@@ -212,6 +131,13 @@
public void installSnapshot( String artifact, String type, Project project, ArtifactTypeHandler handler )
throws MavenException
{
+ handleInstall( type, project, artifact, handler, MavenConstants.SNAPSHOT_SIGNIFIER );
+ }
+
+ private void handleInstall( String type, Project project, String artifact, ArtifactTypeHandler handler,
+ String version )
+ throws MavenException
+ {
File file;
if ( POM_TYPE.equals( type ) )
{
@@ -221,23 +147,21 @@
{
file = getFileForArtifact( artifact );
}
- String snapshotSignature = getSnapshotSignature();
- LOG.info( "Installing snapshot of:'" + artifact + "''" );
- doInstall( file, type, project, MavenConstants.SNAPSHOT_SIGNIFIER, handler );
- doInstall( file, type, project, snapshotSignature, handler );
- if ( INSTALL_POM_SNAPSHOT && !POM_TYPE.equals( type ) )
- {
- File projectFile = project.getFile();
- doInstall( projectFile, POM_TYPE, project, MavenConstants.SNAPSHOT_SIGNIFIER, POM_ARTIFACT_TYPE_HANDLER );
- doInstall( projectFile, POM_TYPE, project, snapshotSignature, POM_ARTIFACT_TYPE_HANDLER );
+
+ doInstall( file, type, project, version, handler );
+
+ // do not install twice
+ if ( !POM_TYPE.equals( type ) )
+ {
+ doInstall( project.getFile(), POM_TYPE, project, version, POM_ARTIFACT_TYPE_HANDLER );
}
}
/**
* Install given file in local repository
*
- * @param file the artifact file to install
- * @param type The type of the artiafct
+ * @param file the artifact file to install
+ * @param type The type of the artiafct
* @param project
* @param version String denominating the version of the artifact
* @throws MavenException
@@ -245,6 +169,13 @@
private void doInstall( File file, String type, Project project, String version, ArtifactTypeHandler handler )
throws MavenException
{
+ if ( version.indexOf( MavenConstants.SNAPSHOT_SIGNIFIER ) >= 0 )
+ {
+ String snapshotSignature = getSnapshotSignature();
+ String v = StringUtils.replace( version, MavenConstants.SNAPSHOT_SIGNIFIER, snapshotSignature );
+ doInstall( file, type, project, v, handler );
+ }
+
try
{
Repository repository = new Repository( "local", "file:" + project.getContext().getMavenRepoLocal() );
@@ -306,9 +237,32 @@
return null;
}
- private void doDeploy( List srcFiles, List destFiles, Project project )
+ private void doDeploy( File file, Project project, ArtifactTypeHandler handler, String version, String type )
throws MavenException
{
+ List srcFiles = new ArrayList( 3 );
+ List destFiles = new ArrayList( 3 );
+
+ srcFiles.add( file );
+ destFiles.add( handler.constructRepositoryFullPath( type, project, version ) );
+
+ if ( version.indexOf( MavenConstants.SNAPSHOT_SIGNIFIER ) >= 0 )
+ {
+ String snapshotSignature = getSnapshotSignature();
+ String v = StringUtils.replace( version, MavenConstants.SNAPSHOT_SIGNIFIER, snapshotSignature );
+
+ File snapshotVersionFile = createSnapshotVersionFile( file, v, project, type );
+
+ String snapshotVersionsFilename = handler.constructRepositoryDirectoryPath( type, project ) +
+ project.getArtifactId() + "-snapshot-version";
+
+ srcFiles.add( snapshotVersionFile );
+ destFiles.add( snapshotVersionsFilename );
+
+ srcFiles.add( file );
+ destFiles.add( handler.constructRepositoryFullPath( type, project, v ) );
+ }
+
// trick add special values to context for default repository;
String repoStr = (String) project.getContext().getVariable( "maven.repo.list" );
@@ -461,8 +415,9 @@
*/
private String getSnapshotSignature()
{
- Date now = new Date();
- return SNAPSHOT_SIGNATURE_FMT.format( now );
+ DateFormat fmt = new SimpleDateFormat( SNAPSHOT_FORMAT );
+ fmt.setTimeZone( TimeZone.getTimeZone( "GMT" ) );
+ return fmt.format( new Date() );
}
/**
@@ -508,7 +463,7 @@
{
file = new File( artifact.getParent(), filename );
FileUtils.fileWrite( file.getAbsolutePath(), snapshotVersion );
-
+ file.deleteOnExit();
}
catch ( Exception e )
{
Modified: maven/maven-1/plugins/trunk/artifact/src/main/org/apache/maven/artifact/deployer/RepositoryBuilder.java
URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/artifact/src/main/org/apache/maven/artifact/deployer/RepositoryBuilder.java?rev=179356&r1=179355&r2=179356&view=diff
==============================================================================
--- maven/maven-1/plugins/trunk/artifact/src/main/org/apache/maven/artifact/deployer/RepositoryBuilder.java (original)
+++ maven/maven-1/plugins/trunk/artifact/src/main/org/apache/maven/artifact/deployer/RepositoryBuilder.java Tue May 31 22:04:14 2005
@@ -23,6 +23,7 @@
import org.apache.maven.wagon.authentication.AuthenticationInfo;
import org.apache.maven.wagon.proxy.ProxyInfo;
import org.apache.maven.MavenConstants;
+import org.apache.maven.MavenException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -39,13 +40,22 @@
private static final Log LOG = LogFactory.getLog( RepositoryBuilder.class );
public static Repository getRepository( Project project, String id )
+ throws MavenException
{
String url = (String) project.getContext().getVariable( "maven.repo." + id );
+ if ( url == null )
+ {
+ throw new MavenException( "URL not specified in property: maven.repo." + id );
+ }
Repository repository = new Repository( id, url );
String dir = (String) project.getContext().getVariable( "maven.repo." + id + ".directory" );
repository.setBasedir( dir );
+ if ( dir == null )
+ {
+ throw new MavenException( "Directory not specified in property: maven.repo." + id + ".directory" );
+ }
String port = (String) project.getContext().getVariable( "maven.repo." + id + ".port" );
if ( port != null )
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org