Search in sources :

Example 21 with Transformation

use of com.google.copybara.Transformation in project copybara by google.

the class MetadataModuleTest method testMapAuthor_reversible.

@Test
public void testMapAuthor_reversible() throws Exception {
    Transformation m = skylark.eval("m", "m = " + "metadata.map_author({\n" + "    'a <a@example.com>' : 'b <b@example.com>',\n" + "}," + "reversible = True)");
    TransformWork work = TransformWorks.of(workdir, "test", testingConsole);
    work.setAuthor(new Author("a", "a@example.com"));
    m.transform(work);
    assertThat(work.getAuthor().toString()).isEqualTo("b <b@example.com>");
    m.reverse().transform(work);
    assertThat(work.getAuthor().toString()).isEqualTo("a <a@example.com>");
}
Also used : Transformation(com.google.copybara.Transformation) TransformWork(com.google.copybara.TransformWork) Author(com.google.copybara.authoring.Author) Test(org.junit.Test)

Example 22 with Transformation

use of com.google.copybara.Transformation in project copybara by google.

the class MetadataModuleTest method testExposeLabelAll.

@Test
public void testExposeLabelAll() throws Exception {
    TransformWork tw = TransformWorks.of(workdir, "some message\n\n" + "LABEL=aaa", testingConsole).withChanges(new Changes(ImmutableList.of(toChange(new DummyRevision("1").withLabels(ImmutableListMultimap.of("LABEL", "bbb")), ORIGINAL_AUTHOR), toChange(new DummyRevision("2").withLabels(ImmutableListMultimap.of("LABEL", "bbb")), ORIGINAL_AUTHOR), toChange(new DummyRevision("2").withLabels(ImmutableListMultimap.of("LABEL", "ccc")), ORIGINAL_AUTHOR)), ImmutableList.of())).withResolvedReference(new DummyRevision("123").withLabels(ImmutableListMultimap.of("LABEL", "ddd")));
    Transformation t = skylark.eval("t", "t = " + "metadata.expose_label('LABEL', 'NEW_VALUE', all = True)");
    t.transform(tw);
    assertThat(tw.getMessage()).isEqualTo("some message\n" + "\n" + "LABEL=aaa\n" + "NEW_VALUE=aaa\n" + "NEW_VALUE=bbb\n" + "NEW_VALUE=ccc\n" + "NEW_VALUE=ddd\n");
}
Also used : Changes(com.google.copybara.Changes) Transformation(com.google.copybara.Transformation) TransformWork(com.google.copybara.TransformWork) DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Example 23 with Transformation

use of com.google.copybara.Transformation 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 24 with Transformation

use of com.google.copybara.Transformation in project copybara by google.

the class Sequence method getTransformations.

private ImmutableList<Transformation> getTransformations() {
    if (!workflowOptions.joinTransformations()) {
        return sequence;
    }
    List<Transformation> result = new ArrayList<>(sequence.size());
    Transformation prev = null;
    for (Transformation transformation : sequence) {
        if (prev != null && prev.canJoin(transformation)) {
            prev = prev.join(transformation);
        } else {
            if (prev != null) {
                result.add(prev);
            }
            prev = transformation;
        }
    }
    if (prev != null) {
        result.add(prev);
    }
    return ImmutableList.copyOf(result);
}
Also used : Transformation(com.google.copybara.Transformation) Transformations.toTransformation(com.google.copybara.transform.Transformations.toTransformation) ArrayList(java.util.ArrayList)

Example 25 with Transformation

use of com.google.copybara.Transformation in project copybara by google.

the class CopyOrMoveTest method testMoveToCheckoutDirRoot_sameName.

/**
 * Tricky case: a folder called 'foo' that contains a file called 'foo'. If we move directory
 * contents to the root weneed to make sure we do it right so that we delete the folder before
 * copying the file.
 */
@Test
public void testMoveToCheckoutDirRoot_sameName() throws Exception {
    Transformation mover = skylark.eval("m", "m = core.move(before = 'foo', after = '')");
    touch("foo/foo");
    touch("foo/bar");
    transform(mover);
    assertThatPath(checkoutDir).containsFiles("foo").containsFiles("bar").containsNoMoreFiles();
}
Also used : Transformation(com.google.copybara.Transformation) Test(org.junit.Test)

Aggregations

Transformation (com.google.copybara.Transformation)42 Test (org.junit.Test)38 TransformWork (com.google.copybara.TransformWork)23 TransformationStatus (com.google.copybara.TransformationStatus)12 Author (com.google.copybara.authoring.Author)3 DummyRevision (com.google.copybara.testing.DummyRevision)3 Changes (com.google.copybara.Changes)2 Sequence (com.google.copybara.transform.Sequence)2 Transformations.toTransformation (com.google.copybara.transform.Transformations.toTransformation)2 NonReversibleValidationException (com.google.copybara.exception.NonReversibleValidationException)1 ValidationException (com.google.copybara.exception.ValidationException)1 FileSubjects.assertThatPath (com.google.copybara.testing.FileSubjects.assertThatPath)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1