Return-Path: Mailing-List: contact ant-dev-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list ant-dev@jakarta.apache.org Received: (qmail 77594 invoked from network); 25 Sep 2000 04:49:30 -0000 Received: from smtp3.mail.yahoo.com (HELO smtp1b.mail.yahoo.com) (128.11.68.135) by locus.apache.org with SMTP; 25 Sep 2000 04:49:30 -0000 Received: from cpe-203-45-133-154.qld.bigpond.net.au (HELO adam) (203.45.133.154) by smtp.mail.vip.suc.yahoo.com with SMTP; 25 Sep 2000 04:49:30 -0000 X-Apparently-From: From: "Adam Murdoch" To: Subject: [PATCH] javacc task Date: Mon, 25 Sep 2000 14:50:39 +1000 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_001D_01C026FF.F8B21430" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0) X-MimeOLE: Produced By Microsoft MimeOLE V5.00.3018.1300 Importance: Normal X-Spam-Rating: locus.apache.org 1.6.2 0/1000/N This is a multi-part message in MIME format. ------=_NextPart_000_001D_01C026FF.F8B21430 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hi, This is a small patch to the JavaCC task to fix checking whether the generated Java files are up-to-date. Was checking the wrong path for the output file if the outputdirectory attribute was set. It looks like this task writes the generated files to the current directory if an output directory is not specified. Coupled with the change to search the current directory's ancestors for the build.xml files, this could lead to some rather strange behaviour if ant is not invoked from the correct directory. If no-one has any issues with it, I'll change the javacc task to write the generated file to the same directory as the grammar file, if the outputdirectory attribute is not set. ------=_NextPart_000_001D_01C026FF.F8B21430 Content-Type: text/plain; name="diff.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="diff.txt" Index: = src/main/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: = /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/option= al/javacc/JavaCC.java,v retrieving revision 1.5 diff -u -r1.5 JavaCC.java --- src/main/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java = 2000/08/17 16:02:21 1.5 +++ src/main/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java = 2000/09/25 03:28:36 @@ -228,8 +228,9 @@ if (target =3D=3D null || !target.isFile()) { throw new BuildException("Invalid target: " + target); } - final File javaFile =3D new File( - target.toString().substring(0, = target.toString().indexOf(".jj")) + ".java"); + + // determine if the generated java file is up-to-date + final File javaFile =3D 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. + *=20 + */ + private File getOutputJavaFile(File outputdir, File srcfile) + { + String path =3D srcfile.getPath(); + + // Extract file's base-name + int startBasename =3D path.lastIndexOf(File.separator); + if ( startBasename !=3D -1 ) { + path =3D path.substring(startBasename+1); + } + + // Replace the file's extension with '.java' + int startExtn =3D path.lastIndexOf('.'); + if (startExtn !=3D -1) { + path =3D path.substring(0, startExtn) + ".java"; + } + else { + path +=3D ".java"; + } + + // Change the directory + if (outputdir !=3D null) { + path =3D outputdir + File.separator + path; + } + + return new File(path); } } ------=_NextPart_000_001D_01C026FF.F8B21430-- _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com