Search in sources :

Example 1 with ISVNClientAdapter

use of org.tigris.subversion.svnclientadapter.ISVNClientAdapter in project subclipse by subclipse.

the class SVNWorkspaceRoot method getProjectName.

/**
 * get the project name for the remote folder. The name is either the name of the remote folder or
 * the name in .project if this file exists.
 *
 * @param folder
 * @param monitor
 * @return
 */
public static String getProjectName(ISVNRemoteFolder folder, IProgressMonitor monitor) throws Exception {
    ISVNClientAdapter client = folder.getRepository().getSVNClient();
    try {
        client.getNotificationHandler().disableLog();
        String result = folder.getName();
        InputStream is = client.getContent(folder.getUrl().appendPath(".project"), SVNRevision.HEAD);
        DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        org.w3c.dom.Document doc = db.parse(is);
        is.close();
        NodeList nl = doc.getDocumentElement().getChildNodes();
        for (int j = 0; j < nl.getLength(); ++j) {
            Node child = nl.item(j);
            if (child instanceof Element && "name".equals(child.getNodeName())) {
                Node grandChild = child.getFirstChild();
                if (grandChild instanceof Text)
                    result = ((Text) grandChild).getData();
            }
        }
        return result;
    } catch (Exception e) {
        throw e;
    } finally {
        if (client != null) {
            client.getNotificationHandler().enableLog();
            folder.getRepository().returnSVNClient(client);
        }
    }
}
Also used : InputStream(java.io.InputStream) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) Text(org.w3c.dom.Text) SVNException(org.tigris.subversion.subclipse.core.SVNException) SVNClientException(org.tigris.subversion.svnclientadapter.SVNClientException) TeamException(org.eclipse.team.core.TeamException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter)

Example 2 with ISVNClientAdapter

use of org.tigris.subversion.svnclientadapter.ISVNClientAdapter in project subclipse by subclipse.

the class FileModificationManager method autoShareProjectIfSVNWorkingCopy.

private void autoShareProjectIfSVNWorkingCopy(IProject project) {
    ISVNClientAdapter client = null;
    try {
        client = SVNProviderPlugin.getPlugin().getSVNClient();
        SVNProviderPlugin.disableConsoleLogging();
        ISVNInfo info = client.getInfoFromWorkingCopy(project.getLocation().toFile());
        if (info != null && info.getRepository() != null) {
            SVNTeamProviderType.getAutoShareJob().share(project);
        }
    } catch (Exception e) {
    } finally {
        SVNProviderPlugin.enableConsoleLogging();
        if (client != null) {
            SVNProviderPlugin.getPlugin().getSVNClientManager().returnSVNClient(client);
        }
    }
}
Also used : ISVNInfo(org.tigris.subversion.svnclientadapter.ISVNInfo) CoreException(org.eclipse.core.runtime.CoreException) SVNException(org.tigris.subversion.subclipse.core.SVNException) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter)

Example 3 with ISVNClientAdapter

use of org.tigris.subversion.svnclientadapter.ISVNClientAdapter in project subclipse by subclipse.

the class GraphBackgroundTask method execute.

protected void execute(IProgressMonitor monitor) throws SVNException, InterruptedException {
    boolean error = false;
    Cache cache = null;
    monitor.beginTask("Calculating graph information", TOTAL_STEPS);
    monitor.worked(SHORT_TASK_STEPS);
    ISVNClientAdapter client = null;
    try {
        client = SVNProviderPlugin.getPlugin().getSVNClient();
        ISVNInfo info;
        if (resource == null)
            info = client.getInfo(remoteResource.getUrl());
        else {
            if (resource.getRawLocation() == null)
                info = client.getInfoFromWorkingCopy(resource.getLocation().toFile());
            else
                info = client.getInfoFromWorkingCopy(resource.getRawLocation().toFile());
            if (info.getUuid() == null) {
                info = client.getInfo(info.getUrl());
            }
        }
        if (editor != null)
            ((RevisionGraphEditorInput) editor.getEditorInput()).setInfo(info);
        long revision = info.getRevision().getNumber();
        String path = info.getUrl().toString().substring(info.getRepository().toString().length());
        monitor.setTaskName("Initializating cache");
        cache = getCache(info.getUuid());
        monitor.worked(SHORT_TASK_STEPS);
        // update the cache
        long latestRevisionStored = cache.getLatestRevision();
        SVNRevision latest = null;
        SVNRevision endRevision = null;
        monitor.setTaskName("Connecting to the repository");
        // TODO: try-catch this line and make it work off-line
        long latestRevisionInRepository = client.getInfo(info.getRepository()).getLastChangedRevision().getNumber();
        monitor.worked(SHORT_TASK_STEPS);
        if (refreshRevision != null || refreshRevisions != null || latestRevisionInRepository > latestRevisionStored) {
            if (refreshRevision == null) {
                if (latestRevisionStored >= latestRevisionInRepository)
                    latest = new SVNRevision.Number(latestRevisionInRepository);
                else
                    latest = new SVNRevision.Number(latestRevisionStored + 1);
            } else {
                latest = refreshRevision;
            }
            if (refreshRevision == null)
                endRevision = SVNRevision.HEAD;
            else
                endRevision = refreshRevision;
            try {
                monitor.setTaskName("Retrieving revision history");
                int unitWork;
                if (refreshRevision == null && refreshRevisions == null)
                    unitWork = VERY_LONG_TASK / (int) (latestRevisionInRepository - latestRevisionStored);
                else if (refreshRevisions != null)
                    unitWork = VERY_LONG_TASK / refreshRevisions.length;
                else
                    unitWork = VERY_LONG_TASK;
                if (refreshRevisions != null) {
                    if (monitor.isCanceled())
                        return;
                    monitor.setTaskName("Refreshing cache");
                    List refreshedNodes = new ArrayList();
                    for (int i = 0; i < refreshNodes.length; i++) {
                        if (refreshNodes[i].getAction() != 'D')
                            refreshedNodes.add(refreshNodes[i]);
                    }
                    cache.refresh(refreshedNodes, info, monitor, unitWork);
                } else if (refreshRevision != null) {
                    if (monitor.isCanceled())
                        return;
                    monitor.setTaskName("Refreshing cache");
                    revision = refreshNode.getRevision();
                    path = refreshNode.getPath();
                    List refreshedNodes = new ArrayList();
                    refreshedNodes.add(refreshNode);
                    cache.refresh(refreshedNodes, info, monitor, unitWork);
                }
                if (getNewRevisions) {
                    CallbackUpdater callbackUpdater = new CallbackUpdater(cache, monitor, unitWork, client);
                    cache.startUpdate();
                    client.getLogMessages(info.getRepository(), latest, latest, endRevision, false, true, 0, includeMergedRevisions, ISVNClientAdapter.DEFAULT_LOG_PROPERTIES, callbackUpdater);
                    cache.finishUpdate();
                }
            } catch (Exception e) {
                Activator.handleError(e);
                error = true;
                Activator.showErrorDialog("Calculate Revision Graph Information", e, false);
            }
        } else {
            monitor.worked(VERY_LONG_TASK);
        }
        if (editor != null) {
            if (error == true || monitor.isCanceled()) {
                if (refreshRevision == null && refreshRevisions == null) {
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            IWorkbenchWindow window = editor.getEditorSite().getWorkbenchWindow();
                            IWorkbenchPage page = window.getActivePage();
                            page.activate(editor);
                            page.closeEditor(editor, false);
                        }
                    });
                }
            } else {
                updateView(monitor, cache, path, revision);
            }
        }
        monitor.done();
    } catch (Exception e) {
        Activator.handleError(e);
        Activator.showErrorDialog("Calculate Revision Graph Information", e, false);
        return;
    } finally {
        if (cache != null)
            cache.close();
        SVNProviderPlugin.getPlugin().getSVNClientManager().returnSVNClient(client);
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ArrayList(java.util.ArrayList) SVNException(org.tigris.subversion.subclipse.core.SVNException) ISVNInfo(org.tigris.subversion.svnclientadapter.ISVNInfo) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ArrayList(java.util.ArrayList) List(java.util.List) SVNRevision(org.tigris.subversion.svnclientadapter.SVNRevision) Cache(org.tigris.subversion.subclipse.graph.cache.Cache) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter)

Example 4 with ISVNClientAdapter

use of org.tigris.subversion.svnclientadapter.ISVNClientAdapter in project subclipse by subclipse.

the class StatusCacheManager method getURL.

// getStatuses returns null URL for svn:externals folder.  This will
// get the URL using svn info command on the local resource
private String getURL(ISVNStatus status) {
    String url = status.getUrlString();
    if (url == null && !(status.getTextStatus() == SVNStatusKind.UNVERSIONED) && !(status.getTextStatus() == SVNStatusKind.IGNORED)) {
        ISVNClientAdapter svnClient = null;
        try {
            svnClient = SVNProviderPlugin.getPlugin().getSVNClient();
            SVNProviderPlugin.disableConsoleLogging();
            ISVNInfo info = svnClient.getInfoFromWorkingCopy(status.getFile());
            SVNUrl svnurl = info.getUrl();
            url = (svnurl != null) ? svnurl.toString() : null;
        } catch (SVNException e) {
        } catch (SVNClientException e) {
        } finally {
            SVNProviderPlugin.enableConsoleLogging();
            SVNProviderPlugin.getPlugin().getSVNClientManager().returnSVNClient(svnClient);
        }
    }
    return url;
}
Also used : SVNUrl(org.tigris.subversion.svnclientadapter.SVNUrl) 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)

Example 5 with ISVNClientAdapter

use of org.tigris.subversion.svnclientadapter.ISVNClientAdapter in project subclipse by subclipse.

the class BranchTagAction method run.

public void run() {
    BranchTagWizard wizard;
    final IResource resource = ((RevisionGraphEditorInput) editor.getEditorInput()).getResource();
    ISVNRemoteResource remoteResource = ((RevisionGraphEditorInput) editor.getEditorInput()).getRemoteResource();
    if (resource == null) {
        ISVNRemoteResource[] resources = { remoteResource };
        wizard = new BranchTagWizard(resources);
    } else {
        IResource[] resources = { resource };
        wizard = new BranchTagWizard(resources);
    }
    wizard.setRevisionNumber(node.getRevision());
    WizardDialog dialog = new ClosableWizardDialog(Display.getDefault().getActiveShell(), wizard);
    if (dialog.open() == WizardDialog.OK) {
        final SVNUrl sourceUrl = wizard.getUrl();
        final SVNUrl destinationUrl = wizard.getToUrl();
        final String message = wizard.getComment();
        final SVNRevision revision = wizard.getRevision();
        final boolean makeParents = wizard.isMakeParents();
        final SVNUrl[] sourceUrls = wizard.getUrls();
        final boolean createOnServer = wizard.isCreateOnServer();
        final Alias newAlias = wizard.getNewAlias();
        final boolean switchAfter = wizard.isSwitchAfterBranchTag();
        try {
            BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {

                public void run() {
                    ISVNClientAdapter client = null;
                    try {
                        if (resource == null) {
                            client = SVNProviderPlugin.getPlugin().getSVNClientManager().getSVNClient();
                            client.copy(sourceUrl, destinationUrl, message, revision, makeParents);
                        } else {
                            IResource[] resources = { resource };
                            BranchTagOperation branchTagOperation = new BranchTagOperation(editor.getEditorSite().getPart(), resources, sourceUrls, destinationUrl, createOnServer, revision, message);
                            branchTagOperation.setMakeParents(makeParents);
                            branchTagOperation.setNewAlias(newAlias);
                            branchTagOperation.switchAfterTagBranchOperation(switchAfter);
                            branchTagOperation.run();
                        }
                    } catch (Exception e) {
                        MessageDialog.openError(Display.getDefault().getActiveShell(), Policy.bind("HistoryView.createTagFromRevision"), e.getMessage());
                    } finally {
                        SVNProviderPlugin.getPlugin().getSVNClientManager().returnSVNClient(client);
                    }
                }
            });
        } catch (Exception e) {
            MessageDialog.openError(Display.getDefault().getActiveShell(), Policy.bind("HistoryView.createTagFromRevision"), e.getMessage());
        }
    }
}
Also used : SVNUrl(org.tigris.subversion.svnclientadapter.SVNUrl) ISVNRemoteResource(org.tigris.subversion.subclipse.core.ISVNRemoteResource) RevisionGraphEditorInput(org.tigris.subversion.subclipse.graph.editors.RevisionGraphEditorInput) BranchTagWizard(org.tigris.subversion.subclipse.ui.wizards.BranchTagWizard) Alias(org.tigris.subversion.subclipse.core.history.Alias) BranchTagOperation(org.tigris.subversion.subclipse.ui.operations.BranchTagOperation) ClosableWizardDialog(org.tigris.subversion.subclipse.ui.wizards.ClosableWizardDialog) SVNRevision(org.tigris.subversion.svnclientadapter.SVNRevision) ClosableWizardDialog(org.tigris.subversion.subclipse.ui.wizards.ClosableWizardDialog) WizardDialog(org.eclipse.jface.wizard.WizardDialog) IResource(org.eclipse.core.resources.IResource) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter)

Aggregations

ISVNClientAdapter (org.tigris.subversion.svnclientadapter.ISVNClientAdapter)108 SVNClientException (org.tigris.subversion.svnclientadapter.SVNClientException)67 SVNException (org.tigris.subversion.subclipse.core.SVNException)37 File (java.io.File)28 IResource (org.eclipse.core.resources.IResource)27 CoreException (org.eclipse.core.runtime.CoreException)22 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)21 TeamException (org.eclipse.team.core.TeamException)21 ISVNLocalResource (org.tigris.subversion.subclipse.core.ISVNLocalResource)20 ISVNRepositoryLocation (org.tigris.subversion.subclipse.core.ISVNRepositoryLocation)20 ISVNInfo (org.tigris.subversion.svnclientadapter.ISVNInfo)19 SVNUrl (org.tigris.subversion.svnclientadapter.SVNUrl)19 ArrayList (java.util.ArrayList)18 SVNRevision (org.tigris.subversion.svnclientadapter.SVNRevision)18 InvocationTargetException (java.lang.reflect.InvocationTargetException)15 ISVNProperty (org.tigris.subversion.svnclientadapter.ISVNProperty)13 OperationProgressNotifyListener (org.tigris.subversion.subclipse.core.client.OperationProgressNotifyListener)9 IProject (org.eclipse.core.resources.IProject)8 List (java.util.List)7 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)7