File: autodia_java.pl

package info (click to toggle)
autodia 2.00-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, sarge
  • size: 340 kB
  • ctags: 195
  • sloc: perl: 4,676; makefile: 51
file content (318 lines) | stat: -rwxr-xr-x 11,508 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/perl -w

###############################################################
# AutoDIA - Automatic Dia XML.   (C)Copyright 2001 A Trevena  #
#                                                             #
# AutoDIA comes with ABSOLUTELY NO WARRANTY; see COPYING file #
# This is free software, and you are welcome to redistribute  #
# it under certain conditions; see COPYING file for details   #
###############################################################

use strict;

use Getopt::Std;
use Data::Dumper;
use File::Find;

use Autodia;
use Inline (
            Java => 'STUDY',
            STUDY => ['java.lang.Class',
                      'java.lang.reflect.Field',
                      'java.lang.reflect.Method'],
            ) ;
use Inline::Java qw(caught);

# get configuration from command line
my %args=();
getopts("FCsSDOmMaArhHi:o:p:d:t:l:zZvVU:P:",\%args);
my %config = %{get_config(\@ARGV,\%args)};

print "\n\nAutoDia - version ".$Autodia::VERSION."(c) Copyright 2003 A Trevena\n\n" unless ( $config{silent} );

# create new diagram

my $handler;

my $language_handlers = Autodia->getHandlers();
my %language_handlers = %$language_handlers;

print "using language : ", $config{language}, "\n" unless ( $config{silent} );

if (defined $language_handlers{lc($config{language})})
  {
    my $handler_module = $language_handlers{lc($config{language})};
    eval "require $handler_module" or die "can't run $handler_module : $! : $@\n";
    print "\n..using $handler_module\n" unless ( $config{silent} );
    $handler = "$handler_module"->new(\%config);
  }
else
  {
    print "language " , $config{language} , "not supported!";
    print " supported languages are : \n";
    foreach my $language (keys %language_handlers)
      { print "\t$language\n"; }
    die "..quiting\n";
  }

$handler->process();

$handler->output() unless ($config{singlefile});

print "complete. (processed ", scalar(@{$config{filenames}}), " files)\n\n" unless ( $config{silent} );

####################################################################

sub get_config {
  my @ARGV = @{shift()};
  my %args = %{shift()};

  if (defined $args{'V'}) {
    print "\n\nAutoDia - version ".$Autodia::VERSION."(c) copyright 2003 A Trevena\n\n";
    exit;
  }


  $args{'i'} =~ s/\"// if defined $args{'i'};
  $args{'d'} =~ s/\"// if defined $args{'d'};

  if ($args{'h'}) {
    print_instructions();
    exit;
  }

  my %config = ();
  my @filenames = ();

  $config{graphviz} = (defined $args{'z'}) ? 1 : 0;
  $config{language} = (defined $args{'l'}) ? $args{'l'} : "perl";
  $config{silent}   = (defined $args{'S'}) ? 1 : 0;
  $config{graphvizdia} = (defined $args{'Z'}) ? 1 : 0;
  $config{vcg} = (defined $args{'v'}) ? 1 : 0;

  $config{singlefile} = (defined $args{'F'}) ? 1 : 0;
  $config{skipcvs} = (defined $args{'C'}) ? 1 : 0;

  $config{username} = (defined $args{'U'}) ? $args{'U'} : "root";
  $config{password} = (defined $args{'P'}) ? $args{'P'} : "";

  $config{methods}  = 1;
  $config{attributes} = 1;
  $config{public} = (defined $args{'H'}) ? 1 : 0;

  if ( $args{'m'} || $args{'A'}) {
    $config{attributes} = 0;
  }

  if ( $args{'M'} || $args{'a'}) {
    $config{methods} = 0;
  }

  Autodia->setConfig(\%config);

  my %file_extensions = %{Autodia->getPattern()};

  if (defined $args{'i'}) {
    my $last;
    if ($args{l} =~ /^dbi$/i) {
      $filenames[0] = $args{'i'};
    } else {
      foreach my $filename ( split(" ",$args{'i'}) ) {
	unless ( -f $filename ) {

	  if ($last) {
	    $filename = "$last $filename";
	    unless (-f $filename) {
	      warn "cannot find $filename .. ignoring\n";
	      $last = $filename;
	      next;
	    }
	  } else {
	    $last = $filename;
	    warn "cannot find $filename .. ignoring\n";
	    next;
	  }
	}
	undef $last;
	push(@filenames,$filename);
      }
    }
  } 
  if (defined $args{'d'}) {
    print "using directory : " , $args{'d'}, "\n" unless ( $config{silent} );
    my @dirs = split(" ",$args{'d'});
    if (defined $args{'r'}) {
      print "recursively searching files..\n" unless ( $config{silent} );
      find ( { wanted => sub {
		 unless (-d) {
		   my $regex = $file_extensions{regex};
		   push @filenames, $File::Find::name
		     if ($File::Find::name =~ m/$regex/);
		 }
	       },
	       preprocess => sub {
		 my @return;
		 foreach (@_) {
		   push(@return,$_) unless (m/^.*\/?(CVS|RCS)$/ && $config{skipcvs});
		 }
		 return @return;
	       },
	     }, @dirs );
    } 
    unless ( $args{'d'} || $args{'i'} ){
      my @wildcards = @{$file_extensions{wildcards}};
      print "searching files using wildcards : @wildcards \n" unless ( $config{silent} );
      foreach my $directory (@dirs) {
	if ($directory eq 'CVS' and $config{skipcvs}) {
	  warn "skipping $directory\n" unless ( $config{silent} );
	  next;
	}
	print "searching $directory\n" unless ( $config{silent} );
	$directory =~ s|(.*)\/$|$1|;
	foreach my $wildcard (@wildcards) {
	  print "$wildcard" unless ( $config{silent} );
	  print " .. " , <$directory/*.$wildcard>, " \n";
	  push @filenames, <$directory/*.$wildcard>;
	}
      }
    }
  } elsif (@ARGV) {
    @filenames = @ARGV;
  } else {
    print_instructions();
    exit;
  }

  $config{filenames}    = \@filenames;
  $config{use_stdout}   = (defined $args{'O'}) ? 1 : 0;
  $config{templatefile} = (defined $args{'t'}) ? $args{'t'} : undef;
  $config{outputfile}   = (defined $args{'o'}) ? $args{'o'} : "autodia.out.xml";
  $config{no_deps}      = (defined $args{'D'}) ? 1 : 0;
  $config{sort}         = (defined $args{'s'}) ? 1 : 0;

  my $inputpath = "";
  if (defined $args{'p'}) {
    $inputpath = $args{'p'};
    unless ($inputpath =~ m/\/$/)
      {
	$inputpath .= "/";
      }
  }

  $config{inputpath}    = $inputpath;

  return \%config;
}

sub print_instructions {
  print "AutoDia - Automatic Dia XML. Copyright 2001 A Trevena\n\n";
  print <<end;
usage:
autodia.pl ([-i filename [-p path] ] or  [-d directory [-r] ]) [options]
autodia.pl -i filename            : use filename as input
autodia.pl -i "filea fileb filec" : use filea, fileb and filec as input
autodia.pl -i filename -p ..      : use ../filename as input file
autodia.pl -d directoryname       : use *.pl/pm in directoryname as input files
autodia.pl -d 'foo bar quz'       : use *pl/pm in directories foo, bar and quz as input files
autodia.pl -d directory -r        : use *pl/pm in directory and its subdirectories as input files
autodia.pl -d directory -F        : use files in directory but only one file per diagram
autodia.pl -d directory -C        : use files in directory but skip CVS directories
autodia.pl -o outfile.xml         : use outfile.xml as output file (otherwise uses autodial.out.xml)
autodia.pl -O                     : output to stdout
autodia.pl -l language            : parse source as language (ie: C) and look for appropriate filename extensions if also -d
autodia.pl -t templatefile        : use templatefile as template (otherwise uses default)
autodia.pl -l DBI -i "mysql:test:localhost" -U username -P password : use the test database on localhost with username and password as username and password
autodia.pl -z                     : use graphviz to produce dot, gif, jpg or png output
autodia.pl -v                     : output VCG digraph for use with VCG
autodia.pl -D                     : ignore dependancies (ie do not process or display dependancies)
autodia.pl -S                     : silent mode, no output to stdout except with -O
autodia.pl -H                     : show only public/visible methods and attributes
autodia.pl -m                     : show only Class methods
autodia.pl -M                     : do not show Class Methods
autodia.pl -a                     : show only Class Attributes
autodia.pl -A                     : do not show Class Attributes
autodia.pl -h                     : display this help message
autodia.pl -V                     : display copyright message and version number
end
  print "\n\n";
  return;
}

##############################################################################

=head1 NAME

autodia.pl - a perl script using the Autodia modules to create UML Class Diagrams or documents. from code or other data sources.

=head1 INTRODUCTION

AutoDia takes source files as input and using a handler parses them to create documentation through templates. The handlers allow AutoDia to parse any language by providing a handler and registering in in autodia.pm. The templates allow the output to be heavily customised from Dia XML to simple HTML and seperates the logic of the application from the presentation of the results.

AutoDia is written in perl and defaults to the perl handler and file extension matching unless a language is specified using the -l switch.

AutoDia requires Template Toolkit and Perl 5. Some handlers and templates may require additional software, for example the Java SDK for the java handler.

AutoDia can use GraphViz to generate layout coordinates, and can produce di-graphs (notation for directional graphs) in dot (plain or canonical) and vcg, as well as Dia xml.

Helpful information, links and news can be found at the autodia website - http://droogs.org/autodia/

=head1 USAGE

=item C<autodia.pl ([-i filename [-p path] ] or [-d directory [-r] ]) [options]>

=item C<autodia.pl -i filename            : use filename as input>

=item C<autodia.pl -i 'filea fileb filec' : use filea, fileb and filec as input>

=item C<autodia.pl -i filename -p ..      : use ../filename as input file>

=item C<autodia.pl -d directoryname       : use *.pl/pm in directoryname as input files>

=item C<autodia.pl -d 'foo bar quz'       : use *pl/pm in directories foo, bar and quz as input files>

=item C<autodia.pl -d directory -r        : use *pl/pm in directory and its subdirectories as input files>

=item C<autodia.pl -d directory -F        : use files in directory but only one file per diagram>
=item C<autodia.pl -d directory -C        : use files in directory but skip CVS directories>


=item C<autodia.pl -o outfile.xml         : use outfile.xml as output file (otherwise uses autodial.out.xml)>

=item C<autodia.pl -O                     : output to stdout>

=item C<autodia.pl -l language            : parse source as language (ie: C) and look for appropriate filename extensions if also -d>

=item C<autodia.pl -t templatefile        : use templatefile as template (otherwise uses template.xml)>

=item C<autodia.pl -l DBI -i "mysql:test:localhost" -U username -P password : use test database on localhost with username and password as username and password>

=item C<autodia.pl -z                     : use graphviz 'yeah, baby!'>

=item C<autodia.pl -v                     : output VCG digraph for use with VCG>

=item C<autodia.pl -H                     : show only Public/Visible methods>

=item C<autodia.pl -m                     : show only Class methods>

=item C<autodia.pl -M                     : do not show Class Methods>

=item C<autodia.pl -a                     : show only Class Attributes>

=item C<autodia.pl -A                     : do not show Class Attributes>

=item C<autodia.pl -S                     : silent mode, no output to stdout except with -O>

=item C<autodia.pl -h                     : display this help message>

=item C<autodia.pl -V                     : display version and copyright message>

=cut

##############################################################################
##############################################################################