diff --git a/src/main/java/de/thetaphi/forbiddenapis/AbstractCheckMojo.java b/src/main/java/de/thetaphi/forbiddenapis/AbstractCheckMojo.java index afe1bf5e..6d3ff3d0 100644 --- a/src/main/java/de/thetaphi/forbiddenapis/AbstractCheckMojo.java +++ b/src/main/java/de/thetaphi/forbiddenapis/AbstractCheckMojo.java @@ -16,6 +16,8 @@ * limitations under the License. */ +import static de.thetaphi.forbiddenapis.Checker.Option.*; + import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; @@ -32,6 +34,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.Arrays; +import java.util.EnumSet; import java.util.List; import java.util.Locale; @@ -207,7 +210,12 @@ public void execute() throws MojoExecutionException, MojoFailureException { ClassLoader.getSystemClassLoader(); try { - final Checker checker = new Checker(loader, internalRuntimeForbidden, failOnMissingClasses, failOnViolation, failOnUnresolvableSignatures) { + final EnumSet options = EnumSet.noneOf(Checker.Option.class); + if (internalRuntimeForbidden) options.add(INTERNAL_RUNTIME_FORBIDDEN); + 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) { log.error(msg); diff --git a/src/main/java/de/thetaphi/forbiddenapis/AntTask.java b/src/main/java/de/thetaphi/forbiddenapis/AntTask.java index 5771e212..d9579bac 100644 --- a/src/main/java/de/thetaphi/forbiddenapis/AntTask.java +++ b/src/main/java/de/thetaphi/forbiddenapis/AntTask.java @@ -18,6 +18,8 @@ * limitations under the License. */ +import static de.thetaphi.forbiddenapis.Checker.Option.*; + import org.apache.tools.ant.AntClassLoader; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; @@ -36,6 +38,7 @@ import java.io.IOException; import java.io.File; import java.util.ArrayList; +import java.util.EnumSet; import java.util.Iterator; import java.util.List; import java.util.Locale; @@ -77,7 +80,12 @@ public void execute() throws BuildException { classFiles.setProject(getProject()); apiSignatures.setProject(getProject()); - final Checker checker = new Checker(loader, internalRuntimeForbidden, failOnMissingClasses, failOnViolation, failOnUnresolvableSignatures) { + final EnumSet options = EnumSet.noneOf(Checker.Option.class); + if (internalRuntimeForbidden) options.add(INTERNAL_RUNTIME_FORBIDDEN); + 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) { log(msg, Project.MSG_ERR); diff --git a/src/main/java/de/thetaphi/forbiddenapis/Checker.java b/src/main/java/de/thetaphi/forbiddenapis/Checker.java index 2d4fdcd6..56912e32 100644 --- a/src/main/java/de/thetaphi/forbiddenapis/Checker.java +++ b/src/main/java/de/thetaphi/forbiddenapis/Checker.java @@ -36,6 +36,7 @@ import java.net.URLConnection; import java.util.Arrays; import java.util.Collections; +import java.util.EnumSet; import java.util.HashMap; import java.util.LinkedHashSet; import java.util.List; @@ -56,6 +57,13 @@ * (which violates the spec). */ public abstract class Checker implements RelatedClassLookup { + + public static enum Option { + INTERNAL_RUNTIME_FORBIDDEN, + FAIL_ON_MISSING_CLASSES, + FAIL_ON_VIOLATION, + FAIL_ON_UNRESOLVABLE_SIGNATURES + } public final boolean isSupportedJDK; @@ -64,7 +72,7 @@ public abstract class Checker implements RelatedClassLookup { final Set bootClassPathJars; final Set bootClassPathDirs; final ClassLoader loader; - final boolean internalRuntimeForbidden, failOnMissingClasses, failOnViolation, defaultFailOnUnresolvableSignatures; + final EnumSet