PR: MNG-613

deploy snapshot information to the correct directory and fix some other minor issues

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@278930 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-09-06 06:58:44 +00:00
parent ddb34ee46d
commit cb2370199b
15 changed files with 398 additions and 87 deletions

View File

@ -115,4 +115,24 @@ 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

@ -122,4 +122,24 @@ 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

@ -179,4 +179,14 @@ public class SnapshotArtifactMetadata
{
return artifact.getBaseVersion();
}
public String getLatestVersion()
{
return null;
}
public String getReleaseVersion()
{
return null;
}
}

View File

@ -59,7 +59,7 @@ public class ArtifactRepositoryMetadata
public String toString()
{
return "repository metadata for artifact: \'" + artifact + "\'";
return "repository metadata for: \'" + getKey() + "\'";
}
public boolean storedInGroupDirectory()
@ -84,7 +84,7 @@ public class ArtifactRepositoryMetadata
public String getBaseVersion()
{
return artifact.getBaseVersion();
return null;
}
protected void updateRepositoryMetadata( ArtifactRepository localRepository, ArtifactRepository remoteRepository )
@ -142,27 +142,6 @@ public class ArtifactRepositoryMetadata
Versioning v = metadata.getVersioning();
if ( v != null )
{
// TODO: merge versioning (reuse code from transformation)
Snapshot s = v.getSnapshot();
Snapshot snapshot = versioning.getSnapshot();
if ( snapshot != null )
{
if ( s == null )
{
v.setSnapshot( snapshot );
changed = true;
}
else if ( s.getTimestamp() != null && !s.getTimestamp().equals( snapshot.getTimestamp() ) )
{
s.setTimestamp( snapshot.getTimestamp() );
changed = true;
}
else if ( s.getBuildNumber() != snapshot.getBuildNumber() )
{
s.setBuildNumber( snapshot.getBuildNumber() );
changed = true;
}
}
if ( versioning.getRelease() != null )
{
changed = true;
@ -225,7 +204,7 @@ public class ArtifactRepositoryMetadata
public Snapshot getSnapshot()
{
return versioning != null ? versioning.getSnapshot() : null;
return null;
}
public String getLatestVersion()
@ -237,4 +216,14 @@ public class ArtifactRepositoryMetadata
{
return versioning.getRelease();
}
public int getBuildNumber()
{
return 0;
}
public String getTimestamp()
{
return null;
}
}

View File

@ -98,7 +98,7 @@ public class DefaultRepositoryMetadataManager
File file = new File( localRepository.getBasedir(),
localRepository.pathOfLocalRepositoryMetadata( metadata, remoteRepository ) );
resolveAlways( metadata, localRepository, file, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN );
resolveAlways( metadata, remoteRepository, file, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN );
}
private void resolveAlways( ArtifactMetadata metadata, ArtifactRepository repository, File file,

View File

@ -199,4 +199,24 @@ 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

@ -0,0 +1,218 @@
package org.apache.maven.artifact.repository.metadata;
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed 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.
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
/**
* Metadata for the artifact version directory of the repository.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
* @todo split instantiation (versioning, plugin mappings) from definition
*/
public class SnapshotArtifactRepositoryMetadata
extends AbstractRepositoryMetadata
{
private Snapshot snapshot;
private Artifact artifact;
public SnapshotArtifactRepositoryMetadata( Artifact artifact )
{
this.artifact = artifact;
}
public SnapshotArtifactRepositoryMetadata( Artifact artifact, Snapshot snapshot )
{
this.snapshot = snapshot;
this.artifact = artifact;
}
public String toString()
{
return "repository metadata for: \'" + getKey() + "\'";
}
public boolean storedInGroupDirectory()
{
return false;
}
public boolean storedInArtifactVersionDirectory()
{
return true;
}
public String getGroupId()
{
return artifact.getGroupId();
}
public String getArtifactId()
{
return artifact.getArtifactId();
}
public String getBaseVersion()
{
return artifact.getBaseVersion();
}
protected void updateRepositoryMetadata( ArtifactRepository localRepository, ArtifactRepository remoteRepository )
throws IOException
{
MetadataXpp3Reader mappingReader = new MetadataXpp3Reader();
Metadata metadata = null;
File metadataFile = new File( localRepository.getBasedir(),
localRepository.pathOfLocalRepositoryMetadata( this, remoteRepository ) );
if ( metadataFile.exists() )
{
Reader reader = null;
try
{
reader = new FileReader( metadataFile );
metadata = mappingReader.read( reader );
}
catch ( FileNotFoundException e )
{
// TODO: Log a warning
}
catch ( IOException e )
{
// TODO: Log a warning
}
catch ( XmlPullParserException e )
{
// TODO: Log a warning
}
finally
{
IOUtil.close( reader );
}
}
boolean changed = false;
// If file could not be found or was not valid, start from scratch
if ( metadata == null )
{
metadata = new Metadata();
metadata.setGroupId( artifact.getGroupId() );
metadata.setArtifactId( artifact.getArtifactId() );
changed = true;
}
if ( snapshot != null )
{
Versioning v = metadata.getVersioning();
if ( v == null )
{
v = new Versioning();
metadata.setVersioning( v );
}
Snapshot s = v.getSnapshot();
if ( s == null )
{
v.setSnapshot( snapshot );
changed = true;
}
else if ( s.getTimestamp() != null && !s.getTimestamp().equals( snapshot.getTimestamp() ) )
{
s.setTimestamp( snapshot.getTimestamp() );
changed = true;
}
else if ( s.getBuildNumber() != snapshot.getBuildNumber() )
{
s.setBuildNumber( snapshot.getBuildNumber() );
changed = true;
}
}
if ( changed )
{
Writer writer = null;
try
{
metadataFile.getParentFile().mkdirs();
writer = new FileWriter( metadataFile );
MetadataXpp3Writer mappingWriter = new MetadataXpp3Writer();
mappingWriter.write( writer, metadata );
}
finally
{
IOUtil.close( writer );
}
}
else
{
metadataFile.setLastModified( System.currentTimeMillis() );
}
}
public Object getKey()
{
return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getBaseVersion();
}
public boolean isSnapshot()
{
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

@ -27,7 +27,7 @@ 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.Snapshot;
import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.codehaus.plexus.logging.AbstractLogEnabled;
@ -68,7 +68,15 @@ public abstract class AbstractVersionTransformation
throws ArtifactMetadataRetrievalException
{
// TODO: can we improve on this?
ArtifactMetadata metadata = new ArtifactRepositoryMetadata( artifact );
ArtifactMetadata metadata = null;
if ( artifact.isSnapshot() )
{
metadata = new ArtifactRepositoryMetadata( artifact );
}
else
{
metadata = new SnapshotArtifactRepositoryMetadata( artifact );
}
repositoryMetadataManager.resolve( metadata, remoteRepositories, localRepository );
@ -86,7 +94,7 @@ public abstract class AbstractVersionTransformation
String version = selectVersion( versioning, artifact.getVersion() );
*/
ArtifactRepositoryMetadata localMetadata = null;
ArtifactMetadata localMetadata = null;
for ( Iterator i = remoteRepositories.iterator(); i.hasNext(); )
{
ArtifactRepository repository = (ArtifactRepository) i.next();
@ -99,8 +107,7 @@ public abstract class AbstractVersionTransformation
break;
}
}
ArtifactRepositoryMetadata m = loadVersioningInformation( metadata, localRepository, localRepository,
artifact );
ArtifactMetadata m = loadVersioningInformation( metadata, localRepository, localRepository, artifact );
if ( m != null )
{
localMetadata = m;
@ -147,22 +154,20 @@ public abstract class AbstractVersionTransformation
return version;
}
protected Snapshot resolveLatestSnapshotVersion( Artifact artifact, ArtifactRepository localRepository,
ArtifactRepository remoteRepository )
protected int resolveLatestSnapshotBuildNumber( Artifact artifact, ArtifactRepository localRepository,
ArtifactRepository remoteRepository )
throws ArtifactMetadataRetrievalException
{
// TODO: can we improve on this?
ArtifactMetadata metadata = new ArtifactRepositoryMetadata( artifact );
ArtifactMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
getLogger().info( "Retrieving previous build number from " + remoteRepository.getId() );
repositoryMetadataManager.resolveAlways( metadata, localRepository, remoteRepository );
ArtifactRepositoryMetadata m = loadVersioningInformation( metadata, remoteRepository, localRepository,
artifact );
Snapshot snapshot;
ArtifactMetadata m = loadVersioningInformation( metadata, remoteRepository, localRepository, artifact );
int buildNumber = 0;
if ( m == null )
{
snapshot = new Snapshot();
try
{
SnapshotArtifactMetadata snapshotMetadata = new SnapshotArtifactMetadata( artifact );
@ -170,8 +175,7 @@ public abstract class AbstractVersionTransformation
ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN );
getLogger().warn( "Using old-style versioning metadata from remote repo for " + artifact );
snapshot.setTimestamp( snapshotMetadata.getTimestamp() );
snapshot.setBuildNumber( snapshotMetadata.getBuildNumber() );
buildNumber = snapshotMetadata.getBuildNumber();
}
catch ( ResourceDoesNotExistException e1 )
{
@ -181,12 +185,12 @@ public abstract class AbstractVersionTransformation
}
else
{
snapshot = m.getSnapshot();
buildNumber = m.getBuildNumber();
}
return snapshot;
return buildNumber;
}
protected abstract String constructVersion( ArtifactRepositoryMetadata metadata );
protected abstract String constructVersion( ArtifactMetadata metadata );
/* TODO
private void mergeVersioning( Versioning dest, Versioning source )
@ -345,22 +349,32 @@ public abstract class AbstractVersionTransformation
return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getBaseVersion();
}
private ArtifactRepositoryMetadata loadVersioningInformation( ArtifactMetadata repoMetadata,
ArtifactRepository remoteRepository,
ArtifactRepository localRepository,
Artifact artifact )
private ArtifactMetadata loadVersioningInformation( ArtifactMetadata repoMetadata,
ArtifactRepository remoteRepository,
ArtifactRepository localRepository, Artifact artifact )
throws ArtifactMetadataRetrievalException
{
File metadataFile = new File( localRepository.getBasedir(),
localRepository.pathOfLocalRepositoryMetadata( repoMetadata, remoteRepository ) );
ArtifactRepositoryMetadata newMetadata = null;
ArtifactMetadata newMetadata = null;
if ( metadataFile.exists() )
{
Metadata metadata = readMetadata( metadataFile );
if ( metadata.getVersioning() != null )
{
newMetadata = new ArtifactRepositoryMetadata( artifact, metadata.getVersioning() );
if ( artifact.isSnapshot() )
{
if ( metadata.getVersioning().getSnapshot() != null )
{
newMetadata = new SnapshotArtifactRepositoryMetadata( artifact,
metadata.getVersioning().getSnapshot() );
}
}
else
{
newMetadata = new ArtifactRepositoryMetadata( artifact, metadata.getVersioning() );
}
}
}
return newMetadata;

View File

@ -22,7 +22,6 @@ import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.LatestArtifactMetadata;
import org.apache.maven.artifact.metadata.LegacyArtifactMetadata;
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;
@ -69,7 +68,7 @@ public class LatestArtifactTransformation
return metadata;
}
protected String constructVersion( ArtifactRepositoryMetadata metadata )
protected String constructVersion( ArtifactMetadata metadata )
{
return metadata.getLatestVersion();
}

View File

@ -17,11 +17,11 @@ package org.apache.maven.artifact.transform;
*/
import org.apache.maven.artifact.Artifact;
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.ReleaseArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
import java.util.List;
@ -69,7 +69,7 @@ public class ReleaseArtifactTransformation
return new ReleaseArtifactMetadata( artifact );
}
protected String constructVersion( ArtifactRepositoryMetadata metadata )
protected String constructVersion( ArtifactMetadata metadata )
{
return metadata.getReleaseVersion();
}

View File

@ -22,9 +22,8 @@ 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.metadata.ArtifactRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.Snapshot;
import org.apache.maven.artifact.repository.metadata.Versioning;
import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
import org.codehaus.plexus.util.StringUtils;
import java.util.Date;
@ -57,11 +56,7 @@ public class SnapshotTransformation
if ( artifact.isSnapshot() )
{
// TODO: Better way to create this - should have to construct Versioning
Versioning versioning = new Versioning();
Snapshot snapshot = new Snapshot();
versioning.setSnapshot( snapshot );
ArtifactMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning );
ArtifactMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
// TODO: should merge with other repository metadata sitting on the same level?
artifact.addMetadata( metadata );
@ -74,15 +69,14 @@ public class SnapshotTransformation
{
if ( artifact.isSnapshot() )
{
Snapshot snapshot = resolveLatestSnapshotVersion( artifact, localRepository, remoteRepository );
snapshot.setTimestamp( getDeploymentTimestamp() );
snapshot.setBuildNumber( snapshot.getBuildNumber() + 1 );
int buildNumber = resolveLatestSnapshotBuildNumber( artifact, localRepository, remoteRepository );
// TODO: Better way to create this - should have to construct Versioning
Versioning versioning = new Versioning();
versioning.setSnapshot( snapshot );
Snapshot snapshot = new Snapshot();
snapshot.setTimestamp( getDeploymentTimestamp() );
snapshot.setBuildNumber( buildNumber + 1 );
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning );
ArtifactMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact, snapshot );
artifact.setResolvedVersion( constructVersion( metadata ) );
@ -104,23 +98,19 @@ public class SnapshotTransformation
return new SnapshotArtifactMetadata( artifact );
}
protected String constructVersion( ArtifactRepositoryMetadata metadata )
protected String constructVersion( ArtifactMetadata metadata )
{
String version = metadata.getBaseVersion();
Snapshot snapshot = metadata.getSnapshot();
if ( snapshot != null )
if ( metadata.getTimestamp() != null && metadata.getBuildNumber() > 0 )
{
if ( snapshot.getTimestamp() != null && snapshot.getBuildNumber() > 0 )
String newVersion = metadata.getTimestamp() + "-" + metadata.getBuildNumber();
if ( version != null )
{
String newVersion = snapshot.getTimestamp() + "-" + snapshot.getBuildNumber();
if ( version != null )
{
version = StringUtils.replace( version, "SNAPSHOT", newVersion );
}
else
{
version = newVersion;
}
version = StringUtils.replace( version, "SNAPSHOT", newVersion );
}
else
{
version = newVersion;
}
}
return version;

View File

@ -26,6 +26,7 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
* @todo merge with artifactmetadatasource
* @todo retrieval exception not appropriate for store
* @todo not happy about the store/retrieve methods - they use "this"
* @todo separate specific interfaces
*/
public interface ArtifactMetadata
{
@ -72,4 +73,12 @@ public interface ArtifactMetadata
* @return the filename
*/
String getRemoteFilename();
int getBuildNumber();
String getTimestamp();
String getLatestVersion();
String getReleaseVersion();
}

View File

@ -129,14 +129,15 @@ public class DeployMojo
artifact.addMetadata( metadata );
}
// TODO: clean up
Versioning versioning = new Versioning();
versioning.addVersion( artifact.getVersion() );
if ( updateReleaseInfo )
{
// TODO: clean up
Versioning versioning = new Versioning();
versioning.setRelease( artifact.getVersion() );
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning );
artifact.addMetadata( metadata );
}
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning );
artifact.addMetadata( metadata );
try
{

View File

@ -97,14 +97,15 @@ public class InstallMojo
artifact.addMetadata( metadata );
}
// TODO: clean up
Versioning versioning = new Versioning();
versioning.addVersion( artifact.getVersion() );
if ( updateReleaseInfo )
{
// TODO: clean up
Versioning versioning = new Versioning();
versioning.setRelease( artifact.getVersion() );
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning );
artifact.addMetadata( metadata );
}
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning );
artifact.addMetadata( metadata );
try
{

View File

@ -145,4 +145,24 @@ 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;
}
}