blob: 119f9af3d7a0a14ad2e3cf9c1265d9bf94633b36 [file] [log] [blame]
Dave Borowitz4a745482017-02-07 09:22:33 -05001#!/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
17set -eu
18
19# Keep this version in sync with dev-contributing.txt.
Dave Borowitz3efa1052019-01-28 07:21:29 -080020VERSION=${1:-1.7}
David Ostrovskyfa779ef2018-01-27 16:11:21 +010021
22case "$VERSION" in
231.3)
24 SHA1="a73cfe6f9af01bd6ff150c0b50c9d620400f784c"
25 ;;
261.5)
27 SHA1="b1f79e4d39a3c501f07c0ce7e8b03ac6964ed1f1"
28 ;;
David Pursehouse6c965672018-06-02 05:56:55 +0200291.6)
Luca Milanesio28e06b32018-06-02 22:00:10 +000030 SHA1="02b3e84e52d2473e2c4868189709905a51647d03"
David Pursehouse6c965672018-06-02 05:56:55 +020031 ;;
David Pursehouseb780f232019-02-19 17:27:59 +0900321.7)
33 SHA1="b6d34a51e579b08db7c624505bdf9af4397f1702"
34 ;;
David Ostrovskyfa779ef2018-01-27 16:11:21 +010035*)
36 echo "unknown google-java-format version: $VERSION"
37 exit 1
38 ;;
39esac
Dave Borowitz4a745482017-02-07 09:22:33 -050040
41root="$(git rev-parse --show-toplevel)"
42if [[ -z "$root" ]]; then
43 echo "google-java-format setup requires a git working tree"
44 exit 1
45fi
46
47dir="$root/tools/format"
48mkdir -p "$dir"
49
50name="google-java-format-$VERSION-all-deps.jar"
51url="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 Ostrovskyfa779ef2018-01-27 16:11:21 +010054launcher="$dir/google-java-format-$VERSION"
Dave Borowitz4a745482017-02-07 09:22:33 -050055cat > "$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 Živkov720c7d72017-02-08 11:57:15 +010072function 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 Borowitz4a745482017-02-07 09:22:33 -050083set -e
84
Saša Živkov720c7d72017-02-08 11:57:15 +010085dir="\$(abs_script_dir_path "\$0")"
Dave Borowitz4a745482017-02-07 09:22:33 -050086exec java -jar "\$dir/$name" "\$@"
87EOF
88
89chmod +x "$launcher"
90
91cat <<EOF
92Installed launcher script at $launcher
93To set up an alias, add the following to your ~/.bashrc or equivalent:
94 alias google-java-format='$launcher'
95EOF