Files
gerrit/tools/setup_gjf.sh
Dave Borowitz 4a74548c22 Document gjf and add a script to standardize/streamline setup
google-java-format is not uniformly available in package management
systems across OSes. More importantly, we want to make sure that all
contributors are using a standardized version, to avoid unnecessary
changes due to slight differences between versions.

While we're in the dev documentation, link to the Google Java Style
Guide, and remove some wording that is clearly redundant with the style
guide.

Change-Id: Ib14dab2e692339f836083fad08a7a435a2f24470
2017-02-07 12:38:37 -05:00

67 lines
2.0 KiB
Bash
Executable File

#!/bin/bash
#
# Copyright (C) 2017 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -eu
# Keep this version in sync with dev-contributing.txt.
VERSION="1.2"
SHA1="b3614824e178dd918dc2cc7c7b54804200ebfc64"
root="$(git rev-parse --show-toplevel)"
if [[ -z "$root" ]]; then
echo "google-java-format setup requires a git working tree"
exit 1
fi
dir="$root/tools/format"
mkdir -p "$dir"
name="google-java-format-$VERSION-all-deps.jar"
url="https://github.com/google/google-java-format/releases/download/google-java-format-$VERSION/$name"
"$root/tools/download_file.py" -o "$dir/$name" -u "$url" -v "$SHA1"
launcher="$dir/google-java-format"
cat > "$launcher" <<EOF
#!/bin/bash
#
# Copyright (C) 2017 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
dir="\$(dirname "\$(readlink -f "\$(type -p "\$0")")")"
exec java -jar "\$dir/$name" "\$@"
EOF
chmod +x "$launcher"
cat <<EOF
Installed launcher script at $launcher
To set up an alias, add the following to your ~/.bashrc or equivalent:
alias google-java-format='$launcher'
EOF