Wed, 07 Mar 2012 22:36:38 -0800
Merge
1.1 --- a/.hgtags Tue Mar 06 20:25:18 2012 +0000 1.2 +++ b/.hgtags Wed Mar 07 22:36:38 2012 -0800 1.3 @@ -149,3 +149,4 @@ 1.4 221a378e06a326f45e5d89e2123cd6323e0181d1 jdk8-b25 1.5 2accafff224ae39caf5f532c305251ba624bf2c0 jdk8-b26 1.6 1533dfab9903e4edcfead3b0192643f38c418b9b jdk8-b27 1.7 +6e2541d60f4e342b5b67140271d7611643929dc3 jdk8-b28
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/make/scripts/normalizer.pl Wed Mar 07 22:36:38 2012 -0800 2.3 @@ -0,0 +1,208 @@ 2.4 +#!/usr/bin/perl 2.5 + 2.6 +# 2.7 +# Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. 2.8 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.9 +# 2.10 +# This code is free software; you can redistribute it and/or modify it 2.11 +# under the terms of the GNU General Public License version 2 only, as 2.12 +# published by the Free Software Foundation. 2.13 +# 2.14 +# This code is distributed in the hope that it will be useful, but WITHOUT 2.15 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.16 +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.17 +# version 2 for more details (a copy is included in the LICENSE file that 2.18 +# accompanied this code). 2.19 +# 2.20 +# You should have received a copy of the GNU General Public License version 2.21 +# 2 along with this work; if not, write to the Free Software Foundation, 2.22 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.23 +# 2.24 +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.25 +# or visit www.oracle.com if you need additional information or have any 2.26 +# questions. 2.27 +# 2.28 + 2.29 +# 2.30 +# Parses java files: 2.31 +# 1. Removes from the end of lines spaces and TABs 2.32 +# 2. Replaces TABs by spaces 2.33 +# 3. Replaces all NewLine separators by Unix NewLine separators 2.34 +# 4. Makes one and only one empty line at the end of each file 2.35 + 2.36 +if ($#ARGV < 0) { 2.37 + &usage; 2.38 + 2.39 + die; 2.40 +} 2.41 + 2.42 +use Cwd 'abs_path'; 2.43 + 2.44 +my @extensions = ("java"); 2.45 + 2.46 +# Read options 2.47 +my $dirpos = 0; 2.48 + 2.49 +while ($dirpos < $#ARGV) { 2.50 + if ($ARGV[$dirpos] eq "-e") { 2.51 + @extensions = split(/,/, $ARGV[$dirpos + 1]); 2.52 + } else { 2.53 + last; 2.54 + } 2.55 + 2.56 + $dirpos += 2; 2.57 +} 2.58 + 2.59 +if ($dirpos > $#ARGV) { 2.60 + &usage; 2.61 + 2.62 + die; 2.63 +} 2.64 + 2.65 +use Cwd; 2.66 +my $currdir = getcwd; 2.67 + 2.68 +my $allfiles = 0; 2.69 + 2.70 +my $filecount = 0; 2.71 + 2.72 +my @tabvalues; 2.73 + 2.74 +# Init tabvalues 2.75 +push (@tabvalues, " "); 2.76 + 2.77 +for (my $i = 1; $i < 8; $i++) { 2.78 + push(@tabvalues, $tabvalues[$i - 1] . " "); 2.79 +} 2.80 + 2.81 +open(FILELIST, ">$currdir/filelist") or die "Failed while open $currdir/filelist: $!\n"; 2.82 + 2.83 +while ($dirpos <= $#ARGV) { 2.84 + use File::Find; 2.85 + 2.86 + find(\&parse_file, abs_path($ARGV[$dirpos])); 2.87 + 2.88 + $dirpos += 1; 2.89 +} 2.90 + 2.91 +close(FILELIST); 2.92 + 2.93 +use Cwd 'chdir'; 2.94 +chdir $currdir; 2.95 + 2.96 +print "Checked $allfiles file(s)\n"; 2.97 +print "Modified $filecount file(s)\n"; 2.98 +print "See results in the file $currdir/filelist\n"; 2.99 + 2.100 +sub parse_file { 2.101 + my $filename = $File::Find::name; 2.102 + 2.103 + # Skip directories 2.104 + return if -d; 2.105 + 2.106 + # Skip SCCS files 2.107 + return if ($filename =~ /\/SCCS\//); 2.108 + 2.109 + # Skip files with invalid extensions 2.110 + my $accepted = 0; 2.111 + foreach my $ext (@extensions) { 2.112 + if ($_ =~ /\.$ext$/i) { 2.113 + $accepted = 1; 2.114 + 2.115 + last; 2.116 + } 2.117 + } 2.118 + return if ($accepted == 0); 2.119 + 2.120 + use File::Basename; 2.121 + my $dirname = dirname($filename); 2.122 + 2.123 + use Cwd 'chdir'; 2.124 + chdir $dirname; 2.125 + 2.126 + open(FILE, $filename) or die "Failed while open $filename: $!\n"; 2.127 + 2.128 + # Read file 2.129 + my @content; 2.130 + my $line; 2.131 + my $emptylinescount = 0; 2.132 + my $modified = 0; 2.133 + 2.134 + while ($line = <FILE>) { 2.135 + my $originalline = $line; 2.136 + 2.137 + # Process line 2.138 + 2.139 + # Remove from the end of the line spaces and return character 2.140 + while ($line =~ /\s$/) { 2.141 + chop($line); 2.142 + } 2.143 + 2.144 + # Replace TABs 2.145 + for (my $i = 0; $i < length($line); $i++) { 2.146 + if (substr($line, $i, 1) =~ /\t/) { 2.147 + $line = substr($line, 0, $i) . $tabvalues[7 - ($i % 8)] . substr($line, $i + 1); 2.148 + } 2.149 + } 2.150 + 2.151 + if (length($line) == 0) { 2.152 + $emptylinescount++; 2.153 + } else { 2.154 + while ($emptylinescount > 0) { 2.155 + push(@content, ""); 2.156 + 2.157 + $emptylinescount--; 2.158 + } 2.159 + 2.160 + push(@content, $line); 2.161 + } 2.162 + 2.163 + if ($originalline ne ($line . "\n")) { 2.164 + $modified = 1; 2.165 + } 2.166 + 2.167 + } 2.168 + 2.169 + $allfiles++; 2.170 + 2.171 + if ($emptylinescount > 0) { 2.172 + $modified = 1; 2.173 + } 2.174 + 2.175 + close(FILE); 2.176 + 2.177 + if ($modified != 0) { 2.178 + # Write file 2.179 + open(FILE, ">$filename") or die "Failed while open $filename: $!\n"; 2.180 + 2.181 + for (my $i = 0; $i <= $#content; $i++) { 2.182 + print FILE "$content[$i]\n"; 2.183 + } 2.184 + 2.185 + close(FILE); 2.186 + 2.187 + # Print name from current dir 2.188 + if (index($filename, $currdir) == 0) { 2.189 + print FILELIST substr($filename, length($currdir) + 1); 2.190 + } else { 2.191 + print FILELIST $filename; 2.192 + } 2.193 + print FILELIST "\n"; 2.194 + 2.195 + $filecount++; 2.196 + 2.197 + print "$filename: modified\n"; 2.198 + } 2.199 +} 2.200 + 2.201 +sub usage { 2.202 + print "Usage:\n"; 2.203 + print " normalizer.pl [-options] <dir> [dir2 dir3 ...]\n"; 2.204 + print " Available options:\n"; 2.205 + print " -e comma separated files extensions. By default accepts only java files\n"; 2.206 + print "\n"; 2.207 + print "Examples:\n"; 2.208 + print " normalizer.pl -e c,cpp,h,hpp .\n"; 2.209 +} 2.210 + 2.211 +