Search in sources :

Example 6 with ISVNLocalResource

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

the class AddResourcesCommand 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 {
    monitor = Policy.monitorFor(monitor);
    // Visit the children of the resources using the depth in order to
    // determine which folders, text files and binary files need to be added
    // A TreeSet is needed for the folders so they are in the right order (i.e. parents created
    // before children)
    final SortedSet<ISVNLocalResource> folders = new TreeSet<ISVNLocalResource>();
    // Sets are required for the files to ensure that files will not appear twice if there parent
    // was added as well
    // and the depth isn't zero
    final HashSet<ISVNLocalResource> files = new HashSet<ISVNLocalResource>();
    for (int i = 0; i < resources.length; i++) {
        final IResource currentResource = resources[i];
        try {
            // Auto-add parents if they are not already managed
            IContainer parent = currentResource.getParent();
            ISVNLocalResource svnParentResource = SVNWorkspaceRoot.getSVNResourceFor(parent);
            while (parent.getType() != IResource.ROOT && parent.getType() != IResource.PROJECT && !svnParentResource.isManaged()) {
                folders.add(svnParentResource);
                parent = parent.getParent();
                svnParentResource = svnParentResource.getParent();
            }
            // Auto-add children accordingly to depth
            final SVNException[] exception = new SVNException[] { null };
            currentResource.accept(new IResourceVisitor() {

                public boolean visit(IResource resource) {
                    try {
                        ISVNLocalResource mResource = SVNWorkspaceRoot.getSVNResourceFor(resource);
                        // added explicitly (is equal currentResource) or is not ignored
                        if ((!mResource.isManaged()) && (currentResource.equals(resource) || !mResource.isIgnored())) {
                            if (resource.getType() == IResource.FILE) {
                                files.add(mResource);
                            } else {
                                folders.add(mResource);
                            }
                        }
                        // Always return true and let the depth determine if children are visited
                        return true;
                    } catch (SVNException e) {
                        exception[0] = e;
                        return false;
                    }
                }
            }, depth, false);
            if (exception[0] != null) {
                throw exception[0];
            }
        } catch (CoreException e) {
            throw new SVNException(new Status(IStatus.ERROR, SVNProviderPlugin.ID, TeamException.UNABLE, Policy.bind("SVNTeamProvider.visitError", new Object[] { resources[i].getFullPath() }), // $NON-NLS-1$
            e));
        }
    }
    // for
    // If an exception occured during the visit, throw it here
    // Add the folders, followed by files!
    ISVNClientAdapter svnClient = root.getRepository().getSVNClient();
    monitor.beginTask(null, files.size() + folders.size());
    monitor.setTaskName("Adding...");
    svnClient.addNotifyListener(operationResourceCollector);
    OperationManager.getInstance().beginOperation(svnClient, new OperationProgressNotifyListener(monitor, svnClient));
    try {
        for (ISVNLocalResource localResource : folders) {
            try {
                svnClient.addDirectory(localResource.getIResource().getLocation().toFile(), false);
                localResource.refreshStatus();
            } catch (SVNClientException e) {
                throw SVNException.wrapException(e);
            }
        }
        for (ISVNLocalResource localResource : files) {
            try {
                svnClient.addFile(localResource.getIResource().getLocation().toFile());
                // If file has read-only attribute set, remove it
                ResourceAttributes attrs = localResource.getIResource().getResourceAttributes();
                if (localResource.getIResource().getType() == IResource.FILE && attrs.isReadOnly()) {
                    attrs.setReadOnly(false);
                    try {
                        localResource.getIResource().setResourceAttributes(attrs);
                    } catch (CoreException swallow) {
                    }
                }
            } catch (SVNClientException e) {
                throw SVNException.wrapException(e);
            }
        }
    } finally {
        Set<IResource> operationResources = operationResourceCollector.getOperationResources();
        OperationManager.getInstance().endOperation(true, operationResources);
        monitor.done();
        if (svnClient != null) {
            svnClient.removeNotifyListener(operationResourceCollector);
            root.getRepository().returnSVNClient(svnClient);
        }
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IResourceVisitor(org.eclipse.core.resources.IResourceVisitor) SVNException(org.tigris.subversion.subclipse.core.SVNException) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) ResourceAttributes(org.eclipse.core.resources.ResourceAttributes) CoreException(org.eclipse.core.runtime.CoreException) TreeSet(java.util.TreeSet) SVNClientException(org.tigris.subversion.svnclientadapter.SVNClientException) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) HashSet(java.util.HashSet) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter) OperationProgressNotifyListener(org.tigris.subversion.subclipse.core.client.OperationProgressNotifyListener)

Example 7 with ISVNLocalResource

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

the class LocalResource method getUrl.

/**
 * get the url of the resource in the repository The resource does not need to exist in repository
 *
 * @return the url or null if cannot get the url (when project is not managed)
 * @throws SVNException
 */
public SVNUrl getUrl() {
    try {
        LocalResourceStatus status = getStatusFromCache();
        if (status.isManaged()) {
            // if the resource is managed, get the url directly
            return status.getUrl();
        } else {
            // otherwise, get the url of the parent
            SVNUrl parentUrl = null;
            ISVNLocalResource parent = getParent();
            if (parent != null) {
                parentUrl = parent.getUrl();
            }
            if (parentUrl == null) {
                // we cannot find the url
                return null;
            }
            return parentUrl.appendPath(resource.getName());
        }
    } catch (SVNException e) {
        return null;
    }
}
Also used : SVNUrl(org.tigris.subversion.svnclientadapter.SVNUrl) SVNException(org.tigris.subversion.subclipse.core.SVNException) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource)

Example 8 with ISVNLocalResource

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

the class AliasManager method transformUrl.

public static String transformUrl(IResource resource, Alias alias) {
    String aliasUrl = alias.getUrl();
    String a;
    ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(resource);
    ISVNRepositoryLocation repository = svnResource.getRepository();
    if (svnResource.getUrl().toString().length() <= aliasUrl.length())
        a = "";
    else
        a = svnResource.getUrl().toString().substring(aliasUrl.length());
    String b = repository.getUrl().toString();
    String c;
    if (alias.getRelativePath() == null)
        c = "";
    else
        c = alias.getRelativePath();
    return b + c + a;
}
Also used : ISVNRepositoryLocation(org.tigris.subversion.subclipse.core.ISVNRepositoryLocation) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource)

Example 9 with ISVNLocalResource

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

the class AliasManager method getAliases.

private Alias[] getAliases(IResource resource, boolean checkParents) {
    ArrayList<Alias> aliases = new ArrayList<Alias>();
    if (resource != null) {
        ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(resource);
        try {
            if (svnResource.isManaged()) {
                ISVNProperty property = null;
                // $NON-NLS-1$
                property = svnResource.getSvnProperty("subclipse:tags");
                if (property != null && property.getValue() != null)
                    getAliases(aliases, property.getValue(), svnResource.getUrl().toString());
                if (checkParents) {
                    IResource checkResource = resource;
                    while (checkResource.getParent() != null) {
                        checkResource = checkResource.getParent();
                        Alias[] parentAliases = getAliases(checkResource, false);
                        for (Alias parentAlias : parentAliases) {
                            if (aliases.contains(parentAlias)) {
                                Alias checkAlias = (Alias) aliases.get(aliases.indexOf(parentAlias));
                                if (parentAlias.getRevision() < checkAlias.getRevision()) {
                                    aliases.remove(checkAlias);
                                    aliases.add(parentAlias);
                                }
                            } else
                                aliases.add(parentAlias);
                        }
                    }
                }
            }
        } catch (SVNException e) {
        }
    }
    Alias[] aliasArray = new Alias[aliases.size()];
    aliases.toArray(aliasArray);
    return aliasArray;
}
Also used : ArrayList(java.util.ArrayList) ISVNProperty(org.tigris.subversion.svnclientadapter.ISVNProperty) SVNException(org.tigris.subversion.subclipse.core.SVNException) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) IResource(org.eclipse.core.resources.IResource)

Example 10 with ISVNLocalResource

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

the class SVNHistoryPage method inputSet.

public boolean inputSet() {
    Object input = getInput();
    if (input instanceof IResource) {
        IResource res = (IResource) input;
        RepositoryProvider teamProvider = RepositoryProvider.getProvider(res.getProject(), SVNProviderPlugin.getTypeId());
        if (teamProvider != null) {
            try {
                ISVNLocalResource localResource = SVNWorkspaceRoot.getSVNResourceFor(res);
                LocalResourceStatus localResourceStatus = (localResource != null) ? localResource.getStatus() : null;
                if (localResource != null && localResourceStatus.isManaged() && (!localResourceStatus.isAdded() || localResourceStatus.isCopied())) {
                    this.resource = res;
                    this.remoteResource = localResource.getBaseResource();
                    this.projectProperties = ProjectProperties.getProjectProperties(res);
                    boolean includeBugs = projectProperties != null;
                    boolean includeTags = tagsPropertySet(res);
                    if (includeTags != this.includeTags || this.includeBugs != includeBugs) {
                        this.includeTags = includeTags;
                        this.includeBugs = includeBugs;
                        refreshTable();
                    }
                    this.historyTableProvider.setRemoteResource(this.remoteResource);
                    this.historyTableProvider.setProjectProperties(this.projectProperties);
                    if (historySearchViewerFilter != null) {
                        // HistorySearchViewerFilter[] filters = { historySearchViewerFilter };
                        // this.tableHistoryViewer.setFilters(filters);
                        this.tableHistoryViewer.resetFilters();
                        this.tableHistoryViewer.addFilter(historySearchViewerFilter);
                        historySearchDialog = new HistorySearchDialog(getSite().getShell(), remoteResource);
                        historySearchDialog.setSearchAll(false);
                        historySearchDialog.setStartRevision(historySearchViewerFilter.getStartRevision());
                        historySearchDialog.setEndRevision(historySearchViewerFilter.getEndRevision());
                        historySearchViewerFilter = null;
                        getClearSearchAction().setEnabled(true);
                    } else {
                        this.tableHistoryViewer.resetFilters();
                        getClearSearchAction().setEnabled(false);
                    }
                    this.tableHistoryViewer.setInput(this.remoteResource);
                    // setTitleToolTip(baseResource.getRepositoryRelativePath());
                    return true;
                }
            } catch (TeamException e) {
                SVNUIPlugin.openError(getSite().getShell(), null, null, e);
            }
        }
    } else if (input instanceof ISVNRemoteResource) {
        this.resource = null;
        this.remoteResource = (ISVNRemoteResource) input;
        boolean includeTags = tagsPropertySet(remoteResource);
        if (includeTags != this.includeTags) {
            this.includeTags = includeTags;
            refreshTable();
        }
        try {
            this.projectProperties = ProjectProperties.getProjectProperties(this.remoteResource);
        } catch (SVNException e) {
            if (!e.operationInterrupted()) {
                SVNUIPlugin.openError(getSite().getShell(), null, null, e);
            }
        }
        boolean includeBugs = projectProperties != null;
        if (includeTags != this.includeTags || this.includeBugs != includeBugs) {
            this.includeTags = includeTags;
            this.includeBugs = includeBugs;
            refreshTable();
        }
        this.historyTableProvider.setRemoteResource(this.remoteResource);
        this.historyTableProvider.setProjectProperties(this.projectProperties);
        if (historySearchViewerFilter != null) {
            // HistorySearchViewerFilter[] filters = { historySearchViewerFilter };
            // this.tableHistoryViewer.setFilters(filters);
            this.tableHistoryViewer.resetFilters();
            this.tableHistoryViewer.addFilter(historySearchViewerFilter);
            historySearchDialog = new HistorySearchDialog(getSite().getShell(), remoteResource);
            historySearchDialog.setSearchAll(false);
            historySearchDialog.setStartRevision(historySearchViewerFilter.getStartRevision());
            historySearchDialog.setEndRevision(historySearchViewerFilter.getEndRevision());
            historySearchViewerFilter = null;
            getClearSearchAction().setEnabled(true);
        } else {
            this.tableHistoryViewer.resetFilters();
            getClearSearchAction().setEnabled(false);
        }
        this.tableHistoryViewer.setInput(this.remoteResource);
        // setTitleToolTip(remoteResource.getRepositoryRelativePath());
        return true;
    }
    return false;
}
Also used : TeamException(org.eclipse.team.core.TeamException) ISVNRemoteResource(org.tigris.subversion.subclipse.core.ISVNRemoteResource) SVNException(org.tigris.subversion.subclipse.core.SVNException) RepositoryProvider(org.eclipse.team.core.RepositoryProvider) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) LocalResourceStatus(org.tigris.subversion.subclipse.core.resources.LocalResourceStatus) HistorySearchDialog(org.tigris.subversion.subclipse.ui.dialogs.HistorySearchDialog) 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