package jetbrains.mps.ide.migration; /*Generated by MPS */ import jetbrains.mps.project.Project; import jetbrains.mps.ide.project.ProjectHelper; import jetbrains.mps.baseLanguage.closures.runtime.Wrappers; import jetbrains.mps.migration.global.ProjectMigration; import jetbrains.mps.migration.global.MigrationOptions; import java.util.List; import jetbrains.mps.internal.collections.runtime.ListSequence; import org.jetbrains.mps.openapi.module.SModule; import jetbrains.mps.migration.component.util.MigrationsUtil; import jetbrains.mps.ide.migration.check.MigrationCheckUtil; import jetbrains.mps.progress.EmptyProgressMonitor; public class AntTaskExecutionUtil { public static boolean migrate(final Project project) throws Exception { final MigrationManager m = ProjectHelper.toIdeaProject(project).getComponent(MigrationManager.class); if (!(m.isMigrationRequired())) { return false; } final Wrappers._boolean ok = new Wrappers._boolean(true); project.getRepository().getModelAccess().executeCommand(new Runnable() { public void run() { while (true) { // we don't know which options are "better" so we "select" no one ProjectMigration step = m.nextProjectStep(new MigrationOptions(), true); if (step == null) { break; } try { step.execute(project); } catch (Throwable t) { throw new RuntimeException("Problem on executing language migrations"); } } List<ScriptApplied> missingMigrations = m.getMissingMigrations(); if (ListSequence.fromList(missingMigrations).isNotEmpty()) { throw new RuntimeException("Some migrations are missing"); } Iterable<SModule> modules = MigrationsUtil.getMigrateableModulesFromProject(project); ok.value = !(MigrationCheckUtil.haveProblems(modules, new EmptyProgressMonitor())); if (!(ok.value)) { throw new RuntimeException("Pre-check failed"); } while (true) { ProjectMigration pm = m.nextProjectStep(new MigrationOptions(), false); if (pm == null) { break; } try { pm.execute(project); } catch (Throwable t) { throw new RuntimeException("Problem on executing language migrations"); } } while (true) { ScriptApplied mig = m.nextModuleStep(null); if (mig == null) { break; } try { m.executeScript(mig); } catch (Throwable t) { throw new RuntimeException("Problem on executing language migrations"); } } } }); project.getRepository().getModelAccess().runWriteInEDT(new Runnable() { public void run() { project.getRepository().saveAll(); } }); project.getRepository().getModelAccess().runReadAction(new Runnable() { public void run() { Iterable<SModule> modules = MigrationsUtil.getMigrateableModulesFromProject(project); ok.value = MigrationCheckUtil.haveProblems(modules, new EmptyProgressMonitor()); } }); if (!(ok.value)) { throw new RuntimeException("Post-check failed"); } return true; } }