/** * Checks to see if the list of outputFiles all exist, and have last-modified timestamps which are * later than the last-modified timestamp of all the grammar files involved in build the output * (imports must be checked). If these conditions hold, the method returns false, otherwise, it * returns true. * * @param grammarFileName The grammar file we are checking */ public boolean buildRequired(String grammarFileName) throws IOException, ANTLRException { BuildDependencyGenerator bd = new BuildDependencyGenerator(this, grammarFileName); List<File> outputFiles = bd.getGeneratedFileList(); List<File> inputFiles = bd.getDependenciesFileList(); // Note that input directory must be set to use buildRequired File grammarFile; if (haveInputDir) { grammarFile = new File(inputDirectory, grammarFileName); } else { grammarFile = new File(grammarFileName); } long grammarLastModified = grammarFile.lastModified(); for (File outputFile : outputFiles) { if (!outputFile.exists() || grammarLastModified > outputFile.lastModified()) { // One of the output files does not exist or is out of date, so we must build it return true; } // Check all of the imported grammars and see if any of these are younger // than any of the output files. if (inputFiles != null) { for (File inputFile : inputFiles) { if (inputFile.lastModified() > outputFile.lastModified()) { // One of the imported grammar files has been updated so we must build return true; } } } } if (isVerbose()) { System.out.println("Grammar " + grammarFile + " is up to date - build skipped"); } return false; }