Revert "[MNG-5728] Switch the default checksum policy from "warn" to "fail""

This commit is contained in:
Robert Scholte 2020-12-02 20:27:26 +01:00
parent 2bdc0c5424
commit 251ba225c6
6 changed files with 17 additions and 64 deletions

View File

@ -43,8 +43,6 @@ public class ArtifactRepositoryPolicy
public static final String CHECKSUM_POLICY_IGNORE = "ignore";
public static final String DEFAULT_CHECKSUM_POLICY = CHECKSUM_POLICY_FAIL;
private boolean enabled;
private String updatePolicy;
@ -73,7 +71,7 @@ public class ArtifactRepositoryPolicy
if ( checksumPolicy == null )
{
checksumPolicy = DEFAULT_CHECKSUM_POLICY;
checksumPolicy = CHECKSUM_POLICY_WARN;
}
this.checksumPolicy = checksumPolicy;
}

View File

@ -60,7 +60,6 @@ import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.List;
@ -299,17 +298,6 @@ public abstract class AbstractArtifactComponentTestCase
{
writer.write( artifact.getId() );
}
MessageDigest md = MessageDigest.getInstance( "MD5" );
md.update( artifact.getId().getBytes() );
byte[] digest = md.digest();
String md5path = repository.pathOf( artifact ) + ".md5";
File md5artifactFile = new File( repository.getBasedir(), md5path );
try ( Writer writer = new OutputStreamWriter( new FileOutputStream( md5artifactFile ), StandardCharsets.ISO_8859_1) )
{
writer.append( printHexBinary( digest ) );
}
}
protected Artifact createArtifact( String artifactId, String version )
@ -383,17 +371,4 @@ public abstract class AbstractArtifactComponentTestCase
return session;
}
private static final char[] hexCode = "0123456789ABCDEF".toCharArray();
private static final String printHexBinary( byte[] data )
{
StringBuilder r = new StringBuilder( data.length * 2 );
for ( byte b : data )
{
r.append( hexCode[( b >> 4 ) & 0xF] );
r.append( hexCode[( b & 0xF )] );
}
return r.toString();
}
}

View File

@ -101,10 +101,7 @@ public class DefaultWagonManagerTest
StringWagon wagon = (StringWagon) wagonManager.getWagon( "string" );
wagon.addExpectedContent( repos.get( 0 ).getLayout().pathOf( artifact ), "expected" );
wagon.addExpectedContent( repos.get( 0 ).getLayout().pathOf( artifact ) + ".md5", "cd26d9e10ce691cc69aa2b90dcebbdac" );
wagon.addExpectedContent( repos.get( 1 ).getLayout().pathOf( artifact ), "expected" );
wagon.addExpectedContent( repos.get( 1 ).getLayout().pathOf( artifact ) + ".md5", "cd26d9e10ce691cc69aa2b90dcebbdac" );
class TransferListener
extends AbstractTransferListener
@ -173,7 +170,6 @@ public class DefaultWagonManagerTest
StringWagon wagon = (StringWagon) wagonManager.getWagon( "string" );
wagon.addExpectedContent( repo.getLayout().pathOf( artifact ), "expected" );
wagon.addExpectedContent( repo.getLayout().pathOf( artifact ) + ".md5", "cd26d9e10ce691cc69aa2b90dcebbdac" );
wagonManager.getArtifact( artifact, repo, null, false );
@ -275,7 +271,6 @@ public class DefaultWagonManagerTest
ArtifactRepository repo = createStringRepo();
StringWagon wagon = (StringWagon) wagonManager.getWagon( "string" );
wagon.addExpectedContent( repo.getLayout().pathOf( artifact ), "expected" );
wagon.addExpectedContent( repo.getLayout().pathOf( artifact ) + ".md5", "cd26d9e10ce691cc69aa2b90dcebbdac" );
/* getArtifact */
assertFalse( "Transfer listener is registered before test",

View File

@ -419,8 +419,8 @@ public class MavenRepositorySystem
}
return new ArtifactRepositoryPolicy( enabled, updatePolicy, checksumPolicy );
}
}
public ArtifactRepository createArtifactRepository( String id, String url, String layoutId,
ArtifactRepositoryPolicy snapshots,
ArtifactRepositoryPolicy releases )
@ -442,7 +442,7 @@ public class MavenRepositorySystem
repositoryId ) );
}
}
public static ArtifactRepository createArtifactRepository( String id, String url,
ArtifactRepositoryLayout repositoryLayout,
ArtifactRepositoryPolicy snapshots,
@ -568,20 +568,20 @@ public class MavenRepositorySystem
return new DefaultArtifact( groupId, artifactId, versionRange, desiredScope, type, classifier, handler,
optional );
}
//
// Code taken from LegacyRepositorySystem
//
public ArtifactRepository createDefaultRemoteRepository( MavenExecutionRequest request )
throws Exception
{
return createRepository( RepositorySystem.DEFAULT_REMOTE_REPO_URL, RepositorySystem.DEFAULT_REMOTE_REPO_ID,
true, ArtifactRepositoryPolicy.UPDATE_POLICY_DAILY, false,
ArtifactRepositoryPolicy.UPDATE_POLICY_DAILY,
ArtifactRepositoryPolicy.DEFAULT_CHECKSUM_POLICY );
ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN );
}
public ArtifactRepository createRepository( String url, String repositoryId, boolean releases,
String releaseUpdates, boolean snapshots, String snapshotUpdates,
String checksumPolicy ) throws Exception
@ -594,7 +594,7 @@ public class MavenRepositorySystem
return createArtifactRepository( repositoryId, url, "default", snapshotsPolicy, releasesPolicy );
}
public Set<String> getRepoIds( List<ArtifactRepository> repositories )
{
Set<String> repoIds = new HashSet<>();
@ -707,8 +707,8 @@ public class MavenRepositorySystem
ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, true,
ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS,
ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE );
}
}
private static final String WILDCARD = "*";
private static final String EXTERNAL_WILDCARD = "external:*";
@ -873,5 +873,5 @@ public class MavenRepositorySystem
}
return result;
}
}
}

View File

@ -1995,11 +1995,12 @@
<description>
<![CDATA[
What to do when verification of an artifact checksum fails. Valid values are
<code>ignore</code>,
<code>ignore</code>
,
<code>fail</code>
(default for Maven 4 and above) or
or
<code>warn</code>
(default for Maven 2 and 3)
(the default).
]]>
</description>
<type>String</type>

View File

@ -19,7 +19,6 @@ package org.apache.maven.repository.internal;
* under the License.
*/
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.model.Repository;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.artifact.DefaultArtifact;
@ -60,7 +59,7 @@ public class ArtifactDescriptorUtils
public static RepositoryPolicy toRepositoryPolicy( org.apache.maven.model.RepositoryPolicy policy )
{
boolean enabled = true;
String checksums = toRepositoryChecksumPolicy( ArtifactRepositoryPolicy.DEFAULT_CHECKSUM_POLICY );
String checksums = RepositoryPolicy.CHECKSUM_POLICY_WARN;
String updates = RepositoryPolicy.UPDATE_POLICY_DAILY;
if ( policy != null )
@ -79,19 +78,4 @@ public class ArtifactDescriptorUtils
return new RepositoryPolicy( enabled, updates, checksums );
}
public static String toRepositoryChecksumPolicy( final String artifactRepositoryPolicy )
{
switch ( artifactRepositoryPolicy )
{
case ArtifactRepositoryPolicy.CHECKSUM_POLICY_FAIL:
return RepositoryPolicy.CHECKSUM_POLICY_FAIL;
case ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE:
return RepositoryPolicy.CHECKSUM_POLICY_IGNORE;
case ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN:
return RepositoryPolicy.CHECKSUM_POLICY_WARN;
default:
throw new IllegalArgumentException( "unknown repository checksum policy: " + artifactRepositoryPolicy );
}
}
}