source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/rmic/SunRmic.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 3.0 KB
Line 
1/*
2 * Copyright 2001-2002,2004 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
18package org.apache.tools.ant.taskdefs.rmic;
19
20import java.io.IOException;
21import java.io.OutputStream;
22import java.lang.reflect.Constructor;
23import java.lang.reflect.Method;
24import org.apache.tools.ant.BuildException;
25import org.apache.tools.ant.Project;
26import org.apache.tools.ant.taskdefs.LogOutputStream;
27import org.apache.tools.ant.types.Commandline;
28
29/**
30 * The implementation of the rmic for SUN's JDK.
31 *
32 * @since Ant 1.4
33 */
34public class SunRmic extends DefaultRmicAdapter {
35
36 public boolean execute() throws BuildException {
37 getRmic().log("Using SUN rmic compiler", Project.MSG_VERBOSE);
38 Commandline cmd = setupRmicCommand();
39
40 // Create an instance of the rmic, redirecting output to
41 // the project log
42 LogOutputStream logstr = new LogOutputStream(getRmic(),
43 Project.MSG_WARN);
44
45 try {
46 Class c = Class.forName("sun.rmi.rmic.Main");
47 Constructor cons
48 = c.getConstructor(new Class[] {OutputStream.class, String.class});
49 Object rmic = cons.newInstance(new Object[] {logstr, "rmic"});
50
51 Method doRmic = c.getMethod("compile",
52 new Class [] {String[].class});
53 Boolean ok =
54 (Boolean) doRmic.invoke(rmic,
55 (new Object[] {cmd.getArguments()}));
56 return ok.booleanValue();
57 } catch (ClassNotFoundException ex) {
58 throw new BuildException("Cannot use SUN rmic, as it is not "
59 + "available. A common solution is to "
60 + "set the environment variable "
61 + "JAVA_HOME or CLASSPATH.",
62 getRmic().getLocation());
63 } catch (Exception ex) {
64 if (ex instanceof BuildException) {
65 throw (BuildException) ex;
66 } else {
67 throw new BuildException("Error starting SUN rmic: ",
68 ex, getRmic().getLocation());
69 }
70 } finally {
71 try {
72 logstr.close();
73 } catch (IOException e) {
74 throw new BuildException(e);
75 }
76 }
77 }
78}
Note: See TracBrowser for help on using the repository browser.