Skip to content

Commit

Permalink
[MNG-6754] Set the same timestamp in multi module builds
Browse files Browse the repository at this point in the history
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
  • Loading branch information
michael-o committed Jul 12, 2021
1 parent f32c3db commit a3907fc
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ else if ( metadata instanceof SnapshotArtifactRepositoryMetadata
}

Versioning versioning = new Versioning();
// TODO Should this be changed for MNG-6754 too?
versioning.updateTimestamp();
versioning.addVersion( artifact.getBaseVersion() );
if ( artifact.isRelease() )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public void transformForDeployment( Artifact artifact, ArtifactRepository remote
private ArtifactMetadata createMetadata( Artifact artifact )
{
Versioning versioning = new Versioning();
// TODO Should this be changed for MNG-6754 too?
versioning.updateTimestamp();
versioning.addVersion( artifact.getVersion() );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public void transformForDeployment( Artifact artifact, ArtifactRepository remote
{
Snapshot snapshot = new Snapshot();

// TODO Should this be changed for MNG-6754 too?
snapshot.setTimestamp( getDeploymentTimestamp() );

// we update the build number anyway so that it doesn't get lost. It requires the timestamp to take effect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ protected static Versioning createVersioning( Snapshot snapshot )
{
Versioning versioning = new Versioning();
versioning.setSnapshot( snapshot );
versioning.updateTimestamp();
return versioning;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public DefaultRepositorySystemSession newRepositorySession( MavenExecutionReques
Map<Object, Object> configProps = new LinkedHashMap<>();
configProps.put( ConfigurationProperties.USER_AGENT, getUserAgent() );
configProps.put( ConfigurationProperties.INTERACTIVE, request.isInteractiveMode() );
configProps.put( "maven.startTime", request.getStartTime() );
configProps.putAll( request.getSystemProperties() );
configProps.putAll( request.getUserProperties() );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;

Expand All @@ -42,15 +43,15 @@ final class LocalSnapshotMetadata

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;
}

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;
}

Expand Down Expand Up @@ -82,7 +83,7 @@ public void bind( Artifact artifact )

public MavenMetadata setFile( File file )
{
return new LocalSnapshotMetadata( metadata, file, legacyFormat );
return new LocalSnapshotMetadata( metadata, file, legacyFormat, timestamp );
}

public Object getKey()
Expand All @@ -98,7 +99,7 @@ public static Object getKey( Artifact artifact )
@Override
protected void merge( Metadata recessive )
{
metadata.getVersioning().updateTimestamp();
metadata.getVersioning().setLastUpdatedTimestamp( timestamp );

if ( !legacyFormat )
{
Expand Down Expand Up @@ -160,4 +161,4 @@ public Nature getNature()
return Nature.SNAPSHOT;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;

Expand All @@ -42,10 +43,14 @@ class LocalSnapshotMetadataGenerator

private final boolean legacyFormat;

private final Date timestamp;

LocalSnapshotMetadataGenerator( RepositorySystemSession session, InstallRequest request )
{
legacyFormat = ConfigUtils.getBoolean( session.getConfigProperties(), false, "maven.metadata.legacy" );

timestamp = (Date) ConfigUtils.getObject( session, new Date(), "maven.startTime" );

snapshots = new LinkedHashMap<>();
}

Expand All @@ -59,7 +64,7 @@ public Collection<? extends Metadata> prepare( Collection<? extends Artifact> ar
LocalSnapshotMetadata snapshotMetadata = snapshots.get( key );
if ( snapshotMetadata == null )
{
snapshotMetadata = new LocalSnapshotMetadata( artifact, legacyFormat );
snapshotMetadata = new LocalSnapshotMetadata( artifact, legacyFormat, timestamp );
snapshots.put( key, snapshotMetadata );
}
snapshotMetadata.bind( artifact );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.io.Reader;
import java.io.Writer;
import java.util.Collections;
import java.util.Date;
import java.util.Map;

/**
Expand All @@ -46,16 +47,19 @@ abstract class MavenMetadata

static final String MAVEN_METADATA_XML = "maven-metadata.xml";

protected Metadata metadata;

private final File file;

protected Metadata metadata;
protected final Date timestamp;

private boolean merged;

protected MavenMetadata( Metadata metadata, File file )
protected MavenMetadata( Metadata metadata, File file, Date timestamp )
{
this.metadata = metadata;
this.file = file;
this.timestamp = timestamp;
}

public String getType()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;

import org.apache.maven.artifact.repository.metadata.Metadata;
import org.eclipse.aether.artifact.Artifact;
Expand All @@ -38,9 +39,9 @@ abstract class MavenSnapshotMetadata

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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@ final class RemoteSnapshotMetadata

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 )
{
return new RemoteSnapshotMetadata( metadata, file, legacyFormat );
return new RemoteSnapshotMetadata( metadata, file, legacyFormat, timestamp );
}

public String getExpandedVersion( Artifact artifact )
Expand All @@ -82,11 +82,11 @@ protected void merge( Metadata recessive )

snapshot = new Snapshot();
snapshot.setBuildNumber( getBuildNumber( recessive ) + 1 );
snapshot.setTimestamp( utcDateFormatter.format( new Date() ) );
snapshot.setTimestamp( utcDateFormatter.format( timestamp ) );

Versioning versioning = new Versioning();
versioning.setSnapshot( snapshot );
versioning.setLastUpdated( snapshot.getTimestamp().replace( ".", "" ) );
versioning.setLastUpdatedTimestamp( timestamp );
lastUpdated = versioning.getLastUpdated();

metadata.setVersioning( versioning );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;

Expand All @@ -42,9 +43,13 @@ class RemoteSnapshotMetadataGenerator

private final boolean legacyFormat;

private final Date timestamp;

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<>();

Expand Down Expand Up @@ -74,7 +79,7 @@ public Collection<? extends Metadata> prepare( Collection<? extends Artifact> ar
RemoteSnapshotMetadata snapshotMetadata = snapshots.get( key );
if ( snapshotMetadata == null )
{
snapshotMetadata = new RemoteSnapshotMetadata( artifact, legacyFormat );
snapshotMetadata = new RemoteSnapshotMetadata( artifact, legacyFormat, timestamp );
snapshots.put( key, snapshotMetadata );
}
snapshotMetadata.bind( artifact );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.LinkedHashSet;

import org.apache.maven.artifact.repository.metadata.Metadata;
Expand All @@ -38,15 +39,15 @@ final class VersionsMetadata

private final Artifact artifact;

VersionsMetadata( Artifact artifact )
VersionsMetadata( Artifact artifact, Date timestamp )
{
super( createRepositoryMetadata( artifact ), null );
super( createRepositoryMetadata( artifact ), null, timestamp );
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;
}

Expand Down Expand Up @@ -76,7 +77,7 @@ private static Metadata createRepositoryMetadata( Artifact artifact )
protected void merge( Metadata recessive )
{
Versioning versioning = metadata.getVersioning();
versioning.updateTimestamp();
versioning.setLastUpdatedTimestamp( timestamp );

if ( recessive.getVersioning() != null )
{
Expand Down Expand Up @@ -107,7 +108,7 @@ public static Object getKey( Artifact artifact )

public MavenMetadata setFile( File file )
{
return new VersionsMetadata( artifact, file );
return new VersionsMetadata( artifact, file, timestamp );
}

public String getGroupId()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
Expand All @@ -31,6 +32,7 @@
import org.eclipse.aether.impl.MetadataGenerator;
import org.eclipse.aether.installation.InstallRequest;
import org.eclipse.aether.metadata.Metadata;
import org.eclipse.aether.util.ConfigUtils;

/**
* @author Benjamin Bentmann
Expand All @@ -43,6 +45,8 @@ class VersionsMetadataGenerator

private Map<Object, VersionsMetadata> processedVersions;

private final Date timestamp;

VersionsMetadataGenerator( RepositorySystemSession session, InstallRequest request )
{
this( session, request.getMetadata() );
Expand All @@ -57,6 +61,7 @@ private VersionsMetadataGenerator( RepositorySystemSession session, Collection<?
{
versions = 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
Expand Down Expand Up @@ -96,7 +101,7 @@ public Collection<? extends Metadata> finish( Collection<? extends Artifact> art
VersionsMetadata versionsMetadata = versions.get( key );
if ( versionsMetadata == null )
{
versionsMetadata = new VersionsMetadata( artifact );
versionsMetadata = new VersionsMetadata( artifact, timestamp );
versions.put( key, versionsMetadata );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void gregorianCalendarIsUsed()
String dateBefore = gregorianDate();

RemoteSnapshotMetadata metadata = new RemoteSnapshotMetadata(
new DefaultArtifact( "a:b:1-SNAPSHOT" ), false);
new DefaultArtifact( "a:b:1-SNAPSHOT" ), false, new Date() );
metadata.merge( new Metadata() );

String dateAfter = gregorianDate();
Expand Down

0 comments on commit a3907fc

Please sign in to comment.