diff --git a/build.xml b/build.xml index f09000cd..f5a111cc 100644 --- a/build.xml +++ b/build.xml @@ -97,7 +97,7 @@ - + @@ -333,7 +333,7 @@ - + @@ -424,7 +424,7 @@ description="Checks bundled signatures file corresponding to the current JVM. Run after every update!"/> - + diff --git a/src/main/java/de/thetaphi/forbiddenapis/AntTask.java b/src/main/java/de/thetaphi/forbiddenapis/AntTask.java index 1cbdc891..cf5b2617 100644 --- a/src/main/java/de/thetaphi/forbiddenapis/AntTask.java +++ b/src/main/java/de/thetaphi/forbiddenapis/AntTask.java @@ -18,325 +18,23 @@ * limitations under the License. */ -import static de.thetaphi.forbiddenapis.Checker.Option.*; +import java.util.Locale; -import org.apache.tools.ant.AntClassLoader; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; -import org.apache.tools.ant.ProjectComponent; -import org.apache.tools.ant.Task; -import org.apache.tools.ant.types.Path; -import org.apache.tools.ant.types.FileList; -import org.apache.tools.ant.types.FileSet; -import org.apache.tools.ant.types.Reference; -import org.apache.tools.ant.types.Resource; -import org.apache.tools.ant.types.ResourceCollection; -import org.apache.tools.ant.types.resources.FileResource; -import org.apache.tools.ant.types.resources.Resources; -import org.apache.tools.ant.types.resources.StringResource; - -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; /** - * Task to check if a set of class files contains calls to forbidden APIs - * from a given classpath and list of API signatures (either inline or as pointer to files). - * In contrast to other ANT tasks, this tool does only visit the given classpath - * and the system classloader, not ANT's class loader. + * {@inheritDoc} + * @deprecated Use {@link de.thetaphi.forbiddenapis.ant.AntTask} instead. */ -public final class AntTask extends Task { - - private final Resources classFiles = new Resources(); - private final Resources apiSignatures = new Resources(); - private final List bundledSignatures = new ArrayList(); - private final List suppressAnnotations = new ArrayList(); - private Path classpath = null; +@Deprecated +public final class AntTask extends de.thetaphi.forbiddenapis.ant.AntTask { - private boolean failOnUnsupportedJava = false; - private boolean internalRuntimeForbidden = false; - private boolean restrictClassFilename = true; - private boolean failOnMissingClasses = true; - private boolean failOnUnresolvableSignatures = true; - private boolean failOnViolation = true; - private boolean ignoreEmptyFileset = false; - @Override public void execute() throws BuildException { - AntClassLoader antLoader = null; - try { - final ClassLoader loader; - if (classpath != null) { - classpath.setProject(getProject()); - loader = antLoader = getProject().createClassLoader(ClassLoader.getSystemClassLoader(), classpath); - antLoader.setParentFirst(true); // use default classloader delegation - } else { - loader = ClassLoader.getSystemClassLoader(); - } - classFiles.setProject(getProject()); - apiSignatures.setProject(getProject()); - - 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(new Logger() { - public void error(String msg) { - log(msg, Project.MSG_ERR); - } - - public void warn(String msg) { - // ANT has no real log levels printed, so prefix with "WARNING": - log("WARNING: " + msg, Project.MSG_WARN); - } - - public void info(String msg) { - log(msg, Project.MSG_INFO); - } - }, loader, options); - - if (!checker.isSupportedJDK) { - final String msg = String.format(Locale.ENGLISH, - "Your Java runtime (%s %s) is not supported by <%s/>. Please run the checks with a supported JDK!", - System.getProperty("java.runtime.name"), System.getProperty("java.runtime.version"), getTaskName()); - if (failOnUnsupportedJava) { - throw new BuildException(msg); - } else { - log("WARNING: " + msg, Project.MSG_WARN); - return; - } - } - - for (final SuppressAnnotationType a : suppressAnnotations) { - checker.addSuppressAnnotation(a.getClassname()); - } - - try { - for (BundledSignaturesType bs : bundledSignatures) { - final String name = bs.getName(); - if (name == null) { - throw new BuildException(" must have the mandatory attribute 'name' referring to a bundled signatures file."); - } - log("Reading bundled API signatures: " + name, Project.MSG_INFO); - checker.parseBundledSignatures(name, null); - } - - @SuppressWarnings("unchecked") - final Iterator iter = apiSignatures.iterator(); - while (iter.hasNext()) { - final Resource r = iter.next(); - if (r instanceof StringResource) { - final String s = ((StringResource) r).getValue(); - if (s != null && s.trim().length() > 0) { - log("Reading inline API signatures...", Project.MSG_INFO); - checker.parseSignaturesString(s); - } - } else { - log("Reading API signatures: " + r, Project.MSG_INFO); - checker.parseSignaturesFile(r.getInputStream()); - } - } - } catch (IOException ioe) { - throw new BuildException("IO problem while reading files with API signatures: " + ioe); - } catch (ParseException pe) { - throw new BuildException("Parsing signatures failed: " + pe.getMessage()); - } - - if (checker.hasNoSignatures()) { - throw new BuildException("No API signatures found; use signaturesFile=, , or inner text to define those!"); - } - - log("Loading classes to check...", Project.MSG_INFO); - try { - @SuppressWarnings("unchecked") - final Iterator iter = classFiles.iterator(); - boolean foundClass = false; - while (iter.hasNext()) { - final Resource r = iter.next(); - final String name = r.getName(); - if (restrictClassFilename && name != null && !name.endsWith(".class")) { - continue; - } - checker.addClassToCheck(r.getInputStream()); - foundClass = true; - } - if (!foundClass) { - if (ignoreEmptyFileset) { - log("There is no or other resource collection given, or the collection does not contain any class files to check.", Project.MSG_WARN); - log("Scanned 0 class files.", Project.MSG_INFO); - return; - } else { - throw new BuildException("There is no or other resource collection given, or the collection does not contain any class files to check."); - } - } - } catch (IOException ioe) { - throw new BuildException("Failed to load one of the given class files: " + ioe); - } - - log("Scanning for API signatures and dependencies...", Project.MSG_INFO); - try { - checker.run(); - } catch (ForbiddenApiException fae) { - throw new BuildException(fae.getMessage()); - } - } finally { - if (antLoader != null) antLoader.cleanup(); - } + log(String.format(Locale.ENGLISH, "DEPRECATED-WARNING: Please change your build.xml to use new task class '%s'", + getClass().getSuperclass().getName()), Project.MSG_WARN); + super.execute(); } - /** Set of class files to check */ - public void add(ResourceCollection rc) { - classFiles.add(rc); - } - - /** Sets a directory as base for class files. The implicit pattern '**/*.class' is used to only scan class files. */ - public void setDir(File dir) { - final FileSet fs = new FileSet(); - fs.setProject(getProject()); - fs.setDir(dir); - // needed if somebody sets restrictClassFilename=false: - fs.setIncludes("**/*.class"); - classFiles.add(fs); - } - - private T addSignaturesResource(T res) { - ((ProjectComponent) res).setProject(getProject()); - apiSignatures.add(res); - return res; - } - - /** Set of files with API signatures as nested element */ - public FileSet createSignaturesFileSet() { - return addSignaturesResource(new FileSet()); - } - - /** List of files with API signatures as nested element */ - public FileList createSignaturesFileList() { - return addSignaturesResource(new FileList()); - } - - /** Single file with API signatures as nested element */ - public FileResource createSignaturesFile() { - return addSignaturesResource(new FileResource()); - } - - /** A file with API signatures signaturesFile= attribute */ - public void setSignaturesFile(File file) { - createSignaturesFile().setFile(file); - } - - /** Support for API signatures list as nested text */ - public void addText(String text) { - addSignaturesResource(new StringResource(text)); - } - - /** Creates a bundled signatures instance */ - public BundledSignaturesType createBundledSignatures() { - final BundledSignaturesType s = new BundledSignaturesType(); - s.setProject(getProject()); - bundledSignatures.add(s); - return s; - } - - /** A bundled signatures name */ - public void setBundledSignatures(String name) { - createBundledSignatures().setName(name); - } - - /** Creates a instance of an annotation class name that suppresses error reporting in classes/methods/fields. */ - public SuppressAnnotationType createSuppressAnnotation() { - final SuppressAnnotationType s = new SuppressAnnotationType(); - s.setProject(getProject()); - suppressAnnotations.add(s); - return s; - } - - /** Class name of annotation that suppresses error reporting in classes/methods/fields. */ - public void setSuppressAnnotation(String classname) { - createSuppressAnnotation().setClassname(classname); - } - - /** Classpath as classpath= attribute */ - public void setClasspath(Path classpath) { - createClasspath().append(classpath); - } - - /** Classpath as classpathRef= attribute */ - public void setClasspathRef(Reference r) { - createClasspath().setRefid(r); - } - - /** Classpath as nested element */ - public Path createClasspath() { - if (this.classpath == null) { - this.classpath = new Path(getProject()); - } - return this.classpath.createPath(); - } - - /** - * Fail the build, if the bundled ASM library cannot read the class file format - * of the runtime library or the runtime library cannot be discovered. - * Defaults to {@code false}. - */ - public void setFailOnUnsupportedJava(boolean failOnUnsupportedJava) { - this.failOnUnsupportedJava = failOnUnsupportedJava; - } - - /** - * Fail the build, if a referenced class is missing. This requires - * that you pass the whole classpath including all dependencies. - * If you don't have all classes in the filesets, the application classes - * must be reachable through this classpath, too. - * Defaults to {@code true}. - */ - public void setFailOnMissingClasses(boolean failOnMissingClasses) { - this.failOnMissingClasses = failOnMissingClasses; - } - - /** - * Fail the build if a signature is not resolving. If this parameter is set to - * to false, then such signatures are silently ignored. - * Defaults to {@code true}. - */ - public void setFailOnUnresolvableSignatures(boolean failOnUnresolvableSignatures) { - this.failOnUnresolvableSignatures = failOnUnresolvableSignatures; - } - - /** - * Forbids calls to classes from the internal java runtime (like sun.misc.Unsafe) - * Defaults to {@code false}. - */ - public void setInternalRuntimeForbidden(boolean internalRuntimeForbidden) { - this.internalRuntimeForbidden = internalRuntimeForbidden; - } - - /** Automatically restrict resource names included to files with a name ending in '.class'. - * This makes filesets easier, as the includes="**/*.class" is not needed. - * Defaults to {@code true}. - */ - public void setRestrictClassFilename(boolean restrictClassFilename) { - this.restrictClassFilename = restrictClassFilename; - } - - /** Ignore empty fileset/resource collection and print a warning instead. - * Defaults to {@code false}. - */ - public void setIgnoreEmptyFileSet(boolean ignoreEmptyFileset) { - this.ignoreEmptyFileset = ignoreEmptyFileset; - } - - /** - * Fail the build if violations have been found. If this parameter is set to {@code false}, - * then the build will continue even if violations have been found. - * Defaults to {@code true}. - */ - public void setFailOnViolation(boolean failOnViolation) { - this.failOnViolation = failOnViolation; - } } diff --git a/src/main/java/de/thetaphi/forbiddenapis/WrapperRuntimeException.java b/src/main/java/de/thetaphi/forbiddenapis/WrapperRuntimeException.java index 72a404d7..4ff0751f 100644 --- a/src/main/java/de/thetaphi/forbiddenapis/WrapperRuntimeException.java +++ b/src/main/java/de/thetaphi/forbiddenapis/WrapperRuntimeException.java @@ -17,7 +17,7 @@ */ @SuppressWarnings("serial") -public final class WrapperRuntimeException extends RuntimeException { +final class WrapperRuntimeException extends RuntimeException { public WrapperRuntimeException(Exception e) { super(e); diff --git a/src/main/java/de/thetaphi/forbiddenapis/ant/AntTask.java b/src/main/java/de/thetaphi/forbiddenapis/ant/AntTask.java new file mode 100644 index 00000000..8a25095c --- /dev/null +++ b/src/main/java/de/thetaphi/forbiddenapis/ant/AntTask.java @@ -0,0 +1,347 @@ +package de.thetaphi.forbiddenapis.ant; + +/* + * (C) Copyright Uwe Schindler (Generics Policeman) and others. + * Parts of this work are licensed to the Apache Software Foundation (ASF) + * under one or more contributor license agreements. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * 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; +import org.apache.tools.ant.ProjectComponent; +import org.apache.tools.ant.Task; +import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.types.FileList; +import org.apache.tools.ant.types.FileSet; +import org.apache.tools.ant.types.Reference; +import org.apache.tools.ant.types.Resource; +import org.apache.tools.ant.types.ResourceCollection; +import org.apache.tools.ant.types.resources.FileResource; +import org.apache.tools.ant.types.resources.Resources; +import org.apache.tools.ant.types.resources.StringResource; + +import de.thetaphi.forbiddenapis.Checker; +import de.thetaphi.forbiddenapis.ForbiddenApiException; +import de.thetaphi.forbiddenapis.Logger; +import de.thetaphi.forbiddenapis.ParseException; + +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; + +/** + * Task to check if a set of class files contains calls to forbidden APIs + * from a given classpath and list of API signatures (either inline or as pointer to files). + * In contrast to other ANT tasks, this tool does only visit the given classpath + * and the system classloader, not ANT's class loader. + */ +public class AntTask extends Task { + + private final Resources classFiles = new Resources(); + private final Resources apiSignatures = new Resources(); + private final List bundledSignatures = new ArrayList(); + private final List suppressAnnotations = new ArrayList(); + private Path classpath = null; + + private boolean failOnUnsupportedJava = false; + private boolean internalRuntimeForbidden = false; + private boolean restrictClassFilename = true; + private boolean failOnMissingClasses = true; + private boolean failOnUnresolvableSignatures = true; + private boolean failOnViolation = true; + private boolean ignoreEmptyFileset = false; + + @Override + public void execute() throws BuildException { + AntClassLoader antLoader = null; + try { + final ClassLoader loader; + if (classpath != null) { + classpath.setProject(getProject()); + loader = antLoader = getProject().createClassLoader(ClassLoader.getSystemClassLoader(), classpath); + antLoader.setParentFirst(true); // use default classloader delegation + } else { + loader = ClassLoader.getSystemClassLoader(); + } + classFiles.setProject(getProject()); + apiSignatures.setProject(getProject()); + + 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(new Logger() { + public void error(String msg) { + log(msg, Project.MSG_ERR); + } + + public void warn(String msg) { + // ANT has no real log levels printed, so prefix with "WARNING": + log("WARNING: " + msg, Project.MSG_WARN); + } + + public void info(String msg) { + log(msg, Project.MSG_INFO); + } + }, loader, options); + + if (!checker.isSupportedJDK) { + final String msg = String.format(Locale.ENGLISH, + "Your Java runtime (%s %s) is not supported by <%s/>. Please run the checks with a supported JDK!", + System.getProperty("java.runtime.name"), System.getProperty("java.runtime.version"), getTaskName()); + if (failOnUnsupportedJava) { + throw new BuildException(msg); + } else { + log("WARNING: " + msg, Project.MSG_WARN); + return; + } + } + + for (final SuppressAnnotationType a : suppressAnnotations) { + checker.addSuppressAnnotation(a.getClassname()); + } + + try { + for (BundledSignaturesType bs : bundledSignatures) { + final String name = bs.getName(); + if (name == null) { + throw new BuildException(" must have the mandatory attribute 'name' referring to a bundled signatures file."); + } + log("Reading bundled API signatures: " + name, Project.MSG_INFO); + checker.parseBundledSignatures(name, null); + } + + @SuppressWarnings("unchecked") + final Iterator iter = apiSignatures.iterator(); + while (iter.hasNext()) { + final Resource r = iter.next(); + if (r instanceof StringResource) { + final String s = ((StringResource) r).getValue(); + if (s != null && s.trim().length() > 0) { + log("Reading inline API signatures...", Project.MSG_INFO); + checker.parseSignaturesString(s); + } + } else { + log("Reading API signatures: " + r, Project.MSG_INFO); + checker.parseSignaturesFile(r.getInputStream()); + } + } + } catch (IOException ioe) { + throw new BuildException("IO problem while reading files with API signatures: " + ioe); + } catch (ParseException pe) { + throw new BuildException("Parsing signatures failed: " + pe.getMessage()); + } + + if (checker.hasNoSignatures()) { + throw new BuildException("No API signatures found; use signaturesFile=, , or inner text to define those!"); + } + + log("Loading classes to check...", Project.MSG_INFO); + try { + @SuppressWarnings("unchecked") + final Iterator iter = classFiles.iterator(); + boolean foundClass = false; + while (iter.hasNext()) { + final Resource r = iter.next(); + final String name = r.getName(); + if (restrictClassFilename && name != null && !name.endsWith(".class")) { + continue; + } + checker.addClassToCheck(r.getInputStream()); + foundClass = true; + } + if (!foundClass) { + if (ignoreEmptyFileset) { + log("There is no or other resource collection given, or the collection does not contain any class files to check.", Project.MSG_WARN); + log("Scanned 0 class files.", Project.MSG_INFO); + return; + } else { + throw new BuildException("There is no or other resource collection given, or the collection does not contain any class files to check."); + } + } + } catch (IOException ioe) { + throw new BuildException("Failed to load one of the given class files: " + ioe); + } + + log("Scanning for API signatures and dependencies...", Project.MSG_INFO); + try { + checker.run(); + } catch (ForbiddenApiException fae) { + throw new BuildException(fae.getMessage()); + } + } finally { + if (antLoader != null) antLoader.cleanup(); + } + } + + /** Set of class files to check */ + public void add(ResourceCollection rc) { + classFiles.add(rc); + } + + /** Sets a directory as base for class files. The implicit pattern '**/*.class' is used to only scan class files. */ + public void setDir(File dir) { + final FileSet fs = new FileSet(); + fs.setProject(getProject()); + fs.setDir(dir); + // needed if somebody sets restrictClassFilename=false: + fs.setIncludes("**/*.class"); + classFiles.add(fs); + } + + private T addSignaturesResource(T res) { + ((ProjectComponent) res).setProject(getProject()); + apiSignatures.add(res); + return res; + } + + /** Set of files with API signatures as nested element */ + public FileSet createSignaturesFileSet() { + return addSignaturesResource(new FileSet()); + } + + /** List of files with API signatures as nested element */ + public FileList createSignaturesFileList() { + return addSignaturesResource(new FileList()); + } + + /** Single file with API signatures as nested element */ + public FileResource createSignaturesFile() { + return addSignaturesResource(new FileResource()); + } + + /** A file with API signatures signaturesFile= attribute */ + public void setSignaturesFile(File file) { + createSignaturesFile().setFile(file); + } + + /** Support for API signatures list as nested text */ + public void addText(String text) { + addSignaturesResource(new StringResource(text)); + } + + /** Creates a bundled signatures instance */ + public BundledSignaturesType createBundledSignatures() { + final BundledSignaturesType s = new BundledSignaturesType(); + s.setProject(getProject()); + bundledSignatures.add(s); + return s; + } + + /** A bundled signatures name */ + public void setBundledSignatures(String name) { + createBundledSignatures().setName(name); + } + + /** Creates a instance of an annotation class name that suppresses error reporting in classes/methods/fields. */ + public SuppressAnnotationType createSuppressAnnotation() { + final SuppressAnnotationType s = new SuppressAnnotationType(); + s.setProject(getProject()); + suppressAnnotations.add(s); + return s; + } + + /** Class name of annotation that suppresses error reporting in classes/methods/fields. */ + public void setSuppressAnnotation(String classname) { + createSuppressAnnotation().setClassname(classname); + } + + /** Classpath as classpath= attribute */ + public void setClasspath(Path classpath) { + createClasspath().append(classpath); + } + + /** Classpath as classpathRef= attribute */ + public void setClasspathRef(Reference r) { + createClasspath().setRefid(r); + } + + /** Classpath as nested element */ + public Path createClasspath() { + if (this.classpath == null) { + this.classpath = new Path(getProject()); + } + return this.classpath.createPath(); + } + + /** + * Fail the build, if the bundled ASM library cannot read the class file format + * of the runtime library or the runtime library cannot be discovered. + * Defaults to {@code false}. + */ + public void setFailOnUnsupportedJava(boolean failOnUnsupportedJava) { + this.failOnUnsupportedJava = failOnUnsupportedJava; + } + + /** + * Fail the build, if a referenced class is missing. This requires + * that you pass the whole classpath including all dependencies. + * If you don't have all classes in the filesets, the application classes + * must be reachable through this classpath, too. + * Defaults to {@code true}. + */ + public void setFailOnMissingClasses(boolean failOnMissingClasses) { + this.failOnMissingClasses = failOnMissingClasses; + } + + /** + * Fail the build if a signature is not resolving. If this parameter is set to + * to false, then such signatures are silently ignored. + * Defaults to {@code true}. + */ + public void setFailOnUnresolvableSignatures(boolean failOnUnresolvableSignatures) { + this.failOnUnresolvableSignatures = failOnUnresolvableSignatures; + } + + /** + * Forbids calls to classes from the internal java runtime (like sun.misc.Unsafe) + * Defaults to {@code false}. + */ + public void setInternalRuntimeForbidden(boolean internalRuntimeForbidden) { + this.internalRuntimeForbidden = internalRuntimeForbidden; + } + + /** Automatically restrict resource names included to files with a name ending in '.class'. + * This makes filesets easier, as the includes="**/*.class" is not needed. + * Defaults to {@code true}. + */ + public void setRestrictClassFilename(boolean restrictClassFilename) { + this.restrictClassFilename = restrictClassFilename; + } + + /** Ignore empty fileset/resource collection and print a warning instead. + * Defaults to {@code false}. + */ + public void setIgnoreEmptyFileSet(boolean ignoreEmptyFileset) { + this.ignoreEmptyFileset = ignoreEmptyFileset; + } + + /** + * Fail the build if violations have been found. If this parameter is set to {@code false}, + * then the build will continue even if violations have been found. + * Defaults to {@code true}. + */ + public void setFailOnViolation(boolean failOnViolation) { + this.failOnViolation = failOnViolation; + } +} diff --git a/src/main/java/de/thetaphi/forbiddenapis/BundledSignaturesType.java b/src/main/java/de/thetaphi/forbiddenapis/ant/BundledSignaturesType.java similarity index 95% rename from src/main/java/de/thetaphi/forbiddenapis/BundledSignaturesType.java rename to src/main/java/de/thetaphi/forbiddenapis/ant/BundledSignaturesType.java index a9157f36..f14e6e39 100644 --- a/src/main/java/de/thetaphi/forbiddenapis/BundledSignaturesType.java +++ b/src/main/java/de/thetaphi/forbiddenapis/ant/BundledSignaturesType.java @@ -1,4 +1,4 @@ -package de.thetaphi.forbiddenapis; +package de.thetaphi.forbiddenapis.ant; /* * (C) Copyright Uwe Schindler (Generics Policeman) and others. diff --git a/src/main/java/de/thetaphi/forbiddenapis/SuppressAnnotationType.java b/src/main/java/de/thetaphi/forbiddenapis/ant/SuppressAnnotationType.java similarity index 95% rename from src/main/java/de/thetaphi/forbiddenapis/SuppressAnnotationType.java rename to src/main/java/de/thetaphi/forbiddenapis/ant/SuppressAnnotationType.java index e3f8508e..e6f4d4fc 100644 --- a/src/main/java/de/thetaphi/forbiddenapis/SuppressAnnotationType.java +++ b/src/main/java/de/thetaphi/forbiddenapis/ant/SuppressAnnotationType.java @@ -1,4 +1,4 @@ -package de.thetaphi.forbiddenapis; +package de.thetaphi.forbiddenapis.ant; /* * (C) Copyright Uwe Schindler (Generics Policeman) and others. diff --git a/src/main/java/de/thetaphi/forbiddenapis/CliMain.java b/src/main/java/de/thetaphi/forbiddenapis/cli/CliMain.java similarity index 97% rename from src/main/java/de/thetaphi/forbiddenapis/CliMain.java rename to src/main/java/de/thetaphi/forbiddenapis/cli/CliMain.java index f985fbde..3322036f 100644 --- a/src/main/java/de/thetaphi/forbiddenapis/CliMain.java +++ b/src/main/java/de/thetaphi/forbiddenapis/cli/CliMain.java @@ -1,4 +1,4 @@ -package de.thetaphi.forbiddenapis; +package de.thetaphi.forbiddenapis.cli; /* * (C) Copyright Uwe Schindler (Generics Policeman) and others. @@ -39,9 +39,15 @@ import org.apache.commons.cli.OptionGroup; import org.apache.commons.cli.Options; import org.apache.commons.cli.PosixParser; - import org.codehaus.plexus.util.DirectoryScanner; +import de.thetaphi.forbiddenapis.Checker; +import de.thetaphi.forbiddenapis.ForbiddenApiException; +import de.thetaphi.forbiddenapis.Logger; +import de.thetaphi.forbiddenapis.ParseException; +import de.thetaphi.forbiddenapis.StdIoLogger; +import de.thetaphi.forbiddenapis.SuppressForbidden; + /** * CLI class with a static main() method */ @@ -300,20 +306,6 @@ public void run() throws ExitException { } } - @SuppressWarnings("serial") - public static final class ExitException extends Exception { - public final int exitCode; - - public ExitException(int exitCode) { - this(exitCode, null); - } - - public ExitException(int exitCode, String message) { - super(message); - this.exitCode = exitCode; - } - } - @SuppressForbidden public static void main(String... args) { try { diff --git a/src/main/java/de/thetaphi/forbiddenapis/cli/ExitException.java b/src/main/java/de/thetaphi/forbiddenapis/cli/ExitException.java new file mode 100644 index 00000000..4b6f93c5 --- /dev/null +++ b/src/main/java/de/thetaphi/forbiddenapis/cli/ExitException.java @@ -0,0 +1,18 @@ +package de.thetaphi.forbiddenapis.cli; + +/** + * Used by the CLI to signal process exit with a specific exit code + */ +@SuppressWarnings("serial") +final class ExitException extends Exception { + public final int exitCode; + + public ExitException(int exitCode) { + this(exitCode, null); + } + + public ExitException(int exitCode, String message) { + super(message); + this.exitCode = exitCode; + } +} \ No newline at end of file diff --git a/src/main/java/de/thetaphi/forbiddenapis/AbstractCheckMojo.java b/src/main/java/de/thetaphi/forbiddenapis/maven/AbstractCheckMojo.java similarity index 98% rename from src/main/java/de/thetaphi/forbiddenapis/AbstractCheckMojo.java rename to src/main/java/de/thetaphi/forbiddenapis/maven/AbstractCheckMojo.java index 3a3f2f9c..c0f73788 100644 --- a/src/main/java/de/thetaphi/forbiddenapis/AbstractCheckMojo.java +++ b/src/main/java/de/thetaphi/forbiddenapis/maven/AbstractCheckMojo.java @@ -1,4 +1,4 @@ -package de.thetaphi.forbiddenapis; +package de.thetaphi.forbiddenapis.maven; /* * (C) Copyright Uwe Schindler (Generics Policeman) and others. @@ -25,6 +25,11 @@ import org.apache.maven.plugins.annotations.Parameter; import org.codehaus.plexus.util.DirectoryScanner; +import de.thetaphi.forbiddenapis.Checker; +import de.thetaphi.forbiddenapis.ForbiddenApiException; +import de.thetaphi.forbiddenapis.Logger; +import de.thetaphi.forbiddenapis.ParseException; + import java.io.Closeable; import java.io.File; import java.io.FileInputStream; diff --git a/src/main/java/de/thetaphi/forbiddenapis/CheckMojo.java b/src/main/java/de/thetaphi/forbiddenapis/maven/CheckMojo.java similarity index 98% rename from src/main/java/de/thetaphi/forbiddenapis/CheckMojo.java rename to src/main/java/de/thetaphi/forbiddenapis/maven/CheckMojo.java index 0f33b66b..53f1fd2d 100644 --- a/src/main/java/de/thetaphi/forbiddenapis/CheckMojo.java +++ b/src/main/java/de/thetaphi/forbiddenapis/maven/CheckMojo.java @@ -1,4 +1,4 @@ -package de.thetaphi.forbiddenapis; +package de.thetaphi.forbiddenapis.maven; /* * (C) Copyright Uwe Schindler (Generics Policeman) and others. diff --git a/src/main/java/de/thetaphi/forbiddenapis/TestCheckMojo.java b/src/main/java/de/thetaphi/forbiddenapis/maven/TestCheckMojo.java similarity index 98% rename from src/main/java/de/thetaphi/forbiddenapis/TestCheckMojo.java rename to src/main/java/de/thetaphi/forbiddenapis/maven/TestCheckMojo.java index 34ab464e..98da5482 100644 --- a/src/main/java/de/thetaphi/forbiddenapis/TestCheckMojo.java +++ b/src/main/java/de/thetaphi/forbiddenapis/maven/TestCheckMojo.java @@ -1,4 +1,4 @@ -package de.thetaphi.forbiddenapis; +package de.thetaphi.forbiddenapis.maven; /* * (C) Copyright Uwe Schindler (Generics Policeman) and others. diff --git a/src/main/resources/de/thetaphi/forbiddenapis/antlib.xml b/src/main/resources/de/thetaphi/forbiddenapis/antlib.xml index 8aad6cc5..1df80dc6 100644 --- a/src/main/resources/de/thetaphi/forbiddenapis/antlib.xml +++ b/src/main/resources/de/thetaphi/forbiddenapis/antlib.xml @@ -15,5 +15,5 @@ * limitations under the License. --> - + diff --git a/src/test/antunit/TestDeprecatedTask.xml b/src/test/antunit/TestDeprecatedTask.xml new file mode 100644 index 00000000..78475a87 --- /dev/null +++ b/src/test/antunit/TestDeprecatedTask.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/antunit/TestFinalJAR.xml b/src/test/antunit/TestFinalJAR.xml index 8b18d892..1ded8638 100644 --- a/src/test/antunit/TestFinalJAR.xml +++ b/src/test/antunit/TestFinalJAR.xml @@ -16,7 +16,7 @@ --> - +