use of com.google.copybara.Transformation in project copybara by google.
the class Sequence method transform.
@Override
public TransformationStatus transform(TransformWork work) throws IOException, ValidationException, RepoException {
List<Transformation> transformationList = getTransformations();
boolean someTransformWasSuccess = false;
for (int i = 0; i < transformationList.size(); i++) {
// Only check the cache in between consecutive Transforms
if (i != 0) {
work.validateTreeStateCache();
}
Transformation transformation = transformationList.get(i);
work.getConsole().progress(getTransformMessage(transformation, i, transformationList.size()));
TransformationStatus status = runOneTransform(work, transformation);
if (status.isNoop()) {
if (noopBehavior == NoopBehavior.FAIL_IF_ANY_NOOP) {
status.throwException(work.getConsole(), workflowOptions.ignoreNoop);
} else if (noopBehavior == NoopBehavior.NOOP_IF_ANY_NOOP) {
if (workflowOptions.ignoreNoop) {
status.warn(work.getConsole());
} else {
return status;
}
} else if (work.getConsole().isVerbose()) {
status.warn(work.getConsole());
}
}
someTransformWasSuccess |= status.isSuccess();
}
if (noopBehavior == NoopBehavior.NOOP_IF_ALL_NOOP && !someTransformWasSuccess) {
return TransformationStatus.noop(String.format("%s was a no-op because all wrapped transforms were no-ops", this));
}
return TransformationStatus.success();
}
use of com.google.copybara.Transformation in project copybara by google.
the class SkylarkParserTest method testParseConfigFile.
/**
* This test checks that we can load a basic Copybara config file. This config file uses almost
* all the features of the structure of the config file. Apart from that we include some testing
* coverage on global values.
*/
@Test
public void testParseConfigFile() throws IOException, ValidationException {
String configContent = setUpInclusionTest();
Config config = parser.loadConfig(configContent);
MockOrigin origin = (MockOrigin) getWorkflow(config, "foo42").getOrigin();
assertThat(origin.url).isEqualTo("https://so.me/random/url");
assertThat(origin.branch).isEqualTo("master");
MockDestination destination = (MockDestination) getWorkflow(config, "foo42").getDestination();
assertThat(destination.folder).isEqualTo("some folder");
Transformation transformation = getWorkflow(config, "foo42").getTransformation();
assertThat(transformation.getClass()).isAssignableTo(Sequence.class);
ImmutableList<? extends Transformation> transformations = ((Sequence) transformation).getSequence();
assertThat(transformations).hasSize(2);
MockTransform transformation1 = (MockTransform) transformations.get(0);
assertThat(transformation1.field1).isEqualTo("foo");
assertThat(transformation1.field2).isEqualTo("bar");
MockTransform transformation2 = (MockTransform) transformations.get(1);
assertThat(transformation2.field1).isEqualTo("baz");
assertThat(transformation2.field2).isEqualTo("bee");
}
use of com.google.copybara.Transformation in project copybara by google.
the class SkylarkParserTest method testTransformsAreOptional.
@Test
public void testTransformsAreOptional() throws IOException, ValidationException {
String configContent = "" + "core.workflow(\n" + " name = 'foo',\n" + " origin = mock.origin(\n" + " url = 'some_url',\n" + " branch = 'master',\n" + " ),\n" + " destination = mock.destination(\n" + " folder = 'some folder'\n" + " ),\n" + " authoring = authoring.overwrite('Copybara <no-reply@google.com>'),\n" + ")\n";
Config config = parser.loadConfig(configContent);
Transformation transformation = getWorkflow(config, "foo").getTransformation();
assertThat(transformation.getClass()).isAssignableTo(Sequence.class);
ImmutableList<? extends Transformation> transformations = ((Sequence) transformation).getSequence();
assertThat(transformations).isEmpty();
}
use of com.google.copybara.Transformation in project copybara by google.
the class SequenceTest method testSequence_nestedSequences_missOnFourthCache.
@Test
public void testSequence_nestedSequences_missOnFourthCache() throws Exception {
TransformWork work = cachedTreeStateTransformWork();
MockTransform t1 = new MockTransform("t1").setUseTreeState(true).setExpectCacheHit(true);
MockTransform t2 = new MockTransform("t2").setUseTreeState(true).setExpectCacheHit(true);
MockTransform t3 = new MockTransform("t3").setUseTreeState(false);
MockTransform t4 = new MockTransform("t4").setUseTreeState(true).setExpectCacheHit(false);
Transformation t = sequence(sequence(t1, t2), sequence(t3, t4));
t.transform(work);
assertThat(t1.wasRun).isTrue();
assertThat(t2.wasRun).isTrue();
assertThat(t3.wasRun).isTrue();
assertThat(t4.wasRun).isTrue();
}
use of com.google.copybara.Transformation in project copybara by google.
the class SequenceTest method testSequence_noopIfAllNoop_someChildNoops.
@Test
public void testSequence_noopIfAllNoop_someChildNoops() throws Exception {
TransformWork work = uncachedTreeStateTransformWork();
MockTransform t1 = new MockTransform("t1");
MockTransform t2 = new MockTransform("t2").setNoop(true);
MockTransform t3 = new MockTransform("t3");
Transformation t = sequence(Sequence.NoopBehavior.NOOP_IF_ALL_NOOP, t1, t2, t3);
TransformationStatus status = t.transform(work);
assertThat(t1.wasRun).isTrue();
assertThat(t2.wasRun).isTrue();
assertThat(t3.wasRun).isTrue();
assertThat(status.isSuccess()).isTrue();
}
Aggregations