Search in sources :

Example 16 with ISVNClientAdapter

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

the class ImportCommand 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 {
    final IProgressMonitor subPm = Policy.infiniteSubMonitorFor(monitor, 100);
    ISVNClientAdapter svnClient = null;
    try {
        subPm.beginTask(null, Policy.INFINITE_PM_GUESS_FOR_SWITCH);
        svnClient = folder.getRepository().getSVNClient();
        OperationManager.getInstance().beginOperation(svnClient, new OperationProgressNotifyListener(subPm, svnClient));
        svnClient.doImport(dir, folder.getUrl(), comment, recurse);
    } catch (SVNClientException e) {
        throw SVNException.wrapException(e);
    } finally {
        folder.getRepository().returnSVNClient(svnClient);
        OperationManager.getInstance().endOperation();
        subPm.done();
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SVNClientException(org.tigris.subversion.svnclientadapter.SVNClientException) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter) OperationProgressNotifyListener(org.tigris.subversion.subclipse.core.client.OperationProgressNotifyListener)

Example 17 with ISVNClientAdapter

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

the class LockResourcesCommand 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 {
    final ISVNClientAdapter svnClient = root.getRepository().getSVNClient();
    final File[] resourceFiles = new File[resources.length];
    for (int i = 0; i < resources.length; i++) resourceFiles[i] = resources[i].getLocation().toFile();
    try {
        monitor.beginTask(null, 100);
        svnClient.addNotifyListener(operationResourceCollector);
        OperationManager.getInstance().beginOperation(svnClient);
        svnClient.lock(resourceFiles, message, force);
    } catch (SVNClientException e) {
        throw SVNException.wrapException(e);
    } finally {
        Set<IResource> operationResources = operationResourceCollector.getOperationResources();
        OperationManager.getInstance().endOperation(true, operationResources, refreshLocal);
        if (svnClient != null) {
            svnClient.removeNotifyListener(operationResourceCollector);
            root.getRepository().returnSVNClient(svnClient);
        }
        monitor.done();
    }
}
Also used : SVNClientException(org.tigris.subversion.svnclientadapter.SVNClientException) File(java.io.File) IResource(org.eclipse.core.resources.IResource) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter)

Example 18 with ISVNClientAdapter

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

the class MergeCommand method run.

public void run(IProgressMonitor monitor) throws SVNException {
    ISVNClientAdapter svnClient = null;
    try {
        monitor.beginTask(null, 100);
        svnClient = root.getRepository().getSVNClient();
        OperationManager.getInstance().beginOperation(svnClient, new OperationProgressNotifyListener(monitor, svnClient));
        monitor.subTask(resource.getName());
        File file = resource.getLocation().toFile();
        svnClient.merge(svnUrl1, svnRevision1, svnUrl2, svnRevision2, file, force, recurse, false, ignoreAncestry);
        try {
            // Refresh the resource after merge
            resource.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
        } catch (CoreException e1) {
        }
        monitor.worked(100);
    } catch (SVNClientException e) {
        throw SVNException.wrapException(e);
    } finally {
        root.getRepository().returnSVNClient(svnClient);
        OperationManager.getInstance().endOperation();
        monitor.done();
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) SVNClientException(org.tigris.subversion.svnclientadapter.SVNClientException) File(java.io.File) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter) OperationProgressNotifyListener(org.tigris.subversion.subclipse.core.client.OperationProgressNotifyListener)

Example 19 with ISVNClientAdapter

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

the class RevertResourcesCommand 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 {
    final Set<IResource> propertiesOnlyFolders = new LinkedHashSet<IResource>();
    // sort first, so that all children of a folder directly follow it in the array
    Arrays.sort(resources, resourceComparator);
    ISVNClientAdapter svnClient = root.getRepository().getSVNClient();
    try {
        final OperationManager operationManager = OperationManager.getInstance();
        operationManager.beginOperation(svnClient);
        // local history first.  Also remove unversioned resources.
        if (recurse && resourcesToRevert != null) {
            for (int i = 0; i < resourcesToRevert.length; i++) {
                if (project == null || resourcesToRevert[i].getProject().equals(project)) {
                    try {
                        Util.saveLocalHistory(resourcesToRevert[i]);
                    } catch (CoreException e) {
                        SVNProviderPlugin.log(IStatus.ERROR, e.getMessage(), e);
                    }
                    LocalResourceStatus status = SVNWorkspaceRoot.getSVNResourceFor(resourcesToRevert[i]).getStatus();
                    if (!(resourcesToRevert[i].getType() == IResource.FOLDER) || !status.isAdded()) {
                        if (!status.isManaged()) {
                            try {
                                resourcesToRevert[i].delete(true, monitor);
                            } catch (CoreException ex) {
                                throw SVNException.wrapException(ex);
                            }
                        }
                    }
                }
            }
        }
        for (int i = 0; i < resources.length; i++) {
            LocalResourceStatus status = SVNWorkspaceRoot.getSVNResourceFor(resources[i]).getStatus();
            // current as a base path.
            if (resources[i].getType() == IResource.FOLDER && status.isAdded()) {
                svnClient.revert(resources[i].getLocation().toFile(), true);
                propertiesOnlyFolders.add(resources[i]);
                monitor.worked(100);
                // be refreshed.
                try {
                    resources[i].accept(new IResourceVisitor() {

                        public boolean visit(IResource aResource) {
                            if (aResource.getType() == IResource.FOLDER) {
                                operationManager.onNotify(aResource.getLocation().toFile(), SVNNodeKind.UNKNOWN);
                                // This is necessary for folders, that are ignored after the revert
                                propertiesOnlyFolders.add(aResource);
                            }
                            return true;
                        }
                    }, IResource.DEPTH_INFINITE, false);
                } catch (CoreException e) {
                    SVNProviderPlugin.log(Status.WARNING, "", e);
                }
                // If folder path has no ending / we can have problem where dir foobar will look like
                // subdir of foo
                String baseFullPath = resources[i].getFullPath().addTrailingSeparator().toString();
                while (i < resources.length - 1 && resources[i + 1].getFullPath().toString().startsWith(baseFullPath)) {
                    monitor.worked(100);
                    i++;
                }
            } else {
                if (!status.isManaged()) {
                    try {
                        resources[i].delete(true, monitor);
                    } catch (CoreException ex) {
                        throw SVNException.wrapException(ex);
                    }
                } else {
                    if (!recurse) {
                        try {
                            Util.saveLocalHistory(resources[i]);
                        } catch (CoreException e) {
                            SVNProviderPlugin.log(IStatus.ERROR, e.getMessage(), e);
                        }
                    }
                    File path = resources[i].getLocation().toFile();
                    svnClient.revert(path, recurse);
                    // notify the change. As workaround, do it manually.
                    if (resources[i].getType() != IResource.FILE) {
                        operationManager.onNotify(path, SVNNodeKind.UNKNOWN);
                        propertiesOnlyFolders.add(resources[i]);
                    }
                    monitor.worked(100);
                }
            }
        }
    } catch (SVNClientException e) {
        throw SVNException.wrapException(e);
    } finally {
        root.getRepository().returnSVNClient(svnClient);
        if (propertiesOnlyFolders.size() > 0) {
            OperationManager.getInstance().endOperation(true, propertiesOnlyFolders);
        } else {
            OperationManager.getInstance().endOperation();
        }
        monitor.done();
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IResourceVisitor(org.eclipse.core.resources.IResourceVisitor) CoreException(org.eclipse.core.runtime.CoreException) SVNClientException(org.tigris.subversion.svnclientadapter.SVNClientException) OperationManager(org.tigris.subversion.subclipse.core.client.OperationManager) LocalResourceStatus(org.tigris.subversion.subclipse.core.resources.LocalResourceStatus) File(java.io.File) IResource(org.eclipse.core.resources.IResource) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter)

Example 20 with ISVNClientAdapter

use of org.tigris.subversion.svnclientadapter.ISVNClientAdapter 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

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