forked from processing/processing-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcessingWeblet.java
More file actions
179 lines (157 loc) · 6.14 KB
/
ProcessingWeblet.java
File metadata and controls
179 lines (157 loc) · 6.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import java.io.IOException;
import writers.ClassWriter;
import writers.FieldWriter;
import writers.FunctionWriter;
import writers.IndexWriter;
import writers.LibraryWriter;
import writers.Shared;
import writers.XMLReferenceWriter;
import com.sun.javadoc.ClassDoc;
import com.sun.javadoc.FieldDoc;
import com.sun.javadoc.MethodDoc;
import com.sun.javadoc.RootDoc;
import com.sun.javadoc.Tag;
import com.sun.tools.doclets.standard.Standard;
/*
* @author David Wicks
* ProcessingWeblet generates the web reference for processing.org and download
* The source code of processing is parsed for webref tags to determine what gets included
* Flags for javadoc when running include:
* -templatedir where to find the html templates for output
* -examplesdir where to find the xml describing the examples to go in the reference
* -localref the local reference output directory
* -webref the web reference output directory
* -corepackage pass in as many of these as necessary to have things considered as part of the core (not a library) e.g -corepackage processing.xml
* -includedir where to find things that aren't in the source, but only in xml e.g. [] (arrayaccess)
*/
public class ProcessingWeblet extends Standard {
private static String examplesFlag = "-examplesdir";
private static String templateFlag = "-templatedir";
private static String outputFlag = "-webref";
private static String exceptionsFlag = "-includedir";
private static String imagesFlag = "-imagedir";
private static String localFlag = "-localref";
private static String coreFlag = "-corepackage"; //to allow for exceptions like XML being in the core
private static String verboseFlag = "-noisy";
private static String rootFlag = "-rootclass";
private static String xmlDescriptionFlag = "-includeXMLTag";
private static IndexWriter indexWriter;
public static boolean start(RootDoc root)
{
setConfig(root.options());
Shared.i().createBaseDirectories();
indexWriter = new IndexWriter();
try
{
// write out everything in the .java files:
// Classes, Methods, Fields ... see specific XxxWriters
System.out.println("\n===Writing .javadoc sourced reference.===");
writeContents(root);
// write out everything in the include directory:
// see: /api_en/include
System.out.println("===Source code @webref files written.===");
if (!Shared.i().getIncludeDirectory().equals(""))
{
System.out.println("\n===Writing XML-sourced reference.===");
XMLReferenceWriter.write( Shared.i().getIncludeDirectory(), indexWriter);
System.out.println("===Include directory files written.===");
}
// write out the index file
System.out.println("\n===Telling the index to write itself.===");
indexWriter.write();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("===All finished in the weblet.===");
return true;
}
private static void setConfig(String[][] configOptions) {
//
Shared.i().corePackages.add("processing.core");
Shared.i().rootClasses.add("PApplet");
Shared.i().rootClasses.add("PConstants");
// look at all possible options (this .equals thing kills switch statements...or does it?)
for (String[] option : configOptions) {
if (option[0].equals(templateFlag)) {
Shared.i().setTemplateDirectory(option[1]);
} else if (option[0].equals(examplesFlag)) {
Shared.i().setExampleDirectory(option[1]);
} else if (option[0].equals(outputFlag)) {
Shared.i().setOutputDirectory(option[1]);
} else if (option[0].equals(exceptionsFlag)) {
// write out files based on exceptions index
Shared.i().setIncludeDirectory( option[1] );
} else if (option[0].equals(imagesFlag)) {
Shared.i().setImageDirectory(option[1]);
} else if( option[0].equals(localFlag) )
{
Shared.i().setLocalOutputDirectory(option[1]);
} else if( option[0].equals(coreFlag)){
Shared.i().corePackages.add(option[1]);
} else if(option[0].equals(verboseFlag)){
Shared.i().setNoisy(true);
} else if( option[0].equals(rootFlag)){
Shared.i().rootClasses.add(option[1]);
} else if( option[0].equals(xmlDescriptionFlag) ) {
Shared.i().addDescriptionTag( option[1] );
}
}
}
public static int optionLength(String option) {
if (option.equals(templateFlag) || option.equals(examplesFlag)
|| option.equals(outputFlag) || option.equals(rootFlag)
|| option.equals(exceptionsFlag) || option.equals(imagesFlag)
|| option.equals(localFlag) || option.equals(coreFlag)
|| option.equals(xmlDescriptionFlag)) {
return 2;
} else if ( option.equals(verboseFlag) ){
return 1;
}
return 0;
}
private static void writeContents(RootDoc root) throws IOException {
for( ClassDoc classDoc : root.classes() ){
if(Shared.i().isCore(classDoc)){
// Document the core functions and classes
if(Shared.i().isRootLevel(classDoc)){
//if it is in PApplet, PConstants or other classes where users can get
//the variables without using dot syntax
// document functions
MethodDoc[] functions = classDoc.methods();
for (MethodDoc fn : functions) {
// write out html reference
FunctionWriter.write(fn);
Tag[] tags = fn.tags(Shared.i().getWebrefTagName());
if (tags.length != 0) {
// add to the index under the @webref category:sub_category
indexWriter.addItem(fn, tags[0]);
}
}
//also need to add fields
for(FieldDoc doc : classDoc.fields()){
if(Shared.i().isWebref(doc)){
FieldWriter.write(doc);
indexWriter.addItem(doc, doc.tags(Shared.i().getWebrefTagName())[0] );
}
}
} else {
// document a class and its public properties
new ClassWriter().write( classDoc );
Tag[] classTags = classDoc.tags(Shared.i().getWebrefTagName());
if (classTags.length != 0) {
// add to the index under the @webref category:sub_category
indexWriter.addItem(classDoc, classTags[0]);
}
}
} else {
// Document the library passed in
if(Shared.i().isNoisy()) {
System.out.println("Loaded class: " + classDoc.name());
}
LibraryWriter writer = new LibraryWriter();
writer.write(classDoc.containingPackage());
}
}
}
}