Search in sources :

Example 51 with IArchimateModel

use of com.archimatetool.model.IArchimateModel in project archi-modelrepository-plugin by archi-contribs.

the class UndoLastCommitAction method run.

@Override
public void run() {
    // Offer to save the model if open and dirty
    // We need to do this to keep grafico and temp files in sync
    IArchimateModel model = getRepository().locateModel();
    if (model != null && IEditorModelManager.INSTANCE.isModelDirty(model)) {
        if (!offerToSaveModel(model)) {
            return;
        }
    }
    boolean response = MessageDialog.openConfirm(fWindow.getShell(), Messages.UndoLastCommitAction_0, Messages.UndoLastCommitAction_1);
    if (!response) {
        return;
    }
    try {
        // Do it!
        // $NON-NLS-1$
        getRepository().resetToRef("HEAD^");
        // Reload the model from the Grafico XML files
        new GraficoModelLoader(getRepository()).loadModel();
        // Save the checksum
        getRepository().saveChecksum();
    } catch (IOException | GitAPIException ex) {
        displayErrorDialog(Messages.UndoLastCommitAction_0, ex);
    }
    notifyChangeListeners(IRepositoryListener.HISTORY_CHANGED);
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) GraficoModelLoader(org.archicontribs.modelrepository.grafico.GraficoModelLoader) IOException(java.io.IOException) IArchimateModel(com.archimatetool.model.IArchimateModel)

Example 52 with IArchimateModel

use of com.archimatetool.model.IArchimateModel in project archi-modelrepository-plugin by archi-contribs.

the class GraficoModelLoader method restoreProblemObjects.

/**
 * Find the problem object xml files from the commit history and restore them
 * @param unresolvedObjects
 * @return
 * @throws IOException
 */
private IArchimateModel restoreProblemObjects(List<UnresolvedObject> unresolvedObjects) throws IOException {
    fRestoredObjects = new ArrayList<IIdentifier>();
    List<String> restoredIdentifiers = new ArrayList<String>();
    try (Repository repository = Git.open(fRepository.getLocalRepositoryFolder()).getRepository()) {
        try (RevWalk revWalk = new RevWalk(repository)) {
            for (UnresolvedObject unresolved : unresolvedObjects) {
                String missingFileName = unresolved.missingObjectURI.lastSegment();
                String missingObjectID = unresolved.missingObjectURI.fragment();
                // Already got this one
                if (restoredIdentifiers.contains(missingObjectID)) {
                    continue;
                }
                boolean found = false;
                // Reset RevWalk
                revWalk.reset();
                ObjectId id = repository.resolve(IGraficoConstants.REFS_HEADS_MASTER);
                if (id != null) {
                    revWalk.markStart(revWalk.parseCommit(id));
                }
                // Iterate all commits
                for (RevCommit commit : revWalk) {
                    try (TreeWalk treeWalk = new TreeWalk(repository)) {
                        treeWalk.addTree(commit.getTree());
                        treeWalk.setRecursive(true);
                        // We can't use a PathFilter for the file name as its path is not correct
                        while (!found && treeWalk.next()) {
                            // File is found
                            if (treeWalk.getPathString().endsWith(missingFileName)) {
                                // Save file
                                ObjectId objectId = treeWalk.getObjectId(0);
                                ObjectLoader loader = repository.open(objectId);
                                File file = new File(fRepository.getLocalRepositoryFolder(), treeWalk.getPathString());
                                file.getParentFile().mkdirs();
                                GraficoUtils.writeObjectToFileWithSystemLineEndings(file, loader);
                                restoredIdentifiers.add(missingObjectID);
                                found = true;
                            }
                        }
                    }
                    if (found) {
                        break;
                    }
                }
            }
            revWalk.dispose();
        }
    }
    // Then re-import
    GraficoModelImporter importer = new GraficoModelImporter(fRepository.getLocalRepositoryFolder());
    IArchimateModel graficoModel = importer.importAsModel();
    // do this again
    graficoModel.setFile(fRepository.getTempModelFile());
    // Collect restored objects
    for (Iterator<EObject> iter = graficoModel.eAllContents(); iter.hasNext(); ) {
        EObject element = iter.next();
        for (String id : restoredIdentifiers) {
            if (element instanceof IIdentifier && id.equals(((IIdentifier) element).getId())) {
                fRestoredObjects.add((IIdentifier) element);
            }
        }
    }
    return graficoModel;
}
Also used : IIdentifier(com.archimatetool.model.IIdentifier) UnresolvedObject(org.archicontribs.modelrepository.grafico.GraficoModelImporter.UnresolvedObject) ObjectId(org.eclipse.jgit.lib.ObjectId) ArrayList(java.util.ArrayList) RevWalk(org.eclipse.jgit.revwalk.RevWalk) Repository(org.eclipse.jgit.lib.Repository) EObject(org.eclipse.emf.ecore.EObject) ObjectLoader(org.eclipse.jgit.lib.ObjectLoader) TreeWalk(org.eclipse.jgit.treewalk.TreeWalk) File(java.io.File) IArchimateModel(com.archimatetool.model.IArchimateModel) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 53 with IArchimateModel

use of com.archimatetool.model.IArchimateModel in project archi-modelrepository-plugin by archi-contribs.

the class ResetToRemoteCommitAction method run.

@Override
public void run() {
    // Offer to save the model if open and dirty
    // We need to do this to keep grafico and temp files in sync
    IArchimateModel model = getRepository().locateModel();
    if (model != null && IEditorModelManager.INSTANCE.isModelDirty(model)) {
        if (!offerToSaveModel(model)) {
            return;
        }
    }
    // Do the Grafico Export first
    try {
        getRepository().exportModelToGraficoFiles();
    } catch (IOException ex) {
        displayErrorDialog(Messages.ResetToRemoteCommitAction_0, ex);
        return;
    }
    try {
        // If there are changes to commit then they'll have to be committed first or abandoned
        if (getRepository().hasChangesToCommit()) {
            if (!MessageDialog.openConfirm(fWindow.getShell(), Messages.ResetToRemoteCommitAction_0, Messages.ResetToRemoteCommitAction_2)) {
                return;
            }
        } else // Else, confirm
        {
            boolean response = MessageDialog.openConfirm(fWindow.getShell(), Messages.ResetToRemoteCommitAction_0, Messages.ResetToRemoteCommitAction_3);
            if (!response) {
                return;
            }
        }
    } catch (IOException | GitAPIException ex) {
        displayErrorDialog(Messages.ResetToRemoteCommitAction_4, ex);
        return;
    }
    // Do it!
    try {
        getRepository().resetToRef(IGraficoConstants.ORIGIN_MASTER);
    } catch (IOException | GitAPIException ex) {
        displayErrorDialog(Messages.ResetToRemoteCommitAction_0, ex);
    }
    // Reload the model from the Grafico XML files
    try {
        new GraficoModelLoader(getRepository()).loadModel();
        // Save the checksum
        getRepository().saveChecksum();
    } catch (IOException ex) {
        displayErrorDialog(Messages.ResetToRemoteCommitAction_0, ex);
    }
    notifyChangeListeners(IRepositoryListener.HISTORY_CHANGED);
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) GraficoModelLoader(org.archicontribs.modelrepository.grafico.GraficoModelLoader) IOException(java.io.IOException) IArchimateModel(com.archimatetool.model.IArchimateModel)

Example 54 with IArchimateModel

use of com.archimatetool.model.IArchimateModel in project archi-modelrepository-plugin by archi-contribs.

the class ArchiRepositoryTests method locateModel_LocateNewModel.

@Test
public void locateModel_LocateNewModel() {
    File localRepoFolder = new File("/temp/folder");
    IArchiRepository repo = new ArchiRepository(localRepoFolder);
    IArchimateModel model = IArchimateFactory.eINSTANCE.createArchimateModel();
    model.setFile(repo.getTempModelFile());
    // Not open
    assertNull(repo.locateModel());
    IEditorModelManager.INSTANCE.openModel(model);
    assertEquals(model, repo.locateModel());
}
Also used : File(java.io.File) IArchimateModel(com.archimatetool.model.IArchimateModel) Test(org.junit.Test)

Example 55 with IArchimateModel

use of com.archimatetool.model.IArchimateModel in project archi-modelrepository-plugin by archi-contribs.

the class GraficoUtilsTests method getLocalGitFolderForModel_IsCorrect.

@Test
public void getLocalGitFolderForModel_IsCorrect() {
    IArchimateModel model = IArchimateFactory.eINSTANCE.createArchimateModel();
    File expected = new File("parent/parent/");
    File file = new File(expected, ".git/" + IGraficoConstants.LOCAL_ARCHI_FILENAME);
    model.setFile(file);
    assertEquals(expected, GraficoUtils.getLocalRepositoryFolderForModel(model));
}
Also used : IArchimateModel(com.archimatetool.model.IArchimateModel) File(java.io.File) Test(org.junit.Test)

Aggregations

IArchimateModel (com.archimatetool.model.IArchimateModel)124 Test (org.junit.Test)51 File (java.io.File)35 IOException (java.io.IOException)22 IArchimateElement (com.archimatetool.model.IArchimateElement)14 EObject (org.eclipse.emf.ecore.EObject)14 IArchiveManager (com.archimatetool.editor.model.IArchiveManager)13 ArchimateTestModel (com.archimatetool.testingtools.ArchimateTestModel)13 IDiagramModel (com.archimatetool.model.IDiagramModel)12 CommandStack (org.eclipse.gef.commands.CommandStack)11 IFolder (com.archimatetool.model.IFolder)10 ArrayList (java.util.ArrayList)10 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)9 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)9 IArchimateModelObject (com.archimatetool.model.IArchimateModelObject)7 IArchimateDiagramModel (com.archimatetool.model.IArchimateDiagramModel)6 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)6 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)5 IIdentifier (com.archimatetool.model.IIdentifier)5 GraficoModelLoader (org.archicontribs.modelrepository.grafico.GraficoModelLoader)5