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.types.Commandline;
024: import org.apache.tools.ant.types.Path;
025:
026: /**
027: * The implementation of the jvc compiler from microsoft.
028: * This is primarily a cut-and-paste from the original javac task before it
029: * was refactored.
030: *
031: * @since Ant 1.3
032: */
033: public class Jvc extends DefaultCompilerAdapter {
034:
035: /**
036: * Run the compilation.
037: * @return true if the compiler ran with a zero exit result (ok)
038: * @exception BuildException if the compilation has problems.
039: */
040: public boolean execute() throws BuildException {
041: attributes.log("Using jvc compiler", Project.MSG_VERBOSE);
042:
043: Path classpath = new Path(project);
044:
045: // jvc doesn't support bootclasspath dir (-bootclasspath)
046: // so we'll emulate it for compatibility and convenience.
047: Path p = getBootClassPath();
048: if (p.size() > 0) {
049: classpath.append(p);
050: }
051:
052: if (includeJavaRuntime) {
053: // jvc doesn't support an extension dir (-extdir)
054: // so we'll emulate it for compatibility and convenience.
055: classpath.addExtdirs(extdirs);
056: }
057:
058: classpath.append(getCompileClasspath());
059:
060: // jvc has no option for source-path so we
061: // will add it to classpath.
062: if (compileSourcepath != null) {
063: classpath.append(compileSourcepath);
064: } else {
065: classpath.append(src);
066: }
067:
068: Commandline cmd = new Commandline();
069: String exec = getJavac().getExecutable();
070: cmd.setExecutable(exec == null ? "jvc" : exec);
071:
072: if (destDir != null) {
073: cmd.createArgument().setValue("/d");
074: cmd.createArgument().setFile(destDir);
075: }
076:
077: // Add the Classpath before the "internal" one.
078: cmd.createArgument().setValue("/cp:p");
079: cmd.createArgument().setPath(classpath);
080:
081: boolean msExtensions = true;
082: String mse = getProject().getProperty(
083: "build.compiler.jvc.extensions");
084: if (mse != null) {
085: msExtensions = Project.toBoolean(mse);
086: }
087:
088: if (msExtensions) {
089: // Enable MS-Extensions and ...
090: cmd.createArgument().setValue("/x-");
091: // ... do not display a Message about this.
092: cmd.createArgument().setValue("/nomessage");
093: }
094:
095: // Do not display Logo
096: cmd.createArgument().setValue("/nologo");
097:
098: if (debug) {
099: cmd.createArgument().setValue("/g");
100: }
101: if (optimize) {
102: cmd.createArgument().setValue("/O");
103: }
104: if (verbose) {
105: cmd.createArgument().setValue("/verbose");
106: }
107:
108: addCurrentCompilerArgs(cmd);
109:
110: int firstFileName = cmd.size();
111: logAndAddFilesToCompile(cmd);
112:
113: return executeExternalCompile(cmd.getCommandline(),
114: firstFileName) == 0;
115: }
116: }
|