source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/optional/javah/SunJavah.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 3.9 KB
Line 
1/*
2 * Copyright 2005 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17package org.apache.tools.ant.taskdefs.optional.javah;
18
19import java.io.File;
20
21import org.apache.tools.ant.BuildException;
22import org.apache.tools.ant.launch.Locator;
23import org.apache.tools.ant.taskdefs.ExecuteJava;
24import org.apache.tools.ant.taskdefs.optional.Javah;
25import org.apache.tools.ant.types.Commandline;
26import org.apache.tools.ant.types.Path;
27
28
29/**
30 * Adapter to com.sun.tools.javah.oldjavah.Main or com.sun.tools.javah.Main.
31 *
32 * @since Ant 1.6.3
33 */
34public class SunJavah implements JavahAdapter {
35
36 public static final String IMPLEMENTATION_NAME = "sun";
37
38 /**
39 * Performs the actual compilation.
40 *
41 * @since Ant 1.6.3
42 */
43 public boolean compile(Javah javah) throws BuildException {
44 Commandline cmd = setupJavahCommand(javah);
45 ExecuteJava ej = new ExecuteJava();
46 Class c = null;
47 try {
48 try {
49 // first search for the "old" javah class in 1.4.2 tools.jar
50 c = Class.forName("com.sun.tools.javah.oldjavah.Main");
51 } catch (ClassNotFoundException cnfe) {
52 // assume older than 1.4.2 tools.jar
53 c = Class.forName("com.sun.tools.javah.Main");
54 }
55 } catch (ClassNotFoundException ex) {
56 throw new BuildException("Can't load javah", ex,
57 javah.getLocation());
58 }
59 cmd.setExecutable(c.getName());
60 ej.setJavaCommand(cmd);
61 File f = Locator.getClassSource(c);
62 if (f != null) {
63 ej.setClasspath(new Path(javah.getProject(), f.getPath()));
64 }
65 return ej.fork(javah) == 0;
66 }
67
68 private Commandline setupJavahCommand(Javah javah) {
69 Commandline cmd = new Commandline();
70
71 if (javah.getDestdir() != null) {
72 cmd.createArgument().setValue("-d");
73 cmd.createArgument().setFile(javah.getDestdir());
74 }
75
76 if (javah.getOutputfile() != null) {
77 cmd.createArgument().setValue("-o");
78 cmd.createArgument().setFile(javah.getOutputfile());
79 }
80
81 if (javah.getClasspath() != null) {
82 cmd.createArgument().setValue("-classpath");
83 cmd.createArgument().setPath(javah.getClasspath());
84 }
85
86 if (javah.getVerbose()) {
87 cmd.createArgument().setValue("-verbose");
88 }
89 if (javah.getOld()) {
90 cmd.createArgument().setValue("-old");
91 }
92 if (javah.getForce()) {
93 cmd.createArgument().setValue("-force");
94 }
95 if (javah.getStubs() && !javah.getOld()) {
96 throw new BuildException("stubs only available in old mode.",
97 javah.getLocation());
98 }
99
100 if (javah.getStubs()) {
101 cmd.createArgument().setValue("-stubs");
102 }
103 Path bcp = new Path(javah.getProject());
104 if (javah.getBootclasspath() != null) {
105 bcp.append(javah.getBootclasspath());
106 }
107 if (bcp.size() > 0) {
108 cmd.createArgument().setValue("-bootclasspath");
109 cmd.createArgument().setPath(bcp);
110 }
111
112 cmd.addArguments(javah.getCurrentArgs());
113
114 javah.logAndAddFiles(cmd);
115 return cmd;
116 }
117
118}
Note: See TracBrowser for help on using the repository browser.