blob: 0cf2f3f7266695a61ce8a1d0e6d59a84ff586ef7 [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.
David Ostrovskyf6df1d72017-02-10 07:59:27 +010020VERSION="1.3"
21SHA1="a73cfe6f9af01bd6ff150c0b50c9d620400f784c"
Dave Borowitz4a745482017-02-07 09:22:33 -050022
23root="$(git rev-parse --show-toplevel)"
24if [[ -z "$root" ]]; then
25 echo "google-java-format setup requires a git working tree"
26 exit 1
27fi
28
29dir="$root/tools/format"
30mkdir -p "$dir"
31
32name="google-java-format-$VERSION-all-deps.jar"
33url="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
36launcher="$dir/google-java-format"
37cat > "$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 Živkov720c7d72017-02-08 11:57:15 +010054function 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 Borowitz4a745482017-02-07 09:22:33 -050065set -e
66
Saša Živkov720c7d72017-02-08 11:57:15 +010067dir="\$(abs_script_dir_path "\$0")"
Dave Borowitz4a745482017-02-07 09:22:33 -050068exec java -jar "\$dir/$name" "\$@"
69EOF
70
71chmod +x "$launcher"
72
73cat <<EOF
74Installed launcher script at $launcher
75To set up an alias, add the following to your ~/.bashrc or equivalent:
76 alias google-java-format='$launcher'
77EOF