source: josm/trunk/geticons.pl@ 13279

Last change on this file since 13279 was 13279, checked in by stoecker, 6 years ago

see #15734 - unify output of icon script to form name:message

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