KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.tools.ant.BuildException;
22 import org.apache.tools.ant.Project;
23 import org.apache.tools.ant.taskdefs.ExecuteJava;
24 import org.apache.tools.ant.types.Commandline;
25 import org.apache.tools.ant.types.Path;
26
27 /**
28  * The implementation of the Java compiler for KJC.
29  * This is primarily a cut-and-paste from Jikes.java and
30  * DefaultCompilerAdapter.
31  *
32  * @since Ant 1.4
33  */

34 public class Kjc extends DefaultCompilerAdapter {
35
36     /**
37      * Run the compilation.
38      * @return true if the compilation succeeded
39      * @exception BuildException if the compilation has problems.
40      */

41     public boolean execute() throws BuildException {
42         attributes.log("Using kjc compiler", Project.MSG_VERBOSE);
43         Commandline cmd = setupKjcCommand();
44         cmd.setExecutable("at.dms.kjc.Main");
45         ExecuteJava ej = new ExecuteJava();
46         ej.setJavaCommand(cmd);
47         return ej.fork(getJavac()) == 0;
48     }
49
50     /**
51      * setup kjc command arguments.
52      * @return the command line
53      */

54     protected Commandline setupKjcCommand() {
55         Commandline cmd = new Commandline();
56
57         // generate classpath, because kjc doesn't support sourcepath.
58
Path classpath = getCompileClasspath();
59
60         if (deprecation) {
61             cmd.createArgument().setValue("-deprecation");
62         }
63
64         if (destDir != null) {
65             cmd.createArgument().setValue("-d");
66             cmd.createArgument().setFile(destDir);
67         }
68
69         // generate the clsspath
70
cmd.createArgument().setValue("-classpath");
71
72         Path cp = new Path(project);
73
74         // kjc don't have bootclasspath option.
75
Path p = getBootClassPath();
76         if (p.size() > 0) {
77             cp.append(p);
78         }
79
80         if (extdirs != null) {
81             cp.addExtdirs(extdirs);
82         }
83
84         cp.append(classpath);
85         if (compileSourcepath != null) {
86             cp.append(compileSourcepath);
87         } else {
88             cp.append(src);
89         }
90
91         cmd.createArgument().setPath(cp);
92
93         // kjc-1.5A doesn't support -encoding option now.
94
// but it will be supported near the feature.
95
if (encoding != null) {
96             cmd.createArgument().setValue("-encoding");
97             cmd.createArgument().setValue(encoding);
98         }
99
100         if (debug) {
101             cmd.createArgument().setValue("-g");
102         }
103
104         if (optimize) {
105             cmd.createArgument().setValue("-O2");
106         }
107
108         if (verbose) {
109             cmd.createArgument().setValue("-verbose");
110         }
111
112         addCurrentCompilerArgs(cmd);
113
114         logAndAddFilesToCompile(cmd);
115         return cmd;
116     }
117 }
118
119
120
Popular Tags