source: josm/trunk/geticons.pl@ 10564

Last change on this file since 10564 was 10561, checked in by stoecker, 8 years ago

see #13158 - add some sanity checks to geticons script

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 5.2 KB
Line 
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 "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
17my %icons;
18
19my $o = $/;
20
21for 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)?\(\"([^\"]*?)\"(?:, ImageProvider.ImageSizes.[A-Z]+)?\)/)
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
154my %haveicons;
155
156for($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 # svg comes after png due to the glob, so only check for svg's
162 if($ifile =~ /^(.*)\.svg$/)
163 {
164 if($haveicons{"$1.png"})
165 {
166 print STDERR "File $1 exists twice as .svg and .png.\n";
167 }
168 # check for unwanted svg effects
169 if(open FILE, "<","images/$ifile")
170 {
171 undef $/;
172 my $f = <FILE>;
173 close FILE;
174 while($f =~ /style\s*=\s*["']([^"']+)["']/g)
175 {
176 for my $x (split(/\s*;\s*/, $1))
177 {
178 print STDERR "Style starts with minus for $ifile: $x\n" if $x =~ /^-/;
179 }
180 }
181 if($f =~ /viewBox\s*=\s*["']([^"']+)["']/)
182 {
183 my $x = $1;
184 print STDERR "ViewBox has float values for $ifile: $x\n" if $x =~ /\./;
185 }
186 }
187 else
188 {
189 print STDERR "Could not open file $ifile: $1";
190 }
191 }
192 $haveicons{$ifile} = 1;
193 }
194}
195
196for my $img (sort keys %icons)
197{
198 if($img =~ /\.(png|svg)/)
199 {
200 print STDERR "File $img does not exist!\n" if(!-f "images/$img");
201 delete $haveicons{$img};
202 }
203 else
204 {
205 print STDERR "File $img(.svg|.png) does not exist!\n" if(!-f "images/$img.png" && !-f "images/$img.svg");
206 delete $haveicons{"$img.svg"};
207 delete $haveicons{"$img.png"};
208 }
209}
210
211for my $img (sort keys %haveicons)
212{
213 print "$img\n";
214}
Note: See TracBrowser for help on using the repository browser.