Search in sources :

Example 21 with TransformWork

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();
}
Also used : TransformWork(com.google.copybara.TransformWork) Test(org.junit.Test)

Example 22 with TransformWork

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);
}
Also used : Transformation(com.google.copybara.Transformation) TransformWork(com.google.copybara.TransformWork) DummyRevision(com.google.copybara.testing.DummyRevision)

Example 23 with TransformWork

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;
}
Also used : TransformationStatus(com.google.copybara.TransformationStatus) TransformWork(com.google.copybara.TransformWork)

Example 24 with TransformWork

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}");
}
Also used : DummyEndpoint(com.google.copybara.testing.DummyEndpoint) WriterContext(com.google.copybara.WriterContext) MigrationInfo(com.google.copybara.MigrationInfo) DestinationEffect(com.google.copybara.DestinationEffect) TransformWork(com.google.copybara.TransformWork) DummyRevision(com.google.copybara.testing.DummyRevision) Metadata(com.google.copybara.Metadata) Author(com.google.copybara.authoring.Author)

Example 25 with TransformWork

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();
}
Also used : Transformation(com.google.copybara.Transformation) TransformWork(com.google.copybara.TransformWork) Test(org.junit.Test)

Aggregations

TransformWork (com.google.copybara.TransformWork)41 Test (org.junit.Test)33 Transformation (com.google.copybara.Transformation)23 TransformationStatus (com.google.copybara.TransformationStatus)9 DummyRevision (com.google.copybara.testing.DummyRevision)6 Changes (com.google.copybara.Changes)5 Author (com.google.copybara.authoring.Author)5 ValidationException (com.google.copybara.exception.ValidationException)4 Change (com.google.copybara.Change)3 ProcessedChange (com.google.copybara.testing.RecordsProcessCallDestination.ProcessedChange)3 EmptyChangeException (com.google.copybara.exception.EmptyChangeException)2 NonReversibleValidationException (com.google.copybara.exception.NonReversibleValidationException)2 RepoException (com.google.copybara.exception.RepoException)2 TransformWorks.toChange (com.google.copybara.testing.TransformWorks.toChange)2 Strings (com.google.common.base.Strings)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1