~ubuntu-branches/ubuntu/jaunty/ant/jaunty-proposed

« back to all changes in this revision

Viewing changes to src/main/org/apache/tools/ant/taskdefs/compilers/Jikes.java

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Gybas
  • Date: 2002-02-14 14:28:48 UTC
  • Revision ID: james.westby@ubuntu.com-20020214142848-2ww7ynmqkj31vlmn
Tags: upstream-1.4.1
ImportĀ upstreamĀ versionĀ 1.4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * The Apache Software License, Version 1.1
 
3
 *
 
4
 * Copyright (c) 2001 The Apache Software Foundation.  All rights
 
5
 * reserved.
 
6
 *
 
7
 * Redistribution and use in source and binary forms, with or without
 
8
 * modification, are permitted provided that the following conditions
 
9
 * are met:
 
10
 *
 
11
 * 1. Redistributions of source code must retain the above copyright
 
12
 *    notice, this list of conditions and the following disclaimer.
 
13
 *
 
14
 * 2. Redistributions in binary form must reproduce the above copyright
 
15
 *    notice, this list of conditions and the following disclaimer in
 
16
 *    the documentation and/or other materials provided with the
 
17
 *    distribution.
 
18
 *
 
19
 * 3. The end-user documentation included with the redistribution, if
 
20
 *    any, must include the following acknowlegement:
 
21
 *       "This product includes software developed by the
 
22
 *        Apache Software Foundation (http://www.apache.org/)."
 
23
 *    Alternately, this acknowlegement may appear in the software itself,
 
24
 *    if and wherever such third-party acknowlegements normally appear.
 
25
 *
 
26
 * 4. The names "The Jakarta Project", "Ant", and "Apache Software
 
27
 *    Foundation" must not be used to endorse or promote products derived
 
28
 *    from this software without prior written permission. For written
 
29
 *    permission, please contact apache@apache.org.
 
30
 *
 
31
 * 5. Products derived from this software may not be called "Apache"
 
32
 *    nor may "Apache" appear in their names without prior written
 
33
 *    permission of the Apache Group.
 
34
 *
 
35
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 
36
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 
37
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
38
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 
39
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
40
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 
41
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 
42
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 
43
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 
44
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 
45
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 
46
 * SUCH DAMAGE.
 
47
 * ====================================================================
 
48
 *
 
49
 * This software consists of voluntary contributions made by many
 
50
 * individuals on behalf of the Apache Software Foundation.  For more
 
51
 * information on the Apache Software Foundation, please see
 
52
 * <http://www.apache.org/>.
 
53
 */
 
54
 
 
55
package org.apache.tools.ant.taskdefs.compilers;
 
56
 
 
57
import org.apache.tools.ant.BuildException;
 
58
import org.apache.tools.ant.Project;
 
59
import org.apache.tools.ant.types.*;
 
60
 
 
61
/**
 
62
 * The implementation of the jikes compiler.
 
63
 * This is primarily a cut-and-paste from the original javac task before it
 
64
 * was refactored.
 
65
 *
 
66
 * @author James Davidson <a href="mailto:duncan@x180.com">duncan@x180.com</a>
 
67
 * @author Robin Green <a href="mailto:greenrd@hotmail.com">greenrd@hotmail.com</a>
 
68
 * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> 
 
69
 * @author <a href="mailto:jayglanville@home.com">J D Glanville</a>
 
70
 */
 
71
public class Jikes extends DefaultCompilerAdapter {
 
72
 
 
73
    /**
 
74
     * Performs a compile using the Jikes compiler from IBM..
 
75
     * Mostly of this code is identical to doClassicCompile()
 
76
     * However, it does not support all options like
 
77
     * bootclasspath, extdirs, deprecation and so on, because
 
78
     * there is no option in jikes and I don't understand
 
79
     * what they should do.
 
80
     *
 
81
     * It has been successfully tested with jikes >1.10
 
82
     *
 
83
     * @author skanthak@muehlheim.de
 
84
     */
 
85
    public boolean execute() throws BuildException {
 
86
        attributes.log("Using jikes compiler", Project.MSG_VERBOSE);
 
87
 
 
88
        Path classpath = new Path(project);
 
89
 
 
90
        // Jikes doesn't support bootclasspath dir (-bootclasspath)
 
91
        // so we'll emulate it for compatibility and convenience.
 
92
        if (bootclasspath != null) {
 
93
            classpath.append(bootclasspath);
 
94
        }
 
95
 
 
96
        // Jikes doesn't support an extension dir (-extdir)
 
97
        // so we'll emulate it for compatibility and convenience.
 
98
        addExtdirsToClasspath(classpath);
 
99
 
 
100
        if ( (bootclasspath == null) || (bootclasspath.size() == 0) ) {
 
101
            // no bootclasspath, therefore, get one from the java runtime
 
102
            includeJavaRuntime = true;
 
103
        } else {
 
104
            // there is a bootclasspath stated.  By default, the
 
105
            // includeJavaRuntime is false.  If the user has stated a
 
106
            // bootclasspath and said to include the java runtime, it's on
 
107
            // their head!
 
108
        }
 
109
        classpath.append(getCompileClasspath());
 
110
 
 
111
        // Jikes has no option for source-path so we
 
112
        // will add it to classpath.
 
113
        classpath.append(src);
 
114
 
 
115
        // if the user has set JIKESPATH we should add the contents as well
 
116
        String jikesPath = System.getProperty("jikes.class.path");
 
117
        if (jikesPath != null) {
 
118
            classpath.append(new Path(project, jikesPath));
 
119
        }
 
120
        
 
121
        Commandline cmd = new Commandline();
 
122
        cmd.setExecutable("jikes");
 
123
 
 
124
        if (deprecation == true)
 
125
            cmd.createArgument().setValue("-deprecation");
 
126
 
 
127
        if (destDir != null) {
 
128
            cmd.createArgument().setValue("-d");
 
129
            cmd.createArgument().setFile(destDir);
 
130
        }
 
131
        
 
132
        cmd.createArgument().setValue("-classpath");
 
133
        cmd.createArgument().setPath(classpath);
 
134
 
 
135
        if (encoding != null) {
 
136
            cmd.createArgument().setValue("-encoding");
 
137
            cmd.createArgument().setValue(encoding);
 
138
        }
 
139
        if (debug) {
 
140
            cmd.createArgument().setValue("-g");
 
141
        }
 
142
        if (optimize) {
 
143
            cmd.createArgument().setValue("-O");
 
144
        }
 
145
        if (verbose) {
 
146
            cmd.createArgument().setValue("-verbose");
 
147
        }
 
148
        if (depend) {
 
149
            cmd.createArgument().setValue("-depend");
 
150
        } 
 
151
        /**
 
152
         * XXX
 
153
         * Perhaps we shouldn't use properties for these
 
154
         * three options (emacs mode, warnings and pedantic),
 
155
         * but include it in the javac directive?
 
156
         */
 
157
 
 
158
        /**
 
159
         * Jikes has the nice feature to print error
 
160
         * messages in a form readable by emacs, so
 
161
         * that emacs can directly set the cursor
 
162
         * to the place, where the error occured.
 
163
         */
 
164
        String emacsProperty = project.getProperty("build.compiler.emacs");
 
165
        if (emacsProperty != null && Project.toBoolean(emacsProperty)) {
 
166
            cmd.createArgument().setValue("+E");
 
167
        }
 
168
 
 
169
        /**
 
170
         * Jikes issues more warnings that javac, for
 
171
         * example, when you have files in your classpath
 
172
         * that don't exist. As this is often the case, these
 
173
         * warning can be pretty annoying.
 
174
         */
 
175
        String warningsProperty = project.getProperty("build.compiler.warnings");
 
176
        if (warningsProperty != null) {
 
177
            attributes.log("!! the build.compiler.warnings property is deprecated. !!",
 
178
                           Project.MSG_WARN);
 
179
            attributes.log("!! Use the nowarn attribute instead. !!",
 
180
                           Project.MSG_WARN);
 
181
            if (!Project.toBoolean(warningsProperty)) {
 
182
                cmd.createArgument().setValue("-nowarn");
 
183
            }
 
184
        } if (attributes.getNowarn()) {
 
185
            /* 
 
186
             * FIXME later
 
187
             *
 
188
             * let the magic property win over the attribute for backwards 
 
189
             * compatibility
 
190
             */
 
191
            cmd.createArgument().setValue("-nowarn");
 
192
        }
 
193
 
 
194
        /**
 
195
         * Jikes can issue pedantic warnings. 
 
196
         */
 
197
        String pedanticProperty = project.getProperty("build.compiler.pedantic");
 
198
        if (pedanticProperty != null && Project.toBoolean(pedanticProperty)) {
 
199
            cmd.createArgument().setValue("+P");
 
200
        }
 
201
 
 
202
        /**
 
203
         * Jikes supports something it calls "full dependency
 
204
         * checking", see the jikes documentation for differences
 
205
         * between -depend and +F.
 
206
         */
 
207
        String fullDependProperty = project.getProperty("build.compiler.fulldepend");
 
208
        if (fullDependProperty != null && Project.toBoolean(fullDependProperty)) {
 
209
            cmd.createArgument().setValue("+F");
 
210
        }
 
211
 
 
212
        int firstFileName = cmd.size();
 
213
        logAndAddFilesToCompile(cmd);
 
214
 
 
215
        return executeExternalCompile(cmd.getCommandline(), firstFileName) == 0;
 
216
    }
 
217
 
 
218
 
 
219
}