[MNG-6754] Set the same timestamp in multi module builds

Reuse MavenExecutionRequest#getStartTime() throughout for snapshot versions,
last updated fields in metadata consistently for local and remote repositories
for the entire reactor and its modules.

This closes #381
This commit is contained in:
Michael Osipov 2020-10-11 20:27:49 +02:00
parent 207237223a
commit 72688805c4
14 changed files with 60 additions and 35 deletions

View File

@ -123,6 +123,7 @@ public class DefaultArtifactInstaller
} }
Versioning versioning = new Versioning(); Versioning versioning = new Versioning();
// TODO Should this be changed for MNG-6754 too?
versioning.updateTimestamp(); versioning.updateTimestamp();
versioning.addVersion( artifact.getBaseVersion() ); versioning.addVersion( artifact.getBaseVersion() );
if ( artifact.isRelease() ) if ( artifact.isRelease() )

View File

@ -82,6 +82,7 @@ public class ReleaseArtifactTransformation
private ArtifactMetadata createMetadata( Artifact artifact ) private ArtifactMetadata createMetadata( Artifact artifact )
{ {
Versioning versioning = new Versioning(); Versioning versioning = new Versioning();
// TODO Should this be changed for MNG-6754 too?
versioning.updateTimestamp(); versioning.updateTimestamp();
versioning.addVersion( artifact.getVersion() ); versioning.addVersion( artifact.getVersion() );

View File

@ -91,6 +91,7 @@ public class SnapshotTransformation
{ {
Snapshot snapshot = new Snapshot(); Snapshot snapshot = new Snapshot();
// TODO Should this be changed for MNG-6754 too?
snapshot.setTimestamp( getDeploymentTimestamp() ); snapshot.setTimestamp( getDeploymentTimestamp() );
// we update the build number anyway so that it doesn't get lost. It requires the timestamp to take effect // we update the build number anyway so that it doesn't get lost. It requires the timestamp to take effect

View File

@ -164,7 +164,6 @@ public abstract class AbstractRepositoryMetadata
{ {
Versioning versioning = new Versioning(); Versioning versioning = new Versioning();
versioning.setSnapshot( snapshot ); versioning.setSnapshot( snapshot );
versioning.updateTimestamp();
return versioning; return versioning;
} }

View File

@ -113,6 +113,7 @@ public class DefaultRepositorySystemSessionFactory
Map<Object, Object> configProps = new LinkedHashMap<>(); Map<Object, Object> configProps = new LinkedHashMap<>();
configProps.put( ConfigurationProperties.USER_AGENT, getUserAgent() ); configProps.put( ConfigurationProperties.USER_AGENT, getUserAgent() );
configProps.put( ConfigurationProperties.INTERACTIVE, request.isInteractiveMode() ); configProps.put( ConfigurationProperties.INTERACTIVE, request.isInteractiveMode() );
configProps.put( "maven.startTime", request.getStartTime() );
configProps.putAll( request.getSystemProperties() ); configProps.putAll( request.getSystemProperties() );
configProps.putAll( request.getUserProperties() ); configProps.putAll( request.getUserProperties() );

View File

@ -22,6 +22,7 @@ package org.apache.maven.repository.internal;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Date;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
@ -42,15 +43,15 @@ final class LocalSnapshotMetadata
private final boolean legacyFormat; private final boolean legacyFormat;
LocalSnapshotMetadata( Artifact artifact, boolean legacyFormat ) LocalSnapshotMetadata( Artifact artifact, boolean legacyFormat, Date timestamp )
{ {
super( createMetadata( artifact, legacyFormat ), null ); super( createMetadata( artifact, legacyFormat ), null, timestamp );
this.legacyFormat = legacyFormat; this.legacyFormat = legacyFormat;
} }
LocalSnapshotMetadata( Metadata metadata, File file, boolean legacyFormat ) LocalSnapshotMetadata( Metadata metadata, File file, boolean legacyFormat, Date timestamp )
{ {
super( metadata, file ); super( metadata, file, timestamp );
this.legacyFormat = legacyFormat; this.legacyFormat = legacyFormat;
} }
@ -82,7 +83,7 @@ final class LocalSnapshotMetadata
public MavenMetadata setFile( File file ) public MavenMetadata setFile( File file )
{ {
return new LocalSnapshotMetadata( metadata, file, legacyFormat ); return new LocalSnapshotMetadata( metadata, file, legacyFormat, timestamp );
} }
public Object getKey() public Object getKey()
@ -98,7 +99,7 @@ final class LocalSnapshotMetadata
@Override @Override
protected void merge( Metadata recessive ) protected void merge( Metadata recessive )
{ {
metadata.getVersioning().updateTimestamp(); metadata.getVersioning().setLastUpdatedTimestamp( timestamp );
if ( !legacyFormat ) if ( !legacyFormat )
{ {

View File

@ -21,6 +21,7 @@ package org.apache.maven.repository.internal;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Date;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
@ -42,10 +43,14 @@ class LocalSnapshotMetadataGenerator
private final boolean legacyFormat; private final boolean legacyFormat;
private final Date timestamp;
LocalSnapshotMetadataGenerator( RepositorySystemSession session, InstallRequest request ) LocalSnapshotMetadataGenerator( RepositorySystemSession session, InstallRequest request )
{ {
legacyFormat = ConfigUtils.getBoolean( session.getConfigProperties(), false, "maven.metadata.legacy" ); legacyFormat = ConfigUtils.getBoolean( session.getConfigProperties(), false, "maven.metadata.legacy" );
timestamp = (Date) ConfigUtils.getObject( session, new Date(), "maven.startTime" );
snapshots = new LinkedHashMap<>(); snapshots = new LinkedHashMap<>();
} }
@ -59,7 +64,7 @@ class LocalSnapshotMetadataGenerator
LocalSnapshotMetadata snapshotMetadata = snapshots.get( key ); LocalSnapshotMetadata snapshotMetadata = snapshots.get( key );
if ( snapshotMetadata == null ) if ( snapshotMetadata == null )
{ {
snapshotMetadata = new LocalSnapshotMetadata( artifact, legacyFormat ); snapshotMetadata = new LocalSnapshotMetadata( artifact, legacyFormat, timestamp );
snapshots.put( key, snapshotMetadata ); snapshots.put( key, snapshotMetadata );
} }
snapshotMetadata.bind( artifact ); snapshotMetadata.bind( artifact );

View File

@ -34,6 +34,7 @@ import java.io.IOException;
import java.io.Reader; import java.io.Reader;
import java.io.Writer; import java.io.Writer;
import java.util.Collections; import java.util.Collections;
import java.util.Date;
import java.util.Map; import java.util.Map;
/** /**
@ -46,16 +47,19 @@ abstract class MavenMetadata
static final String MAVEN_METADATA_XML = "maven-metadata.xml"; static final String MAVEN_METADATA_XML = "maven-metadata.xml";
protected Metadata metadata;
private final File file; private final File file;
protected Metadata metadata; protected final Date timestamp;
private boolean merged; private boolean merged;
protected MavenMetadata( Metadata metadata, File file ) protected MavenMetadata( Metadata metadata, File file, Date timestamp )
{ {
this.metadata = metadata; this.metadata = metadata;
this.file = file; this.file = file;
this.timestamp = timestamp;
} }
public String getType() public String getType()

View File

@ -22,6 +22,7 @@ package org.apache.maven.repository.internal;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Date;
import org.apache.maven.artifact.repository.metadata.Metadata; import org.apache.maven.artifact.repository.metadata.Metadata;
import org.eclipse.aether.artifact.Artifact; import org.eclipse.aether.artifact.Artifact;
@ -38,9 +39,9 @@ abstract class MavenSnapshotMetadata
protected final boolean legacyFormat; protected final boolean legacyFormat;
protected MavenSnapshotMetadata( Metadata metadata, File file, boolean legacyFormat ) protected MavenSnapshotMetadata( Metadata metadata, File file, boolean legacyFormat, Date timestamp )
{ {
super( metadata, file ); super( metadata, file, timestamp );
this.legacyFormat = legacyFormat; this.legacyFormat = legacyFormat;
} }

View File

@ -47,19 +47,19 @@ final class RemoteSnapshotMetadata
private final Map<String, SnapshotVersion> versions = new LinkedHashMap<>(); private final Map<String, SnapshotVersion> versions = new LinkedHashMap<>();
RemoteSnapshotMetadata( Artifact artifact, boolean legacyFormat ) RemoteSnapshotMetadata( Artifact artifact, boolean legacyFormat, Date timestamp )
{ {
super( createRepositoryMetadata( artifact, legacyFormat ), null, legacyFormat ); super( createRepositoryMetadata( artifact, legacyFormat ), null, legacyFormat, timestamp );
} }
private RemoteSnapshotMetadata( Metadata metadata, File file, boolean legacyFormat ) private RemoteSnapshotMetadata( Metadata metadata, File file, boolean legacyFormat, Date timestamp )
{ {
super( metadata, file, legacyFormat ); super( metadata, file, legacyFormat, timestamp );
} }
public MavenMetadata setFile( File file ) public MavenMetadata setFile( File file )
{ {
return new RemoteSnapshotMetadata( metadata, file, legacyFormat ); return new RemoteSnapshotMetadata( metadata, file, legacyFormat, timestamp );
} }
public String getExpandedVersion( Artifact artifact ) public String getExpandedVersion( Artifact artifact )
@ -82,11 +82,11 @@ final class RemoteSnapshotMetadata
snapshot = new Snapshot(); snapshot = new Snapshot();
snapshot.setBuildNumber( getBuildNumber( recessive ) + 1 ); snapshot.setBuildNumber( getBuildNumber( recessive ) + 1 );
snapshot.setTimestamp( utcDateFormatter.format( new Date() ) ); snapshot.setTimestamp( utcDateFormatter.format( timestamp ) );
Versioning versioning = new Versioning(); Versioning versioning = new Versioning();
versioning.setSnapshot( snapshot ); versioning.setSnapshot( snapshot );
versioning.setLastUpdated( snapshot.getTimestamp().replace( ".", "" ) ); versioning.setLastUpdatedTimestamp( timestamp );
lastUpdated = versioning.getLastUpdated(); lastUpdated = versioning.getLastUpdated();
metadata.setVersioning( versioning ); metadata.setVersioning( versioning );

View File

@ -21,6 +21,7 @@ package org.apache.maven.repository.internal;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Date;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
@ -42,9 +43,13 @@ class RemoteSnapshotMetadataGenerator
private final boolean legacyFormat; private final boolean legacyFormat;
private final Date timestamp;
RemoteSnapshotMetadataGenerator( RepositorySystemSession session, DeployRequest request ) RemoteSnapshotMetadataGenerator( RepositorySystemSession session, DeployRequest request )
{ {
legacyFormat = ConfigUtils.getBoolean( session.getConfigProperties(), false, "maven.metadata.legacy" ); legacyFormat = ConfigUtils.getBoolean( session, false, "maven.metadata.legacy" );
timestamp = (Date) ConfigUtils.getObject( session, new Date(), "maven.startTime" );
snapshots = new LinkedHashMap<>(); snapshots = new LinkedHashMap<>();
@ -74,7 +79,7 @@ class RemoteSnapshotMetadataGenerator
RemoteSnapshotMetadata snapshotMetadata = snapshots.get( key ); RemoteSnapshotMetadata snapshotMetadata = snapshots.get( key );
if ( snapshotMetadata == null ) if ( snapshotMetadata == null )
{ {
snapshotMetadata = new RemoteSnapshotMetadata( artifact, legacyFormat ); snapshotMetadata = new RemoteSnapshotMetadata( artifact, legacyFormat, timestamp );
snapshots.put( key, snapshotMetadata ); snapshots.put( key, snapshotMetadata );
} }
snapshotMetadata.bind( artifact ); snapshotMetadata.bind( artifact );

View File

@ -22,6 +22,7 @@ package org.apache.maven.repository.internal;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Date;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import org.apache.maven.artifact.repository.metadata.Metadata; import org.apache.maven.artifact.repository.metadata.Metadata;
@ -38,15 +39,15 @@ final class VersionsMetadata
private final Artifact artifact; private final Artifact artifact;
VersionsMetadata( Artifact artifact ) VersionsMetadata( Artifact artifact, Date timestamp )
{ {
super( createRepositoryMetadata( artifact ), null ); super( createRepositoryMetadata( artifact ), null, timestamp );
this.artifact = artifact; this.artifact = artifact;
} }
VersionsMetadata( Artifact artifact, File file ) VersionsMetadata( Artifact artifact, File file, Date timestamp )
{ {
super( createRepositoryMetadata( artifact ), file ); super( createRepositoryMetadata( artifact ), file, timestamp );
this.artifact = artifact; this.artifact = artifact;
} }
@ -76,7 +77,7 @@ final class VersionsMetadata
protected void merge( Metadata recessive ) protected void merge( Metadata recessive )
{ {
Versioning versioning = metadata.getVersioning(); Versioning versioning = metadata.getVersioning();
versioning.updateTimestamp(); versioning.setLastUpdatedTimestamp( timestamp );
if ( recessive.getVersioning() != null ) if ( recessive.getVersioning() != null )
{ {
@ -107,7 +108,7 @@ final class VersionsMetadata
public MavenMetadata setFile( File file ) public MavenMetadata setFile( File file )
{ {
return new VersionsMetadata( artifact, file ); return new VersionsMetadata( artifact, file, timestamp );
} }
public String getGroupId() public String getGroupId()

View File

@ -21,6 +21,7 @@ package org.apache.maven.repository.internal;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
@ -31,6 +32,7 @@ import org.eclipse.aether.deployment.DeployRequest;
import org.eclipse.aether.impl.MetadataGenerator; import org.eclipse.aether.impl.MetadataGenerator;
import org.eclipse.aether.installation.InstallRequest; import org.eclipse.aether.installation.InstallRequest;
import org.eclipse.aether.metadata.Metadata; import org.eclipse.aether.metadata.Metadata;
import org.eclipse.aether.util.ConfigUtils;
/** /**
* @author Benjamin Bentmann * @author Benjamin Bentmann
@ -43,6 +45,8 @@ class VersionsMetadataGenerator
private Map<Object, VersionsMetadata> processedVersions; private Map<Object, VersionsMetadata> processedVersions;
private final Date timestamp;
VersionsMetadataGenerator( RepositorySystemSession session, InstallRequest request ) VersionsMetadataGenerator( RepositorySystemSession session, InstallRequest request )
{ {
this( session, request.getMetadata() ); this( session, request.getMetadata() );
@ -57,6 +61,7 @@ class VersionsMetadataGenerator
{ {
versions = new LinkedHashMap<>(); versions = new LinkedHashMap<>();
processedVersions = new LinkedHashMap<>(); processedVersions = new LinkedHashMap<>();
timestamp = (Date) ConfigUtils.getObject( session, new Date(), "maven.startTime" );
/* /*
* NOTE: This should be considered a quirk to support interop with Maven's legacy ArtifactDeployer which * NOTE: This should be considered a quirk to support interop with Maven's legacy ArtifactDeployer which
@ -96,7 +101,7 @@ class VersionsMetadataGenerator
VersionsMetadata versionsMetadata = versions.get( key ); VersionsMetadata versionsMetadata = versions.get( key );
if ( versionsMetadata == null ) if ( versionsMetadata == null )
{ {
versionsMetadata = new VersionsMetadata( artifact ); versionsMetadata = new VersionsMetadata( artifact, timestamp );
versions.put( key, versionsMetadata ); versions.put( key, versionsMetadata );
} }
} }

View File

@ -66,7 +66,7 @@ public class RemoteSnapshotMetadataTest
String dateBefore = gregorianDate(); String dateBefore = gregorianDate();
RemoteSnapshotMetadata metadata = new RemoteSnapshotMetadata( RemoteSnapshotMetadata metadata = new RemoteSnapshotMetadata(
new DefaultArtifact( "a:b:1-SNAPSHOT" ), false); new DefaultArtifact( "a:b:1-SNAPSHOT" ), false, new Date() );
metadata.merge( new Metadata() ); metadata.merge( new Metadata() );
String dateAfter = gregorianDate(); String dateAfter = gregorianDate();