Skip to content

Commit

Permalink
Issue #2109: fix for build failures
Browse files Browse the repository at this point in the history
  • Loading branch information
romani committed Oct 31, 2015
1 parent 6af35e9 commit c43ee5c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 45 deletions.
6 changes: 6 additions & 0 deletions config/pmd.xml
Expand Up @@ -186,6 +186,12 @@
<property name="violationSuppressXPath" value="//ClassOrInterfaceDeclaration[@Image='Main']"/>
</properties>
</rule>
<rule ref="rulesets/java/logging-java.xml/AvoidPrintStackTrace">
<properties>
<!-- it is ok to use print stack trace in CLI class -->
<property name="violationSuppressXPath" value="//ClassOrInterfaceDeclaration[@Image='Main']"/>
</properties>
</rule>

<rule ref="rulesets/java/migrating.xml"/>

Expand Down
2 changes: 1 addition & 1 deletion config/suppressions.xml
Expand Up @@ -100,7 +100,7 @@

<!-- Suppressions from PMD configuration-->
<!-- validateCli is not reasonable to split as encapsulation of logic will be damaged -->
<suppress checks="CyclomaticComplexity" files="Main\.java" lines="179"/>
<suppress checks="CyclomaticComplexity" files="Main\.java" lines="169"/>
<!-- JavadocMethodCheck, JavadocStyleCheck, JavadocUtils.getJavadocTags() - deprecated -->
<suppress checks="CyclomaticComplexity" files="JavadocMethodCheck\.java"/>
<suppress checks="CyclomaticComplexity" files="JavadocStyleCheck\.java"/>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/puppycrawl/tools/checkstyle/Checker.java
Expand Up @@ -277,6 +277,7 @@ public int process(List<File> files) throws CheckstyleException {
fireFileFinished(fileName);
}
catch (Exception ex) {
// We need to catch all exception to put a reason failure(file name) in exception
throw new CheckstyleException("Exception happens during processing of "
+ file.getPath(), ex);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/puppycrawl/tools/checkstyle/Main.java
Expand Up @@ -82,8 +82,8 @@ private Main() {
* is the number of errors found in all the files.
* @param args the command line arguments.
* @throws FileNotFoundException if there is a problem with files access
* @noinspection CallToPrintStackTrace
**/
@SuppressWarnings("CallToPrintStackTrace")
public static void main(String... args) throws FileNotFoundException {
int errorCounter = 0;
boolean cliViolations = false;
Expand Down
60 changes: 17 additions & 43 deletions src/test/java/com/puppycrawl/tools/checkstyle/MainTest.java
Expand Up @@ -147,11 +147,11 @@ public void testNonExistingConfigFile()
exit.checkAssertionAfterwards(new Assertion() {
@Override
public void checkAssertion() {
assertEquals(String.format(Locale.ROOT,
"Unable to find: src/main/resources/non_existing_config.xml%n"
+ "Checkstyle ends with 1 errors.%n"),
assertEquals(String.format(Locale.ROOT, "Checkstyle ends with 1 errors.%n"),
systemOut.getLog());
assertEquals("", systemErr.getLog());
final String cause = "com.puppycrawl.tools.checkstyle.api.CheckstyleException:"
+ " Unable to find: src/main/resources/non_existing_config.xml";
assertTrue(systemErr.getLog().startsWith(cause));
}
});
Main.main("-c", "src/main/resources/non_existing_config.xml",
Expand All @@ -176,38 +176,18 @@ public void checkAssertion() {
@Test
public void testNonExistingClass() throws Exception {
exit.expectSystemExitWithStatus(-2);
final String cause = "Unable to instantiate 'NonExistingClass' class,"
+ " it is also not possible to instantiate it as"
+ " com.puppycrawl.tools.checkstyle.checks.annotation.NonExistingClass,"
+ " com.puppycrawl.tools.checkstyle.checks.blocks.NonExistingClass,"
+ " com.puppycrawl.tools.checkstyle.checks.coding.NonExistingClass,"
+ " com.puppycrawl.tools.checkstyle.checks.design.NonExistingClass,"
+ " com.puppycrawl.tools.checkstyle.checks.header.NonExistingClass,"
+ " com.puppycrawl.tools.checkstyle.checks.imports.NonExistingClass,"
+ " com.puppycrawl.tools.checkstyle.checks.indentation.NonExistingClass,"
+ " com.puppycrawl.tools.checkstyle.checks.javadoc.NonExistingClass,"
+ " com.puppycrawl.tools.checkstyle.checks.metrics.NonExistingClass,"
+ " com.puppycrawl.tools.checkstyle.checks.modifier.NonExistingClass,"
+ " com.puppycrawl.tools.checkstyle.checks.naming.NonExistingClass,"
+ " com.puppycrawl.tools.checkstyle.checks.regexp.NonExistingClass,"
+ " com.puppycrawl.tools.checkstyle.checks.sizes.NonExistingClass,"
+ " com.puppycrawl.tools.checkstyle.checks.whitespace.NonExistingClass,"
+ " com.puppycrawl.tools.checkstyle.checks.NonExistingClass,"
+ " com.puppycrawl.tools.checkstyle.filters.NonExistingClass,"
+ " com.puppycrawl.tools.checkstyle.NonExistingClass."
+ " Please recheck that class name is specified as canonical name or read"
+ " 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(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() {
@Override
public void checkAssertion() {
final String expectedExceptionMessage =
String.format(Locale.ROOT, "Checkstyle ends with 1 errors.%n");
assertEquals(expectedExceptionMessage, systemOut.getLog());
assertEquals("", systemErr.getLog());

final String cause = "com.puppycrawl.tools.checkstyle.api.CheckstyleException:"
+ " cannot initialize module TreeWalker - "
+ "Unable to instantiate 'NonExistingClass' class, "
+ "it is also not possible to instantiate it as ";
assertTrue(systemErr.getLog().startsWith(cause));
}
});

Expand Down Expand Up @@ -438,16 +418,10 @@ public void testExistingIncorrectConfigFile()
exit.checkAssertionAfterwards(new Assertion() {
@Override
public void checkAssertion() {
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(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")));
assertEquals("", systemErr.getLog());
assertEquals("Checkstyle ends with 1 errors.\n", systemOut.getLog());
assertTrue(systemErr.getLog().startsWith("com.puppycrawl.tools.checkstyle.api."
+ "CheckstyleException: unable to parse configuration stream"
+ " - Content is not allowed in prolog.:7:1\n"));
}
});
Main.main("-c", getPath("config-Incorrect.xml"),
Expand Down Expand Up @@ -596,7 +570,7 @@ public void testFileReferenceDuringException() throws Exception {
@Override
public void checkAssertion() {
assertEquals(expectedExceptionMessage, systemOut.getLog());
String exceptionFirstLine = "com.puppycrawl.tools.checkstyle.api."
final String exceptionFirstLine = "com.puppycrawl.tools.checkstyle.api."
+ "CheckstyleException: Exception happens during processing of "
+ "src/test/resources-noncompilable/com/puppycrawl/tools/"
+ "checkstyle/InputIncorrectClass.java\n";
Expand Down

0 comments on commit c43ee5c

Please sign in to comment.