Issue #1217: goal 'testCheck' was activated in 'forbiddenapis' plugin, violations fixed
This commit is contained in:
parent
be3e035ce3
commit
7d5db23ad5
23
pom.xml
23
pom.xml
|
|
@ -891,12 +891,35 @@
|
|||
<exclude>**/GeneratedJavaLexer.class</exclude>
|
||||
<exclude>**/JavadocParser.class</exclude>
|
||||
<exclude>**/Main.class</exclude>
|
||||
<!-- Tests related -->
|
||||
<exclude>**/Input*</exclude>
|
||||
<exclude>**/*Input.class</exclude>
|
||||
<exclude>**/New*</exclude>
|
||||
<exclude>**/CompareTreesWithComments.class</exclude>
|
||||
<exclude>**/UpdateClass.class</exclude>
|
||||
<exclude>**/bug*</exclude>
|
||||
<exclude>**/oneMoreClass.class</exclude>
|
||||
<exclude>**/RightCurlyInput_Other.class</exclude>
|
||||
<exclude>**/JavaNCSSCheckTestInput$1.class</exclude>
|
||||
<exclude>**/test_*</exclude>
|
||||
<exclude>**/WithInner$Inner.class</exclude>
|
||||
<exclude>**/Foo*</exclude>
|
||||
<exclude>**/WithAnon$1.class</exclude>
|
||||
<exclude>**/UncommentedMainTest*</exclude>
|
||||
<exclude>**/Temp*</exclude>
|
||||
<exclude>**/Issue*</exclude>
|
||||
<exclude>**/ParenPadWithSpace.class</exclude>
|
||||
<exclude>**/Main1.class</exclude>
|
||||
<exclude>**/ConfigurationBuilder.class</exclude>
|
||||
<exclude>**/WithAnonymousClass$1.class</exclude>
|
||||
<exclude>**/Test.class</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>check</goal>
|
||||
<goal>testCheck</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package com.google.checkstyle.test.base;
|
||||
|
||||
import static java.text.MessageFormat.format;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
|
@ -10,6 +9,7 @@ import java.io.IOException;
|
|||
import java.io.InputStreamReader;
|
||||
import java.io.LineNumberReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
|
@ -163,7 +163,9 @@ public abstract class BaseCheckTestSupport
|
|||
*/
|
||||
protected String getCheckMessage(Class<? extends AbstractViolationReporter> aClass,
|
||||
String messageKey, Object... arguments) {
|
||||
return format(getCheckMessage(aClass, messageKey), arguments);
|
||||
final MessageFormat formatter = new MessageFormat(getCheckMessage(aClass, messageKey),
|
||||
Locale.ROOT);
|
||||
return formatter.format(arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -175,7 +177,8 @@ public abstract class BaseCheckTestSupport
|
|||
{
|
||||
for (Map.Entry<String, String> entry : messages.entrySet()) {
|
||||
if (messageKey.equals(entry.getKey())) {
|
||||
return format(entry.getValue(), arguments);
|
||||
final MessageFormat formatter = new MessageFormat(entry.getValue(), Locale.ROOT);
|
||||
return formatter.format(arguments);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import java.nio.charset.StandardCharsets;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
|
@ -61,7 +62,7 @@ public class IndentationConfigurationBuilder extends ConfigurationBuilder
|
|||
final int actualIndent = getLineStart(line, tabWidth);
|
||||
|
||||
if (actualIndent != indentInComment) {
|
||||
throw new IllegalStateException(String.format(
|
||||
throw new IllegalStateException(String.format(Locale.ROOT,
|
||||
"File \"%1$s\" has incorrect indentation in comment."
|
||||
+ "Line %2$d: comment:%3$d, actual:%4$d.",
|
||||
aFileName,
|
||||
|
|
@ -75,14 +76,14 @@ public class IndentationConfigurationBuilder extends ConfigurationBuilder
|
|||
}
|
||||
|
||||
if (!isCommentConsistent(comment)) {
|
||||
throw new IllegalStateException(String.format(
|
||||
throw new IllegalStateException(String.format(Locale.ROOT,
|
||||
"File \"%1$s\" has inconsistent comment on line %2$d",
|
||||
aFileName,
|
||||
lineNumber));
|
||||
}
|
||||
}
|
||||
else if (NONEMPTY_LINE_REGEX.matcher(line).matches()) {
|
||||
throw new IllegalStateException(String.format(
|
||||
throw new IllegalStateException(String.format(Locale.ROOT,
|
||||
"File \"%1$s\" has no indentation comment or its format "
|
||||
+ "malformed. Error on line: %2$d(%3$s)",
|
||||
aFileName,
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
|
@ -76,7 +77,7 @@ public class AllChecksPresentOnAvailableChecksPageTest {
|
|||
}
|
||||
|
||||
private static boolean isPresent(String availableChecks, String checkName) {
|
||||
final String linkPattern = String.format(LINK_TEMPLATE, checkName);
|
||||
final String linkPattern = String.format(Locale.ROOT, LINK_TEMPLATE, checkName);
|
||||
return availableChecks.matches(linkPattern);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import java.nio.file.Path;
|
|||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
|
|
@ -100,8 +101,9 @@ public class AllChecksTest extends BaseCheckTestSupport {
|
|||
final int[] acceptableTokens = testedCheck.getAcceptableTokens();
|
||||
|
||||
if (!isSubset(defaultTokens, acceptableTokens)) {
|
||||
String errorMessage = String.format("%s's default tokens must be a subset"
|
||||
+ " of acceptable tokens.", check.getName());
|
||||
String errorMessage = String.format(Locale.ROOT,
|
||||
"%s's default tokens must be a subset"
|
||||
+ " of acceptable tokens.", check.getName());
|
||||
Assert.fail(errorMessage);
|
||||
}
|
||||
}
|
||||
|
|
@ -119,8 +121,9 @@ public class AllChecksTest extends BaseCheckTestSupport {
|
|||
final int[] acceptableTokens = testedCheck.getAcceptableTokens();
|
||||
|
||||
if (!isSubset(requiredTokens, acceptableTokens)) {
|
||||
String errorMessage = String.format("%s's required tokens must be a subset"
|
||||
+ " of acceptable tokens.", check.getName());
|
||||
String errorMessage = String.format(Locale.ROOT,
|
||||
"%s's required tokens must be a subset"
|
||||
+ " of acceptable tokens.", check.getName());
|
||||
Assert.fail(errorMessage);
|
||||
}
|
||||
}
|
||||
|
|
@ -138,8 +141,9 @@ public class AllChecksTest extends BaseCheckTestSupport {
|
|||
final int[] requiredTokens = testedCheck.getRequiredTokens();
|
||||
|
||||
if (!isSubset(requiredTokens, defaultTokens)) {
|
||||
String errorMessage = String.format("%s's required tokens must be a subset"
|
||||
+ " of default tokens.", check.getName());
|
||||
String errorMessage = String.format(Locale.ROOT,
|
||||
"%s's required tokens must be a subset"
|
||||
+ " of default tokens.", check.getName());
|
||||
Assert.fail(errorMessage);
|
||||
}
|
||||
}
|
||||
|
|
@ -155,7 +159,8 @@ public class AllChecksTest extends BaseCheckTestSupport {
|
|||
|
||||
for (String check : checksNames) {
|
||||
if (!checksReferencedInConfig.contains(check)) {
|
||||
String errorMessage = String.format("%s is not referenced in checkstyle_checks.xml", check);
|
||||
String errorMessage = String.format(Locale.ROOT,
|
||||
"%s is not referenced in checkstyle_checks.xml", check);
|
||||
Assert.fail(errorMessage);
|
||||
}
|
||||
}
|
||||
|
|
@ -172,7 +177,7 @@ public class AllChecksTest extends BaseCheckTestSupport {
|
|||
|
||||
for (String moduleName : checkstyleModulesNames) {
|
||||
if (!modulesNamesWhichHaveXdocs.contains(moduleName)) {
|
||||
final String missingModuleMessage = String.format(
|
||||
final String missingModuleMessage = String.format(Locale.ROOT,
|
||||
"Module %s does not have xdoc documentation.",
|
||||
moduleName);
|
||||
Assert.fail(missingModuleMessage);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package com.puppycrawl.tools.checkstyle;
|
||||
|
||||
import static java.text.MessageFormat.format;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
|
@ -11,6 +10,7 @@ import java.io.InputStreamReader;
|
|||
import java.io.LineNumberReader;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
|
@ -172,6 +172,8 @@ public class BaseCheckTestSupport {
|
|||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
return format(pr.getProperty(messageKey), arguments);
|
||||
final MessageFormat formatter = new MessageFormat(pr.getProperty(messageKey),
|
||||
Locale.ROOT);
|
||||
return formatter.format(arguments);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ public class MainTest {
|
|||
exit.checkAssertionAfterwards(new Assertion() {
|
||||
@Override
|
||||
public void checkAssertion() {
|
||||
String usage = String.format("Unrecognized option: -w%n"
|
||||
String usage = String.format(Locale.ROOT, "Unrecognized option: -w%n"
|
||||
+ "usage: java com.puppycrawl.tools.checkstyle.Main [options] -c <config.xml>%n"
|
||||
+ " file...%n"
|
||||
+ " -c <arg> Sets the check configuration file to use.%n"
|
||||
|
|
@ -135,8 +135,8 @@ public class MainTest {
|
|||
exit.checkAssertionAfterwards(new Assertion() {
|
||||
@Override
|
||||
public void checkAssertion() {
|
||||
assertEquals(
|
||||
String.format("Unable to find: src/main/resources/non_existing_config.xml%n"
|
||||
assertEquals(String.format(Locale.ROOT,
|
||||
"Unable to find: src/main/resources/non_existing_config.xml%n"
|
||||
+ "Checkstyle ends with 1 errors.%n"),
|
||||
systemOut.getLog());
|
||||
assertEquals("", systemErr.getLog());
|
||||
|
|
@ -152,7 +152,7 @@ public class MainTest {
|
|||
exit.checkAssertionAfterwards(new Assertion() {
|
||||
@Override
|
||||
public void checkAssertion() {
|
||||
assertEquals(String.format("Invalid output format. "
|
||||
assertEquals(String.format(Locale.ROOT, "Invalid output format. "
|
||||
+ "Found 'xmlp' but expected 'plain' or 'xml'.%n"), systemOut.getLog());
|
||||
assertEquals("", systemErr.getLog());
|
||||
}
|
||||
|
|
@ -187,7 +187,7 @@ public class MainTest {
|
|||
+ " how to configure short name usage http://checkstyle.sourceforge.net/config.html#Packages."
|
||||
+ " Please also recheck that provided ClassLoader to Checker is configured correctly.";
|
||||
final String expectedExceptionMessage =
|
||||
String.format("cannot initialize module TreeWalker - %1$s%n"
|
||||
String.format(Locale.ROOT, "cannot initialize module TreeWalker - %1$s%n"
|
||||
+ "Cause: com.puppycrawl.tools.checkstyle.api.CheckstyleException: %1$s%n"
|
||||
+ "Checkstyle ends with 1 errors.%n", cause);
|
||||
exit.checkAssertionAfterwards(new Assertion() {
|
||||
|
|
@ -208,7 +208,7 @@ public class MainTest {
|
|||
exit.checkAssertionAfterwards(new Assertion() {
|
||||
@Override
|
||||
public void checkAssertion() {
|
||||
assertEquals(String.format("Starting audit...%n"
|
||||
assertEquals(String.format(Locale.ROOT, "Starting audit...%n"
|
||||
+ "Audit done.%n"), systemOut.getLog());
|
||||
assertEquals("", systemErr.getLog());
|
||||
}
|
||||
|
|
@ -230,7 +230,8 @@ public class MainTest {
|
|||
final ResourceBundle compilationProperties =
|
||||
ResourceBundle.getBundle("checkstylecompilation");
|
||||
String version = compilationProperties.getString("checkstyle.compile.version");
|
||||
assertEquals(String.format("<?xml version=\"1.0\" encoding=\"UTF-8\"?>%n"
|
||||
assertEquals(String.format(Locale.ROOT,
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>%n"
|
||||
+ "<checkstyle version=\"%s\">%n"
|
||||
+ "<file name=\"%s\">%n"
|
||||
+ "</file>%n"
|
||||
|
|
@ -249,7 +250,7 @@ public class MainTest {
|
|||
exit.checkAssertionAfterwards(new Assertion() {
|
||||
@Override
|
||||
public void checkAssertion() {
|
||||
assertEquals(String.format("Starting audit...%n"
|
||||
assertEquals(String.format(Locale.ROOT, "Starting audit...%n"
|
||||
+ "Audit done.%n"), systemOut.getLog());
|
||||
assertEquals("", systemErr.getLog());
|
||||
}
|
||||
|
|
@ -269,7 +270,7 @@ public class MainTest {
|
|||
String expectedPath = currentPath
|
||||
+ "/src/test/resources/com/puppycrawl/tools/checkstyle/InputMain.java"
|
||||
.replace("/", File.separator);
|
||||
assertEquals(String.format("Starting audit...%n"
|
||||
assertEquals(String.format(Locale.ROOT, "Starting audit...%n"
|
||||
+ "%1$s:3:14: "
|
||||
+ "warning: Name 'InputMain' must match pattern '^[a-z0-9]*$'.%n"
|
||||
+ "%1$s:5:7: "
|
||||
|
|
@ -294,7 +295,7 @@ public class MainTest {
|
|||
String expectedPath = currentPath
|
||||
+ "/src/test/resources/com/puppycrawl/tools/checkstyle/InputMain.java"
|
||||
.replace("/", File.separator);
|
||||
assertEquals(String.format("Starting audit...%n"
|
||||
assertEquals(String.format(Locale.ROOT, "Starting audit...%n"
|
||||
+ "%1$s:3:14: error: "
|
||||
+ "Name 'InputMain' must match pattern '^[a-z0-9]*$'.%n"
|
||||
+ "%1$s:5:7: error: "
|
||||
|
|
@ -396,7 +397,7 @@ public class MainTest {
|
|||
exit.checkAssertionAfterwards(new Assertion() {
|
||||
@Override
|
||||
public void checkAssertion() {
|
||||
assertEquals(String.format("Starting audit...%n"
|
||||
assertEquals(String.format(Locale.ROOT, "Starting audit...%n"
|
||||
+ "Audit done.%n"), systemOut.getLog());
|
||||
assertEquals("", systemErr.getLog());
|
||||
}
|
||||
|
|
@ -432,10 +433,10 @@ public class MainTest {
|
|||
exit.checkAssertionAfterwards(new Assertion() {
|
||||
@Override
|
||||
public void checkAssertion() {
|
||||
assertTrue(systemOut.getLog().startsWith(String.format(
|
||||
assertTrue(systemOut.getLog().startsWith(String.format(Locale.ROOT,
|
||||
"unable to parse configuration stream - Content is not allowed in prolog.:7:1%n"
|
||||
+ "Cause: org.xml.sax.SAXParseException; systemId: file:")));
|
||||
assertTrue(systemOut.getLog().endsWith(String.format(
|
||||
assertTrue(systemOut.getLog().endsWith(String.format(Locale.ROOT,
|
||||
"com/puppycrawl/tools/checkstyle/config-Incorrect.xml; lineNumber: 7; columnNumber: 1; "
|
||||
+ "Content is not allowed in prolog.%n"
|
||||
+ "Checkstyle ends with 1 errors.%n")));
|
||||
|
|
@ -529,7 +530,7 @@ public class MainTest {
|
|||
sb.append("Starting audit...").append(System.getProperty("line.separator"));
|
||||
String format = "%s.java:%s: warning: File length is %s lines (max allowed is 80).";
|
||||
for (String[] outputValue : outputValues) {
|
||||
String line = String.format(format,
|
||||
String line = String.format(Locale.ROOT, format,
|
||||
expectedPath + outputValue[0], outputValue[1],
|
||||
outputValue[2]);
|
||||
sb.append(line).append(System.getProperty("line.separator"));
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import static org.junit.Assert.assertNull;
|
|||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
@ -147,13 +148,13 @@ public class DetailASTTest {
|
|||
Object[] params = {
|
||||
node, parent, prev, filename, root,
|
||||
};
|
||||
String badParentMsg = MessageFormat.format(
|
||||
"Bad parent node={0} parent={1} filename={3} root={4}",
|
||||
params);
|
||||
MessageFormat badParentFormatter = new MessageFormat(
|
||||
"Bad parent node={0} parent={1} filename={3} root={4}", Locale.ROOT);
|
||||
String badParentMsg = badParentFormatter.format(params);
|
||||
assertEquals(badParentMsg, parent, node.getParent());
|
||||
String badPrevMsg = MessageFormat.format(
|
||||
"Bad prev node={0} prev={2} parent={1} filename={3} root={4}",
|
||||
params);
|
||||
MessageFormat badPrevFormatter = new MessageFormat(
|
||||
"Bad prev node={0} prev={2} parent={1} filename={3} root={4}", Locale.ROOT);
|
||||
String badPrevMsg = badPrevFormatter.format(params);
|
||||
assertEquals(badPrevMsg, prev, node.getPreviousSibling());
|
||||
|
||||
if (node.getFirstChild() != null) {
|
||||
|
|
|
|||
|
|
@ -21,8 +21,6 @@ package com.puppycrawl.tools.checkstyle.checks.coding;
|
|||
|
||||
import static com.puppycrawl.tools.checkstyle.checks.coding.IllegalTokenTextCheck.MSG_KEY;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
@ -71,7 +69,7 @@ public class IllegalTokenTextCheckTest
|
|||
String customMessage = "My custom message";
|
||||
checkConfig.addAttribute("message", customMessage);
|
||||
final String[] expected = {
|
||||
"24:28: " + MessageFormat.format(customMessage, "a href"),
|
||||
"24:28: " + customMessage,
|
||||
};
|
||||
verify(checkConfig, getPath("InputIllegalTokens.java"), expected);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import static org.junit.Assert.fail;
|
|||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.commons.beanutils.ConversionException;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
|
@ -85,7 +86,8 @@ public class RegexpHeaderCheckTest extends BaseFileSetCheckTestSupport {
|
|||
try {
|
||||
String header = "^/**\\n * Licensed to the Apache Software Foundation (ASF)";
|
||||
instance.setHeader(header);
|
||||
fail(String.format("%s should have been thrown", ConversionException.class));
|
||||
fail(String.format(Locale.ROOT, "%s should have been thrown",
|
||||
ConversionException.class));
|
||||
}
|
||||
catch (ConversionException ex) {
|
||||
// expected
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ import java.nio.charset.StandardCharsets;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
|
@ -86,7 +87,7 @@ public class IndentationCheckTest extends BaseCheckTestSupport {
|
|||
final int actualIndent = getLineStart(line, tabWidth);
|
||||
|
||||
if (actualIndent != indentInComment) {
|
||||
throw new IllegalStateException(String.format(
|
||||
throw new IllegalStateException(String.format(Locale.ROOT,
|
||||
"File \"%1$s\" has incorrect indentation in comment."
|
||||
+ "Line %2$d: comment:%3$d, actual:%4$d.",
|
||||
aFileName,
|
||||
|
|
@ -100,14 +101,14 @@ public class IndentationCheckTest extends BaseCheckTestSupport {
|
|||
}
|
||||
|
||||
if (!isCommentConsistent(comment)) {
|
||||
throw new IllegalStateException(String.format(
|
||||
throw new IllegalStateException(String.format(Locale.ROOT,
|
||||
"File \"%1$s\" has inconsistent comment on line %2$d",
|
||||
aFileName,
|
||||
lineNumber));
|
||||
}
|
||||
}
|
||||
else if (NONEMPTY_LINE_REGEX.matcher(line).matches()) {
|
||||
throw new IllegalStateException(String.format(
|
||||
throw new IllegalStateException(String.format(Locale.ROOT,
|
||||
"File \"%1$s\" has no indentation comment or its format "
|
||||
+ "malformed. Error on line: %2$d",
|
||||
aFileName,
|
||||
|
|
|
|||
Loading…
Reference in New Issue