/* // $Id: //guest/julian_hyde/saffron/src/main/openjava/ojc/OpenJavaTask.java#1 $ // (C) Copyright 2002 Julian Hyde // jhyde, 16 February, 2002 */ package openjava.ojc; import openjava.tools.DebugOut; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.taskdefs.Javac; import org.apache.tools.ant.types.Path; import org.apache.tools.ant.util.GlobPatternMapper; import org.apache.tools.ant.util.SourceFileScanner; import java.io.File; import java.io.IOException; import java.util.Vector; /** * <code>OpenJavaTask</code> is an <a * href="http://jakarta.apache.org/ant/">ANT</a> task to invoke <a * href="http://www.hlla.is.ac.jp/~mich/openjava/">OpenJava</a>. * * <p> To use it, include this class on Ant's classpath, and put<blockquote> * <pre><taskdef name="ojavac" classname="openjava.ojc.OpenJavaTask"/></pre> * </blockquote> in your build file. Arguments: * * <table> * <tr><th>Attribute</th><th>Type</th> * <th>Description</th><th>Required</th></tr> * <tr> * <td>verbose</td> * <td>boolean</td> * <td>Sets whether output is verbose. This * is a boolean option. The default is false.</td> * <td>No</td> * </tr> * <tr> * <td>debugInfo</td> * <td>int</td> * <td>Specifies debugging info level.</td> * <td>No, default 0</td> * </tr> * <tr> * <td>debugToErr</td> * <td>boolean</td> * <td>Specifies whether to write debugging output to stderr or to * stdout.</td> * <td>No, default true</td> * </tr> * <tr> * <td>srcdir</td> * <td>path</td> * <td>Specifies where to look for source files. (See the note about * <code>destdir</code> <a href="#destdir">below</a>.)</td> * <td>Yes</td> * </tr> * <tr> * <td>destDir</td> * <td>directory</td> * <td>Specifies where to place generated files.</td> * <td>No, default is the current directory</td> * </tr> * <tr> * <td>compiler</td> * <td>class</td> * <td>Specify name of the class which acts as Java compiler. This must * be a class which implements {@link openjava.ojc.JavaCompiler} (such * as {@link openjava.ojc.SunJavaCompiler}, {@link * openjava.obj.NullCompiler}, {@link openjava.ojc.SunLibCompiler}).</td> * <td>No, default is {@link openjava.ojc.SunJavaCompiler}</td> * </tr> * <tr> * <td>defaultMeta</td> * <td>file</td> * <td>Specifies separated meta-binding configurations</td> * <td>No</td> * </tr> * <tr> * <td>caller</td> * <td>boolean</td> * <td>Sets whether to translate caller-side code.</td> * <td>No, default is true</td> * </tr> * <tr> * <td>compilerArgs</td> * <td>string</td> * <td>Argument string to pass to the Java compiler</td> * <td>No</td> * </tr> * <tr> * <td>jvmArgs</td> * <td>string</td> * <td>Argument string to pass to the Java VM</td> * <td>No</td> * </tr> * </table> * * Notes:<ol> * <li>Because <code>OpenJavaTask</code> extends Ant's <code>javac</code> task * (<code>class {@link Javac}), all <code>javac</code>'s options are * available too.</li> * <li><a name="destdir"><code>destdir</code> retains its <code>javac</code> * meaning: it is the * directory where <code>.class</code> files are placed. The * <code>-d</code> argument to <code>OpenJava</code> is not exposed: * generated <code>.java</code> files are always placed alongside the * source <code>.oj</code> files under <code>srcdir</code>.</a></li> * <li>The <code>-J</code> argument to <code>OpenJava</code> is not exposed. * The OpenJava compiler inherits from Ant's virtual machine. (I don't know * whether <code>fork</code> works, or what happens.)</li> * <li>The <code>-C</code> argument to <code>OpenJava</code> is not exposed. * The OpenJava compiler inherits Java compiler settings from Ant's * <code>javac</code> task.</li> * </ol> * @author jhyde * @since 16 February, 2002 * @version $Id: //guest/julian_hyde/saffron/src/main/openjava/ojc/OpenJavaTask.java#1 $ **/ public class OpenJavaTask extends Javac implements JavaCompiler { private Vector argVector = new Vector(); private Path src; private File destDir; private Vector compileList; private File[] files; public void execute() throws BuildException { try { String[] args = getArgs(); CommandArguments commandArgs = new TaskCommandArguments(args, this); new Compiler(commandArgs).run(); } catch (Exception e) { throw new BuildException(e.toString()); } } private String[] getArgs() { if (src == null) { throw new BuildException( "srcdir attribute must be set!", location); } String[] list = src.list(); if (list.length == 0) { throw new BuildException( "srcdir attribute must be set!", location); } if (destDir != null && !destDir.isDirectory()) { throw new BuildException( "destination directory \"" + destDir + "\" does not exist or is not a directory", location); } // scan source directories and dest directory to build up compile lists compileList = new Vector(); for (int i = 0; i < list.length; i++) { File srcDir = (File)project.resolveFile(list[i]); if (!srcDir.exists()) { throw new BuildException( "srcdir \"" + srcDir.getPath() + "\" does not exist!", location); } DirectoryScanner ds = getDirectoryScanner(srcDir); String[] files = ds.getIncludedFiles(); scanDir(srcDir, destDir != null ? destDir : srcDir, files); } this.files = new File[compileList.size()]; compileList.copyInto(files); for (int i = 0; i < files.length; i++) { argVector.addElement(files[i].toString()); } String[] args = new String[argVector.size()]; argVector.copyInto(args); if (false) { System.out.print("args={"); for (int i = 0; i < args.length; i++) { System.out.println((i == 0 ? "" : ",") + args[i]); } System.out.println("}"); } return args; } /** * Scans the directory looking for source files to be compiled. * The results are returned in the class variable compileList. */ protected void scanDir(File srcDir, File destDir, String files[]) { GlobPatternMapper m = new GlobPatternMapper(); m.setFrom("*.oj"); m.setTo("*.java"); SourceFileScanner sfs = new SourceFileScanner(this); File[] newFiles = sfs.restrictAsFiles(files, srcDir, destDir, m); for (int i = 0; i < newFiles.length; i++) { compileList.addElement(newFiles[i]); } } public void setVerbose(boolean b) { if (b) { argVector.addElement("-verbose"); } } public void setDebugInfo(int i) { if (i > 0) { argVector.addElement("-g=" + i); } } public void setDebugToErr(boolean b) { if (!b) { DebugOut.setDebugOut(System.out); } } public void setSrcdir(Path src) { super.setSrcdir(src); this.src = src; } public void setDestdir(File f) { super.setDestdir(f); this.destDir = f; argVector.addElement("-d" + f); } public void setCompiler(Class c) { argVector.addElement("-compiler=" + c); } public void setDefaultMeta(File f) { argVector.addElement("--default-meta=" + f); } public void setCaller(boolean b) { if (!b) { argVector.addElement("-calleroff"); } } /** * Implements JavaCompiler, by calling the superclass {@link #execute} * method. This is nice, because all of the options have been set already. **/ public void compile(String[] args) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < args.length; i++) { if (i > 0) { sb.append(","); } sb.append(args[i]); } setIncludes(sb.toString()); setExcludes(null); super.execute(); } /** * <code>TaskCommandArguments</code> is a cunning implementation which * gives this {@link OpenJavaTask} rather than creating a new compiler * object. This means that we can use the options which have already been * set in it. **/ private static class TaskCommandArguments extends CommandArguments { OpenJavaTask task; TaskCommandArguments(String[] args, OpenJavaTask task) throws IOException { super(args); this.task = task; } // override CommandArguments public JavaCompiler getJavaCompiler() { return task; } }; } // End OpenJavaTask.java
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 1474 | Julian Hyde |
saffron: Aggregations are working. Renamed 'aggregator' to 'aggregation'. |