ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@locus.apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/javacc JavaCC.java
Date Mon, 25 Sep 2000 14:39:33 GMT
bodewig     00/09/25 07:39:31

  Modified:    src/main/org/apache/tools/ant/taskdefs/optional/javacc
                        JavaCC.java
  Log:
  Make JavaCC use the correct path when checking whether the generated
  files are up to date.
  Submitted by:	Adam Murdoch <adammurdoch@yahoo.com>
  
  Revision  Changes    Path
  1.6       +35 -2     jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java
  
  Index: JavaCC.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- JavaCC.java	2000/08/17 16:02:21	1.5
  +++ JavaCC.java	2000/09/25 14:39:29	1.6
  @@ -228,8 +228,9 @@
           if (target == null || !target.isFile()) {
               throw new BuildException("Invalid target: " + target);
           }
  -        final File javaFile = new File(
  -            target.toString().substring(0, target.toString().indexOf(".jj")) + ".java");
  +
  +        // determine if the generated java file is up-to-date
  +        final File javaFile = getOutputJavaFile(outputDirectory, target);
           if (javaFile.exists() && target.lastModified() < javaFile.lastModified())
{
               project.log("Target is already built - skipping (" + target + ")");
               return;
  @@ -263,5 +264,37 @@
           catch (IOException e) {
               throw new BuildException("Failed to launch JavaCC: " + e);
           }
  +    }
  +
  +    /**
  +     * Determines the output Java file to be generated by the given grammar
  +     * file.
  +     * 
  +     */
  +    private File getOutputJavaFile(File outputdir, File srcfile)
  +    {
  +        String path = srcfile.getPath();
  +
  +        // Extract file's base-name
  +        int startBasename = path.lastIndexOf(File.separator);
  +        if ( startBasename != -1 ) {
  +            path = path.substring(startBasename+1);
  +        }
  +
  +        // Replace the file's extension with '.java'
  +        int startExtn = path.lastIndexOf('.');
  +        if (startExtn != -1) {
  +            path = path.substring(0, startExtn) + ".java";
  +        }
  +        else {
  +            path += ".java";
  +        }
  +
  +        // Change the directory
  +        if (outputdir != null) {
  +            path = outputdir + File.separator + path;
  +        }
  +
  +        return new File(path);
       }
   }
  
  
  

Mime
View raw message