This is an automated email from the ASF dual-hosted git repository. rfscholte pushed a commit to branch MNG-5728 in repository https://gitbox.apache.org/repos/asf/maven.git
commit 501ac7d5caf195133eac194640367c56f0ccb6eb Author: Nicolas Juneau <[email protected]> AuthorDate: Fri Nov 27 16:03:11 2020 +0100 [MNG-5728] Switch the default checksum policy from "warn" to "fail" Signed-off-by: rfscholte <[email protected]> --- .../main/java/org/apache/maven/cli/MavenCli.java | 8 +-- .../java/org/apache/maven/cli/MavenCliTest.java | 77 +++++++++++++++++++++- 2 files changed, 78 insertions(+), 7 deletions(-) diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java index fd650f0..4734299 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java @@ -1639,17 +1639,13 @@ public class MavenCli private String determineGlobalCheckPolicy( final CommandLine commandLine ) { - if ( commandLine.hasOption( CLIManager.CHECKSUM_FAILURE_POLICY ) ) - { - return MavenExecutionRequest.CHECKSUM_POLICY_FAIL; - } - else if ( commandLine.hasOption( CLIManager.CHECKSUM_WARNING_POLICY ) ) + if ( commandLine.hasOption( CLIManager.CHECKSUM_WARNING_POLICY ) ) { return MavenExecutionRequest.CHECKSUM_POLICY_WARN; } else { - return null; + return MavenExecutionRequest.CHECKSUM_POLICY_FAIL; } } diff --git a/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java b/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java index e60ee9d..4387258 100644 --- a/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java +++ b/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java @@ -57,7 +57,6 @@ import org.codehaus.plexus.DefaultPlexusContainer; import org.codehaus.plexus.PlexusContainer; import org.eclipse.sisu.plexus.PlexusBeanModule; import org.junit.After; -import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.mockito.InOrder; @@ -465,6 +464,82 @@ public class MavenCliTest assertThat( executionRequest.getLocalRepositoryPath().toString(), is( "." + File.separatorChar + "custom2" ) ); } + + /** + * Tests the default global checksum policy (when no -C or -c option is given) to make sure that the default is + * strict. + */ + public void testDefaultGlobalChecksumPolicy() + { + String[] options = new String[2]; + options[0] = prefixCmdOption( CLIManager.OFFLINE ); + options[1] = prefixCmdOption( CLIManager.QUIET ); + + CliRequest request = createDummyCliRequest( options ); + cli.doMain( request ); + + // Test that the default policy is "fail" + assertThat( request.request.getGlobalChecksumPolicy(), is( MavenExecutionRequest.CHECKSUM_POLICY_FAIL ) ); + } + + /** + * Tests that the warn flag (-c) works + */ + public void testWarnCheckSumPolicy() + { + String[] options = new String[3]; + options[0] = prefixCmdOption( CLIManager.OFFLINE ); + options[1] = prefixCmdOption( CLIManager.QUIET ); + + // Warn + options[2] = prefixCmdOption( CLIManager.CHECKSUM_WARNING_POLICY ); + + CliRequest request = createDummyCliRequest( options ); + cli.doMain( request ); + + assertThat( request.request.getGlobalChecksumPolicy(), is( MavenExecutionRequest.CHECKSUM_POLICY_WARN ) ); + } + + /** + * Check that the strict flag (-C) works + */ + public void testStrictChecksumPolicy() + { + String[] options = new String[3]; + options[0] = prefixCmdOption( CLIManager.OFFLINE ); + options[1] = prefixCmdOption( CLIManager.QUIET ); + + // Fail + options[2] = prefixCmdOption( CLIManager.CHECKSUM_FAILURE_POLICY ); + + CliRequest request = createDummyCliRequest( options ); + cli.doMain( request ); + + assertThat( request.request.getGlobalChecksumPolicy(), is( MavenExecutionRequest.CHECKSUM_POLICY_FAIL ) ); + } + + /** + * Prefixes a single-letter command line option character ('o') + * with a dash so it can be interpreted as a command line option ('-o') + * + * @param option The option char to prefix + * @return The prefixed option + */ + private static String prefixCmdOption(char option) { + StringBuilder sb = new StringBuilder(2); + sb.append('-'); + sb.append(option); + + return sb.toString(); + } + + private static CliRequest createDummyCliRequest( String[] options ) + { + CliRequest rq = new CliRequest( options, null ); + rq.multiModuleProjectDirectory = new File( "." ); + + return rq; + } private MavenProject createMavenProject( String groupId, String artifactId ) {
