Skip to content

Commit

Permalink
[MRESOLVER-265] Checksum of checksum (#187)
Browse files Browse the repository at this point in the history
There is a discrepancy when a checksum is attached (so not added
by resolver itself), and resolver will checksum it if the algorithm
is not configured (ie. default config used but SHA512 added).

This makes it work as expected, as checksum recognition works
now against ALL SUPPORTED and not configured ONLY checksums).
  • Loading branch information
cstamas authored Jun 24, 2022
1 parent d1d6ce5 commit f251fdc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public RepositoryLayout newInstance( RepositorySystemSession session, RemoteRepo
}

return new Maven2RepositoryLayout(
new ArrayList<>( checksumAlgorithmFactorySelector.getChecksumAlgorithmFactories() ),
checksumsAlgorithms,
omitChecksumsForExtensions
);
Expand All @@ -150,15 +151,18 @@ public RepositoryLayout newInstance( RepositorySystemSession session, RemoteRepo
private static class Maven2RepositoryLayout
implements RepositoryLayout
{
private final List<ChecksumAlgorithmFactory> allChecksumAlgorithms;

private final List<ChecksumAlgorithmFactory> checksumAlgorithms;
private final List<ChecksumAlgorithmFactory> configuredChecksumAlgorithms;

private final Set<String> extensionsWithoutChecksums;

private Maven2RepositoryLayout( List<ChecksumAlgorithmFactory> checksumAlgorithms,
private Maven2RepositoryLayout( List<ChecksumAlgorithmFactory> allChecksumAlgorithms,
List<ChecksumAlgorithmFactory> configuredChecksumAlgorithms,
Set<String> extensionsWithoutChecksums )
{
this.checksumAlgorithms = Collections.unmodifiableList( checksumAlgorithms );
this.allChecksumAlgorithms = Collections.unmodifiableList( allChecksumAlgorithms );
this.configuredChecksumAlgorithms = Collections.unmodifiableList( configuredChecksumAlgorithms );
this.extensionsWithoutChecksums = requireNonNull( extensionsWithoutChecksums );
}

Expand All @@ -177,7 +181,7 @@ private URI toUri( String path )
@Override
public List<ChecksumAlgorithmFactory> getChecksumAlgorithmFactories()
{
return checksumAlgorithms;
return configuredChecksumAlgorithms;
}

@Override
Expand Down Expand Up @@ -263,8 +267,8 @@ public List<ChecksumLocation> getChecksumLocations( Metadata metadata, boolean u

private List<ChecksumLocation> getChecksumLocations( URI location )
{
List<ChecksumLocation> checksumLocations = new ArrayList<>( checksumAlgorithms.size() );
for ( ChecksumAlgorithmFactory checksumAlgorithmFactory : checksumAlgorithms )
List<ChecksumLocation> checksumLocations = new ArrayList<>( configuredChecksumAlgorithms.size() );
for ( ChecksumAlgorithmFactory checksumAlgorithmFactory : configuredChecksumAlgorithms )
{
checksumLocations.add( ChecksumLocation.forLocation( location, checksumAlgorithmFactory ) );
}
Expand All @@ -273,7 +277,7 @@ private List<ChecksumLocation> getChecksumLocations( URI location )

private boolean isChecksum( String extension )
{
return checksumAlgorithms.stream().anyMatch( a -> extension.endsWith( "." + a.getFileExtension() ) );
return allChecksumAlgorithms.stream().anyMatch( a -> extension.endsWith( "." + a.getFileExtension() ) );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,17 @@ public void testCustomChecksumsIgnored()
assertEquals( 0, checksums.size() );
}

@Test
public void testNotConfiguredButSupportedChecksumsHandledAsChecksums()
throws Exception
{
layout = factory.newInstance( session, newRepo( "default" ) );
DefaultArtifact artifact = new DefaultArtifact( "g.i.d", "a-i.d", "cls", "jar.sha512", "1.0" );
URI uri = layout.getLocation( artifact, true );
List<ChecksumLocation> checksums = layout.getChecksumLocations( artifact, true, uri );
assertEquals( 0, checksums.size() );
}

@Test
public void testCustomChecksumsIgnored_IllegalInout()
throws Exception
Expand Down

0 comments on commit f251fdc

Please sign in to comment.