| Colin Cross | b852a58 | 2017-08-10 17:58:12 -0700 | [diff] [blame] | 1 | #!/bin/bash -e | 
 | 2 |  | 
| Colin Cross | d00350c | 2017-11-17 10:55:38 -0800 | [diff] [blame] | 3 | # Copyright 2017 Google Inc. All rights reserved. | 
 | 4 | # | 
 | 5 | # Licensed under the Apache License, Version 2.0 (the "License"); | 
 | 6 | # you may not use this file except in compliance with the License. | 
 | 7 | # You may obtain a copy of the License at | 
 | 8 | # | 
 | 9 | #     http://www.apache.org/licenses/LICENSE-2.0 | 
 | 10 | # | 
 | 11 | # Unless required by applicable law or agreed to in writing, software | 
 | 12 | # distributed under the License is distributed on an "AS IS" BASIS, | 
 | 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
 | 14 | # See the License for the specific language governing permissions and | 
 | 15 | # limitations under the License. | 
 | 16 |  | 
| Colin Cross | b852a58 | 2017-08-10 17:58:12 -0700 | [diff] [blame] | 17 | # Script that takes a list of files on stdin and converts it to arguments to jar on stdout | 
 | 18 | # Usage: | 
 | 19 | #        find $dir -type f | sort | jar-args.sh $dir > jar_args.txt | 
 | 20 | #        jar cf out.jar @jar_args.txt | 
 | 21 |  | 
 | 22 | case $(uname) in | 
 | 23 |   Linux) | 
 | 24 |     extended_re=-r | 
 | 25 |     ;; | 
 | 26 |   Darwin) | 
 | 27 |     extended_re=-E | 
 | 28 |     ;; | 
 | 29 |   *) echo "unknown OS:" $(uname) >&2 && exit 1;; | 
 | 30 | esac | 
 | 31 |  | 
 | 32 | if [ "$1" == "--test" ]; then | 
 | 33 |   in=$(mktemp) | 
 | 34 |   expected=$(mktemp) | 
 | 35 |   out=$(mktemp) | 
 | 36 |   cat > $in <<EOF | 
 | 37 | a | 
 | 38 | a/b | 
 | 39 | a/b/' | 
 | 40 | a/b/" | 
 | 41 | a/b/\\ | 
 | 42 | a/b/# | 
 | 43 | a/b/a | 
 | 44 | EOF | 
 | 45 |   cat > $expected <<EOF | 
 | 46 |  | 
 | 47 | -C 'a' 'b' | 
 | 48 | -C 'a' 'b/\\'' | 
 | 49 | -C 'a' 'b/"' | 
 | 50 | -C 'a' 'b/\\\\' | 
 | 51 | -C 'a' 'b/#' | 
 | 52 | -C 'a' 'b/a' | 
 | 53 | EOF | 
 | 54 |   cat $in | $0 a > $out | 
 | 55 |  | 
 | 56 |   if cmp $out $expected; then | 
 | 57 |     status=0 | 
 | 58 |     echo "PASS" | 
 | 59 |   else | 
 | 60 |     status=1 | 
 | 61 |     echo "FAIL" | 
 | 62 |     echo "got:" | 
 | 63 |     cat $out | 
 | 64 |     echo "expected:" | 
 | 65 |     cat $expected | 
 | 66 |   fi | 
 | 67 |   rm -f $in $expected $out | 
 | 68 |   exit $status | 
 | 69 | fi | 
 | 70 |  | 
 | 71 | # In order, the regexps: | 
 | 72 | #   - Strip $1/ from the beginning of each line, and everything from lines that just have $1 | 
 | 73 | #   - Escape single and double quotes, '#', ' ', and '\' | 
 | 74 | #   - Prefix each non-blank line with -C $1 | 
 | 75 | sed ${extended_re} \ | 
 | 76 |   -e"s,^$1(/|\$),," \ | 
 | 77 |   -e"s,(['\\]),\\\\\1,g" \ | 
 | 78 |   -e"s,^(.+),-C '$1' '\1'," |