use of com.google.copybara.config.Config in project copybara by google.
the class ConfigBuilderTest method testGitToGitTemplate.
@Test
public void testGitToGitTemplate() throws Exception {
ConfigBuilder underTest = new ConfigBuilder(new GitToGitTemplate());
underTest.setNamedStringParameter("origin_url", "github.com/origin");
underTest.setNamedStringParameter("destination_url", "github.com/destination");
underTest.setNamedStringParameter("email", "Name <foo@bar.com>");
underTest.addStringKeywordParameter("mode", "SQUASH");
String builtConfig = underTest.build();
assertThat(builtConfig).isEqualTo(GIT_TO_GIT_CONFIG);
assertThat(underTest.isValid()).isTrue();
// Verify that config is valid
Config cfg = skylark.loadConfig(builtConfig);
assertThat(cfg.getMigrations()).containsKey("default");
}
use of com.google.copybara.config.Config in project copybara by google.
the class MetadataModuleTest method testCurrentRevForSquashEmptyChanges.
@Test
public void testCurrentRevForSquashEmptyChanges() throws Exception {
options.setForce(true);
passThruAuthoring();
options.setLastRevision(origin.resolve("HEAD").asString());
origin.singleFileChange(42, "test", "excluded", "");
DummyRevision expectedRev = origin.resolve("HEAD");
Config config = loadConfig("" + "core.workflow(\n" + " name = 'default',\n" + " origin = testing.origin(),\n" + " origin_files = glob(['**'], exclude = ['excluded']),\n" + " authoring = " + authoring + "\n," + " destination = testing.destination(),\n" + " mode = '" + WorkflowMode.SQUASH + "',\n" + " transformations = [" + " metadata.replace_message('${COPYBARA_CURRENT_REV}')," + " ]\n" + ")\n");
config.getMigration("default").run(workdir, ImmutableList.of());
assertThat(Iterables.getLast(destination.processed).getChangesSummary()).isEqualTo(expectedRev.asString());
}
use of com.google.copybara.config.Config in project copybara by google.
the class Copybara method validate.
/**
* Validates that the configuration is correct and that there is a valid migration specified by
* {@code migrationName}.
*
* <p>Note that, besides validating the specific migration, all the configuration will be
* validated syntactically.
*/
public boolean validate(Options options, ConfigLoader<?> configLoader, String migrationName) throws IOException {
Console console = options.get(GeneralOptions.class).console();
ArrayList<Message> messages = new ArrayList<>();
try {
Config config = configLoader.loadConfig(options, console);
messages.addAll(validateConfig(config, migrationName));
} catch (ValidationException e) {
// The validate subcommand should not throw Validation exceptions but log a result
StringBuilder error = new StringBuilder(e.getMessage()).append("\n");
Throwable cause = e.getCause();
while (cause != null) {
error.append(" CAUSED BY: ").append(cause.getMessage()).append("\n");
cause = cause.getCause();
}
messages.add(Message.error(error.toString()));
}
messages.forEach(message -> message.printTo(console));
boolean hasNoErrors = messages.stream().noneMatch(message -> message.getType() == MessageType.ERROR);
if (hasNoErrors) {
console.info(String.format("Configuration '%s' is valid.", configLoader.location()));
} else {
console.error(String.format("Configuration '%s' is invalid.", configLoader.location()));
}
return hasNoErrors;
}
use of com.google.copybara.config.Config in project copybara by google.
the class Copybara method loadConfig.
protected Config loadConfig(Options options, ConfigLoader<?> configLoader, String migrationName) throws IOException, ValidationException {
GeneralOptions generalOptions = options.get(GeneralOptions.class);
Console console = generalOptions.console();
Config config = configLoader.loadConfig(options, console);
console.progress("Validating configuration");
List<Message> validationMessages = validateConfig(config, migrationName);
List<Message> errors = validationMessages.stream().filter(message -> message.getType() == MessageType.ERROR).collect(Collectors.toList());
if (errors.isEmpty()) {
return config;
}
errors.forEach(error -> error.printTo(console));
console.error("Configuration is invalid.");
throw new ValidationException("Error validating configuration: Configuration is invalid.");
}
use of com.google.copybara.config.Config in project copybara by google.
the class CopybaraTest method setUp.
@Before
public void setUp() throws Exception {
optionsBuilder = new OptionsBuilder();
console = new TestingConsole();
eventMonitor = new TestingEventMonitor();
optionsBuilder.setConsole(console);
optionsBuilder.general.withEventMonitor(eventMonitor);
migration = mock(Migration.class);
config = new Config(ImmutableMap.of("workflow", migration), "foo/copy.bara.sky");
}
Aggregations