src/share/classes/com/sun/tools/apt/Main.java

changeset 1
9a66ca7c79fa
child 554
9d9f26857129
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/apt/Main.java	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,115 @@
     1.4 +/*
     1.5 + * Copyright 2004 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Sun designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Sun in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.26 + * have any questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.tools.apt;
    1.30 +
    1.31 +import java.io.PrintWriter;
    1.32 +import com.sun.mirror.apt.AnnotationProcessorFactory;
    1.33 +
    1.34 +/**
    1.35 + * The main program for the command-line tool apt.
    1.36 + *
    1.37 + * <p>Nothing described in this source file is part of any supported
    1.38 + * API.  If you write code that depends on this, you do so at your own
    1.39 + * risk.  This code and its internal interfaces are subject to change
    1.40 + * or deletion without notice.
    1.41 + */
    1.42 +public class Main {
    1.43 +
    1.44 +    static {
    1.45 +        ClassLoader loader = Main.class.getClassLoader();
    1.46 +        if (loader != null)
    1.47 +            loader.setPackageAssertionStatus("com.sun.tools.apt", true);
    1.48 +    }
    1.49 +
    1.50 +    /** Command line interface.  If args is <tt>null</tt>, a
    1.51 +     * <tt>NullPointerException</tt> is thrown.
    1.52 +     * @param args   The command line parameters.
    1.53 +     */
    1.54 +    public static void main(String... args) {
    1.55 +        System.exit(process(args));
    1.56 +    }
    1.57 +
    1.58 +    /** Programatic interface.  If args is <tt>null</tt>, a
    1.59 +     * <tt>NullPointerException</tt> is thrown.
    1.60 +     * Output is directed to <tt>System.err</tt>.
    1.61 +     * @param args   The command line parameters.
    1.62 +     */
    1.63 +    public static int process(String... args) {
    1.64 +        return processing(null, null, args);
    1.65 +    }
    1.66 +
    1.67 +    /** Programmatic interface.  If any argument
    1.68 +     * is <tt>null</tt>, a <tt>NullPointerException</tt> is thrown.
    1.69 +     * @param args   The command line parameters.
    1.70 +     * @param out    Where the tool's output is directed.
    1.71 +     */
    1.72 +    public static int process(PrintWriter out, String... args) {
    1.73 +        if (out == null)
    1.74 +            throw new NullPointerException("Parameter out cannot be null.");
    1.75 +        return processing(null, out, args);
    1.76 +    }
    1.77 +
    1.78 +    /** Programmatic interface.  If <tt>factory</tt> or <tt>args</tt>
    1.79 +     * is <tt>null</tt>, a <tt>NullPointerException</tt> is thrown.
    1.80 +     * The &quot;<tt>-factory</tt>&quot; and &quot;<tt>-factorypath</tt>&quot;
    1.81 +     * command line parameters are ignored by this entry point.
    1.82 +     * Output is directed to <tt>System.err</tt>.
    1.83 +     *
    1.84 +     * @param factory The annotation processor factory to use
    1.85 +     * @param args    The command line parameters.
    1.86 +     */
    1.87 +    public static int process(AnnotationProcessorFactory factory, String... args) {
    1.88 +        return process(factory, new PrintWriter(System.err, true), args);
    1.89 +    }
    1.90 +
    1.91 +    /** Programmatic interface.  If any argument
    1.92 +     * is <tt>null</tt>, a <tt>NullPointerException</tt> is thrown.
    1.93 +     * The &quot;<tt>-factory</tt>&quot; and &quot;<tt>-factorypath</tt>&quot;
    1.94 +     * command line parameters are ignored by this entry point.
    1.95 +     *
    1.96 +     * @param factory The annotation processor factory to use
    1.97 +     * @param args   The command line parameters.
    1.98 +     * @param out    Where the tool's output is directed.
    1.99 +     */
   1.100 +    public static int process(AnnotationProcessorFactory factory, PrintWriter out,
   1.101 +                              String... args) {
   1.102 +        if (out == null)
   1.103 +            throw new NullPointerException("Parameter out cannot be null.");
   1.104 +        if (factory == null)
   1.105 +            throw new NullPointerException("Parameter factory cannot be null");
   1.106 +        return processing(factory, out, args);
   1.107 +    }
   1.108 +
   1.109 +    private static int processing(AnnotationProcessorFactory factory,
   1.110 +                                  PrintWriter out,
   1.111 +                                  String... args) {
   1.112 +        if (out == null)
   1.113 +            out = new PrintWriter(System.err, true);
   1.114 +        com.sun.tools.apt.main.Main compiler =
   1.115 +            new com.sun.tools.apt.main.Main("apt", out);
   1.116 +        return compiler.compile(args, factory);
   1.117 +    }
   1.118 +}

mercurial