source: josm/trunk/scripts/geticons.pl@ 14900

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

see #15240 - detect another type of ImageProvider calls for in image check script

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 4.7 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 }
[13857]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 }
[13857]76 if($l =~ /ImageProvider\.get(?:IfAvailable)?\(\"(.*?)\",\s*\"(.*?)\"(?:, (?:ImageProvider\.)?ImageSizes\.[A-Z]+)?\s*\)/)
[10069]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;
[13384]154 for my $sep ("'", '"')
[10561]155 {
[13384]156 while($f =~ /style\s*=\s*$sep([^$sep]+)$sep/g)
[10561]157 {
[13384]158 for my $x (split(/\s*;\s*/, $1))
159 {
160 print STDERR "$ifile: Style starts with minus: $x\n" if $x =~ /^-/;
161 }
[10561]162 }
163 }
164 if($f =~ /viewBox\s*=\s*["']([^"']+)["']/)
165 {
166 my $x = $1;
[13279]167 print STDERR "$ifile: ViewBox has float values: $x\n" if $x =~ /\./;
[10561]168 }
169 }
170 else
171 {
[13279]172 print STDERR "$ifile: Could not open file: $1";
[10561]173 }
174 }
[2808]175 $haveicons{$ifile} = 1;
176 }
177}
178
179for my $img (sort keys %icons)
180{
[7668]181 if($img =~ /\.(png|svg)/)
182 {
[13279]183 print STDERR "$img: File does not exist!\n" if(!-f "images/$img");
[7668]184 delete $haveicons{$img};
185 }
186 else
187 {
[13279]188 print STDERR "$img(.svg|.png): File does not exist!\n" if(!-f "images/$img.png" && !-f "images/$img.svg");
[7668]189 delete $haveicons{"$img.svg"};
190 delete $haveicons{"$img.png"};
191 }
[2808]192}
193
194for my $img (sort keys %haveicons)
195{
[13279]196 print "$img: Unused image.\n";
[2808]197}
Note: See TracBrowser for help on using the repository browser.