Search in sources :

Example 1 with BranchInfo

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

the class MergeBranchAction method doOnlineMerge.

private void doOnlineMerge(BranchInfo branchToMerge) throws IOException, GitAPIException, GeneralSecurityException {
    // Store currentBranch first
    BranchInfo currentBranch = getRepository().getBranchStatus().getCurrentLocalBranch();
    PushModelAction pushAction = new PushModelAction(fWindow, getRepository().locateModel());
    // Init
    int status = pushAction.init();
    if (status == RefreshModelAction.USER_CANCEL) {
        return;
    }
    // Check primary key set
    if (!EncryptedCredentialsStorage.checkPrimaryKeySet()) {
        return;
    }
    // Get for this before opening the progress dialog
    // UsernamePassword is will be null if using SSH
    UsernamePassword npw = getUsernamePassword();
    // User cancelled on HTTP
    if (npw == null && GraficoUtils.isHTTP(getRepository().getOnlineRepositoryURL())) {
        return;
    }
    // Do main action with PM dialog
    Display.getCurrent().asyncExec(new Runnable() {

        @Override
        public void run() {
            ProgressMonitorDialog pmDialog = new ProgressMonitorDialog(fWindow.getShell());
            try {
                pmDialog.run(false, true, new IRunnableWithProgress() {

                    @Override
                    public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                        try {
                            // Update Proxy
                            ProxyAuthenticator.update();
                            monitor.beginTask(Messages.MergeBranchAction_11, -1);
                            // Pull
                            int pullStatus = pushAction.pull(npw, pmDialog);
                            // Push
                            if (pullStatus == RefreshModelAction.PULL_STATUS_OK || pullStatus == RefreshModelAction.PULL_STATUS_UP_TO_DATE) {
                                pushAction.push(npw, pmDialog);
                            } else {
                                return;
                            }
                            // Switch to other branch
                            pmDialog.getProgressMonitor().subTask(Messages.MergeBranchAction_14);
                            SwitchBranchAction switchBranchAction = new SwitchBranchAction(fWindow);
                            switchBranchAction.setRepository(getRepository());
                            switchBranchAction.switchBranch(branchToMerge, true);
                            // Pull again
                            pullStatus = pushAction.pull(npw, pmDialog);
                            // Push
                            if (pullStatus == RefreshModelAction.PULL_STATUS_OK || pullStatus == RefreshModelAction.PULL_STATUS_UP_TO_DATE) {
                                pushAction.push(npw, pmDialog);
                            } else {
                                return;
                            }
                            // Switch back
                            pmDialog.getProgressMonitor().subTask(Messages.MergeBranchAction_14);
                            switchBranchAction.switchBranch(currentBranch, true);
                            // Merge
                            merge(currentBranch, branchToMerge, pmDialog);
                            // Final Push on this branch
                            pushAction.push(npw, pmDialog);
                            // Ask user to delete branch (if not master)
                            DeleteBranchAction deleteBranchAction = new DeleteBranchAction(fWindow);
                            deleteBranchAction.setRepository(getRepository());
                            deleteBranchAction.setBranch(branchToMerge);
                            if (deleteBranchAction.shouldBeEnabled()) {
                                pmDialog.getShell().setVisible(false);
                                boolean doDeleteBranch = MessageDialog.openQuestion(fWindow.getShell(), Messages.MergeBranchAction_1, NLS.bind(Messages.MergeBranchAction_9, branchToMerge.getShortName()));
                                if (doDeleteBranch) {
                                    pmDialog.getShell().setVisible(true);
                                    pmDialog.getProgressMonitor().subTask(Messages.MergeBranchAction_12);
                                    // Branch will have been pushed at this point so BranchInfo is no longer valid to determine if it's just a local branch
                                    deleteBranchAction.deleteBranchAndPush(branchToMerge, npw);
                                }
                            }
                        } catch (Exception ex) {
                            pmDialog.getShell().setVisible(false);
                            displayErrorDialog(Messages.MergeBranchAction_1, ex);
                        } finally {
                            try {
                                saveChecksumAndNotifyListeners();
                            } catch (IOException ex) {
                                ex.printStackTrace();
                            }
                            // Clear Proxy
                            ProxyAuthenticator.clear();
                        }
                    }
                });
            } catch (InvocationTargetException | InterruptedException ex) {
                ex.printStackTrace();
            }
        }
    });
}
Also used : BranchInfo(org.archicontribs.modelrepository.grafico.BranchInfo) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IOException(java.io.IOException) GeneralSecurityException(java.security.GeneralSecurityException) CanceledException(org.eclipse.jgit.api.errors.CanceledException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) UsernamePassword(org.archicontribs.modelrepository.authentication.UsernamePassword) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor)

Example 2 with BranchInfo

use of org.archicontribs.modelrepository.grafico.BranchInfo 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 (Exception 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 (Exception ex) {
        displayErrorDialog(Messages.ResetToRemoteCommitAction_4, ex);
        return;
    }
    // Do it!
    try {
        BranchInfo currentRemoteBranch = getCurrentRemoteBranchInfo();
        if (currentRemoteBranch != null) {
            getRepository().resetToRef(currentRemoteBranch.getFullName());
        }
    } catch (Exception 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 : GraficoModelLoader(org.archicontribs.modelrepository.grafico.GraficoModelLoader) BranchInfo(org.archicontribs.modelrepository.grafico.BranchInfo) IOException(java.io.IOException) IArchimateModel(com.archimatetool.model.IArchimateModel) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IOException(java.io.IOException)

Example 3 with BranchInfo

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

the class BranchesView method updateActions.

/**
 * Update the Local Actions depending on the local selection
 * @param selection
 */
private void updateActions() {
    BranchInfo branchInfo = (BranchInfo) getBranchesViewer().getStructuredSelection().getFirstElement();
    fActionSwitchBranch.setBranch(branchInfo);
    fActionAddBranch.setBranch(branchInfo);
    fActionMergeBranch.setBranch(branchInfo);
    fActionDeleteBranch.setBranch(branchInfo);
    fActionDeleteStaleBranches.setSelection(getBranchesViewer().getStructuredSelection());
}
Also used : BranchInfo(org.archicontribs.modelrepository.grafico.BranchInfo)

Example 4 with BranchInfo

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

the class BranchesViewer method doSetInput.

void doSetInput(IArchiRepository archiRepo) {
    // Get BranchStatus
    BranchStatus branchStatus = null;
    try {
        branchStatus = archiRepo.getBranchStatus();
    } catch (IOException | GitAPIException ex) {
        ex.printStackTrace();
    }
    setInput(branchStatus);
    // Set selection to current branch
    if (branchStatus != null) {
        BranchInfo branchInfo = branchStatus.getCurrentLocalBranch();
        if (branchInfo != null) {
            setSelection(new StructuredSelection(branchInfo));
        }
    }
    // And relayout
    getControl().getParent().layout();
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) BranchInfo(org.archicontribs.modelrepository.grafico.BranchInfo) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) BranchStatus(org.archicontribs.modelrepository.grafico.BranchStatus) IOException(java.io.IOException)

Example 5 with BranchInfo

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

the class HistoryView method updateActions.

/**
 * Update the Local Actions depending on the local selection
 * @param selection
 */
private void updateActions() {
    RevCommit commit = (RevCommit) getHistoryViewer().getStructuredSelection().getFirstElement();
    // Set commit in these actions
    fActionExtractCommit.setCommit(commit);
    fActionRestoreCommit.setCommit(commit);
    // Also set the commit in the Comment Viewer
    fCommentViewer.setCommit(commit);
    // Update these actions
    fActionUndoLastCommit.update();
    fActionResetToRemoteCommit.update();
    // Disable actions if our selected branch is not actually the current branch
    BranchInfo selectedBranch = (BranchInfo) getBranchesViewer().getStructuredSelection().getFirstElement();
    boolean isCurrentBranch = selectedBranch != null && selectedBranch.isCurrentBranch();
    fActionRestoreCommit.setEnabled(isCurrentBranch && fActionRestoreCommit.isEnabled());
    fActionUndoLastCommit.setEnabled(isCurrentBranch && fActionUndoLastCommit.isEnabled());
    fActionResetToRemoteCommit.setEnabled(isCurrentBranch && fActionResetToRemoteCommit.isEnabled());
}
Also used : BranchInfo(org.archicontribs.modelrepository.grafico.BranchInfo) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

BranchInfo (org.archicontribs.modelrepository.grafico.BranchInfo)12 IOException (java.io.IOException)9 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)9 IArchimateModel (com.archimatetool.model.IArchimateModel)3 GeneralSecurityException (java.security.GeneralSecurityException)3 BranchStatus (org.archicontribs.modelrepository.grafico.BranchStatus)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 UsernamePassword (org.archicontribs.modelrepository.authentication.UsernamePassword)2 IArchiRepository (org.archicontribs.modelrepository.grafico.IArchiRepository)2 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)2 CanceledException (org.eclipse.jgit.api.errors.CanceledException)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Composite (org.eclipse.swt.widgets.Composite)2 Label (org.eclipse.swt.widgets.Label)2 GraficoModelLoader (org.archicontribs.modelrepository.grafico.GraficoModelLoader)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1