Skip to content
Browse files

NEXUS-5383: Snapshot merges failure

The "to merge or not" decision was based on
metadata/versioning/snapshot/timestamp value.

This was wrong, as since model 1.1.0, the
newly added snapshotVersions element should be
always merged, while the "legacy" element
metadata/versioning/snapshot/timestamp
should be "merged" only if newer.
  • Loading branch information...
1 parent 08af70a commit d96d478f3d36d8f94b4b3001fedc5062d18fa8ab @cstamas cstamas committed Nov 16, 2012
View
38 ...src/main/java/org/sonatype/nexus/proxy/maven/metadata/operations/NexusMergeOperation.java
@@ -24,6 +24,7 @@
public class NexusMergeOperation
implements MetadataOperation
{
+
private Metadata sourceMetadata;
private Version sourceModelVersion;
@@ -116,13 +117,15 @@ else if ( hasLastUpdatedSet( targetMetadata ) && hasLastUpdatedSet( sourceMetada
&& !sourceMetadata.getGroupId().equals( targetMetadata.getGroupId() ) )
{
throw new MetadataException( "Could not merge metadata with different groupId: '"
- + sourceMetadata.getGroupId() + "' and '" + targetMetadata.getGroupId() + "'" );
+ + sourceMetadata.getGroupId() + "' and '" + targetMetadata.getGroupId()
+ + "'" );
}
if ( sourceMetadata.getArtifactId() != null && targetMetadata.getArtifactId() != null
&& !sourceMetadata.getArtifactId().equals( targetMetadata.getArtifactId() ) )
{
throw new MetadataException( "Could not merge metadata with different artifactId: '"
- + sourceMetadata.getArtifactId() + "' and '" + targetMetadata.getArtifactId() + "'" );
+ + sourceMetadata.getArtifactId() + "' and '"
+ + targetMetadata.getArtifactId() + "'" );
}
// versioning
@@ -151,31 +154,42 @@ else if ( hasLastUpdatedSet( targetMetadata ) && hasLastUpdatedSet( sourceMetada
{
timestamp =
Long.parseLong( targetMetadata.getVersioning().getSnapshot().getTimestamp().replace( ".",
- "" ) );
+ "" ) );
}
catch ( NumberFormatException e )
{
}
}
+ long sourceTimestamp = -1;
+
if ( sourceSnapshot.getTimestamp() != null )
{
- long sourceTimestamp = -1;
-
try
{
sourceTimestamp = Long.parseLong( sourceSnapshot.getTimestamp().replace( ".", "" ) );
}
catch ( NumberFormatException e )
{
}
+ }
- if ( sourceTimestamp > timestamp )
- {
- ops.add( new SetSnapshotOperation( new SnapshotOperand( sourceModelVersion,
- sourceSnapshot.getTimestamp().replace( ".", "" ), sourceSnapshot,
- sourceMetadata.getVersioning().getSnapshotVersions() ) ) );
- }
+ // set snapshot element if source has it, and if target either does not have it, or is older
+ if ( sourceTimestamp != -1 && ( timestamp == -1 || ( timestamp < sourceTimestamp ) ) )
+ {
+ // set Snapshot and add extras
+ ops.add( new SetSnapshotOperation( new SnapshotOperand( sourceModelVersion,
+ sourceMetadata.getVersioning().getLastUpdated(),
+ sourceSnapshot,
+ sourceMetadata.getVersioning().getSnapshotVersions() ) ) );
+ }
+ else
+ {
+ // do not set Snapshot and add extras
+ ops.add( new SetSnapshotOperation( new SnapshotOperand( sourceModelVersion,
+ sourceMetadata.getVersioning().getLastUpdated(),
+ null,
+ sourceMetadata.getVersioning().getSnapshotVersions() ) ) );
}
}
}
@@ -198,7 +212,7 @@ public void setOperand( AbstractOperand data )
if ( data == null || !( data instanceof MetadataOperand ) )
{
throw new MetadataException( "Operand is not correct: expected MetadataOperand, but got "
- + ( data == null ? "null" : data.getClass().getName() ) );
+ + ( data == null ? "null" : data.getClass().getName() ) );
}

0 comments on commit d96d478

Please sign in to comment.
Something went wrong with that request. Please try again.