PR: MNG-613

make sure versions are aggregated

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@278961 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-09-06 09:52:37 +00:00
parent cb2370199b
commit 3a4efa1029
17 changed files with 136 additions and 236 deletions

View File

@ -116,23 +116,4 @@ public class LatestArtifactMetadata
return false;
}
public int getBuildNumber()
{
return 0;
}
public String getTimestamp()
{
return null;
}
public String getLatestVersion()
{
return null;
}
public String getReleaseVersion()
{
return null;
}
}

View File

@ -123,23 +123,4 @@ public class ReleaseArtifactMetadata
return false;
}
public int getBuildNumber()
{
return 0;
}
public String getTimestamp()
{
return null;
}
public String getLatestVersion()
{
return null;
}
public String getReleaseVersion()
{
return null;
}
}

View File

@ -97,11 +97,6 @@ public class SnapshotArtifactMetadata
}
}
public String getTimestamp()
{
return timestamp;
}
public int getBuildNumber()
{
return buildNumber;
@ -180,13 +175,4 @@ public class SnapshotArtifactMetadata
return artifact.getBaseVersion();
}
public String getLatestVersion()
{
return null;
}
public String getReleaseVersion()
{
return null;
}
}

View File

@ -207,23 +207,4 @@ public class ArtifactRepositoryMetadata
return null;
}
public String getLatestVersion()
{
return versioning.getLatest();
}
public String getReleaseVersion()
{
return versioning.getRelease();
}
public int getBuildNumber()
{
return 0;
}
public String getTimestamp()
{
return null;
}
}

View File

@ -200,23 +200,4 @@ public class GroupRepositoryMetadata
return false;
}
public int getBuildNumber()
{
return 0;
}
public String getTimestamp()
{
return null;
}
public String getLatestVersion()
{
return null;
}
public String getReleaseVersion()
{
return null;
}
}

View File

@ -196,23 +196,4 @@ public class SnapshotArtifactRepositoryMetadata
return artifact.isSnapshot();
}
public int getBuildNumber()
{
return snapshot != null ? snapshot.getBuildNumber() : 0;
}
public String getTimestamp()
{
return snapshot != null ? snapshot.getTimestamp() : null;
}
public String getLatestVersion()
{
return null;
}
public String getReleaseVersion()
{
return null;
}
}

View File

@ -21,13 +21,13 @@ import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.LegacyArtifactMetadata;
import org.apache.maven.artifact.metadata.SnapshotArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.Metadata;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager;
import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.Versioning;
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.codehaus.plexus.logging.AbstractLogEnabled;
@ -69,7 +69,7 @@ public abstract class AbstractVersionTransformation
{
// TODO: can we improve on this?
ArtifactMetadata metadata = null;
if ( artifact.isSnapshot() )
if ( !artifact.isSnapshot() )
{
metadata = new ArtifactRepositoryMetadata( artifact );
}
@ -94,23 +94,23 @@ public abstract class AbstractVersionTransformation
String version = selectVersion( versioning, artifact.getVersion() );
*/
ArtifactMetadata localMetadata = null;
Versioning versioning = null;
for ( Iterator i = remoteRepositories.iterator(); i.hasNext(); )
{
ArtifactRepository repository = (ArtifactRepository) i.next();
localMetadata = loadVersioningInformation( metadata, repository, localRepository, artifact );
if ( localMetadata != null )
versioning = loadVersioningInformation( metadata, repository, localRepository, artifact );
if ( versioning != null )
{
artifact.setRepository( repository );
// TODO: merge instead (see above)
break;
}
}
ArtifactMetadata m = loadVersioningInformation( metadata, localRepository, localRepository, artifact );
if ( m != null )
Versioning v = loadVersioningInformation( metadata, localRepository, localRepository, artifact );
if ( v != null )
{
localMetadata = m;
versioning = v;
// TODO: figure out way to avoid duplicated message
if ( getLogger().isDebugEnabled() /*&& !alreadyResolved*/ )
{
@ -120,9 +120,9 @@ public abstract class AbstractVersionTransformation
}
String version = null;
if ( localMetadata != null )
if ( versioning != null )
{
version = constructVersion( localMetadata );
version = constructVersion( versioning, artifact.getBaseVersion() );
}
if ( version == null )
@ -154,43 +154,7 @@ public abstract class AbstractVersionTransformation
return version;
}
protected int resolveLatestSnapshotBuildNumber( Artifact artifact, ArtifactRepository localRepository,
ArtifactRepository remoteRepository )
throws ArtifactMetadataRetrievalException
{
// TODO: can we improve on this?
ArtifactMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
getLogger().info( "Retrieving previous build number from " + remoteRepository.getId() );
repositoryMetadataManager.resolveAlways( metadata, localRepository, remoteRepository );
ArtifactMetadata m = loadVersioningInformation( metadata, remoteRepository, localRepository, artifact );
int buildNumber = 0;
if ( m == null )
{
try
{
SnapshotArtifactMetadata snapshotMetadata = new SnapshotArtifactMetadata( artifact );
snapshotMetadata.retrieveFromRemoteRepository( remoteRepository, wagonManager,
ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN );
getLogger().warn( "Using old-style versioning metadata from remote repo for " + artifact );
buildNumber = snapshotMetadata.getBuildNumber();
}
catch ( ResourceDoesNotExistException e1 )
{
// safe to ignore, use default snapshot data
getLogger().debug( "Unable to find legacy metadata - ignoring" );
}
}
else
{
buildNumber = m.getBuildNumber();
}
return buildNumber;
}
protected abstract String constructVersion( ArtifactMetadata metadata );
protected abstract String constructVersion( Versioning versioning, String baseVersion );
/* TODO
private void mergeVersioning( Versioning dest, Versioning source )
@ -349,35 +313,20 @@ public abstract class AbstractVersionTransformation
return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getBaseVersion();
}
private ArtifactMetadata loadVersioningInformation( ArtifactMetadata repoMetadata,
ArtifactRepository remoteRepository,
ArtifactRepository localRepository, Artifact artifact )
protected Versioning loadVersioningInformation( ArtifactMetadata repoMetadata, ArtifactRepository remoteRepository,
ArtifactRepository localRepository, Artifact artifact )
throws ArtifactMetadataRetrievalException
{
File metadataFile = new File( localRepository.getBasedir(),
localRepository.pathOfLocalRepositoryMetadata( repoMetadata, remoteRepository ) );
ArtifactMetadata newMetadata = null;
Versioning versioning = null;
if ( metadataFile.exists() )
{
Metadata metadata = readMetadata( metadataFile );
if ( metadata.getVersioning() != null )
{
if ( artifact.isSnapshot() )
{
if ( metadata.getVersioning().getSnapshot() != null )
{
newMetadata = new SnapshotArtifactRepositoryMetadata( artifact,
metadata.getVersioning().getSnapshot() );
}
}
else
{
newMetadata = new ArtifactRepositoryMetadata( artifact, metadata.getVersioning() );
}
}
versioning = metadata.getVersioning();
}
return newMetadata;
return versioning;
}
/**

View File

@ -68,8 +68,8 @@ public class LatestArtifactTransformation
return metadata;
}
protected String constructVersion( ArtifactMetadata metadata )
protected String constructVersion( Versioning versioning, String baseVersion )
{
return metadata.getLatestVersion();
return versioning.getLatest();
}
}

View File

@ -22,6 +22,8 @@ import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.LegacyArtifactMetadata;
import org.apache.maven.artifact.metadata.ReleaseArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.Versioning;
import java.util.List;
@ -54,14 +56,40 @@ public class ReleaseArtifactTransformation
public void transformForInstall( Artifact artifact, ArtifactRepository localRepository )
throws ArtifactMetadataRetrievalException
{
// metadata is added at install time
Versioning versioning = new Versioning();
versioning.addVersion( artifact.getVersion() );
if ( artifact.isRelease() )
{
versioning.setRelease( artifact.getVersion() );
}
// TODO: need to create?
ArtifactMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning );
artifact.addMetadata( metadata );
}
public void transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository,
ArtifactRepository localRepository )
throws ArtifactMetadataRetrievalException
{
// metadata is added at deploy time
Versioning versioning = new Versioning();
versioning.addVersion( artifact.getVersion() );
if ( artifact.isRelease() )
{
versioning.setRelease( artifact.getVersion() );
}
// TODO: need to create?
ArtifactMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning );
artifact.addMetadata( metadata );
// TODO: this should be in the part that actually merges instead
getLogger().info( "Retrieving previous metadata from " + remoteRepository.getId() );
repositoryMetadataManager.resolveAlways( metadata, localRepository, remoteRepository );
}
protected LegacyArtifactMetadata createLegacyMetadata( Artifact artifact )
@ -69,8 +97,8 @@ public class ReleaseArtifactTransformation
return new ReleaseArtifactMetadata( artifact );
}
protected String constructVersion( ArtifactMetadata metadata )
protected String constructVersion( Versioning versioning, String bS )
{
return metadata.getReleaseVersion();
return versioning.getRelease();
}
}

View File

@ -22,8 +22,11 @@ import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.LegacyArtifactMetadata;
import org.apache.maven.artifact.metadata.SnapshotArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.artifact.repository.metadata.Snapshot;
import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.Versioning;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.codehaus.plexus.util.StringUtils;
import java.util.Date;
@ -78,7 +81,9 @@ public class SnapshotTransformation
ArtifactMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact, snapshot );
artifact.setResolvedVersion( constructVersion( metadata ) );
Versioning versioning = new Versioning();
versioning.setSnapshot( snapshot );
artifact.setResolvedVersion( constructVersion( versioning, artifact.getBaseVersion() ) );
artifact.addMetadata( metadata );
}
@ -98,21 +103,62 @@ public class SnapshotTransformation
return new SnapshotArtifactMetadata( artifact );
}
protected String constructVersion( ArtifactMetadata metadata )
protected String constructVersion( Versioning versioning, String baseVersion )
{
String version = metadata.getBaseVersion();
if ( metadata.getTimestamp() != null && metadata.getBuildNumber() > 0 )
String version = baseVersion;
Snapshot snapshot = versioning.getSnapshot();
if ( snapshot != null )
{
String newVersion = metadata.getTimestamp() + "-" + metadata.getBuildNumber();
if ( version != null )
if ( snapshot.getTimestamp() != null && snapshot.getBuildNumber() > 0 )
{
version = StringUtils.replace( version, "SNAPSHOT", newVersion );
}
else
{
version = newVersion;
String newVersion = snapshot.getTimestamp() + "-" + snapshot.getBuildNumber();
if ( version != null )
{
version = StringUtils.replace( version, "SNAPSHOT", newVersion );
}
else
{
version = newVersion;
}
}
}
return version;
}
private int resolveLatestSnapshotBuildNumber( Artifact artifact, ArtifactRepository localRepository,
ArtifactRepository remoteRepository )
throws ArtifactMetadataRetrievalException
{
// TODO: can we improve on this?
ArtifactMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
getLogger().info( "Retrieving previous build number from " + remoteRepository.getId() );
repositoryMetadataManager.resolveAlways( metadata, localRepository, remoteRepository );
Versioning versioning = loadVersioningInformation( metadata, remoteRepository, localRepository, artifact );
int buildNumber = 0;
if ( versioning == null )
{
try
{
SnapshotArtifactMetadata snapshotMetadata = new SnapshotArtifactMetadata( artifact );
snapshotMetadata.retrieveFromRemoteRepository( remoteRepository, wagonManager,
ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN );
getLogger().warn( "Using old-style versioning metadata from remote repo for " + artifact );
buildNumber = snapshotMetadata.getBuildNumber();
}
catch ( ResourceDoesNotExistException e1 )
{
// safe to ignore, use default snapshot data
getLogger().debug( "Unable to find legacy metadata - ignoring" );
}
}
else if ( versioning.getSnapshot() != null )
{
buildNumber = versioning.getSnapshot().getBuildNumber();
}
return buildNumber;
}
}

View File

@ -49,7 +49,7 @@ public interface Artifact
String SCOPE_RUNTIME = "runtime";
String SCOPE_PROVIDED = "provided";
String SCOPE_SYSTEM = "system";
String getGroupId();
@ -141,4 +141,8 @@ public interface Artifact
* @todo remove, a quick hack for the lifecycle executor
*/
void setArtifactHandler( ArtifactHandler handler );
boolean isRelease();
void setRelease( boolean release );
}

View File

@ -74,6 +74,8 @@ public class DefaultArtifact
private boolean resolved;
private boolean release = false;
public DefaultArtifact( String groupId, String artifactId, VersionRange versionRange, String scope, String type,
String classifier, ArtifactHandler artifactHandler )
{
@ -462,4 +464,13 @@ public class DefaultArtifact
this.artifactHandler = artifactHandler;
}
public void setRelease( boolean release )
{
this.release = release;
}
public boolean isRelease()
{
return release;
}
}

View File

@ -74,11 +74,4 @@ public interface ArtifactMetadata
*/
String getRemoteFilename();
int getBuildNumber();
String getTimestamp();
String getLatestVersion();
String getReleaseVersion();
}

View File

@ -21,8 +21,6 @@ import org.apache.maven.artifact.deployer.ArtifactDeployer;
import org.apache.maven.artifact.deployer.ArtifactDeploymentException;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.Versioning;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.artifact.ProjectArtifactMetadata;
@ -129,15 +127,10 @@ public class DeployMojo
artifact.addMetadata( metadata );
}
// TODO: clean up
Versioning versioning = new Versioning();
versioning.addVersion( artifact.getVersion() );
if ( updateReleaseInfo )
{
versioning.setRelease( artifact.getVersion() );
artifact.setRelease( true );
}
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning );
artifact.addMetadata( metadata );
try
{

View File

@ -19,8 +19,6 @@ package org.apache.maven.plugin.install;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.installer.ArtifactInstallationException;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.Versioning;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.artifact.ProjectArtifactMetadata;
@ -88,6 +86,7 @@ public class InstallMojo
public void execute()
throws MojoExecutionException
{
// TODO: push into transformation
boolean isPomArtifact = "pom".equals( packaging );
File pom = new File( basedir, "pom.xml" );
@ -97,15 +96,10 @@ public class InstallMojo
artifact.addMetadata( metadata );
}
// TODO: clean up
Versioning versioning = new Versioning();
versioning.addVersion( artifact.getVersion() );
if ( updateReleaseInfo )
{
versioning.setRelease( artifact.getVersion() );
artifact.setRelease( true );
}
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning );
artifact.addMetadata( metadata );
try
{

View File

@ -250,4 +250,14 @@ public class ActiveProjectArtifact
{
return "active project artifact:\n\tartifact = " + artifact + ";\n\tproject: " + project;
}
public boolean isRelease()
{
return artifact.isRelease();
}
public void setRelease( boolean release )
{
artifact.setResolved( release );
}
}

View File

@ -146,23 +146,4 @@ public class ProjectArtifactMetadata
return artifact.isSnapshot();
}
public String getLatestVersion()
{
return null;
}
public String getReleaseVersion()
{
return null;
}
public int getBuildNumber()
{
return 0;
}
public String getTimestamp()
{
return null;
}
}