Search in sources :

Example 61 with ISVNLocalResource

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

the class RevertResourceManager method resourceChanged.

public void resourceChanged(IResourceChangeEvent event) {
    final List<IResourceDelta> addedFileResources = new ArrayList<IResourceDelta>();
    try {
        event.getDelta().accept(new IResourceDeltaVisitor() {

            public boolean visit(IResourceDelta delta) throws CoreException {
                IResource resource = delta.getResource();
                if (resource.getType() == IResource.PROJECT) {
                    IProject project = (IProject) resource;
                    if (!project.isAccessible()) {
                        // i.e., closed project
                        return false;
                    }
                    if ((delta.getFlags() & IResourceDelta.OPEN) != 0) {
                        // ignore project open
                        return false;
                    }
                    if (!SVNWorkspaceRoot.isManagedBySubclipse(project)) {
                        // not a svn handled project
                        return false;
                    }
                } else if (resource.getType() == IResource.FILE) {
                    if (delta.getKind() == IResourceDelta.ADDED || delta.getKind() == IResourceDelta.CHANGED) {
                        addedFileResources.add(delta);
                    } else if (delta.getKind() == IResourceDelta.REMOVED) {
                        SVNMoveDeleteHook.removeFromDeletedFileList((IFile) delta.getResource());
                    }
                }
                return true;
            }
        });
        if (!addedFileResources.isEmpty()) {
            final IResourceDelta[] resources = (IResourceDelta[]) addedFileResources.toArray(new IResourceDelta[addedFileResources.size()]);
            final ISVNLocalResource[] revertResources = processResources(resources);
            if (revertResources.length > 0) {
                List<IProject> projects = new ArrayList<IProject>();
                for (ISVNLocalResource revertResource : revertResources) {
                    IProject project = revertResource.getResource().getProject();
                    if (project != null && !projects.contains(project)) {
                        projects.add(project);
                    }
                }
                IProject[] projectArray = new IProject[projects.size()];
                projects.toArray(projectArray);
                JobUtility.scheduleJob("Revert Resources", new Runnable() {

                    public void run() {
                        try {
                            for (int i = 0; i < revertResources.length; i++) {
                                if (revertResources[i] instanceof ISVNLocalFile) {
                                    ISVNLocalFile res = (ISVNLocalFile) revertResources[i];
                                    File file = res.getFile().getAbsoluteFile();
                                    // TODO a better location?
                                    File tmp = new File(res.getFile().getAbsolutePath() + ".svntmp");
                                    if (tmp.exists()) {
                                        tmp.delete();
                                    }
                                    if (file.renameTo(tmp)) {
                                        // res.revert is recursive and updates local history
                                        revert(res);
                                        if (!file.delete()) {
                                            // TODO handle this in a better way?
                                            if (file.exists()) {
                                                throw SVNException.wrapException(new IllegalStateException("Could not remove " + file));
                                            }
                                        }
                                        if (!tmp.renameTo(file)) {
                                            // TODO handle this in a better way?
                                            throw SVNException.wrapException(new IllegalStateException("Could not rename " + tmp + " to " + file));
                                        }
                                        try {
                                            res.getParent().getResource().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
                                        } catch (CoreException e) {
                                        }
                                    } else {
                                        // TODO handle this in a better way?
                                        throw SVNException.wrapException(new IllegalStateException("Could not rename " + file + " to " + tmp));
                                    }
                                } else {
                                    revert(revertResources[i]);
                                }
                            }
                        } catch (SVNException e) {
                            SVNProviderPlugin.log(e.getStatus());
                        }
                    }
                }, MultiRule.combine(projectArray), false);
            }
        }
    } catch (CoreException e) {
        SVNProviderPlugin.log(e.getStatus());
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) SVNException(org.tigris.subversion.subclipse.core.SVNException) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) IResourceDeltaVisitor(org.eclipse.core.resources.IResourceDeltaVisitor) ISVNLocalFile(org.tigris.subversion.subclipse.core.ISVNLocalFile) File(java.io.File) IFile(org.eclipse.core.resources.IFile) ISVNLocalFile(org.tigris.subversion.subclipse.core.ISVNLocalFile) IResource(org.eclipse.core.resources.IResource) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Example 62 with ISVNLocalResource

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

the class SVNRevisionComparator method compare.

/* (non-Javadoc)
   * @see org.eclipse.team.core.variants.IResourceVariantComparator#compare(org.eclipse.core.resources.IResource, org.eclipse.team.core.variants.IResourceVariant)
   */
public boolean compare(IResource local, IResourceVariant remote) {
    if (local == null && remote == null)
        return true;
    if (local == null || remote == null)
        return false;
    ISVNLocalResource a = SVNWorkspaceRoot.getSVNResourceFor(local);
    ISVNRemoteResource b = (ISVNRemoteResource) remote;
    try {
        return a.getStatus().getLastChangedRevision().getNumber() == b.getLastChangedRevision().getNumber();
    } catch (SVNException e) {
        Util.logError("Cannot compare local resource with remote resource", e);
    } catch (NullPointerException npe) {
        // We have already checked for the important/expected nulls
        return true;
    }
    return false;
}
Also used : ISVNRemoteResource(org.tigris.subversion.subclipse.core.ISVNRemoteResource) SVNException(org.tigris.subversion.subclipse.core.SVNException) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource)

Example 63 with ISVNLocalResource

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

the class SVNWorkspaceSubscriber method isSupervised.

/* (non-Javadoc)
   * @see org.eclipse.team.core.subscribers.Subscriber#isSupervised(org.eclipse.core.resources.IResource)
   */
public boolean isSupervised(IResource resource) throws TeamException {
    try {
        if (resource.isTeamPrivateMember() || SVNWorkspaceRoot.isLinkedResource(resource))
            return false;
        RepositoryProvider provider = RepositoryProvider.getProvider(resource.getProject(), SVNProviderPlugin.getTypeId());
        if (provider == null)
            return false;
        // TODO: what happens for resources that don't exist?
        // TODO: is it proper to use ignored here?
        ISVNLocalResource svnThing = SVNWorkspaceRoot.getSVNResourceFor(resource);
        if (svnThing.isIgnored()) {
            // An ignored resource could have an incoming addition (conflict)
            return (remoteSyncStateStore.getBytes(resource) != null) || ((remoteSyncStateStore.members(resource) != null) && (remoteSyncStateStore.members(resource).length > 0));
        }
        return true;
    } catch (TeamException e) {
        // so the resource is not supervised.
        if (e.getStatus().getCode() == IResourceStatus.RESOURCE_NOT_FOUND) {
            return false;
        }
        throw e;
    }
}
Also used : TeamException(org.eclipse.team.core.TeamException) RepositoryProvider(org.eclipse.team.core.RepositoryProvider) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource)

Example 64 with ISVNLocalResource

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

the class SynchronizeViewGraphAction method isEnabledForSelection.

private boolean isEnabledForSelection() {
    if (fSelection == null || fSelection.isEmpty())
        return false;
    ISynchronizeModelElement element = (ISynchronizeModelElement) fSelection.getFirstElement();
    IResource resource = element.getResource();
    if (resource == null)
        return false;
    ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(resource);
    try {
        return (svnResource != null && svnResource.isManaged() && !svnResource.isAdded());
    } catch (SVNException e) {
        return false;
    }
}
Also used : ISynchronizeModelElement(org.eclipse.team.ui.synchronize.ISynchronizeModelElement) SVNException(org.tigris.subversion.subclipse.core.SVNException) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) IResource(org.eclipse.core.resources.IResource)

Example 65 with ISVNLocalResource

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

the class LocalFolder method members.

/* (non-Javadoc)
   * @see org.tigris.subversion.subclipse.core.ISVNFolder#members(org.eclipse.core.runtime.IProgressMonitor, int)
   */
public ISVNResource[] members(IProgressMonitor monitor, int flags) throws SVNException {
    if (!resource.exists())
        return new ISVNLocalResource[0];
    boolean ignoreHiddenChanges = SVNProviderPlugin.getPlugin().getPluginPreferences().getBoolean(ISVNCoreConstants.PREF_IGNORE_HIDDEN_CHANGES);
    final List<ISVNLocalResource> result = new ArrayList<ISVNLocalResource>();
    IResource[] resources;
    try {
        boolean isHiddenSupported = true;
        ;
        if (!ignoreHiddenChanges) {
            try {
                isHiddenSupported = Util.isHiddenSupported();
            } catch (NoSuchMethodException e) {
                isHiddenSupported = false;
            }
        }
        if (ignoreHiddenChanges || !isHiddenSupported) {
            resources = ((IContainer) resource).members(true);
        } else {
            // 8 = IContainer.INCLUDE_HIDDEN.
            resources = ((IContainer) resource).members(8 | IContainer.INCLUDE_PHANTOMS);
        }
    } catch (CoreException e) {
        throw SVNException.wrapException(e);
    }
    final boolean includeFiles = (((flags & FILE_MEMBERS) != 0) || ((flags & (FILE_MEMBERS | FOLDER_MEMBERS)) == 0));
    final boolean includeFolders = (((flags & FOLDER_MEMBERS) != 0) || ((flags & (FILE_MEMBERS | FOLDER_MEMBERS)) == 0));
    final boolean includeManaged = (((flags & MANAGED_MEMBERS) != 0) || ((flags & (MANAGED_MEMBERS | UNMANAGED_MEMBERS | IGNORED_MEMBERS)) == 0));
    final boolean includeUnmanaged = (((flags & UNMANAGED_MEMBERS) != 0) || ((flags & (MANAGED_MEMBERS | UNMANAGED_MEMBERS | IGNORED_MEMBERS)) == 0));
    final boolean includeIgnored = ((flags & IGNORED_MEMBERS) != 0);
    final boolean includeExisting = (((flags & EXISTING_MEMBERS) != 0) || ((flags & (EXISTING_MEMBERS | PHANTOM_MEMBERS)) == 0));
    final boolean includePhantoms = (((flags & PHANTOM_MEMBERS) != 0) || ((flags & (EXISTING_MEMBERS | PHANTOM_MEMBERS)) == 0));
    for (int i = 0; i < resources.length; i++) {
        if ((includeFiles && (resources[i].getType() == IResource.FILE)) || (includeFolders && (resources[i].getType() == IResource.FOLDER))) {
            ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(resources[i]);
            final boolean isManaged = svnResource.isManaged();
            final boolean isIgnored = svnResource.isIgnored();
            if ((isManaged && includeManaged) || (isIgnored && includeIgnored) || (!isManaged && !isIgnored && includeUnmanaged)) {
                final boolean exists = svnResource.exists();
                if ((includeExisting && exists) || (includePhantoms && !exists)) {
                    if (!ignoreHiddenChanges || !Util.isHidden(resources[i], false)) {
                        result.add(svnResource);
                    }
                }
            }
        }
    }
    return (ISVNLocalResource[]) result.toArray(new ISVNLocalResource[result.size()]);
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ArrayList(java.util.ArrayList) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) IResource(org.eclipse.core.resources.IResource)

Aggregations

ISVNLocalResource (org.tigris.subversion.subclipse.core.ISVNLocalResource)120 IResource (org.eclipse.core.resources.IResource)77 SVNException (org.tigris.subversion.subclipse.core.SVNException)76 ArrayList (java.util.ArrayList)39 CoreException (org.eclipse.core.runtime.CoreException)24 Iterator (java.util.Iterator)20 IFile (org.eclipse.core.resources.IFile)20 ISVNClientAdapter (org.tigris.subversion.svnclientadapter.ISVNClientAdapter)20 InvocationTargetException (java.lang.reflect.InvocationTargetException)18 List (java.util.List)18 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)18 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)17 LocalResourceStatus (org.tigris.subversion.subclipse.core.resources.LocalResourceStatus)17 SVNClientException (org.tigris.subversion.svnclientadapter.SVNClientException)17 File (java.io.File)16 TeamException (org.eclipse.team.core.TeamException)16 ISVNRepositoryLocation (org.tigris.subversion.subclipse.core.ISVNRepositoryLocation)15 ISynchronizeModelElement (org.eclipse.team.ui.synchronize.ISynchronizeModelElement)14 IContainer (org.eclipse.core.resources.IContainer)13 SyncInfo (org.eclipse.team.core.synchronize.SyncInfo)11