-
Notifications
You must be signed in to change notification settings - Fork 11
/
makeHelpWebsite.pl
268 lines (248 loc) · 8.8 KB
/
makeHelpWebsite.pl
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#!/usr/bin/perl
#
# Copyright 2007 Egon Willighagen <[email protected]>
#
# License: EPL
#
use diagnostics;
use strict;
my $prefixFeatures = ".";
if (-d "./features") {
$prefixFeatures = "features";
}
my $prefixPlugins = ".";
if (-d "./plugins") {
$prefixPlugins = "plugins";
}
print "Features subdir found: $prefixFeatures\n";
print "Plugins subdir found: $prefixPlugins\n";
# make a clean output
system('rm -Rf output');
system('mkdir -p output');
# First make sure we copy the stylesheets
system('mkdir -p output/PRODUCT_PLUGIN');
system("cp $prefixPlugins/net.bioclipse/*.css output/PRODUCT_PLUGIN/.");
# OK, now start copying in things and create the main index.html
print "Finding features...";
my @features = `find $prefixFeatures -name 'feature.xml'`;
print " found: " . scalar(@features) . "\n";
my %tocs;
my @plugins;
my @featureIDs;
foreach my $feature (@features) {
my $id = "";
if ($feature =~ m/\/([^\/]*)\/feature.xml/) {
$id = $1;
}
push @featureIDs, $id;
print " feature: $id\n";
# extract the plugins from the features
open(my $FEATUREXML, '<', "$prefixFeatures/$id/feature.xml")
or die $!;
my $pluginlines = 0;
while (my $line = <$FEATUREXML>) {
if ($pluginlines == 1) {
if ($line =~ m/id="([^"]*)"/) {
my $plugin = $1;
print " plugin: $plugin\n";
my $dir = "$plugin";
# step I: process the plugin.xml
if (!-e "$prefixPlugins/$dir/plugin.xml") {
# skip it
} else {
open(my $PLUGINXML, '<', "$prefixPlugins/$dir/plugin.xml")
or die $!;
my $extensionElement = 0;
my $extensionPoint = "";
my $tocElement = 0;
my %tocInfo;
my $suffix = "";
while (my $line = <$PLUGINXML>) {
$tocs{$dir.$suffix}{"dir"} = $dir;
if ($line =~ "<extension") {
$extensionElement = 1;
} elsif ($line =~ "</extension") {
$extensionElement = 0;
$extensionPoint = "";
$tocElement = 0;
}
if ($extensionElement == 1) {
if ($line =~ m/point=[\"|\'](.*?)[\"|\']/) {
$extensionPoint = $1;
# print "EP: $extensionPoint\n";
}
if ($extensionPoint eq "org.eclipse.help.toc") {
if ($line =~ m/<toc/) {
$tocElement = 1;
}
if ($tocElement == 1) {
if ($line =~ m/file=[\"|\'](.*?)[\"|\']/) {
my $file = $1;
if ($tocs{$dir}{"tocfile"}) {
$suffix = $suffix . "#"; # deal with more EPs per plugin
}
$tocs{$dir.$suffix}{"tocfile"} = $file;
}
}
}
# print "EXT line: $line";
} # else skip content
}
# step II: process the META-INF/MANIFEST.MF
open(my $MANIFEST, '<', "$prefixPlugins/$dir/META-INF/MANIFEST.MF")
or die $!;
while (my $line = <$MANIFEST>) {
if ($line =~ m/^Bundle-Name:\s*(.*)/) {
my $name = $1;
if ($name eq "\%pluginName") {
# need to to something clever
if (open(my $PLUGINPROPS,
'<',
"$prefixPlugins/$dir/plugin.properties")) {
while (my $line = <$PLUGINPROPS>) {
if ($line =~ /\s*pluginName\s*=\s*(.*)/) {
$name = $1;
$name =~ s/^\s*//g;
$name =~ s/\s*$//g;
}
}
}
}
$tocs{$dir}{"name"} = $name;
} elsif ($line =~ m/^Bundle-Version:\s*(.*)/) {
$tocs{$dir}{"version"} = $1;
} elsif ($line =~ m/^Bundle-Vendor:\s*(.*)/) {
my $name = $1;
if ($name eq "\%providerName") {
# need to to something clever
if (open(my $PLUGINPROPS,
'<',
"$prefixPlugins/$dir/plugin.properties")) {
while (my $line = <$PLUGINPROPS>) {
if ($line =~ /\s*providerName\s*=\s*(.*)/) {
$name = $1;
$name =~ s/^\s*//g;
$name =~ s/\s*$//g;
}
}
}
}
$tocs{$dir}{"vendor"} = $name;
} elsif ($line =~ m/^Bundle-SymbolicName:\s*(.*?);/) {
$tocs{$dir}{"symbolicname"} = $1;
}
}
}
}
} else {
if ($line =~ m/<plugin/) {
$pluginlines = 1;
}
}
}
}
# Iterate over all plugin.xml files, and extract which TOC files are mentioned.
# We cannot assume all of them to be called toc.xml, thought that currently often
# is the case.
foreach my $plugin (@plugins) {
my $dir = $plugin;
}
print "Creating main toc...\n";
open(my $MAINTOC, '>', 'output/index.html')
or die $!;
print {$MAINTOC} "<html>\n";
print {$MAINTOC} "<head>\n";
print {$MAINTOC} " <title>Bioclipse Documentation</title>\n";
print {$MAINTOC} " <link rel=\"stylesheet\" href=\"PRODUCT_PLUGIN/narrow_book.css\" type=\"text/css\">\n";
print {$MAINTOC} "</head>\n";
print {$MAINTOC} "<body>\n";
print {$MAINTOC} " <h1>Plugins</h1>\n";
print {$MAINTOC} " <ul>\n";
foreach my $tocDir (sort keys %tocs) {
next if ($tocDir =~ /#/); # skip EPs for which the $tocDir is already given
my $tocOutputDir = "output/$tocDir";
system("mkdir -p $tocOutputDir");
my $filename = "$tocOutputDir/index.html";
print {$MAINTOC} " <li><a href=\"$tocDir/index.html\">" .
$tocs{$tocDir}{"name"} . "</a> (" . $tocDir . ")</li>\n";
open(my $PLUGINTOC, '>', $filename)
or die $!;
print {$PLUGINTOC} "<html>\n";
print {$PLUGINTOC} "<head>\n";
print {$PLUGINTOC} " <title>" . $tocs{$tocDir}{"name"} . "</title>\n";
print {$PLUGINTOC} " <link rel=\"stylesheet\" href=\"../PRODUCT_PLUGIN/narrow_book.css\" type=\"text/css\">\n";
print {$PLUGINTOC} "</head>\n";
print {$PLUGINTOC} "<body>\n";
print {$PLUGINTOC} " <h1>".$tocs{$tocDir}{"name"}."</h1>\n";
print {$PLUGINTOC} " <table>\n";
print {$PLUGINTOC} " <tr><td><b>Version</b></td><td>".$tocs{$tocDir}{"version"}."</td></tr>\n" if ($tocs{$tocDir}{"version"});
print {$PLUGINTOC} " <tr><td><b>Vendor</b></td><td>".$tocs{$tocDir}{"vendor"}."</td></tr>\n" if ($tocs{$tocDir}{"vendor"});
print {$PLUGINTOC} " <tr><td><b>Symbolic Name</b></td><td>".$tocs{$tocDir}{"symbolicname"}."</td></tr>\n" if ($tocs{$tocDir}{"symbolicname"});
print {$PLUGINTOC} " </table>\n";
# process the 'toc.xml'
my $suffix = "";
while ($tocs{"$tocDir$suffix"}{"tocfile"}) { # OK, a toc.xml is defined
my $tocFileName = "$tocDir/" . $tocs{"$tocDir$suffix"}{"tocfile"};
open(my $TOCXML, '<',"$prefixPlugins/$tocFileName")
or die $!;
my $tocElement = 0;
my $tocStartTag = 0;
my $topicElement = 0;
my $topicLabel = "";
my $topicHREF = "";
while (my $line = <$TOCXML>) {
if ($line =~ "<toc") {
$tocElement++;
$tocStartTag = 1;
} elsif ($line =~ "</toc") {
print {$PLUGINTOC} "</ul>\n";
$tocElement--;
} elsif ($line =~ "<topic") {
$topicElement = 1;
$topicLabel = "";
$topicHREF = "";
}
if ($tocStartTag == 1) {
if ($line =~ m/label=[\"|\'](.*?)[\"|\']/) {
my $label = $1;
print {$PLUGINTOC} "<h2>$label</h2>\n";
print {$PLUGINTOC} "<ul>\n";
}
if ($line =~ m/>/) {
$tocStartTag = 0;
}
}
if ($topicElement == 1) {
if ($line =~ m/label=[\"|\'](.*?)[\"|\']/) {
$topicLabel = $1;
}
if ($line =~ m/href=[\"|\'](.*?)[\"|\']/) {
$topicHREF = $1;
}
if ($line =~ m/\/>/) {
$topicElement = 0;
print {$PLUGINTOC} " <li><a href=\"$topicHREF\">$topicLabel</a></li>\n";
# make sure to copy things too
if ($topicHREF =~ m/(.*)\//) {
my $topicSrcDir = $tocDir."/".$1;
my $topicTargetDir = "output/".$topicSrcDir;
system("mkdir -p $topicTargetDir");
# ok, the next might copy things too many time, but at least the
# images get copied too. Now it just complaints about .svn permission
# stuff :(
system("cp -R $prefixPlugins/$topicSrcDir/* $topicTargetDir "
. '2> /dev/null');
system("find $topicTargetDir -name '.svn' | xargs rm -Rf");
}
}
}
}
$suffix = $suffix . "#";
}
print {$PLUGINTOC} "</body>\n";
print {$PLUGINTOC} "</html>\n";
}
print {$MAINTOC} " </ul>\n";
print {$MAINTOC} "</body>\n";
print {$MAINTOC} "</html>\n";
close(MAINTOC);