Skip to content

Commit

Permalink
Add a logMissingSignatures parameter, to prevent the logging of missi…
Browse files Browse the repository at this point in the history
…ng signatures
  • Loading branch information
JoepWeijers committed Jun 21, 2019
1 parent df5f00c commit aa9bc5c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/main/java/de/thetaphi/forbiddenapis/Checker.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public static enum Option {
FAIL_ON_MISSING_CLASSES,
FAIL_ON_VIOLATION,
FAIL_ON_UNRESOLVABLE_SIGNATURES,
LOG_MISSING_SIGNATURES,
DISABLE_CLASSLOADING_CACHE
}

Expand Down
8 changes: 5 additions & 3 deletions src/main/java/de/thetaphi/forbiddenapis/Signatures.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ private UnresolvableReporting(boolean reportClassNotFound) {
private final RelatedClassLookup lookup;
private final Logger logger;
private final boolean failOnUnresolvableSignatures;
private final boolean logMissingSignatures;

/** Key is used to lookup forbidden signature in following formats:
* <ul>
Expand All @@ -95,13 +96,14 @@ private UnresolvableReporting(boolean reportClassNotFound) {
private boolean forbidNonPortableRuntime = false;

public Signatures(Checker checker) {
this(checker, checker.logger, checker.options.contains(Option.FAIL_ON_UNRESOLVABLE_SIGNATURES));
this(checker, checker.logger, checker.options.contains(Option.FAIL_ON_UNRESOLVABLE_SIGNATURES), checker.options.contains(Option.LOG_MISSING_SIGNATURES));
}

public Signatures(RelatedClassLookup lookup, Logger logger, boolean failOnUnresolvableSignatures) {
public Signatures(RelatedClassLookup lookup, Logger logger, boolean failOnUnresolvableSignatures, boolean logMissingSignatures) {
this.lookup = lookup;
this.logger = logger;
this.failOnUnresolvableSignatures = failOnUnresolvableSignatures;
this.logMissingSignatures = logMissingSignatures;
}

static String getKey(String internalClassName) {
Expand Down Expand Up @@ -211,7 +213,7 @@ private void addSignature(final String line, final String defaultMessage, final
}

private void reportMissingSignatureClasses(Set<String> missingClasses) {
if (missingClasses.isEmpty()) {
if (missingClasses.isEmpty() || !logMissingSignatures) {
return;
}
logger.warn("Some signatures were ignored because the following classes were not found on classpath:");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,21 @@ public abstract class AbstractCheckMojo extends AbstractMojo implements Constant

/**
* Fail the build if a signature is not resolving. If this parameter is set to
* to false, then such signatures are silently ignored. This is useful in multi-module Maven
* to false, then such signatures are ignored. This is useful in multi-module Maven
* projects where only some modules have the dependency to which the signature file(s) apply.
* @since 1.4
*/
@Parameter(required = false, defaultValue = "true")
private boolean failOnUnresolvableSignatures;

/**
* Output a warning in the log if a signature is missing. If this parameter is set to
* to false, then such signatures are not logged at all. This is useful in multi-module Maven
* projects where only some modules have the dependency to which the signature file(s) apply.
* @since 2.7
*/
@Parameter(required = false, defaultValue = "true")
private boolean logMissingSignatures;

/**
* Fail the build if violations have been found. Defaults to {@code true}.
Expand Down Expand Up @@ -323,6 +332,7 @@ public void info(String msg) {
if (failOnMissingClasses) options.add(FAIL_ON_MISSING_CLASSES);
if (failOnViolation) options.add(FAIL_ON_VIOLATION);
if (failOnUnresolvableSignatures) options.add(FAIL_ON_UNRESOLVABLE_SIGNATURES);
if (logMissingSignatures) options.add(LOG_MISSING_SIGNATURES);
if (disableClassloadingCache) options.add(DISABLE_CLASSLOADING_CACHE);
final Checker checker = new Checker(log, loader, options);

Expand Down

0 comments on commit aa9bc5c

Please sign in to comment.