Search in sources :

Example 1 with ValidationMessage

use of com.google.copybara.config.ValidationResult.ValidationMessage in project copybara by google.

the class ValidateCmd method run.

@Override
public ExitCode run(CommandEnv commandEnv) throws ValidationException, IOException, RepoException {
    ConfigFileArgs configFileArgs = commandEnv.parseConfigFileArgs(this, /*useSourceRef*/
    false);
    ConfigLoader configLoader = configLoaderProvider.newLoader(configFileArgs.getConfigPath(), configFileArgs.getSourceRef());
    ValidationResult result = validate(commandEnv.getOptions(), configLoader, configFileArgs.getWorkflowName());
    Console console = commandEnv.getOptions().get(GeneralOptions.class).console();
    for (ValidationMessage message : result.getAllMessages()) {
        switch(message.getLevel()) {
            case WARNING:
                console.warn(message.getMessage());
                break;
            case ERROR:
                console.error(message.getMessage());
                break;
        }
    }
    if (result.hasErrors()) {
        console.errorFmt("Configuration '%s' is invalid.", configLoader.location());
        return ExitCode.CONFIGURATION_ERROR;
    }
    console.infoFmt("Configuration '%s' is valid.", configLoader.location());
    return ExitCode.SUCCESS;
}
Also used : ValidationMessage(com.google.copybara.config.ValidationResult.ValidationMessage) Console(com.google.copybara.util.console.Console) ValidationResult(com.google.copybara.config.ValidationResult)

Aggregations

ValidationResult (com.google.copybara.config.ValidationResult)1 ValidationMessage (com.google.copybara.config.ValidationResult.ValidationMessage)1 Console (com.google.copybara.util.console.Console)1