source: josm/trunk/geticons.pl@ 12292

Last change on this file since 12292 was 10566, checked in by stoecker, 8 years ago

see #13084 - fix some errors in icon move

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 5.0 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 $img = $2;
40 ++$icons{$img};
41 }
42 if($l =~ /ImageProvider(?:\.get)?\(\"([^\"]*?)\"(?:, ImageProvider.ImageSizes.[A-Z]+)?\)/)
43 {
44 my $i = $1;
45 ++$icons{$i};
46 }
47 while($l =~ /\/\*\s*ICON\s*\*\/\s*\"(.*?)\"/g)
48 {
49 my $i = $1;
50 ++$icons{$i};
51 }
52 while($l =~ /\/\*\s*ICON\((.*?)\)\s*\*\/\s*\"(.*?)\"/g)
53 {
54 my $i = "$1$2";
55 ++$icons{$i};
56 }
57 if($l =~ /new\s+ImageLabel\(\"(.*?)\"/)
58 {
59 my $i = "statusline/$1";
60 ++$icons{$i};
61 }
62 if($l =~ /createPreferenceTab\(\"(.*?)\"/)
63 {
64 my $i = "preferences/$1";
65 ++$icons{$i};
66 }
67 if($l =~ /setIcon\(\"(.*?)\"/)
68 {
69 my $i = "statusline/$1";
70 ++$icons{$i};
71 }
72 if($l =~ /ImageProvider\.get(?:IfAvailable)?\(\"(.*?)\",\s*\"(.*?)\"\s*\)/)
73 {
74 my $i = "$1/$2";
75 ++$icons{$i};
76 }
77 if($l =~ /new ImageProvider\(\"(.*?)\",\s*\"(.*?)\"\s*\)/)
78 {
79 my $i = "$1/$2";
80 ++$icons{$i};
81 }
82 if($l =~ /ImageProvider\.overlay\(.*?,\s*\"(.*?)\",/)
83 {
84 my $i = $1;
85 ++$icons{$i};
86 }
87 if($l =~ /getCursor\(\"(.*?)\",\s*\"(.*?)\"/)
88 {
89 my $i = "cursor/modifier/$2";
90 ++$icons{$i};
91 $i = "cursor/$1";
92 ++$icons{$i};
93 }
94 if($l =~ /ImageProvider\.getCursor\(\"(.*?)\",\s*null\)/)
95 {
96 my $i = "cursor/$1";
97 ++$icons{$i};
98 }
99 if($l =~ /SideButton*\(\s*(?:mark)?tr\s*\(\s*\".*?\"\s*\)\s*,\s*\"(.*?)\"/)
100 {
101 my $i = "dialogs/$1";
102 ++$icons{$i};
103 }
104 if($l =~ /super\(\s*tr\(\".*?\"\),\s*\"(.*?)\"/s)
105 {
106 my $i = "$extends$1";
107 ++$icons{$i};
108 }
109 if($l =~ /super\(\s*trc\(\".*?\",\s*\".*?\"\),\s*\"(.*?)\"/s)
110 {
111 my $i = "$extends$1";
112 ++$icons{$i};
113 }
114 if($l =~ /audiotracericon\",\s*\"(.*?)\"/s)
115 {
116 my $i = "markers/$1";
117 ++$icons{$i};
118 }
119 if($l =~ /\"(.*?)\",\s*parentLayer/s)
120 {
121 my $i = "markers/$1";
122 ++$icons{$i};
123 }
124 if($l =~ /setButtonIcons.*\{(.*)\}/)
125 {
126 my $t = $1;
127 while($t =~ /\"(.*?)\"/g)
128 {
129 my $i = $1;
130 ++$icons{$i};
131 }
132 }
133 if($l =~ /extends MapMode/)
134 {
135 $extends = "mapmode/";
136 }
137 elsif($l =~ /extends ToggleDialog/)
138 {
139 $extends = "dialogs/";
140 }
141 elsif($l =~ /extends JosmAction/)
142 {
143 $extends = "";
144 }
145 }
146 close FILE;
147 }
148}
149
150my %haveicons;
151
152for($i = 1; my @ifiles = (glob("images".("/*" x $i).".png"), glob("images".("/*" x $i).".svg")); ++$i)
153{
154 for my $ifile (sort @ifiles)
155 {
156 $ifile =~ s/^images\///;
157 # svg comes after png due to the glob, so only check for svg's
158 if($ifile =~ /^(.*)\.svg$/)
159 {
160 if($haveicons{"$1.png"})
161 {
162 print STDERR "File $1 exists twice as .svg and .png.\n";
163 }
164 # check for unwanted svg effects
165 if(open FILE, "<","images/$ifile")
166 {
167 undef $/;
168 my $f = <FILE>;
169 close FILE;
170 while($f =~ /style\s*=\s*["']([^"']+)["']/g)
171 {
172 for my $x (split(/\s*;\s*/, $1))
173 {
174 print STDERR "Style starts with minus for $ifile: $x\n" if $x =~ /^-/;
175 }
176 }
177 if($f =~ /viewBox\s*=\s*["']([^"']+)["']/)
178 {
179 my $x = $1;
180 print STDERR "ViewBox has float values for $ifile: $x\n" if $x =~ /\./;
181 }
182 }
183 else
184 {
185 print STDERR "Could not open file $ifile: $1";
186 }
187 }
188 $haveicons{$ifile} = 1;
189 }
190}
191
192for my $img (sort keys %icons)
193{
194 if($img =~ /\.(png|svg)/)
195 {
196 print STDERR "File $img does not exist!\n" if(!-f "images/$img");
197 delete $haveicons{$img};
198 }
199 else
200 {
201 print STDERR "File $img(.svg|.png) does not exist!\n" if(!-f "images/$img.png" && !-f "images/$img.svg");
202 delete $haveicons{"$img.svg"};
203 delete $haveicons{"$img.png"};
204 }
205}
206
207for my $img (sort keys %haveicons)
208{
209 print "$img\n";
210}
Note: See TracBrowser for help on using the repository browser.