3 import java.io.FileNotFoundException;
4 import java.io.FileOutputStream;
5 import java.io.IOException;
6 import java.io.OutputStream;
8 import js.common.CLIToolProgressMonitor;
9 import js.common.ToolProgressMonitor;
10 import js.tinyvm.util.TinyVMCommandLineParser;
12 import org.apache.commons.cli.CommandLine;
17 public class TinyVM extends TinyVMTool
19 private TinyVMCommandLineParser fParser;
22 * Main entry point for command line usage.
24 * @param args command line
26 public static void main (String[] args)
30 TinyVM tinyVM = new TinyVM(new CLIToolProgressMonitor());
33 catch (TinyVMException e)
35 System.err.println(e.getMessage());
43 public TinyVM (ToolProgressMonitor monitor)
46 fParser = new TinyVMCommandLineParser();
52 * @param args command line
53 * @throws TinyVMException
55 public void start (String[] args) throws TinyVMException
57 assert args != null: "Precondition: args != null";
59 CommandLine commandLine = fParser.parse(args);
62 boolean verbose = commandLine.hasOption("v");
63 String classpath = commandLine.getOptionValue("cp");
64 String output = commandLine.getOptionValue("o");
65 boolean all = commandLine.hasOption("a");
66 boolean bigEndian = "be".equalsIgnoreCase(commandLine
67 .getOptionValue("wo"));
70 String[] classes = commandLine.getArgs();
72 ((CLIToolProgressMonitor) getProgressMonitor()).setVerbose(verbose);
74 OutputStream stream = null;
77 stream = output == null
78 ? (OutputStream) System.out
79 : (OutputStream) new FileOutputStream(output);
80 link(classpath, classes, all, stream, bigEndian);
82 catch (FileNotFoundException e)
84 throw new TinyVMException(e.getMessage(), e);
88 if (stream instanceof FileOutputStream)
96 throw new TinyVMException(e);