[14982] | 1 | /*
|
---|
| 2 | * Copyright 2001-2005 The Apache Software Foundation
|
---|
| 3 | *
|
---|
| 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
| 5 | * you may not use this file except in compliance with the License.
|
---|
| 6 | * You may obtain a copy of the License at
|
---|
| 7 | *
|
---|
| 8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
| 9 | *
|
---|
| 10 | * Unless required by applicable law or agreed to in writing, software
|
---|
| 11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
| 13 | * See the License for the specific language governing permissions and
|
---|
| 14 | * limitations under the License.
|
---|
| 15 | *
|
---|
| 16 | */
|
---|
| 17 |
|
---|
| 18 | package org.apache.tools.ant.taskdefs.compilers;
|
---|
| 19 |
|
---|
| 20 | import org.apache.tools.ant.BuildException;
|
---|
| 21 | import org.apache.tools.ant.Project;
|
---|
| 22 | import org.apache.tools.ant.types.Commandline;
|
---|
| 23 | import org.apache.tools.ant.types.Path;
|
---|
| 24 |
|
---|
| 25 | /**
|
---|
| 26 | * The implementation of the jikes compiler.
|
---|
| 27 | * This is primarily a cut-and-paste from the original javac task before it
|
---|
| 28 | * was refactored.
|
---|
| 29 | *
|
---|
| 30 | * @since Ant 1.3
|
---|
| 31 | */
|
---|
| 32 | public class Jikes extends DefaultCompilerAdapter {
|
---|
| 33 |
|
---|
| 34 | /**
|
---|
| 35 | * Performs a compile using the Jikes compiler from IBM.
|
---|
| 36 | * Mostly of this code is identical to doClassicCompile()
|
---|
| 37 | * However, it does not support all options like
|
---|
| 38 | * extdirs, deprecation and so on, because
|
---|
| 39 | * there is no option in jikes and I don't understand
|
---|
| 40 | * what they should do.
|
---|
| 41 | *
|
---|
| 42 | * It has been successfully tested with jikes >1.10
|
---|
| 43 | */
|
---|
| 44 | public boolean execute() throws BuildException {
|
---|
| 45 | attributes.log("Using jikes compiler", Project.MSG_VERBOSE);
|
---|
| 46 |
|
---|
| 47 | Commandline cmd = new Commandline();
|
---|
| 48 |
|
---|
| 49 | // For -sourcepath, use the "sourcepath" value if present.
|
---|
| 50 | // Otherwise default to the "srcdir" value.
|
---|
| 51 | Path sourcepath = null;
|
---|
| 52 | if (compileSourcepath != null) {
|
---|
| 53 | sourcepath = compileSourcepath;
|
---|
| 54 | } else {
|
---|
| 55 | sourcepath = src;
|
---|
| 56 | }
|
---|
| 57 | // If the buildfile specifies sourcepath="", then don't
|
---|
| 58 | // output any sourcepath.
|
---|
| 59 | if (sourcepath.size() > 0) {
|
---|
| 60 | cmd.createArgument().setValue("-sourcepath");
|
---|
| 61 | cmd.createArgument().setPath(sourcepath);
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | Path classpath = new Path(project);
|
---|
| 65 |
|
---|
| 66 | if (bootclasspath == null || bootclasspath.size() == 0) {
|
---|
| 67 | // no bootclasspath, therefore, get one from the java runtime
|
---|
| 68 | includeJavaRuntime = true;
|
---|
| 69 | } else {
|
---|
| 70 | // there is a bootclasspath stated. By default, the
|
---|
| 71 | // includeJavaRuntime is false. If the user has stated a
|
---|
| 72 | // bootclasspath and said to include the java runtime, it's on
|
---|
| 73 | // their head!
|
---|
| 74 | }
|
---|
| 75 | classpath.append(getCompileClasspath());
|
---|
| 76 |
|
---|
| 77 | // if the user has set JIKESPATH we should add the contents as well
|
---|
| 78 | String jikesPath = System.getProperty("jikes.class.path");
|
---|
| 79 | if (jikesPath != null) {
|
---|
| 80 | classpath.append(new Path(project, jikesPath));
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | if (extdirs != null && extdirs.size() > 0) {
|
---|
| 84 | cmd.createArgument().setValue("-extdirs");
|
---|
| 85 | cmd.createArgument().setPath(extdirs);
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | String exec = getJavac().getExecutable();
|
---|
| 89 | cmd.setExecutable(exec == null ? "jikes" : exec);
|
---|
| 90 |
|
---|
| 91 | if (deprecation == true) {
|
---|
| 92 | cmd.createArgument().setValue("-deprecation");
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | if (destDir != null) {
|
---|
| 96 | cmd.createArgument().setValue("-d");
|
---|
| 97 | cmd.createArgument().setFile(destDir);
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | cmd.createArgument().setValue("-classpath");
|
---|
| 101 | cmd.createArgument().setPath(classpath);
|
---|
| 102 |
|
---|
| 103 | if (encoding != null) {
|
---|
| 104 | cmd.createArgument().setValue("-encoding");
|
---|
| 105 | cmd.createArgument().setValue(encoding);
|
---|
| 106 | }
|
---|
| 107 | if (debug) {
|
---|
| 108 | String debugLevel = attributes.getDebugLevel();
|
---|
| 109 | if (debugLevel != null) {
|
---|
| 110 | cmd.createArgument().setValue("-g:" + debugLevel);
|
---|
| 111 | } else {
|
---|
| 112 | cmd.createArgument().setValue("-g");
|
---|
| 113 | }
|
---|
| 114 | } else {
|
---|
| 115 | cmd.createArgument().setValue("-g:none");
|
---|
| 116 | }
|
---|
| 117 | if (optimize) {
|
---|
| 118 | cmd.createArgument().setValue("-O");
|
---|
| 119 | }
|
---|
| 120 | if (verbose) {
|
---|
| 121 | cmd.createArgument().setValue("-verbose");
|
---|
| 122 | }
|
---|
| 123 | if (depend) {
|
---|
| 124 | cmd.createArgument().setValue("-depend");
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | if (target != null) {
|
---|
| 128 | cmd.createArgument().setValue("-target");
|
---|
| 129 | cmd.createArgument().setValue(target);
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | /**
|
---|
| 133 | * XXX
|
---|
| 134 | * Perhaps we shouldn't use properties for these
|
---|
| 135 | * three options (emacs mode, warnings and pedantic),
|
---|
| 136 | * but include it in the javac directive?
|
---|
| 137 | */
|
---|
| 138 |
|
---|
| 139 | /**
|
---|
| 140 | * Jikes has the nice feature to print error
|
---|
| 141 | * messages in a form readable by emacs, so
|
---|
| 142 | * that emacs can directly set the cursor
|
---|
| 143 | * to the place, where the error occurred.
|
---|
| 144 | */
|
---|
| 145 | String emacsProperty = project.getProperty("build.compiler.emacs");
|
---|
| 146 | if (emacsProperty != null && Project.toBoolean(emacsProperty)) {
|
---|
| 147 | cmd.createArgument().setValue("+E");
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | /**
|
---|
| 151 | * Jikes issues more warnings that javac, for
|
---|
| 152 | * example, when you have files in your classpath
|
---|
| 153 | * that don't exist. As this is often the case, these
|
---|
| 154 | * warning can be pretty annoying.
|
---|
| 155 | */
|
---|
| 156 | String warningsProperty =
|
---|
| 157 | project.getProperty("build.compiler.warnings");
|
---|
| 158 | if (warningsProperty != null) {
|
---|
| 159 | attributes.log("!! the build.compiler.warnings property is "
|
---|
| 160 | + "deprecated. !!", Project.MSG_WARN);
|
---|
| 161 | attributes.log("!! Use the nowarn attribute instead. !!",
|
---|
| 162 | Project.MSG_WARN);
|
---|
| 163 | if (!Project.toBoolean(warningsProperty)) {
|
---|
| 164 | cmd.createArgument().setValue("-nowarn");
|
---|
| 165 | }
|
---|
| 166 | } if (attributes.getNowarn()) {
|
---|
| 167 | cmd.createArgument().setValue("-nowarn");
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | /**
|
---|
| 171 | * Jikes can issue pedantic warnings.
|
---|
| 172 | */
|
---|
| 173 | String pedanticProperty =
|
---|
| 174 | project.getProperty("build.compiler.pedantic");
|
---|
| 175 | if (pedanticProperty != null && Project.toBoolean(pedanticProperty)) {
|
---|
| 176 | cmd.createArgument().setValue("+P");
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 | /**
|
---|
| 180 | * Jikes supports something it calls "full dependency
|
---|
| 181 | * checking", see the jikes documentation for differences
|
---|
| 182 | * between -depend and +F.
|
---|
| 183 | */
|
---|
| 184 | String fullDependProperty =
|
---|
| 185 | project.getProperty("build.compiler.fulldepend");
|
---|
| 186 | if (fullDependProperty != null
|
---|
| 187 | && Project.toBoolean(fullDependProperty)) {
|
---|
| 188 | cmd.createArgument().setValue("+F");
|
---|
| 189 | }
|
---|
| 190 |
|
---|
| 191 | if (attributes.getSource() != null) {
|
---|
| 192 | cmd.createArgument().setValue("-source");
|
---|
| 193 | String source = attributes.getSource();
|
---|
| 194 | if (source.equals("1.1") || source.equals("1.2")) {
|
---|
| 195 | // support for -source 1.1 and -source 1.2 has been
|
---|
| 196 | // added with JDK 1.4.2, Jikes doesn't like it
|
---|
| 197 | attributes.log("Jikes doesn't support '-source "
|
---|
| 198 | + source + "', will use '-source 1.3' instead");
|
---|
| 199 | cmd.createArgument().setValue("1.3");
|
---|
| 200 | } else {
|
---|
| 201 | cmd.createArgument().setValue(source);
|
---|
| 202 | }
|
---|
| 203 | }
|
---|
| 204 |
|
---|
| 205 | addCurrentCompilerArgs(cmd);
|
---|
| 206 |
|
---|
| 207 | int firstFileName = cmd.size();
|
---|
| 208 |
|
---|
| 209 | if (bootclasspath != null) {
|
---|
| 210 | cmd.createArgument().setValue("-bootclasspath");
|
---|
| 211 | cmd.createArgument().setPath(bootclasspath);
|
---|
| 212 | }
|
---|
| 213 |
|
---|
| 214 | logAndAddFilesToCompile(cmd);
|
---|
| 215 |
|
---|
| 216 | return
|
---|
| 217 | executeExternalCompile(cmd.getCommandline(), firstFileName) == 0;
|
---|
| 218 | }
|
---|
| 219 |
|
---|
| 220 |
|
---|
| 221 | }
|
---|