mirror of https://github.com/apache/maven.git
PR: MNG-613
push shared code into metadata manager git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@280232 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
02cc158420
commit
3a4b91b310
|
@ -175,4 +175,8 @@ public class SnapshotArtifactMetadata
|
|||
return artifact.getBaseVersion();
|
||||
}
|
||||
|
||||
public void setRepository( ArtifactRepository remoteRepository )
|
||||
{
|
||||
artifact.setRepository( remoteRepository );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ import java.io.Writer;
|
|||
* @version $Id$
|
||||
*/
|
||||
public abstract class AbstractRepositoryMetadata
|
||||
implements ArtifactMetadata
|
||||
implements RepositoryMetadata
|
||||
{
|
||||
private Metadata metadata;
|
||||
|
||||
|
@ -162,7 +162,12 @@ public abstract class AbstractRepositoryMetadata
|
|||
return versioning;
|
||||
}
|
||||
|
||||
protected Metadata getMetadata()
|
||||
public void setMetadata( Metadata metadata )
|
||||
{
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
public Metadata getMetadata()
|
||||
{
|
||||
return metadata;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ package org.apache.maven.artifact.repository.metadata;
|
|||
*/
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
|
||||
/**
|
||||
* Metadata for the artifact directory of the repository.
|
||||
|
@ -78,4 +79,8 @@ public class ArtifactRepositoryMetadata
|
|||
return false;
|
||||
}
|
||||
|
||||
public void setRepository( ArtifactRepository remoteRepository )
|
||||
{
|
||||
artifact.setRepository( remoteRepository );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,11 +21,18 @@ 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.ArtifactRepositoryPolicy;
|
||||
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
|
||||
import org.apache.maven.wagon.ResourceDoesNotExistException;
|
||||
import org.apache.maven.wagon.TransferFailedException;
|
||||
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.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
|
@ -44,24 +51,28 @@ public class DefaultRepositoryMetadataManager
|
|||
*/
|
||||
private Set cachedMetadata = new HashSet();
|
||||
|
||||
public void resolve( ArtifactMetadata metadata, List remoteRepositories, ArtifactRepository localRepository )
|
||||
public void resolve( RepositoryMetadata metadata, List remoteRepositories, ArtifactRepository localRepository )
|
||||
throws ArtifactMetadataRetrievalException
|
||||
{
|
||||
boolean alreadyResolved = alreadyResolved( metadata );
|
||||
if ( !alreadyResolved )
|
||||
// TODO: currently this is first wins, but really we should take the latest by comparing either the
|
||||
// snapshot timestamp, or some other timestamp later encoded into the metadata.
|
||||
loadMetadata( metadata, localRepository, localRepository );
|
||||
|
||||
for ( Iterator i = remoteRepositories.iterator(); i.hasNext(); )
|
||||
{
|
||||
for ( Iterator i = remoteRepositories.iterator(); i.hasNext(); )
|
||||
ArtifactRepository repository = (ArtifactRepository) i.next();
|
||||
|
||||
ArtifactRepositoryPolicy policy = metadata.isSnapshot() ? repository.getSnapshots()
|
||||
: repository.getReleases();
|
||||
|
||||
if ( !policy.isEnabled() )
|
||||
{
|
||||
ArtifactRepository repository = (ArtifactRepository) i.next();
|
||||
|
||||
ArtifactRepositoryPolicy policy = metadata.isSnapshot() ? repository.getSnapshots()
|
||||
: repository.getReleases();
|
||||
|
||||
if ( !policy.isEnabled() )
|
||||
{
|
||||
getLogger().debug( "Skipping disabled repository " + repository.getId() );
|
||||
}
|
||||
else
|
||||
getLogger().debug( "Skipping disabled repository " + repository.getId() );
|
||||
}
|
||||
else
|
||||
{
|
||||
boolean alreadyResolved = alreadyResolved( metadata );
|
||||
if ( !alreadyResolved )
|
||||
{
|
||||
File file = new File( localRepository.getBasedir(),
|
||||
localRepository.pathOfLocalRepositoryMetadata( metadata, repository ) );
|
||||
|
@ -84,14 +95,70 @@ public class DefaultRepositoryMetadataManager
|
|||
{
|
||||
metadata.storeInLocalRepository( localRepository, repository );
|
||||
}
|
||||
cachedMetadata.add( metadata.getKey() );
|
||||
}
|
||||
loadMetadata( metadata, repository, localRepository );
|
||||
}
|
||||
|
||||
cachedMetadata.add( metadata.getKey() );
|
||||
}
|
||||
}
|
||||
|
||||
public void resolveAlways( ArtifactMetadata metadata, ArtifactRepository localRepository,
|
||||
private void loadMetadata( RepositoryMetadata repoMetadata, ArtifactRepository remoteRepository,
|
||||
ArtifactRepository localRepository )
|
||||
throws ArtifactMetadataRetrievalException
|
||||
{
|
||||
File metadataFile = new File( localRepository.getBasedir(),
|
||||
localRepository.pathOfLocalRepositoryMetadata( repoMetadata, remoteRepository ) );
|
||||
|
||||
if ( metadataFile.exists() )
|
||||
{
|
||||
Metadata metadata = readMetadata( metadataFile );
|
||||
repoMetadata.setRepository( remoteRepository );
|
||||
|
||||
if ( repoMetadata.getMetadata() != null )
|
||||
{
|
||||
metadata.merge( repoMetadata.getMetadata() );
|
||||
}
|
||||
repoMetadata.setMetadata( metadata );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo share with DefaultPluginMappingManager.
|
||||
*/
|
||||
protected 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;
|
||||
}
|
||||
|
||||
public void resolveAlways( RepositoryMetadata metadata, ArtifactRepository localRepository,
|
||||
ArtifactRepository remoteRepository )
|
||||
throws ArtifactMetadataRetrievalException
|
||||
{
|
||||
|
@ -99,6 +166,12 @@ public class DefaultRepositoryMetadataManager
|
|||
localRepository.pathOfLocalRepositoryMetadata( metadata, remoteRepository ) );
|
||||
|
||||
resolveAlways( metadata, remoteRepository, file, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN );
|
||||
|
||||
if ( file.exists() )
|
||||
{
|
||||
Metadata prevMetadata = readMetadata( file );
|
||||
metadata.setMetadata( prevMetadata );
|
||||
}
|
||||
}
|
||||
|
||||
private void resolveAlways( ArtifactMetadata metadata, ArtifactRepository repository, File file,
|
||||
|
@ -135,15 +208,17 @@ public class DefaultRepositoryMetadataManager
|
|||
throws ArtifactMetadataRetrievalException
|
||||
{
|
||||
getLogger().info( "Retrieving previous metadata from " + deploymentRepository.getId() );
|
||||
resolveAlways( metadata, localRepository, deploymentRepository );
|
||||
|
||||
File file = new File( localRepository.getBasedir(),
|
||||
localRepository.pathOfLocalRepositoryMetadata( metadata, deploymentRepository ) );
|
||||
|
||||
resolveAlways( metadata, deploymentRepository, file, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN );
|
||||
|
||||
metadata.storeInLocalRepository( localRepository, deploymentRepository );
|
||||
|
||||
try
|
||||
{
|
||||
File f = new File( localRepository.getBasedir(),
|
||||
localRepository.pathOfLocalRepositoryMetadata( metadata, deploymentRepository ) );
|
||||
wagonManager.putArtifactMetadata( f, metadata, deploymentRepository );
|
||||
wagonManager.putArtifactMetadata( file, metadata, deploymentRepository );
|
||||
}
|
||||
catch ( TransferFailedException e )
|
||||
{
|
||||
|
|
|
@ -16,6 +16,8 @@ package org.apache.maven.artifact.repository.metadata;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -93,4 +95,8 @@ public class GroupRepositoryMetadata
|
|||
return false;
|
||||
}
|
||||
|
||||
public void setRepository( ArtifactRepository remoteRepository )
|
||||
{
|
||||
// intentionally blank
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
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.repository.ArtifactRepository;
|
||||
|
||||
/**
|
||||
* Describes repository directory metadata.
|
||||
*
|
||||
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
* @version $Id$
|
||||
* @todo not happy about the store method - they use "this"
|
||||
*/
|
||||
public interface RepositoryMetadata
|
||||
extends ArtifactMetadata
|
||||
{
|
||||
/**
|
||||
* Set the repository the metadata was located in.
|
||||
*
|
||||
* @param remoteRepository the repository
|
||||
*/
|
||||
void setRepository( ArtifactRepository remoteRepository );
|
||||
|
||||
/**
|
||||
* Get the repository metadata associated with this marker.
|
||||
*
|
||||
* @return the metadata, or <code>null</code> if none loaded
|
||||
*/
|
||||
Metadata getMetadata();
|
||||
|
||||
/**
|
||||
* Set the metadata contents.
|
||||
*
|
||||
* @param metadata the metadata
|
||||
*/
|
||||
void setMetadata( Metadata metadata );
|
||||
}
|
|
@ -24,10 +24,10 @@ import java.util.List;
|
|||
|
||||
public interface RepositoryMetadataManager
|
||||
{
|
||||
void resolve( ArtifactMetadata repositoryMetadata, List repositories, ArtifactRepository localRepository )
|
||||
void resolve( RepositoryMetadata repositoryMetadata, List repositories, ArtifactRepository localRepository )
|
||||
throws ArtifactMetadataRetrievalException;
|
||||
|
||||
void resolveAlways( ArtifactMetadata metadata, ArtifactRepository localRepository,
|
||||
void resolveAlways( RepositoryMetadata metadata, ArtifactRepository localRepository,
|
||||
ArtifactRepository remoteRepository )
|
||||
throws ArtifactMetadataRetrievalException;
|
||||
|
|
@ -17,6 +17,7 @@ package org.apache.maven.artifact.repository.metadata;
|
|||
*/
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
|
||||
/**
|
||||
* Metadata for the artifact version directory of the repository.
|
||||
|
@ -75,4 +76,9 @@ public class SnapshotArtifactRepositoryMetadata
|
|||
{
|
||||
return artifact.isSnapshot();
|
||||
}
|
||||
|
||||
public void setRepository( ArtifactRepository remoteRepository )
|
||||
{
|
||||
artifact.setRepository( remoteRepository );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,27 +18,21 @@ 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.ArtifactMetadata;
|
||||
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
||||
import org.apache.maven.artifact.metadata.LegacyArtifactMetadata;
|
||||
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.RepositoryMetadata;
|
||||
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;
|
||||
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;
|
||||
|
@ -68,7 +62,7 @@ public abstract class AbstractVersionTransformation
|
|||
throws ArtifactMetadataRetrievalException
|
||||
{
|
||||
// TODO: can we improve on this?
|
||||
ArtifactMetadata metadata;
|
||||
RepositoryMetadata metadata;
|
||||
if ( !artifact.isSnapshot() || Artifact.LATEST_VERSION.equals( artifact.getBaseVersion() ) )
|
||||
{
|
||||
metadata = new ArtifactRepositoryMetadata( artifact );
|
||||
|
@ -80,49 +74,11 @@ public abstract class AbstractVersionTransformation
|
|||
|
||||
repositoryMetadataManager.resolve( metadata, remoteRepositories, localRepository );
|
||||
|
||||
/*
|
||||
// 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(); )
|
||||
{
|
||||
ArtifactRepository repository = (ArtifactRepository) i.next();
|
||||
|
||||
mergeVersioning( versioning, loadVersioningInformation( metadata, repository, localRepository ) );
|
||||
}
|
||||
mergeVersioning( versioning, loadVersioningInformation( metadata, localRepository, localRepository ) );
|
||||
|
||||
String version = selectVersion( versioning, artifact.getVersion() );
|
||||
*/
|
||||
Versioning versioning = null;
|
||||
for ( Iterator i = remoteRepositories.iterator(); i.hasNext(); )
|
||||
{
|
||||
ArtifactRepository repository = (ArtifactRepository) i.next();
|
||||
|
||||
versioning = loadVersioningInformation( metadata, repository, localRepository, artifact );
|
||||
if ( versioning != null )
|
||||
{
|
||||
artifact.setRepository( repository );
|
||||
// TODO: merge instead (see above)
|
||||
break;
|
||||
}
|
||||
}
|
||||
Versioning v = loadVersioningInformation( metadata, localRepository, localRepository, artifact );
|
||||
if ( v != null )
|
||||
{
|
||||
versioning = v;
|
||||
// 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" );
|
||||
}
|
||||
}
|
||||
|
||||
Metadata repoMetadata = metadata.getMetadata();
|
||||
String version = null;
|
||||
if ( versioning != null )
|
||||
if ( repoMetadata != null && repoMetadata.getVersioning() != null )
|
||||
{
|
||||
version = constructVersion( versioning, artifact.getBaseVersion() );
|
||||
version = constructVersion( repoMetadata.getVersioning(), artifact.getBaseVersion() );
|
||||
}
|
||||
|
||||
if ( version == null )
|
||||
|
@ -135,9 +91,10 @@ public abstract class AbstractVersionTransformation
|
|||
}
|
||||
|
||||
// TODO: also do this logging for other metadata?
|
||||
// TODO: figure out way to avoid duplicated message
|
||||
if ( getLogger().isDebugEnabled() )
|
||||
{
|
||||
if ( version != null && !version.equals( artifact.getBaseVersion() ) )
|
||||
if ( !version.equals( artifact.getBaseVersion() ) )
|
||||
{
|
||||
String message = artifact.getArtifactId() + ": resolved to version " + version;
|
||||
if ( artifact.getRepository() != null )
|
||||
|
@ -150,40 +107,17 @@ public abstract class AbstractVersionTransformation
|
|||
}
|
||||
getLogger().debug( message );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Locally installed file is newer, don't use the resolved version
|
||||
getLogger().debug( artifact.getArtifactId() + ": using locally installed snapshot" );
|
||||
}
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
protected abstract String constructVersion( Versioning versioning, String baseVersion );
|
||||
|
||||
/* 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
|
||||
*/
|
||||
|
@ -312,56 +246,4 @@ public abstract class AbstractVersionTransformation
|
|||
// No type - one per POM
|
||||
return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getBaseVersion();
|
||||
}
|
||||
|
||||
protected Versioning loadVersioningInformation( ArtifactMetadata repoMetadata, ArtifactRepository remoteRepository,
|
||||
ArtifactRepository localRepository, Artifact artifact )
|
||||
throws ArtifactMetadataRetrievalException
|
||||
{
|
||||
File metadataFile = new File( localRepository.getBasedir(),
|
||||
localRepository.pathOfLocalRepositoryMetadata( repoMetadata, remoteRepository ) );
|
||||
|
||||
Versioning versioning = null;
|
||||
if ( metadataFile.exists() )
|
||||
{
|
||||
Metadata metadata = readMetadata( metadataFile );
|
||||
versioning = metadata.getVersioning();
|
||||
}
|
||||
return versioning;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ public class ReleaseArtifactTransformation
|
|||
return new ReleaseArtifactMetadata( artifact );
|
||||
}
|
||||
|
||||
protected String constructVersion( Versioning versioning, String bS )
|
||||
protected String constructVersion( Versioning versioning, String baseVersion )
|
||||
{
|
||||
return versioning.getRelease();
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@ 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.Metadata;
|
||||
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
|
||||
import org.apache.maven.artifact.repository.metadata.Snapshot;
|
||||
import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
|
||||
import org.apache.maven.artifact.repository.metadata.Versioning;
|
||||
|
@ -58,10 +60,9 @@ public class SnapshotTransformation
|
|||
{
|
||||
if ( artifact.isSnapshot() )
|
||||
{
|
||||
// TODO: Better way to create this - should have to construct Versioning
|
||||
ArtifactMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
|
||||
RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
|
||||
metadata.getMetadata().getVersioning().getSnapshot().setLocalCopy( true );
|
||||
|
||||
// TODO: should merge with other repository metadata sitting on the same level?
|
||||
artifact.addMetadata( metadata );
|
||||
}
|
||||
}
|
||||
|
@ -109,7 +110,11 @@ public class SnapshotTransformation
|
|||
Snapshot snapshot = versioning.getSnapshot();
|
||||
if ( snapshot != null )
|
||||
{
|
||||
if ( snapshot.getTimestamp() != null && snapshot.getBuildNumber() > 0 )
|
||||
if ( snapshot.isLocalCopy() )
|
||||
{
|
||||
version = baseVersion;
|
||||
}
|
||||
else if ( snapshot.getTimestamp() != null && snapshot.getBuildNumber() > 0 )
|
||||
{
|
||||
String newVersion = snapshot.getTimestamp() + "-" + snapshot.getBuildNumber();
|
||||
version = StringUtils.replace( baseVersion, "SNAPSHOT", newVersion );
|
||||
|
@ -123,14 +128,21 @@ public class SnapshotTransformation
|
|||
throws ArtifactMetadataRetrievalException
|
||||
{
|
||||
// TODO: can we improve on this?
|
||||
ArtifactMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
|
||||
RepositoryMetadata 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 )
|
||||
Metadata repoMetadata = metadata.getMetadata();
|
||||
if ( repoMetadata != null )
|
||||
{
|
||||
if ( repoMetadata.getVersioning() != null && repoMetadata.getVersioning().getSnapshot() != null )
|
||||
{
|
||||
buildNumber = repoMetadata.getVersioning().getSnapshot().getBuildNumber();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -147,10 +159,6 @@ public class SnapshotTransformation
|
|||
getLogger().debug( "Unable to find legacy metadata - ignoring" );
|
||||
}
|
||||
}
|
||||
else if ( versioning.getSnapshot() != null )
|
||||
{
|
||||
buildNumber = versioning.getSnapshot().getBuildNumber();
|
||||
}
|
||||
return buildNumber;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,16 @@
|
|||
<implementation>org.apache.maven.artifact.manager.DefaultWagonManager</implementation>
|
||||
</component>
|
||||
|
||||
<component>
|
||||
<role>org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager</role>
|
||||
<implementation>org.apache.maven.artifact.repository.metadata.DefaultRepositoryMetadataManager</implementation>
|
||||
<requirements>
|
||||
<requirement>
|
||||
<role>org.apache.maven.artifact.manager.WagonManager</role>
|
||||
</requirement>
|
||||
</requirements>
|
||||
</component>
|
||||
|
||||
<!--
|
||||
|
|
||||
| Transformations
|
||||
|
@ -152,4 +162,10 @@
|
|||
</requirement>
|
||||
</requirements>
|
||||
</component>
|
||||
|
||||
<component>
|
||||
<role>org.apache.maven.artifact.repository.ArtifactRepositoryFactory</role>
|
||||
<implementation>org.apache.maven.artifact.repository.DefaultArtifactRepositoryFactory</implementation>
|
||||
</component>
|
||||
|
||||
</component-set>
|
||||
|
|
|
@ -25,19 +25,9 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
|
|||
* @version $Id$
|
||||
* @todo merge with artifactmetadatasource
|
||||
* @todo retrieval exception not appropriate for store
|
||||
* @todo not happy about the store/retrieve methods - they use "this"
|
||||
*/
|
||||
public interface ArtifactMetadata
|
||||
{
|
||||
/**
|
||||
* Store the metadata in the local repository.
|
||||
*
|
||||
* @param localRepository the local repository
|
||||
* @param remoteRepository the remote repository it came from
|
||||
*/
|
||||
void storeInLocalRepository( ArtifactRepository localRepository, ArtifactRepository remoteRepository )
|
||||
throws ArtifactMetadataRetrievalException;
|
||||
|
||||
/**
|
||||
* Whether this metadata should be stored alongside the artifact.
|
||||
*/
|
||||
|
@ -77,6 +67,17 @@ public interface ArtifactMetadata
|
|||
* Merge a new metadata set into this piece of metadata.
|
||||
*
|
||||
* @param metadata the new metadata
|
||||
* @todo this should only be needed on the repository metadata
|
||||
*/
|
||||
void merge( ArtifactMetadata metadata );
|
||||
|
||||
/**
|
||||
* Store the metadata in the local repository.
|
||||
*
|
||||
* @param localRepository the local repository
|
||||
* @param remoteRepository the remote repository it came from
|
||||
* @todo this should only be needed on the repository metadata
|
||||
*/
|
||||
void storeInLocalRepository( ArtifactRepository localRepository, ArtifactRepository remoteRepository )
|
||||
throws ArtifactMetadataRetrievalException;
|
||||
}
|
||||
|
|
|
@ -106,26 +106,10 @@
|
|||
</requirement>
|
||||
</requirements>
|
||||
</component>
|
||||
|
||||
<component>
|
||||
<role>org.apache.maven.artifact.repository.ArtifactRepositoryFactory</role>
|
||||
<implementation>org.apache.maven.artifact.repository.DefaultArtifactRepositoryFactory</implementation>
|
||||
</component>
|
||||
|
||||
<component>
|
||||
<role>org.apache.maven.artifact.resolver.ArtifactCollector</role>
|
||||
<implementation>org.apache.maven.artifact.resolver.DefaultArtifactCollector</implementation>
|
||||
</component>
|
||||
|
||||
<component>
|
||||
<role>org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager</role>
|
||||
<role-hint>default</role-hint>
|
||||
<implementation>org.apache.maven.artifact.repository.metadata.DefaultRepositoryMetadataManager</implementation>
|
||||
<requirements>
|
||||
<requirement>
|
||||
<role>org.apache.maven.artifact.manager.WagonManager</role>
|
||||
</requirement>
|
||||
</requirements>
|
||||
</component>
|
||||
</components>
|
||||
</component-set>
|
||||
|
|
|
@ -16,23 +16,15 @@ 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;
|
||||
import org.apache.maven.artifact.repository.metadata.Metadata;
|
||||
import org.apache.maven.artifact.repository.metadata.Plugin;
|
||||
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
|
||||
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager;
|
||||
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
|
||||
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.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
@ -97,32 +89,14 @@ public class DefaultPluginMappingManager
|
|||
private void loadPluginMappings( String groupId, List pluginRepositories, ArtifactRepository localRepository )
|
||||
throws ArtifactMetadataRetrievalException
|
||||
{
|
||||
ArtifactMetadata metadata = new GroupRepositoryMetadata( groupId );
|
||||
RepositoryMetadata metadata = new GroupRepositoryMetadata( groupId );
|
||||
|
||||
repositoryMetadataManager.resolve( metadata, pluginRepositories, localRepository );
|
||||
|
||||
// TODO: can this go directly into the manager?
|
||||
for ( Iterator i = pluginRepositories.iterator(); i.hasNext(); )
|
||||
Metadata repoMetadata = metadata.getMetadata();
|
||||
if ( repoMetadata != null )
|
||||
{
|
||||
ArtifactRepository repository = (ArtifactRepository) i.next();
|
||||
|
||||
loadRepositoryPluginMappings( metadata, repository, localRepository );
|
||||
}
|
||||
loadRepositoryPluginMappings( metadata, localRepository, localRepository );
|
||||
}
|
||||
|
||||
private void loadRepositoryPluginMappings( ArtifactMetadata metadata, ArtifactRepository remoteRepository,
|
||||
ArtifactRepository localRepository )
|
||||
throws ArtifactMetadataRetrievalException
|
||||
{
|
||||
File metadataFile = new File( localRepository.getBasedir(),
|
||||
localRepository.pathOfLocalRepositoryMetadata( metadata, remoteRepository ) );
|
||||
|
||||
if ( metadataFile.exists() )
|
||||
{
|
||||
Metadata pluginMap = readMetadata( metadataFile );
|
||||
|
||||
for ( Iterator pluginIterator = pluginMap.getPlugins().iterator(); pluginIterator.hasNext(); )
|
||||
for ( Iterator pluginIterator = repoMetadata.getPlugins().iterator(); pluginIterator.hasNext(); )
|
||||
{
|
||||
Plugin mapping = (Plugin) pluginIterator.next();
|
||||
|
||||
|
@ -140,37 +114,4 @@ public class 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 plugin mappings from: " + mappingFile, e );
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
throw new ArtifactMetadataRetrievalException( "Cannot read plugin mappings from: " + mappingFile, e );
|
||||
}
|
||||
catch ( XmlPullParserException e )
|
||||
{
|
||||
throw new ArtifactMetadataRetrievalException( "Cannot parse plugin mappings from: " + mappingFile, e );
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close( fileReader );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,8 +25,8 @@ import org.apache.maven.artifact.metadata.ResolutionGroup;
|
|||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
|
||||
import org.apache.maven.artifact.repository.metadata.Metadata;
|
||||
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
|
||||
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager;
|
||||
import org.apache.maven.artifact.repository.metadata.Versioning;
|
||||
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
|
||||
import org.apache.maven.artifact.resolver.filter.AndArtifactFilter;
|
||||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
||||
|
@ -276,40 +276,16 @@ public class MavenMetadataSource
|
|||
List remoteRepositories )
|
||||
throws ArtifactMetadataRetrievalException
|
||||
{
|
||||
ArtifactMetadata metadata = new ArtifactRepositoryMetadata( artifact );
|
||||
RepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact );
|
||||
repositoryMetadataManager.resolve( metadata, remoteRepositories, localRepository );
|
||||
|
||||
// TODO: this has been ripped from AbstractVersionTransformation - stop duplication
|
||||
Versioning versioning = null;
|
||||
for ( Iterator i = remoteRepositories.iterator(); i.hasNext(); )
|
||||
{
|
||||
ArtifactRepository repository = (ArtifactRepository) i.next();
|
||||
|
||||
versioning = loadVersioningInformation( metadata, repository, localRepository, artifact );
|
||||
if ( versioning != null )
|
||||
{
|
||||
artifact.setRepository( repository );
|
||||
// TODO: merge instead (see above)
|
||||
break;
|
||||
}
|
||||
}
|
||||
Versioning v = loadVersioningInformation( metadata, localRepository, localRepository, artifact );
|
||||
if ( v != null )
|
||||
{
|
||||
versioning = v;
|
||||
// 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" );
|
||||
}
|
||||
}
|
||||
|
||||
List versions;
|
||||
if ( versioning != null )
|
||||
Metadata repoMetadata = metadata.getMetadata();
|
||||
if ( repoMetadata != null )
|
||||
{
|
||||
versions = new ArrayList( versioning.getVersions().size() );
|
||||
for ( Iterator i = versioning.getVersions().iterator(); i.hasNext(); )
|
||||
List metadataVersions = repoMetadata.getVersioning().getVersions();
|
||||
versions = new ArrayList( metadataVersions.size() );
|
||||
for ( Iterator i = metadataVersions.iterator(); i.hasNext(); )
|
||||
{
|
||||
String version = (String) i.next();
|
||||
versions.add( new DefaultArtifactVersion( version ) );
|
||||
|
@ -323,20 +299,19 @@ public class MavenMetadataSource
|
|||
return versions;
|
||||
}
|
||||
|
||||
private Versioning loadVersioningInformation( ArtifactMetadata repoMetadata, ArtifactRepository remoteRepository,
|
||||
ArtifactRepository localRepository, Artifact artifact )
|
||||
private Metadata loadMetadata( ArtifactMetadata repoMetadata, ArtifactRepository remoteRepository,
|
||||
ArtifactRepository localRepository )
|
||||
throws ArtifactMetadataRetrievalException
|
||||
{
|
||||
File metadataFile = new File( localRepository.getBasedir(),
|
||||
localRepository.pathOfLocalRepositoryMetadata( repoMetadata, remoteRepository ) );
|
||||
|
||||
Versioning versioning = null;
|
||||
Metadata metadata = null;
|
||||
if ( metadataFile.exists() )
|
||||
{
|
||||
Metadata metadata = readMetadata( metadataFile );
|
||||
versioning = metadata.getVersioning();
|
||||
metadata = readMetadata( metadataFile );
|
||||
}
|
||||
return versioning;
|
||||
return metadata;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -121,6 +121,13 @@
|
|||
v.setSnapshot( snapshot );
|
||||
changed = true;
|
||||
}
|
||||
else if ( snapshot.isLocalCopy() )
|
||||
{
|
||||
s.setLocalCopy( true );
|
||||
s.setTimestamp( null );
|
||||
s.setBuildNumber( 0 );
|
||||
changed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( snapshot.getTimestamp() != null && !snapshot.getTimestamp().equals( s.getTimestamp() ) )
|
||||
|
@ -128,7 +135,7 @@
|
|||
s.setTimestamp( snapshot.getTimestamp() );
|
||||
changed = true;
|
||||
}
|
||||
if ( s.getBuildNumber() != snapshot.getBuildNumber() )
|
||||
if ( snapshot.getBuildNumber() > 0 && s.getBuildNumber() != snapshot.getBuildNumber() )
|
||||
{
|
||||
s.setBuildNumber( snapshot.getBuildNumber() );
|
||||
changed = true;
|
||||
|
@ -201,6 +208,13 @@
|
|||
<description>The incremental build number</description>
|
||||
<type>int</type>
|
||||
</field>
|
||||
<field>
|
||||
<name>localCopy</name>
|
||||
<version>1.0.0</version>
|
||||
<description>Whether to use a local copy instead (with filename that includes the base version)</description>
|
||||
<type>boolean</type>
|
||||
<defaultValue>false</defaultValue>
|
||||
</field>
|
||||
</fields>
|
||||
</class>
|
||||
<class>
|
||||
|
|
Loading…
Reference in New Issue