for (String migrationName : migrationNames) {
Ui.Task migrationTask = AppContext.RUN.ui.pushTask(
"perform_migration",
String.format("Performing migration '%s'", migrationName));
MigrationConfig migrationConfig = context.migrationConfigs.get(migrationName);
if (migrationConfig == null) {
AppContext.RUN.ui.error("No migration found with name " + migrationName);
continue;
}
List<Migration> migrations =
DetermineMigrationsLogic.determineMigrations(context, migrationConfig, db);
if (migrations.isEmpty()) {
AppContext.RUN.ui.info("No pending revisions to migrate for " + migrationName);
continue;
}
Equivalence lastEq = migrations.get(0).sinceEquivalence;
// toRe represents toRepo at the revision of last equivalence with fromRepo.
RepositoryExpression toRe = new RepositoryExpression(migrationConfig.getToRepository());
if (lastEq != null) {
toRe = toRe.atRevision(
lastEq.getRevisionForRepository(migrationConfig.getToRepository()).revId);
}
Writer toWriter;
try {
toWriter = toRe.createWriter(context);
} catch (WritingError e) {
throw new MoeProblem("Couldn't create local repo " + toRe + ": " + e);
}
DraftRevision dr = null;
Revision lastMigratedRevision = null;
if (lastEq != null) {
lastMigratedRevision = lastEq.getRevisionForRepository(migrationConfig.getFromRepository());
}
for (Migration m : migrations) {
// For each migration, the reference to-codebase for inverse translation is the Writer,
// since it contains the latest changes (i.e. previous migrations) to the to-repository.
Expression referenceToCodebase = new RepositoryExpression(migrationConfig.getToRepository())
.withOption("localroot", toWriter.getRoot().getAbsolutePath());
Ui.Task oneMigrationTask = AppContext.RUN.ui.pushTask(
"perform_individual_migration",
String.format("Performing individual migration '%s'", m.toString()));
dr = OneMigrationLogic.migrate(m, context, toWriter, referenceToCodebase);
lastMigratedRevision = m.fromRevisions.get(m.fromRevisions.size() - 1);
AppContext.RUN.ui.popTask(oneMigrationTask, "");
}
// TODO(user): Add properly formatted one-DraftRevison-per-Migration message for svn.
migrationsMadeBuilder.add(String.format(
"%s in repository %s", dr.getLocation(), migrationConfig.getToRepository()));
toWriter.printPushMessage();
AppContext.RUN.ui.popTaskAndPersist(migrationTask, toWriter.getRoot());
}
List<String> migrationsMade = migrationsMadeBuilder.build();