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