1 /******************************************************************************* 2 * Copyright (c) 2000, 2013 IBM Corporation and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * IBM - Initial API and implementation 13 *******************************************************************************/ 14 package org.eclipse.pde.internal.build.ant; 15 16 import org.eclipse.pde.internal.build.IXMLConstants; 17 import org.eclipse.pde.internal.build.Utils; 18 19 /** 20 * Wrapper class for the Ant javac task. 21 */ 22 public class JavacTask implements ITask { 23 24 protected String classpathId; 25 protected String bootclasspath; 26 protected String destdir; 27 protected String failonerror; 28 protected String[] srcdir; 29 protected String verbose; 30 protected String includeAntRuntime; 31 protected String fork; 32 protected String debug; 33 protected String source; 34 protected String target; 35 protected String compileArgs; 36 protected String specificCompileArgs; 37 protected String compileArgsFile; 38 protected String encoding; 39 protected String logExtension; 40 protected String errorProperty; 41 protected String[] excludes; 42 protected String compilerAdapter; 43 protected String warningProperties; 44 private boolean adapterUseLog = false; 45 private boolean adapterUseArgFile = false; 46 47 /** 48 * Default constructor for the class. 49 */ JavacTask()50 public JavacTask() { 51 super(); 52 } 53 54 /** 55 * @see ITask#print(AntScript) 56 */ 57 @Override print(AntScript script)58 public void print(AntScript script) { 59 script.printTab(); 60 script.print("<javac"); //$NON-NLS-1$ 61 script.printAttribute("destdir", destdir, false); //$NON-NLS-1$ 62 script.printAttribute("failonerror", failonerror, false); //$NON-NLS-1$ 63 script.printAttribute("verbose", verbose, false); //$NON-NLS-1$ 64 script.printAttribute("fork", fork, false); //$NON-NLS-1$ 65 script.printAttribute("debug", debug, false); //$NON-NLS-1$ 66 script.printAttribute("includeAntRuntime", includeAntRuntime, false); //$NON-NLS-1$ 67 script.printAttribute("bootclasspath", bootclasspath, false); //$NON-NLS-1$ 68 script.printAttribute("source", source, false); //$NON-NLS-1$ 69 script.printAttribute("target", target, false); //$NON-NLS-1$ 70 script.printAttribute("encoding", encoding, false); //$NON-NLS-1$ 71 script.printAttribute("errorProperty", errorProperty, false); //$NON-NLS-1$ 72 script.printAttribute("compiler", compilerAdapter, false); //$NON-NLS-1$ 73 script.println(">"); //$NON-NLS-1$ 74 75 script.indent++; 76 77 if (compileArgs != null) { 78 script.println("<compilerarg line=\"" + compileArgs + "\" compiler=\"" + Utils.getPropertyFormat(IXMLConstants.PROPERTY_BUILD_COMPILER) + "\"/>"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ 79 } 80 81 if (specificCompileArgs != null) { 82 script.printTabs(); 83 script.print("<compilerarg"); //$NON-NLS-1$ 84 script.printAttribute("line", specificCompileArgs, true); //$NON-NLS-1$ 85 script.printAttribute("compiler", compilerAdapter, false); //$NON-NLS-1$ 86 script.println("/>"); //$NON-NLS-1$ 87 } 88 script.println("<classpath refid=\"" + classpathId + "\" />"); //$NON-NLS-1$ //$NON-NLS-2$ 89 90 for (int i = 0; i < srcdir.length; i++) { 91 script.printTab(); 92 script.print("<src path="); //$NON-NLS-1$ 93 script.printQuotes(srcdir[i]); 94 script.println("/>"); //$NON-NLS-1$ 95 } 96 97 for (int i = 0; excludes != null && i < excludes.length; i++) { 98 script.printTab(); 99 script.print("<exclude "); //$NON-NLS-1$ 100 script.printAttribute("name", excludes[i], true); //$NON-NLS-1$ 101 script.println("/>"); //$NON-NLS-1$ 102 } 103 104 if (warningProperties != null) { 105 script.printTab(); 106 script.print("<compilerarg"); //$NON-NLS-1$ 107 script.printAttribute("line", "-properties '" + warningProperties + "'", true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 108 if (compilerAdapter != null && adapterUseArgFile) 109 script.printAttribute("compiler", compilerAdapter, true); //$NON-NLS-1$ 110 else 111 script.printAttribute("compiler", IXMLConstants.JDT_COMPILER_ADAPTER, true); //$NON-NLS-1$ 112 script.println("/>"); //$NON-NLS-1$ 113 } 114 115 if (compileArgsFile != null) { 116 script.printTabs(); 117 script.print("<compilerarg"); //$NON-NLS-1$ 118 script.printAttribute("value", "@" + compileArgsFile, true); //$NON-NLS-1$ //$NON-NLS-2$ 119 if (compilerAdapter != null && adapterUseArgFile) 120 script.printAttribute("compiler", compilerAdapter, true); //$NON-NLS-1$ 121 else 122 script.printAttribute("compiler", IXMLConstants.JDT_COMPILER_ADAPTER, true); //$NON-NLS-1$ 123 script.println("/>"); //$NON-NLS-1$ 124 } 125 126 if (destdir != null) { 127 script.printTabs(); 128 script.print("<compilerarg"); //$NON-NLS-1$ 129 script.printAttribute("line", "-log '" + destdir + logExtension + "'", true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 130 if (compilerAdapter != null && adapterUseLog) 131 script.printAttribute("compiler", compilerAdapter, true); //$NON-NLS-1$ 132 else 133 script.printAttribute("compiler", IXMLConstants.JDT_COMPILER_ADAPTER, true); //$NON-NLS-1$ 134 script.println("/>"); //$NON-NLS-1$ 135 } 136 script.indent--; 137 script.printEndTag("javac"); //$NON-NLS-1$ 138 } 139 140 /** 141 * Set the javac task classpath refid to be the given value. 142 * @param classpathId 143 */ setClasspathId(String classpathId)144 public void setClasspathId(String classpathId) { 145 this.classpathId = classpathId; 146 } 147 148 /** 149 * Set the javac task boot classpath to be the given value. 150 * 151 * @param bootclasspath the boot classpath attribute 152 */ setBootClasspath(String bootclasspath)153 public void setBootClasspath(String bootclasspath) { 154 this.bootclasspath = bootclasspath; 155 } 156 157 /** 158 * Set the javac task destination directory to be the given value. 159 * 160 * @param destdir the destination directory 161 */ setDestdir(String destdir)162 public void setDestdir(String destdir) { 163 this.destdir = destdir; 164 } 165 166 /** 167 * Set the javac task failOnError attribute to be the given value. Valid values 168 * are <code>"true"</code> and <code>"false"</code>. 169 * 170 * @param failonerror either <code>"true"</code> or <code>"false"</code> 171 */ setFailOnError(String failonerror)172 public void setFailOnError(String failonerror) { 173 this.failonerror = failonerror; 174 } 175 176 /** 177 * Set the javac task includeAntRuntime attribute to be the given value. Valid 178 * values are <code>"no"</code> and <code>"yes"</code>. 179 * 180 * @param include either <code>"no"</code> or <code>"yes"</code> 181 */ setIncludeAntRuntime(String include)182 public void setIncludeAntRuntime(String include) { 183 this.includeAntRuntime = include; 184 } 185 186 /** 187 * Set the javac task source directory attribute to be the given value. 188 * 189 * @param srcdir the source directory 190 */ setSrcdir(String[] srcdir)191 public void setSrcdir(String[] srcdir) { 192 this.srcdir = srcdir; 193 } 194 195 /** 196 * Set patterns to exclude from compilation 197 * @param excludes 198 */ setExcludes(String[] excludes)199 public void setExcludes(String[] excludes) { 200 this.excludes = excludes; 201 } 202 203 /** 204 * Set the javac task verbose attribute to be the given value. Valid values 205 * are <code>"true"</code> and <code>"false"</code>. 206 * 207 * @param verbose either <code>"true"</code> or <code>"false"</code> 208 */ setVerbose(String verbose)209 public void setVerbose(String verbose) { 210 this.verbose = verbose; 211 } 212 213 /** 214 * Set the javac task fork attribute to be the given value. Valid values 215 * are <code>"true"</code> and <code>"false"</code>. 216 * 217 * @param fork either <code>"true"</code> or <code>"false"</code> 218 */ setFork(String fork)219 public void setFork(String fork) { 220 this.fork = fork; 221 } 222 223 /** 224 * Set the javac task debug attribute to be the given value. Valid values 225 * are <code>"on"</code> and <code>"off"</code>. 226 * 227 * @param debug either <code>"on"</code> or <code>"off"</code> 228 */ setDebug(String debug)229 public void setDebug(String debug) { 230 this.debug = debug; 231 } 232 233 /** 234 * Set the javac task source attribute to be the given value. 235 * 236 * @param source either <code>"1.3"</code> or <code>"1.4"</code> 237 */ setSource(String source)238 public void setSource(String source) { 239 this.source = source; 240 } 241 242 /** 243 * Set the javac task target attribute to be the given value. 244 * 245 * @param target either <code>"1.3"</code> or <code>"1.4"</code> 246 */ setTarget(String target)247 public void setTarget(String target) { 248 this.target = target; 249 } 250 setCompileArgs(String args)251 public void setCompileArgs(String args) { 252 this.compileArgs = args; 253 } 254 setSpecificCompileArgs(String args)255 public void setSpecificCompileArgs(String args) { 256 this.specificCompileArgs = args; 257 } 258 setEncoding(String encoding)259 public void setEncoding(String encoding) { 260 this.encoding = encoding; 261 } 262 setLogExtension(String extension)263 public void setLogExtension(String extension) { 264 this.logExtension = extension; 265 } 266 setCompileArgsFile(String file)267 public void setCompileArgsFile(String file) { 268 this.compileArgsFile = file; 269 } 270 setErrorProperty(String errorProperty)271 public void setErrorProperty(String errorProperty) { 272 this.errorProperty = errorProperty; 273 } 274 setCompilerAdapter(String compilerAdapter)275 public void setCompilerAdapter(String compilerAdapter) { 276 this.compilerAdapter = compilerAdapter; 277 } 278 setAdapterUseLog(boolean useLog)279 public void setAdapterUseLog(boolean useLog) { 280 this.adapterUseLog = useLog; 281 282 } 283 setAdapterArgFile(boolean useFile)284 public void setAdapterArgFile(boolean useFile) { 285 this.adapterUseArgFile = useFile; 286 287 } 288 setWarningProperties(String warningProperties)289 public void setWarningProperties(String warningProperties) { 290 this.warningProperties = warningProperties; 291 } 292 } 293