Dave Borowitz | 4a74548 | 2017-02-07 09:22:33 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (C) 2017 The Android Open Source Project |
| 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 | |
| 17 | set -eu |
| 18 | |
| 19 | # Keep this version in sync with dev-contributing.txt. |
David Ostrovsky | f6df1d7 | 2017-02-10 07:59:27 +0100 | [diff] [blame] | 20 | VERSION="1.3" |
| 21 | SHA1="a73cfe6f9af01bd6ff150c0b50c9d620400f784c" |
Dave Borowitz | 4a74548 | 2017-02-07 09:22:33 -0500 | [diff] [blame] | 22 | |
| 23 | root="$(git rev-parse --show-toplevel)" |
| 24 | if [[ -z "$root" ]]; then |
| 25 | echo "google-java-format setup requires a git working tree" |
| 26 | exit 1 |
| 27 | fi |
| 28 | |
| 29 | dir="$root/tools/format" |
| 30 | mkdir -p "$dir" |
| 31 | |
| 32 | name="google-java-format-$VERSION-all-deps.jar" |
| 33 | url="https://github.com/google/google-java-format/releases/download/google-java-format-$VERSION/$name" |
| 34 | "$root/tools/download_file.py" -o "$dir/$name" -u "$url" -v "$SHA1" |
| 35 | |
| 36 | launcher="$dir/google-java-format" |
| 37 | cat > "$launcher" <<EOF |
| 38 | #!/bin/bash |
| 39 | # |
| 40 | # Copyright (C) 2017 The Android Open Source Project |
| 41 | # |
| 42 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 43 | # you may not use this file except in compliance with the License. |
| 44 | # You may obtain a copy of the License at |
| 45 | # |
| 46 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 47 | # |
| 48 | # Unless required by applicable law or agreed to in writing, software |
| 49 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 50 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 51 | # See the License for the specific language governing permissions and |
| 52 | # limitations under the License. |
| 53 | |
Saša Živkov | 720c7d7 | 2017-02-08 11:57:15 +0100 | [diff] [blame] | 54 | function abs_script_dir_path { |
| 55 | SOURCE=\${BASH_SOURCE[0]} |
| 56 | while [ -h "\$SOURCE" ]; do |
| 57 | DIR=\$( cd -P \$( dirname "\$SOURCE") && pwd ) |
| 58 | SOURCE=\$(readlink "\$SOURCE") |
| 59 | [[ \$SOURCE != /* ]] && SOURCE="\$DIR/\$SOURCE" |
| 60 | done |
| 61 | DIR=\$( cd -P \$( dirname "\$SOURCE" ) && pwd ) |
| 62 | echo \$DIR |
| 63 | } |
| 64 | |
Dave Borowitz | 4a74548 | 2017-02-07 09:22:33 -0500 | [diff] [blame] | 65 | set -e |
| 66 | |
Saša Živkov | 720c7d7 | 2017-02-08 11:57:15 +0100 | [diff] [blame] | 67 | dir="\$(abs_script_dir_path "\$0")" |
Dave Borowitz | 4a74548 | 2017-02-07 09:22:33 -0500 | [diff] [blame] | 68 | exec java -jar "\$dir/$name" "\$@" |
| 69 | EOF |
| 70 | |
| 71 | chmod +x "$launcher" |
| 72 | |
| 73 | cat <<EOF |
| 74 | Installed launcher script at $launcher |
| 75 | To set up an alias, add the following to your ~/.bashrc or equivalent: |
| 76 | alias google-java-format='$launcher' |
| 77 | EOF |