1 /*
2  * Copyright 2018 Google Inc. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.google.turbine.main;
18 
19 import static java.util.Objects.requireNonNull;
20 
21 import com.google.common.base.Joiner;
22 
23 /** A command-line usage error. */
24 class UsageException extends RuntimeException {
25 
26   private static final String[] USAGE = {
27     "",
28     "Usage: turbine [options]",
29     "",
30     "Options:",
31     "  --output",
32     "    The jar output file.",
33     "  --sources",
34     "    The sources to compile.",
35     "  --source_jars",
36     "    jar archives of sources to compile.",
37     "  --classpath",
38     "    The compilation classpath.",
39     "  --bootclasspath",
40     "    The compilation bootclasspath.",
41     "  --help",
42     "    Print this usage statement.",
43     "  @<filename>",
44     "    Read options and filenames from file.",
45     "",
46   };
47 
UsageException()48   UsageException() {
49     super(buildMessage(null));
50   }
51 
UsageException(String message)52   UsageException(String message) {
53     super(buildMessage(requireNonNull(message)));
54   }
55 
buildMessage(String message)56   private static String buildMessage(String message) {
57     StringBuilder builder = new StringBuilder();
58     if (message != null) {
59       builder.append(message).append('\n');
60     }
61     Joiner.on('\n').appendTo(builder, USAGE).append('\n');
62     return builder.toString();
63   }
64 }
65