Skip to content

Commit fa113c6

Browse files
Simon Sorianoronshapiro
authored andcommitted
Add support for custom google-java-format jar
Adds --google-java-format-jar option that lets the user specify a path to the google-java-format-jar. Fixes #44, #227 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=244863050
1 parent 365e36f commit fa113c6

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

scripts/google-java-format-diff.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ def main():
5858
parser.add_argument('--skip-sorting-imports', action='store_true',
5959
help='do not fix the import order')
6060
parser.add_argument('-b', '--binary', help='path to google-java-format binary')
61+
parser.add_argument('--google-java-format-jar', metavar='ABSOLUTE_PATH', default=None,
62+
help='use a custom google-java-format jar')
63+
6164
args = parser.parse_args()
6265

6366
# Extract changed lines for each file.
@@ -91,15 +94,18 @@ def main():
9194
['-lines', str(start_line) + ':' + str(end_line)])
9295

9396
if args.binary:
94-
binary = args.binary
97+
base_command = [args.binary]
98+
elif args.google_java_format_jar:
99+
base_command = ['java', '-jar', args.google_java_format_jar]
95100
else:
96101
binary = find_executable('google-java-format') or '/usr/bin/google-java-format'
102+
base_command = [binary]
97103

98104
# Reformat files containing changes in place.
99105
for filename, lines in lines_by_file.iteritems():
100106
if args.i and args.verbose:
101107
print 'Formatting', filename
102-
command = [binary]
108+
command = base_command[:]
103109
if args.i:
104110
command.append('-i')
105111
if args.aosp:

0 commit comments

Comments
 (0)