Search in sources :

Example 1 with SVNStatus

use of org.tigris.subversion.subclipse.core.SVNStatus in project subclipse by subclipse.

the class RemoteFolder method getMembers.

/**
 * Get the members of this folder at the same revision than this resource
 *
 * @param monitor a progress monitor
 * @return ISVNRemoteResource[] an array of child remoteResources
 */
protected ISVNRemoteResource[] getMembers(IProgressMonitor monitor) throws SVNException {
    final IProgressMonitor progress = Policy.monitorFor(monitor);
    // $NON-NLS-1$
    progress.beginTask(Policy.bind("RemoteFolder.getMembers"), 100);
    // Try to hit the cache first.
    if (children != null) {
        progress.done();
        return children;
    }
    ISVNClientAdapter client = null;
    try {
        client = getRepository().getSVNClient();
        ISVNDirEntryWithLock[] list = client.getListWithLocks(url, getRevision(), SVNRevision.HEAD, false);
        List<RemoteResource> result = new ArrayList<RemoteResource>(list.length);
        // directories first
        for (ISVNDirEntryWithLock entryWithLock : list) {
            ISVNDirEntry entry = entryWithLock.getDirEntry();
            if (entry.getNodeKind() == SVNNodeKind.DIR) {
                result.add(new RemoteFolder(this, getRepository(), url.appendPath(entry.getPath()), getRevision(), entry.getLastChangedRevision(), entry.getLastChangedDate(), entry.getLastCommitAuthor()));
            }
        }
        // files then
        for (ISVNDirEntryWithLock entryWithLock : list) {
            ISVNDirEntry entry = entryWithLock.getDirEntry();
            ISVNLock lock = entryWithLock.getLock();
            if (entry.getNodeKind() == SVNNodeKind.FILE) {
                RemoteFile remoteFile = new RemoteFile(this, getRepository(), url.appendPath(entry.getPath()), getRevision(), entry.getLastChangedRevision(), entry.getLastChangedDate(), entry.getLastCommitAuthor());
                remoteFile.setPegRevision(getRevision());
                remoteFile.setLock(lock);
                result.add(remoteFile);
            }
        }
        // Save it to the cache
        children = (ISVNRemoteResource[]) result.toArray(new ISVNRemoteResource[result.size()]);
        return children;
    } catch (SVNClientException e) {
        throw new SVNException(new SVNStatus(IStatus.ERROR, SVNStatus.DOES_NOT_EXIST, Policy.bind("RemoteFolder.doesNotExist", // $NON-NLS-1$
        getRepositoryRelativePath())));
    } finally {
        getRepository().returnSVNClient(client);
        progress.done();
    }
}
Also used : ISVNRemoteResource(org.tigris.subversion.subclipse.core.ISVNRemoteResource) ISVNRemoteFolder(org.tigris.subversion.subclipse.core.ISVNRemoteFolder) ISVNLock(org.tigris.subversion.svnclientadapter.ISVNLock) ArrayList(java.util.ArrayList) ISVNRemoteResource(org.tigris.subversion.subclipse.core.ISVNRemoteResource) SVNException(org.tigris.subversion.subclipse.core.SVNException) SVNStatus(org.tigris.subversion.subclipse.core.SVNStatus) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SVNClientException(org.tigris.subversion.svnclientadapter.SVNClientException) ISVNDirEntryWithLock(org.tigris.subversion.svnclientadapter.ISVNDirEntryWithLock) ISVNDirEntry(org.tigris.subversion.svnclientadapter.ISVNDirEntry) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter)

Example 2 with SVNStatus

use of org.tigris.subversion.subclipse.core.SVNStatus in project subclipse by subclipse.

the class SVNHistoryPage method getUpdateToRevisionAction.

// update to the selected revision (context menu)
private IAction getUpdateToRevisionAction() {
    if (updateToRevisionAction == null) {
        updateToRevisionAction = getContextMenuAction(Policy.bind("HistoryView.getRevisionAction"), new // $NON-NLS-1$
        IWorkspaceRunnable() {

            public void run(IProgressMonitor monitor) throws CoreException {
                ISelection selection = getSelection();
                if (!(selection instanceof IStructuredSelection))
                    return;
                IStructuredSelection ss = (IStructuredSelection) selection;
                ISVNRemoteFile remoteFile = (ISVNRemoteFile) getLogEntry(ss).getRemoteResource();
                try {
                    if (remoteFile != null) {
                        if (confirmOverwrite()) {
                            IFile file = (IFile) resource;
                            new ReplaceOperation(getSite().getPage().getActivePart(), file, remoteFile.getLastChangedRevision()).run(monitor);
                            historyTableProvider.setRemoteResource(remoteFile);
                            historyTableProvider.setProjectProperties(ProjectProperties.getProjectProperties(resource));
                            Display.getDefault().asyncExec(new Runnable() {

                                public void run() {
                                    tableHistoryViewer.refresh();
                                }
                            });
                        }
                    }
                } catch (InvocationTargetException e) {
                    throw new CoreException(new SVNStatus(IStatus.ERROR, 0, e.getMessage()));
                } catch (InterruptedException e) {
                // Cancelled by user
                }
            }
        });
        PlatformUI.getWorkbench().getHelpSystem().setHelp(updateToRevisionAction, IHelpContextIds.GET_FILE_REVISION_ACTION);
    }
    return updateToRevisionAction;
}
Also used : SVNStatus(org.tigris.subversion.subclipse.core.SVNStatus) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFile(org.eclipse.core.resources.IFile) ReplaceOperation(org.tigris.subversion.subclipse.ui.operations.ReplaceOperation) CoreException(org.eclipse.core.runtime.CoreException) ISVNRemoteFile(org.tigris.subversion.subclipse.core.ISVNRemoteFile) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with SVNStatus

use of org.tigris.subversion.subclipse.core.SVNStatus in project subclipse by subclipse.

the class SVNOperation method handleErrors.

protected void handleErrors(IStatus[] errors) throws SVNException {
    if (errors.length == 0)
        return;
    if (errors.length == 1 && statusCount == 1) {
        throw new SVNException(errors[0]);
    }
    MultiStatus result = new MultiStatus(SVNUIPlugin.ID, 0, getErrorMessage(errors, statusCount), null);
    for (int i = 0; i < errors.length; i++) {
        IStatus s = errors[i];
        if (s.isMultiStatus()) {
            result.add(new SVNStatus(s.getSeverity(), s.getMessage(), s.getException()));
            result.addAll(s);
        } else {
            result.add(s);
        }
    }
    throw new SVNException(result);
}
Also used : SVNStatus(org.tigris.subversion.subclipse.core.SVNStatus) IStatus(org.eclipse.core.runtime.IStatus) MultiStatus(org.eclipse.core.runtime.MultiStatus) SVNException(org.tigris.subversion.subclipse.core.SVNException)

Example 4 with SVNStatus

use of org.tigris.subversion.subclipse.core.SVNStatus in project subclipse by subclipse.

the class SVNUIPlugin method openError.

/**
 * Convenience method for showing an error dialog
 *
 * @param shell a valid shell or null
 * @param exception the exception to be report
 * @param title the title to be displayed
 * @param flags customizing attributes for the error handling
 * @return IStatus the status that was displayed to the user
 */
public static IStatus openError(Shell providedShell, String title, String message, Throwable exception, int flags) {
    // Unwrap InvocationTargetExceptions
    if (exception instanceof InvocationTargetException) {
        Throwable target = ((InvocationTargetException) exception).getTargetException();
        // re-throw any runtime exceptions or errors so they can be handled by the workbench
        if (target instanceof RuntimeException) {
            throw (RuntimeException) target;
        }
        if (target instanceof Error) {
            throw (Error) target;
        }
        return openError(providedShell, title, message, target, flags);
    }
    // Determine the status to be displayed (and possibly logged)
    IStatus status = null;
    boolean log = false;
    if (exception instanceof CoreException) {
        status = ((CoreException) exception).getStatus();
        log = ((flags & LOG_CORE_EXCEPTIONS) > 0);
    } else if (exception instanceof TeamException) {
        status = ((TeamException) exception).getStatus();
        log = ((flags & LOG_TEAM_EXCEPTIONS) > 0);
    } else if (exception instanceof InterruptedException) {
        // $NON-NLS-1$
        return new SVNStatus(IStatus.OK, Policy.bind("ok"));
    } else if (exception != null) {
        // $NON-NLS-1$
        status = new SVNStatus(IStatus.ERROR, Policy.bind("internal"), exception);
        log = ((flags & LOG_OTHER_EXCEPTIONS) > 0);
        // $NON-NLS-1$
        if (title == null)
            title = Policy.bind("SimpleInternal");
    }
    // Check for a build error and report it differently
    if (status.getCode() == IResourceStatus.BUILD_FAILED) {
        // $NON-NLS-1$
        message = Policy.bind("buildError");
        log = true;
    }
    // Check for multi-status with only one child
    if (status.isMultiStatus() && status.getChildren().length == 1) {
        status = status.getChildren()[0];
    }
    if (status.isOK())
        return status;
    // Log if the user requested it
    if (log)
        SVNUIPlugin.log(status);
    // Create a runnable that will display the error status
    String svnInterface = SVNUIPlugin.getPlugin().getPreferenceStore().getString(ISVNUIConstants.PREF_SVNINTERFACE);
    boolean loadError = svnInterface.equals("javahl") && status != null && status.getMessage() != null && status.getMessage().equals(SVNClientManager.UNABLE_TO_LOAD_DEFAULT_CLIENT);
    if (!loadError || loadErrorHandled) {
        final String displayTitle = title;
        final String displayMessage = message;
        final IStatus displayStatus = status;
        final IOpenableInShell openable = new IOpenableInShell() {

            public void open(Shell shell) {
                if (displayStatus.getSeverity() == IStatus.INFO && !displayStatus.isMultiStatus()) {
                    MessageDialog.openInformation(shell, Policy.bind("information"), // $NON-NLS-1$
                    displayStatus.getMessage());
                } else {
                    ErrorDialog.openError(shell, displayTitle, displayMessage, displayStatus);
                }
            }
        };
        openDialog(providedShell, openable, flags);
    }
    if (loadError)
        loadErrorHandled = true;
    // return the status we display
    return status;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) InvocationTargetException(java.lang.reflect.InvocationTargetException) SVNStatus(org.tigris.subversion.subclipse.core.SVNStatus) TeamException(org.eclipse.team.core.TeamException) Shell(org.eclipse.swt.widgets.Shell) CoreException(org.eclipse.core.runtime.CoreException)

Example 5 with SVNStatus

use of org.tigris.subversion.subclipse.core.SVNStatus in project subclipse by subclipse.

the class SVNWorkspaceRoot method setSharing.

/**
 * Set the sharing for a project to enable it to be used with the SVNTeamProvider. This is used
 * when a project has .svn directory but is not shared in Eclipse. An exception is thrown if
 * project does not have a remote directory counterpart
 */
public static void setSharing(IProject project, IProgressMonitor monitor) throws TeamException {
    // Ensure provided info matches that of the project
    LocalResourceStatus status = peekResourceStatusFor(project);
    // we will change this exception !
    if (!status.hasRemote())
        throw new SVNException(new SVNStatus(IStatus.ERROR, // $NON-NLS-1$
        Policy.bind("SVNProvider.infoMismatch", project.getName())));
    String repositoryURL = null;
    ISVNClientAdapter client = SVNProviderPlugin.getPlugin().getSVNClient();
    try {
        SVNProviderPlugin.disableConsoleLogging();
        ISVNInfo info = client.getInfoFromWorkingCopy(project.getLocation().toFile());
        if (info.getRepository() != null)
            repositoryURL = info.getRepository().toString();
    } catch (SVNClientException e) {
    } finally {
        SVNProviderPlugin.enableConsoleLogging();
        SVNProviderPlugin.getPlugin().getSVNClientManager().returnSVNClient(client);
    }
    if (repositoryURL == null)
        repositoryURL = status.getUrlString();
    // Ensure that the provided location is managed
    SVNProviderPlugin.getPlugin().getRepositories().getRepository(repositoryURL, false);
    // Register the project with Team
    RepositoryProvider.map(project, SVNProviderPlugin.getTypeId());
}
Also used : SVNStatus(org.tigris.subversion.subclipse.core.SVNStatus) ISVNStatus(org.tigris.subversion.svnclientadapter.ISVNStatus) SVNClientException(org.tigris.subversion.svnclientadapter.SVNClientException) ISVNInfo(org.tigris.subversion.svnclientadapter.ISVNInfo) SVNException(org.tigris.subversion.subclipse.core.SVNException) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter)

Aggregations

SVNStatus (org.tigris.subversion.subclipse.core.SVNStatus)7 SVNException (org.tigris.subversion.subclipse.core.SVNException)5 CoreException (org.eclipse.core.runtime.CoreException)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArrayList (java.util.ArrayList)2 IStatus (org.eclipse.core.runtime.IStatus)2 ISVNRemoteResource (org.tigris.subversion.subclipse.core.ISVNRemoteResource)2 ISVNClientAdapter (org.tigris.subversion.svnclientadapter.ISVNClientAdapter)2 SVNClientException (org.tigris.subversion.svnclientadapter.SVNClientException)2 IFile (org.eclipse.core.resources.IFile)1 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)1 MultiStatus (org.eclipse.core.runtime.MultiStatus)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 Shell (org.eclipse.swt.widgets.Shell)1 TeamException (org.eclipse.team.core.TeamException)1 ISVNRemoteFile (org.tigris.subversion.subclipse.core.ISVNRemoteFile)1 ISVNRemoteFolder (org.tigris.subversion.subclipse.core.ISVNRemoteFolder)1 ISVNRepositoryLocation (org.tigris.subversion.subclipse.core.ISVNRepositoryLocation)1