mirror of https://github.com/apache/maven.git
PR: MNG-951
timestamp the metadata so that it can be merged correctly git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@292139 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
55dc8586c7
commit
31a4d8ea41
|
@ -159,6 +159,7 @@ public abstract class AbstractRepositoryMetadata
|
|||
{
|
||||
Versioning versioning = new Versioning();
|
||||
versioning.setSnapshot( snapshot );
|
||||
versioning.updateTimestamp();
|
||||
return versioning;
|
||||
}
|
||||
|
||||
|
@ -178,16 +179,16 @@ public abstract class AbstractRepositoryMetadata
|
|||
AbstractRepositoryMetadata repoMetadata = (AbstractRepositoryMetadata) metadata;
|
||||
this.metadata.merge( repoMetadata.getMetadata() );
|
||||
}
|
||||
|
||||
|
||||
public String extendedToString()
|
||||
{
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
|
||||
|
||||
buffer.append( "\nRepository Metadata\n--------------------------" );
|
||||
buffer.append( "\nGroupId: " ).append( getGroupId() );
|
||||
buffer.append( "\nArtifactId: " ).append( getArtifactId() );
|
||||
buffer.append( "\nMetadata Type: " ).append(getClass().getName() );
|
||||
|
||||
buffer.append( "\nMetadata Type: " ).append( getClass().getName() );
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,12 +89,6 @@ public class DefaultRepositoryMetadataManager
|
|||
}
|
||||
else
|
||||
{
|
||||
// NOTE: [jc; 21-sept-2005] won't this cause inconsistencies if the metadata wasn't found?
|
||||
// this will write out an essentially empty metadata file, which will result
|
||||
// in the loop below NOT merging anything (each successive pass is still empty),
|
||||
// which means that the last repository will be set as the artifact repo, rather
|
||||
// than leaving it null. This is the root cause of MNG-900, but I'm not sure how
|
||||
// to fix it.
|
||||
metadata.storeInLocalRepository( localRepository, repository );
|
||||
}
|
||||
}
|
||||
|
@ -105,7 +99,6 @@ public class DefaultRepositoryMetadataManager
|
|||
// snapshot timestamp, or some other timestamp later encoded into the metadata.
|
||||
// TODO: this needs to be repeated here so the merging doesn't interfere with the written metadata
|
||||
// - we'd be much better having a pristine input, and an ongoing metadata for merging instead
|
||||
loadMetadata( metadata, localRepository, localRepository );
|
||||
|
||||
for ( Iterator i = remoteRepositories.iterator(); i.hasNext(); )
|
||||
{
|
||||
|
@ -119,6 +112,7 @@ public class DefaultRepositoryMetadataManager
|
|||
loadMetadata( metadata, repository, localRepository );
|
||||
}
|
||||
}
|
||||
loadMetadata( metadata, localRepository, localRepository );
|
||||
}
|
||||
|
||||
private void loadMetadata( RepositoryMetadata repoMetadata, ArtifactRepository remoteRepository,
|
||||
|
@ -134,12 +128,15 @@ public class DefaultRepositoryMetadataManager
|
|||
|
||||
if ( repoMetadata.getMetadata() != null )
|
||||
{
|
||||
if ( !metadata.merge( repoMetadata.getMetadata() ) )
|
||||
if ( repoMetadata.getMetadata().merge( metadata ) )
|
||||
{
|
||||
repoMetadata.setRepository( remoteRepository );
|
||||
}
|
||||
}
|
||||
repoMetadata.setMetadata( metadata );
|
||||
else
|
||||
{
|
||||
repoMetadata.setMetadata( metadata );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -188,7 +185,7 @@ public class DefaultRepositoryMetadataManager
|
|||
getLogger().debug( "System is offline. Cannot resolve metadata:\n" + metadata.extendedToString() + "\n\n" );
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
File file = new File( localRepository.getBasedir(),
|
||||
localRepository.pathOfLocalRepositoryMetadata( metadata, remoteRepository ) );
|
||||
|
||||
|
@ -210,7 +207,7 @@ public class DefaultRepositoryMetadataManager
|
|||
getLogger().debug( "System is offline. Cannot resolve metadata:\n" + metadata.extendedToString() + "\n\n" );
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
wagonManager.getArtifactMetadata( metadata, repository, file, checksumPolicy );
|
||||
|
@ -245,7 +242,7 @@ public class DefaultRepositoryMetadataManager
|
|||
getLogger().warn( "System is offline. Cannot deploy metadata:\n" + metadata.extendedToString() + "\n\n" );
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
getLogger().info( "Retrieving previous metadata from " + deploymentRepository.getId() );
|
||||
|
||||
File file = new File( localRepository.getBasedir(),
|
||||
|
|
|
@ -33,7 +33,8 @@ public class SnapshotArtifactRepositoryMetadata
|
|||
|
||||
public SnapshotArtifactRepositoryMetadata( Artifact artifact )
|
||||
{
|
||||
this( artifact, new Snapshot() );
|
||||
super( createMetadata( artifact, null ) );
|
||||
this.artifact = artifact;
|
||||
}
|
||||
|
||||
public SnapshotArtifactRepositoryMetadata( Artifact artifact, Snapshot snapshot )
|
||||
|
|
|
@ -109,17 +109,9 @@ public abstract class AbstractVersionTransformation
|
|||
else
|
||||
{
|
||||
// Locally installed file is newer, don't use the resolved version
|
||||
getLogger().debug( artifact.getArtifactId() + ": using locally installed snapshot");
|
||||
getLogger().debug( artifact.getArtifactId() + ": using locally installed snapshot" );
|
||||
}
|
||||
}
|
||||
|
||||
if ( version.equals( artifact.getBaseVersion() ) )
|
||||
{
|
||||
// odd: we hit here when: using legecy repo, not local, and no snapshot version meta data was availble
|
||||
// but the repository was set to one of the remote repos (and it was the wrong one).
|
||||
artifact.setRepository( null );
|
||||
}
|
||||
|
||||
return version;
|
||||
}
|
||||
|
||||
|
@ -157,12 +149,12 @@ public abstract class AbstractVersionTransformation
|
|||
if ( !wagonManager.isOnline() )
|
||||
{
|
||||
LegacyArtifactMetadata metadata = createLegacyMetadata( artifact );
|
||||
getLogger().debug( "System is offline. Cannot resolve metadata:\n" + metadata.extendedToString() + "\n\n" );
|
||||
|
||||
getLogger().debug(
|
||||
"System is offline. Cannot resolve metadata:\n" + metadata.extendedToString() + "\n\n" );
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
boolean checkedUpdates = false;
|
||||
for ( Iterator i = remoteRepositories.iterator(); i.hasNext(); )
|
||||
{
|
||||
|
@ -178,8 +170,8 @@ public abstract class AbstractVersionTransformation
|
|||
}
|
||||
else
|
||||
{
|
||||
boolean checkForUpdates = localMetadata == null
|
||||
|| policy.checkOutOfDate( localMetadata.getLastModified() );
|
||||
boolean checkForUpdates = localMetadata == null ||
|
||||
policy.checkOutOfDate( localMetadata.getLastModified() );
|
||||
|
||||
if ( checkForUpdates )
|
||||
{
|
||||
|
@ -207,7 +199,7 @@ public abstract class AbstractVersionTransformation
|
|||
catch ( ResourceDoesNotExistException e )
|
||||
{
|
||||
getLogger().debug( "Legacy metadata for: " + artifact.getId() +
|
||||
" could not be found on repository: " + repository.getId(), e );
|
||||
" could not be found on repository: " + repository.getId() );
|
||||
}
|
||||
catch ( ArtifactMetadataRetrievalException e )
|
||||
{
|
||||
|
@ -233,7 +225,8 @@ public abstract class AbstractVersionTransformation
|
|||
resolvedArtifactCache.add( getCacheKey( artifact ) );
|
||||
}
|
||||
|
||||
if ( localMetadata != null && artifact.getFile().exists() && !localMetadata.newerThanFile( artifact.getFile() ) )
|
||||
if ( localMetadata != null && artifact.getFile().exists() &&
|
||||
!localMetadata.newerThanFile( artifact.getFile() ) )
|
||||
{
|
||||
if ( getLogger().isDebugEnabled() && !alreadyResolved )
|
||||
{
|
||||
|
@ -242,7 +235,7 @@ public abstract class AbstractVersionTransformation
|
|||
}
|
||||
localMetadata = null;
|
||||
}
|
||||
|
||||
|
||||
return localMetadata != null ? localMetadata.constructVersion() : null;
|
||||
}
|
||||
|
||||
|
|
|
@ -73,6 +73,7 @@ public class ReleaseArtifactTransformation
|
|||
private ArtifactMetadata createMetadata( Artifact artifact )
|
||||
{
|
||||
Versioning versioning = new Versioning();
|
||||
versioning.updateTimestamp();
|
||||
versioning.addVersion( artifact.getVersion() );
|
||||
|
||||
if ( artifact.isRelease() )
|
||||
|
|
|
@ -59,8 +59,9 @@ public class SnapshotTransformation
|
|||
{
|
||||
if ( artifact.isSnapshot() )
|
||||
{
|
||||
RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
|
||||
metadata.getMetadata().getVersioning().getSnapshot().setLocalCopy( true );
|
||||
Snapshot snapshot = new Snapshot();
|
||||
snapshot.setLocalCopy( true );
|
||||
RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact, snapshot );
|
||||
|
||||
artifact.addMetadata( metadata );
|
||||
}
|
||||
|
@ -129,12 +130,13 @@ public class SnapshotTransformation
|
|||
if ( !wagonManager.isOnline() )
|
||||
{
|
||||
getLogger().debug( "System is offline. Cannot resolve metadata:\n" + metadata.extendedToString() + "\n\n" );
|
||||
|
||||
getLogger().info( "System is offline. Assuming build number of 0 for " + metadata.getGroupId() + ":" + metadata.getArtifactId() + " snapshot." );
|
||||
|
||||
getLogger().info( "System is offline. Assuming build number of 0 for " + metadata.getGroupId() + ":" +
|
||||
metadata.getArtifactId() + " snapshot." );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
getLogger().info( "Retrieving previous build number from " + remoteRepository.getId() );
|
||||
repositoryMetadataManager.resolveAlways( metadata, localRepository, remoteRepository );
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<artifactId>maven-plugin-parent</artifactId>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<version>2.0-beta-1</version>
|
||||
<version>2.0-beta-3-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>maven-plugin-plugin</artifactId>
|
||||
|
@ -26,6 +26,11 @@
|
|||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-project</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-repository-metadata</artifactId>
|
||||
<version>2.0-beta-3-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-plugin-tools-api</artifactId>
|
||||
|
|
|
@ -42,6 +42,7 @@ public class AddPluginArtifactMetadataMojo
|
|||
|
||||
Versioning versioning = new Versioning();
|
||||
versioning.setLatest( projectArtifact.getVersion() );
|
||||
versioning.updateTimestamp();
|
||||
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( projectArtifact, versioning );
|
||||
projectArtifact.addMetadata( metadata );
|
||||
|
||||
|
|
|
@ -53,109 +53,123 @@
|
|||
<codeSegment>
|
||||
<version>1.0.0</version>
|
||||
<code><![CDATA[
|
||||
public boolean merge( Metadata sourceMetadata )
|
||||
public boolean merge( Metadata sourceMetadata )
|
||||
{
|
||||
boolean changed = false;
|
||||
|
||||
for ( java.util.Iterator i = sourceMetadata.getPlugins().iterator(); i.hasNext(); )
|
||||
{
|
||||
Plugin plugin = (Plugin) i.next();
|
||||
boolean found = false;
|
||||
|
||||
for ( java.util.Iterator it = getPlugins().iterator(); it.hasNext() && !found; )
|
||||
{
|
||||
boolean changed = false;
|
||||
Plugin preExisting = (Plugin) it.next();
|
||||
|
||||
for ( java.util.Iterator i = sourceMetadata.getPlugins().iterator(); i.hasNext(); )
|
||||
if ( preExisting.getPrefix().equals( plugin.getPrefix() ) )
|
||||
{
|
||||
Plugin plugin = (Plugin) i.next();
|
||||
boolean found = false;
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
for ( java.util.Iterator it = getPlugins().iterator(); it.hasNext() && !found; )
|
||||
{
|
||||
Plugin preExisting = (Plugin) it.next();
|
||||
if ( !found )
|
||||
{
|
||||
Plugin mappedPlugin = new Plugin();
|
||||
|
||||
if ( preExisting.getPrefix().equals( plugin.getPrefix() ) )
|
||||
{
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
mappedPlugin.setArtifactId( plugin.getArtifactId() );
|
||||
|
||||
if ( !found )
|
||||
{
|
||||
Plugin mappedPlugin = new Plugin();
|
||||
mappedPlugin.setPrefix( plugin.getPrefix() );
|
||||
|
||||
mappedPlugin.setArtifactId( plugin.getArtifactId() );
|
||||
addPlugin( mappedPlugin );
|
||||
|
||||
mappedPlugin.setPrefix( plugin.getPrefix() );
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
addPlugin( mappedPlugin );
|
||||
Versioning versioning = sourceMetadata.getVersioning();
|
||||
if ( versioning != null )
|
||||
{
|
||||
Versioning v = getVersioning();
|
||||
if ( v == null )
|
||||
{
|
||||
v = new Versioning();
|
||||
setVersioning( v );
|
||||
changed = true;
|
||||
}
|
||||
|
||||
changed = true;
|
||||
}
|
||||
for ( Iterator i = versioning.getVersions().iterator(); i.hasNext(); )
|
||||
{
|
||||
String version = (String) i.next();
|
||||
if ( !v.getVersions().contains( version ) )
|
||||
{
|
||||
changed = true;
|
||||
v.getVersions().add( version );
|
||||
}
|
||||
}
|
||||
|
||||
if ( versioning.getLastUpdated() == null || versioning.getLastUpdated().length() == 0 )
|
||||
{
|
||||
// this should only be for historical reasons - we assume local is newer
|
||||
versioning.setLastUpdated( v.getLastUpdated() );
|
||||
}
|
||||
|
||||
if ( v.getLastUpdated() == null || v.getLastUpdated().length() == 0 ||
|
||||
versioning.getLastUpdated().compareTo( v.getLastUpdated() ) > 0 )
|
||||
{
|
||||
v.setLastUpdated( versioning.getLastUpdated() );
|
||||
|
||||
if ( versioning.getRelease() != null )
|
||||
{
|
||||
changed = true;
|
||||
v.setRelease( versioning.getRelease() );
|
||||
}
|
||||
if ( versioning.getLatest() != null )
|
||||
{
|
||||
changed = true;
|
||||
v.setLatest( versioning.getLatest() );
|
||||
}
|
||||
|
||||
Versioning versioning = sourceMetadata.getVersioning();
|
||||
if ( versioning != null )
|
||||
Snapshot s = v.getSnapshot();
|
||||
Snapshot snapshot = versioning.getSnapshot();
|
||||
if ( snapshot != null )
|
||||
{
|
||||
Versioning v = getVersioning();
|
||||
if ( v != null )
|
||||
if ( s == null )
|
||||
{
|
||||
if ( versioning.getRelease() != null )
|
||||
{
|
||||
changed = true;
|
||||
v.setRelease( versioning.getRelease() );
|
||||
}
|
||||
if ( versioning.getLatest() != null )
|
||||
{
|
||||
changed = true;
|
||||
v.setLatest( versioning.getLatest() );
|
||||
}
|
||||
for ( java.util.Iterator i = versioning.getVersions().iterator(); i.hasNext(); )
|
||||
{
|
||||
String version = (String) i.next();
|
||||
if ( !v.getVersions().contains( version ) )
|
||||
{
|
||||
changed = true;
|
||||
v.getVersions().add( version );
|
||||
}
|
||||
}
|
||||
s = new Snapshot();
|
||||
v.setSnapshot( s );
|
||||
changed = true;
|
||||
}
|
||||
|
||||
Snapshot s = v.getSnapshot();
|
||||
Snapshot snapshot = versioning.getSnapshot();
|
||||
if ( snapshot != null )
|
||||
{
|
||||
if ( s == null )
|
||||
{
|
||||
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() ) )
|
||||
{
|
||||
s.setTimestamp( snapshot.getTimestamp() );
|
||||
changed = true;
|
||||
}
|
||||
if ( snapshot.getBuildNumber() > 0 && s.getBuildNumber() != snapshot.getBuildNumber() )
|
||||
{
|
||||
s.setBuildNumber( snapshot.getBuildNumber() );
|
||||
changed = true;
|
||||
}
|
||||
if ( s.isLocalCopy() )
|
||||
{
|
||||
s.setLocalCopy( false );
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( snapshot.isLocalCopy() )
|
||||
{
|
||||
s.setLocalCopy( true );
|
||||
s.setTimestamp( null );
|
||||
s.setBuildNumber( 0 );
|
||||
changed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
setVersioning( versioning );
|
||||
changed = true;
|
||||
if ( snapshot.getTimestamp() != null && !snapshot.getTimestamp().equals( s.getTimestamp() ) )
|
||||
{
|
||||
s.setTimestamp( snapshot.getTimestamp() );
|
||||
changed = true;
|
||||
}
|
||||
if ( snapshot.getBuildNumber() > 0 && s.getBuildNumber() != snapshot.getBuildNumber() )
|
||||
{
|
||||
s.setBuildNumber( snapshot.getBuildNumber() );
|
||||
changed = true;
|
||||
}
|
||||
if ( s.isLocalCopy() )
|
||||
{
|
||||
s.setLocalCopy( false );
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
]]></code>
|
||||
</codeSegment>
|
||||
</codeSegments>
|
||||
|
@ -194,7 +208,27 @@
|
|||
<multiplicity>*</multiplicity>
|
||||
</association>
|
||||
</field>
|
||||
<field>
|
||||
<name>lastUpdated</name>
|
||||
<version>1.0.0</version>
|
||||
<type>String</type>
|
||||
<description>When the metadata was last updated</description>
|
||||
</field>
|
||||
</fields>
|
||||
<codeSegments>
|
||||
<codeSegment>
|
||||
<version>1.0.0</version>
|
||||
<code>
|
||||
public void updateTimestamp()
|
||||
{
|
||||
java.util.TimeZone timezone = java.util.TimeZone.getTimeZone( "UTC" );
|
||||
java.text.DateFormat fmt = new java.text.SimpleDateFormat( "yyyyMMddHHmmss" );
|
||||
fmt.setTimeZone( timezone );
|
||||
setLastUpdated( fmt.format( new java.util.Date() ) );
|
||||
}
|
||||
</code>
|
||||
</codeSegment>
|
||||
</codeSegments>
|
||||
</class>
|
||||
<class>
|
||||
<name>Snapshot</name>
|
||||
|
|
Loading…
Reference in New Issue