Java Code Examples for com.google.devtools.common.options.OptionsParser#ConstructionException

The following examples show how to use com.google.devtools.common.options.OptionsParser#ConstructionException . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlazeCommandDispatcher.java    From bazel with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an option parser using the common options classes and the command-specific options
 * classes.
 *
 * <p>An overriding method should first call this method and can then override default values
 * directly or by calling {@link BlazeOptionHandler#parseOptions} for command-specific options.
 */
private OptionsParser createOptionsParser(BlazeCommand command)
    throws OptionsParser.ConstructionException {
  OpaqueOptionsData optionsData;
  try {
    optionsData = optionsDataCache.getUnchecked(command);
  } catch (UncheckedExecutionException e) {
    Throwables.throwIfInstanceOf(e.getCause(), OptionsParser.ConstructionException.class);
    throw new IllegalStateException(e);
  }
  Command annotation = command.getClass().getAnnotation(Command.class);
  OptionsParser parser =
      OptionsParser.builder()
          .optionsData(optionsData)
          .skipStarlarkOptionPrefixes()
          .allowResidue(annotation.allowResidue())
          .build();
  return parser;
}
 
Example 2
Source File: AllIncompatibleChangesExpansionTest.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Test
public void incompatibleChangeTagDoesNotTriggerAllIncompatibleChangesCheck() {
  try {
    OptionsParser.builder()
        .optionsClasses(ExampleOptions.class, IncompatibleChangeTagOption.class)
        .build();
  } catch (OptionsParser.ConstructionException e) {
    fail(
        "some_option_with_a_tag should not trigger the expansion, so there should be no checks "
            + "on it having the right prefix and metadata tags. Instead, the following exception "
            + "was thrown: "
            + e.getMessage());
  }
}
 
Example 3
Source File: AllIncompatibleChangesExpansionTest.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * Ensure that we get an {@link OptionsParser.ConstructionException} containing {@code message}
 * when the incompatible changes in the given {@link OptionsBase} subclass are validated.
 */
// Because javadoc can't resolve inner classes.
@SuppressWarnings("javadoc")
private static void assertBadness(Class<? extends OptionsBase> optionsBaseClass, String message) {
  OptionsParser.ConstructionException e =
      assertThrows(
          "Should have failed with message \"" + message + "\"",
          OptionsParser.ConstructionException.class,
          () ->
              OptionsParser.builder()
                  .optionsClasses(ExampleOptions.class, optionsBaseClass)
                  .build());
  assertThat(e).hasMessageThat().contains(message);
}