diff --git a/src/main/java/de/thetaphi/forbiddenapis/AbstractCheckMojo.java b/src/main/java/de/thetaphi/forbiddenapis/AbstractCheckMojo.java index 6d3ff3d0..3a3f2f9c 100644 --- a/src/main/java/de/thetaphi/forbiddenapis/AbstractCheckMojo.java +++ b/src/main/java/de/thetaphi/forbiddenapis/AbstractCheckMojo.java @@ -215,22 +215,19 @@ public void execute() throws MojoExecutionException, MojoFailureException { if (failOnMissingClasses) options.add(FAIL_ON_MISSING_CLASSES); if (failOnViolation) options.add(FAIL_ON_VIOLATION); if (failOnUnresolvableSignatures) options.add(FAIL_ON_UNRESOLVABLE_SIGNATURES); - final Checker checker = new Checker(loader, options) { - @Override - protected void logError(String msg) { + final Checker checker = new Checker(new Logger() { + public void error(String msg) { log.error(msg); } - @Override - protected void logWarn(String msg) { + public void warn(String msg) { log.warn(msg); } - @Override - protected void logInfo(String msg) { + public void info(String msg) { log.info(msg); } - }; + }, loader, options); if (!checker.isSupportedJDK) { final String msg = String.format(Locale.ENGLISH, diff --git a/src/main/java/de/thetaphi/forbiddenapis/AntTask.java b/src/main/java/de/thetaphi/forbiddenapis/AntTask.java index d9579bac..1cbdc891 100644 --- a/src/main/java/de/thetaphi/forbiddenapis/AntTask.java +++ b/src/main/java/de/thetaphi/forbiddenapis/AntTask.java @@ -85,23 +85,20 @@ public void execute() throws BuildException { if (failOnMissingClasses) options.add(FAIL_ON_MISSING_CLASSES); if (failOnViolation) options.add(FAIL_ON_VIOLATION); if (failOnUnresolvableSignatures) options.add(FAIL_ON_UNRESOLVABLE_SIGNATURES); - final Checker checker = new Checker(loader, options) { - @Override - protected void logError(String msg) { + final Checker checker = new Checker(new Logger() { + public void error(String msg) { log(msg, Project.MSG_ERR); } - @Override - protected void logWarn(String msg) { + public void warn(String msg) { // ANT has no real log levels printed, so prefix with "WARNING": log("WARNING: " + msg, Project.MSG_WARN); } - @Override - protected void logInfo(String msg) { + public void info(String msg) { log(msg, Project.MSG_INFO); } - }; + }, loader, options); if (!checker.isSupportedJDK) { final String msg = String.format(Locale.ENGLISH, diff --git a/src/main/java/de/thetaphi/forbiddenapis/Checker.java b/src/main/java/de/thetaphi/forbiddenapis/Checker.java index f05f22ce..21b30a6c 100644 --- a/src/main/java/de/thetaphi/forbiddenapis/Checker.java +++ b/src/main/java/de/thetaphi/forbiddenapis/Checker.java @@ -56,7 +56,7 @@ * and the system classloader. It uses the local classpath in preference to the system classpath * (which violates the spec). */ -public abstract class Checker implements RelatedClassLookup { +public final class Checker implements RelatedClassLookup { public static enum Option { INTERNAL_RUNTIME_FORBIDDEN, @@ -69,6 +69,8 @@ public static enum Option { private final long start; + final Logger logger; + final Set bootClassPathJars; final Set bootClassPathDirs; final ClassLoader loader; @@ -90,15 +92,12 @@ public static enum Option { // descriptors (not internal names) of all annotations that suppress: final Set suppressAnnotations = new LinkedHashSet(); - protected abstract void logError(String msg); - protected abstract void logWarn(String msg); - protected abstract void logInfo(String msg); - - public Checker(ClassLoader loader, Option... options) { - this(loader, (options.length == 0) ? EnumSet.noneOf(Option.class) : EnumSet.copyOf(Arrays.asList(options))); + public Checker(Logger logger, ClassLoader loader, Option... options) { + this(logger, loader, (options.length == 0) ? EnumSet.noneOf(Option.class) : EnumSet.copyOf(Arrays.asList(options))); } - public Checker(ClassLoader loader, EnumSet