Search in sources :

Example 21 with SVNException

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

the class LocalResource method getUrl.

/**
 * get the url of the resource in the repository The resource does not need to exist in repository
 *
 * @return the url or null if cannot get the url (when project is not managed)
 * @throws SVNException
 */
public SVNUrl getUrl() {
    try {
        LocalResourceStatus status = getStatusFromCache();
        if (status.isManaged()) {
            // if the resource is managed, get the url directly
            return status.getUrl();
        } else {
            // otherwise, get the url of the parent
            SVNUrl parentUrl = null;
            ISVNLocalResource parent = getParent();
            if (parent != null) {
                parentUrl = parent.getUrl();
            }
            if (parentUrl == null) {
                // we cannot find the url
                return null;
            }
            return parentUrl.appendPath(resource.getName());
        }
    } catch (SVNException e) {
        return null;
    }
}
Also used : SVNUrl(org.tigris.subversion.svnclientadapter.SVNUrl) SVNException(org.tigris.subversion.subclipse.core.SVNException) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource)

Example 22 with SVNException

use of org.tigris.subversion.subclipse.core.SVNException 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 23 with SVNException

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

the class SVNRepositoryLocation method getRemoteFile.

/*
   * (non-Javadoc)
   * @see org.tigris.subversion.subclipse.core.ISVNRepositoryLocation#getRemoteFile(org.tigris.subversion.svnclientadapter.SVNUrl)
   */
public ISVNRemoteFile getRemoteFile(SVNUrl url) throws SVNException {
    ISVNClientAdapter svnClient = getSVNClient();
    ISVNInfo info = null;
    try {
        if (this.getRepositoryRoot().equals(url))
            return new RemoteFile(this, url, SVNRevision.HEAD);
        else
            info = svnClient.getInfo(url, SVNRevision.HEAD, SVNRevision.HEAD);
    } catch (SVNClientException e) {
        throw new SVNException("Can't get latest remote resource for " + url);
    }
    if (// no remote file
    info == null)
        // no remote file
        return null;
    else {
        return new RemoteFile(// we don't know its parent
        null, this, url, SVNRevision.HEAD, info.getLastChangedRevision(), info.getLastChangedDate(), info.getLastCommitAuthor());
    }
}
Also used : SVNClientException(org.tigris.subversion.svnclientadapter.SVNClientException) ISVNInfo(org.tigris.subversion.svnclientadapter.ISVNInfo) SVNException(org.tigris.subversion.subclipse.core.SVNException) ISVNRemoteFile(org.tigris.subversion.subclipse.core.ISVNRemoteFile) RemoteFile(org.tigris.subversion.subclipse.core.resources.RemoteFile) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter)

Example 24 with SVNException

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

the class LocalFolder method getSVNFolders.

public IFolder[] getSVNFolders(IProgressMonitor monitor, final boolean unmanage) throws SVNException {
    final ArrayList<IFolder> svnFolders = new ArrayList<IFolder>();
    SVNProviderPlugin.run(new ISVNRunnable() {

        public void run(IProgressMonitor pm) throws SVNException {
            pm = Policy.monitorFor(pm);
            pm.beginTask(null, 100);
            ISVNResource[] members = members(Policy.subMonitorFor(pm, 20), FOLDER_MEMBERS | MANAGED_MEMBERS);
            ArrayList<IContainer> dirs = new ArrayList<IContainer>();
            for (ISVNResource member : members) {
                dirs.add((IContainer) ((ISVNLocalResource) member).getIResource());
            }
            // we add the current folder to the
            dirs.add((IContainer) getIResource());
            // list : we want to add .svn dir
            // for it too
            IProgressMonitor monitorDel = Policy.subMonitorFor(pm, 80);
            monitorDel.beginTask(null, dirs.size());
            for (IContainer container : dirs) {
                monitorDel.worked(1);
                recursiveGetSVNFolders(container, monitorDel, unmanage);
            }
            monitorDel.done();
            pm.done();
        }

        private void recursiveGetSVNFolders(IContainer container, IProgressMonitor pm, boolean unmanage) {
            try {
                // We must not add svn directories for linked resources.
                if (container.isLinked())
                    return;
                pm.beginTask(null, 10);
                pm.subTask(container.getFullPath().toOSString());
                IResource[] members = container.members(true);
                for (IResource member : members) {
                    pm.worked(1);
                    if (member.getType() != IResource.FILE) {
                        recursiveGetSVNFolders((IContainer) member, pm, unmanage);
                    }
                }
                // Post order traversal
                IFolder svnFolder = container.getFolder(new Path(SVNProviderPlugin.getPlugin().getAdminDirectoryName()));
                if (svnFolder.exists()) {
                    svnFolders.add(svnFolder);
                    if (unmanage) {
                        try {
                            svnFolder.delete(true, null);
                        } catch (CoreException e) {
                        }
                    }
                }
            } catch (CoreException e) {
            // Just ignore and continue
            } finally {
                pm.done();
            }
        }
    }, Policy.subMonitorFor(monitor, 99));
    IFolder[] folderArray = new IFolder[svnFolders.size()];
    svnFolders.toArray(folderArray);
    return folderArray;
}
Also used : Path(org.eclipse.core.runtime.Path) ISVNRunnable(org.tigris.subversion.subclipse.core.ISVNRunnable) ArrayList(java.util.ArrayList) ISVNResource(org.tigris.subversion.subclipse.core.ISVNResource) SVNException(org.tigris.subversion.subclipse.core.SVNException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 25 with SVNException

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

the class AliasManager method getAliases.

private Alias[] getAliases(IResource resource, boolean checkParents) {
    ArrayList<Alias> aliases = new ArrayList<Alias>();
    if (resource != null) {
        ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(resource);
        try {
            if (svnResource.isManaged()) {
                ISVNProperty property = null;
                // $NON-NLS-1$
                property = svnResource.getSvnProperty("subclipse:tags");
                if (property != null && property.getValue() != null)
                    getAliases(aliases, property.getValue(), svnResource.getUrl().toString());
                if (checkParents) {
                    IResource checkResource = resource;
                    while (checkResource.getParent() != null) {
                        checkResource = checkResource.getParent();
                        Alias[] parentAliases = getAliases(checkResource, false);
                        for (Alias parentAlias : parentAliases) {
                            if (aliases.contains(parentAlias)) {
                                Alias checkAlias = (Alias) aliases.get(aliases.indexOf(parentAlias));
                                if (parentAlias.getRevision() < checkAlias.getRevision()) {
                                    aliases.remove(checkAlias);
                                    aliases.add(parentAlias);
                                }
                            } else
                                aliases.add(parentAlias);
                        }
                    }
                }
            }
        } catch (SVNException e) {
        }
    }
    Alias[] aliasArray = new Alias[aliases.size()];
    aliases.toArray(aliasArray);
    return aliasArray;
}
Also used : ArrayList(java.util.ArrayList) ISVNProperty(org.tigris.subversion.svnclientadapter.ISVNProperty) SVNException(org.tigris.subversion.subclipse.core.SVNException) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) IResource(org.eclipse.core.resources.IResource)

Aggregations

SVNException (org.tigris.subversion.subclipse.core.SVNException)162 IResource (org.eclipse.core.resources.IResource)68 ISVNLocalResource (org.tigris.subversion.subclipse.core.ISVNLocalResource)68 ArrayList (java.util.ArrayList)39 CoreException (org.eclipse.core.runtime.CoreException)25 ISVNClientAdapter (org.tigris.subversion.svnclientadapter.ISVNClientAdapter)25 SVNClientException (org.tigris.subversion.svnclientadapter.SVNClientException)23 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)21 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)19 Iterator (java.util.Iterator)18 TeamException (org.eclipse.team.core.TeamException)18 InvocationTargetException (java.lang.reflect.InvocationTargetException)17 IContainer (org.eclipse.core.resources.IContainer)16 SVNUrl (org.tigris.subversion.svnclientadapter.SVNUrl)16 File (java.io.File)15 IProject (org.eclipse.core.resources.IProject)15 ISynchronizeModelElement (org.eclipse.team.ui.synchronize.ISynchronizeModelElement)14 IFile (org.eclipse.core.resources.IFile)13 GridData (org.eclipse.swt.layout.GridData)13 ISVNRemoteResource (org.tigris.subversion.subclipse.core.ISVNRemoteResource)13