Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | #! /usr/local/bin/perl |
michael@0 | 2 | # |
michael@0 | 3 | # This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | # License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
michael@0 | 6 | |
michael@0 | 7 | |
michael@0 | 8 | require('coreconf.pl'); |
michael@0 | 9 | |
michael@0 | 10 | #######-- read in variables on command line into %var |
michael@0 | 11 | |
michael@0 | 12 | $use_jar = 1; |
michael@0 | 13 | $ZIP = "$ENV{JAVA_HOME}/bin/jar"; |
michael@0 | 14 | |
michael@0 | 15 | if ( $ENV{JAVA_HOME} eq "" ) { |
michael@0 | 16 | $ZIP = "zip"; |
michael@0 | 17 | $use_jar = 0; |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | |
michael@0 | 21 | &parse_argv; |
michael@0 | 22 | |
michael@0 | 23 | |
michael@0 | 24 | ######-- Do the packaging of jars. |
michael@0 | 25 | |
michael@0 | 26 | foreach $jarfile (split(/ /,$var{FILES}) ) { |
michael@0 | 27 | print STDERR "---------------------------------------------\n"; |
michael@0 | 28 | print STDERR "Packaging jar file $jarfile....\n"; |
michael@0 | 29 | |
michael@0 | 30 | $jarinfo = $var{$jarfile}; |
michael@0 | 31 | |
michael@0 | 32 | ($jardir,$jaropts) = split(/\|/,$jarinfo); |
michael@0 | 33 | |
michael@0 | 34 | if ( $use_jar ) { |
michael@0 | 35 | $zipoptions = "-cvf"; |
michael@0 | 36 | } else { |
michael@0 | 37 | $zipoptions = "-T -r"; |
michael@0 | 38 | if ($jaropts =~ /a/) { |
michael@0 | 39 | if ($var{OS_ARCH} eq 'WINNT') { |
michael@0 | 40 | $zipoptions .= ' -ll'; |
michael@0 | 41 | } |
michael@0 | 42 | } |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | # just in case the directory ends in a /, remove it |
michael@0 | 46 | if ($jardir =~ /\/$/) { |
michael@0 | 47 | chop $jardir; |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | $dirdepth --; |
michael@0 | 51 | |
michael@0 | 52 | print STDERR "jardir = $jardir\n"; |
michael@0 | 53 | system("ls $jardir"); |
michael@0 | 54 | |
michael@0 | 55 | if (-d $jardir) { |
michael@0 | 56 | |
michael@0 | 57 | |
michael@0 | 58 | # count the number of slashes |
michael@0 | 59 | |
michael@0 | 60 | $slashes =0; |
michael@0 | 61 | |
michael@0 | 62 | foreach $i (split(//,$jardir)) { |
michael@0 | 63 | if ($i =~ /\//) { |
michael@0 | 64 | $slashes++; |
michael@0 | 65 | } |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | $dotdots =0; |
michael@0 | 69 | |
michael@0 | 70 | foreach $i (split(m|/|,$jardir)) { |
michael@0 | 71 | if ($i eq '..') { |
michael@0 | 72 | $dotdots ++; |
michael@0 | 73 | } |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | $dirdepth = ($slashes +1) - (2*$dotdots); |
michael@0 | 77 | |
michael@0 | 78 | print STDERR "changing dir $jardir\n"; |
michael@0 | 79 | chdir($jardir); |
michael@0 | 80 | print STDERR "making dir META-INF\n"; |
michael@0 | 81 | mkdir("META-INF",0755); |
michael@0 | 82 | |
michael@0 | 83 | $filelist = ""; |
michael@0 | 84 | opendir(DIR,"."); |
michael@0 | 85 | while ($_ = readdir(DIR)) { |
michael@0 | 86 | if (! ( ($_ eq '.') || ($_ eq '..'))) { |
michael@0 | 87 | if ( $jaropts =~ /i/) { |
michael@0 | 88 | if (! /^include$/) { |
michael@0 | 89 | $filelist .= "$_ "; |
michael@0 | 90 | } |
michael@0 | 91 | } |
michael@0 | 92 | else { |
michael@0 | 93 | $filelist .= "$_ "; |
michael@0 | 94 | } |
michael@0 | 95 | } |
michael@0 | 96 | } |
michael@0 | 97 | closedir(DIR); |
michael@0 | 98 | |
michael@0 | 99 | print STDERR "$ZIP $zipoptions $jarfile $filelist\n"; |
michael@0 | 100 | system("$ZIP $zipoptions $jarfile $filelist"); |
michael@0 | 101 | rmdir("META-INF"); |
michael@0 | 102 | for $i (1 .. $dirdepth) { |
michael@0 | 103 | chdir(".."); |
michael@0 | 104 | print STDERR "chdir ..\n"; |
michael@0 | 105 | } |
michael@0 | 106 | } |
michael@0 | 107 | else { |
michael@0 | 108 | print STDERR "Directory $jardir doesn't exist\n"; |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | } |
michael@0 | 112 |