FileDocCategorySizeDatePackage
SunJavah.javaAPI DocApache Ant 1.704283Wed Dec 13 06:16:20 GMT 2006org.apache.tools.ant.taskdefs.optional.javah

SunJavah

public class SunJavah extends Object implements JavahAdapter
Adapter to com.sun.tools.javah.oldjavah.Main or com.sun.tools.javah.Main.
since
Ant 1.6.3

Fields Summary
public static final String
IMPLEMENTATION_NAME
the name of the javah adapter - sun
Constructors Summary
Methods Summary
public booleancompile(org.apache.tools.ant.taskdefs.optional.Javah javah)
Performs the actual compilation.

param
javah the calling javah task.
return
true if the compilation was successful.
throws
BuildException if there is an error.
since
Ant 1.6.3


                                    
          
        Commandline cmd = setupJavahCommand(javah);
        ExecuteJava ej = new ExecuteJava();
        Class c = null;
        try {
            try {
                // first search for the "old" javah class in 1.4.2 tools.jar
                c = Class.forName("com.sun.tools.javah.oldjavah.Main");
            } catch (ClassNotFoundException cnfe) {
                // assume older than 1.4.2 tools.jar
                c = Class.forName("com.sun.tools.javah.Main");
            }
        } catch (ClassNotFoundException ex) {
            throw new BuildException(
                "Can't load javah", ex, javah.getLocation());
        }
        cmd.setExecutable(c.getName());
        ej.setJavaCommand(cmd);
        File f = Locator.getClassSource(c);
        if (f != null) {
            ej.setClasspath(new Path(javah.getProject(), f.getPath()));
        }
        return ej.fork(javah) == 0;
    
private org.apache.tools.ant.types.CommandlinesetupJavahCommand(org.apache.tools.ant.taskdefs.optional.Javah javah)

        Commandline cmd = new Commandline();

        if (javah.getDestdir() != null) {
            cmd.createArgument().setValue("-d");
            cmd.createArgument().setFile(javah.getDestdir());
        }

        if (javah.getOutputfile() != null) {
            cmd.createArgument().setValue("-o");
            cmd.createArgument().setFile(javah.getOutputfile());
        }

        if (javah.getClasspath() != null) {
            cmd.createArgument().setValue("-classpath");
            cmd.createArgument().setPath(javah.getClasspath());
        }

        if (javah.getVerbose()) {
            cmd.createArgument().setValue("-verbose");
        }
        if (javah.getOld()) {
            cmd.createArgument().setValue("-old");
        }
        if (javah.getForce()) {
            cmd.createArgument().setValue("-force");
        }
        if (javah.getStubs() && !javah.getOld()) {
            throw new BuildException(
                "stubs only available in old mode.", javah.getLocation());
        }

        if (javah.getStubs()) {
            cmd.createArgument().setValue("-stubs");
        }
        Path bcp = new Path(javah.getProject());
        if (javah.getBootclasspath() != null) {
            bcp.append(javah.getBootclasspath());
        }
        bcp = bcp.concatSystemBootClasspath("ignore");
        if (bcp.size() > 0) {
            cmd.createArgument().setValue("-bootclasspath");
            cmd.createArgument().setPath(bcp);
        }

        cmd.addArguments(javah.getCurrentArgs());

        javah.logAndAddFiles(cmd);
        return cmd;