Skip to content

Commit

Permalink
Add a logMissingClassFiles parameter, to prevent the logging of missi…
Browse files Browse the repository at this point in the history
…ng class files
  • Loading branch information
Joep Weijers authored and Joep Weijers committed Jul 8, 2019
1 parent aa9bc5c commit 9b3bc63
Show file tree
Hide file tree
Showing 2 changed files with 19 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 @@ -55,6 +55,7 @@ public static enum Option {
FAIL_ON_VIOLATION,
FAIL_ON_UNRESOLVABLE_SIGNATURES,
LOG_MISSING_SIGNATURES,
LOG_MISSING_CLASS_FILES,
DISABLE_CLASSLOADING_CACHE
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@ public abstract class AbstractCheckMojo extends AbstractMojo implements Constant
*/
@Parameter(required = false, defaultValue = "true")
private boolean logMissingSignatures;

/**
* Output a warning in the log if a the classes directory is missing or does not contain class
* files. If this parameter is set to to false, then such directories are not logged at all.
* This is useful in multi-module Maven projects where not all modules have test classes.
* @since 2.8
*/
@Parameter(required = false, defaultValue = "true")
private boolean logMissingClassFiles;

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

Expand All @@ -357,7 +367,9 @@ public void info(String msg) {
log.info("Scanning for classes to check...");
final File classesDirectory = getClassesDirectory();
if (!classesDirectory.exists()) {
log.warn("Classes directory does not exist, forbiddenapis check skipped: " + classesDirectory);
if (logMissingClassFiles) {
log.warn("Classes directory does not exist, forbiddenapis check skipped: " + classesDirectory);
}
return;
}
final DirectoryScanner ds = new DirectoryScanner();
Expand All @@ -369,9 +381,11 @@ public void info(String msg) {
ds.scan();
final String[] files = ds.getIncludedFiles();
if (files.length == 0) {
log.warn(String.format(Locale.ENGLISH,
"No classes found in '%s' (includes=%s, excludes=%s), forbiddenapis check skipped.",
classesDirectory.toString(), Arrays.toString(includes), Arrays.toString(excludes)));
if (logMissingClassFiles) {
log.warn(String.format(Locale.ENGLISH,
"No classes found in '%s' (includes=%s, excludes=%s), forbiddenapis check skipped.",
classesDirectory.toString(), Arrays.toString(includes), Arrays.toString(excludes)));
}
return;
}

Expand Down

0 comments on commit 9b3bc63

Please sign in to comment.