use of com.google.copybara.util.console.Console 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;
}
use of com.google.copybara.util.console.Console in project copybara by google.
the class InfoCmd method info.
/**
* Retrieves the {@link Info} of the {@code migrationName} and prints it to the console.
*/
private static void info(Options options, Config config, String migrationName, ImmutableMap<String, String> context) throws ValidationException, RepoException {
Info<? extends Revision> info = getInfo(migrationName, config);
Console console = options.get(GeneralOptions.class).console();
int outputSize = 0;
for (MigrationReference<? extends Revision> migrationRef : info.migrationReferences()) {
console.info(String.format("'%s': last_migrated %s - last_available %s.", migrationRef.getLabel(), migrationRef.getLastMigrated() != null ? migrationRef.getLastMigrated().asString() : "None", migrationRef.getLastAvailableToMigrate() != null ? migrationRef.getLastAvailableToMigrate().asString() : "None"));
ImmutableList<? extends Change<? extends Revision>> availableToMigrate = migrationRef.getAvailableToMigrate();
int outputLimit = options.get(GeneralOptions.class).getOutputLimit();
if (!availableToMigrate.isEmpty()) {
console.infoFmt("Available changes %s:", availableToMigrate.size() <= outputLimit ? String.format("(%d)", availableToMigrate.size()) : String.format("(showing only first %d out of %d)", outputLimit, availableToMigrate.size()));
TablePrinter table = new TablePrinter("Date", "Revision", "Description", "Author");
for (Change<? extends Revision> change : Iterables.limit(availableToMigrate, outputLimit)) {
outputSize++;
table.addRow(change.getDateTime().format(DATE_FORMATTER), Ascii.truncate(change.getRevision().asString(), REVISION_MAX_LENGTH, ""), Ascii.truncate(change.firstLineMessage(), DESCRIPTION_MAX_LENGTH, "..."), Ascii.truncate(change.getAuthor().toString(), AUTHOR_MAX_LENGTH, "..."));
}
for (String line : table.build()) {
console.info(line);
}
}
if (outputSize > 100) {
console.infoFmt("Use %s to limit the output of the command.", GeneralOptions.OUTPUT_LIMIT_FLAG);
}
}
options.get(GeneralOptions.class).eventMonitors().dispatchEvent(e -> e.onInfoFinished(new InfoFinishedEvent(info, context)));
}
use of com.google.copybara.util.console.Console in project copybara by google.
the class GerritOrigin method newReader.
@Override
public Reader<GitRevision> newReader(Glob originFiles, Authoring authoring) {
return new GitOrigin.ReaderImpl(repoUrl, originFiles, authoring, gitOptions, gitOriginOptions, generalOptions, includeBranchCommitLogs, submoduleStrategy, firstParent, partialFetch, patchTransformation, describeVersion, /*configPath=*/
null, /*workflowName=*/
null) {
@Override
public ImmutableList<GitRevision> findBaselinesWithoutLabel(GitRevision startRevision, int limit) throws RepoException, ValidationException {
// Skip the first change as it is the Gerrit review change
BaselinesWithoutLabelVisitor<GitRevision> visitor = new BaselinesWithoutLabelVisitor<>(originFiles, limit, /*skipFirst=*/
true);
visitChanges(startRevision, visitor);
return visitor.getResult();
}
@Override
public Endpoint getFeedbackEndPoint(Console console) throws ValidationException {
gerritOptions.validateEndpointChecker(endpointChecker, repoUrl);
return new GerritEndpoint(gerritOptions.newGerritApiSupplier(repoUrl, endpointChecker), repoUrl, console);
}
@Override
public ChangesResponse<GitRevision> changes(@Nullable GitRevision fromRef, GitRevision toRef) throws RepoException, ValidationException {
ChangesResponse<GitRevision> result = super.changes(fromRef, toRef);
Change<GitRevision> change = change(toRef);
if (!ignoreGerritNoop || change.getChangeFiles() == null || !toRef.associatedLabels().containsKey(GerritChange.GERRIT_COMPLETE_CHANGE_ID_LABEL)) {
return result;
}
PathMatcher pathMatcher = originFiles.relativeTo(Paths.get("/"));
if (change.getChangeFiles().stream().noneMatch(x -> pathMatcher.matches(Paths.get("/", x)))) {
logger.atInfo().log("Skipping a Gerrit noop change with ref: %s", toRef.getSha1());
return ChangesResponse.noChanges(EmptyReason.NO_CHANGES);
}
return result;
}
};
}
Aggregations