-
Notifications
You must be signed in to change notification settings - Fork 0
/
render_class_diagrams.pl
388 lines (321 loc) · 13.4 KB
/
render_class_diagrams.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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
use strict;
use File::Basename;
use Cwd;
use lib Cwd::abs_path(File::Basename::dirname(__FILE__));
use NGCP::BulkProcessor::Globals qw($system_version
$system_abbreviation
$system_instance_label
$application_path
);
our $umldiagrampath = Cwd::abs_path(File::Basename::dirname(__FILE__)) . '/uml/';
our $uml_diagram_format = 'dot'; #'png'
use NGCP::BulkProcessor::Utils qw(
getscriptpath
cleanupdir
makepath
changemod
getscriptpath
);
use NGCP::BulkProcessor::Array qw(contains);
use NGCP::BulkProcessor::Logging qw(
getlogger
scriptinfo
);
use NGCP::BulkProcessor::LogError qw(
fileerror
filewarn
done
);
use File::Find;
use File::Basename;
use UML::Class::Simple;
my $graphviz_dot_path;
if ($^O eq 'MSWin32') {
# IPC run3 used in UML::Class::Simple obviously ignores windows (vista 32)
# PATH variable. so we specify the path to graphviz dot.exe manually:
#$graphviz_dot_path = 'C:\Program Files\Graphviz2.26.3\bin\dot.exe';
$graphviz_dot_path = 'C:\Program Files (x86)\Graphviz2.26.3\bin\dot.exe';
} else {
# unix probably ok - leave UML::Class::Simple alone:
$graphviz_dot_path = undef;
}
my $logger = getlogger(getscriptpath());
my @dirs_to_skip = ();
push @dirs_to_skip,$application_path . "Dao/mr553/";
push @dirs_to_skip,$application_path . "Dao/mr457/";
push @dirs_to_skip,$application_path . "Dao/mr441/";
push @dirs_to_skip,$application_path . "Dao/mr341/";
push @dirs_to_skip,$application_path . "Dao/mr103/";
#push @dirs_to_skip,$application_path . "Dao/mr102/";
push @dirs_to_skip,$application_path . "Dao/mr38/";
push @dirs_to_skip,$application_path . "Dao/Trunk/accounting";
push @dirs_to_skip,$application_path . "Dao/Trunk/billing";
push @dirs_to_skip,$application_path . "Dao/Trunk/kamailio";
push @dirs_to_skip,$application_path . "Redis/mr65/";
push @dirs_to_skip,$application_path . "RestRequests/";
push @dirs_to_skip,$application_path . "Service/";
push @dirs_to_skip,$application_path . "RestConnectors/";
push @dirs_to_skip,$application_path . "Projects/t/";
push @dirs_to_skip,$application_path . "Projects/ETL/";
push @dirs_to_skip,$application_path . "Projects/Export/";
push @dirs_to_skip,$application_path . "Projects/Disaster/";
push @dirs_to_skip,$application_path . "Projects/Migration/";
push @dirs_to_skip,$application_path . "Projects/Massive/Generator/";
push @dirs_to_skip,$application_path . "Projects/Massive/RegistrationMonitoring/";
#push @dirs_to_skip,$application_path . "FileProcessors/";
my $public_only = 1;
my $inherited_methods = 0;
#my @perlfileextensions = ('.pm'); #('.pl','.pm');
my @perlfileextensions = ('.pm');
my $rperlextensions = join('|',map { local $_ = $_ ; $_ = quotemeta($_); $_; } @perlfileextensions);
my @parsedfiles = ();
my $mode = $ARGV[0];
eval {
my $painter;
my $outputfilepath;
if ('cleanup' eq $mode) {
cleanupdir($umldiagrampath,0,\&scriptinfo,\&filewarn,$logger);
} elsif ('all' eq $mode) {
find({ wanted => \&dir_names, follow => 1 }, $application_path);
$outputfilepath = $umldiagrampath . '_' . $system_abbreviation . '_' . $system_instance_label . '.' . $uml_diagram_format;
$painter = getpainter(\@parsedfiles);
if (outputpainter($painter,$outputfilepath) and -e $outputfilepath) {
scriptinfo($outputfilepath . ' created',$logger);
} else {
print STDERR "Could not create $outputfilepath.\n";
}
} elsif ('dao_ngcp' eq $mode) {
$outputfilepath = $umldiagrampath . '_dao_ngcp.' . $uml_diagram_format;
$painter = getpainter([
$application_path . 'SqlRecord.pm',
$application_path . 'Dao/Trunk/provisioning/voip_subscribers.pm',
]);
if (outputpainter($painter,$outputfilepath) and -e $outputfilepath) {
scriptinfo($outputfilepath . ' created',$logger);
} else {
print STDERR "Could not create $outputfilepath.\n";
}
} elsif ('dao_openser' eq $mode) {
$outputfilepath = $umldiagrampath . '_dao_openser.' . $uml_diagram_format;
$painter = getpainter([
$application_path . 'SqlRecord.pm',
$application_path . 'Dao/mr102/openser/location.pm',
$application_path . 'Dao/mr102/openser/voicemail_users.pm',
]);
if (outputpainter($painter,$outputfilepath) and -e $outputfilepath) {
scriptinfo($outputfilepath . ' created',$logger);
} else {
print STDERR "Could not create $outputfilepath.\n";
}
} elsif ('dao_regmon' eq $mode) {
$outputfilepath = $umldiagrampath . '_dao_regmon.' . $uml_diagram_format;
$painter = getpainter([
$application_path . 'SqlRecord.pm',
$application_path . 'Projects/Massive/VodafoneRO/RegistrationMonitoring/Dao/Proc4SwDynamic.pm',
$application_path . 'Projects/Massive/VodafoneRO/RegistrationMonitoring/Dao/Proc4SwStatic.pm',
$application_path . 'Projects/Massive/VodafoneRO/RegistrationMonitoring/Dao/SwStatus.pm',
]);
if (outputpainter($painter,$outputfilepath) and -e $outputfilepath) {
scriptinfo($outputfilepath . ' created',$logger);
} else {
print STDERR "Could not create $outputfilepath.\n";
}
} elsif ('dao_cmtsmon' eq $mode) {
$outputfilepath = $umldiagrampath . '_dao_cmtsmon.' . $uml_diagram_format;
$painter = getpainter([
$application_path . 'SqlRecord.pm',
$application_path . 'Projects/Massive/VodafoneRO/CmtsMonitoring/Dao/SwInputDynamic.pm',
$application_path . 'Projects/Massive/VodafoneRO/CmtsMonitoring/Dao/SwOutput.pm',
]);
if (outputpainter($painter,$outputfilepath) and -e $outputfilepath) {
scriptinfo($outputfilepath . ' created',$logger);
} else {
print STDERR "Could not create $outputfilepath.\n";
}
} elsif ('sql_connectors' eq $mode) {
$outputfilepath = $umldiagrampath . '_sql_connectors.' . $uml_diagram_format;
$painter = getpainter([
$application_path . 'SqlConnector.pm',
$application_path . 'SqlProcessor.pm',
$application_path . 'SqlRecord.pm',
$application_path . 'SqlConnectors/MySQLDB.pm',
$application_path . 'SqlConnectors/OracleDB.pm',
$application_path . 'SqlConnectors/SQLiteDB.pm',
$application_path . 'SqlConnectors/CSVDB.pm',
$application_path . 'SqlConnectors/SQLServerDB.pm',
$application_path . 'SqlConnectors/PostgreSQLDB.pm',
]);
if (outputpainter($painter,$outputfilepath) and -e $outputfilepath) {
scriptinfo($outputfilepath . ' created',$logger);
} else {
print STDERR "Could not create $outputfilepath.\n";
}
} elsif ('no_sql_connectors' eq $mode) {
$outputfilepath = $umldiagrampath . '_no_sql_connectors.' . $uml_diagram_format;
$painter = getpainter([
$application_path . 'NoSqlConnector.pm',
$application_path . 'NoSqlConnectors/Redis.pm',
$application_path . 'NoSqlConnectors/RedisEntry.pm',
$application_path . 'NoSqlConnectors/RedisProcessor.pm',
]);
if (outputpainter($painter,$outputfilepath) and -e $outputfilepath) {
scriptinfo($outputfilepath . ' created',$logger);
} else {
print STDERR "Could not create $outputfilepath.\n";
}
} elsif ('redis' eq $mode) {
$outputfilepath = $umldiagrampath . '_redis.' . $uml_diagram_format;
$painter = getpainter([
$application_path . 'NoSqlConnectors/RedisEntry.pm',
$application_path . 'Redis/mr755/location/usrdom.pm',
$application_path . 'Redis/mr755/location/entry.pm',
]);
if (outputpainter($painter,$outputfilepath) and -e $outputfilepath) {
scriptinfo($outputfilepath . ' created',$logger);
} else {
print STDERR "Could not create $outputfilepath.\n";
}
} elsif ('framework1' eq $mode) {
$outputfilepath = $umldiagrampath . '_framework1.' . $uml_diagram_format;
$painter = getpainter([
$application_path . 'Array.pm',
$application_path . 'Calendar.pm',
$application_path . 'ConnectorPool.pm',
$application_path . 'DSPath.pm',
$application_path . 'DSSorter.pm',
]);
if (outputpainter($painter,$outputfilepath) and -e $outputfilepath) {
scriptinfo($outputfilepath . ' created',$logger);
} else {
print STDERR "Could not create $outputfilepath.\n";
}
} elsif ('framework3' eq $mode) {
$outputfilepath = $umldiagrampath . '_framework3.' . $uml_diagram_format;
$painter = getpainter([
$application_path . 'FileProcessor.pm',
$application_path . 'Globals.pm',
$application_path . 'LoadConfig.pm',
$application_path . 'LogError.pm',
$application_path . 'Logging.pm',
$application_path . 'Mail.pm',
]);
if (outputpainter($painter,$outputfilepath) and -e $outputfilepath) {
scriptinfo($outputfilepath . ' created',$logger);
} else {
print STDERR "Could not create $outputfilepath.\n";
}
} elsif ('framework2' eq $mode) {
$outputfilepath = $umldiagrampath . '_framework2.' . $uml_diagram_format;
$painter = getpainter([
$application_path . 'RestConnector.pm',
$application_path . 'RestItem.pm',
$application_path . 'RestProcessor.pm',
$application_path . 'Serialization.pm',
$application_path . 'Table.pm',
$application_path . 'Utils.pm',
]);
if (outputpainter($painter,$outputfilepath) and -e $outputfilepath) {
scriptinfo($outputfilepath . ' created',$logger);
} else {
print STDERR "Could not create $outputfilepath.\n";
}
}
};
if ($@) {
exit(1);
} else {
done(undef,undef,$logger);
exit(0);
}
sub dir_names {
my $path = $File::Find::dir;
$path .= '/' . $_ if ($_ ne '.' and $_ ne '..');
if (-d $path) {
my $dir = $path . '/';
unless (scalar grep { index($dir, $_, 0) == 0; } @dirs_to_skip) {
#print 'creating perldoc html files for source files in ' . $path . "\n";
push @parsedfiles,createumldiagramsofdir($dir,$umldiagrampath . substr($dir,length($application_path)));
#push @dirs_to_skip,$dir;
}
}
}
sub createumldiagramsofdir {
my ($inputdir,$outputdir) = @_;
makepath($outputdir);
local *DOCDIR;
if (not opendir(DOCDIR, $inputdir)) {
fileerror('cannot opendir ' . $inputdir . ': ' . $!,$logger);
return;
}
my @files = grep { /$rperlextensions$/ && -f $inputdir . $_} readdir(DOCDIR);
closedir DOCDIR;
my @inputfilepaths = ();
foreach my $file (@files) {
my $inputfilepath = $inputdir . $file;
my ($inputfilename,$inputfiledir,$inputfilesuffix) = fileparse($inputfilepath, $rperlextensions);
my $outputfilepath = $outputdir . $inputfilename . '.' . $uml_diagram_format; #'.png';
#unlink $outputfilepath;
my $painter = getpainter($inputfilepath);
# we can explicitly specify the image size
#$painter->size(5, 3.6); # in inches
# ...and change the default title background color:
#$painter->node_color('#ffffff'); # defaults to '#f1e1f4'
# only show public methods and properties
#$painter->public_only(1);
# hide all methods from parent classes
#$painter->inherited_methods(0);
if (outputpainter($painter,$outputfilepath) and -e $outputfilepath) {
changemod($outputfilepath);
push @inputfilepaths,$inputfilepath;
scriptinfo('uml diagram ' . $outputfilepath . ' created for source file ' . $inputfilepath,$logger);
} else {
# write message to STDERR make it look the same as perldoc
print STDERR 'Could not create uml diagram for "' . $inputfilepath . "\".\n";
}
}
if (scalar @inputfilepaths > 0) {
my @dirparts = File::Spec->splitdir($inputdir);
my $outputfilepath = $outputdir . $dirparts[$#dirparts - 1] . '.' . $uml_diagram_format; #'.png';
my $painter = getpainter(\@inputfilepaths);
# we can explicitly specify the image size
#$painter->size(5, 3.6); # in inches
# ...and change the default title background color:
#$painter->node_color('#ffffff'); # defaults to '#f1e1f4'
# only show public methods and properties
#$painter->public_only(1);
# hide all methods from parent classes
#$painter->inherited_methods(0);
if (outputpainter($painter,$outputfilepath) and -e $outputfilepath) {
scriptinfo('uml diagram ' . $outputfilepath . ' created for source dir ' . $inputdir,$logger);
} else {
# write message to STDERR make it look the same as perldoc
print STDERR 'Could not create uml diagram for dir "' . $inputdir . "\".\n";
}
}
return @inputfilepaths;
}
sub getpainter {
my $inputfilepaths = shift;
my @classes = classes_from_files($inputfilepaths);
my $painter = UML::Class::Simple->new(\@classes);
if ($graphviz_dot_path) {
$painter->{dot_prog} = $graphviz_dot_path;
}
$painter->public_only($public_only);
$painter->inherited_methods($inherited_methods);
#$painter->size(8.3, 11.7);
return $painter;
}
sub outputpainter {
my ($painter,$outputfilepath) = @_;
if (scalar @{$painter->as_dom()->{classes}} > 0) {
if ($uml_diagram_format eq 'png') {
$painter->as_png($outputfilepath);
} elsif ($uml_diagram_format eq 'dot') {
$painter->as_dot($outputfilepath);
}
return 1;
} else {
return 0;
}
}