PR: MNG-613

changes versioning to use repository metadata

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@278881 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-09-05 23:12:55 +00:00
parent a5b853b357
commit 8f3c207194
36 changed files with 794 additions and 315 deletions

View File

@ -154,6 +154,9 @@
<requirement>
<role>org.apache.maven.artifact.manager.WagonManager</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager</role>
</requirement>
</requirements>
</component>
@ -165,6 +168,9 @@
<requirement>
<role>org.apache.maven.artifact.manager.WagonManager</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager</role>
</requirement>
</requirements>
</component>
@ -176,6 +182,9 @@
<requirement>
<role>org.apache.maven.artifact.manager.WagonManager</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager</role>
</requirement>
</requirements>
</component>

View File

@ -56,7 +56,7 @@ public class DefaultArtifactDeployer
{
try
{
transformationManager.transformForDeployment( artifact, deploymentRepository );
transformationManager.transformForDeployment( artifact, deploymentRepository, localRepository );
// Copy the original file to the new one if it was transformed
File artifactFile = new File( localRepository.getBasedir(), localRepository.pathOf( artifact ) );

View File

@ -215,7 +215,8 @@ public class DefaultWagonManager
// This one we will eat when looking through remote repositories
// because we want to cycle through them all before squawking.
getLogger().warn( "Unable to get resource from repository " + repository.getId() + " (" + repository.getUrl() + ")" );
getLogger().warn(
"Unable to get resource from repository " + repository.getId() + " (" + repository.getUrl() + ")" );
}
}
@ -236,7 +237,7 @@ public class DefaultWagonManager
{
getLogger().debug( "Trying repository " + repository.getId() );
getRemoteFile( repository, artifact.getFile(), remotePath, downloadMonitor, policy.getChecksumPolicy() );
getLogger().debug( " Artifact resolved");
getLogger().debug( " Artifact resolved" );
artifact.setResolved( true );
}
@ -252,7 +253,6 @@ public class DefaultWagonManager
{
String remotePath = repository.pathOfRemoteRepositoryMetadata( metadata );
getLogger().info( "Retrieving " + metadata );
getRemoteFile( repository, destination, remotePath, null, checksumPolicy );
}

View File

@ -35,7 +35,7 @@ import java.util.Date;
*/
public abstract class AbstractVersionArtifactMetadata
extends AbstractArtifactMetadata
implements VersionArtifactMetadata
implements LegacyArtifactMetadata
{
protected static final String SNAPSHOT_VERSION_FILE = "version.txt";
@ -46,13 +46,7 @@ public abstract class AbstractVersionArtifactMetadata
super( artifact );
}
protected File getLocalRepositoryLocation( ArtifactRepository localRepository, ArtifactRepository remoteRepository )
{
return new File( localRepository.getBasedir(),
localRepository.pathOfLocalRepositoryMetadata( this, remoteRepository ) );
}
private void readFromFile( File file )
public void readFromFile( File file )
throws IOException
{
setContent( FileUtils.fileRead( file ) );
@ -61,26 +55,6 @@ public abstract class AbstractVersionArtifactMetadata
protected abstract void setContent( String content );
public boolean exists()
{
return lastModified > 0;
}
public Date getLastModified()
{
return new Date( lastModified );
}
public void readFromLocalRepository( ArtifactRepository localRepository, ArtifactRepository remoteRepository )
throws IOException
{
File f = getLocalRepositoryLocation( localRepository, remoteRepository );
if ( f.exists() )
{
readFromFile( f );
}
}
public void retrieveFromRemoteRepository( ArtifactRepository remoteRepository, WagonManager wagonManager,
String checksumPolicy )
throws ArtifactMetadataRetrievalException, ResourceDoesNotExistException
@ -105,7 +79,7 @@ public abstract class AbstractVersionArtifactMetadata
}
}
public void storeInLocalRepository( ArtifactRepository localRepository, ArtifactRepository remoteRepository )
public void storeInLocalRepository( ArtifactRepository localRepository )
throws ArtifactMetadataRetrievalException
{
String version = constructVersion();
@ -113,11 +87,10 @@ public abstract class AbstractVersionArtifactMetadata
{
try
{
String path = getLocalRepositoryLocation( localRepository, remoteRepository ).getPath();
File file = new File( path );
// TODO: this should be centralised before the resolution of the artifact
File file = new File( localRepository.getBasedir(),
localRepository.pathOfLocalRepositoryMetadata( this, null ) );
file.getParentFile().mkdirs();
FileUtils.fileWrite( path, version );
FileUtils.fileWrite( file.getPath(), version );
lastModified = file.lastModified();
}
catch ( IOException e )
@ -126,4 +99,15 @@ public abstract class AbstractVersionArtifactMetadata
}
}
}
public void storeInLocalRepository( ArtifactRepository localRepository, ArtifactRepository remoteRepository )
throws ArtifactMetadataRetrievalException
{
throw new IllegalStateException( "This code should no longer be called" );
}
public Date getLastModified()
{
return new Date( lastModified );
}
}

View File

@ -55,7 +55,6 @@ public class LatestArtifactMetadata
{
LatestArtifactMetadata metadata = (LatestArtifactMetadata) o;
// TODO: we need some more complicated version comparison
if ( version == null )
{
if ( metadata.version == null )

View File

@ -1,5 +1,13 @@
package org.apache.maven.artifact.metadata;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import java.io.File;
import java.io.IOException;
import java.util.Date;
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
@ -16,36 +24,27 @@ package org.apache.maven.artifact.metadata;
* limitations under the License.
*/
import java.io.File;
import java.util.Date;
/**
* Contains metadata about a versioned artifact.
* Methods used by the old artifact metadata. To be removed in beta-2.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
*/
public interface VersionArtifactMetadata
public interface LegacyArtifactMetadata
extends ArtifactMetadata, Comparable
{
/**
* Determine if the metadata is considered newer than a given file.
*
* @return whether it is newer
*/
void readFromFile( File file )
throws IOException;
void retrieveFromRemoteRepository( ArtifactRepository repository, WagonManager wagonManager, String checksumPolicy )
throws ArtifactMetadataRetrievalException, ResourceDoesNotExistException;
void storeInLocalRepository( ArtifactRepository localRepository )
throws ArtifactMetadataRetrievalException;
boolean newerThanFile( File file );
/**
* Get the resolved version from the metadata.
*
* @return the resolved version
*/
String constructVersion();
/**
* Determine when the metadata was last modified.
*
* @return the date the metadata was last modified.
*/
Date getLastModified();
}

View File

@ -30,7 +30,6 @@ import java.io.File;
*/
public class ReleaseArtifactMetadata
extends AbstractVersionArtifactMetadata
implements Comparable
{
private String version;
@ -63,7 +62,6 @@ public class ReleaseArtifactMetadata
{
ReleaseArtifactMetadata metadata = (ReleaseArtifactMetadata) o;
// TODO: we need some more complicated version comparison
if ( version == null )
{
if ( metadata.version == null )

View File

@ -97,12 +97,6 @@ public class SnapshotArtifactMetadata
}
}
public void setVersion( String timestamp, int buildNumber )
{
this.timestamp = timestamp;
this.buildNumber = buildNumber;
}
public String getTimestamp()
{
return timestamp;
@ -124,9 +118,6 @@ public class SnapshotArtifactMetadata
{
SnapshotArtifactMetadata metadata = (SnapshotArtifactMetadata) o;
// TODO: probably shouldn't test timestamp - except that it may be used do differentiate for a build number of 0
// in the local repository. check, then remove from here and just compare the build numbers
if ( buildNumber > metadata.buildNumber )
{
return 1;

View File

@ -66,8 +66,20 @@ public class DefaultArtifactRepository
this.layout = layout;
if ( snapshots == null )
{
snapshots = new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS,
ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE );
}
this.snapshots = snapshots;
if ( releases == null )
{
releases = new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS,
ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE );
}
this.releases = releases;
}

View File

@ -0,0 +1,60 @@
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.metadata.ArtifactMetadata;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.repository.ArtifactRepository;
import java.io.IOException;
/**
* Shared methods of the repository metadata handling.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
*/
public abstract class AbstractRepositoryMetadata
implements ArtifactMetadata
{
public String getRemoteFilename()
{
return "maven-metadata.xml";
}
public String getLocalFilename( ArtifactRepository repository )
{
return "maven-metadata-" + repository.getKey() + ".xml";
}
public void storeInLocalRepository( ArtifactRepository localRepository, ArtifactRepository remoteRepository )
throws ArtifactMetadataRetrievalException
{
try
{
updateRepositoryMetadata( localRepository, remoteRepository );
}
catch ( IOException e )
{
throw new ArtifactMetadataRetrievalException( "Error updating group repository metadata", e );
}
}
protected abstract void updateRepositoryMetadata( ArtifactRepository localRepository,
ArtifactRepository remoteRepository )
throws IOException;
}

View File

@ -0,0 +1,220 @@
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 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 ArtifactRepositoryMetadata
extends AbstractRepositoryMetadata
{
private Versioning versioning;
private Artifact artifact;
public ArtifactRepositoryMetadata( Artifact artifact )
{
this.artifact = artifact;
}
public ArtifactRepositoryMetadata( Artifact artifact, Versioning versioning )
{
this.versioning = versioning;
this.artifact = artifact;
}
public String toString()
{
return "repository metadata for artifact: \'" + artifact + "\'";
}
public boolean storedInGroupDirectory()
{
return false;
}
public boolean storedInArtifactVersionDirectory()
{
return false;
}
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 ( versioning != null )
{
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;
}
}
}
else
{
metadata.setVersioning( versioning );
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();
}
public boolean isSnapshot()
{
return artifact.isSnapshot();
}
public Snapshot getSnapshot()
{
return versioning != null ? versioning.getSnapshot() : null;
}
public String getLatestVersion()
{
return versioning.getLatest();
}
public String getReleaseVersion()
{
return versioning.getRelease();
}
}

View File

@ -57,7 +57,7 @@ public class DefaultRepositoryMetadataManager
ArtifactRepositoryPolicy policy = metadata.isSnapshot() ? repository.getSnapshots()
: repository.getReleases();
if ( policy == null || !policy.isEnabled() )
if ( !policy.isEnabled() )
{
getLogger().debug( "Skipping disabled repository " + repository.getId() );
}
@ -66,37 +66,23 @@ public class DefaultRepositoryMetadataManager
File file = new File( localRepository.getBasedir(),
localRepository.pathOfLocalRepositoryMetadata( metadata, repository ) );
// TODO: should be able to calculate this less often
boolean checkForUpdates = policy.checkOutOfDate( new Date( file.lastModified() ) );
if ( checkForUpdates )
{
getLogger().info( metadata.getKey() + ": checking for updates from " + repository.getId() );
try
{
wagonManager.getArtifactMetadata( metadata, repository, file, policy.getChecksumPolicy() );
resolveAlways( metadata, repository, file, policy.getChecksumPolicy() );
}
// TODO: ???
// metadata.setRepository( repository );
// touch file so that this is not checked again until interval has passed
if ( file.exists() )
{
file.setLastModified( System.currentTimeMillis() );
}
}
catch ( ResourceDoesNotExistException e )
{
getLogger().info( "Repository metadata " + metadata +
" could not be found on repository: " + repository.getId() );
getLogger().debug( "Cause", e );
}
catch ( TransferFailedException e )
{
throw new ArtifactMetadataRetrievalException( "Unable to retrieve metadata", e );
}
// touch file so that this is not checked again until interval has passed
if ( file.exists() )
{
file.setLastModified( System.currentTimeMillis() );
}
else
{
metadata.storeInLocalRepository( localRepository, repository );
}
}
}
@ -105,6 +91,40 @@ public class DefaultRepositoryMetadataManager
}
}
public void resolveAlways( ArtifactMetadata metadata, ArtifactRepository localRepository,
ArtifactRepository remoteRepository )
throws ArtifactMetadataRetrievalException
{
File file = new File( localRepository.getBasedir(),
localRepository.pathOfLocalRepositoryMetadata( metadata, remoteRepository ) );
resolveAlways( metadata, localRepository, file, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN );
}
private void resolveAlways( ArtifactMetadata metadata, ArtifactRepository repository, File file,
String checksumPolicy )
throws ArtifactMetadataRetrievalException
{
try
{
wagonManager.getArtifactMetadata( metadata, repository, file, checksumPolicy );
}
catch ( ResourceDoesNotExistException e )
{
getLogger().debug( metadata + " could not be found on repository: " + repository.getId() );
// delete the local copy so the old details aren't used.
if ( file.exists() )
{
file.delete();
}
}
catch ( TransferFailedException e )
{
throw new ArtifactMetadataRetrievalException( "Unable to retrieve metadata", e );
}
}
private boolean alreadyResolved( ArtifactMetadata metadata )
{
return cachedMetadata.contains( metadata.getKey() );

View File

@ -16,8 +16,6 @@ package org.apache.maven.artifact.repository.metadata;
* limitations under the License.
*/
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
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;
@ -42,7 +40,7 @@ import java.util.Map;
* @version $Id$
*/
public class GroupRepositoryMetadata
implements ArtifactMetadata
extends AbstractRepositoryMetadata
{
private final String groupId;
@ -58,32 +56,6 @@ public class GroupRepositoryMetadata
return "repository metadata for group: \'" + groupId + "\'";
}
public void storeInLocalRepository( ArtifactRepository localRepository, ArtifactRepository remoteRepository )
throws ArtifactMetadataRetrievalException
{
if ( !pluginMappings.isEmpty() )
{
try
{
updateRepositoryMetadata( localRepository, remoteRepository );
}
catch ( IOException e )
{
throw new ArtifactMetadataRetrievalException( "Error updating group repository metadata", e );
}
}
}
public String getRemoteFilename()
{
return "maven-metadata.xml";
}
public String getLocalFilename( ArtifactRepository repository )
{
return "maven-metadata-" + repository.getKey() + ".xml";
}
public boolean storedInGroupDirectory()
{
return true;
@ -114,7 +86,7 @@ public class GroupRepositoryMetadata
pluginMappings.put( goalPrefix, artifactId );
}
private void updateRepositoryMetadata( ArtifactRepository localRepository, ArtifactRepository remoteRepository )
protected void updateRepositoryMetadata( ArtifactRepository localRepository, ArtifactRepository remoteRepository )
throws IOException
{
MetadataXpp3Reader mappingReader = new MetadataXpp3Reader();
@ -152,12 +124,16 @@ public class GroupRepositoryMetadata
}
}
boolean changed = false;
// If file could not be found or was not valid, start from scratch
if ( pluginMap == null )
{
pluginMap = new Metadata();
pluginMap.setGroupId( groupId );
changed = true;
}
for ( Iterator i = pluginMappings.keySet().iterator(); i.hasNext(); )
@ -187,21 +163,30 @@ public class GroupRepositoryMetadata
mappedPlugin.setPrefix( prefix );
pluginMap.addPlugin( mappedPlugin );
changed = true;
}
}
Writer writer = null;
try
if ( changed )
{
writer = new FileWriter( metadataFile );
Writer writer = null;
try
{
writer = new FileWriter( metadataFile );
MetadataXpp3Writer mappingWriter = new MetadataXpp3Writer();
MetadataXpp3Writer mappingWriter = new MetadataXpp3Writer();
mappingWriter.write( writer, pluginMap );
mappingWriter.write( writer, pluginMap );
}
finally
{
IOUtil.close( writer );
}
}
finally
else
{
IOUtil.close( writer );
metadataFile.setLastModified( System.currentTimeMillis() );
}
}

View File

@ -131,15 +131,6 @@ public class DefaultArtifactResolver
"Failed to resolve artifact, possibly due to a repository list that is not appropriately equipped for this artifact's metadata.",
artifact, remoteRepositories );
}
/* TODO: pretty sure this can be removed. No metadata on resolved artifacts
// must be after the artifact is downloaded
for ( Iterator i = artifact.getMetadataList().iterator(); i.hasNext(); )
{
ArtifactMetadata metadata = (ArtifactMetadata) i.next();
metadata.storeInLocalRepository( localRepository );
}
*/
}
catch ( ResourceDoesNotExistException e )
{

View File

@ -18,16 +18,27 @@ package org.apache.maven.artifact.transform;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.metadata.AbstractVersionArtifactMetadata;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.VersionArtifactMetadata;
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.Snapshot;
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.codehaus.plexus.logging.AbstractLogEnabled;
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.IOException;
import java.io.Reader;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@ -38,33 +49,82 @@ import java.util.Set;
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
* @todo try and refactor to remove abstract methods - not particular happy about current design
*/
public abstract class AbstractVersionTransformation
extends AbstractLogEnabled
implements ArtifactTransformation
{
protected RepositoryMetadataManager repositoryMetadataManager;
protected WagonManager wagonManager;
/**
* @todo very primitve. Probably we can cache artifacts themselves in a central location, as well as reset the flag over time in a long running process.
* @todo remove in beta-2 - used for legacy handling
*/
private static Set resolvedArtifactCache = new HashSet();
protected String resolveVersion( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
throws ArtifactMetadataRetrievalException
{
ArtifactMetadata localMetadata = resolveMetadata( artifact, localRepository, remoteRepositories );
// TODO: can we improve on this?
ArtifactMetadata metadata = new ArtifactRepositoryMetadata( artifact );
String version;
repositoryMetadataManager.resolve( metadata, remoteRepositories, localRepository );
if ( localMetadata == null )
/*
// TODO: can this go directly into the manager? At least share with DefaultPluginMappingManager
// TODO: use this, cache the output, select from that list instead of the next set
Versioning versioning = new Versioning();
for ( Iterator i = remoteRepositories.iterator(); i.hasNext(); )
{
version = artifact.getVersion();
ArtifactRepository repository = (ArtifactRepository) i.next();
mergeVersioning( versioning, loadVersioningInformation( metadata, repository, localRepository ) );
}
else
mergeVersioning( versioning, loadVersioningInformation( metadata, localRepository, localRepository ) );
String version = selectVersion( versioning, artifact.getVersion() );
*/
ArtifactRepositoryMetadata localMetadata = null;
for ( Iterator i = remoteRepositories.iterator(); i.hasNext(); )
{
VersionArtifactMetadata versionMetadata = (VersionArtifactMetadata) localMetadata;
version = versionMetadata.constructVersion();
ArtifactRepository repository = (ArtifactRepository) i.next();
localMetadata = loadVersioningInformation( metadata, repository, localRepository, artifact );
if ( localMetadata != null )
{
artifact.setRepository( repository );
// TODO: merge instead (see above)
break;
}
}
ArtifactRepositoryMetadata m = loadVersioningInformation( metadata, localRepository, localRepository,
artifact );
if ( m != null )
{
localMetadata = m;
// TODO: figure out way to avoid duplicated message
if ( getLogger().isDebugEnabled() /*&& !alreadyResolved*/ )
{
// Locally installed file is newer, don't use the resolved version
getLogger().debug( artifact.getArtifactId() + ": using locally installed snapshot" );
}
}
String version = null;
if ( localMetadata != null )
{
version = constructVersion( localMetadata );
}
if ( version == null )
{
version = resolveLegacyVersion( artifact, localRepository, remoteRepositories );
if ( version == null )
{
version = artifact.getVersion();
}
}
// TODO: also do this logging for other metadata?
@ -87,28 +147,95 @@ public abstract class AbstractVersionTransformation
return version;
}
/**
* @param artifact
* @param localRepository
* @param remoteRepositories
* @return
* @throws ArtifactMetadataRetrievalException
* @todo share with DefaultRepositoryMetadataManager
*/
private ArtifactMetadata resolveMetadata( Artifact artifact, ArtifactRepository localRepository,
List remoteRepositories )
protected Snapshot resolveLatestSnapshotVersion( Artifact artifact, ArtifactRepository localRepository,
ArtifactRepository remoteRepository )
throws ArtifactMetadataRetrievalException
{
getLogger().debug( "resolveMetaData(" + artifact.getId()+ "): repositories: " + remoteRepositories);
// TODO: can we improve on this?
ArtifactMetadata metadata = new ArtifactRepositoryMetadata( artifact );
VersionArtifactMetadata localMetadata;
try
repositoryMetadataManager.resolveAlways( metadata, localRepository, remoteRepository );
ArtifactRepositoryMetadata m = loadVersioningInformation( metadata, remoteRepository, localRepository,
artifact );
Snapshot snapshot;
if ( m == null )
{
localMetadata = readFromLocalRepository( artifact, localRepository );
snapshot = new Snapshot();
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 );
snapshot.setTimestamp( snapshotMetadata.getTimestamp() );
snapshot.setBuildNumber( snapshotMetadata.getBuildNumber() );
}
catch ( ResourceDoesNotExistException e1 )
{
// safe to ignore, use default snapshot data
getLogger().debug( "Unable to find legacy metadata - ignoring" );
}
}
catch ( IOException e )
else
{
throw new ArtifactMetadataRetrievalException( "Error reading local metadata", e );
snapshot = m.getSnapshot();
}
return snapshot;
}
protected abstract String constructVersion( ArtifactRepositoryMetadata metadata );
/* TODO
private void mergeVersioning( Versioning dest, Versioning source )
{
// TODO: currently, it is first wins. We should probably compare the versions, or check timestamping?
// This could also let us choose the newer of the locally installed version and the remotely built version
if ( dest.getLatest() == null )
{
dest.setLatest( source.getLatest() );
}
if ( dest.getRelease() == null )
{
dest.setRelease( source.getRelease() );
}
if ( dest.getSnapshot() == null )
{
dest.setSnapshot( source.getSnapshot() );
}
for ( Iterator i = source.getVersions().iterator(); i.hasNext(); )
{
String version = (String) i.next();
if ( !dest.getVersions().contains( version ) )
{
dest.getVersions().add( version );
}
}
}
*/
/**
* @todo remove in beta-2 - used for legacy handling
*/
private String resolveLegacyVersion( Artifact artifact, ArtifactRepository localRepository,
List remoteRepositories )
throws ArtifactMetadataRetrievalException
{
LegacyArtifactMetadata localMetadata = createLegacyMetadata( artifact );
File f = new File( localRepository.getBasedir(),
localRepository.pathOfLocalRepositoryMetadata( localMetadata, null ) );
if ( f.exists() )
{
try
{
localMetadata.readFromFile( f );
}
catch ( IOException e )
{
throw new ArtifactMetadataRetrievalException( "Error reading local metadata", e );
}
}
boolean alreadyResolved = alreadyResolved( artifact );
@ -122,69 +249,63 @@ public abstract class AbstractVersionTransformation
ArtifactRepositoryPolicy policy = artifact.isSnapshot() ? repository.getSnapshots()
: repository.getReleases();
if ( policy == null || !policy.isEnabled() )
if ( !policy.isEnabled() )
{
getLogger().debug( "resolveMetaData: " + artifact.getId() + ": Skipping disabled repository " +
repository.getId() + " (" + repository.getUrl() + ")" );
}
else
{
// TODO: should be able to calculate this less often
boolean checkForUpdates = policy.checkOutOfDate( localMetadata.getLastModified() );
if ( checkForUpdates )
{
checkedUpdates = true;
getLogger().info(
artifact.getId() + ": checking for updates from " + repository.getId() +
" (" + repository.getUrl() + ")" );
VersionArtifactMetadata remoteMetadata;
LegacyArtifactMetadata remoteMetadata;
try
{
remoteMetadata = retrieveFromRemoteRepository( artifact, repository, localMetadata,
policy.getChecksumPolicy() );
remoteMetadata = createLegacyMetadata( artifact );
remoteMetadata.retrieveFromRemoteRepository( repository, wagonManager,
policy.getChecksumPolicy() );
getLogger().warn( "Using old-style versioning metadata from remote repo for " + artifact );
int difference = remoteMetadata.compareTo( localMetadata );
if ( difference > 0 )
{
// remote is newer
artifact.setRepository( repository );
localMetadata = remoteMetadata;
}
}
catch ( ResourceDoesNotExistException e )
{
getLogger().debug( "resolveMetaData: Artifact version metadata for: " +
artifact.getId() + " could not be found on repository: " + repository.getId(), e );
continue;
}
int difference = remoteMetadata.compareTo( localMetadata );
if ( difference > 0 )
{
// remote is newer
artifact.setRepository( repository );
localMetadata = remoteMetadata;
getLogger().debug( "resolveMetaData: Artifact version metadata for: " + artifact.getId() +
" could not be found on repository: " + repository.getId(), e );
}
}
else
{
getLogger().debug( "resolveMetaData: " + artifact.getId() +
": NOT checking for updates from " + repository.getId() +
" (" + repository.getUrl() + ")" );
getLogger().debug( "resolveMetaData: " + artifact.getId() + ": NOT checking for updates from " +
repository.getId() + " (" + repository.getUrl() + ")" );
}
}
}
// touch the file if it was checked for updates, but don't create it if it doesn't exist remotely to avoid
// touch the file if it was checked for updates, but don't create it if it did't exist to avoid
// storing SNAPSHOT as the actual version which doesn't exist remotely.
if ( checkedUpdates && localMetadata.getLastModified().getTime() > 0 )
{
localMetadata.storeInLocalRepository( localRepository,
null ); // TODO: fix artifact repository - but this will be removed anyway
localMetadata.storeInLocalRepository( localRepository );
}
resolvedArtifactCache.add( getCacheKey( artifact ) );
}
// TODO: if the POM and JAR are inconsistent, this might mean that different version of each are used
if ( artifact.getFile().exists() && !localMetadata.newerThanFile( artifact.getFile() ) )
{
if ( getLogger().isDebugEnabled() && !alreadyResolved )
@ -194,42 +315,90 @@ public abstract class AbstractVersionTransformation
}
localMetadata = null;
}
return localMetadata;
return localMetadata != null ? localMetadata.constructVersion() : null;
}
protected VersionArtifactMetadata retrieveFromRemoteRepository( Artifact artifact,
ArtifactRepository remoteRepository,
ArtifactMetadata localMetadata,
String checksumPolicy )
throws ArtifactMetadataRetrievalException, ResourceDoesNotExistException
{
AbstractVersionArtifactMetadata metadata = createMetadata( artifact );
metadata.retrieveFromRemoteRepository( remoteRepository, wagonManager, checksumPolicy );
return metadata;
}
protected abstract AbstractVersionArtifactMetadata createMetadata( Artifact artifact );
private VersionArtifactMetadata readFromLocalRepository( Artifact artifact, ArtifactRepository localRepository )
throws IOException
{
// TODO: we could cache the results of this, perhaps inside the artifact repository?
AbstractVersionArtifactMetadata metadata = createMetadata( artifact );
metadata.readFromLocalRepository( localRepository,
null ); // TODO: fix artifact repository - but this will be removed anyway
return metadata;
}
/**
* Select the version to use based on a merged versioning element.
*
* @param versioning the versioning element
* @param defaultVersion the version to select if none is selected from versioning
* @return the version selected
*/
// protected abstract String selectVersion( Versioning versioning, String defaultVersion );
protected abstract LegacyArtifactMetadata createLegacyMetadata( Artifact artifact );
/**
* @todo remove in beta-2 - used for legacy handling
*/
private boolean alreadyResolved( Artifact artifact )
{
return resolvedArtifactCache.contains( getCacheKey( artifact ) );
}
/**
* @todo remove in beta-2 - used for legacy handling
*/
private static String getCacheKey( Artifact artifact )
{
// No type - one per POM
return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getBaseVersion();
}
private ArtifactRepositoryMetadata loadVersioningInformation( ArtifactMetadata repoMetadata,
ArtifactRepository remoteRepository,
ArtifactRepository localRepository,
Artifact artifact )
throws ArtifactMetadataRetrievalException
{
File metadataFile = new File( localRepository.getBasedir(),
localRepository.pathOfLocalRepositoryMetadata( repoMetadata, remoteRepository ) );
ArtifactRepositoryMetadata newMetadata = null;
if ( metadataFile.exists() )
{
Metadata metadata = readMetadata( metadataFile );
if ( metadata.getVersioning() != null )
{
newMetadata = new ArtifactRepositoryMetadata( artifact, metadata.getVersioning() );
}
}
return newMetadata;
}
/**
* @todo share with DefaultPluginMappingManager.
*/
private static Metadata readMetadata( File mappingFile )
throws ArtifactMetadataRetrievalException
{
Metadata result;
Reader fileReader = null;
try
{
fileReader = new FileReader( mappingFile );
MetadataXpp3Reader mappingReader = new MetadataXpp3Reader();
result = mappingReader.read( fileReader );
}
catch ( FileNotFoundException e )
{
throw new ArtifactMetadataRetrievalException( "Cannot read version information from: " + mappingFile, e );
}
catch ( IOException e )
{
throw new ArtifactMetadataRetrievalException( "Cannot read version information from: " + mappingFile, e );
}
catch ( XmlPullParserException e )
{
throw new ArtifactMetadataRetrievalException( "Cannot parse version information from: " + mappingFile, e );
}
finally
{
IOUtil.close( fileReader );
}
return result;
}
}

View File

@ -48,13 +48,14 @@ public class DefaultArtifactTransformationManager
}
}
public void transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository )
public void transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository,
ArtifactRepository localRepository )
throws ArtifactMetadataRetrievalException
{
for ( Iterator i = artifactTransformations.iterator(); i.hasNext(); )
{
ArtifactTransformation transform = (ArtifactTransformation) i.next();
transform.transformForDeployment( artifact, remoteRepository );
transform.transformForDeployment( artifact, remoteRepository, localRepository );
}
}

View File

@ -17,10 +17,13 @@ package org.apache.maven.artifact.transform;
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.AbstractVersionArtifactMetadata;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
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;
@ -47,15 +50,27 @@ public class LatestArtifactTransformation
// metadata is added at install time
}
public void transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository )
public void transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository,
ArtifactRepository localRepository )
throws ArtifactMetadataRetrievalException
{
// metadata is added at deploy time
}
protected AbstractVersionArtifactMetadata createMetadata( Artifact artifact )
protected LegacyArtifactMetadata createLegacyMetadata( Artifact artifact )
{
return new LatestArtifactMetadata( artifact );
}
protected ArtifactMetadata createMetadata( Artifact artifact, Versioning versioning )
{
LatestArtifactMetadata metadata = new LatestArtifactMetadata( artifact );
metadata.setVersion( versioning.getLatest() );
return metadata;
}
protected String constructVersion( ArtifactRepositoryMetadata metadata )
{
return metadata.getLatestVersion();
}
}

View File

@ -17,10 +17,11 @@ package org.apache.maven.artifact.transform;
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.AbstractVersionArtifactMetadata;
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;
@ -41,7 +42,7 @@ public class ReleaseArtifactTransformation
if ( RELEASE_VERSION.equals( artifact.getVersion() ) )
{
String version = resolveVersion( artifact, localRepository, remoteRepositories );
if ( version != null && !version.equals( artifact.getVersion() ) )
{
artifact.setBaseVersion( version );
@ -56,15 +57,20 @@ public class ReleaseArtifactTransformation
// metadata is added at install time
}
public void transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository )
public void transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository,
ArtifactRepository localRepository )
throws ArtifactMetadataRetrievalException
{
// metadata is added at deploy time
}
protected AbstractVersionArtifactMetadata createMetadata( Artifact artifact )
protected LegacyArtifactMetadata createLegacyMetadata( Artifact artifact )
{
return new ReleaseArtifactMetadata( artifact );
}
protected String constructVersion( ArtifactRepositoryMetadata metadata )
{
return metadata.getReleaseVersion();
}
}

View File

@ -17,12 +17,15 @@ package org.apache.maven.artifact.transform;
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.AbstractVersionArtifactMetadata;
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.wagon.ResourceDoesNotExistException;
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.codehaus.plexus.util.StringUtils;
import java.util.Date;
import java.util.List;
@ -53,36 +56,35 @@ public class SnapshotTransformation
{
if ( artifact.isSnapshot() )
{
SnapshotArtifactMetadata metadata = new SnapshotArtifactMetadata( artifact );
// 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 );
// TODO: should merge with other repository metadata sitting on the same level?
artifact.addMetadata( metadata );
}
}
public void transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository )
public void transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository,
ArtifactRepository localRepository )
throws ArtifactMetadataRetrievalException
{
if ( artifact.isSnapshot() )
{
SnapshotArtifactMetadata metadata;
Snapshot snapshot = resolveLatestSnapshotVersion( artifact, localRepository, remoteRepository );
snapshot.setTimestamp( getDeploymentTimestamp() );
snapshot.setBuildNumber( snapshot.getBuildNumber() + 1 );
try
{
metadata = (SnapshotArtifactMetadata) retrieveFromRemoteRepository( artifact, remoteRepository, null,
ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE );
}
catch ( ResourceDoesNotExistException e )
{
getLogger().debug( "Snapshot version metadata for: " + artifact.getId() +
" not found. Creating a new metadata instance.", e );
// TODO: Better way to create this - should have to construct Versioning
Versioning versioning = new Versioning();
versioning.setSnapshot( snapshot );
// ignore. We'll be creating this metadata if it doesn't exist...
metadata = (SnapshotArtifactMetadata) createMetadata( artifact );
}
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning );
metadata.setVersion( getDeploymentTimestamp(), metadata.getBuildNumber() + 1 );
artifact.setResolvedVersion( metadata.constructVersion() );
artifact.setResolvedVersion( constructVersion( metadata ) );
artifact.addMetadata( metadata );
}
@ -97,9 +99,30 @@ public class SnapshotTransformation
return deploymentTimestamp;
}
protected AbstractVersionArtifactMetadata createMetadata( Artifact artifact )
protected LegacyArtifactMetadata createLegacyMetadata( Artifact artifact )
{
return new SnapshotArtifactMetadata( artifact );
}
}
protected String constructVersion( ArtifactRepositoryMetadata metadata )
{
String version = metadata.getBaseVersion();
Snapshot snapshot = metadata.getSnapshot();
if ( snapshot != null )
{
if ( snapshot.getTimestamp() != null && snapshot.getBuildNumber() > 0 )
{
String newVersion = snapshot.getTimestamp() + "-" + snapshot.getBuildNumber();
if ( version != null )
{
version = StringUtils.replace( version, "SNAPSHOT", newVersion );
}
else
{
version = newVersion;
}
}
}
return version;
}
}

View File

@ -23,6 +23,9 @@
<requirement>
<role>org.apache.maven.artifact.manager.WagonManager</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager</role>
</requirement>
</requirements>
</component>
@ -34,6 +37,9 @@
<requirement>
<role>org.apache.maven.artifact.manager.WagonManager</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager</role>
</requirement>
</requirements>
</component>
@ -45,6 +51,9 @@
<requirement>
<role>org.apache.maven.artifact.manager.WagonManager</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager</role>
</requirement>
</requirements>
</component>

View File

@ -247,7 +247,6 @@ public abstract class AbstractArtifactComponentTestCase
{
ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
// TODO: used to be SCOPE_COMPILE, check
return artifactFactory.createBuildArtifact( groupId, artifactId, version, type );
}

View File

@ -21,7 +21,7 @@ package org.apache.maven.artifact;
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
* @todo it may be better for this to move to maven-artifact, and artifact.getFile() to throw it - perhaps it is a runtime exception?
* @todo it may be better for artifact.getFile() to throw it - perhaps it is a runtime exception?
*/
public class DependencyResolutionRequiredException
extends Exception

View File

@ -36,7 +36,7 @@ public class DefaultArtifactFactory
{
return createArtifact( groupId, artifactId, version, scope, type, null, null );
}
public Artifact createArtifactWithClassifier( String groupId, String artifactId, String version, String scope,
String type, String classifier )
{
@ -100,7 +100,6 @@ public class DefaultArtifactFactory
private Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type,
String classifier, String inheritedScope )
{
// TODO: better constructor
VersionRange versionRange = null;
if ( version != null )
{

View File

@ -17,7 +17,6 @@ package org.apache.maven.artifact.metadata;
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
/**
* Common elements of artifact metadata.
@ -30,8 +29,6 @@ public abstract class AbstractArtifactMetadata
{
protected Artifact artifact;
protected ArtifactRepository repository;
protected AbstractArtifactMetadata( Artifact artifact )
{
this.artifact = artifact;
@ -62,8 +59,4 @@ public abstract class AbstractArtifactMetadata
return artifact.getGroupId() + ":" + artifact.getArtifactId();
}
public void setRepository( ArtifactRepository repository )
{
this.repository = repository;
}
}

View File

@ -56,9 +56,6 @@ public interface ArtifactMetadata
Object getKey();
/**
* @todo delete?
*/
boolean isSnapshot();
/**

View File

@ -26,4 +26,8 @@ public interface RepositoryMetadataManager
{
void resolve( ArtifactMetadata repositoryMetadata, List repositories, ArtifactRepository localRepository )
throws ArtifactMetadataRetrievalException;
void resolveAlways( ArtifactMetadata metadata, ArtifactRepository localRepository,
ArtifactRepository remoteRepository )
throws ArtifactMetadataRetrievalException;
}

View File

@ -24,7 +24,5 @@ import org.apache.maven.artifact.Artifact;
*/
public interface ArtifactFilter
{
//TODO(JVZ): change the signature of this to filter(Artifact) where the meaning of filter is
// to exclude. I did this backward and it's confusing.
boolean include( Artifact artifact );
}

View File

@ -58,8 +58,10 @@ public interface ArtifactTransformation
*
* @param artifact Artifact to be transformed.
* @param remoteRepository the repository to deploy to
* @param localRepository the local repository
*/
void transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository )
void transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository,
ArtifactRepository localRepository )
throws ArtifactMetadataRetrievalException;
}

View File

@ -56,8 +56,10 @@ public interface ArtifactTransformationManager
*
* @param artifact Artifact to be transformed.
* @param remoteRepository the repository to deploy to
* @param localRepository the local repository the metadata is stored in
*/
void transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository )
void transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository,
ArtifactRepository localRepository )
throws ArtifactMetadataRetrievalException;
}

View File

@ -24,7 +24,6 @@ import java.net.URL;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
@ -178,7 +177,7 @@ public class Verifier
continue;
}
lines.addAll( replaceArtifacts( line ) );
lines.add( replaceArtifacts( line ) );
}
reader.close();
@ -192,7 +191,7 @@ public class Verifier
return lines;
}
private static List replaceArtifacts( String line )
private static String replaceArtifacts( String line )
{
String MARKER = "${artifact:";
int index = line.indexOf( MARKER );
@ -209,22 +208,11 @@ public class Verifier
newLine += convertArtifact( artifact );
newLine += line.substring( index + 1 );
index = newLine.lastIndexOf( "SNAPSHOT" );
if ( index >= 0 )
{
List l = new ArrayList();
l.add( newLine );
l.add( newLine.substring( 0, index ) + "SNAPSHOT.version.txt" );
return l;
}
else
{
return Collections.singletonList( newLine );
}
return newLine;
}
else
{
return Collections.singletonList( line );
return line;
}
}

View File

@ -600,7 +600,6 @@ public class DefaultLifecycleExecutor
String goal = tok.nextToken().trim();
// Not from the CLI, don't use prefix
// TODO: [MNG-608] this needs to be false
MojoDescriptor mojoDescriptor = getMojoDescriptor( goal, session, project, selectedPhase, false );
if ( mojoDescriptor.isDirectInvocationOnly() )

View File

@ -16,6 +16,7 @@ package org.apache.maven.plugin;
* limitations under the License.
*/
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata;
@ -96,7 +97,7 @@ public class DefaultPluginMappingManager
private void loadPluginMappings( String groupId, List pluginRepositories, ArtifactRepository localRepository )
throws ArtifactMetadataRetrievalException
{
GroupRepositoryMetadata metadata = new GroupRepositoryMetadata( groupId );
ArtifactMetadata metadata = new GroupRepositoryMetadata( groupId );
repositoryMetadataManager.resolve( metadata, pluginRepositories, localRepository );
@ -110,7 +111,7 @@ public class DefaultPluginMappingManager
loadRepositoryPluginMappings( metadata, localRepository, localRepository );
}
private void loadRepositoryPluginMappings( GroupRepositoryMetadata metadata, ArtifactRepository remoteRepository,
private void loadRepositoryPluginMappings( ArtifactMetadata metadata, ArtifactRepository remoteRepository,
ArtifactRepository localRepository )
throws ArtifactMetadataRetrievalException
{
@ -121,24 +122,21 @@ public class DefaultPluginMappingManager
{
Metadata pluginMap = readMetadata( metadataFile );
if ( pluginMap != null )
for ( Iterator pluginIterator = pluginMap.getPlugins().iterator(); pluginIterator.hasNext(); )
{
for ( Iterator pluginIterator = pluginMap.getPlugins().iterator(); pluginIterator.hasNext(); )
{
Plugin mapping = (Plugin) pluginIterator.next();
Plugin mapping = (Plugin) pluginIterator.next();
String prefix = mapping.getPrefix();
String prefix = mapping.getPrefix();
String artifactId = mapping.getArtifactId();
String artifactId = mapping.getArtifactId();
org.apache.maven.model.Plugin plugin = new org.apache.maven.model.Plugin();
org.apache.maven.model.Plugin plugin = new org.apache.maven.model.Plugin();
plugin.setGroupId( metadata.getGroupId() );
plugin.setGroupId( metadata.getGroupId() );
plugin.setArtifactId( artifactId );
plugin.setArtifactId( artifactId );
pluginDefinitionsByPrefix.put( prefix, plugin );
}
pluginDefinitionsByPrefix.put( prefix, plugin );
}
}
}

View File

@ -136,6 +136,7 @@ public class ArtifactDownloader
String version = dep.getVersion();
if ( snapshot )
{
// TODO: augment with maven-metadata
String filename = getSnapshotMetadataFile( destinationFile.getName(), "SNAPSHOT.version.txt" );
File file = localRepository.getMetadataFile( dep.getGroupId(), dep.getArtifactId(),
dep.getVersion(), dep.getType(), filename );
@ -173,7 +174,7 @@ public class ArtifactDownloader
}
else
{
log( "WARNING: local SNAPSHOT version not found, using default" );
log( "WARNING: local SNAPSHOT version not found, using default" );
}
}
if ( !dep.getType().equals( "pom" ) )

View File

@ -20,8 +20,9 @@ import org.apache.maven.artifact.Artifact;
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.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 org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.artifact.ProjectArtifactMetadata;
@ -130,8 +131,10 @@ public class DeployMojo
if ( updateReleaseInfo )
{
ReleaseArtifactMetadata metadata = new ReleaseArtifactMetadata( artifact );
metadata.setVersion( artifact.getVersion() );
// TODO: clean up
Versioning versioning = new Versioning();
versioning.setRelease( artifact.getVersion() );
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning );
artifact.addMetadata( metadata );
}

View File

@ -19,7 +19,8 @@ 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.metadata.ReleaseArtifactMetadata;
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;
@ -29,6 +30,7 @@ import java.util.List;
/**
* Installs project's main artifact in local repository.
*
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
* @version $Id$
* @goal install
@ -68,7 +70,7 @@ public class InstallMojo
* @parameter expression="${updateReleaseInfo}"
*/
private boolean updateReleaseInfo = false;
/**
* @parameter expression="${project.artifact}"
* @required
@ -87,7 +89,7 @@ public class InstallMojo
throws MojoExecutionException
{
boolean isPomArtifact = "pom".equals( packaging );
File pom = new File( basedir, "pom.xml" );
if ( !isPomArtifact )
{
@ -97,11 +99,13 @@ public class InstallMojo
if ( updateReleaseInfo )
{
ReleaseArtifactMetadata metadata = new ReleaseArtifactMetadata( artifact );
metadata.setVersion( artifact.getVersion() );
// TODO: clean up
Versioning versioning = new Versioning();
versioning.setRelease( artifact.getVersion() );
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning );
artifact.addMetadata( metadata );
}
try
{
if ( isPomArtifact )

View File

@ -1,8 +1,9 @@
package org.apache.maven.plugin.plugin.metadata;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.LatestArtifactMetadata;
import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.Versioning;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
@ -39,10 +40,10 @@ public class AddPluginArtifactMetadataMojo
{
Artifact projectArtifact = project.getArtifact();
LatestArtifactMetadata metadata = new LatestArtifactMetadata( projectArtifact );
metadata.setVersion( projectArtifact.getVersion() );
// TODO: clean up
Versioning versioning = new Versioning();
versioning.setLatest( projectArtifact.getVersion() );
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( projectArtifact, versioning );
projectArtifact.addMetadata( metadata );
GroupRepositoryMetadata groupMetadata = new GroupRepositoryMetadata( project.getGroupId() );