use of com.google.devtools.common.options.OptionsParsingException in project bazel by bazelbuild.
the class BlazeRuntime method serverMain.
/**
* A main method that does not send email. The return value indicates the desired exit status of
* the program.
*/
private static int serverMain(Iterable<BlazeModule> modules, OutErr outErr, String[] args) {
InterruptSignalHandler sigintHandler = null;
try {
final RPCServer blazeServer = createBlazeRPCServer(modules, Arrays.asList(args));
// Register the signal handler.
sigintHandler = new InterruptSignalHandler() {
@Override
public void run() {
LOG.severe("User interrupt");
blazeServer.interrupt();
}
};
blazeServer.serve();
return ExitCode.SUCCESS.getNumericExitCode();
} catch (OptionsParsingException e) {
outErr.printErr(e.getMessage());
return ExitCode.COMMAND_LINE_ERROR.getNumericExitCode();
} catch (IOException e) {
outErr.printErr("I/O Error: " + e.getMessage());
return ExitCode.BUILD_FAILURE.getNumericExitCode();
} catch (AbruptExitException e) {
outErr.printErr(e.getMessage());
return e.getExitCode().getNumericExitCode();
} finally {
if (sigintHandler != null) {
sigintHandler.uninstall();
}
}
}
use of com.google.devtools.common.options.OptionsParsingException in project bazel by bazelbuild.
the class DateFilterConverter method convert.
@Override
public DateFilter convert(String input) throws OptionsParsingException {
if (input.isEmpty()) {
return null;
}
String[] parts = input.split("\\.\\.");
if (parts.length != 2) {
throw new OptionsParsingException("Error parsing time_between option: no '..' found.");
}
if (parts[0].isEmpty()) {
throw new OptionsParsingException("Error parsing time_between option: start date not found");
}
if (parts[1].isEmpty()) {
throw new OptionsParsingException("Error parsing time_between option: end date not found");
}
// TODO(yueg): support more date formats
try {
Date from = DateFilter.DATE_FORMAT.parse(parts[0]);
Date to = DateFilter.DATE_FORMAT.parse(parts[1]);
return new DateFilter(from, to);
} catch (ParseException e) {
throw new OptionsParsingException("Error parsing datetime, format should be: yyyy-MM-ddTHH:mm:ss");
}
}
use of com.google.devtools.common.options.OptionsParsingException in project bazel by bazelbuild.
the class InvocationPolicyEnforcerTest method testAllowValuesDisallowsFlagDefaultButNoPolicyDefault.
@Test
public void testAllowValuesDisallowsFlagDefaultButNoPolicyDefault() throws Exception {
InvocationPolicy.Builder invocationPolicyBuilder = InvocationPolicy.newBuilder();
invocationPolicyBuilder.addFlagPoliciesBuilder().setFlagName("test_string").getAllowValuesBuilder().addAllowedValues("foo").addAllowedValues("bar");
InvocationPolicyEnforcer enforcer = createOptionsPolicyEnforcer(invocationPolicyBuilder);
// Option should be its default
TestOptions testOptions = getTestOptions();
assertEquals(STRING_FLAG_DEFAULT, testOptions.testString);
try {
enforcer.enforce(parser, "build");
fail();
} catch (OptionsParsingException e) {
// expected.
}
}
use of com.google.devtools.common.options.OptionsParsingException in project bazel by bazelbuild.
the class InvocationPolicyEnforcerTest method testAllowValuesDisallowsMultipleValues.
@Test
public void testAllowValuesDisallowsMultipleValues() throws Exception {
InvocationPolicy.Builder invocationPolicyBuilder = InvocationPolicy.newBuilder();
invocationPolicyBuilder.addFlagPoliciesBuilder().setFlagName("test_multiple_string").getAllowValuesBuilder().addAllowedValues("foo").addAllowedValues("bar");
InvocationPolicyEnforcer enforcer = createOptionsPolicyEnforcer(invocationPolicyBuilder);
parser.parse("--test_multiple_string=baz", "--test_multiple_string=bar");
// Option should be "baz" and "bar" as specified by the user.
TestOptions testOptions = getTestOptions();
assertThat(testOptions.testMultipleString).containsExactly("baz", "bar").inOrder();
try {
enforcer.enforce(parser, "build");
fail();
} catch (OptionsParsingException e) {
// expected, since baz is not allowed.
}
}
use of com.google.devtools.common.options.OptionsParsingException in project bazel by bazelbuild.
the class InvocationPolicyEnforcerTest method testDisallowValuesRaisesErrorIfDefaultIsDisallowedAndSetsUseDefault.
@Test
public void testDisallowValuesRaisesErrorIfDefaultIsDisallowedAndSetsUseDefault() throws Exception {
InvocationPolicy.Builder invocationPolicyBuilder = InvocationPolicy.newBuilder();
invocationPolicyBuilder.addFlagPoliciesBuilder().setFlagName("test_string").getDisallowValuesBuilder().addDisallowedValues(STRING_FLAG_DEFAULT).getUseDefaultBuilder();
InvocationPolicyEnforcer enforcer = createOptionsPolicyEnforcer(invocationPolicyBuilder);
try {
enforcer.enforce(parser, "build");
fail();
} catch (OptionsParsingException e) {
assertThat(e.getMessage()).contains("but also specifies to use the default value");
}
}
Aggregations