|
@@ -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); |
|
|
|
|
|
} |
|
|
} |
|
|
} |