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 |
|
---|
5 | my @default = (
|
---|
6 | "styles/standard/*.xml",
|
---|
7 | "styles/standard/*.mapcss",
|
---|
8 | "data/*.xml",
|
---|
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 | "src/org/openstreetmap/josm/*/*/*/*/*/*.java"
|
---|
15 | );
|
---|
16 |
|
---|
17 | my %icons;
|
---|
18 |
|
---|
19 | my $o = $/;
|
---|
20 |
|
---|
21 | for my $arg (@ARGV ? @ARGV : @default)
|
---|
22 | {
|
---|
23 | for my $file (glob($arg))
|
---|
24 | {
|
---|
25 | open(FILE,"<",$file) or die "Could not open $file\n";
|
---|
26 | #print "Read file $file\n";
|
---|
27 | $/ = $file =~ /\.java$/ ? ";" : $o;
|
---|
28 | my $extends = "";
|
---|
29 | while(my $l = <FILE>)
|
---|
30 | {
|
---|
31 | next if $l =~ /NO-ICON/;
|
---|
32 | if($l =~ /icon\s*[:=]\s*["']([^"'+]+?)["']/)
|
---|
33 | {
|
---|
34 | ++$icons{$1};
|
---|
35 | }
|
---|
36 |
|
---|
37 | if(($l =~ /(?:icon-image|repeat-image|fill-image)\s*:\s*(\"?(.*?)\"?)\s*;/) && ($1 ne "none"))
|
---|
38 | {
|
---|
39 | my $val = $2;
|
---|
40 | my $img = "styles/standard/$val";
|
---|
41 | $img = "styles/$val" if((!-f "images/$img") && -f "images/styles/$val");
|
---|
42 | $img = $val if((!-f "images/$img") && -f "images/$val");
|
---|
43 | ++$icons{$img};
|
---|
44 | }
|
---|
45 | if($l =~ /ImageProvider(?:\.get)?\(\"([^\"]*?)\"\)/)
|
---|
46 | {
|
---|
47 | my $i = $1;
|
---|
48 | $i = "styles/standard/$i" if $i eq "misc/no_icon";
|
---|
49 | ++$icons{$i};
|
---|
50 | }
|
---|
51 | while($l =~ /\/\*\s*ICON\s*\*\/\s*\"(.*?)\"/g)
|
---|
52 | {
|
---|
53 | my $i = $1;
|
---|
54 | ++$icons{$i};
|
---|
55 | }
|
---|
56 | while($l =~ /\/\*\s*ICON\((.*?)\)\s*\*\/\s*\"(.*?)\"/g)
|
---|
57 | {
|
---|
58 | my $i = "$1$2";
|
---|
59 | ++$icons{$i};
|
---|
60 | }
|
---|
61 | if($l =~ /new\s+ImageLabel\(\"(.*?)\"/)
|
---|
62 | {
|
---|
63 | my $i = "statusline/$1";
|
---|
64 | ++$icons{$i};
|
---|
65 | }
|
---|
66 | if($l =~ /createPreferenceTab\(\"(.*?)\"/)
|
---|
67 | {
|
---|
68 | my $i = "preferences/$1";
|
---|
69 | ++$icons{$i};
|
---|
70 | }
|
---|
71 | if($l =~ /setIcon\(\"(.*?)\"/)
|
---|
72 | {
|
---|
73 | my $i = "statusline/$1";
|
---|
74 | ++$icons{$i};
|
---|
75 | }
|
---|
76 | if($l =~ /ImageProvider\.get(?:IfAvailable)?\(\"(.*?)\",\s*\"(.*?)\"\s*\)/)
|
---|
77 | {
|
---|
78 | my $i = "$1/$2";
|
---|
79 | ++$icons{$i};
|
---|
80 | }
|
---|
81 | if($l =~ /new ImageProvider\(\"(.*?)\",\s*\"(.*?)\"\s*\)/)
|
---|
82 | {
|
---|
83 | my $i = "$1/$2";
|
---|
84 | ++$icons{$i};
|
---|
85 | }
|
---|
86 | if($l =~ /ImageProvider\.overlay\(.*?,\s*\"(.*?)\",/)
|
---|
87 | {
|
---|
88 | my $i = $1;
|
---|
89 | ++$icons{$i};
|
---|
90 | }
|
---|
91 | if($l =~ /getCursor\(\"(.*?)\",\s*\"(.*?)\"/)
|
---|
92 | {
|
---|
93 | my $i = "cursor/modifier/$2";
|
---|
94 | ++$icons{$i};
|
---|
95 | $i = "cursor/$1";
|
---|
96 | ++$icons{$i};
|
---|
97 | }
|
---|
98 | if($l =~ /ImageProvider\.getCursor\(\"(.*?)\",\s*null\)/)
|
---|
99 | {
|
---|
100 | my $i = "cursor/$1";
|
---|
101 | ++$icons{$i};
|
---|
102 | }
|
---|
103 | if($l =~ /SideButton*\(\s*(?:mark)?tr\s*\(\s*\".*?\"\s*\)\s*,\s*\"(.*?)\"/)
|
---|
104 | {
|
---|
105 | my $i = "dialogs/$1";
|
---|
106 | ++$icons{$i};
|
---|
107 | }
|
---|
108 | if($l =~ /super\(\s*tr\(\".*?\"\),\s*\"(.*?)\"/s)
|
---|
109 | {
|
---|
110 | my $i = "$extends$1";
|
---|
111 | ++$icons{$i};
|
---|
112 | }
|
---|
113 | if($l =~ /super\(\s*trc\(\".*?\",\s*\".*?\"\),\s*\"(.*?)\"/s)
|
---|
114 | {
|
---|
115 | my $i = "$extends$1";
|
---|
116 | ++$icons{$i};
|
---|
117 | }
|
---|
118 | if($l =~ /audiotracericon\",\s*\"(.*?)\"/s)
|
---|
119 | {
|
---|
120 | my $i = "markers/$1";
|
---|
121 | ++$icons{$i};
|
---|
122 | }
|
---|
123 | if($l =~ /\"(.*?)\",\s*parentLayer/s)
|
---|
124 | {
|
---|
125 | my $i = "markers/$1";
|
---|
126 | ++$icons{$i};
|
---|
127 | }
|
---|
128 | if($l =~ /setButtonIcons.*\{(.*)\}/)
|
---|
129 | {
|
---|
130 | my $t = $1;
|
---|
131 | while($t =~ /\"(.*?)\"/g)
|
---|
132 | {
|
---|
133 | my $i = $1;
|
---|
134 | ++$icons{$i};
|
---|
135 | }
|
---|
136 | }
|
---|
137 | if($l =~ /extends MapMode/)
|
---|
138 | {
|
---|
139 | $extends = "mapmode/";
|
---|
140 | }
|
---|
141 | elsif($l =~ /extends ToggleDialog/)
|
---|
142 | {
|
---|
143 | $extends = "dialogs/";
|
---|
144 | }
|
---|
145 | elsif($l =~ /extends JosmAction/)
|
---|
146 | {
|
---|
147 | $extends = "";
|
---|
148 | }
|
---|
149 | }
|
---|
150 | close FILE;
|
---|
151 | }
|
---|
152 | }
|
---|
153 |
|
---|
154 | my %haveicons;
|
---|
155 |
|
---|
156 | for($i = 1; my @ifiles = (glob("images".("/*" x $i).".png"), glob("images".("/*" x $i).".svg")); ++$i)
|
---|
157 | {
|
---|
158 | for my $ifile (sort @ifiles)
|
---|
159 | {
|
---|
160 | $ifile =~ s/^images\///;
|
---|
161 | $haveicons{$ifile} = 1;
|
---|
162 | }
|
---|
163 | }
|
---|
164 |
|
---|
165 | for my $img (sort keys %icons)
|
---|
166 | {
|
---|
167 | if($img =~ /\.(png|svg)/)
|
---|
168 | {
|
---|
169 | print STDERR "File $img does not exist!\n" if(!-f "images/$img");
|
---|
170 | delete $haveicons{$img};
|
---|
171 | }
|
---|
172 | else
|
---|
173 | {
|
---|
174 | print STDERR "File $img(.svg|.png) does not exist!\n" if(!-f "images/$img.png" && !-f "images/$img.svg");
|
---|
175 | delete $haveicons{"$img.svg"};
|
---|
176 | delete $haveicons{"$img.png"};
|
---|
177 | }
|
---|
178 | }
|
---|
179 |
|
---|
180 | for my $img (sort keys %haveicons)
|
---|
181 | {
|
---|
182 | print "$img\n";
|
---|
183 | }
|
---|