mirror of https://github.com/apache/maven.git
Resolving: MNG-251
o Added transformation manager o snapshot timestamp/buildnumber is now managed from the transformation rather than the metadata o maven-archiver now clones the MavenProject and resolves snapshot versions for introduction into manifest and exported pom. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@239219 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b88302c209
commit
146e022327
|
@ -60,6 +60,14 @@ public class MavenArchiver
|
||||||
Manifest.Attribute createdAttr = new Manifest.Attribute( "Created-By", "Apache Maven" );
|
Manifest.Attribute createdAttr = new Manifest.Attribute( "Created-By", "Apache Maven" );
|
||||||
m.addConfiguredAttribute( createdAttr );
|
m.addConfiguredAttribute( createdAttr );
|
||||||
|
|
||||||
|
Artifact projectArtifact = project.getArtifact();
|
||||||
|
|
||||||
|
if ( projectArtifact.isSnapshot() )
|
||||||
|
{
|
||||||
|
Manifest.Attribute buildNumberAttr = new Manifest.Attribute( "Build-Number", "" + project.getSnapshotDeploymentBuildNumber() );
|
||||||
|
m.addConfiguredAttribute( buildNumberAttr );
|
||||||
|
}
|
||||||
|
|
||||||
if ( config.getPackageName() != null )
|
if ( config.getPackageName() != null )
|
||||||
{
|
{
|
||||||
Manifest.Attribute packageAttr = new Manifest.Attribute( "Package", config.getPackageName() );
|
Manifest.Attribute packageAttr = new Manifest.Attribute( "Package", config.getPackageName() );
|
||||||
|
@ -215,11 +223,20 @@ public class MavenArchiver
|
||||||
// POM information without the use of maven tools can do so.
|
// POM information without the use of maven tools can do so.
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
String groupId = project.getGroupId();
|
// we have to clone the project instance so we can write out the pom with the deployment version,
|
||||||
|
// without impacting the main project instance...
|
||||||
|
MavenProject workingProject = new MavenProject( project );
|
||||||
|
|
||||||
String artifactId = project.getArtifactId();
|
if ( workingProject.getArtifact().isSnapshot() )
|
||||||
|
{
|
||||||
|
workingProject.setVersion( workingProject.getSnapshotDeploymentVersion() );
|
||||||
|
}
|
||||||
|
|
||||||
File exportReadyPom = writeExportReadyPom( project );
|
String groupId = workingProject.getGroupId();
|
||||||
|
|
||||||
|
String artifactId = workingProject.getArtifactId();
|
||||||
|
|
||||||
|
File exportReadyPom = writeExportReadyPom( workingProject );
|
||||||
|
|
||||||
archiver.addFile( exportReadyPom, "META-INF/maven/" + groupId + "/" + artifactId + "/pom.xml" );
|
archiver.addFile( exportReadyPom, "META-INF/maven/" + groupId + "/" + artifactId + "/pom.xml" );
|
||||||
|
|
||||||
|
@ -229,13 +246,13 @@ public class MavenArchiver
|
||||||
|
|
||||||
Properties p = new Properties();
|
Properties p = new Properties();
|
||||||
|
|
||||||
p.setProperty( "groupId", project.getGroupId() );
|
p.setProperty( "groupId", workingProject.getGroupId() );
|
||||||
|
|
||||||
p.setProperty( "artifactId", project.getArtifactId() );
|
p.setProperty( "artifactId", workingProject.getArtifactId() );
|
||||||
|
|
||||||
p.setProperty( "version", project.getVersion() );
|
p.setProperty( "version", workingProject.getVersion() );
|
||||||
|
|
||||||
File pomPropertiesFile = new File( project.getFile().getParentFile(), "pom.properties" );
|
File pomPropertiesFile = new File( workingProject.getFile().getParentFile(), "pom.properties" );
|
||||||
|
|
||||||
OutputStream os = new FileOutputStream( pomPropertiesFile );
|
OutputStream os = new FileOutputStream( pomPropertiesFile );
|
||||||
|
|
||||||
|
@ -256,7 +273,7 @@ public class MavenArchiver
|
||||||
archiver.setManifest( manifestFile );
|
archiver.setManifest( manifestFile );
|
||||||
}
|
}
|
||||||
|
|
||||||
Manifest manifest = getManifest( project, archiveConfiguration.getManifest() );
|
Manifest manifest = getManifest( workingProject, archiveConfiguration.getManifest() );
|
||||||
|
|
||||||
// Configure the jar
|
// Configure the jar
|
||||||
archiver.addConfiguredManifest( manifest );
|
archiver.addConfiguredManifest( manifest );
|
||||||
|
|
|
@ -21,7 +21,7 @@ import org.apache.maven.artifact.manager.WagonManager;
|
||||||
import org.apache.maven.artifact.metadata.ArtifactMetadata;
|
import org.apache.maven.artifact.metadata.ArtifactMetadata;
|
||||||
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
import org.apache.maven.artifact.transform.ArtifactTransformation;
|
import org.apache.maven.artifact.transform.ArtifactTransformationManager;
|
||||||
import org.apache.maven.wagon.TransferFailedException;
|
import org.apache.maven.wagon.TransferFailedException;
|
||||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||||
import org.codehaus.plexus.util.FileUtils;
|
import org.codehaus.plexus.util.FileUtils;
|
||||||
|
@ -29,7 +29,6 @@ import org.codehaus.plexus.util.FileUtils;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class DefaultArtifactDeployer
|
public class DefaultArtifactDeployer
|
||||||
extends AbstractLogEnabled
|
extends AbstractLogEnabled
|
||||||
|
@ -37,7 +36,7 @@ public class DefaultArtifactDeployer
|
||||||
{
|
{
|
||||||
private WagonManager wagonManager;
|
private WagonManager wagonManager;
|
||||||
|
|
||||||
private List artifactTransformations;
|
private ArtifactTransformationManager transformationManager;
|
||||||
|
|
||||||
/** @deprecated we want to use the artifact method only, and ensure artifact.file is set correctly. */
|
/** @deprecated we want to use the artifact method only, and ensure artifact.file is set correctly. */
|
||||||
public void deploy( String basedir, String finalName, Artifact artifact, ArtifactRepository deploymentRepository,
|
public void deploy( String basedir, String finalName, Artifact artifact, ArtifactRepository deploymentRepository,
|
||||||
|
@ -55,12 +54,7 @@ public class DefaultArtifactDeployer
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// TODO: better to have a transform manager, or reuse the handler manager again so we don't have these requirements duplicated all over?
|
transformationManager.transformForDeployment( artifact, localRepository );
|
||||||
for ( Iterator i = artifactTransformations.iterator(); i.hasNext(); )
|
|
||||||
{
|
|
||||||
ArtifactTransformation transform = (ArtifactTransformation) i.next();
|
|
||||||
transform.transformForDeployment( artifact, deploymentRepository );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy the original file to the new one if it was transformed
|
// Copy the original file to the new one if it was transformed
|
||||||
File artifactFile = new File( localRepository.getBasedir(), localRepository.pathOf( artifact ) );
|
File artifactFile = new File( localRepository.getBasedir(), localRepository.pathOf( artifact ) );
|
||||||
|
|
|
@ -20,20 +20,19 @@ import org.apache.maven.artifact.Artifact;
|
||||||
import org.apache.maven.artifact.metadata.ArtifactMetadata;
|
import org.apache.maven.artifact.metadata.ArtifactMetadata;
|
||||||
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
import org.apache.maven.artifact.transform.ArtifactTransformation;
|
import org.apache.maven.artifact.transform.ArtifactTransformationManager;
|
||||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||||
import org.codehaus.plexus.util.FileUtils;
|
import org.codehaus.plexus.util.FileUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class DefaultArtifactInstaller
|
public class DefaultArtifactInstaller
|
||||||
extends AbstractLogEnabled
|
extends AbstractLogEnabled
|
||||||
implements ArtifactInstaller
|
implements ArtifactInstaller
|
||||||
{
|
{
|
||||||
private List artifactTransformations;
|
private ArtifactTransformationManager transformationManager;
|
||||||
|
|
||||||
/** @deprecated we want to use the artifact method only, and ensure artifact.file is set correctly. */
|
/** @deprecated we want to use the artifact method only, and ensure artifact.file is set correctly. */
|
||||||
public void install( String basedir, String finalName, Artifact artifact, ArtifactRepository localRepository )
|
public void install( String basedir, String finalName, Artifact artifact, ArtifactRepository localRepository )
|
||||||
|
@ -50,12 +49,7 @@ public class DefaultArtifactInstaller
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// TODO: better to have a transform manager, or reuse the handler manager again so we don't have these requirements duplicated all over?
|
transformationManager.transformForInstall( artifact, localRepository );
|
||||||
for ( Iterator i = artifactTransformations.iterator(); i.hasNext(); )
|
|
||||||
{
|
|
||||||
ArtifactTransformation transform = (ArtifactTransformation) i.next();
|
|
||||||
transform.transformForInstall( artifact, localRepository );
|
|
||||||
}
|
|
||||||
|
|
||||||
String localPath = localRepository.pathOf( artifact );
|
String localPath = localRepository.pathOf( artifact );
|
||||||
|
|
||||||
|
|
|
@ -43,9 +43,6 @@ public class SnapshotArtifactMetadata
|
||||||
|
|
||||||
private static final String UTC_TIMESTAMP_PATTERN = "yyyyMMdd.HHmmss";
|
private static final String UTC_TIMESTAMP_PATTERN = "yyyyMMdd.HHmmss";
|
||||||
|
|
||||||
// TODO: very quick and nasty hack to get the same timestamp across a build - not embedder friendly
|
|
||||||
private static String sessionTimestamp = null;
|
|
||||||
|
|
||||||
public SnapshotArtifactMetadata( Artifact artifact )
|
public SnapshotArtifactMetadata( Artifact artifact )
|
||||||
{
|
{
|
||||||
super( artifact, artifact.getArtifactId() + "-" + artifact.getBaseVersion() + "." + SNAPSHOT_VERSION_FILE );
|
super( artifact, artifact.getArtifactId() + "-" + artifact.getBaseVersion() + "." + SNAPSHOT_VERSION_FILE );
|
||||||
|
@ -84,11 +81,22 @@ public class SnapshotArtifactMetadata
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setVersion( String timestamp, int buildNumber )
|
||||||
|
{
|
||||||
|
this.timestamp = timestamp;
|
||||||
|
this.buildNumber = buildNumber;
|
||||||
|
}
|
||||||
|
|
||||||
public String getTimestamp()
|
public String getTimestamp()
|
||||||
{
|
{
|
||||||
return timestamp;
|
return timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getBuildNumber()
|
||||||
|
{
|
||||||
|
return buildNumber;
|
||||||
|
}
|
||||||
|
|
||||||
public static DateFormat getUtcDateFormatter()
|
public static DateFormat getUtcDateFormatter()
|
||||||
{
|
{
|
||||||
DateFormat utcDateFormatter = new SimpleDateFormat( UTC_TIMESTAMP_PATTERN );
|
DateFormat utcDateFormatter = new SimpleDateFormat( UTC_TIMESTAMP_PATTERN );
|
||||||
|
@ -96,22 +104,6 @@ public class SnapshotArtifactMetadata
|
||||||
return utcDateFormatter;
|
return utcDateFormatter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update()
|
|
||||||
{
|
|
||||||
this.buildNumber++;
|
|
||||||
timestamp = getSessionTimestamp();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getSessionTimestamp()
|
|
||||||
{
|
|
||||||
if ( sessionTimestamp == null )
|
|
||||||
{
|
|
||||||
sessionTimestamp = getUtcDateFormatter().format( new Date() );
|
|
||||||
}
|
|
||||||
return sessionTimestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public int compareTo( Object o )
|
public int compareTo( Object o )
|
||||||
{
|
{
|
||||||
SnapshotArtifactMetadata metadata = (SnapshotArtifactMetadata) o;
|
SnapshotArtifactMetadata metadata = (SnapshotArtifactMetadata) o;
|
||||||
|
|
|
@ -24,7 +24,7 @@ import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
||||||
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
|
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
||||||
import org.apache.maven.artifact.transform.ArtifactTransformation;
|
import org.apache.maven.artifact.transform.ArtifactTransformationManager;
|
||||||
import org.apache.maven.wagon.ResourceDoesNotExistException;
|
import org.apache.maven.wagon.ResourceDoesNotExistException;
|
||||||
import org.apache.maven.wagon.TransferFailedException;
|
import org.apache.maven.wagon.TransferFailedException;
|
||||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||||
|
@ -47,7 +47,7 @@ public class DefaultArtifactResolver
|
||||||
|
|
||||||
private WagonManager wagonManager;
|
private WagonManager wagonManager;
|
||||||
|
|
||||||
private List artifactTransformations;
|
private ArtifactTransformationManager transformationManager;
|
||||||
|
|
||||||
protected ArtifactFactory artifactFactory;
|
protected ArtifactFactory artifactFactory;
|
||||||
|
|
||||||
|
@ -86,19 +86,14 @@ public class DefaultArtifactResolver
|
||||||
|
|
||||||
artifact.setFile( new File( localRepository.getBasedir(), localPath ) );
|
artifact.setFile( new File( localRepository.getBasedir(), localPath ) );
|
||||||
|
|
||||||
// TODO: better to have a transform manager, or reuse the handler manager again so we don't have these requirements duplicated all over?
|
|
||||||
for ( Iterator i = artifactTransformations.iterator(); i.hasNext(); )
|
|
||||||
{
|
|
||||||
ArtifactTransformation transform = (ArtifactTransformation) i.next();
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
transform.transformForResolve( artifact, remoteRepositories, localRepository );
|
transformationManager.transformForResolve( artifact, remoteRepositories, localRepository );
|
||||||
}
|
}
|
||||||
catch ( ArtifactMetadataRetrievalException e )
|
catch ( ArtifactMetadataRetrievalException e )
|
||||||
{
|
{
|
||||||
throw new ArtifactResolutionException( e.getMessage(), artifact, remoteRepositories, e );
|
throw new ArtifactResolutionException( e.getMessage(), artifact, remoteRepositories, e );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
File destination = artifact.getFile();
|
File destination = artifact.getFile();
|
||||||
if ( !destination.exists() || force )
|
if ( !destination.exists() || force )
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
package org.apache.maven.artifact.transform;
|
||||||
|
|
||||||
|
import org.apache.maven.artifact.Artifact;
|
||||||
|
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
||||||
|
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DefaultArtifactTransformationManager
|
||||||
|
implements ArtifactTransformationManager
|
||||||
|
{
|
||||||
|
|
||||||
|
private List artifactTransformations;
|
||||||
|
|
||||||
|
private SnapshotTransformation snapshotTransformation;
|
||||||
|
|
||||||
|
public void transformForResolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
|
||||||
|
throws ArtifactMetadataRetrievalException
|
||||||
|
{
|
||||||
|
for ( Iterator i = artifactTransformations.iterator(); i.hasNext(); )
|
||||||
|
{
|
||||||
|
ArtifactTransformation transform = (ArtifactTransformation) i.next();
|
||||||
|
transform.transformForResolve( artifact, remoteRepositories, localRepository );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void transformForInstall( Artifact artifact, ArtifactRepository localRepository )
|
||||||
|
throws ArtifactMetadataRetrievalException
|
||||||
|
{
|
||||||
|
for ( Iterator i = artifactTransformations.iterator(); i.hasNext(); )
|
||||||
|
{
|
||||||
|
ArtifactTransformation transform = (ArtifactTransformation) i.next();
|
||||||
|
transform.transformForInstall( artifact, localRepository );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository )
|
||||||
|
throws ArtifactMetadataRetrievalException
|
||||||
|
{
|
||||||
|
for ( Iterator i = artifactTransformations.iterator(); i.hasNext(); )
|
||||||
|
{
|
||||||
|
ArtifactTransformation transform = (ArtifactTransformation) i.next();
|
||||||
|
transform.transformForDeployment( artifact, remoteRepository );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSnapshotDeploymentTimestamp()
|
||||||
|
{
|
||||||
|
return snapshotTransformation.getDeploymentTimestamp();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSnapshotDeploymentBuildNumber( Artifact artifact )
|
||||||
|
{
|
||||||
|
return snapshotTransformation.getDeploymentBuildNumber( artifact);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSnapshotDeploymentVersion( Artifact snapshotArtifact )
|
||||||
|
{
|
||||||
|
return snapshotTransformation.getDeploymentVersion( snapshotArtifact );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -17,6 +17,7 @@ package org.apache.maven.artifact.transform;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.maven.artifact.Artifact;
|
import org.apache.maven.artifact.Artifact;
|
||||||
|
import org.apache.maven.artifact.ArtifactUtils;
|
||||||
import org.apache.maven.artifact.metadata.AbstractVersionArtifactMetadata;
|
import org.apache.maven.artifact.metadata.AbstractVersionArtifactMetadata;
|
||||||
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
||||||
import org.apache.maven.artifact.metadata.SnapshotArtifactMetadata;
|
import org.apache.maven.artifact.metadata.SnapshotArtifactMetadata;
|
||||||
|
@ -24,7 +25,10 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
|
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
|
||||||
import org.apache.maven.wagon.ResourceDoesNotExistException;
|
import org.apache.maven.wagon.ResourceDoesNotExistException;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||||
|
@ -35,6 +39,12 @@ import java.util.List;
|
||||||
public class SnapshotTransformation
|
public class SnapshotTransformation
|
||||||
extends AbstractVersionTransformation
|
extends AbstractVersionTransformation
|
||||||
{
|
{
|
||||||
|
private String deploymentTimestamp;
|
||||||
|
|
||||||
|
private int deploymentBuildNumber = 1;
|
||||||
|
|
||||||
|
private Map buildNumbers = new HashMap();
|
||||||
|
|
||||||
public void transformForResolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
|
public void transformForResolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
|
||||||
throws ArtifactMetadataRetrievalException
|
throws ArtifactMetadataRetrievalException
|
||||||
{
|
{
|
||||||
|
@ -66,6 +76,8 @@ public class SnapshotTransformation
|
||||||
{
|
{
|
||||||
metadata = (SnapshotArtifactMetadata) retrieveFromRemoteRepository( artifact, remoteRepository, null,
|
metadata = (SnapshotArtifactMetadata) retrieveFromRemoteRepository( artifact, remoteRepository, null,
|
||||||
ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE );
|
ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE );
|
||||||
|
|
||||||
|
updateDeploymentBuildNumber( artifact, metadata.getTimestamp(), metadata.getBuildNumber() );
|
||||||
}
|
}
|
||||||
catch ( ResourceDoesNotExistException e )
|
catch ( ResourceDoesNotExistException e )
|
||||||
{
|
{
|
||||||
|
@ -77,7 +89,7 @@ public class SnapshotTransformation
|
||||||
metadata = (SnapshotArtifactMetadata) createMetadata( artifact );
|
metadata = (SnapshotArtifactMetadata) createMetadata( artifact );
|
||||||
}
|
}
|
||||||
|
|
||||||
metadata.update();
|
metadata.setVersion( getDeploymentTimestamp(), deploymentBuildNumber );
|
||||||
|
|
||||||
artifact.setResolvedVersion( metadata.constructVersion() );
|
artifact.setResolvedVersion( metadata.constructVersion() );
|
||||||
|
|
||||||
|
@ -85,9 +97,62 @@ public class SnapshotTransformation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateDeploymentBuildNumber( Artifact artifact, String timestamp, int buildNumberFromMetadata )
|
||||||
|
{
|
||||||
|
// we only have to handle bumping the build number if we're on the same timestamp, somehow...miraculously
|
||||||
|
if ( deploymentTimestamp.equals( timestamp ) )
|
||||||
|
{
|
||||||
|
String artifactKey = ArtifactUtils.versionlessKey( artifact );
|
||||||
|
|
||||||
|
Integer buildNum = (Integer) buildNumbers.get( artifactKey );
|
||||||
|
|
||||||
|
if ( buildNum == null || buildNum.intValue() <= buildNumberFromMetadata )
|
||||||
|
{
|
||||||
|
buildNum = new Integer( buildNumberFromMetadata + 1 );
|
||||||
|
|
||||||
|
buildNumbers.put( artifactKey, buildNum );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDeploymentTimestamp()
|
||||||
|
{
|
||||||
|
if ( deploymentTimestamp == null )
|
||||||
|
{
|
||||||
|
deploymentTimestamp = SnapshotArtifactMetadata.getUtcDateFormatter().format( new Date() );
|
||||||
|
}
|
||||||
|
return deploymentTimestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDeploymentBuildNumber( Artifact artifact )
|
||||||
|
{
|
||||||
|
String artifactKey = ArtifactUtils.versionlessKey( artifact );
|
||||||
|
|
||||||
|
Integer buildNum = (Integer) buildNumbers.get( artifactKey );
|
||||||
|
|
||||||
|
if ( buildNum == null )
|
||||||
|
{
|
||||||
|
buildNum = new Integer( 1 );
|
||||||
|
buildNumbers.put( artifactKey, buildNum );
|
||||||
|
}
|
||||||
|
|
||||||
|
return buildNum.intValue();
|
||||||
|
}
|
||||||
|
|
||||||
protected AbstractVersionArtifactMetadata createMetadata( Artifact artifact )
|
protected AbstractVersionArtifactMetadata createMetadata( Artifact artifact )
|
||||||
{
|
{
|
||||||
return new SnapshotArtifactMetadata( artifact );
|
return new SnapshotArtifactMetadata( artifact );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getDeploymentVersion( Artifact artifact )
|
||||||
|
{
|
||||||
|
int buildnum = getDeploymentBuildNumber( artifact );
|
||||||
|
|
||||||
|
SnapshotArtifactMetadata metadata = (SnapshotArtifactMetadata) createMetadata( artifact );
|
||||||
|
|
||||||
|
metadata.setVersion( getDeploymentTimestamp(), buildnum );
|
||||||
|
|
||||||
|
return metadata.constructVersion();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -47,6 +47,28 @@
|
||||||
</requirement>
|
</requirement>
|
||||||
</requirements>
|
</requirements>
|
||||||
</component>
|
</component>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
|
|
||||||
|
| ArtifactTransformationManager
|
||||||
|
|
|
||||||
|
-->
|
||||||
|
<component>
|
||||||
|
<role>org.apache.maven.artifact.transform.ArtifactTransformationManager</role>
|
||||||
|
<implementation>org.apache.maven.artifact.transform.DefaultArtifactTransformationManager</implementation>
|
||||||
|
<requirements>
|
||||||
|
<requirement>
|
||||||
|
<role>org.apache.maven.artifact.transform.ArtifactTransformation</role>
|
||||||
|
<field-name>artifactTransformations</field-name>
|
||||||
|
</requirement>
|
||||||
|
<requirement>
|
||||||
|
<role>org.apache.maven.artifact.transform.ArtifactTransformation</role>
|
||||||
|
<role-hint>snapshot</role-hint>
|
||||||
|
<field-name>snapshotTransformation</field-name>
|
||||||
|
</requirement>
|
||||||
|
</requirements>
|
||||||
|
</component>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
|
|
|
|
||||||
| Resolver
|
| Resolver
|
||||||
|
@ -60,8 +82,7 @@
|
||||||
<role>org.apache.maven.artifact.manager.WagonManager</role>
|
<role>org.apache.maven.artifact.manager.WagonManager</role>
|
||||||
</requirement>
|
</requirement>
|
||||||
<requirement>
|
<requirement>
|
||||||
<role>org.apache.maven.artifact.transform.ArtifactTransformation</role>
|
<role>org.apache.maven.artifact.transform.ArtifactTransformationManager</role>
|
||||||
<field-name>artifactTransformations</field-name>
|
|
||||||
</requirement>
|
</requirement>
|
||||||
<requirement>
|
<requirement>
|
||||||
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
|
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
|
||||||
|
@ -82,8 +103,7 @@
|
||||||
<implementation>org.apache.maven.artifact.installer.DefaultArtifactInstaller</implementation>
|
<implementation>org.apache.maven.artifact.installer.DefaultArtifactInstaller</implementation>
|
||||||
<requirements>
|
<requirements>
|
||||||
<requirement>
|
<requirement>
|
||||||
<role>org.apache.maven.artifact.transform.ArtifactTransformation</role>
|
<role>org.apache.maven.artifact.transform.ArtifactTransformationManager</role>
|
||||||
<field-name>artifactTransformations</field-name>
|
|
||||||
</requirement>
|
</requirement>
|
||||||
</requirements>
|
</requirements>
|
||||||
</component>
|
</component>
|
||||||
|
@ -101,8 +121,7 @@
|
||||||
<role>org.apache.maven.artifact.manager.WagonManager</role>
|
<role>org.apache.maven.artifact.manager.WagonManager</role>
|
||||||
</requirement>
|
</requirement>
|
||||||
<requirement>
|
<requirement>
|
||||||
<role>org.apache.maven.artifact.transform.ArtifactTransformation</role>
|
<role>org.apache.maven.artifact.transform.ArtifactTransformationManager</role>
|
||||||
<field-name>artifactTransformations</field-name>
|
|
||||||
</requirement>
|
</requirement>
|
||||||
</requirements>
|
</requirements>
|
||||||
</component>
|
</component>
|
||||||
|
|
|
@ -61,4 +61,5 @@ public interface ArtifactTransformation
|
||||||
*/
|
*/
|
||||||
void transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository )
|
void transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository )
|
||||||
throws ArtifactMetadataRetrievalException;
|
throws ArtifactMetadataRetrievalException;
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
package org.apache.maven.artifact.transform;
|
||||||
|
|
||||||
|
import org.apache.maven.artifact.Artifact;
|
||||||
|
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
||||||
|
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manages multiple ArtifactTransformation instances and applies them in succession.
|
||||||
|
*/
|
||||||
|
public interface ArtifactTransformationManager
|
||||||
|
{
|
||||||
|
String ROLE = ArtifactTransformationManager.class.getName();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Take in a artifact and return the transformed artifact for locating in the remote repository. If no
|
||||||
|
* transformation has occured the original artifact is returned.
|
||||||
|
*
|
||||||
|
* @param artifact Artifact to be transformed.
|
||||||
|
* @param remoteRepositories the repositories to check
|
||||||
|
* @param localRepository the local repository
|
||||||
|
*/
|
||||||
|
void transformForResolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
|
||||||
|
throws ArtifactMetadataRetrievalException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Take in a artifact and return the transformed artifact for locating in the local repository. If no
|
||||||
|
* transformation has occured the original artifact is returned.
|
||||||
|
*
|
||||||
|
* @param artifact Artifact to be transformed.
|
||||||
|
* @param localRepository the local repository it will be stored in
|
||||||
|
*/
|
||||||
|
void transformForInstall( Artifact artifact, ArtifactRepository localRepository )
|
||||||
|
throws ArtifactMetadataRetrievalException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Take in a artifact and return the transformed artifact for distributing toa remote repository. If no
|
||||||
|
* transformation has occured the original artifact is returned.
|
||||||
|
*
|
||||||
|
* @param artifact Artifact to be transformed.
|
||||||
|
* @param remoteRepository the repository to deploy to
|
||||||
|
*/
|
||||||
|
void transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository )
|
||||||
|
throws ArtifactMetadataRetrievalException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the timestamp which will be used to deploy artifacts from this build.
|
||||||
|
*/
|
||||||
|
String getSnapshotDeploymentTimestamp();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the buildnumber which will be used to deploy artifacts from this build.
|
||||||
|
*/
|
||||||
|
int getSnapshotDeploymentBuildNumber( Artifact snapshotArtifact );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the artifact-version which will be used to deploy artifacts from this build.
|
||||||
|
*/
|
||||||
|
String getSnapshotDeploymentVersion( Artifact snapshotArtifact );
|
||||||
|
|
||||||
|
}
|
|
@ -26,6 +26,7 @@ import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolver;
|
import org.apache.maven.artifact.resolver.ArtifactResolver;
|
||||||
|
import org.apache.maven.artifact.transform.ArtifactTransformationManager;
|
||||||
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||||
import org.apache.maven.artifact.versioning.VersionRange;
|
import org.apache.maven.artifact.versioning.VersionRange;
|
||||||
import org.apache.maven.model.Build;
|
import org.apache.maven.model.Build;
|
||||||
|
@ -120,6 +121,8 @@ public class DefaultMavenProjectBuilder
|
||||||
|
|
||||||
private ArtifactRepositoryFactory artifactRepositoryFactory;
|
private ArtifactRepositoryFactory artifactRepositoryFactory;
|
||||||
|
|
||||||
|
private ArtifactTransformationManager transformationManager;
|
||||||
|
|
||||||
private final Map modelCache = new HashMap();
|
private final Map modelCache = new HashMap();
|
||||||
|
|
||||||
public static final String MAVEN_MODEL_VERSION = "4.0.0";
|
public static final String MAVEN_MODEL_VERSION = "4.0.0";
|
||||||
|
@ -577,6 +580,13 @@ public class DefaultMavenProjectBuilder
|
||||||
project.getVersion(), project.getPackaging() );
|
project.getVersion(), project.getPackaging() );
|
||||||
project.setArtifact( projectArtifact );
|
project.setArtifact( projectArtifact );
|
||||||
|
|
||||||
|
if ( projectArtifact.isSnapshot() )
|
||||||
|
{
|
||||||
|
project.setSnapshotDeploymentVersion( transformationManager.getSnapshotDeploymentVersion( projectArtifact ) );
|
||||||
|
|
||||||
|
project.setSnapshotDeploymentBuildNumber( transformationManager.getSnapshotDeploymentBuildNumber( projectArtifact ) );
|
||||||
|
}
|
||||||
|
|
||||||
project.setPluginArtifactRepositories( ProjectUtils.buildArtifactRepositories( model.getPluginRepositories(),
|
project.setPluginArtifactRepositories( ProjectUtils.buildArtifactRepositories( model.getPluginRepositories(),
|
||||||
artifactRepositoryFactory,
|
artifactRepositoryFactory,
|
||||||
container ) );
|
container ) );
|
||||||
|
|
|
@ -137,6 +137,10 @@ public class MavenProject
|
||||||
|
|
||||||
private Build buildOverlay;
|
private Build buildOverlay;
|
||||||
|
|
||||||
|
private String snapshotDeploymentVersion;
|
||||||
|
|
||||||
|
private int snapshotDeploymentBuildNumber = -1;
|
||||||
|
|
||||||
public MavenProject( Model model )
|
public MavenProject( Model model )
|
||||||
{
|
{
|
||||||
this.model = model;
|
this.model = model;
|
||||||
|
@ -183,6 +187,9 @@ public class MavenProject
|
||||||
this.originalModel = ModelUtils.cloneModel( project.originalModel );
|
this.originalModel = ModelUtils.cloneModel( project.originalModel );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.snapshotDeploymentVersion = project.snapshotDeploymentVersion;
|
||||||
|
this.snapshotDeploymentBuildNumber = project.snapshotDeploymentBuildNumber;
|
||||||
|
|
||||||
// TODO: need to clone this too?
|
// TODO: need to clone this too?
|
||||||
this.artifact = project.artifact;
|
this.artifact = project.artifact;
|
||||||
}
|
}
|
||||||
|
@ -1342,4 +1349,31 @@ public class MavenProject
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSnapshotDeploymentVersion( String deploymentVersion )
|
||||||
|
{
|
||||||
|
this.snapshotDeploymentVersion = deploymentVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSnapshotDeploymentVersion()
|
||||||
|
{
|
||||||
|
if ( snapshotDeploymentVersion == null )
|
||||||
|
{
|
||||||
|
return getVersion();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return snapshotDeploymentVersion;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSnapshotDeploymentBuildNumber( int deploymentBuildNumber )
|
||||||
|
{
|
||||||
|
this.snapshotDeploymentBuildNumber = deploymentBuildNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSnapshotDeploymentBuildNumber()
|
||||||
|
{
|
||||||
|
return snapshotDeploymentBuildNumber;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,9 @@
|
||||||
<role>org.apache.maven.project.MavenProjectBuilder</role>
|
<role>org.apache.maven.project.MavenProjectBuilder</role>
|
||||||
<implementation>org.apache.maven.project.DefaultMavenProjectBuilder</implementation>
|
<implementation>org.apache.maven.project.DefaultMavenProjectBuilder</implementation>
|
||||||
<requirements>
|
<requirements>
|
||||||
|
<requirement>
|
||||||
|
<role>org.apache.maven.artifact.transform.ArtifactTransformationManager</role>
|
||||||
|
</requirement>
|
||||||
<requirement>
|
<requirement>
|
||||||
<role>org.apache.maven.profiles.MavenProfilesBuilder</role>
|
<role>org.apache.maven.profiles.MavenProfilesBuilder</role>
|
||||||
</requirement>
|
</requirement>
|
||||||
|
|
Loading…
Reference in New Issue