[cpd] Deprecate skipLexicalErrors

This commit is contained in:
Andreas Dangel
2024-05-17 16:16:20 +02:00
parent b624b41673
commit 10c78f26de
8 changed files with 55 additions and 13 deletions

View File

@@ -68,8 +68,12 @@ public class CpdCommand extends AbstractAnalysisPmdSubcommand<CPDConfiguration>
@Option(names = "--ignore-sequences", description = "Ignore sequences of identifiers and literals")
private boolean ignoreIdentifierAndLiteralSequences;
/**
* @deprecated Use {@link #failOnError} instead.
*/
@Option(names = "--skip-lexical-errors",
description = "Skip files which can't be tokenized due to invalid characters, instead of aborting with an error.")
description = "Skip files which can't be tokenized due to invalid characters, instead of aborting with an error. Deprecated - use --[no-]fail-on-error instead.")
@Deprecated
private boolean skipLexicalErrors;
@Option(names = "--no-skip-blocks",
@@ -124,6 +128,14 @@ public class CpdCommand extends AbstractAnalysisPmdSubcommand<CPDConfiguration>
configuration.setSourceEncoding(encoding.getEncoding());
configuration.setInputUri(uri);
if (skipLexicalErrors) {
configuration.getReporter().warn("--skip-lexical-errors is deprecated. Use --no-fail-on-error instead.");
configuration.setFailOnError(false);
}
// implicitly enable skipLexicalErrors, so that we can fail the build at the end. A report is created in any case.
configuration.setSkipLexicalErrors(true);
return configuration;
}

View File

@@ -221,7 +221,7 @@ class CpdCliTest extends BaseCliTest {
*/
@Test
void testSkipLexicalErrors() throws Exception {
runCli(RECOVERED_ERRORS_OR_VIOLATIONS,
runCli(VIOLATIONS_FOUND,
"--minimum-tokens", "10",
"-d", BASE_RES_PATH + "badandgood/",
"--format", "text",
@@ -239,7 +239,7 @@ class CpdCliTest extends BaseCliTest {
"-d", Paths.get(BASE_RES_PATH, "badandgood", "BadFile.java").toString(),
"--format", "text")
.verify(r -> {
r.checkStdErr(containsPattern("Error while tokenizing: Lexical error in file '.*?BadFile\\.java'"));
r.checkStdErr(containsPattern("Skipping file: Lexical error in file '.*?BadFile\\.java'"));
r.checkStdOut(emptyString());
});
}
@@ -252,14 +252,14 @@ class CpdCliTest extends BaseCliTest {
"--format", "text",
"--no-fail-on-error")
.verify(r -> {
r.checkStdErr(containsPattern("Error while tokenizing: Lexical error in file '.*?BadFile\\.java'"));
r.checkStdErr(containsPattern("Skipping file: Lexical error in file '.*?BadFile\\.java'"));
r.checkStdOut(emptyString());
});
}
@Test
void testExitCodeWithLexicalErrorsAndSkipLexical() throws Exception {
runCli(RECOVERED_ERRORS_OR_VIOLATIONS,
runCli(OK,
"--minimum-tokens", "10",
"-d", Paths.get(BASE_RES_PATH, "badandgood", "BadFile.java").toString(),
"--format", "text",