Skip to content

Commit

Permalink
Limit line length / number of missing classes to be reported on signa…
Browse files Browse the repository at this point in the history
…ture parsing
  • Loading branch information
uschindler committed Mar 30, 2018
1 parent 3a19ec9 commit 44fe193
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
21 changes: 13 additions & 8 deletions src/main/java/de/thetaphi/forbiddenapis/Checker.java
Original file line number Diff line number Diff line change
Expand Up @@ -447,16 +447,21 @@ private void addSignature(final String line, final String defaultMessage, final
}

private void reportMissingSignatureClasses(Set<String> missingClasses) {
if (!missingClasses.isEmpty()) {
final StringBuilder sb = new StringBuilder("Some signatures were ignored because the following classes were not found on classpath: ");
boolean comma = false;
for (String s : missingClasses) {
if (comma) sb.append(", ");
comma = true;
sb.append(s);
if (missingClasses.isEmpty()) {
return;
}
logger.warn("Some signatures were ignored because the following classes were not found on classpath:");
final StringBuilder sb = new StringBuilder();
int count = 0;
for (String s : missingClasses) {
sb.append(count == 0 ? " " : ", ").append(s);
count++;
if (sb.length() >= 70) {
sb.append(",... (and ").append(missingClasses.size() - count).append(" more).");
break;
}
logger.warn(sb.toString());
}
logger.warn(sb.toString());
}

/** Reads a list of bundled API signatures from classpath. */
Expand Down
6 changes: 4 additions & 2 deletions src/test/antunit/TestInlineSignatures.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@
java.lang.String#forbiddenFoobarField @ should be ignored
java.awt.Color @ Color is disallowed, thats not bad, because ANT has no colors... (this was just added to don't fail because of missing signatures)
</forbiddenapis>
<au:assertLogContains level="warning" text="Some signatures were ignored because the following classes were not found on classpath: foo.bar.ForbiddenApis"/>
<au:assertLogContains level="warning" text="Some signatures were ignored because the following classes were not found on classpath:"/>
<au:assertLogContains level="warning" text=" foo.bar.ForbiddenApis"/>
<au:assertLogContains level="warning" text="Method not found while parsing signature: java.lang.String#forbiddenFoobarMethod() [signature ignored]"/>
<au:assertLogContains level="warning" text="Field not found while parsing signature: java.lang.String#forbiddenFoobarField [signature ignored]"/>
</target>
Expand All @@ -110,7 +111,8 @@
java.lang.String#forbiddenFoobarField @ should be ignored
java.awt.Color @ Color is disallowed, thats not bad, because ANT has no colors... (this was just added to don't fail because of missing signatures)
</forbiddenapis>
<au:assertLogContains level="warning" text="Some signatures were ignored because the following classes were not found on classpath: foo.bar.ForbiddenApis"/>
<au:assertLogContains level="warning" text="Some signatures were ignored because the following classes were not found on classpath:"/>
<au:assertLogContains level="warning" text=" foo.bar.ForbiddenApis"/>
<au:assertLogContains level="warning" text="Method not found while parsing signature: java.lang.String#forbiddenFoobarMethod() [signature ignored]"/>
<au:assertLogContains level="warning" text="Field not found while parsing signature: java.lang.String#forbiddenFoobarField [signature ignored]"/>
</target>
Expand Down
3 changes: 2 additions & 1 deletion src/test/antunit/TestMavenMojo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@
<sysproperty key="antunit.signatures" value="foo.bar.ForbiddenApis#testMethod()&#10;java.lang.String#forbiddenFoobarMethod()&#10;java.lang.String#forbiddenFoobarField"/>
<sysproperty key="antunit.failOnUnresolvableSignatures" value="false"/>
</artifact:mvn>
<au:assertLogContains text="Some signatures were ignored because the following classes were not found on classpath: foo.bar.ForbiddenApis"/>
<au:assertLogContains text="Some signatures were ignored because the following classes were not found on classpath:"/>
<au:assertLogContains text=" foo.bar.ForbiddenApis"/>
<au:assertLogContains text="Method not found while parsing signature: java.lang.String#forbiddenFoobarMethod() [signature ignored]"/>
<au:assertLogContains text="Field not found while parsing signature: java.lang.String#forbiddenFoobarField [signature ignored]"/>
</target>
Expand Down

0 comments on commit 44fe193

Please sign in to comment.