Permalink
Browse files

Made TestMergeDialog able to run with zipped models.

  • Loading branch information...
1 parent 9a49abb commit f48117720ad1c34c1c596b81648a7b7d272c153b Evgeny Gerashchenko committed Jan 12, 2011
Showing with 37 additions and 26 deletions.
  1. +37 −26 core/kernel/source/jetbrains/mps/vcs/diff/ui/TestMergeDialog.java
View
63 core/kernel/source/jetbrains/mps/vcs/diff/ui/TestMergeDialog.java
@@ -17,53 +17,63 @@
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Computable;
-import com.intellij.openapi.util.InvalidDataException;
-import com.intellij.openapi.application.Application;
-import com.intellij.openapi.application.impl.ApplicationImpl;
-import com.intellij.openapi.graph.base.DataProvider;
-import com.intellij.openapi.diff.DiffManager;
-import com.intellij.openapi.diff.DiffRequest;
-import com.intellij.openapi.diff.MergeRequest;
-import com.intellij.openapi.diff.impl.mergeTool.MergeRequestImpl;
-import com.intellij.idea.IdeaTestApplication;
+
import static jetbrains.mps.TestMain.configureMPS;
+
+import com.intellij.util.io.ZipUtil;
import jetbrains.mps.ide.IdeMain;
import jetbrains.mps.ide.IdeMain.TestMode;
import jetbrains.mps.smodel.*;
import jetbrains.mps.smodel.persistence.def.ModelPersistence;
-import jetbrains.mps.util.JDOMUtil;
+import jetbrains.mps.util.FileUtil;
import jetbrains.mps.vcs.ModelUtils;
+import jetbrains.mps.vcs.VcsHelper;
+import jetbrains.mps.vcs.VcsHelper.VcsMergeVersion;
+import jetbrains.mps.vcs.diff.ui.ModelDiffTool.ReadException;
import jetbrains.mps.vfs.FileSystem;
import jetbrains.mps.vfs.IFile;
import jetbrains.mps.project.*;
-import jetbrains.mps.TestMain;
-import jetbrains.mps.library.LibraryManager;
-import jetbrains.mps.library.Library;
-import jetbrains.mps.library.BaseLibraryManager.MyState;
import jetbrains.mps.nodeEditor.EditorManager;
-import org.jdom.Document;
import org.jdom.JDOMException;
import org.jetbrains.annotations.NotNull;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
-import java.io.FileInputStream;
-import java.io.IOException;
import java.io.File;
-import java.util.List;
-import java.util.Set;
+import java.io.IOException;
public class TestMergeDialog {
- private static EditorManager myEditorManager = new EditorManager();
+ private static EditorManager ourEditorManager = new EditorManager();
public static void main(final String[] args) throws JDOMException, IOException {
IdeMain.setTestMode(TestMode.NO_TEST);
configureMPS();
- final SModel baseModel = ModelUtils.readModel(args[0]);
- final SModel mineModel = ModelUtils.readModel(args[1]);
- final SModel newModel = ModelUtils.readModel(args[2]);
+ final SModel models[] = new SModel[3];
+
+ String resultFile;
+ if (args.length == 2) {
+ try {
+ final SModel[] zipped = ModelUtils.loadZippedModels(new File(args[0]), VcsMergeVersion.values(), false);
+ models[0] = zipped[0];
+ models[1] = zipped[1];
+ models[2] = zipped[2];
+ } catch (ReadException e) {
+ return;
+ }
+
+ resultFile = args[1];
+ } else if (args.length == 4) {
+ models[0] = ModelUtils.readModel(args[0]);
+ models[1] = ModelUtils.readModel(args[1]);
+ models[2] = ModelUtils.readModel(args[2]);
+
+ resultFile = args[3];
+ } else {
+ System.err.println("There must be 2 or 4 parameters");
+ return;
+ }
/*ModelAccess.instance().runWriteAction(new Runnable() {
public void run() {
@@ -82,6 +92,7 @@ public void run() {
}
});
*/
+ final String finalResultFile = resultFile;
SwingUtilities.invokeLater(new Runnable() {
public void run() {
final MergeModelsDialog dialog = ModelAccess.instance().runReadAction(new Computable<MergeModelsDialog>() {
@@ -104,13 +115,13 @@ public IScope getScope() {
@Override
public <T> T getComponent(Class<T> clazz) {
if (clazz == EditorManager.class) {
- return (T) myEditorManager;
+ return (T) ourEditorManager;
}
return null;
}
};
- return new MergeModelsDialog(context, baseModel, mineModel, newModel);
+ return new MergeModelsDialog(context, models[0], models[1], models[2]);
}
});
dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
@@ -123,7 +134,7 @@ public IScope getScope() {
}
ModelAccess.instance().runReadAction(new Runnable() {
public void run() {
- IFile iFile = FileSystem.getFile(args[3]);
+ IFile iFile = FileSystem.getFile(finalResultFile);
if (!iFile.exists()) iFile.createNewFile();
ModelPersistence.saveModel(result, iFile);
}

0 comments on commit f481177

Please sign in to comment.