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 java.lang.reflect.Method;
|
---|
20 | import org.apache.tools.ant.BuildException;
|
---|
21 | import org.apache.tools.ant.ProjectComponent;
|
---|
22 | import org.apache.tools.ant.taskdefs.optional.Native2Ascii;
|
---|
23 | import org.apache.tools.ant.types.Commandline;
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Adapter to sun.tools.native2ascii.Main.
|
---|
27 | *
|
---|
28 | * @since Ant 1.6.3
|
---|
29 | */
|
---|
30 | public final class SunNative2Ascii extends DefaultNative2Ascii {
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * Identifies this adapter.
|
---|
34 | */
|
---|
35 | public static final String IMPLEMENTATION_NAME = "sun";
|
---|
36 |
|
---|
37 | protected void setup(Commandline cmd, Native2Ascii args)
|
---|
38 | throws BuildException {
|
---|
39 | if (args.getReverse()) {
|
---|
40 | cmd.createArgument().setValue("-reverse");
|
---|
41 | }
|
---|
42 | super.setup(cmd, args);
|
---|
43 | }
|
---|
44 |
|
---|
45 | protected boolean run(Commandline cmd, ProjectComponent log)
|
---|
46 | throws BuildException {
|
---|
47 | try {
|
---|
48 | Class n2aMain = Class.forName("sun.tools.native2ascii.Main");
|
---|
49 | Class[] param = new Class[] {String[].class};
|
---|
50 | Method convert = n2aMain.getMethod("convert", param);
|
---|
51 | if (convert == null) {
|
---|
52 | throw new BuildException("Could not find convert() method in "
|
---|
53 | + "sun.tools.native2ascii.Main");
|
---|
54 | }
|
---|
55 | Object o = n2aMain.newInstance();
|
---|
56 | return ((Boolean) convert.invoke(o,
|
---|
57 | new Object[] {cmd.getArguments()})
|
---|
58 | ).booleanValue();
|
---|
59 | } catch (BuildException ex) {
|
---|
60 | //rethrow
|
---|
61 | throw ex;
|
---|
62 | } catch (Exception ex) {
|
---|
63 | //wrap
|
---|
64 | throw new BuildException("Error starting Sun's native2ascii: ", ex);
|
---|
65 | }
|
---|
66 | }
|
---|
67 | }
|
---|