Class GrammarDirectoryScanner

  • Direct Known Subclasses:
    LegacyGrammarDirectoryScanner

    class GrammarDirectoryScanner
    extends java.lang.Object
    Scans source directories for JavaCC grammar files.
    Version:
    $Id$
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.List<GrammarInfo> includedGrammars
      A set of grammar infos describing the included grammar files, must never be null.
      private java.io.File outputDirectory
      The absolute path to the output directory used to detect stale target files by timestamp checking, may be null if no stale detection should be performed.
      private java.lang.String parserPackage
      The package name for the generated parser, may be null to use the package declaration from the grammar file.
      private org.codehaus.plexus.util.DirectoryScanner scanner
      The directory scanner used to scan the source directory for files.
      private int staleMillis
      The granularity in milliseconds of the last modification date for testing whether a grammar file needs recompilation because its corresponding target file is stale.
    • Constructor Summary

      Constructors 
      Constructor Description
      GrammarDirectoryScanner()
      Creates a new grammar directory scanner.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      GrammarInfo[] getIncludedGrammars()
      Gets the grammar files that were included by the scanner during the last invocation of scan().
      protected java.io.File[] getTargetFiles​(java.io.File targetDirectory, java.lang.String grammarFile, GrammarInfo grammarInfo)
      Determines the output files corresponding to the specified grammar file.
      void scan()
      Scans the source directory for grammar files that match at least one inclusion pattern but no exclusion pattern, optionally performing timestamp checking to exclude grammars whose corresponding parser files are up to date.
      void setExcludes​(java.lang.String[] excludes)
      Sets the Ant-like exclusion patterns.
      void setIncludes​(java.lang.String[] includes)
      Sets the Ant-like inclusion patterns.
      void setOutputDirectory​(java.io.File directory)
      Sets the absolute path to the output directory used to detect stale target files.
      void setParserPackage​(java.lang.String packageName)
      Sets the package name for the generated parser.
      void setSourceDirectory​(java.io.File directory)
      Sets the absolute path to the source directory to scan for grammar files.
      void setStaleMillis​(int milliseconds)
      Sets the granularity in milliseconds of the last modification date for stale file detection.
      • Methods inherited from class java.lang.Object

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

      • scanner

        private final org.codehaus.plexus.util.DirectoryScanner scanner
        The directory scanner used to scan the source directory for files.
      • outputDirectory

        private java.io.File outputDirectory
        The absolute path to the output directory used to detect stale target files by timestamp checking, may be null if no stale detection should be performed.
      • parserPackage

        private java.lang.String parserPackage
        The package name for the generated parser, may be null to use the package declaration from the grammar file.
      • staleMillis

        private int staleMillis
        The granularity in milliseconds of the last modification date for testing whether a grammar file needs recompilation because its corresponding target file is stale.
      • includedGrammars

        private final java.util.List<GrammarInfo> includedGrammars
        A set of grammar infos describing the included grammar files, must never be null.
    • Constructor Detail

      • GrammarDirectoryScanner

        public GrammarDirectoryScanner()
        Creates a new grammar directory scanner.
    • Method Detail

      • setSourceDirectory

        public void setSourceDirectory​(java.io.File directory)
        Sets the absolute path to the source directory to scan for grammar files. This directory must exist or the scanner will report an error.
        Parameters:
        directory - The absolute path to the source directory to scan, must not be null.
      • setParserPackage

        public void setParserPackage​(java.lang.String packageName)
        Sets the package name for the generated parser.
        Parameters:
        packageName - The package name for the generated parser, may be null to use the package declaration from the grammar file.
      • setIncludes

        public void setIncludes​(java.lang.String[] includes)
        Sets the Ant-like inclusion patterns.
        Parameters:
        includes - The set of Ant-like inclusion patterns, may be null to include all files.
      • setExcludes

        public void setExcludes​(java.lang.String[] excludes)
        Sets the Ant-like exclusion patterns.
        Parameters:
        excludes - The set of Ant-like exclusion patterns, may be null to exclude no files.
      • setOutputDirectory

        public void setOutputDirectory​(java.io.File directory)
        Sets the absolute path to the output directory used to detect stale target files.
        Parameters:
        directory - The absolute path to the output directory used to detect stale target files by timestamp checking, may be null if no stale detection should be performed.
      • setStaleMillis

        public void setStaleMillis​(int milliseconds)
        Sets the granularity in milliseconds of the last modification date for stale file detection.
        Parameters:
        milliseconds - The granularity in milliseconds of the last modification date for testing whether a grammar file needs recompilation because its corresponding target file is stale.
      • scan

        public void scan()
                  throws java.io.IOException
        Scans the source directory for grammar files that match at least one inclusion pattern but no exclusion pattern, optionally performing timestamp checking to exclude grammars whose corresponding parser files are up to date.
        Throws:
        java.io.IOException - If a grammar file could not be analyzed for metadata.
      • getTargetFiles

        protected java.io.File[] getTargetFiles​(java.io.File targetDirectory,
                                                java.lang.String grammarFile,
                                                GrammarInfo grammarInfo)
        Determines the output files corresponding to the specified grammar file.
        Parameters:
        targetDirectory - The absolute path to the output directory for the target files, must not be null.
        grammarFile - The path to the grammar file, relative to the scanned source directory, must not be null.
        grammarInfo - The grammar info describing the grammar file, must not be null
        Returns:
        A file array with target files, never null.
      • getIncludedGrammars

        public GrammarInfo[] getIncludedGrammars()
        Gets the grammar files that were included by the scanner during the last invocation of scan().
        Returns:
        An array of grammar infos describing the included grammar files, will be empty if no files were included but is never null.