KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > rmic > KaffeRmic


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
19 package org.apache.tools.ant.taskdefs.rmic;
20
21 import org.apache.tools.ant.BuildException;
22 import org.apache.tools.ant.Project;
23 import org.apache.tools.ant.taskdefs.ExecuteJava;
24 import org.apache.tools.ant.types.Commandline;
25
26 /**
27  * The implementation of the rmic for Kaffe
28  *
29  * @since Ant 1.4
30  */

31 public class KaffeRmic extends DefaultRmicAdapter {
32     // sorted by newest Kaffe version first
33
private static final String JavaDoc[] RMIC_CLASSNAMES = new String JavaDoc[] {
34         "gnu.classpath.tools.rmi.rmic.RMIC",
35         // pre Kaffe 1.1.5
36
"gnu.java.rmi.rmic.RMIC",
37         // pre Kaffe 1.1.2
38
"kaffe.rmi.rmic.RMIC",
39     };
40
41     /**
42      * the name of this adapter for users to select
43      */

44     public static final String JavaDoc COMPILER_NAME = "kaffe";
45
46     /** {@inheritDoc} */
47     public boolean execute() throws BuildException {
48         getRmic().log("Using Kaffe rmic", Project.MSG_VERBOSE);
49         Commandline cmd = setupRmicCommand();
50
51         Class JavaDoc c = getRmicClass();
52         if (c == null) {
53             StringBuffer JavaDoc buf = new StringBuffer JavaDoc("Cannot use Kaffe rmic, as it"
54                                                 + " is not available. None"
55                                                 + " of ");
56             for (int i = 0; i < RMIC_CLASSNAMES.length; i++) {
57                 if (i != 0) {
58                     buf.append(", ");
59                 }
60
61                 buf.append(RMIC_CLASSNAMES[i]);
62             }
63             buf.append(" have been found. A common solution is to set the"
64                        + " environment variable JAVA_HOME or CLASSPATH.");
65             throw new BuildException(buf.toString(),
66                                      getRmic().getLocation());
67         }
68
69         cmd.setExecutable(c.getName());
70         if (!c.getName().equals(RMIC_CLASSNAMES[RMIC_CLASSNAMES.length - 1])) {
71             // only supported since Kaffe 1.1.2
72
cmd.createArgument().setValue("-verbose");
73             getRmic().log(Commandline.describeCommand(cmd));
74         }
75         ExecuteJava ej = new ExecuteJava();
76         ej.setJavaCommand(cmd);
77         return ej.fork(getRmic()) == 0;
78     }
79
80     /**
81      * test for kaffe being on the system
82      * @return true if kaffe is on the current classpath
83      */

84     public static boolean isAvailable() {
85         return getRmicClass() != null;
86     }
87
88     /**
89      * tries to load Kaffe RMIC and falls back to the older class name
90      * if necessary.
91      *
92      * @return null if neither class can get loaded.
93      */

94     private static Class JavaDoc getRmicClass() {
95         for (int i = 0; i < RMIC_CLASSNAMES.length; i++) {
96             try {
97                 return Class.forName(RMIC_CLASSNAMES[i]);
98             } catch (ClassNotFoundException JavaDoc cnfe) {
99                 // Ignore
100
}
101         }
102         return null;
103     }
104 }
105
Popular Tags