Search in sources :

Example 11 with ISVNClientAdapter

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

the class GetRemoteResourceCommand method run.

/* (non-Javadoc)
   * @see org.tigris.subversion.subclipse.core.commands.ISVNCommand#run(org.eclipse.core.runtime.IProgressMonitor)
   */
public void run(IProgressMonitor monitor) throws SVNException {
    monitor = Policy.monitorFor(monitor);
    // $NON-NLS-1$
    monitor.beginTask(Policy.bind("GetRemoteResourceCommand.getLogEntries"), 100);
    remoteResource = null;
    ISVNClientAdapter svnClient = repository.getSVNClient();
    ISVNInfo info;
    try {
        info = svnClient.getInfo(url, revision, revision);
    } catch (SVNClientException e) {
        throw new SVNException("Can't get remote resource " + url + " at revision " + revision, e);
    } finally {
        repository.returnSVNClient(svnClient);
    }
    if (info == null) {
        // no remote file
        remoteResource = null;
    } else {
        if (info.getNodeKind() == SVNNodeKind.FILE)
            remoteResource = new RemoteFile(// we don't know its parent
            null, repository, url, revision, info.getLastChangedRevision(), info.getLastChangedDate(), info.getLastCommitAuthor());
        else
            remoteResource = new RemoteFolder(// we don't know its parent
            null, repository, url, revision, info.getLastChangedRevision(), info.getLastChangedDate(), info.getLastCommitAuthor());
    }
    monitor.done();
}
Also used : RemoteFolder(org.tigris.subversion.subclipse.core.resources.RemoteFolder) SVNClientException(org.tigris.subversion.svnclientadapter.SVNClientException) ISVNInfo(org.tigris.subversion.svnclientadapter.ISVNInfo) SVNException(org.tigris.subversion.subclipse.core.SVNException) RemoteFile(org.tigris.subversion.subclipse.core.resources.RemoteFile) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter)

Example 12 with ISVNClientAdapter

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

the class GetStatusCommand 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) {
    ISVNClientAdapter svnClient = null;
    String url = status.getUrlString();
    if (url == null && !(status.getTextStatus() == SVNStatusKind.UNVERSIONED)) {
        try {
            svnClient = repository.getSVNClient();
            ISVNInfo info = svnClient.getInfoFromWorkingCopy(status.getFile());
            SVNUrl svnurl = info.getUrl();
            url = (svnurl != null) ? svnurl.toString() : null;
        } catch (SVNException e) {
        } catch (SVNClientException e) {
        } finally {
            repository.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 13 with ISVNClientAdapter

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

the class PeekStatusCommand method execute.

public void execute() throws SVNException {
    ISVNClientAdapter client = null;
    ISVNNotifyListener revisionListener = new ISVNNotifyListener() {

        public void setCommand(int command) {
        }

        public void logCommandLine(String commandLine) {
        }

        public void logMessage(String message) {
        }

        public void logError(String message) {
        }

        public void logRevision(long aRevision, String path) {
            PeekStatusCommand.this.revision = new SVNRevision.Number(aRevision);
        }

        public void logCompleted(String message) {
        }

        public void onNotify(File path, SVNNodeKind kind) {
        }
    };
    try {
        client = SVNProviderPlugin.getPlugin().getSVNClientManager().getSVNClient();
        client.addNotifyListener(revisionListener);
        File file;
        if (resource != null)
            file = resource.getLocation().toFile();
        else
            file = path.toFile();
        status = null;
        ISVNStatus[] statuses = client.getStatus(file, false, true, false);
        for (int i = 0; i < statuses.length; i++) {
            if (file.equals(statuses[i].getFile())) {
                status = statuses[i];
                if (status.getUrl() == null && !(status.getTextStatus() == SVNStatusKind.UNVERSIONED))
                    info = client.getInfo(status.getFile());
                break;
            }
        }
    } catch (SVNClientException e) {
        throw SVNException.wrapException(e);
    } finally {
        if (client != null) {
            client.removeNotifyListener(revisionListener);
            SVNProviderPlugin.getPlugin().getSVNClientManager().returnSVNClient(client);
        }
    }
}
Also used : SVNNodeKind(org.tigris.subversion.svnclientadapter.SVNNodeKind) ISVNNotifyListener(org.tigris.subversion.svnclientadapter.ISVNNotifyListener) SVNClientException(org.tigris.subversion.svnclientadapter.SVNClientException) ISVNStatus(org.tigris.subversion.svnclientadapter.ISVNStatus) SVNRevision(org.tigris.subversion.svnclientadapter.SVNRevision) File(java.io.File) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter)

Example 14 with ISVNClientAdapter

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

the class StatusAndInfoCommand method run.

/* (non-Javadoc)
   * @see org.tigris.subversion.subclipse.core.commands.ISVNCommand#run(org.eclipse.core.runtime.IProgressMonitor)
   */
public void run(IProgressMonitor monitor) throws SVNException {
    ISVNClientAdapter svnClient = null;
    try {
        svnClient = SVNProviderPlugin.getPlugin().getSVNClient();
        execute(svnClient, monitor);
    } catch (SVNClientException e) {
        throw SVNException.wrapException(e);
    } finally {
        SVNProviderPlugin.getPlugin().getSVNClientManager().returnSVNClient(svnClient);
    }
}
Also used : SVNClientException(org.tigris.subversion.svnclientadapter.SVNClientException) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter)

Example 15 with ISVNClientAdapter

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

the class AddResourcesCommand method run.

/* (non-Javadoc)
   * @see org.tigris.subversion.subclipse.core.commands.ISVNCommand#run(org.eclipse.core.runtime.IProgressMonitor)
   */
public void run(IProgressMonitor monitor) throws SVNException {
    monitor = Policy.monitorFor(monitor);
    // Visit the children of the resources using the depth in order to
    // determine which folders, text files and binary files need to be added
    // A TreeSet is needed for the folders so they are in the right order (i.e. parents created
    // before children)
    final SortedSet<ISVNLocalResource> folders = new TreeSet<ISVNLocalResource>();
    // Sets are required for the files to ensure that files will not appear twice if there parent
    // was added as well
    // and the depth isn't zero
    final HashSet<ISVNLocalResource> files = new HashSet<ISVNLocalResource>();
    for (int i = 0; i < resources.length; i++) {
        final IResource currentResource = resources[i];
        try {
            // Auto-add parents if they are not already managed
            IContainer parent = currentResource.getParent();
            ISVNLocalResource svnParentResource = SVNWorkspaceRoot.getSVNResourceFor(parent);
            while (parent.getType() != IResource.ROOT && parent.getType() != IResource.PROJECT && !svnParentResource.isManaged()) {
                folders.add(svnParentResource);
                parent = parent.getParent();
                svnParentResource = svnParentResource.getParent();
            }
            // Auto-add children accordingly to depth
            final SVNException[] exception = new SVNException[] { null };
            currentResource.accept(new IResourceVisitor() {

                public boolean visit(IResource resource) {
                    try {
                        ISVNLocalResource mResource = SVNWorkspaceRoot.getSVNResourceFor(resource);
                        // added explicitly (is equal currentResource) or is not ignored
                        if ((!mResource.isManaged()) && (currentResource.equals(resource) || !mResource.isIgnored())) {
                            if (resource.getType() == IResource.FILE) {
                                files.add(mResource);
                            } else {
                                folders.add(mResource);
                            }
                        }
                        // Always return true and let the depth determine if children are visited
                        return true;
                    } catch (SVNException e) {
                        exception[0] = e;
                        return false;
                    }
                }
            }, depth, false);
            if (exception[0] != null) {
                throw exception[0];
            }
        } catch (CoreException e) {
            throw new SVNException(new Status(IStatus.ERROR, SVNProviderPlugin.ID, TeamException.UNABLE, Policy.bind("SVNTeamProvider.visitError", new Object[] { resources[i].getFullPath() }), // $NON-NLS-1$
            e));
        }
    }
    // for
    // If an exception occured during the visit, throw it here
    // Add the folders, followed by files!
    ISVNClientAdapter svnClient = root.getRepository().getSVNClient();
    monitor.beginTask(null, files.size() + folders.size());
    monitor.setTaskName("Adding...");
    svnClient.addNotifyListener(operationResourceCollector);
    OperationManager.getInstance().beginOperation(svnClient, new OperationProgressNotifyListener(monitor, svnClient));
    try {
        for (ISVNLocalResource localResource : folders) {
            try {
                svnClient.addDirectory(localResource.getIResource().getLocation().toFile(), false);
                localResource.refreshStatus();
            } catch (SVNClientException e) {
                throw SVNException.wrapException(e);
            }
        }
        for (ISVNLocalResource localResource : files) {
            try {
                svnClient.addFile(localResource.getIResource().getLocation().toFile());
                // If file has read-only attribute set, remove it
                ResourceAttributes attrs = localResource.getIResource().getResourceAttributes();
                if (localResource.getIResource().getType() == IResource.FILE && attrs.isReadOnly()) {
                    attrs.setReadOnly(false);
                    try {
                        localResource.getIResource().setResourceAttributes(attrs);
                    } catch (CoreException swallow) {
                    }
                }
            } catch (SVNClientException e) {
                throw SVNException.wrapException(e);
            }
        }
    } finally {
        Set<IResource> operationResources = operationResourceCollector.getOperationResources();
        OperationManager.getInstance().endOperation(true, operationResources);
        monitor.done();
        if (svnClient != null) {
            svnClient.removeNotifyListener(operationResourceCollector);
            root.getRepository().returnSVNClient(svnClient);
        }
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IResourceVisitor(org.eclipse.core.resources.IResourceVisitor) SVNException(org.tigris.subversion.subclipse.core.SVNException) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) ResourceAttributes(org.eclipse.core.resources.ResourceAttributes) CoreException(org.eclipse.core.runtime.CoreException) TreeSet(java.util.TreeSet) SVNClientException(org.tigris.subversion.svnclientadapter.SVNClientException) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) HashSet(java.util.HashSet) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter) OperationProgressNotifyListener(org.tigris.subversion.subclipse.core.client.OperationProgressNotifyListener)

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