01: /*
02: * Copyright 2006 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package com.google.doctool.custom;
17:
18: import com.sun.javadoc.Doclet;
19: import com.sun.javadoc.RootDoc;
20: import com.sun.tools.doclets.standard.Standard;
21: import com.sun.tools.javadoc.Main;
22:
23: import java.util.ArrayList;
24: import java.util.Arrays;
25: import java.util.List;
26:
27: /**
28: * A doclet for using GWT-specific tags in standard javadoc output.
29: */
30: public class GWTJavaDoclet extends Doclet {
31:
32: static RootDoc root = null;
33:
34: private static final String[] TAGLET_ARGS = new String[] {
35: "-taglet", ExampleTaglet.class.getName(), "-taglet",
36: TipTaglet.class.getName(), "-taglet",
37: IncludeTaglet.class.getName() };
38:
39: public static void main(String[] args) {
40: List examplePackages = new ArrayList();
41: List filteredArgs = new ArrayList();
42:
43: // filter out and save packages args
44: for (int i = 0; i < args.length; ++i) {
45: if (args[i].equalsIgnoreCase("-examplepackages")) {
46: String nextArg = args[++i];
47: String[] split = nextArg.split(":|;");
48: for (int j = 0; j < split.length; ++j) {
49: examplePackages.add(split[j]);
50: }
51: } else if (args[i].equalsIgnoreCase("-packages")) {
52: String nextArg = args[++i];
53: String[] split = nextArg.split(":|;");
54: for (int j = 0; j < split.length; ++j) {
55: filteredArgs.add(split[j]);
56: }
57: } else {
58: filteredArgs.add(args[i]);
59: }
60: }
61:
62: // Build a javadoc structure that includes example packages for reference
63: String name = GWTJavaDoclet.class.getName();
64: List myArgs = new ArrayList();
65: myArgs.addAll(filteredArgs);
66: myArgs.addAll(examplePackages);
67: Main.execute(name, name, (String[]) myArgs
68: .toArray(new String[] {}));
69:
70: // Now delegate to the real javadoc without the example packages
71: filteredArgs.addAll(0, Arrays.asList(TAGLET_ARGS));
72: Main.execute((String[]) filteredArgs.toArray(new String[] {}));
73: }
74:
75: public static int optionLength(String option) {
76: // delegate
77: return Standard.optionLength(option);
78: }
79:
80: public static boolean start(RootDoc root) {
81: // cache the root; ExampleTag will use it for reference later.
82: GWTJavaDoclet.root = root;
83: return true;
84: }
85:
86: }
|