Class GenerateMojo

  • All Implemented Interfaces:
    org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo

    @Mojo(name="generate",
          defaultPhase=GENERATE_SOURCES,
          threadSafe=false)
    public class GenerateMojo
    extends org.apache.maven.plugin.AbstractMojo
    Creates a Java parser from CUP definition, using CUP.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private CliCupInvoker cupInvoker  
      (package private) java.io.File cupSourceDirectory
      Source directory of the cup files.
      (package private) java.lang.String cupSourceFilesFilter
      Regular expression of the cup files in the cupSourceDirectory.
      private static java.lang.String DEFAULT_JAVA_PACKAGE  
      (package private) static java.lang.String DEFAULT_PARSER_NAME
      Default class name of the parser.
      (package private) static java.lang.String DEFAULT_SYMBOLS_NAME
      Default class name of symbols holder.
      private boolean force
      Whether to force generation of parser and symbols.
      (package private) java.io.File generatedSourcesDirectory
      Name of the directory into which CUP should generate the parser.
      private Logger log  
      (package private) org.apache.maven.project.MavenProject mavenProject  
      private static java.lang.String PACKAGE_DEFINITION
      In a CUP definition, the Java package is introduce by the package keyword.
      (package private) java.lang.String parserName  
      (package private) boolean symbolInterface
      Whether to output the symbol constant code as an interface rather than as a class.
      (package private) java.lang.String symbolsName  
      • Fields inherited from interface org.apache.maven.plugin.Mojo

        ROLE
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void execute()  
      private java.lang.String findJavaPackage​(java.io.File cupFile)  
      (package private) void generateParser​(java.io.File cupFile)  
      private java.io.File getAbsolutePath​(java.io.File path)
      Converts the specified path argument into an absolute path.
      private java.io.File[] getSources()
      Returns the cup source files.
      private boolean isGeneratedCodeOutdated​(java.io.File cupFile, java.lang.String javaPackage)  
      (package private) com.google.common.base.Optional<java.lang.String> optionalJavaPackage​(java.lang.String line)  
      • Methods inherited from class org.apache.maven.plugin.AbstractMojo

        getLog, getPluginContext, setLog, setPluginContext
      • Methods inherited from class java.lang.Object

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

      • PACKAGE_DEFINITION

        private static final java.lang.String PACKAGE_DEFINITION
        In a CUP definition, the Java package is introduce by the package keyword.
        See Also:
        Constant Field Values
      • DEFAULT_JAVA_PACKAGE

        private static final java.lang.String DEFAULT_JAVA_PACKAGE
        See Also:
        Constant Field Values
      • DEFAULT_PARSER_NAME

        static final java.lang.String DEFAULT_PARSER_NAME
        Default class name of the parser. Note that CUP uses a lower-case class name.
        See Also:
        Constant Field Values
      • DEFAULT_SYMBOLS_NAME

        static final java.lang.String DEFAULT_SYMBOLS_NAME
        Default class name of symbols holder. Note that CUP uses a lower-case class name.
        See Also:
        Constant Field Values
      • cupSourceDirectory

        @Parameter(defaultValue="${project.basedir}/src/main/cup")
        java.io.File cupSourceDirectory
        Source directory of the cup files.
      • cupSourceFilesFilter

        @Parameter(defaultValue=".*\\.cup")
        java.lang.String cupSourceFilesFilter
        Regular expression of the cup files in the cupSourceDirectory.
      • generatedSourcesDirectory

        @Parameter(defaultValue="${project.build.directory}/generated-sources/cup")
        java.io.File generatedSourcesDirectory
        Name of the directory into which CUP should generate the parser.
      • symbolInterface

        @Parameter(defaultValue="false")
        boolean symbolInterface
        Whether to output the symbol constant code as an interface rather than as a class.
      • symbolsName

        @Parameter(defaultValue="sym")
        java.lang.String symbolsName
      • parserName

        @Parameter(defaultValue="parser")
        java.lang.String parserName
      • mavenProject

        @Parameter(property="project",
                   required=true,
                   readonly=true)
        org.apache.maven.project.MavenProject mavenProject
      • force

        @Parameter(defaultValue="false")
        private boolean force
        Whether to force generation of parser and symbols.
      • log

        private final Logger log
    • Constructor Detail

      • GenerateMojo

        public GenerateMojo()
      • GenerateMojo

        GenerateMojo​(CliCupInvoker cupInvoker,
                     org.apache.maven.plugin.logging.Log logger)
    • Method Detail

      • execute

        public void execute()
                     throws org.apache.maven.plugin.MojoExecutionException,
                            org.apache.maven.plugin.MojoFailureException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
        org.apache.maven.plugin.MojoFailureException
      • generateParser

        void generateParser​(java.io.File cupFile)
                     throws java.io.IOException,
                            org.apache.maven.plugin.MojoExecutionException
        Parameters:
        cupFile - CUP definition file
        Throws:
        java.io.IOException
        org.apache.maven.plugin.MojoExecutionException
      • isGeneratedCodeOutdated

        private boolean isGeneratedCodeOutdated​(java.io.File cupFile,
                                                java.lang.String javaPackage)
      • findJavaPackage

        private java.lang.String findJavaPackage​(java.io.File cupFile)
                                          throws java.io.IOException
        Throws:
        java.io.IOException
      • optionalJavaPackage

        com.google.common.base.Optional<java.lang.String> optionalJavaPackage​(java.lang.String line)
      • getSources

        private java.io.File[] getSources()
                                   throws org.apache.maven.plugin.MojoFailureException
        Returns the cup source files.
        Returns:
        the files in the cupSourceDirectory directory that match cupSourceFilesFilter.
        Throws:
        org.apache.maven.plugin.MojoFailureException
      • getAbsolutePath

        private java.io.File getAbsolutePath​(java.io.File path)
        Converts the specified path argument into an absolute path. If the path is relative like "src/main/jflex", it is resolved against the base directory of the mavenProject (in constrast, File.getAbsoluteFile() would resolve against the current directory which may be different, especially during a reactor build).
        Parameters:
        path - The path argument to convert, may be null.
        Returns:
        The absolute path corresponding to the input argument.