use of com.google.copybara.TransformWork in project copybara by google.
the class TodoReplaceTest method testMapping.
@Test
public void testMapping() throws Exception {
TodoReplace replace = todoReplace("mapping = { 'aaa': 'foo', 'bbb' : 'bar'}");
write("one", "" + "aaa\n" + "// TODO( aaa, bbb,other): Example\n");
write("two", "// TODO(aaa): Other Example\n");
TransformWork work = run(replace);
assertThatPath(checkoutDir).containsFile("one", "" + "aaa\n" + "// TODO( foo, bar,other): Example\n").containsFile("two", "// TODO(foo): Other Example\n").containsNoMoreFiles();
run(replace.reverse());
assertThatPath(checkoutDir).containsFile("one", "" + "aaa\n" + "// TODO( aaa, bbb,other): Example\n").containsFile("two", "// TODO(aaa): Other Example\n").containsNoMoreFiles();
}
use of com.google.copybara.TransformWork in project copybara by google.
the class MetadataModuleTest method checkExposeLabel.
private void checkExposeLabel(String msg, String transform, String expectedOutput) throws ValidationException, IOException {
TransformWork tw = TransformWorks.of(workdir, msg, testingConsole).withChanges(EMPTY_CHANGES).withResolvedReference(new DummyRevision("123").withLabels(ImmutableMap.of("SOME", "value")));
Transformation t = skylarkExecutor.eval("t", "t = " + transform);
t.transform(tw);
assertThat(tw.getMessage()).isEqualTo(expectedOutput);
}
use of com.google.copybara.TransformWork in project copybara by google.
the class ExplicitReversal method transform.
@Override
public TransformationStatus transform(TransformWork work) throws IOException, ValidationException, RepoException {
TransformWork newWork;
newWork = work.insideExplicitTransform();
TransformationStatus status = forward.transform(newWork);
work.updateFrom(newWork);
return status;
}
use of com.google.copybara.TransformWork in project copybara by google.
the class GerritDestinationTest method process.
private void process(DummyRevision originRef, GerritDestination destination) throws ValidationException, RepoException, IOException {
WriterContext writerContext = new WriterContext("GerritDestination", "TEST", false, new DummyRevision("test"), Glob.ALL_FILES.roots());
Writer<GitRevision> gitRevisionWriter = destination.newWriter(writerContext);
// This is largely unused, except for the label finder.
TransformWork work = new TransformWork(workdir, new Metadata("Desc", new Author("foo", "foo@foo.com"), ImmutableSetMultimap.of()), Changes.EMPTY, console, new MigrationInfo(DummyOrigin.LABEL_NAME, null), originRef, console -> new DummyEndpoint(), console -> gitRevisionWriter.getFeedbackEndPoint(console), () -> gitRevisionWriter.getDestinationReader(console, null, workdir));
ImmutableList<DestinationEffect> result = gitRevisionWriter.write(TransformResults.of(workdir, originRef).withLabelFinder(work::getAllLabels).withIdentity(originRef.asString()), Glob.createGlob(ImmutableList.of("**"), excludedDestinationPaths), console);
assertThat(result).hasSize(1);
assertThat(result.get(0).getErrors()).isEmpty();
assertThat(result.get(0).getType()).isEqualTo(Type.CREATED);
assertThat(result.get(0).getDestinationRef().getType()).isEqualTo("commit");
assertThat(result.get(0).getDestinationRef().getId()).matches("[0-9a-f]{40}");
}
use of com.google.copybara.TransformWork in project copybara by google.
the class SequenceTest method testSequence_failIfAnyNoop_insideIgnoreNoop.
@Test
public void testSequence_failIfAnyNoop_insideIgnoreNoop() throws Exception {
TransformWork work = uncachedTreeStateTransformWork();
MockTransform t1 = new MockTransform("t1").setNoop(true);
Transformation t = sequence(Sequence.NoopBehavior.IGNORE_NOOP, sequence(Sequence.NoopBehavior.FAIL_IF_ANY_NOOP, t1));
assertThrows(VoidOperationException.class, () -> t.transform(work));
assertThat(t1.wasRun).isTrue();
}
Aggregations