use of com.google.copybara.TransformWork in project copybara by google.
the class SequenceTest method cachedTreeStateTranformWork.
private TransformWork cachedTreeStateTranformWork() throws IOException {
TransformWork work = TransformWorks.of(checkoutDir, "foo", console);
// Force a map based tree-state
work.getTreeState().find(Glob.ALL_FILES.relativeTo(checkoutDir));
work.getTreeState().notifyNoChange();
work = work.withUpdatedTreeState();
assertCachedTreeState(work).isTrue();
return work;
}
use of com.google.copybara.TransformWork in project copybara by google.
the class SequenceTest method testSequenceTreeStateIsNotCached_firstBad.
@Test
public void testSequenceTreeStateIsNotCached_firstBad() throws IOException, ValidationException {
t1.useTreeState = false;
t2.useTreeState = true;
TransformWork work = cachedTreeStateTranformWork();
sequence.transform(work);
assertCachedTreeState(work.withUpdatedTreeState()).isFalse();
}
use of com.google.copybara.TransformWork in project copybara by google.
the class SequenceTest method testSequenceTreeStateIsNotCached_allGood.
/**
* The TreeState passed to a Sequence shouldn't return a cached TreeState after invocation and
* calling updateTreeState(). Since it could contain many non-cache-safe transforms and the
* last one could be a safe one. But we shouldn't be able to reuse that cache.
*/
@Test
public void testSequenceTreeStateIsNotCached_allGood() throws IOException, ValidationException {
t1.useTreeState = true;
t2.useTreeState = true;
TransformWork work = cachedTreeStateTranformWork();
sequence.transform(work);
assertCachedTreeState(work.withUpdatedTreeState()).isFalse();
}
use of com.google.copybara.TransformWork in project copybara by google.
the class SkylarkTransformation method transform.
@Override
public TransformationStatus transform(TransformWork work) throws IOException, ValidationException, RepoException {
SkylarkConsole skylarkConsole = new SkylarkConsole(work.getConsole());
TransformWork skylarkWork = work.withConsole(skylarkConsole).withParams(params);
TransformationStatus status = TransformationStatus.success();
try (Mutability mu = Mutability.create("dynamic_transform")) {
StarlarkThread thread = new StarlarkThread(mu, StarlarkSemantics.DEFAULT);
thread.setPrintHandler(printHandler);
Object result = Starlark.call(thread, function, ImmutableList.of(skylarkWork), /*kwargs=*/
ImmutableMap.of());
result = result == Starlark.NONE ? TransformationStatus.success() : result;
checkCondition(result instanceof TransformationStatus, "Dynamic transforms functions should return nothing or objects of type %s, but '%s'" + " returned: %s", TransformationStatus.STARLARK_TYPE_NAME, describe(), result);
status = (TransformationStatus) result;
} catch (EvalException e) {
if (e.getCause() instanceof EmptyChangeException) {
throw ((EmptyChangeException) e.getCause());
}
if (e.getCause() instanceof RepoException) {
throw new RepoException(String.format("Error while executing the skylark transformation %s: %s", describe(), e.getMessageWithStack()), e);
}
throw new ValidationException(String.format("Error while executing the skylark transformation %s: %s", describe(), e.getMessageWithStack()), e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException("This should not happen.", e);
} finally {
work.updateFrom(skylarkWork);
}
checkCondition(skylarkConsole.getErrorCount() == 0, "%d error(s) while executing %s", skylarkConsole.getErrorCount(), describe());
return status;
}
use of com.google.copybara.TransformWork in project copybara by google.
the class GitOriginTest method testChanges.
@Test
public void testChanges() throws Exception {
// Need to "round" it since git doesn't store the milliseconds
ZonedDateTime beforeTime = ZonedDateTime.now(ZoneId.systemDefault()).minusSeconds(1);
String author = "John Name <john@name.com>";
singleFileCommit(author, "change2", "test.txt", "some content2");
git("tag", "-m", "This is a tag", "0.1");
singleFileCommit(author, "change3", "test.txt", "some content3");
singleFileCommit(author, "change4", "test.txt", "some content4");
ImmutableList<Change<GitRevision>> changes = newReader().changes(origin.resolve(firstCommitRef), origin.resolve("HEAD")).getChanges();
assertThat(changes).hasSize(3);
assertThat(changes.stream().map(c -> c.getRevision().getUrl()).allMatch(c -> c.startsWith("file://"))).isTrue();
assertThat(changes.get(0).getMessage()).isEqualTo("change2\n");
assertThat(changes.get(0).getRevision().associatedLabel("GIT_DESCRIBE_CHANGE_VERSION")).contains("0.1");
assertThat(changes.get(1).getMessage()).isEqualTo("change3\n");
assertThat(changes.get(1).getRevision().associatedLabel("GIT_DESCRIBE_CHANGE_VERSION")).contains("0.1-1-g" + changes.get(1).getRevision().asString().substring(0, 7));
assertThat(changes.get(2).getMessage()).isEqualTo("change4\n");
assertThat(changes.get(2).getRevision().associatedLabel("GIT_DESCRIBE_CHANGE_VERSION")).contains("0.1-2-g" + changes.get(2).getRevision().asString().substring(0, 7));
TransformWork work = TransformWorks.of(Paths.get(""), "some msg", console).withChanges(new Changes(changes.reverse(), ImmutableList.of()));
assertThat(work.getLabel("GIT_DESCRIBE_CHANGE_VERSION")).isEqualTo("0.1-2-g" + changes.get(2).getRevision().asString().substring(0, 7));
assertThat(work.getAllLabels("GIT_DESCRIBE_CHANGE_VERSION").getImmutableList()).isEqualTo(ImmutableList.of("0.1-2-g" + changes.get(2).getRevision().asString().substring(0, 7), "0.1-1-g" + changes.get(1).getRevision().asString().substring(0, 7), "0.1"));
for (Change<GitRevision> change : changes) {
assertThat(change.getAuthor().getEmail()).isEqualTo("john@name.com");
assertThat(change.getDateTime()).isAtLeast(beforeTime);
assertThat(change.getDateTime()).isAtMost(ZonedDateTime.now(ZoneId.systemDefault()).plusSeconds(1));
}
}
Aggregations