Skip to content

Commit

Permalink
[MNG-5180] Versioning's snapshot version list is not included in
Browse files Browse the repository at this point in the history
metadata merge

Co-authored-by: Konrad Windszus <[email protected]>

This closes #684
  • Loading branch information
patope authored and michael-o committed Feb 27, 2022
1 parent d29af90 commit 05e96da
Show file tree
Hide file tree
Showing 3 changed files with 340 additions and 5 deletions.
5 changes: 5 additions & 0 deletions maven-repository-metadata/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ under the License.
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-api</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
50 changes: 45 additions & 5 deletions maven-repository-metadata/src/main/mdo/metadata.mdo
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ under the License.
<codeSegment>
<version>1.0.0+</version>
<code><![CDATA[
private String getSnapshotVersionKey( SnapshotVersion sv )
{
return sv.getClassifier() + ":" + sv.getExtension();
}

public boolean merge( Metadata sourceMetadata )
{
boolean changed = false;
Expand Down Expand Up @@ -178,11 +183,13 @@ under the License.
Snapshot snapshot = versioning.getSnapshot();
if ( snapshot != null )
{
boolean updateSnapshotVersions = false;
if ( s == null )
{
s = new Snapshot();
v.setSnapshot( s );
changed = true;
updateSnapshotVersions = true;
}

// overwrite
Expand All @@ -191,6 +198,7 @@ under the License.
{
s.setTimestamp( snapshot.getTimestamp() );
changed = true;
updateSnapshotVersions = true;
}
if ( s.getBuildNumber() != snapshot.getBuildNumber() )
{
Expand All @@ -202,6 +210,34 @@ under the License.
s.setLocalCopy( snapshot.isLocalCopy() );
changed = true;
}
if ( updateSnapshotVersions )
{
java.util.Map<String, SnapshotVersion> versions = new java.util.LinkedHashMap<>();
// never convert from legacy to new format if either source or target is legacy format
if ( !v.getSnapshotVersions().isEmpty() )
{
for ( SnapshotVersion sv : versioning.getSnapshotVersions() )
{
String key = getSnapshotVersionKey( sv );
versions.put( key, sv );
}
// never convert from legacy format
if ( !versions.isEmpty() )
{
for ( SnapshotVersion sv : v.getSnapshotVersions() )
{
String key = getSnapshotVersionKey( sv );
if ( !versions.containsKey( key ) )
{
versions.put( key, sv );
}
}
}
v.setSnapshotVersions( new java.util.ArrayList<SnapshotVersion>( versions.values() ) );
}

changed = true;
}
}
}
}
Expand Down Expand Up @@ -241,7 +277,7 @@ under the License.
<name>lastUpdated</name>
<version>1.0.0+</version>
<type>String</type>
<description>When the metadata was last updated (both "groupId/artifactId" and "groupId/artifactId/version" directories)</description>
<description>When the metadata was last updated (both "groupId/artifactId" and "groupId/artifactId/version" directories). The timestamp is expressed using UTC in the format yyyyMMddHHmmss.</description>
</field>
<field xdoc.separator="blank">
<name>snapshot</name>
Expand All @@ -254,7 +290,7 @@ under the License.
<field>
<name>snapshotVersions</name>
<version>1.1.0+</version>
<description>Information for each sub-artifact available in this artifact snapshot.</description>
<description>Information for each sub-artifact available in this artifact snapshot. This is only the most recent SNAPSHOT for each unique extension/classifier combination.</description>
<association>
<type>SnapshotVersion</type>
<multiplicity>*</multiplicity>
Expand Down Expand Up @@ -289,7 +325,7 @@ under the License.
<field>
<name>timestamp</name>
<version>1.0.0+</version>
<description>The time it was deployed</description>
<description>The timestamp when this version was deployed. The timestamp is expressed using UTC in the format yyyyMMdd.HHmmss.</description>
<type>String</type>
</field>
<field>
Expand All @@ -316,26 +352,30 @@ under the License.
<name>classifier</name>
<version>1.1.0+</version>
<type>String</type>
<description>The classifier of the sub-artifact.</description>
<description>The classifier of the sub-artifact. Each classifier and extension pair may only appear once.</description>
<defaultValue></defaultValue>
<identifier>true</identifier>
</field>
<field>
<name>extension</name>
<version>1.1.0+</version>
<type>String</type>
<description>The file extension of the sub-artifact.</description>
<description>The file extension of the sub-artifact. Each classifier and extension pair may only appear once.</description>
<identifier>true</identifier>
</field>
<field xml.tagName="value">
<name>version</name>
<version>1.1.0+</version>
<type>String</type>
<description>The resolved snapshot version of the sub-artifact.</description>
<identifier>true</identifier>
</field>
<field>
<name>updated</name>
<version>1.1.0+</version>
<type>String</type>
<description>The timestamp when this version information was last updated. The timestamp is expressed using UTC in the format yyyyMMddHHmmss.</description>
<identifier>true</identifier>
</field>
</fields>
</class>
Expand Down
Loading

0 comments on commit 05e96da

Please sign in to comment.