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>");
}
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");
}
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);
}
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);
}
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();
}
Aggregations