001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM - Initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.build.ant;
011:
012: import org.eclipse.pde.internal.build.IXMLConstants;
013: import org.eclipse.pde.internal.build.Utils;
014:
015: /**
016: * Wrapper class for the Ant javac task.
017: */
018: public class JavacTask implements ITask {
019:
020: protected String classpathId;
021: protected String bootclasspath;
022: protected String destdir;
023: protected String failonerror;
024: protected String[] srcdir;
025: protected String verbose;
026: protected String includeAntRuntime;
027: protected String fork;
028: protected String debug;
029: protected String source;
030: protected String target;
031: protected String compileArgs;
032: protected String compileArgsFile;
033: protected String encoding;
034: protected String logExtension;
035:
036: /**
037: * Default constructor for the class.
038: */
039: public JavacTask() {
040: super ();
041: }
042:
043: /**
044: * @see ITask#print(AntScript)
045: */
046: public void print(AntScript script) {
047: script.printTab();
048: script.print("<javac"); //$NON-NLS-1$
049: script.printAttribute("destdir", destdir, false); //$NON-NLS-1$
050: script.printAttribute("failonerror", failonerror, false); //$NON-NLS-1$
051: script.printAttribute("verbose", verbose, false); //$NON-NLS-1$
052: script.printAttribute("fork", fork, false); //$NON-NLS-1$
053: script.printAttribute("debug", debug, false); //$NON-NLS-1$
054: script.printAttribute(
055: "includeAntRuntime", includeAntRuntime, false); //$NON-NLS-1$
056: script.printAttribute("bootclasspath", bootclasspath, false); //$NON-NLS-1$
057: script.printAttribute("source", source, false); //$NON-NLS-1$
058: script.printAttribute("target", target, false); //$NON-NLS-1$
059: script.printAttribute("encoding", encoding, false); //$NON-NLS-1$
060: script.println(">"); //$NON-NLS-1$
061:
062: script.indent++;
063:
064: if (compileArgs != null) {
065: script
066: .println("<compilerarg line=\"" + compileArgs + "\" compiler=\"" + Utils.getPropertyFormat(IXMLConstants.PROPERTY_BUILD_COMPILER) + "\"/>"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
067: }
068:
069: script.println("<classpath refid=\"" + classpathId + "\" />"); //$NON-NLS-1$ //$NON-NLS-2$
070:
071: for (int i = 0; i < srcdir.length; i++) {
072: script.printTab();
073: script.print("<src path="); //$NON-NLS-1$
074: script.printQuotes(srcdir[i]);
075: script.println("/>"); //$NON-NLS-1$
076: }
077:
078: if (compileArgsFile != null) {
079: script
080: .println("<compilerarg value=\"@" + compileArgsFile + "\" compiler=\"" + IXMLConstants.JDT_COMPILER_ADAPTER + "\"/>"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
081: }
082: if (destdir != null) {
083: script
084: .println("<compilerarg line=\"-log '" + destdir + logExtension + "'\" compiler=\"" + IXMLConstants.JDT_COMPILER_ADAPTER + "\"/>"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
085: }
086: script.indent--;
087: script.printEndTag("javac"); //$NON-NLS-1$
088: }
089:
090: /**
091: * Set the javac task classpath refid to be the given value.
092: * @param classpathId
093: */
094: public void setClasspathId(String classpathId) {
095: this .classpathId = classpathId;
096: }
097:
098: /**
099: * Set the javac task boot classpath to be the given value.
100: *
101: * @param bootclasspath the boot classpath attribute
102: */
103: public void setBootClasspath(String bootclasspath) {
104: this .bootclasspath = bootclasspath;
105: }
106:
107: /**
108: * Set the javac task destination directory to be the given value.
109: *
110: * @param destdir the destination directory
111: */
112: public void setDestdir(String destdir) {
113: this .destdir = destdir;
114: }
115:
116: /**
117: * Set the javac task failOnError attribute to be the given value. Valid values
118: * are <code>"true"</code> and <code>"false"</code>.
119: *
120: * @param failonerror either <code>"true"</code> or <code>"false"</code>
121: */
122: public void setFailOnError(String failonerror) {
123: this .failonerror = failonerror;
124: }
125:
126: /**
127: * Set the javac task includeAntRuntime attribute to be the given value. Valid
128: * values are <code>"no"</code> and <code>"yes"</code>.
129: *
130: * @param include either <code>"no"</code> or <code>"yes"</code>
131: */
132: public void setIncludeAntRuntime(String include) {
133: this .includeAntRuntime = include;
134: }
135:
136: /**
137: * Set the javac task source directory attribute to be the given value.
138: *
139: * @param srcdir the source directory
140: */
141: public void setSrcdir(String[] srcdir) {
142: this .srcdir = srcdir;
143: }
144:
145: /**
146: * Set the javac task verbose attribute to be the given value. Valid values
147: * are <code>"true"</code> and <code>"false"</code>.
148: *
149: * @param verbose either <code>"true"</code> or <code>"false"</code>
150: */
151: public void setVerbose(String verbose) {
152: this .verbose = verbose;
153: }
154:
155: /**
156: * Set the javac task fork attribute to be the given value. Valid values
157: * are <code>"true"</code> and <code>"false"</code>.
158: *
159: * @param fork either <code>"true"</code> or <code>"false"</code>
160: */
161: public void setFork(String fork) {
162: this .fork = fork;
163: }
164:
165: /**
166: * Set the javac task debug attribute to be the given value. Valid values
167: * are <code>"on"</code> and <code>"off"</code>.
168: *
169: * @param debug either <code>"on"</code> or <code>"off"</code>
170: */
171: public void setDebug(String debug) {
172: this .debug = debug;
173: }
174:
175: /**
176: * Set the javac task source attribute to be the given value.
177: *
178: * @param source either <code>"1.3"</code> or <code>"1.4"</code>
179: */
180: public void setSource(String source) {
181: this .source = source;
182: }
183:
184: /**
185: * Set the javac task target attribute to be the given value.
186: *
187: * @param target either <code>"1.3"</code> or <code>"1.4"</code>
188: */
189: public void setTarget(String target) {
190: this .target = target;
191: }
192:
193: public void setCompileArgs(String args) {
194: this .compileArgs = args;
195: }
196:
197: public void setEncoding(String encoding) {
198: this .encoding = encoding;
199: }
200:
201: public void setLogExtension(String extension) {
202: this .logExtension = extension;
203: }
204:
205: public void setCompileArgsFile(String file) {
206: this.compileArgsFile = file;
207: }
208: }
|