source: josm/trunk/geticons.pl @ 7670

Last change on this file since 7670 was 7670, checked in by stoecker, 9 years ago

remove remaining false icon detections

  • Property svn:executable set to *
File size: 3.9 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\(\"([^\"]*?)\"\)/)
46      {
47        my $i = $1;
48        ++$icons{$i};
49      }
50      while($l =~ /\/\*\s*ICON\s*\*\/\s*\"(.*?)\"/g)
51      {
52        my $i = $1;
53        ++$icons{$i};
54      }
55      while($l =~ /\/\*\s*ICON\((.*?)\)\s*\*\/\s*\"(.*?)\"/g)
56      {
57        my $i = "$1$2";
58        ++$icons{$i};
59      }
60      if($l =~ /new\s+ImageLabel\(\"(.*?)\"/)
61      {
62        my $i = "statusline/$1";
63        ++$icons{$i};
64      }
65      if($l =~ /createPreferenceTab\(\"(.*?)\"/)
66      {
67        my $i = "preferences/$1";
68        ++$icons{$i};
69      }
70      if($l =~ /ImageProvider\.get\(\"(.*?)\",\s*\"(.*?)\"\s*\)/)
71      {
72        my $i = "$1/$2";
73        ++$icons{$i};
74      }
75      if($l =~ /ImageProvider\.overlay\(.*?,\s*\"(.*?)\",/)
76      {
77        my $i = $1;
78        ++$icons{$i};
79      }
80      if($l =~ /getCursor\(\"(.*?)\",\s*\"(.*?)\"/)
81      {
82        my $i = "cursor/modifier/$2";
83        ++$icons{$i};
84        $i = "cursor/$1";
85        ++$icons{$i};
86      }
87      if($l =~ /ImageProvider\.getCursor\(\"(.*?)\",\s*null\)/)
88      {
89        my $i = "cursor/$1";
90        ++$icons{$i};
91      }
92      if($l =~ /SideButton*\(\s*(?:mark)?tr\s*\(\s*\".*?\"\s*\)\s*,\s*\"(.*?)\"/)
93      {
94        my $i = "dialogs/$1";
95        ++$icons{$i};
96      }
97      if($l =~ /super\(\s*tr\(\".*?\"\),\s*\"(.*?)\"/s)
98      {
99        my $i = "$extends$1";
100        ++$icons{$i};
101      }
102      if($l =~ /super\(\s*trc\(\".*?\",\s*\".*?\"\),\s*\"(.*?)\"/s)
103      {
104        my $i = "$extends$1";
105        ++$icons{$i};
106      }
107      if($l =~ /audiotracericon\",\s*\"(.*?)\"/s)
108      {
109        my $i = "markers/$1";
110        ++$icons{$i};
111      }
112      if($l =~ /\"(.*?)\",\s*parentLayer/s)
113      {
114        my $i = "markers/$1";
115        ++$icons{$i};
116      }
117      if($l =~ /\.setButtonIcons.*\{(.*)\}/)
118      {
119        my $t = $1;
120        while($t =~ /\"(.*?)\"/g)
121        {
122          my $i = $1;
123          ++$icons{$i};
124        }
125      }
126      if($l =~ /extends MapMode/)
127      {
128        $extends = "mapmode/";
129      }
130      elsif($l =~ /extends ToggleDialog/)
131      {
132        $extends = "dialogs/";
133      }
134    }
135    close FILE;
136  }
137}
138
139my %haveicons;
140
141for($i = 1; my @ifiles = (glob("images".("/*" x $i).".png"), glob("images".("/*" x $i).".svg")); ++$i)
142{
143  for my $ifile (sort @ifiles)
144  {
145    $ifile =~ s/^images\///;
146    $haveicons{$ifile} = 1;
147  }
148}
149
150for my $img (sort keys %icons)
151{
152  if($img =~ /\.(png|svg)/)
153  {
154    print STDERR "File $img does not exist!\n" if(!-f "images/$img");
155    delete $haveicons{$img};
156  }
157  else
158  {
159    print STDERR "File $img(.svg|.png) does not exist!\n" if(!-f "images/$img.png" && !-f "images/$img.svg");
160    delete $haveicons{"$img.svg"};
161    delete $haveicons{"$img.png"};
162  }
163}
164
165for my $img (sort keys %haveicons)
166{
167  print "$img\n";
168}
Note: See TracBrowser for help on using the repository browser.