File tree Expand file tree Collapse file tree 3 files changed +17
-9
lines changed
core/src/main/java/com/google/googlejavaformat/java Expand file tree Collapse file tree 3 files changed +17
-9
lines changed Original file line number Diff line number Diff line change 1414
1515package com .google .googlejavaformat .java ;
1616
17- public class GoogleJavaFormatVersion {
18- public static final String VERSION = "1.0" ;
17+ import java .util .Optional ;
18+
19+ class GoogleJavaFormatVersion {
20+
21+ static Object version () {
22+ return Optional .ofNullable (Main .class .getPackage ().getImplementationVersion ())
23+ .orElse ("unknown" );
24+ }
1925}
Original file line number Diff line number Diff line change @@ -40,9 +40,9 @@ public final class Main {
4040 private static final int MAX_THREADS = 20 ;
4141 private static final String STDIN_FILENAME = "<stdin>" ;
4242
43- static final String [] VERSION = {
44- "google-java-format: Version " + GoogleJavaFormatVersion .VERSION
45- };
43+ static final String versionString () {
44+ return "google-java-format: Version " + GoogleJavaFormatVersion .version ();
45+ }
4646
4747 private final PrintWriter outWriter ;
4848 private final PrintWriter errWriter ;
@@ -88,9 +88,7 @@ public static void main(String[] args) {
8888 public int format (String ... args ) throws UsageException {
8989 CommandLineOptions parameters = processArgs (args );
9090 if (parameters .version ()) {
91- for (String line : VERSION ) {
92- errWriter .println (line );
93- }
91+ errWriter .println (versionString ());
9492 return 0 ;
9593 }
9694 if (parameters .help ()) {
Original file line number Diff line number Diff line change @@ -87,11 +87,15 @@ private static String buildMessage(String message) {
8787 appendLines (builder , USAGE );
8888 appendLines (builder , ADDITIONAL_USAGE );
8989 appendLines (builder , new String [] {"" });
90- appendLines (builder , Main .VERSION );
90+ appendLine (builder , Main .versionString () );
9191 appendLines (builder , DOCS_LINK );
9292 return builder .toString ();
9393 }
9494
95+ private static void appendLine (StringBuilder builder , String line ) {
96+ builder .append (line ).append (System .lineSeparator ());
97+ }
98+
9599 private static void appendLines (StringBuilder builder , String [] lines ) {
96100 NEWLINE_JOINER .appendTo (builder , lines ).append (System .lineSeparator ());
97101 }
You can’t perform that action at this time.
0 commit comments