File: pack200.sh

package info (click to toggle)
libnb-platform18-java 12.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 729,800 kB
  • sloc: java: 5,059,097; xml: 574,432; php: 78,788; javascript: 29,039; ansic: 10,278; sh: 6,386; cpp: 4,612; jsp: 3,643; sql: 1,097; makefile: 540; objc: 288; perl: 277; haskell: 93
file content (108 lines) | stat: -rwxr-xr-x 3,128 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/sh -x
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#

verifyClassName=
verifyClassPath=
doVerify=0

#it slows down building
#if [ -n "$2" ] && [ -n "$3" ] ; then
#   verifyClassName="$2"
#   verifyClassPath="$3"
#   doVerify=1
#fi

javaPath=`/usr/libexec/java_home --version 1.8`
#javaPath="/Library/Java/JavaVirtualMachines/1.6.0_65-b14-462.jdk/Contents/Home"
unpackCommand="$javaPath/bin/unpack200"
javaCommand="$javaPath/bin/java"
packCommand="$javaPath/bin/pack200"

verify(){
  filenamePacked="$1"
  filenameSource="$2"
  tmpFile="$2.tmp"
  $unpackCommand "$1" "$tmpFile"
  result=1
  if [ 0 -eq $? ] ; then
	$javaCommand -cp "$verifyClassPath" "$verifyClassName" "$tmpFile" >/dev/null
	result=$?
  fi

  if [ -f "$tmpFile" ] ; then
      rm "$tmpFile"
  fi

  return $result
}

for f in `find $1 -name "*.jar"`
do
  bn=`basename $f`
  if  [ "$bn" != "jhall.jar" ] && [ "$bn" != "derby.jar" ] && [ "$bn" != "derbyclient.jar" ]
  then
    if [ ! -z "$dont_pack_anything" ] && [ "$dont_pack_anything" == "y" ] ; then
        echo "Skipping packing of $f"
        continue
    fi
    if [ ! -z "$dont_pack_localization_jars" ] && [ "$dont_pack_localization_jars" == "y" ]; then
        if [ ! -z `echo $f | grep "/locale/"` ]; then
            echo "Skipping packing of localization jars: $f"
            continue
        fi
    fi
    if [ -f "$f.pack" ] || [ -f "$f.pack.gz" ] ; then 
        echo "Packed file $f.pack(.gz) exists, skipping packing of the original file $f"
        continue
    fi
    if [ -f `echo $f | sed 's/.jar/.jad/'` ] ; then
        echo "Jar Descriptor (.jad) exists, skipping packing of the original file $f"
        continue
    fi
    if [ 2 -eq `unzip -l "$f" 2>/dev/null | grep "META-INF/" | sed "s/.*META-INF\///g" | grep "\.SF\|\.RSA\|\.DSA"| wc -l` ] ; then
        echo "Jar file $f is signed, skipping packing"
        continue
    fi

    echo Packing $f
    $packCommand -J-Xmx256m -g $f.pack $f
    if [ 0 -eq $? ] ; then
        res=0
        if [ 1 -eq $doVerify ] ; then
	    verify $f.pack $f
            res=$?
	fi

        if [ 0 -eq $res ] ; then
            chmod `stat -f %Lp $f` $f.pack && touch -r $f $f.pack
            rm $f
        else
            echo Error verification packed jar : $f
	    rm $f.pack
        fi
    else
	if [ -f $f.pack ] ; then
	    echo Error packing jar : $f
	    rm $f.pack
	fi
    fi
  fi
done