Search in sources :

Example 1 with LocalResourceStatus

use of org.tigris.subversion.subclipse.core.resources.LocalResourceStatus in project subclipse by subclipse.

the class FileModificationManager method resourceChanged.

/**
 * Listen for file modifications and fire modification state changes
 *
 * @see
 *     org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent)
 */
public void resourceChanged(IResourceChangeEvent event) {
    try {
        final List<IResource> modifiedResources = new ArrayList<IResource>();
        final List<IResource> modifiedInfiniteDepthResources = new ArrayList<IResource>();
        event.getDelta().accept(new IResourceDeltaVisitor() {

            public boolean visit(IResourceDelta delta) {
                IResource resource = delta.getResource();
                if (resource.isDerived()) {
                    LocalResourceStatus aStatus = null;
                    try {
                        aStatus = SVNProviderPlugin.getPlugin().getStatusCacheManager().getStatusFromCache(resource);
                    } catch (SVNException e) {
                        SVNProviderPlugin.log(IStatus.ERROR, e.getMessage(), e);
                    }
                    if ((aStatus == null) || !aStatus.isManaged()) {
                        return false;
                    }
                    if (ignoreManagedDerivedResources) {
                        return false;
                    }
                }
                if (resource.getType() == IResource.FILE) {
                    if (delta.getKind() == IResourceDelta.CHANGED && resource.exists()) {
                        if ((delta.getFlags() & INTERESTING_CHANGES) != 0) {
                            modifiedResources.add(resource);
                            return true;
                        }
                    } else if (delta.getKind() == IResourceDelta.ADDED) {
                        modifiedResources.add(resource);
                        return true;
                    } else if (delta.getKind() == IResourceDelta.REMOVED) {
                        // provide notifications for deletions since they may not have been managed
                        // The move/delete hook would have updated the parent counts properly
                        modifiedResources.add(resource);
                        return true;
                    }
                } else if (resource.getType() == IResource.FOLDER) {
                    // FIXME: Why a different processing for add and delete?
                    if (delta.getKind() == IResourceDelta.ADDED) {
                        if (resource.getParent() != null && !modifiedInfiniteDepthResources.contains(resource.getParent())) {
                            modifiedInfiniteDepthResources.add(resource.getParent());
                        } else {
                            modifiedInfiniteDepthResources.add(resource);
                        }
                        return false;
                    } else if (delta.getKind() == IResourceDelta.REMOVED) {
                        modifiedInfiniteDepthResources.add(resource);
                        // No need to add the complete resource tree
                        return false;
                    }
                    return true;
                } else if (resource.getType() == IResource.PROJECT) {
                    IProject project = (IProject) resource;
                    if ((delta.getKind() & IResourceDelta.REMOVED) != 0) {
                        SVNWorkspaceRoot.unsetManagedBySubclipse(project);
                        return false;
                    }
                    if (!project.isAccessible()) {
                        return false;
                    }
                    if (delta.getKind() != IResourceDelta.ADDED && (delta.getFlags() & IResourceDelta.OPEN) != 0) {
                        return false;
                    }
                    if (!SVNWorkspaceRoot.isManagedBySubclipse(project)) {
                        if (delta.getKind() == IResourceDelta.ADDED) {
                            autoShareProjectIfSVNWorkingCopy(project);
                        }
                        // not a svn handled project
                        return false;
                    }
                    if (delta.getKind() == IResourceDelta.ADDED) {
                        modifiedInfiniteDepthResources.add(resource);
                        return false;
                    } else if (delta.getKind() == IResourceDelta.REMOVED) {
                        modifiedInfiniteDepthResources.add(resource);
                        return false;
                    }
                }
                return true;
            }
        });
        if (!ignoreRefreshSvnStatusCache && (!modifiedResources.isEmpty() || !modifiedInfiniteDepthResources.isEmpty())) {
            List<IProject> projects = new ArrayList<IProject>();
            if (!modifiedResources.isEmpty()) {
                IResource[] resources = (IResource[]) modifiedResources.toArray(new IResource[modifiedResources.size()]);
                for (IResource resource : resources) {
                    IProject project = resource.getProject();
                    if (project != null && !projects.contains(project)) {
                        projects.add(project);
                    }
                }
            }
            if (!modifiedInfiniteDepthResources.isEmpty()) {
                IResource[] resources = (IResource[]) modifiedInfiniteDepthResources.toArray(new IResource[modifiedInfiniteDepthResources.size()]);
                for (IResource resource : resources) {
                    IProject project = resource.getProject();
                    if (project != null && !projects.contains(project)) {
                        projects.add(project);
                    }
                }
            }
            IProject[] projectArray = new IProject[projects.size()];
            projects.toArray(projectArray);
            JobUtility.scheduleJob("Refresh SVN status cache", new Runnable() {

                public void run() {
                    // SVNLightweightDecorator)
                    if (!modifiedResources.isEmpty()) {
                        IResource[] resources = (IResource[]) modifiedResources.toArray(new IResource[modifiedResources.size()]);
                        refreshStatus(resources);
                        SVNProviderPlugin.broadcastModificationStateChanges(resources);
                    }
                    if (!modifiedInfiniteDepthResources.isEmpty()) {
                        refreshStatusInfinite(modifiedInfiniteDepthResources);
                        IResource[] resources = (IResource[]) modifiedInfiniteDepthResources.toArray(new IResource[modifiedInfiniteDepthResources.size()]);
                        SVNProviderPlugin.broadcastModificationStateChanges(resources);
                    }
                }
            }, new RefreshStatusCacheSchedulingRule(MultiRule.combine(projectArray)), false);
        }
    } catch (CoreException e) {
        SVNProviderPlugin.log(e.getStatus());
    }
}
Also used : ArrayList(java.util.ArrayList) SVNException(org.tigris.subversion.subclipse.core.SVNException) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) IResourceDeltaVisitor(org.eclipse.core.resources.IResourceDeltaVisitor) LocalResourceStatus(org.tigris.subversion.subclipse.core.resources.LocalResourceStatus) IResource(org.eclipse.core.resources.IResource) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Example 2 with LocalResourceStatus

use of org.tigris.subversion.subclipse.core.resources.LocalResourceStatus in project subclipse by subclipse.

the class StatusCacheManager method basicGetStatus.

/**
 * Get the statuse(s) from the svn meta files
 *
 * @param resource
 * @param strategy
 * @return
 * @throws SVNException
 */
private LocalResourceStatus basicGetStatus(IResource resource, StatusUpdateStrategy strategy) throws SVNException {
    if (!resource.exists())
        return LocalResourceStatus.NONE;
    LocalResourceStatus status = null;
    /* Code commented so that svn:externals that are multi-level deep will be
     * decorated.  In this scenario, there can be unversioned files in the middle
     * of the svn:externals files.                                               */
    // if (isAncestorNotManaged(resource)) {
    // // we know the resource is not managed because one of its ancestor is not managed
    // status = new LocalResourceStatus(new
    // SVNStatusUnversioned(resource.getLocation().toFile(),false));
    // } else {
    // we don't know if resource is managed or not, we must update its status
    strategy.setStatusCache(statusCache);
    setStatuses(resource, strategy.statusesToUpdate(resource));
    status = statusCache.getStatus(resource);
    if (status == null && resource != null && resource.getLocation() != null) {
        status = new LocalResourceStatus(new SVNStatusUnversioned(resource.getLocation().toFile(), false), null, checkForReadOnly);
    }
    return status;
}
Also used : SVNStatusUnversioned(org.tigris.subversion.svnclientadapter.SVNStatusUnversioned) LocalResourceStatus(org.tigris.subversion.subclipse.core.resources.LocalResourceStatus)

Example 3 with LocalResourceStatus

use of org.tigris.subversion.subclipse.core.resources.LocalResourceStatus in project subclipse by subclipse.

the class SVNWorkspaceSubscriber method getSyncInfo.

/* (non-Javadoc)
   * @see org.eclipse.team.core.subscribers.Subscriber#getSyncInfo(org.eclipse.core.resources.IResource)
   */
public SyncInfo getSyncInfo(IResource resource) throws TeamException {
    if (resource == null)
        return null;
    if (!isSupervised(resource))
        return null;
    if (ignoreHiddenChanges && Util.isHidden(resource)) {
        return null;
    }
    // LocalResourceStatus localStatus = SVNWorkspaceRoot.getSVNResourceFor( resource );
    LocalResourceStatus localStatus = SVNProviderPlugin.getPlugin().getStatusCacheManager().getStatus(resource);
    RemoteResourceStatus remoteStatusInfo = null;
    byte[] remoteBytes = remoteSyncStateStore.getBytes(resource);
    if ((remoteBytes != null) && (remoteBytes != DUMMY_SYNC_BYTES)) {
        remoteStatusInfo = RemoteResourceStatus.fromBytes(remoteBytes);
    }
    SyncInfo syncInfo = new SVNStatusSyncInfo(resource, localStatus, remoteStatusInfo, comparator);
    syncInfo.init();
    return syncInfo;
}
Also used : RemoteResourceStatus(org.tigris.subversion.subclipse.core.resources.RemoteResourceStatus) SyncInfo(org.eclipse.team.core.synchronize.SyncInfo) LocalResourceStatus(org.tigris.subversion.subclipse.core.resources.LocalResourceStatus)

Example 4 with LocalResourceStatus

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

Example 5 with LocalResourceStatus

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

Aggregations

LocalResourceStatus (org.tigris.subversion.subclipse.core.resources.LocalResourceStatus)26 ISVNLocalResource (org.tigris.subversion.subclipse.core.ISVNLocalResource)17 IResource (org.eclipse.core.resources.IResource)12 SVNException (org.tigris.subversion.subclipse.core.SVNException)12 ISVNRepositoryLocation (org.tigris.subversion.subclipse.core.ISVNRepositoryLocation)7 CoreException (org.eclipse.core.runtime.CoreException)6 TeamException (org.eclipse.team.core.TeamException)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 ArrayList (java.util.ArrayList)4 ISVNClientAdapter (org.tigris.subversion.svnclientadapter.ISVNClientAdapter)4 File (java.io.File)3 List (java.util.List)2 IContainer (org.eclipse.core.resources.IContainer)2 IFile (org.eclipse.core.resources.IFile)2 IProject (org.eclipse.core.resources.IProject)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 Path (org.eclipse.core.runtime.Path)2 WizardDialog (org.eclipse.jface.wizard.WizardDialog)2 OperationManager (org.tigris.subversion.subclipse.core.client.OperationManager)2 SVNClientException (org.tigris.subversion.svnclientadapter.SVNClientException)2