Search in sources :

Example 16 with SVNException

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

the class GetLogsCommand method run.

/**
 * execute the command
 *
 * @param aMonitor
 * @throws SVNException
 */
public void run(IProgressMonitor aMonitor) throws SVNException {
    ISVNRepositoryLocation repository = null;
    ISVNClientAdapter svnClient = null;
    logEntries = null;
    IProgressMonitor monitor = Policy.monitorFor(aMonitor);
    // $NON-NLS-1$
    monitor.beginTask(Policy.bind("RemoteFile.getLogEntries"), 100);
    ISVNLogMessage[] logMessages;
    try {
        if (callback == null) {
            logMessages = remoteResource.getLogMessages(pegRevision, revisionStart, revisionEnd, stopOnCopy, !SVNProviderPlugin.getPlugin().getSVNClientManager().isFetchChangePathOnDemand(), limit, includeMergedRevisions);
        } else {
            repository = remoteResource.getRepository();
            svnClient = repository.getSVNClient();
            if (remoteResource instanceof BaseResource) {
                boolean logMessagesRetrieved = false;
                ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(remoteResource.getResource());
                if (svnResource != null) {
                    LocalResourceStatus status = svnResource.getStatus();
                    if (status != null && status.isCopied()) {
                        ISVNInfo info = svnClient.getInfoFromWorkingCopy(svnResource.getFile());
                        SVNUrl copiedFromUrl = info.getCopyUrl();
                        if (copiedFromUrl != null) {
                            svnClient.getLogMessages(copiedFromUrl, SVNRevision.HEAD, revisionStart, revisionEnd, stopOnCopy, !SVNProviderPlugin.getPlugin().getSVNClientManager().isFetchChangePathOnDemand(), limit, includeMergedRevisions, ISVNClientAdapter.DEFAULT_LOG_PROPERTIES, callback);
                            logMessagesRetrieved = true;
                            GetRemoteResourceCommand getRemoteResourceCommand = new GetRemoteResourceCommand(remoteResource.getRepository(), copiedFromUrl, SVNRevision.HEAD);
                            getRemoteResourceCommand.run(null);
                            remoteResource = getRemoteResourceCommand.getRemoteResource();
                        }
                    }
                }
                if (!logMessagesRetrieved)
                    svnClient.getLogMessages(((BaseResource) remoteResource).getFile(), pegRevision, revisionStart, revisionEnd, stopOnCopy, !SVNProviderPlugin.getPlugin().getSVNClientManager().isFetchChangePathOnDemand(), limit, includeMergedRevisions, ISVNClientAdapter.DEFAULT_LOG_PROPERTIES, callback);
            } else {
                svnClient.getLogMessages(remoteResource.getUrl(), pegRevision, revisionStart, revisionEnd, stopOnCopy, !SVNProviderPlugin.getPlugin().getSVNClientManager().isFetchChangePathOnDemand(), limit, includeMergedRevisions, ISVNClientAdapter.DEFAULT_LOG_PROPERTIES, callback);
            }
            logMessages = callback.getLogMessages();
        }
        if (remoteResource.isFolder()) {
            logEntries = LogEntry.createLogEntriesFrom((ISVNRemoteFolder) remoteResource, logMessages, getTags(logMessages));
        } else {
            logEntries = LogEntry.createLogEntriesFrom((ISVNRemoteFile) remoteResource, logMessages, getTags(logMessages), getUrls(logMessages));
        }
    } catch (Exception e) {
        throw SVNException.wrapException(e);
    } finally {
        if (repository != null) {
            repository.returnSVNClient(svnClient);
        }
        monitor.done();
    }
}
Also used : SVNUrl(org.tigris.subversion.svnclientadapter.SVNUrl) BaseResource(org.tigris.subversion.subclipse.core.resources.BaseResource) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) ISVNRemoteFolder(org.tigris.subversion.subclipse.core.ISVNRemoteFolder) ISVNLogMessage(org.tigris.subversion.svnclientadapter.ISVNLogMessage) SVNException(org.tigris.subversion.subclipse.core.SVNException) ISVNRepositoryLocation(org.tigris.subversion.subclipse.core.ISVNRepositoryLocation) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ISVNRemoteFile(org.tigris.subversion.subclipse.core.ISVNRemoteFile) ISVNInfo(org.tigris.subversion.svnclientadapter.ISVNInfo) LocalResourceStatus(org.tigris.subversion.subclipse.core.resources.LocalResourceStatus) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter)

Example 17 with SVNException

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

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

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

Example 20 with SVNException

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

the class ShareProjectCommand 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 {
    // Determine if the repository is known
    boolean alreadyExists = SVNProviderPlugin.getPlugin().getRepositories().isKnownRepository(location.getLocation(), false);
    final ISVNClientAdapter svnClient = location.getSVNClient();
    try {
        // perform the workspace modifications in a runnable
        SVNProviderPlugin.run(new ISVNRunnable() {

            public void run(IProgressMonitor pm) throws SVNException {
                String message;
                if (comment == null)
                    // $NON-NLS-1$
                    message = Policy.bind("SVNProvider.initialImport");
                else
                    message = comment;
                try {
                    // create the remote dir
                    SVNUrl url = location.getUrl().appendPath(remoteDirName);
                    if (createDirectory)
                        svnClient.mkdir(url, true, message);
                    try {
                        OperationManager.getInstance().beginOperation(svnClient, new OperationProgressNotifyListener(pm, svnClient));
                        // checkout it so that we have .svn
                        // If directory already existed in repository, do recursive checkout.
                        svnClient.checkout(url, project.getLocation().toFile(), SVNRevision.HEAD, !createDirectory);
                    } finally {
                        OperationManager.getInstance().endOperation();
                    }
                } catch (SVNClientException e) {
                    throw new SVNException("Error while creating module: " + e.getMessage(), e);
                }
                // SharingWizard.doesSVNDirectoryExist calls
                // getStatus on the folder which populates the
                // status cache
                // Need to clear the cache so we can get the new
                // hasRemote value
                SVNProviderPlugin.getPlugin().getStatusCacheManager().refreshStatus(project, true);
                try {
                    // Register it with Team.
                    RepositoryProvider.map(project, SVNProviderPlugin.getTypeId());
                } catch (TeamException e) {
                    throw new SVNException("Cannot register project with svn provider", e);
                }
            }
        }, monitor);
    } catch (SVNException e) {
        // its cache
        if (!alreadyExists)
            SVNProviderPlugin.getPlugin().getRepositories().disposeRepository(location);
        throw e;
    } finally {
        location.returnSVNClient(svnClient);
    }
    // Add the repository if it didn't exist already
    if (!alreadyExists)
        SVNProviderPlugin.getPlugin().getRepositories().addOrUpdateRepository(location);
}
Also used : ISVNRunnable(org.tigris.subversion.subclipse.core.ISVNRunnable) TeamException(org.eclipse.team.core.TeamException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SVNUrl(org.tigris.subversion.svnclientadapter.SVNUrl) SVNClientException(org.tigris.subversion.svnclientadapter.SVNClientException) SVNException(org.tigris.subversion.subclipse.core.SVNException) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter) OperationProgressNotifyListener(org.tigris.subversion.subclipse.core.client.OperationProgressNotifyListener)

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