Browse Source

Make JavaCC use the correct path when checking whether the generated

files are up to date.
Submitted by:	Adam Murdoch <adammurdoch@yahoo.com>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268035 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 25 years ago
parent
commit
da89ca486a
1 changed files with 35 additions and 2 deletions
  1. +35
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java

+ 35
- 2
src/main/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java View File

@@ -228,8 +228,9 @@ public class JavaCC extends Task {
if (target == null || !target.isFile()) { if (target == null || !target.isFile()) {
throw new BuildException("Invalid target: " + target); 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()) { if (javaFile.exists() && target.lastModified() < javaFile.lastModified()) {
project.log("Target is already built - skipping (" + target + ")"); project.log("Target is already built - skipping (" + target + ")");
return; return;
@@ -264,4 +265,36 @@ public class JavaCC extends Task {
throw new BuildException("Failed to launch JavaCC: " + 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);
}
} }

Loading…
Cancel
Save