source: josm/trunk/geticons.pl@ 2808

Last change on this file since 2808 was 2808, checked in by stoecker, 14 years ago

first version of a tool to detect icon usage, does not yet detect all icons used in code (see #4338)

  • Property svn:executable set to *
File size: 2.9 KB
RevLine 
[2808]1#! /usr/bin/perl -w
2# short tool to find out all used icons and allows deleting unused icons
3# when building release files
4
5my @default = (
6 "styles/standard/*.xml",
7 "presets/*.xml",
8 "src/org/openstreetmap/josm/*.java",
9 "src/org/openstreetmap/josm/*/*.java",
10 "src/org/openstreetmap/josm/*/*/*.java",
11 "src/org/openstreetmap/josm/*/*/*/*.java",
12 "src/org/openstreetmap/josm/*/*/*/*/*.java",
13 "src/org/openstreetmap/josm/*/*/*/*/*/*.java"
14);
15
16my %icons;
17
18my $o = $/;
19
20for my $arg (@ARGV ? @ARGV : @default)
21{
22 for my $file (glob($arg))
23 {
24 open(FILE,"<",$file) or die "Could not open $file\n";
25 #print "Read file $file\n";
26 $/ = $file =~ /\.java$/ ? ";" : $o;
27 my $extends = "";
28 while(my $l = <FILE>)
29 {
30 if($l =~ /src\s*=\s*["'](.*?)["']/)
31 {
32 ++$icons{"styles/standard/$1"};
33 }
34 elsif($l =~ /icon\s*=\s*["'](.*?)["']/)
35 {
36 ++$icons{$1};
37 }
38
39 if($l =~ /ImageProvider\.get\(\"([^\"]*?)\"\)/)
40 {
41 my $i = $1;
42 $i .= ".png" if !($i =~ /\.png$/);
43 ++$icons{$i};
44 }
45 if($l =~ /new\s+ImageLabel\(\"(.*?)\"/)
46 {
47 my $i = "statusline/$1";
48 $i .= ".png" if !($i =~ /\.png$/);
49 ++$icons{$i};
50 }
51 if($l =~ /createPreferenceTab\(\"(.*?)\"/)
52 {
53 my $i = "preferences/$1";
54 $i .= ".png" if !($i =~ /\.png$/);
55 ++$icons{$i};
56 }
57 if($l =~ /ImageProvider\.get\(\"(.*?)\",\s+\"(.*?)\"\)/)
58 {
59 my $i = "$1/$2";
60 $i .= ".png" if !($i =~ /\.png$/);
61 ++$icons{$i};
62 }
63 if($l =~ /ImageProvider\.getCursor\(\"(.*?)\",\s+\"(.*?)\"\)/)
64 {
65 my $i = "cursor/modifier/$2";
66 $i .= ".png" if !($i =~ /\.png$/);
67 ++$icons{$i};
68 $i = "cursor/$1";
69 $i .= ".png" if !($i =~ /\.png$/);
70 ++$icons{$i};
71 }
72 if($l =~ /super\(\s*tr\(\".*?\"\),\s*\"(.*?)\"/s)
73 {
74 my $i = "$extends$1";
75 $i .= ".png" if !($i =~ /\.png$/);
76 ++$icons{$i};
77 }
78
79 if($l =~ /allowedtypes\s+=.*\{(.*)\}/s)
80 {
81 my $t = $1;
82 while($t =~ /\"(.*?)\"/g)
83 {
84 ++$icons{"Mf_$1.png"};
85 }
86 }
87 if($l =~ /\.setButtonIcons.*\{(.*)\}/)
88 {
89 my $t = $1;
90 while($t =~ /\"(.*?)\"/g)
91 {
92 my $i = $1;
93 $i .= ".png" if !($i =~ /\.png$/);
94 ++$icons{$i};
95 }
96 }
97 if($l =~ /extends MapMode/)
98 {
99 $extends = "mapmode/";
100 }
101 if($l =~ /extends ToggleDialog/)
102 {
103 $extends = "dialogs/";
104 }
105 }
106 close FILE;
107 }
108}
109
110my %haveicons;
111
112for($i = 0; my @ifiles = glob("images".("/*" x $i).".png"); ++$i)
113{
114 for my $ifile (sort @ifiles)
115 {
116 $ifile =~ s/^images\///;
117 $haveicons{$ifile} = 1;
118 }
119}
120
121for my $img (sort keys %icons)
122{
123 print STDERR "File $img does not exist!\n" if(!-f "images/$img");
124 delete $haveicons{$img};
125}
126
127for my $img (sort keys %haveicons)
128{
129 print "$img\n";
130}
Note: See TracBrowser for help on using the repository browser.