use of com.google.copybara.exception.RepoException in project copybara by google.
the class WorkflowRunHelper method migrate.
/**
* Performs a full migration, including checking out files from the origin, deleting excluded
* files, transforming the code, and writing to the destination. This writes to the destination
* exactly once.
*
* @param rev revision to the version which will be written to the destination
* @param lastRev last revision that was migrated
* @param processConsole console to use to print progress messages
* @param metadata metadata of the change to be migrated
* @param changes changes included in this migration
* @param destinationBaseline it not null, use this baseline in the destination
* @param changeIdentityRevision the revision to be used for computing the change identity
*/
ImmutableList<DestinationEffect> migrate(O rev, @Nullable O lastRev, Console processConsole, Metadata metadata, Changes changes, @Nullable String destinationBaseline, @Nullable O changeIdentityRevision) throws IOException, RepoException, ValidationException {
ImmutableList<DestinationEffect> effects = ImmutableList.of();
boolean callPerMigrationHook = true;
try {
eventMonitor().onChangeMigrationStarted(new ChangeMigrationStartedEvent());
effects = doMigrate(rev, lastRev, processConsole, metadata, changes, destinationBaseline, changeIdentityRevision);
return effects;
} catch (EmptyChangeException empty) {
effects = ImmutableList.of(new DestinationEffect(Type.NOOP, empty.getMessage(), changes.getCurrent(), /*destinationRef=*/
null, ImmutableList.of()));
throw empty;
} catch (ValidationException | IOException | RepoException | RuntimeException e) {
effects = ImmutableList.of(new DestinationEffect(Type.ERROR, "Errors happened during the migration", changes.getCurrent(), /*destinationRef=*/
null, ImmutableList.of(e.getMessage() != null ? e.getMessage() : e.toString())));
callPerMigrationHook = e instanceof ValidationException;
throw e;
} finally {
eventMonitor().onChangeMigrationFinished(new ChangeMigrationFinishedEvent(effects));
if (callPerMigrationHook) {
FinishHookContext finishHookContext = new FinishHookContext(getOriginReader().getFeedbackEndPoint(), getDestinationWriter().getFeedbackEndPoint(), effects, resolvedRef, new SkylarkConsole(getConsole()));
try (ProfilerTask ignored = profiler().start("finish_hooks")) {
for (Action action : workflow.getAfterMigrationActions()) {
try (ProfilerTask ignored2 = profiler().start(action.getName())) {
logger.log(Level.INFO, "Running after migration hook: " + action.getName());
action.run(finishHookContext);
}
}
}
}
}
}
use of com.google.copybara.exception.RepoException in project copybara by google.
the class FolderOrigin method newReader.
@Override
public Reader<FolderRevision> newReader(Glob originFiles, Authoring authoring) throws ValidationException {
return new Reader<FolderRevision>() {
@Override
public void checkout(FolderRevision ref, Path workdir) throws RepoException, ValidationException {
try {
FileUtil.copyFilesRecursively(ref.path, workdir, copySymlinkStrategy, originFiles);
FileUtil.addPermissionsAllRecursively(workdir, FILE_PERMISSIONS);
} catch (AbsoluteSymlinksNotAllowed e) {
throw new ValidationException("Cannot copy files into the workdir: Some" + " symlinks refer to locations outside of the folder and" + " 'materialize_outside_symlinks' config option was not used:\n" + " %s -> %s\n", e.getSymlink(), e.getDestinationFile());
} catch (IOException e) {
throw new RepoException(String.format("Cannot copy files into the workdir:\n" + " origin folder: %s\n" + " workdir: %s", ref.path, workdir), e);
}
}
@Override
public ChangesResponse<FolderRevision> changes(@Nullable FolderRevision fromRef, FolderRevision toRef) throws RepoException {
// Ignore fromRef since a folder doesn't have history of changes
return ChangesResponse.forChanges(ImmutableList.of(change(toRef)));
}
@Override
public boolean supportsHistory() {
return false;
}
@Override
public Change<FolderRevision> change(FolderRevision ref) throws RepoException {
return new Change<>(ref, author, message, ref.readTimestamp(), ImmutableMap.of());
}
@Override
public void visitChanges(FolderRevision start, ChangesVisitor visitor) throws RepoException {
visitor.visit(change(start));
}
};
}
use of com.google.copybara.exception.RepoException in project copybara by google.
the class GitMirrorTest method testMirrorConflict.
@Test
public void testMirrorConflict() throws Exception {
Migration mirror = prepareForConflict();
try {
mirror.run(workdir, /*sourceRef=*/
null);
fail();
} catch (RepoException e) {
assertThat(e.getMessage()).contains("[rejected]");
}
}
use of com.google.copybara.exception.RepoException in project copybara by google.
the class GithubPrOriginTest method setup.
@Before
public void setup() throws Exception {
repoGitDir = Files.createTempDirectory("GithubPrDestinationTest-repoGitDir");
workdir = Files.createTempDirectory("workdir");
localHub = Files.createTempDirectory("localHub");
git("init", "--bare", repoGitDir.toString());
console = new TestingConsole();
options = new OptionsBuilder().setConsole(console).setOutputRootToTmpDir();
options.git = new TestGitOptions(localHub, () -> this.options.general, new Validator() {
@Override
public void validateFetch(String url, boolean prune, boolean force, Iterable<String> refspecs) {
for (String refspec : refspecs) {
// WARNING! This check is important. While using short names like
// 'master' in git fetch works for local git invocations, other
// implementations of GitRepository might have problems if we don't
// pass the whole reference.
assertThat(refspec).startsWith("refs/");
assertThat(refspec).contains(":refs/");
}
}
});
options.github = new GithubOptions(() -> options.general, options.git) {
@Override
public GithubApi getApi(String project) throws RepoException {
assertThat(project).isEqualTo(expectedProject);
return super.getApi(project);
}
@Override
protected HttpTransport getHttpTransport() {
return gitApiMockHttpTransport;
}
};
Path credentialsFile = Files.createTempFile("credentials", "test");
Files.write(credentialsFile, "https://user:SECRET@github.com".getBytes(UTF_8));
options.git.credentialHelperStorePath = credentialsFile.toString();
skylark = new SkylarkTestExecutor(options, GitModule.class);
skylarkParser = new SkylarkParser(ImmutableSet.of(Core.class, Authoring.Module.class, FolderModule.class, GitModule.class));
}
use of com.google.copybara.exception.RepoException in project copybara by google.
the class WorkflowTest method checkIterativeModeWithError.
@SuppressWarnings("unchecked")
private <T extends Exception> T checkIterativeModeWithError(T exception) throws IOException, ValidationException {
for (int timestamp = 0; timestamp < 10; timestamp++) {
origin.addSimpleChange(timestamp);
}
// Override destination with one that always throws EmptyChangeException.
options.testingOptions.destination = new RecordsProcessCallDestination() {
@Override
public Writer newWriter(Glob destinationFiles, boolean dryRun, @Nullable String groupId, @Nullable Writer oldWriter) {
return new WriterImpl(destinationFiles, dryRun) {
@Override
public ImmutableList<DestinationEffect> write(TransformResult transformResult, Console console) throws ValidationException, RepoException, IOException {
assert exception != null;
Throwables.propagateIfPossible(exception, ValidationException.class, RepoException.class);
throw new RuntimeException(exception);
}
};
}
};
Workflow workflow = iterativeWorkflow(/*previousRef=*/
"1");
try {
workflow.run(workdir, /*sourceRef=*/
"3");
fail();
} catch (Exception expected) {
assertThat(expected).isInstanceOf(expected.getClass());
return (T) expected;
}
return exception;
}
Aggregations