KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > compilers > Javac13


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * 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
19 package org.apache.tools.ant.taskdefs.compilers;
20
21 import java.lang.reflect.Method JavaDoc;
22 import org.apache.tools.ant.BuildException;
23 import org.apache.tools.ant.Project;
24 import org.apache.tools.ant.types.Commandline;
25
26
27 /**
28  * The implementation of the javac compiler for JDK 1.3
29  * This is primarily a cut-and-paste from the original javac task before it
30  * was refactored.
31  *
32  * @since Ant 1.3
33  */

34 public class Javac13 extends DefaultCompilerAdapter {
35
36     /**
37      * Integer returned by the "Modern" jdk1.3 compiler to indicate success.
38      */

39     private static final int MODERN_COMPILER_SUCCESS = 0;
40
41     /**
42      * Run the compilation.
43      * @return true if the compiler ran with a zero exit result (ok)
44      * @exception BuildException if the compilation has problems.
45      */

46     public boolean execute() throws BuildException {
47         attributes.log("Using modern compiler", Project.MSG_VERBOSE);
48         Commandline cmd = setupModernJavacCommand();
49
50         // Use reflection to be able to build on all JDKs >= 1.1:
51
try {
52             Class JavaDoc c = Class.forName ("com.sun.tools.javac.Main");
53             Object JavaDoc compiler = c.newInstance ();
54             Method JavaDoc compile = c.getMethod ("compile",
55                 new Class JavaDoc [] {(new String JavaDoc [] {}).getClass ()});
56             int result = ((Integer JavaDoc) compile.invoke
57                           (compiler, new Object JavaDoc[] {cmd.getArguments()}))
58                 .intValue ();
59             return (result == MODERN_COMPILER_SUCCESS);
60         } catch (Exception JavaDoc ex) {
61             if (ex instanceof BuildException) {
62                 throw (BuildException) ex;
63             } else {
64                 throw new BuildException("Error starting modern compiler",
65                                          ex, location);
66             }
67         }
68     }
69 }
70
Popular Tags