Skip to content

Commit 63bae01

Browse files
committed
Limit line length / number of missing classes to be reported on signature parsing
1 parent 3a19ec9 commit 63bae01

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

src/main/java/de/thetaphi/forbiddenapis/Checker.java

+13-8
Original file line numberDiff line numberDiff line change
@@ -447,16 +447,21 @@ private void addSignature(final String line, final String defaultMessage, final
447447
}
448448

449449
private void reportMissingSignatureClasses(Set<String> missingClasses) {
450-
if (!missingClasses.isEmpty()) {
451-
final StringBuilder sb = new StringBuilder("Some signatures were ignored because the following classes were not found on classpath: ");
452-
boolean comma = false;
453-
for (String s : missingClasses) {
454-
if (comma) sb.append(", ");
455-
comma = true;
456-
sb.append(s);
450+
if (missingClasses.isEmpty()) {
451+
return;
452+
}
453+
logger.warn("Some signatures were ignored because the following classes were not found on classpath:");
454+
final StringBuilder sb = new StringBuilder();
455+
int count = 0;
456+
for (String s : missingClasses) {
457+
sb.append(count == 0 ? " " : ", ").append(s);
458+
count++;
459+
if (sb.length() >= 70) {
460+
sb.append(",... (and ").append(missingClasses.size() - count).append(" more).");
461+
break;
457462
}
458-
logger.warn(sb.toString());
459463
}
464+
logger.warn(sb.toString());
460465
}
461466

462467
/** Reads a list of bundled API signatures from classpath. */

src/test/antunit/TestInlineSignatures.xml

+4-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@
9797
java.lang.String#forbiddenFoobarField @ should be ignored
9898
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)
9999
</forbiddenapis>
100-
<au:assertLogContains level="warning" text="Some signatures were ignored because the following classes were not found on classpath: foo.bar.ForbiddenApis"/>
100+
<au:assertLogContains level="warning" text="Some signatures were ignored because the following classes were not found on classpath:"/>
101+
<au:assertLogContains level="warning" text=" foo.bar.ForbiddenApis"/>
101102
<au:assertLogContains level="warning" text="Method not found while parsing signature: java.lang.String#forbiddenFoobarMethod() [signature ignored]"/>
102103
<au:assertLogContains level="warning" text="Field not found while parsing signature: java.lang.String#forbiddenFoobarField [signature ignored]"/>
103104
</target>
@@ -110,7 +111,8 @@
110111
java.lang.String#forbiddenFoobarField @ should be ignored
111112
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)
112113
</forbiddenapis>
113-
<au:assertLogContains level="warning" text="Some signatures were ignored because the following classes were not found on classpath: foo.bar.ForbiddenApis"/>
114+
<au:assertLogContains level="warning" text="Some signatures were ignored because the following classes were not found on classpath:"/>
115+
<au:assertLogContains level="warning" text=" foo.bar.ForbiddenApis"/>
114116
<au:assertLogContains level="warning" text="Method not found while parsing signature: java.lang.String#forbiddenFoobarMethod() [signature ignored]"/>
115117
<au:assertLogContains level="warning" text="Field not found while parsing signature: java.lang.String#forbiddenFoobarField [signature ignored]"/>
116118
</target>

src/test/antunit/TestMavenMojo.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@
8484
<sysproperty key="antunit.signatures" value="foo.bar.ForbiddenApis#testMethod()&#10;java.lang.String#forbiddenFoobarMethod()&#10;java.lang.String#forbiddenFoobarField"/>
8585
<sysproperty key="antunit.failOnUnresolvableSignatures" value="false"/>
8686
</artifact:mvn>
87-
<au:assertLogContains text="Some signatures were ignored because the following classes were not found on classpath: foo.bar.ForbiddenApis"/>
87+
<au:assertLogContains text="Some signatures were ignored because the following classes were not found on classpath:"/>
88+
<au:assertLogContains text=" foo.bar.ForbiddenApis"/>
8889
<au:assertLogContains text="Method not found while parsing signature: java.lang.String#forbiddenFoobarMethod() [signature ignored]"/>
8990
<au:assertLogContains text="Field not found while parsing signature: java.lang.String#forbiddenFoobarField [signature ignored]"/>
9091
</target>

0 commit comments

Comments
 (0)