Class AjcHelper


  • public class AjcHelper
    extends java.lang.Object
    A helper class for creating classpaths for the compilers and report mojos
    Author:
    Kaare Nilsen
    • Constructor Summary

      Constructors 
      Constructor Description
      AjcHelper()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String createClassPath​(org.apache.maven.project.MavenProject project, java.util.List<org.apache.maven.artifact.Artifact> pluginArtifacts, java.util.List<java.lang.String> outDirs)
      Constructs AspectJ compiler classpath string
      protected static java.lang.String getAsCsv​(java.lang.String[] strings)
      Convert a string array to a comma separated list
      static java.util.Set<java.lang.String> getBuildFilesForAjdtFile​(java.lang.String ajdtBuildDefFile, java.io.File basedir)
      Based on a AJDT build properties file resolves the combination of all include and exclude statements and returns a set of all the files to be compiled and woven.
      static java.util.Set<java.lang.String> getBuildFilesForSourceDirs​(java.util.List<java.lang.String> sourceDirs, java.lang.String[] includes, java.lang.String[] excludes)
      Based on a set of sourcedirs, apply include and exclude statements and returns a set of all the files to be compiled and woven.
      static java.util.Set<java.lang.String> getWeaveSourceFiles​(java.lang.String[] weaveDirs)
      Based on a set of weave directories returns a set of all the files to be woven.
      static boolean isValidComplianceLevel​(java.lang.String complianceLevel)
      Checks if the given complianceLevel value is valid.
      static java.util.List<java.lang.String> readBuildConfigFile​(java.lang.String fileName, java.io.File outputDir)
      Reads a build config file, and returns the List of all compiler arguments.
      protected static java.util.Set<java.lang.String> resolveIncludeExcludeString​(java.lang.String inExcludeString, java.io.File basedir)
      Helper method to find all .java or .aj files specified by the inExcludeString.
      static void writeBuildConfigToFile​(java.util.List<java.lang.String> arguments, java.lang.String fileName, java.io.File outputDir)
      Creates a file that can be used as input to the ajc compiler using the -argdfile flag.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_INCLUDES

        public static final java.lang.String DEFAULT_INCLUDES
        See Also:
        Constant Field Values
      • DEFAULT_EXCLUDES

        public static final java.lang.String DEFAULT_EXCLUDES
        See Also:
        Constant Field Values
      • ACCEPTED_COMPLIANCE_LEVEL_VALUES

        public static final java.util.List<java.lang.String> ACCEPTED_COMPLIANCE_LEVEL_VALUES
        List holding all accepted values for the complianceLevel parameter.
    • Constructor Detail

      • AjcHelper

        public AjcHelper()
    • Method Detail

      • isValidComplianceLevel

        public static boolean isValidComplianceLevel​(java.lang.String complianceLevel)
        Checks if the given complianceLevel value is valid.
        Parameters:
        complianceLevel - A complianceLevel
        Returns:
        true if the supplied complianceLevel is valid, implying that it is defined within the ACCEPTED_COMPLIANCE_LEVEL_VALUES List.
        See Also:
        ACCEPTED_COMPLIANCE_LEVEL_VALUES
      • createClassPath

        public static java.lang.String createClassPath​(org.apache.maven.project.MavenProject project,
                                                       java.util.List<org.apache.maven.artifact.Artifact> pluginArtifacts,
                                                       java.util.List<java.lang.String> outDirs)
        Constructs AspectJ compiler classpath string
        Parameters:
        project - the Maven Project
        pluginArtifacts - the plugin Artifacts
        outDirs - the outputDirectories
        Returns:
        a os spesific classpath string
      • getBuildFilesForAjdtFile

        public static java.util.Set<java.lang.String> getBuildFilesForAjdtFile​(java.lang.String ajdtBuildDefFile,
                                                                               java.io.File basedir)
                                                                        throws org.apache.maven.plugin.MojoExecutionException
        Based on a AJDT build properties file resolves the combination of all include and exclude statements and returns a set of all the files to be compiled and woven.
        Parameters:
        ajdtBuildDefFile - the ajdtBuildDefFile
        basedir - the baseDirectory
        Returns:
        Set of Build Files
        Throws:
        org.apache.maven.plugin.MojoExecutionException - if build properties are not found or cannot be read
      • getBuildFilesForSourceDirs

        public static java.util.Set<java.lang.String> getBuildFilesForSourceDirs​(java.util.List<java.lang.String> sourceDirs,
                                                                                 java.lang.String[] includes,
                                                                                 java.lang.String[] excludes)
                                                                          throws org.apache.maven.plugin.MojoExecutionException
        Based on a set of sourcedirs, apply include and exclude statements and returns a set of all the files to be compiled and woven.
        Parameters:
        sourceDirs - source directories
        includes - file include patterns
        excludes - file exclude patterns
        Returns:
        Set of Build Files for Source Dirs
        Throws:
        org.apache.maven.plugin.MojoExecutionException - if sourceDirs cannot be resolved
      • getWeaveSourceFiles

        public static java.util.Set<java.lang.String> getWeaveSourceFiles​(java.lang.String[] weaveDirs)
                                                                   throws org.apache.maven.plugin.MojoExecutionException
        Based on a set of weave directories returns a set of all the files to be woven.
        Parameters:
        weaveDirs - weave directories
        Returns:
        a set of all the files to be woven
        Throws:
        org.apache.maven.plugin.MojoExecutionException - if weave directories cannot be resolved
      • writeBuildConfigToFile

        public static void writeBuildConfigToFile​(java.util.List<java.lang.String> arguments,
                                                  java.lang.String fileName,
                                                  java.io.File outputDir)
                                           throws java.io.IOException
        Creates a file that can be used as input to the ajc compiler using the -argdfile flag. Each line in these files should contain one option or filename. Comments, as in Java, start with // and extend to the end of the line.
        Parameters:
        arguments - All arguments passed to ajc in this run
        fileName - the filename of the argfile
        outputDir - the build output area.
        Throws:
        java.io.IOException - if argfile cannot be created or written
      • readBuildConfigFile

        public static java.util.List<java.lang.String> readBuildConfigFile​(java.lang.String fileName,
                                                                           java.io.File outputDir)
                                                                    throws java.io.IOException
        Reads a build config file, and returns the List of all compiler arguments.
        Parameters:
        fileName - the filename of the argfile
        outputDir - the build output area
        Returns:
        the List of all compiler arguments.
        Throws:
        java.io.IOException - if any file operation fails
      • getAsCsv

        protected static java.lang.String getAsCsv​(java.lang.String[] strings)
        Convert a string array to a comma separated list
        Parameters:
        strings - string array to be converted
        Returns:
        A comma separated list of Strings
      • resolveIncludeExcludeString

        protected static java.util.Set<java.lang.String> resolveIncludeExcludeString​(java.lang.String inExcludeString,
                                                                                     java.io.File basedir)
                                                                              throws org.apache.maven.plugin.MojoExecutionException
        Helper method to find all .java or .aj files specified by the inExcludeString. The includeString is a comma separated list over files, or directories relative to the specified basedir. Examples of correct listings
                 src/main/java/
                 src/main/java
                 src/main/java/com/project/AClass.java
                 src/main/java/com/project/AnAspect.aj
                 src/main/java/com/project/AnAspect.java
         
        Parameters:
        inExcludeString - in-/exclude string
        basedir - the baseDirectory
        Returns:
        a list over all files in the include string
        Throws:
        org.apache.maven.plugin.MojoExecutionException - if Java or AspectJ source files cannot be resolved