aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tools
diff options
context:
space:
mode:
authorSean Dague2007-08-01 19:20:07 +0000
committerSean Dague2007-08-01 19:20:07 +0000
commit5635a72d52ac1195341df7686b3f7f36c596f156 (patch)
tree2d52ebe8e21bb4dff6f72deb34f42d3f2efa08b8 /tools
parent* Workaround for Mono not correctly implementing the OperatingSystemVersion c... (diff)
downloadopensim-SC_OLD-5635a72d52ac1195341df7686b3f7f36c596f156.zip
opensim-SC_OLD-5635a72d52ac1195341df7686b3f7f36c596f156.tar.gz
opensim-SC_OLD-5635a72d52ac1195341df7686b3f7f36c596f156.tar.bz2
opensim-SC_OLD-5635a72d52ac1195341df7686b3f7f36c596f156.tar.xz
added perl classaudit tool
Diffstat (limited to 'tools')
-rwxr-xr-xtools/classaudit.pl133
1 files changed, 133 insertions, 0 deletions
diff --git a/tools/classaudit.pl b/tools/classaudit.pl
new file mode 100755
index 0000000..efe0069
--- /dev/null
+++ b/tools/classaudit.pl
@@ -0,0 +1,133 @@
1#!/usr/bin/perl
2#
3# Audit tool for OpenSim class and namespace definitions.
4#
5# Copyright 2007 IBM
6#
7# Authors: Sean Dague
8#
9# Redistribution and use in source and binary forms, with or without
10# modification, are permitted provided that the following conditions are met:
11# * Redistributions of source code must retain the above copyright
12# notice, this list of conditions and the following disclaimer.
13# * Redistributions in binary form must reproduce the above copyright
14# notice, this list of conditions and the following disclaimer in the
15# documentation and/or other materials provided with the distribution.
16# * Neither the name of the OpenSim Project nor the
17# names of its contributors may be used to endorse or promote products
18# derived from this software without specific prior written permission.
19#
20# THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
21# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23# DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
24# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31use strict;
32use File::Find;
33use Data::Dumper;
34use constant YELLOW => "\033[33m";
35use constant RED => "\033[31m";
36use constant CLEAR => "\033[0m";
37our %totals;
38
39
40find(\&test, "../OpenSim");
41print Dumper(\%totals);
42
43sub test {
44 my $file = $File::Find::name;
45 my $dir = $File::Find::dir;
46 $file =~ s{^../}{}; #strip off prefix
47 $dir =~ s{^../}{}; #strip off prefix
48
49 return if ($file !~ /\.cs$/);
50 return if ($file =~ /AssemblyInfo\.cs$/);
51
52 print "Processing File: $file\n";
53
54 my $namespace = find_namespace($_);
55 my $class = find_class($_);
56
57
58
59 if(cmp_namespace($namespace, $dir) == 1) {
60 $totals{goodns}++;
61 } else {
62 $totals{badns}++;
63 }
64
65
66 if(cmp_class($namespace, $class, $file) == 1) {
67 $totals{goodclass}++;
68 } else {
69 $totals{badclass}++;
70 }
71 print "\n";
72}
73
74sub find_class {
75 my $file = shift;
76 my $content = slurp($file);
77 if ($content =~ /\n\s*(public|private|protected)?\s*(class|interface)\s+(\S+)/) {
78 return $3;
79 }
80 return "";
81}
82
83sub find_namespace {
84 my $file = shift;
85 my $content = slurp($file);
86
87 if ($content =~ /\bnamespace\s+(\S+)/s) {
88 return $1;
89 }
90 return "";
91}
92
93sub slurp {
94 my $file = shift;
95 local(*IN);
96 local $/ = undef;
97
98 open(IN, "$file") or die "Can't open '$file': $!";
99 my $content = <IN>;
100 close(IN);
101
102 return $content;
103}
104
105sub cmp_class {
106 my ($ns, $class, $file) = @_;
107 $class = "$ns.$class";
108 my $classtrans = $class;
109 $classtrans =~ s{\.}{/}g;
110 $classtrans .= ".cs";
111
112 if($classtrans ne $file) {
113 error(YELLOW, "CLASS: $class != $file");
114 return -1;
115 }
116 return 1;
117}
118
119sub cmp_namespace {
120 my ($ns, $dir) = @_;
121 my $nstrans = $ns;
122 $nstrans =~ s{\.}{/}g;
123
124 if($nstrans ne $dir) {
125 error(RED, "NS: $ns != $dir");
126 return -1;
127 }
128 return 1;
129}
130
131sub error {
132 print @_, CLEAR, "\n";
133}