1 18 package org.apache.tools.ant.taskdefs.optional.javah; 19 20 import java.io.File ; 21 22 import org.apache.tools.ant.BuildException; 23 import org.apache.tools.ant.launch.Locator; 24 import org.apache.tools.ant.taskdefs.ExecuteJava; 25 import org.apache.tools.ant.taskdefs.optional.Javah; 26 import org.apache.tools.ant.types.Commandline; 27 import org.apache.tools.ant.types.Path; 28 29 30 35 public class SunJavah implements JavahAdapter { 36 37 38 public static final String IMPLEMENTATION_NAME = "sun"; 39 40 47 public boolean compile(Javah javah) throws BuildException { 48 Commandline cmd = setupJavahCommand(javah); 49 ExecuteJava ej = new ExecuteJava(); 50 Class c = null; 51 try { 52 try { 53 c = Class.forName("com.sun.tools.javah.oldjavah.Main"); 55 } catch (ClassNotFoundException cnfe) { 56 c = Class.forName("com.sun.tools.javah.Main"); 58 } 59 } catch (ClassNotFoundException ex) { 60 throw new BuildException( 61 "Can't load javah", ex, javah.getLocation()); 62 } 63 cmd.setExecutable(c.getName()); 64 ej.setJavaCommand(cmd); 65 File f = Locator.getClassSource(c); 66 if (f != null) { 67 ej.setClasspath(new Path(javah.getProject(), f.getPath())); 68 } 69 return ej.fork(javah) == 0; 70 } 71 72 private Commandline setupJavahCommand(Javah javah) { 73 Commandline cmd = new Commandline(); 74 75 if (javah.getDestdir() != null) { 76 cmd.createArgument().setValue("-d"); 77 cmd.createArgument().setFile(javah.getDestdir()); 78 } 79 80 if (javah.getOutputfile() != null) { 81 cmd.createArgument().setValue("-o"); 82 cmd.createArgument().setFile(javah.getOutputfile()); 83 } 84 85 if (javah.getClasspath() != null) { 86 cmd.createArgument().setValue("-classpath"); 87 cmd.createArgument().setPath(javah.getClasspath()); 88 } 89 90 if (javah.getVerbose()) { 91 cmd.createArgument().setValue("-verbose"); 92 } 93 if (javah.getOld()) { 94 cmd.createArgument().setValue("-old"); 95 } 96 if (javah.getForce()) { 97 cmd.createArgument().setValue("-force"); 98 } 99 if (javah.getStubs() && !javah.getOld()) { 100 throw new BuildException( 101 "stubs only available in old mode.", javah.getLocation()); 102 } 103 104 if (javah.getStubs()) { 105 cmd.createArgument().setValue("-stubs"); 106 } 107 Path bcp = new Path(javah.getProject()); 108 if (javah.getBootclasspath() != null) { 109 bcp.append(javah.getBootclasspath()); 110 } 111 bcp = bcp.concatSystemBootClasspath("ignore"); 112 if (bcp.size() > 0) { 113 cmd.createArgument().setValue("-bootclasspath"); 114 cmd.createArgument().setPath(bcp); 115 } 116 117 cmd.addArguments(javah.getCurrentArgs()); 118 119 javah.logAndAddFiles(cmd); 120 return cmd; 121 } 122 123 } 124 | Popular Tags |