1 /* |
|
2 * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. Oracle designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Oracle in the LICENSE file that accompanied this code. |
|
10 * |
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
|
15 * accompanied this code). |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License version |
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 * |
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 * or visit www.oracle.com if you need additional information or have any |
|
23 * questions. |
|
24 */ |
|
25 |
|
26 package com.sun.tools.apt; |
|
27 |
|
28 import java.io.PrintWriter; |
|
29 import com.sun.mirror.apt.AnnotationProcessorFactory; |
|
30 |
|
31 /** |
|
32 * The main program for the command-line tool apt. |
|
33 * |
|
34 * <p>Nothing described in this source file is part of any supported |
|
35 * API. If you write code that depends on this, you do so at your own |
|
36 * risk. This code and its internal interfaces are subject to change |
|
37 * or deletion without notice. |
|
38 */ |
|
39 public class Main { |
|
40 |
|
41 static { |
|
42 ClassLoader loader = Main.class.getClassLoader(); |
|
43 if (loader != null) |
|
44 loader.setPackageAssertionStatus("com.sun.tools.apt", true); |
|
45 } |
|
46 |
|
47 /** Command line interface. If args is <tt>null</tt>, a |
|
48 * <tt>NullPointerException</tt> is thrown. |
|
49 * @param args The command line parameters. |
|
50 */ |
|
51 public static void main(String... args) { |
|
52 System.exit(process(args)); |
|
53 } |
|
54 |
|
55 /** Programatic interface. If args is <tt>null</tt>, a |
|
56 * <tt>NullPointerException</tt> is thrown. |
|
57 * Output is directed to <tt>System.err</tt>. |
|
58 * @param args The command line parameters. |
|
59 */ |
|
60 public static int process(String... args) { |
|
61 return processing(null, null, args); |
|
62 } |
|
63 |
|
64 /** Programmatic interface. If any argument |
|
65 * is <tt>null</tt>, a <tt>NullPointerException</tt> is thrown. |
|
66 * @param args The command line parameters. |
|
67 * @param out Where the tool's output is directed. |
|
68 */ |
|
69 public static int process(PrintWriter out, String... args) { |
|
70 if (out == null) |
|
71 throw new NullPointerException("Parameter out cannot be null."); |
|
72 return processing(null, out, args); |
|
73 } |
|
74 |
|
75 /** Programmatic interface. If <tt>factory</tt> or <tt>args</tt> |
|
76 * is <tt>null</tt>, a <tt>NullPointerException</tt> is thrown. |
|
77 * The "<tt>-factory</tt>" and "<tt>-factorypath</tt>" |
|
78 * command line parameters are ignored by this entry point. |
|
79 * Output is directed to <tt>System.err</tt>. |
|
80 * |
|
81 * @param factory The annotation processor factory to use |
|
82 * @param args The command line parameters. |
|
83 */ |
|
84 public static int process(AnnotationProcessorFactory factory, String... args) { |
|
85 return process(factory, new PrintWriter(System.err, true), args); |
|
86 } |
|
87 |
|
88 /** Programmatic interface. If any argument |
|
89 * is <tt>null</tt>, a <tt>NullPointerException</tt> is thrown. |
|
90 * The "<tt>-factory</tt>" and "<tt>-factorypath</tt>" |
|
91 * command line parameters are ignored by this entry point. |
|
92 * |
|
93 * @param factory The annotation processor factory to use |
|
94 * @param args The command line parameters. |
|
95 * @param out Where the tool's output is directed. |
|
96 */ |
|
97 public static int process(AnnotationProcessorFactory factory, PrintWriter out, |
|
98 String... args) { |
|
99 if (out == null) |
|
100 throw new NullPointerException("Parameter out cannot be null."); |
|
101 if (factory == null) |
|
102 throw new NullPointerException("Parameter factory cannot be null"); |
|
103 return processing(factory, out, args); |
|
104 } |
|
105 |
|
106 private static int processing(AnnotationProcessorFactory factory, |
|
107 PrintWriter out, |
|
108 String... args) { |
|
109 if (out == null) |
|
110 out = new PrintWriter(System.err, true); |
|
111 com.sun.tools.apt.main.Main compiler = |
|
112 new com.sun.tools.apt.main.Main("apt", out); |
|
113 return compiler.compile(args, factory); |
|
114 } |
|
115 } |
|