Search in sources :

Example 1 with GraficoModelLoader

use of org.archicontribs.modelrepository.grafico.GraficoModelLoader in project archi-modelrepository-plugin by archi-contribs.

the class RevertCommitAction 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.RevertCommitAction_0, ex);
        return;
    }
    // Then offer to Commit
    try {
        if (getRepository().hasChangesToCommit()) {
            if (!offerToCommitChanges()) {
                return;
            }
        }
    } catch (IOException | GitAPIException ex) {
        displayErrorDialog(Messages.RevertCommitAction_3, ex);
        return;
    }
    // Revert
    try (Git git = Git.open(getRepository().getLocalRepositoryFolder())) {
        RevertCommand revertCommand = doRevertCommand(git);
        MergeResult failingResult = revertCommand.getFailingResult();
        if (failingResult != null) {
            MergeConflictHandler handler = new MergeConflictHandler(failingResult, getRepository(), fWindow.getShell());
            boolean result = handler.checkForMergeConflicts();
            if (result) {
                handler.mergeAndCommit(Messages.RevertCommitAction_4, false);
            } else {
                // User cancelled - we assume user has committed all changes so we can reset
                handler.resetToLocalState();
            }
        } else {
            new GraficoModelLoader(getRepository()).loadModel();
        }
        // Save the checksum
        getRepository().saveChecksum();
        notifyChangeListeners(IRepositoryListener.HISTORY_CHANGED);
    } catch (IOException | GitAPIException ex) {
        displayErrorDialog(Messages.RevertCommitAction_1, ex);
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) Git(org.eclipse.jgit.api.Git) GraficoModelLoader(org.archicontribs.modelrepository.grafico.GraficoModelLoader) RevertCommand(org.eclipse.jgit.api.RevertCommand) MergeResult(org.eclipse.jgit.api.MergeResult) IOException(java.io.IOException) MergeConflictHandler(org.archicontribs.modelrepository.grafico.MergeConflictHandler) IArchimateModel(com.archimatetool.model.IArchimateModel)

Example 2 with GraficoModelLoader

use of org.archicontribs.modelrepository.grafico.GraficoModelLoader 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 3 with GraficoModelLoader

use of org.archicontribs.modelrepository.grafico.GraficoModelLoader 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 4 with GraficoModelLoader

use of org.archicontribs.modelrepository.grafico.GraficoModelLoader in project archi-modelrepository-plugin by archi-contribs.

the class AbortChangesAction method run.

@Override
public void run() {
    boolean response = MessageDialog.openConfirm(fWindow.getShell(), Messages.AbortChangesAction_0, Messages.AbortChangesAction_1);
    if (!response) {
        return;
    }
    try {
        getRepository().resetToRef(IGraficoConstants.REFS_HEADS_MASTER);
    } catch (IOException | GitAPIException ex) {
        displayErrorDialog(Messages.AbortChangesAction_0, ex);
    }
    try {
        // Load the model
        new GraficoModelLoader(getRepository()).loadModel();
        // Save the checksum
        getRepository().saveChecksum();
    } catch (IOException ex) {
        displayErrorDialog(Messages.AbortChangesAction_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)

Example 5 with GraficoModelLoader

use of org.archicontribs.modelrepository.grafico.GraficoModelLoader in project archi-modelrepository-plugin by archi-contribs.

the class CloneModelAction method run.

@Override
public void run() {
    CloneInputDialog dialog = new CloneInputDialog(fWindow.getShell());
    if (dialog.open() != Window.OK) {
        return;
    }
    final String repoURL = dialog.getURL();
    final String userName = dialog.getUsername();
    final String userPassword = dialog.getPassword();
    if (!StringUtils.isSet(repoURL) && !StringUtils.isSet(userName) && !StringUtils.isSet(userPassword)) {
        return;
    }
    File localRepoFolder = new File(ModelRepositoryPlugin.INSTANCE.getUserModelRepositoryFolder(), GraficoUtils.getLocalGitFolderName(repoURL));
    // Folder is not empty
    if (localRepoFolder.exists() && localRepoFolder.isDirectory() && localRepoFolder.list().length > 0) {
        MessageDialog.openError(fWindow.getShell(), Messages.CloneModelAction_0, // $NON-NLS-1$
        Messages.CloneModelAction_2 + " " + localRepoFolder.getAbsolutePath());
        return;
    }
    setRepository(new ArchiRepository(localRepoFolder));
    /**
     * Wrapper class to handle progress monitor
     */
    class CloneProgressHandler extends ProgressHandler {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            super.run(monitor);
            try {
                monitor.beginTask(Messages.CloneModelAction_4, IProgressMonitor.UNKNOWN);
                // Proxy check
                ProxyAuthenticater.update(repoURL);
                // Clone
                getRepository().cloneModel(repoURL, userName, userPassword, this);
                monitor.subTask(Messages.CloneModelAction_5);
                // Load it from the Grafico files if we can
                IArchimateModel graficoModel = new GraficoModelLoader(getRepository()).loadModel();
                // We couldn't load it from Grafico so create a new blank model
                if (graficoModel == null) {
                    // New one. This will open in the tree
                    IArchimateModel model = IEditorModelManager.INSTANCE.createNewModel();
                    model.setFile(getRepository().getTempModelFile());
                    // And Save it
                    IEditorModelManager.INSTANCE.saveModel(model);
                    // Export to Grafico
                    getRepository().exportModelToGraficoFiles();
                    // And do a first commit
                    getRepository().commitChanges(Messages.CloneModelAction_6, false);
                    // Save the checksum
                    getRepository().saveChecksum();
                }
                // Store repo credentials if option is set
                if (ModelRepositoryPlugin.INSTANCE.getPreferenceStore().getBoolean(IPreferenceConstants.PREFS_STORE_REPO_CREDENTIALS)) {
                    SimpleCredentialsStorage scs = new SimpleCredentialsStorage(new File(getRepository().getLocalGitFolder(), IGraficoConstants.REPO_CREDENTIALS_FILE));
                    scs.store(userName, userPassword);
                }
                // Notify listeners
                notifyChangeListeners(IRepositoryListener.REPOSITORY_ADDED);
            } catch (GitAPIException | IOException | NoSuchAlgorithmException ex) {
                displayErrorDialog(Messages.CloneModelAction_0, ex);
            } finally {
                monitor.done();
            }
        }
    }
    Display.getCurrent().asyncExec(new Runnable() {

        @Override
        public void run() {
            try {
                ProgressMonitorDialog pmDialog = new ProgressMonitorDialog(fWindow.getShell());
                pmDialog.run(false, true, new CloneProgressHandler());
            } catch (InvocationTargetException | InterruptedException ex) {
                ex.printStackTrace();
            }
        }
    });
}
Also used : ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) CloneInputDialog(org.archicontribs.modelrepository.dialogs.CloneInputDialog) ArchiRepository(org.archicontribs.modelrepository.grafico.ArchiRepository) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) GraficoModelLoader(org.archicontribs.modelrepository.grafico.GraficoModelLoader) SimpleCredentialsStorage(org.archicontribs.modelrepository.authentication.SimpleCredentialsStorage) File(java.io.File) IArchimateModel(com.archimatetool.model.IArchimateModel)

Aggregations

IOException (java.io.IOException)6 GraficoModelLoader (org.archicontribs.modelrepository.grafico.GraficoModelLoader)6 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)6 IArchimateModel (com.archimatetool.model.IArchimateModel)5 File (java.io.File)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 SimpleCredentialsStorage (org.archicontribs.modelrepository.authentication.SimpleCredentialsStorage)1 CloneInputDialog (org.archicontribs.modelrepository.dialogs.CloneInputDialog)1 ArchiRepository (org.archicontribs.modelrepository.grafico.ArchiRepository)1 MergeConflictHandler (org.archicontribs.modelrepository.grafico.MergeConflictHandler)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)1 Git (org.eclipse.jgit.api.Git)1 MergeResult (org.eclipse.jgit.api.MergeResult)1 RevertCommand (org.eclipse.jgit.api.RevertCommand)1 ObjectId (org.eclipse.jgit.lib.ObjectId)1 ObjectLoader (org.eclipse.jgit.lib.ObjectLoader)1 Repository (org.eclipse.jgit.lib.Repository)1 TreeWalk (org.eclipse.jgit.treewalk.TreeWalk)1