1 | /*
|
---|
2 | * Copyright 2001-2002,2004-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 | */
|
---|
17 |
|
---|
18 | package org.apache.tools.ant.taskdefs.rmic;
|
---|
19 |
|
---|
20 | import org.apache.tools.ant.BuildException;
|
---|
21 | import org.apache.tools.ant.Project;
|
---|
22 | import org.apache.tools.ant.taskdefs.ExecuteJava;
|
---|
23 | import org.apache.tools.ant.types.Commandline;
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * The implementation of the rmic for Kaffe
|
---|
27 | *
|
---|
28 | * @since Ant 1.4
|
---|
29 | */
|
---|
30 | public class KaffeRmic extends DefaultRmicAdapter {
|
---|
31 | // sorted by newest Kaffe version first
|
---|
32 | private static final String[] RMIC_CLASSNAMES = new String[] {
|
---|
33 | "gnu.classpath.tools.rmi.rmic.RMIC",
|
---|
34 | // pre Kaffe 1.1.5
|
---|
35 | "gnu.java.rmi.rmic.RMIC",
|
---|
36 | // pre Kaffe 1.1.2
|
---|
37 | "kaffe.rmi.rmic.RMIC",
|
---|
38 | };
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * the name of this adapter for users to select
|
---|
42 | */
|
---|
43 | public static final String COMPILER_NAME = "kaffe";
|
---|
44 |
|
---|
45 |
|
---|
46 | public boolean execute() throws BuildException {
|
---|
47 | getRmic().log("Using Kaffe rmic", Project.MSG_VERBOSE);
|
---|
48 | Commandline cmd = setupRmicCommand();
|
---|
49 |
|
---|
50 | Class c = getRmicClass();
|
---|
51 | if (c == null) {
|
---|
52 | StringBuffer buf = new StringBuffer("Cannot use Kaffe rmic, as it"
|
---|
53 | + " is not available. None"
|
---|
54 | + " of ");
|
---|
55 | for (int i = 0; i < RMIC_CLASSNAMES.length; i++) {
|
---|
56 | if (i != 0) {
|
---|
57 | buf.append(", ");
|
---|
58 | }
|
---|
59 |
|
---|
60 | buf.append(RMIC_CLASSNAMES[i]);
|
---|
61 | }
|
---|
62 | buf.append(" have been found. A common solution is to set the"
|
---|
63 | + " environment variable JAVA_HOME or CLASSPATH.");
|
---|
64 | throw new BuildException(buf.toString(),
|
---|
65 | getRmic().getLocation());
|
---|
66 | }
|
---|
67 |
|
---|
68 | cmd.setExecutable(c.getName());
|
---|
69 | ExecuteJava ej = new ExecuteJava();
|
---|
70 | ej.setJavaCommand(cmd);
|
---|
71 | return ej.fork(getRmic()) == 0;
|
---|
72 | }
|
---|
73 |
|
---|
74 | /**
|
---|
75 | * test for kaffe being on the system
|
---|
76 | * @return true if kaffe is on the current classpath
|
---|
77 | */
|
---|
78 | public static boolean isAvailable() {
|
---|
79 | return getRmicClass() != null;
|
---|
80 | }
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * tries to load Kaffe RMIC and falls back to the older class name
|
---|
84 | * if necessary.
|
---|
85 | *
|
---|
86 | * @return null if neither class can get loaded.
|
---|
87 | */
|
---|
88 | private static Class getRmicClass() {
|
---|
89 | for (int i = 0; i < RMIC_CLASSNAMES.length; i++) {
|
---|
90 | try {
|
---|
91 | return Class.forName(RMIC_CLASSNAMES[i]);
|
---|
92 | } catch (ClassNotFoundException cnfe) {
|
---|
93 | }
|
---|
94 | }
|
---|
95 | return null;
|
---|
96 | }
|
---|
97 | }
|
---|