Search in sources :

Example 16 with SVNTeamProvider

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

the class SVNMoveDeleteHook method moveFolder.

public boolean moveFolder(IResourceTree tree, IFolder source, IFolder destination, int updateFlags, IProgressMonitor monitor) {
    if (SVNWorkspaceRoot.isLinkedResource(source))
        return false;
    try {
        ISVNLocalFolder resource = new LocalFolder(source);
        if (!resource.isManaged())
            return false;
        RepositoryProvider repositoryProvider = RepositoryProvider.getProvider(destination.getProject());
        if (repositoryProvider == null || // target is not SVN project
        !(repositoryProvider instanceof SVNTeamProvider))
            return false;
        ISVNRepositoryLocation sourceRepository = resource.getRepository();
        ISVNLocalResource parent = SVNWorkspaceRoot.getSVNResourceFor(destination.getParent());
        ISVNRepositoryLocation targetRepository = parent.getRepository();
        if (!sourceRepository.equals(targetRepository)) {
            return false;
        }
        monitor.beginTask(null, 1000);
        ISVNClientAdapter svnClient = sourceRepository.getSVNClient();
        try {
            OperationManager.getInstance().beginOperation(svnClient);
            // see bug #15
            if (!SVNWorkspaceRoot.getSVNFolderFor(destination.getParent()).isManaged()) {
                SVNTeamProvider provider = (SVNTeamProvider) repositoryProvider;
                provider.add(new IResource[] { destination.getParent() }, IResource.DEPTH_ZERO, new NullProgressMonitor());
                if (parent != null)
                    parent.refreshStatus();
            }
            svnClient.move(source.getLocation().toFile(), destination.getLocation().toFile(), true);
            tree.movedFolderSubtree(source, destination);
            destination.refreshLocal(IResource.DEPTH_INFINITE, monitor);
        } catch (SVNClientException e) {
            throw SVNException.wrapException(e);
        } catch (CoreException e) {
            throw SVNException.wrapException(e);
        } finally {
            resource.getRepository().returnSVNClient(svnClient);
            OperationManager.getInstance().endOperation(false);
        }
    } catch (SVNException e) {
        tree.failed(e.getStatus());
    } finally {
        monitor.done();
    }
    return true;
}
Also used : ISVNLocalFolder(org.tigris.subversion.subclipse.core.ISVNLocalFolder) ISVNLocalFolder(org.tigris.subversion.subclipse.core.ISVNLocalFolder) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) SVNTeamProvider(org.tigris.subversion.subclipse.core.SVNTeamProvider) ISVNRepositoryLocation(org.tigris.subversion.subclipse.core.ISVNRepositoryLocation) CoreException(org.eclipse.core.runtime.CoreException) SVNClientException(org.tigris.subversion.svnclientadapter.SVNClientException) SVNException(org.tigris.subversion.subclipse.core.SVNException) RepositoryProvider(org.eclipse.team.core.RepositoryProvider) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter)

Example 17 with SVNTeamProvider

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

the class GenerateDiffFileOperation method run.

/**
 * @see IRunnableWithProgress#run(IProgressMonitor)
 */
public void run(IProgressMonitor monitor) throws InvocationTargetException {
    ISVNClientAdapter svnClient = null;
    ISVNRepositoryLocation repository = null;
    try {
        // $NON-NLS-1$
        monitor.beginTask("", 500);
        // $NON-NLS-1$
        monitor.setTaskName(Policy.bind("GenerateSVNDiff.working"));
        OutputStream os;
        if (toClipboard) {
            os = new ByteArrayOutputStream();
        } else {
            os = new FileOutputStream(outputFile);
        }
        // $NON-NLS-1$ //$NON-NLS-2$
        File tmpFile = File.createTempFile("sub", "");
        tmpFile.deleteOnExit();
        ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(resources[0]);
        newFiles = new ArrayList();
        if (unaddedResources.length > 0) {
            // });
            for (int i = 0; i < unaddedResources.length; i++) newFiles.add(unaddedResources[i]);
            if (newFiles.size() > 0) {
                try {
                    // associate the resources with their respective RepositoryProvider
                    Hashtable table = getProviderMapping((IResource[]) newFiles.toArray(new IResource[newFiles.size()]));
                    Set keySet = table.keySet();
                    Iterator iterator = keySet.iterator();
                    while (iterator.hasNext()) {
                        IProgressMonitor subMonitor = Policy.subMonitorFor(monitor, 100);
                        SVNTeamProvider provider = (SVNTeamProvider) iterator.next();
                        List list = (List) table.get(provider);
                        IResource[] providerResources = (IResource[]) list.toArray(new IResource[list.size()]);
                        provider.add(providerResources, IResource.DEPTH_INFINITE, subMonitor);
                    }
                } catch (TeamException e) {
                    throw new InvocationTargetException(e);
                }
            }
        }
        repository = svnResource.getRepository();
        svnClient = repository.getSVNClient();
        try {
            monitor.worked(100);
            File[] files = getVersionedFiles();
            if (selectedResources == null)
                svnClient.diff(files, tmpFile, recursive);
            else {
                if (eclipseFormat) {
                    HashSet includedResources = new HashSet();
                    includedResources.addAll(Arrays.asList(unaddedResources));
                    includedResources.addAll(Arrays.asList(resources));
                    createEclipsePatch((IResource[]) includedResources.toArray(new IResource[0]), tmpFile, recursive);
                } else {
                    File relativeToPath = null;
                    if (projectRelative) {
                        relativeToPath = selectedResources[0].getProject().getLocation().toFile();
                    } else {
                        relativeToPath = getRelativeToPath();
                        if (relativeToPath.isFile()) {
                            relativeToPath = relativeToPath.getParentFile();
                        }
                    }
                    svnClient.createPatch(files, relativeToPath, tmpFile, recursive);
                }
            }
            monitor.worked(300);
            InputStream is = new FileInputStream(tmpFile);
            byte[] buffer = new byte[30000];
            int length;
            while ((length = is.read(buffer)) != -1) {
                os.write(buffer, 0, length);
            }
            is.close();
        } finally {
            os.close();
        }
        if (newFiles.size() > 0) {
            for (int i = 0; i < newFiles.size(); i++) {
                IResource resource = (IResource) newFiles.get(i);
                try {
                    SVNWorkspaceRoot.getSVNResourceFor(resource).revert();
                } catch (Exception e) {
                }
            }
        }
        boolean emptyDiff = false;
        if (toClipboard) {
            final ByteArrayOutputStream baos = (ByteArrayOutputStream) os;
            if (baos.size() == 0) {
                emptyDiff = true;
            } else {
                Display.getDefault().syncExec(new Runnable() {

                    public void run() {
                        TextTransfer plainTextTransfer = TextTransfer.getInstance();
                        Clipboard clipboard = new Clipboard(shell.getDisplay());
                        clipboard.setContents(new String[] { baos.toString() }, new Transfer[] { plainTextTransfer });
                        clipboard.dispose();
                    }
                });
            }
        } else {
            if (outputFile.length() == 0) {
                emptyDiff = true;
                outputFile.delete();
            }
        }
        // check for empty diff and report
        if (emptyDiff) {
            Display.getDefault().syncExec(new Runnable() {

                public void run() {
                    MessageDialog.openInformation(shell, // $NON-NLS-1$
                    Policy.bind("GenerateSVNDiff.noDiffsFoundTitle"), // $NON-NLS-1$
                    Policy.bind("GenerateSVNDiff.noDiffsFoundMsg"));
                }
            });
        }
    } catch (Exception e) {
        throw new InvocationTargetException(e);
    } finally {
        if (repository != null) {
            repository.returnSVNClient(svnClient);
        }
        monitor.done();
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) TeamException(org.eclipse.team.core.TeamException) ISVNRepositoryLocation(org.tigris.subversion.subclipse.core.ISVNRepositoryLocation) SVNTeamProvider(org.tigris.subversion.subclipse.core.SVNTeamProvider) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter) HashSet(java.util.HashSet) Hashtable(java.util.Hashtable) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) InvocationTargetException(java.lang.reflect.InvocationTargetException) FileInputStream(java.io.FileInputStream) SVNClientException(org.tigris.subversion.svnclientadapter.SVNClientException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) TeamException(org.eclipse.team.core.TeamException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) FileOutputStream(java.io.FileOutputStream) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Transfer(org.eclipse.swt.dnd.Transfer) Clipboard(org.eclipse.swt.dnd.Clipboard) File(java.io.File) IResource(org.eclipse.core.resources.IResource) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 18 with SVNTeamProvider

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

the class RelocateWizard method setSharedProjects.

private void setSharedProjects() {
    IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
    ArrayList shared = new ArrayList();
    for (int i = 0; i < projects.length; i++) {
        RepositoryProvider teamProvider = RepositoryProvider.getProvider(projects[i], SVNProviderPlugin.getTypeId());
        if (teamProvider != null) {
            try {
                SVNTeamProvider svnProvider = (SVNTeamProvider) teamProvider;
                if (svnProvider.getSVNWorkspaceRoot().getRepository().equals(repository))
                    shared.add(projects[i]);
            } catch (Exception e) {
            }
        }
    }
    sharedProjects = new IProject[shared.size()];
    shared.toArray(sharedProjects);
}
Also used : SVNTeamProvider(org.tigris.subversion.subclipse.core.SVNTeamProvider) ArrayList(java.util.ArrayList) RepositoryProvider(org.eclipse.team.core.RepositoryProvider) IProject(org.eclipse.core.resources.IProject)

Example 19 with SVNTeamProvider

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

the class RepositoryManager method commit.

/**
 * Commit the given resources to their associated providers.
 *
 * @param resources the resources to commit
 * @param monitor the progress monitor
 */
public void commit(IResource[] resources, String comment, boolean keepLocks, IProgressMonitor monitor) throws TeamException {
    if (monitor == null) {
        monitor = new NullProgressMonitor();
    }
    Map table = getProviderMapping(resources);
    Set keySet = table.keySet();
    // $NON-NLS-1$
    monitor.beginTask("", keySet.size() * 1000);
    // $NON-NLS-1$
    monitor.setTaskName(Policy.bind("RepositoryManager.committing"));
    Iterator iterator = keySet.iterator();
    while (iterator.hasNext()) {
        IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1000);
        SVNTeamProvider provider = (SVNTeamProvider) iterator.next();
        List list = (List) table.get(provider);
        IResource[] providerResources = (IResource[]) list.toArray(new IResource[list.size()]);
        provider.checkin(providerResources, comment, keepLocks, IResource.DEPTH_INFINITE, subMonitor);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SVNTeamProvider(org.tigris.subversion.subclipse.core.SVNTeamProvider) Set(java.util.Set) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IResource(org.eclipse.core.resources.IResource)

Example 20 with SVNTeamProvider

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

the class AddSynchronizeOperation method run.

protected void run(SVNTeamProvider provider, SyncInfoSet set, IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
    resources = set.getResources();
    getShell().getDisplay().syncExec(new Runnable() {

        public void run() {
            addIgnoredResources = promptForAddOfIgnored(resources);
        }
    });
    if (!addIgnoredResources)
        return;
    run(new WorkspaceModifyOperation() {

        public void execute(IProgressMonitor monitor) throws InvocationTargetException {
            try {
                // associate the resources with their respective RepositoryProvider
                Hashtable table = getProviderMapping(resources);
                Set keySet = table.keySet();
                // $NON-NLS-1$
                monitor.beginTask("", keySet.size() * 1000);
                // $NON-NLS-1$
                monitor.setTaskName(Policy.bind("AddAction.adding"));
                Iterator iterator = keySet.iterator();
                while (iterator.hasNext()) {
                    IProgressMonitor subMonitor = Policy.subMonitorFor(monitor, 1000);
                    SVNTeamProvider provider = (SVNTeamProvider) iterator.next();
                    List list = (List) table.get(provider);
                    IResource[] providerResources = (IResource[]) list.toArray(new IResource[list.size()]);
                    provider.add(providerResources, IResource.DEPTH_INFINITE, subMonitor);
                }
            } catch (TeamException e) {
                throw new InvocationTargetException(e);
            } finally {
                monitor.done();
            }
        }
    }, true, /* cancelable */
    PROGRESS_BUSYCURSOR);
}
Also used : TeamException(org.eclipse.team.core.TeamException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SVNTeamProvider(org.tigris.subversion.subclipse.core.SVNTeamProvider) SyncInfoSet(org.eclipse.team.core.synchronize.SyncInfoSet) Set(java.util.Set) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) Hashtable(java.util.Hashtable) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) InvocationTargetException(java.lang.reflect.InvocationTargetException) IResource(org.eclipse.core.resources.IResource)

Aggregations

SVNTeamProvider (org.tigris.subversion.subclipse.core.SVNTeamProvider)24 IResource (org.eclipse.core.resources.IResource)14 Iterator (java.util.Iterator)12 ArrayList (java.util.ArrayList)11 List (java.util.List)9 TeamException (org.eclipse.team.core.TeamException)9 HashMap (java.util.HashMap)8 Set (java.util.Set)8 IProject (org.eclipse.core.resources.IProject)8 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 SVNException (org.tigris.subversion.subclipse.core.SVNException)8 Map (java.util.Map)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 Hashtable (java.util.Hashtable)5 CoreException (org.eclipse.core.runtime.CoreException)5 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)5 RepositoryProvider (org.eclipse.team.core.RepositoryProvider)5 SyncInfoSet (org.eclipse.team.core.synchronize.SyncInfoSet)5 ISVNLocalResource (org.tigris.subversion.subclipse.core.ISVNLocalResource)5 ISVNRepositoryLocation (org.tigris.subversion.subclipse.core.ISVNRepositoryLocation)5