Search in sources :

Example 1 with ISVNRunnable

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

the class CheckinResourcesCommand 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 {
    commitError = false;
    postCommitError = null;
    final ISVNClientAdapter svnClient = root.getRepository().getSVNClient();
    OperationManager.getInstance().beginOperation(svnClient, new OperationProgressNotifyListener(monitor, svnClient));
    try {
        // Prepare the parents list
        // we will Auto-commit parents if they are not already commited
        List<IContainer> parentsList = new ArrayList<IContainer>();
        List<IProject> projectList = new ArrayList<IProject>();
        for (IResource currentResource : resources) {
            IProject project = currentResource.getProject();
            if (!projectList.contains(project)) {
                projectList.add(project);
            }
            IContainer parent = currentResource.getParent();
            ISVNLocalResource svnParentResource = SVNWorkspaceRoot.getSVNResourceFor(parent);
            while (parent.getType() != IResource.ROOT && parent.getType() != IResource.PROJECT && !svnParentResource.hasRemote()) {
                if (!inCommitList(parent))
                    parentsList.add(parent);
                parent = parent.getParent();
                svnParentResource = svnParentResource.getParent();
            }
        }
        // convert parents and resources to an array of File
        int parents = parentsList.size();
        // change commit to non-recursive!!
        if (parents > 0)
            depth = IResource.DEPTH_ZERO;
        final File[] resourceFiles = new File[parents + resources.length];
        for (int i = 0; i < parents; i++) {
            resourceFiles[i] = ((IResource) parentsList.get(i)).getLocation().toFile();
        }
        for (int i = 0, j = parents; i < resources.length; i++, j++) {
            resourceFiles[j] = resources[i].getLocation().toFile();
        }
        IProject[] projects = new IProject[projectList.size()];
        projectList.toArray(projects);
        ISchedulingRule rule = MultiRule.combine(projects);
        SVNProviderPlugin.run(new ISVNRunnable() {

            public void run(final IProgressMonitor pm) throws SVNException {
                try {
                    notifyListener = new ISVNNotifyListener() {

                        public void logCommandLine(String commandLine) {
                        }

                        public void logCompleted(String message) {
                        }

                        public void logError(String message) {
                        }

                        public void logMessage(String message) {
                            if (message.startsWith("Transmitting file data"))
                                pm.subTask(message);
                        }

                        public void logRevision(long revision, String path) {
                        }

                        public void onNotify(File path, SVNNodeKind kind) {
                        }

                        public void setCommand(int command) {
                        }
                    };
                    pm.beginTask(null, resourceFiles.length);
                    pm.setTaskName("Checking in...");
                    svnClient.addNotifyListener(operationResourceCollector);
                    svnClient.addNotifyListener(notifyListener);
                    // then the resources the user has requested to commit
                    if (svnClient.canCommitAcrossWC())
                        svnClient.commitAcrossWC(resourceFiles, message, depth == IResource.DEPTH_INFINITE, keepLocks, true);
                    else
                        svnClient.commit(resourceFiles, message, depth == IResource.DEPTH_INFINITE, keepLocks);
                    postCommitError = svnClient.getPostCommitError();
                } catch (SVNClientException e) {
                    commitError = true;
                    throw SVNException.wrapException(e);
                } finally {
                    pm.done();
                    if (svnClient != null) {
                        svnClient.removeNotifyListener(operationResourceCollector);
                        svnClient.removeNotifyListener(notifyListener);
                        root.getRepository().returnSVNClient(svnClient);
                    }
                }
            }
        }, rule, Policy.monitorFor(monitor));
    } finally {
        OperationManager.getInstance().endOperation(true, operationResourceCollector.getOperationResources(), !commitError);
    }
}
Also used : ISVNRunnable(org.tigris.subversion.subclipse.core.ISVNRunnable) ArrayList(java.util.ArrayList) SVNException(org.tigris.subversion.subclipse.core.SVNException) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) IProject(org.eclipse.core.resources.IProject) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SVNNodeKind(org.tigris.subversion.svnclientadapter.SVNNodeKind) ISVNNotifyListener(org.tigris.subversion.svnclientadapter.ISVNNotifyListener) SVNClientException(org.tigris.subversion.svnclientadapter.SVNClientException) IContainer(org.eclipse.core.resources.IContainer) File(java.io.File) IResource(org.eclipse.core.resources.IResource) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter) OperationProgressNotifyListener(org.tigris.subversion.subclipse.core.client.OperationProgressNotifyListener)

Example 2 with ISVNRunnable

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

Example 3 with ISVNRunnable

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

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

the class CheckoutCommand 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 {
    try {
        for (int i = 0; i < resources.length; i++) {
            final IProject project = projects[i];
            final ISVNRemoteFolder resource = resources[i];
            SVNProviderPlugin.run(new ISVNRunnable() {

                public void run(IProgressMonitor pm) throws SVNException {
                    basicRun(project, resource, pm);
                }
            }, projects[i], Policy.monitorFor(monitor));
        }
    } finally {
        OperationManager.getInstance().endOperation();
    }
}
Also used : ISVNRunnable(org.tigris.subversion.subclipse.core.ISVNRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SVNException(org.tigris.subversion.subclipse.core.SVNException) ISVNRemoteFolder(org.tigris.subversion.subclipse.core.ISVNRemoteFolder) IProject(org.eclipse.core.resources.IProject)

Example 5 with ISVNRunnable

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

the class SwitchToUrlCommand method run.

/* (non-Javadoc)
   * @see org.tigris.subversion.subclipse.core.commands.ISVNCommand#run(org.eclipse.core.runtime.IProgressMonitor)
   */
public void run(final IProgressMonitor monitor) throws SVNException {
    final ISVNClientAdapter svnClient = root.getRepository().getSVNClient();
    OperationManager.getInstance().beginOperation(svnClient, new OperationProgressNotifyListener(monitor, svnClient));
    try {
        SVNProviderPlugin.run(new ISVNRunnable() {

            public void run(IProgressMonitor monitor) throws SVNException {
                try {
                    monitor.beginTask(null, Policy.INFINITE_PM_GUESS_FOR_SWITCH);
                    if (conflictResolver != null) {
                        svnClient.addConflictResolutionCallback(conflictResolver);
                    }
                    svnClient.addNotifyListener(operationResourceCollector);
                    File file = resource.getLocation().toFile();
                    svnClient.switchToUrl(file, svnUrl, svnRevision, svnRevision, depth, setDepth, ignoreExternals, force, ignoreAncestry);
                    OperationManager.getInstance().onNotify(resource.getLocation().toFile(), SVNNodeKind.UNKNOWN);
                } catch (SVNClientException e) {
                    throw SVNException.wrapException(e);
                } finally {
                    if (svnClient != null) {
                        if (conflictResolver != null) {
                            svnClient.addConflictResolutionCallback(null);
                        }
                        root.getRepository().returnSVNClient(svnClient);
                    }
                    monitor.done();
                }
            }
        }, resource.getProject(), Policy.monitorFor(monitor));
    } finally {
        Set<IResource> operationResources = operationResourceCollector.getOperationResources();
        if (operationResources.size() == 0) {
            IResource[] resources = SVNWorkspaceRoot.getResourcesFor(resource);
            for (IResource refreshResource : resources) {
                operationResources.add(refreshResource);
            }
        }
        OperationManager.getInstance().endOperation(true, operationResources);
    }
}
Also used : ISVNRunnable(org.tigris.subversion.subclipse.core.ISVNRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SVNClientException(org.tigris.subversion.svnclientadapter.SVNClientException) SVNException(org.tigris.subversion.subclipse.core.SVNException) File(java.io.File) IResource(org.eclipse.core.resources.IResource) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter) OperationProgressNotifyListener(org.tigris.subversion.subclipse.core.client.OperationProgressNotifyListener)

Aggregations

IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 ISVNRunnable (org.tigris.subversion.subclipse.core.ISVNRunnable)6 SVNException (org.tigris.subversion.subclipse.core.SVNException)6 IResource (org.eclipse.core.resources.IResource)4 OperationProgressNotifyListener (org.tigris.subversion.subclipse.core.client.OperationProgressNotifyListener)4 ISVNClientAdapter (org.tigris.subversion.svnclientadapter.ISVNClientAdapter)4 SVNClientException (org.tigris.subversion.svnclientadapter.SVNClientException)4 ArrayList (java.util.ArrayList)3 IProject (org.eclipse.core.resources.IProject)3 File (java.io.File)2 IContainer (org.eclipse.core.resources.IContainer)2 ISchedulingRule (org.eclipse.core.runtime.jobs.ISchedulingRule)2 IFolder (org.eclipse.core.resources.IFolder)1 CoreException (org.eclipse.core.runtime.CoreException)1 Path (org.eclipse.core.runtime.Path)1 TeamException (org.eclipse.team.core.TeamException)1 ISVNLocalResource (org.tigris.subversion.subclipse.core.ISVNLocalResource)1 ISVNRemoteFolder (org.tigris.subversion.subclipse.core.ISVNRemoteFolder)1 ISVNResource (org.tigris.subversion.subclipse.core.ISVNResource)1 ISVNNotifyListener (org.tigris.subversion.svnclientadapter.ISVNNotifyListener)1