source: josm/trunk/geticons.pl@ 13281

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

see #15734 - drop some old checks

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 4.6 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",
[4172]7 "styles/standard/*.mapcss",
[2967]8 "data/*.xml",
[2808]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 {
[13277]25 my @defs;
[2808]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 {
[13277]32 if($l =~ /private static final String ([A-Z_]+) = ("[^"]+")/)
33 {
34 push(@defs, [$1, $2]);
35 }
[7668]36 next if $l =~ /NO-ICON/;
[13277]37 for my $d (@defs)
38 {
39 $l =~ s/$d->[0]/$d->[1]/g;
40 }
[10069]41 if($l =~ /icon\s*[:=]\s*["']([^"'+]+?)["']/)
[2808]42 {
43 ++$icons{$1};
44 }
45
[7670]46 if(($l =~ /(?:icon-image|repeat-image|fill-image)\s*:\s*(\"?(.*?)\"?)\s*;/) && ($1 ne "none"))
[4172]47 {
[10566]48 my $img = $2;
[4172]49 ++$icons{$img};
50 }
[10514]51 if($l =~ /ImageProvider(?:\.get)?\(\"([^\"]*?)\"(?:, ImageProvider.ImageSizes.[A-Z]+)?\)/)
[2808]52 {
53 my $i = $1;
54 ++$icons{$i};
55 }
[4172]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 }
[2808]66 if($l =~ /new\s+ImageLabel\(\"(.*?)\"/)
67 {
68 my $i = "statusline/$1";
69 ++$icons{$i};
70 }
[10069]71 if($l =~ /setIcon\(\"(.*?)\"/)
[2808]72 {
[10069]73 my $i = "statusline/$1";
74 ++$icons{$i};
75 }
76 if($l =~ /ImageProvider\.get(?:IfAvailable)?\(\"(.*?)\",\s*\"(.*?)\"\s*\)/)
77 {
[2808]78 my $i = "$1/$2";
79 ++$icons{$i};
80 }
[10069]81 if($l =~ /new ImageProvider\(\"(.*?)\",\s*\"(.*?)\"\s*\)/)
82 {
83 my $i = "$1/$2";
84 ++$icons{$i};
85 }
[2811]86 if($l =~ /getCursor\(\"(.*?)\",\s*\"(.*?)\"/)
87 {
[2808]88 my $i = "cursor/modifier/$2";
89 ++$icons{$i};
90 $i = "cursor/$1";
91 ++$icons{$i};
92 }
[2811]93 if($l =~ /ImageProvider\.getCursor\(\"(.*?)\",\s*null\)/)
94 {
95 my $i = "cursor/$1";
96 ++$icons{$i};
97 }
[2808]98 if($l =~ /super\(\s*tr\(\".*?\"\),\s*\"(.*?)\"/s)
99 {
100 my $i = "$extends$1";
101 ++$icons{$i};
102 }
[2981]103 if($l =~ /super\(\s*trc\(\".*?\",\s*\".*?\"\),\s*\"(.*?)\"/s)
104 {
105 my $i = "$extends$1";
106 ++$icons{$i};
107 }
[13277]108 if($l =~ /setButtonIcons.*\{(.*)\}/ || $l =~ /setButtonIcons\((.*)\)/ )
[2808]109 {
110 my $t = $1;
111 while($t =~ /\"(.*?)\"/g)
112 {
113 my $i = $1;
114 ++$icons{$i};
115 }
116 }
117 if($l =~ /extends MapMode/)
118 {
119 $extends = "mapmode/";
120 }
[7668]121 elsif($l =~ /extends ToggleDialog/)
[2808]122 {
123 $extends = "dialogs/";
124 }
[10069]125 elsif($l =~ /extends JosmAction/)
126 {
127 $extends = "";
128 }
[2808]129 }
130 close FILE;
131 }
132}
133
134my %haveicons;
135
[7668]136for($i = 1; my @ifiles = (glob("images".("/*" x $i).".png"), glob("images".("/*" x $i).".svg")); ++$i)
[2808]137{
138 for my $ifile (sort @ifiles)
139 {
140 $ifile =~ s/^images\///;
[10561]141 # svg comes after png due to the glob, so only check for svg's
142 if($ifile =~ /^(.*)\.svg$/)
143 {
144 if($haveicons{"$1.png"})
145 {
[13279]146 print STDERR "$1: File exists twice as .svg and .png.\n";
[10561]147 }
148 # check for unwanted svg effects
149 if(open FILE, "<","images/$ifile")
150 {
151 undef $/;
152 my $f = <FILE>;
153 close FILE;
154 while($f =~ /style\s*=\s*["']([^"']+)["']/g)
155 {
156 for my $x (split(/\s*;\s*/, $1))
157 {
[13279]158 print STDERR "$ifile: Style starts with minus: $x\n" if $x =~ /^-/;
[10561]159 }
160 }
161 if($f =~ /viewBox\s*=\s*["']([^"']+)["']/)
162 {
163 my $x = $1;
[13279]164 print STDERR "$ifile: ViewBox has float values: $x\n" if $x =~ /\./;
[10561]165 }
166 }
167 else
168 {
[13279]169 print STDERR "$ifile: Could not open file: $1";
[10561]170 }
171 }
[2808]172 $haveicons{$ifile} = 1;
173 }
174}
175
176for my $img (sort keys %icons)
177{
[7668]178 if($img =~ /\.(png|svg)/)
179 {
[13279]180 print STDERR "$img: File does not exist!\n" if(!-f "images/$img");
[7668]181 delete $haveicons{$img};
182 }
183 else
184 {
[13279]185 print STDERR "$img(.svg|.png): File does not exist!\n" if(!-f "images/$img.png" && !-f "images/$img.svg");
[7668]186 delete $haveicons{"$img.svg"};
187 delete $haveicons{"$img.png"};
188 }
[2808]189}
190
191for my $img (sort keys %haveicons)
192{
[13279]193 print "$img: Unused image.\n";
[2808]194}
Note: See TracBrowser for help on using the repository browser.