KickJava   Java API By Example, From Geeks To Geeks.

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


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.types.Commandline;
24 import org.apache.tools.ant.types.Path;
25
26 /**
27  * The implementation of the jvc compiler from microsoft.
28  * This is primarily a cut-and-paste from the original javac task before it
29  * was refactored.
30  *
31  * @since Ant 1.3
32  */

33 public class Jvc extends DefaultCompilerAdapter {
34
35     /**
36      * Run the compilation.
37      * @return true if the compiler ran with a zero exit result (ok)
38      * @exception BuildException if the compilation has problems.
39      */

40     public boolean execute() throws BuildException {
41         attributes.log("Using jvc compiler", Project.MSG_VERBOSE);
42
43         Path classpath = new Path(project);
44
45         // jvc doesn't support bootclasspath dir (-bootclasspath)
46
// so we'll emulate it for compatibility and convenience.
47
Path p = getBootClassPath();
48         if (p.size() > 0) {
49             classpath.append(p);
50         }
51
52         if (includeJavaRuntime) {
53             // jvc doesn't support an extension dir (-extdir)
54
// so we'll emulate it for compatibility and convenience.
55
classpath.addExtdirs(extdirs);
56         }
57
58         classpath.append(getCompileClasspath());
59
60         // jvc has no option for source-path so we
61
// will add it to classpath.
62
if (compileSourcepath != null) {
63             classpath.append(compileSourcepath);
64         } else {
65             classpath.append(src);
66         }
67
68         Commandline cmd = new Commandline();
69         String JavaDoc exec = getJavac().getExecutable();
70         cmd.setExecutable(exec == null ? "jvc" : exec);
71
72         if (destDir != null) {
73             cmd.createArgument().setValue("/d");
74             cmd.createArgument().setFile(destDir);
75         }
76
77         // Add the Classpath before the "internal" one.
78
cmd.createArgument().setValue("/cp:p");
79         cmd.createArgument().setPath(classpath);
80
81         boolean msExtensions = true;
82         String JavaDoc mse = getProject().getProperty("build.compiler.jvc.extensions");
83         if (mse != null) {
84             msExtensions = Project.toBoolean(mse);
85         }
86
87         if (msExtensions) {
88             // Enable MS-Extensions and ...
89
cmd.createArgument().setValue("/x-");
90             // ... do not display a Message about this.
91
cmd.createArgument().setValue("/nomessage");
92         }
93
94         // Do not display Logo
95
cmd.createArgument().setValue("/nologo");
96
97         if (debug) {
98             cmd.createArgument().setValue("/g");
99         }
100         if (optimize) {
101             cmd.createArgument().setValue("/O");
102         }
103         if (verbose) {
104             cmd.createArgument().setValue("/verbose");
105         }
106
107         addCurrentCompilerArgs(cmd);
108
109         int firstFileName = cmd.size();
110         logAndAddFilesToCompile(cmd);
111
112         return
113             executeExternalCompile(cmd.getCommandline(), firstFileName) == 0;
114     }
115 }
116
Popular Tags