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 | */
|
---|
17 | package org.apache.tools.ant.taskdefs.optional.native2ascii;
|
---|
18 |
|
---|
19 | import org.apache.tools.ant.BuildException;
|
---|
20 | import org.apache.tools.ant.ProjectComponent;
|
---|
21 | import org.apache.tools.ant.taskdefs.ExecuteJava;
|
---|
22 | import org.apache.tools.ant.taskdefs.optional.Native2Ascii;
|
---|
23 | import org.apache.tools.ant.types.Commandline;
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Adapter to kaffe.tools.native2ascii.Native2Ascii.
|
---|
27 | *
|
---|
28 | * @since Ant 1.6.3
|
---|
29 | */
|
---|
30 | public final class KaffeNative2Ascii extends DefaultNative2Ascii {
|
---|
31 |
|
---|
32 | // sorted by newest Kaffe version first
|
---|
33 | private static final String[] N2A_CLASSNAMES = new String[] {
|
---|
34 | "gnu.classpath.tools.native2ascii.Native2Ascii",
|
---|
35 | // pre Kaffe 1.1.5
|
---|
36 | "kaffe.tools.native2ascii.Native2Ascii",
|
---|
37 | };
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * Identifies this adapter.
|
---|
41 | */
|
---|
42 | public static final String IMPLEMENTATION_NAME = "kaffe";
|
---|
43 |
|
---|
44 | protected void setup(Commandline cmd, Native2Ascii args)
|
---|
45 | throws BuildException {
|
---|
46 | if (args.getReverse()) {
|
---|
47 | throw new BuildException("-reverse is not supported by Kaffe");
|
---|
48 | }
|
---|
49 | super.setup(cmd, args);
|
---|
50 | }
|
---|
51 |
|
---|
52 | protected boolean run(Commandline cmd, ProjectComponent log)
|
---|
53 | throws BuildException {
|
---|
54 | ExecuteJava ej = new ExecuteJava();
|
---|
55 | Class c = getN2aClass();
|
---|
56 | if (c == null) {
|
---|
57 | throw new BuildException("Couldn't load Kaffe's Native2Ascii"
|
---|
58 | + " class");
|
---|
59 | }
|
---|
60 |
|
---|
61 | cmd.setExecutable(c.getName());
|
---|
62 | ej.setJavaCommand(cmd);
|
---|
63 | ej.execute(log.getProject());
|
---|
64 | // otherwise ExecuteJava has thrown an exception
|
---|
65 | return true;
|
---|
66 | }
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * tries to load Kaffe Native2Ascii and falls back to the older
|
---|
70 | * class name if necessary.
|
---|
71 | *
|
---|
72 | * @return null if neither class can get loaded.
|
---|
73 | */
|
---|
74 | private static Class getN2aClass() {
|
---|
75 | for (int i = 0; i < N2A_CLASSNAMES.length; i++) {
|
---|
76 | try {
|
---|
77 | return Class.forName(N2A_CLASSNAMES[i]);
|
---|
78 | } catch (ClassNotFoundException cnfe) {
|
---|
79 | }
|
---|
80 | }
|
---|
81 | return null;
|
---|
82 | }
|
---|
83 |
|
---|
84 | }
|
---|