Class AbstractCheckMojo

java.lang.Object
org.apache.maven.plugin.AbstractMojo
de.thetaphi.forbiddenapis.maven.AbstractCheckMojo
All Implemented Interfaces:
Constants, org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo
Direct Known Subclasses:
CheckMojo, TestCheckMojo

public abstract class AbstractCheckMojo extends org.apache.maven.plugin.AbstractMojo implements Constants
Base class for forbiddenapis Mojos.
Since:
1.0
  • Field Details

    • signaturesFiles

      @Parameter(required=false) private File[] signaturesFiles
      Lists all files, which contain signatures and comments for forbidden API calls. The signatures are resolved against the compile classpath.
      Since:
      1.0
    • signaturesArtifacts

      @Parameter(required=false) private SignaturesArtifact[] signaturesArtifacts
      Lists all Maven artifacts, which contain signatures and comments for forbidden API calls. The artifact needs to be specified like a Maven dependency. Resolution is not transitive. You can refer to plain text Maven artifacts (type="txt", e.g., with a separate classifier):
       <signaturesArtifact>
         <groupId>org.apache.foobar</groupId>
         <artifactId>example</artifactId>
         <version>1.0</version>
         <classifier>signatures</classifier>
         <type>txt</type>
       </signaturesArtifact>
       
      Alternatively, refer to signatures files inside JAR artifacts. In that case, the additional parameter path has to be given:
       <signaturesArtifact>
         <groupId>org.apache.foobar</groupId>
         <artifactId>example</artifactId>
         <version>1.0</version>
         <type>jar</type>
         <path>path/inside/jar/file/signatures.txt</path>
       </signaturesArtifact>
       

      The signatures are resolved against the compile classpath.

      Since:
      2.0
    • signatures

      @Parameter(required=false) private String signatures
      Gives a multiline list of signatures, inline in the pom.xml. Use an XML CDATA section to do that! The signatures are resolved against the compile classpath.
      Since:
      1.0
    • bundledSignatures

      @Parameter(required=false) private String[] bundledSignatures
      Specifies built-in signatures files (e.g., deprecated APIs for specific Java versions, unsafe method calls using default locale, default charset,...)
      Since:
      1.0
    • signaturesWithSeverityWarn

      @Parameter(required=false) private String[] signaturesWithSeverityWarn
      Specifies a list of forbidden API signatures for which violations should lead to a warning only (i.e. not fail the build). This takes precedence over failOnViolation. In order to be effective the signature must be given in either bundledSignatures, signaturesFiles, signaturesArtifacts, or signatures.
      Since:
      3.9
    • signaturesWithSeveritySuppress

      @Parameter(required=false) private String[] signaturesWithSeveritySuppress
      Specifies a list of forbidden API signatures for which violations should not be reported at all (i.e. neither fail the build nor appear in the logs). This takes precedence over failOnViolation and signaturesWithSeverityWarn. In order to be effective the signature must be given in either bundledSignatures, signaturesFiles, signaturesArtifacts, or signatures.
      Since:
      3.9
    • failOnUnsupportedJava

      @Parameter(required=false, defaultValue="false") private boolean failOnUnsupportedJava
      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.
      Since:
      1.0
    • failOnMissingClasses

      @Parameter(required=false, defaultValue="true") private boolean failOnMissingClasses
      Fail the build, if a class referenced in the scanned code is missing. This requires that you pass the whole classpath including all dependencies to this Mojo (Maven does this by default).
      Since:
      1.0
    • failOnUnresolvableSignatures

      @Deprecated @Parameter(required=false, defaultValue="true") private boolean failOnUnresolvableSignatures
      Deprecated.
      The setting failOnUnresolvableSignatures was deprecated and will be removed in next version. Use ignoreSignaturesOfMissingClasses instead.
      Fail the build if a signature is not resolving. If this parameter is set to to false, then such signatures are ignored. Defaults to true.

      When disabling this setting, the task still prints a warning to inform the user about broken signatures. This cannot be disabled. There is a second setting ignoreSignaturesOfMissingClasses that can be used to silently ignore signatures that refer to methods or field in classes that are not on classpath, e.g. This is useful in multi-module Maven builds where a common set of signatures is used, that are not part of every sub-modules dependencies.

      Since:
      1.4
      See Also:
    • ignoreSignaturesOfMissingClasses

      @Parameter(required=false, defaultValue="false") private boolean ignoreSignaturesOfMissingClasses
      If a class is missing while parsing signatures files, all methods and fields from this class are silently ignored. This is useful in multi-module Maven projects where only some modules have the dependency to which the signature file(s) apply. This settings prints no warning at all, so verify the signatures at least once with full dependencies. Defaults to false.
      Since:
      3.0
    • failOnViolation

      @Parameter(required=false, property="forbiddenapis.failOnViolation", defaultValue="true") private boolean failOnViolation
      Fail the build if violations have been found. Defaults to true.
      Since:
      2.0
    • disableClassloadingCache

      @Parameter(required=false, defaultValue="false") private boolean disableClassloadingCache
      Disable the internal JVM classloading cache when getting bytecode from the classpath. This setting slows down checks, but may work around issues with other Mojos, that do not close their class loaders. If you get FileNotFoundExceptions related to non-existent JAR entries you can try to work around using this setting.
      Since:
      2.2
    • targetVersion

      @Parameter(required=false, defaultValue="${maven.compiler.target}") private String targetVersion
      The default compiler target version used to expand references to bundled JDK signatures. E.g., if you use "jdk-deprecated", it will expand to this version. This setting should be identical to the target version used in the compiler plugin.
      Since:
      1.0
    • releaseVersion

      @Parameter(required=false, defaultValue="${maven.compiler.release}") private String releaseVersion
      The default compiler release version used to expand references to bundled JDK signatures. E.g., if you use "jdk-deprecated", it will expand to this version. This setting should be identical to the release version used in the compiler plugin starting with Java 9. If given, this setting is used in preference to targetVersion.
      Since:
      3.1
    • includes

      @Parameter(required=false) private String[] includes
      List of Ant patterns which must match all relative class paths to be considered. All relative class paths matching one or more of the given patterns and not matching any of the ones from excludes are considered. The given paths are relative to classesDirectory. Can be changed to e.g. exclude several files (using excludes). The default is a single include with pattern **/*.class.
      Since:
      1.0
      See Also:
    • excludes

      @Parameter(required=false) private String[] excludes
      List of Ant patterns. All relative class paths matching one or more of the given patterns are skipped. The given paths are relative to classesDirectory.
      Since:
      1.0
      See Also:
    • suppressAnnotations

      @Parameter(required=false) private String[] suppressAnnotations
      List of a custom Java annotations (full class names) that are used in the checked code to suppress errors. Those annotations must have at least RetentionPolicy.CLASS. They can be applied to classes, their methods, or fields. By default, @de.thetaphi.forbiddenapis.SuppressForbidden can always be used, but needs the forbidden-apis.jar file in classpath of compiled project, which may not be wanted. Instead of a full class name, a glob pattern may be used (e.g., **.SuppressForbidden).
      Since:
      1.8
    • skip

      @Parameter(required=false, property="forbiddenapis.skip", defaultValue="false") private boolean skip
      Skip entire check. Most useful on the command line via "-Dforbiddenapis.skip=true".
      Since:
      1.6
    • packaging

      @Parameter(defaultValue="${project.packaging}", readonly=true, required=true) private String packaging
      The project packaging (pom, jar, etc.).
    • repoSystem

      @Component private org.eclipse.aether.RepositorySystem repoSystem
    • repoSession

      @Parameter(defaultValue="${repositorySystemSession}", readonly=true, required=true) private org.eclipse.aether.RepositorySystemSession repoSession
    • projectRepos

      @Parameter(defaultValue="${project.remoteProjectRepositories}", readonly=true, required=true) private List<org.eclipse.aether.repository.RemoteRepository> projectRepos
  • Constructor Details

    • AbstractCheckMojo

      public AbstractCheckMojo()
  • Method Details

    • getClassPathElements

      protected abstract List<String> getClassPathElements()
      provided by the concrete Mojos for compile and test classes processing
    • getClassesDirectory

      protected abstract File getClassesDirectory()
      provided by the concrete Mojos for compile and test classes processing
    • getTargetVersion

      protected String getTargetVersion()
      gets overridden for test, because it uses testTargetVersion as optional name to override
    • resolveSignaturesArtifact

      private File resolveSignaturesArtifact(SignaturesArtifact signaturesArtifact) throws org.eclipse.aether.resolution.ArtifactResolutionException
      Throws:
      org.eclipse.aether.resolution.ArtifactResolutionException
    • encodeUrlPath

      private String encodeUrlPath(String path)
    • createJarUrl

      private URL createJarUrl(File f, String jarPath) throws MalformedURLException
      Throws:
      MalformedURLException
    • execute

      public void execute() throws org.apache.maven.plugin.MojoExecutionException
      Specified by:
      execute in interface org.apache.maven.plugin.Mojo
      Throws:
      org.apache.maven.plugin.MojoExecutionException