01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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.native2ascii;
19:
20: import java.lang.reflect.Method;
21: import org.apache.tools.ant.BuildException;
22: import org.apache.tools.ant.ProjectComponent;
23: import org.apache.tools.ant.taskdefs.optional.Native2Ascii;
24: import org.apache.tools.ant.types.Commandline;
25:
26: /**
27: * Adapter to sun.tools.native2ascii.Main.
28: *
29: * @since Ant 1.6.3
30: */
31: public final class SunNative2Ascii extends DefaultNative2Ascii {
32:
33: /**
34: * Identifies this adapter.
35: */
36: public static final String IMPLEMENTATION_NAME = "sun";
37:
38: /** {@inheritDoc} */
39: protected void setup(Commandline cmd, Native2Ascii args)
40: throws BuildException {
41: if (args.getReverse()) {
42: cmd.createArgument().setValue("-reverse");
43: }
44: super .setup(cmd, args);
45: }
46:
47: /** {@inheritDoc} */
48: protected boolean run(Commandline cmd, ProjectComponent log)
49: throws BuildException {
50: try {
51: Class n2aMain = Class
52: .forName("sun.tools.native2ascii.Main");
53: Class[] param = new Class[] { String[].class };
54: Method convert = n2aMain.getMethod("convert", param);
55: if (convert == null) {
56: throw new BuildException(
57: "Could not find convert() method in "
58: + "sun.tools.native2ascii.Main");
59: }
60: Object o = n2aMain.newInstance();
61: return ((Boolean) convert.invoke(o, new Object[] { cmd
62: .getArguments() })).booleanValue();
63: } catch (BuildException ex) {
64: //rethrow
65: throw ex;
66: } catch (Exception ex) {
67: //wrap
68: throw new BuildException(
69: "Error starting Sun's native2ascii: ", ex);
70: }
71: }
72: }
|