FileDocCategorySizeDatePackage
JJDoc.javaAPI DocApache Ant 1.707371Wed Dec 13 06:16:20 GMT 2006org.apache.tools.ant.taskdefs.optional.javacc

JJDoc

public class JJDoc extends org.apache.tools.ant.Task
Runs the JJDoc compiler compiler.

Fields Summary
private static final String
OUTPUT_FILE
private static final String
TEXT
private static final String
ONE_TABLE
private final Hashtable
optionalAttrs
private String
outputFile
private boolean
plainText
private static final String
DEFAULT_SUFFIX_HTML
private static final String
DEFAULT_SUFFIX_TEXT
private File
targetFile
private File
javaccHome
private org.apache.tools.ant.types.CommandlineJava
cmdl
Constructors Summary
public JJDoc()
Constructor

        cmdl.setVm(JavaEnvUtils.getJreExecutable("java"));
    
Methods Summary
private java.lang.StringcreateOutputFileName(java.io.File destFile, java.lang.String optionalOutputFile, boolean plain)

        String suffix = DEFAULT_SUFFIX_HTML;
        String javaccFile = destFile.getAbsolutePath().replace('\\", '/");

        if (plain) {
            suffix = DEFAULT_SUFFIX_TEXT;
        }

        if ((optionalOutputFile == null) || optionalOutputFile.equals("")) {
            int filePos = javaccFile.lastIndexOf("/");

            if (filePos >= 0) {
                javaccFile = javaccFile.substring(filePos + 1);
            }

            int suffixPos = javaccFile.lastIndexOf('.");

            if (suffixPos == -1) {
                optionalOutputFile = javaccFile + suffix;
            } else {
                String currentSuffix = javaccFile.substring(suffixPos);

                if (currentSuffix.equals(suffix)) {
                    optionalOutputFile = javaccFile + suffix;
                } else {
                    optionalOutputFile = javaccFile.substring(0, suffixPos)
                        + suffix;
                }
            }
        } else {
            optionalOutputFile = optionalOutputFile.replace('\\", '/");
        }

        return (getProject().getBaseDir() + "/" + optionalOutputFile)
            .replace('\\", '/");
    
public voidexecute()
Do the task.

throws
BuildException if there is an error.


        // load command line with optional attributes
        Enumeration iter = optionalAttrs.keys();
        while (iter.hasMoreElements()) {
            String name  = (String) iter.nextElement();
            Object value = optionalAttrs.get(name);
            cmdl.createArgument()
                .setValue("-" + name + ":" + value.toString());
        }

        if (targetFile == null || !targetFile.isFile()) {
            throw new BuildException("Invalid target: " + targetFile);
        }

        if (outputFile != null) {
            cmdl.createArgument() .setValue("-" + OUTPUT_FILE + ":"
                                            + outputFile.replace('\\", '/"));
        }

        // use the directory containing the target as the output directory
        File javaFile = new File(createOutputFileName(targetFile, outputFile,
                                                      plainText));

        if (javaFile.exists()
             && targetFile.lastModified() < javaFile.lastModified()) {
            log("Target is already built - skipping (" + targetFile + ")",
                Project.MSG_VERBOSE);
            return;
        }

        cmdl.createArgument().setValue(targetFile.getAbsolutePath());

        final Path classpath = cmdl.createClasspath(getProject());
        final File javaccJar = JavaCC.getArchiveFile(javaccHome);
        classpath.createPathElement().setPath(javaccJar.getAbsolutePath());
        classpath.addJavaRuntime();

        cmdl.setClassname(JavaCC.getMainClass(classpath,
                                              JavaCC.TASKDEF_TYPE_JJDOC));

        final Commandline.Argument arg = cmdl.createVmArgument();
        arg.setValue("-mx140M");
        arg.setValue("-Dinstall.root=" + javaccHome.getAbsolutePath());

        final Execute process =
            new Execute(new LogStreamHandler(this,
                                             Project.MSG_INFO,
                                             Project.MSG_INFO),
                        null);
        log(cmdl.describeCommand(), Project.MSG_VERBOSE);
        process.setCommandline(cmdl.getCommandline());

        try {
            if (process.execute() != 0) {
                throw new BuildException("JJDoc failed.");
            }
        } catch (IOException e) {
            throw new BuildException("Failed to launch JJDoc", e);
        }
    
public voidsetJavacchome(java.io.File javaccHome)
The directory containing the JavaCC distribution.

param
javaccHome the home directory.

        this.javaccHome = javaccHome;
    
public voidsetOnetable(boolean oneTable)
Sets the ONE_TABLE documentation option.

param
oneTable a boolean value.

        optionalAttrs.put(ONE_TABLE, oneTable ? Boolean.TRUE : Boolean.FALSE);
    
public voidsetOutputfile(java.lang.String outputFile)
The outputfile to write the generated BNF documentation file to. If not set, the file is written with the same name as the JavaCC grammar file with a suffix .html or .txt.

param
outputFile the name of the output file.

        this.outputFile = outputFile;
    
public voidsetTarget(java.io.File target)
The javacc grammar file to process.

param
target the grammar file.

        this.targetFile = target;
    
public voidsetText(boolean plainText)
Sets the TEXT BNF documentation option.

param
plainText a boolean value.



                    
        
        optionalAttrs.put(TEXT, plainText ? Boolean.TRUE : Boolean.FALSE);
        this.plainText = plainText;