KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > javah > Kaffeh


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */

18 package org.apache.tools.ant.taskdefs.optional.javah;
19
20 import org.apache.tools.ant.BuildException;
21 import org.apache.tools.ant.taskdefs.Execute;
22 import org.apache.tools.ant.taskdefs.optional.Javah;
23 import org.apache.tools.ant.types.Commandline;
24 import org.apache.tools.ant.types.Path;
25 import org.apache.tools.ant.util.JavaEnvUtils;
26
27 /**
28  * Adapter to the native kaffeh compiler.
29  *
30  * @since Ant 1.6.3
31  */

32 public class Kaffeh implements JavahAdapter {
33
34     /** the name of the javah adapter - kaffeh */
35     public static final String JavaDoc IMPLEMENTATION_NAME = "kaffeh";
36
37     /**
38      * Performs the actual compilation.
39      * @param javah the calling javah task.
40      * @return true if the compilation was successful.
41      * @throws BuildException if there is an error.
42      * @since Ant 1.6.3
43      */

44     public boolean compile(Javah javah) throws BuildException {
45         Commandline cmd = setupKaffehCommand(javah);
46         try {
47             Execute.runCommand(javah, cmd.getCommandline());
48             return true;
49         } catch (BuildException e) {
50             if (e.getMessage().indexOf("failed with return code") == -1) {
51                 throw e;
52             }
53         }
54         return false;
55     }
56
57     private Commandline setupKaffehCommand(Javah javah) {
58         Commandline cmd = new Commandline();
59         cmd.setExecutable(JavaEnvUtils.getJdkExecutable("kaffeh"));
60
61         if (javah.getDestdir() != null) {
62             cmd.createArgument().setValue("-d");
63             cmd.createArgument().setFile(javah.getDestdir());
64         }
65
66         if (javah.getOutputfile() != null) {
67             cmd.createArgument().setValue("-o");
68             cmd.createArgument().setFile(javah.getOutputfile());
69         }
70
71         Path cp = new Path(javah.getProject());
72         if (javah.getBootclasspath() != null) {
73             cp.append(javah.getBootclasspath());
74         }
75         cp = cp.concatSystemBootClasspath("ignore");
76         if (javah.getClasspath() != null) {
77             cp.append(javah.getClasspath());
78         }
79         if (cp.size() > 0) {
80             cmd.createArgument().setValue("-classpath");
81             cmd.createArgument().setPath(cp);
82         }
83
84         if (!javah.getOld()) {
85             cmd.createArgument().setValue("-jni");
86         }
87
88         cmd.addArguments(javah.getCurrentArgs());
89
90         javah.logAndAddFiles(cmd);
91         return cmd;
92     }
93
94 }
95
Popular Tags