Search in sources :

Example 6 with ISVNClientAdapter

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

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

the class CheckoutCommand method scrubProject.

/*
   * Delete the target projects before checking out
   * @param monitor - may be null !
   */
private void scrubProject(ISVNRemoteFolder resource, IProject project, IProgressMonitor monitor) throws SVNException {
    if (project == null) {
        if (monitor != null) {
            monitor.done();
        }
        return;
    }
    if (monitor != null) {
        monitor.beginTask("", 100);
        monitor.subTask(// $NON-NLS-1$
        Policy.bind("SVNProvider.Scrubbing_local_project_1", project.getName()));
    }
    try {
        File destPath = null;
        if (projectRoot != null) {
            destPath = new File(projectRoot.toFile(), project.getName());
        }
        // New location, just delete the project but not the content.
        if (destPath != null && !destPath.exists() && project != null && project.exists()) {
            project.delete(IResource.NEVER_DELETE_PROJECT_CONTENT, monitor);
            project = null;
        }
        if (project != null && project.exists() && (destPath == null || destPath.exists())) {
            if (!project.isOpen()) {
                project.open((monitor != null) ? Policy.subMonitorFor(monitor, 10) : null);
            }
            // unmap the project from any previous repository provider
            if (RepositoryProvider.getProvider(project) != null)
                RepositoryProvider.unmap(project);
            IResource[] children = project.members(IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS);
            IProgressMonitor subMonitor = (monitor != null) ? Policy.subMonitorFor(monitor, 80) : null;
            if (subMonitor != null) {
                subMonitor.beginTask(null, children.length * 100);
            }
            ISVNClientAdapter clientSilent = null;
            try {
                for (int j = 0; j < children.length; j++) {
                    if (!children[j].getName().equals(".project")) {
                        // $NON-NLS-1$
                        if (clientSilent == null)
                            clientSilent = SVNProviderPlugin.getPlugin().getSVNClient();
                        ISVNInfo info = null;
                        try {
                            SVNUrl url = new SVNUrl(resource.getUrl().toString() + "/" + children[j].getProjectRelativePath());
                            try {
                                SVNProviderPlugin.disableConsoleLogging();
                                info = clientSilent.getInfo(url);
                            } catch (SVNClientException e2) {
                            } finally {
                                SVNProviderPlugin.enableConsoleLogging();
                            }
                        } catch (MalformedURLException e1) {
                        }
                        if (info != null)
                            children[j].delete(true, /* force */
                            (subMonitor != null) ? Policy.subMonitorFor(subMonitor, 100) : null);
                    }
                }
            } finally {
                if (subMonitor != null) {
                    subMonitor.done();
                }
                SVNProviderPlugin.getPlugin().getSVNClientManager().returnSVNClient(clientSilent);
            }
        } else if (project != null) {
            // Make sure there is no directory in the local file system.
            File location = new File(project.getParent().getLocation().toFile(), project.getName());
            if (location.exists()) {
                deepDelete(location);
            }
        }
    } catch (CoreException e) {
        throw SVNException.wrapException(e);
    } finally {
        if (monitor != null) {
            monitor.subTask(" ");
            monitor.done();
        }
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) MalformedURLException(java.net.MalformedURLException) CoreException(org.eclipse.core.runtime.CoreException) SVNUrl(org.tigris.subversion.svnclientadapter.SVNUrl) SVNClientException(org.tigris.subversion.svnclientadapter.SVNClientException) ISVNInfo(org.tigris.subversion.svnclientadapter.ISVNInfo) File(java.io.File) IResource(org.eclipse.core.resources.IResource) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter)

Example 8 with ISVNClientAdapter

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

the class CheckoutCommand method basicRun.

protected void basicRun(final IProject project, ISVNRemoteFolder resource, final IProgressMonitor pm) throws SVNException {
    ISVNClientAdapter svnClient = null;
    if (pm != null) {
        pm.beginTask(null, 1000);
    }
    try {
        // Perform the checkout
        boolean createProject = false;
        svnClient = resource.getRepository().getSVNClient();
        OperationManager.getInstance().beginOperation(svnClient, new OperationProgressNotifyListener(pm, svnClient));
        // Prepare the target projects to receive resources
        scrubProject(resource, project, (pm != null) ? Policy.subMonitorFor(pm, 100) : null);
        File destPath;
        if (project.getLocation() == null) {
            // not exist in the workspace
            if (projectRoot == null) {
                ISVNLocalFolder root = SVNWorkspaceRoot.getSVNFolderFor(ResourcesPlugin.getWorkspace().getRoot());
                destPath = new File(root.getIResource().getLocation().toFile(), project.getName());
            } else {
                destPath = new File(projectRoot.toFile(), project.getName());
            }
            if (!destPath.exists()) {
                destPath.mkdirs();
            }
            createProject = true;
        } else {
            if (projectRoot != null) {
                try {
                    destPath = new File(projectRoot.toFile(), project.getName());
                    setProjectToRoot(project, destPath);
                } catch (CoreException e) {
                    throw new SVNException("Cannot create project to checkout to", e);
                }
            } else {
                destPath = project.getLocation().toFile();
            }
        }
        if (createProject) {
            createProjectList.add(project);
        }
        checkoutProject(pm, resource, svnClient, destPath);
        SVNWorkspaceRoot.setManagedBySubclipse(project);
        if (refreshProjects) {
            try {
                project.create(null);
                project.open(null);
            } catch (CoreException e1) {
                throw new SVNException("Cannot create project to checkout to", e1);
            }
            refreshProject(project, (pm != null) ? Policy.subMonitorFor(pm, 100) : null);
        } else {
            manageProjectList.add(project);
        }
    } finally {
        resource.getRepository().returnSVNClient(svnClient);
        if (pm != null) {
            pm.done();
        }
    }
}
Also used : ISVNLocalFolder(org.tigris.subversion.subclipse.core.ISVNLocalFolder) CoreException(org.eclipse.core.runtime.CoreException) SVNException(org.tigris.subversion.subclipse.core.SVNException) File(java.io.File) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter) OperationProgressNotifyListener(org.tigris.subversion.subclipse.core.client.OperationProgressNotifyListener)

Example 9 with ISVNClientAdapter

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

the class CleanupResourcesCommand 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 = root.getRepository().getSVNClient();
    try {
        monitor.beginTask(null, 100 * resources.length);
        OperationManager.getInstance().beginOperation(svnClient);
        for (int i = 0; i < resources.length; i++) {
            if (resources[i].getLocation() != null) {
                svnClient.cleanup(resources[i].getLocation().toFile());
                cleanedUpResources.add(resources[i]);
            }
            monitor.worked(100);
        }
    } catch (SVNClientException e) {
        throw SVNException.wrapException(e);
    } finally {
        Set<IResource> refreshResources = new LinkedHashSet<IResource>();
        for (IResource resource : cleanedUpResources) {
            addToRefreshList(refreshResources, resource);
        }
        OperationManager.getInstance().endOperation(true, refreshResources);
        root.getRepository().returnSVNClient(svnClient);
        monitor.done();
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) SVNClientException(org.tigris.subversion.svnclientadapter.SVNClientException) IResource(org.eclipse.core.resources.IResource) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter)

Example 10 with ISVNClientAdapter

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

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