001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.tools.ant.taskdefs.compilers;
020:
021: import org.apache.tools.ant.BuildException;
022: import org.apache.tools.ant.Project;
023: import org.apache.tools.ant.taskdefs.ExecuteJava;
024: import org.apache.tools.ant.types.Commandline;
025: import org.apache.tools.ant.types.Path;
026:
027: /**
028: * The implementation of the Java compiler for KJC.
029: * This is primarily a cut-and-paste from Jikes.java and
030: * DefaultCompilerAdapter.
031: *
032: * @since Ant 1.4
033: */
034: public class Kjc extends DefaultCompilerAdapter {
035:
036: /**
037: * Run the compilation.
038: * @return true if the compilation succeeded
039: * @exception BuildException if the compilation has problems.
040: */
041: public boolean execute() throws BuildException {
042: attributes.log("Using kjc compiler", Project.MSG_VERBOSE);
043: Commandline cmd = setupKjcCommand();
044: cmd.setExecutable("at.dms.kjc.Main");
045: ExecuteJava ej = new ExecuteJava();
046: ej.setJavaCommand(cmd);
047: return ej.fork(getJavac()) == 0;
048: }
049:
050: /**
051: * setup kjc command arguments.
052: * @return the command line
053: */
054: protected Commandline setupKjcCommand() {
055: Commandline cmd = new Commandline();
056:
057: // generate classpath, because kjc doesn't support sourcepath.
058: Path classpath = getCompileClasspath();
059:
060: if (deprecation) {
061: cmd.createArgument().setValue("-deprecation");
062: }
063:
064: if (destDir != null) {
065: cmd.createArgument().setValue("-d");
066: cmd.createArgument().setFile(destDir);
067: }
068:
069: // generate the clsspath
070: cmd.createArgument().setValue("-classpath");
071:
072: Path cp = new Path(project);
073:
074: // kjc don't have bootclasspath option.
075: Path p = getBootClassPath();
076: if (p.size() > 0) {
077: cp.append(p);
078: }
079:
080: if (extdirs != null) {
081: cp.addExtdirs(extdirs);
082: }
083:
084: cp.append(classpath);
085: if (compileSourcepath != null) {
086: cp.append(compileSourcepath);
087: } else {
088: cp.append(src);
089: }
090:
091: cmd.createArgument().setPath(cp);
092:
093: // kjc-1.5A doesn't support -encoding option now.
094: // but it will be supported near the feature.
095: if (encoding != null) {
096: cmd.createArgument().setValue("-encoding");
097: cmd.createArgument().setValue(encoding);
098: }
099:
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: }
|