@@ -1,5 +1,5 @@
/*
* Copyright 2000-2004 The Apache Software Foundation
* Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@ import java.io.File;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Hashtable;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
@@ -175,6 +176,9 @@ public class JJTree extends Task {
this.javaccHome = javaccHome;
}
/**
* Constructor
*/
public JJTree() {
cmdl.setVm(JavaEnvUtils.getJreExecutable("java"));
}
@@ -264,11 +268,11 @@ public class JJTree extends Task {
}
}
private String createOutputFileName(File targe tFile, String optionalOutputFile,
String outputDirectory ) {
private String createOutputFileName(File des tFile, String optionalOutputFile,
String outputDir) {
optionalOutputFile = validateOutputFile(optionalOutputFile,
outputDirectory );
String jjtreeFile = targe tFile.getAbsolutePath().replace('\\', '/');
outputDir);
String jjtreeFile = des tFile.getAbsolutePath().replace('\\', '/');
if ((optionalOutputFile == null) || optionalOutputFile.equals("")) {
int filePos = jjtreeFile.lastIndexOf("/");
@@ -293,57 +297,51 @@ public class JJTree extends Task {
}
}
if ((outputDirectory == null) || outputDirectory .equals("")) {
outputDirectory = getDefaultOutputDirectory();
if ((outputDir == null) || outputDir.equals("")) {
outputDir = getDefaultOutputDirectory();
}
return (outputDirectory + "/" + optionalOutputFile).replace('\\', '/');
return (outputDir + "/" + optionalOutputFile).replace('\\', '/');
}
/*
* Not used anymore
private boolean isAbsolute(String fileName) {
return (fileName.startsWith("/") || (new File(fileName).isAbsolute()));
}
*/
/**
* When running JJTree from an Ant taskdesk the -OUTPUT_DIRECTORY must
* always be set. But when -OUTPUT_DIRECTORY is set, -OUTPUT_FILE is
* handled as if relative of this -OUTPUT_DIRECTORY. Thus when the
* -OUTPUT_FILE is absolute or contains a drive letter we have a problem.
*
* @param outpu tFile
* @param outputDirectory
* @param des tFile
* @param outputDir
* @return
* @throws BuildException
*/
private String validateOutputFile(String outpu tFile,
String outputDirectory )
private String validateOutputFile(String des tFile,
String outputDir)
throws BuildException {
if (outpu tFile == null) {
if (des tFile == null) {
return null;
}
if ((outputDirectory == null)
&& (outputFile.startsWith("/") || outpu tFile.startsWith("\\"))) {
String relativeOutputFile = makeOutputFileRelative(outpu tFile);
if ((outputDir == null)
&& (destFile.startsWith("/") || des tFile.startsWith("\\"))) {
String relativeOutputFile = makeOutputFileRelative(des tFile);
setOutputfile(relativeOutputFile);
return relativeOutputFile;
}
String root = getRoot(new File(outpu tFile)).getAbsolutePath();
String root = getRoot(new File(des tFile)).getAbsolutePath();
if ((root.length() > 1)
&& outpu tFile.startsWith(root.substring(0, root.length() - 1))) {
&& des tFile.startsWith(root.substring(0, root.length() - 1))) {
throw new BuildException("Drive letter in 'outputfile' not "
+ "supported: " + outpu tFile);
+ "supported: " + des tFile);
}
return outpu tFile;
return des tFile;
}
private String makeOutputFileRelative(String outpu tFile) {
private String makeOutputFileRelative(String des tFile) {
StringBuffer relativePath = new StringBuffer();
String defaultOutputDirectory = getDefaultOutputDirectory();
int nextPos = defaultOutputDirectory.indexOf('/');
@@ -360,7 +358,7 @@ public class JJTree extends Task {
}
}
relativePath.append(outpu tFile);
relativePath.append(des tFile);
return relativePath.toString();
}
@@ -384,4 +382,4 @@ public class JJTree extends Task {
return root;
}
}
}