use of com.google.copybara.util.SettableSupplier in project copybara by google.
the class Main method runInternal.
/**
* Runs the command and returns the {@link ExitCode}.
*
* <p>This method is also responsible for the exception handling/logging.
*/
private ExitCode runInternal(String[] args, Console console, FileSystem fs) {
try {
ModuleSupplier moduleSupplier = newModuleSupplier();
final MainArguments mainArgs = new MainArguments(args);
GeneralOptions.Args generalOptionsArgs = new GeneralOptions.Args();
SettableSupplier<GeneralOptions> generalOptionsSupplier = new SettableSupplier<>();
List<Option> allOptions = new ArrayList<>(moduleSupplier.newOptions(generalOptionsSupplier));
JCommander jcommander = new JCommander(ImmutableList.builder().addAll(allOptions).add(mainArgs).add(generalOptionsArgs).build());
jcommander.setProgramName("copybara");
String version = getVersion();
logger.log(Level.INFO, "Copybara version: " + version);
jcommander.parse(args);
if (mainArgs.help) {
console.info(usage(jcommander, version));
return ExitCode.SUCCESS;
}
if (mainArgs.version) {
console.info(getBinaryInfo());
return ExitCode.SUCCESS;
}
ImmutableMap<String, CopybaraCmd> commands = Maps.uniqueIndex(getCommands(), CopybaraCmd::name);
mainArgs.parseUnnamedArgs(commands, commands.get("migrate"));
GeneralOptions generalOptions = generalOptionsArgs.init(environment, fs, console);
generalOptionsSupplier.set(generalOptions);
allOptions.add(generalOptions);
Options options = new Options(allOptions);
initEnvironment(options, mainArgs, jcommander);
ConfigLoader<?> configLoader = newConfigLoader(moduleSupplier, options, mainArgs.getConfigPath(), mainArgs.getSourceRef());
Copybara copybara = newCopybaraTool(moduleSupplier, options, mainArgs.getConfigPath());
return mainArgs.getSubcommand().run(mainArgs, options, configLoader, copybara);
} catch (CommandLineException | ParameterException e) {
printCauseChain(Level.WARNING, console, args, e);
console.error("Try 'copybara --help'.");
return ExitCode.COMMAND_LINE_ERROR;
} catch (RepoException e) {
printCauseChain(Level.SEVERE, console, args, e);
// have to do this hack.
if (e.getCause() instanceof InterruptedException) {
return ExitCode.INTERRUPTED;
}
return ExitCode.REPOSITORY_ERROR;
} catch (EmptyChangeException e) {
// This is not necessarily an error. Maybe the tool was run previously and there are no new
// changes to import.
console.warn(e.getMessage());
return ExitCode.NO_OP;
} catch (ValidationException e) {
printCauseChain(Level.WARNING, console, args, e);
// TODO(malcon): Think of a better way of doing this
return e.isRetryable() ? ExitCode.REPOSITORY_ERROR : ExitCode.CONFIGURATION_ERROR;
} catch (IOException e) {
handleUnexpectedError(console, e.getMessage(), args, e);
return ExitCode.ENVIRONMENT_ERROR;
} catch (RuntimeException e) {
// This usually indicates a serious programming error that will require Copybara team
// intervention. Print stack trace without concern for presentation.
e.printStackTrace();
handleUnexpectedError(console, "Unexpected error (please file a bug): " + e.getMessage(), args, e);
return ExitCode.INTERNAL_ERROR;
}
}
Aggregations