Search in sources :

Example 1 with BranchTagCommand

use of org.tigris.subversion.subclipse.core.commands.BranchTagCommand in project subclipse by subclipse.

the class BranchTagOperation method execute.

protected void execute(SVNTeamProvider provider, IResource[] resources, IProgressMonitor monitor) throws SVNException, InterruptedException {
    if (branchCreated)
        return;
    branchCreated = true;
    monitor.beginTask(null, 100);
    try {
        BranchTagCommand command = new BranchTagCommand(provider.getSVNWorkspaceRoot(), getResources(), sourceUrls, destinationUrl, message, createOnServer, revision);
        command.setMakeParents(makeParents);
        command.setMultipleTransactions(multipleTransactions);
        command.run(Policy.subMonitorFor(monitor, 1000));
        if (svnExternals != null) {
            List<SVNUrl> copyToUrls = new ArrayList<SVNUrl>();
            List<String> fileList = new ArrayList<String>();
            Map<String, String> copyToMap = new HashMap<String, String>();
            for (SVNExternal svnExternal : svnExternals) {
                if (svnExternal.isSelected()) {
                    if (!fileList.contains(svnExternal.getFile().getAbsolutePath())) {
                        fileList.add(svnExternal.getFile().getAbsolutePath());
                        IResource[] localResources = SVNWorkspaceRoot.getResourcesFor(new Path(svnExternal.getFile().getPath()));
                        ISVNRemoteResource remoteResource = SVNWorkspaceRoot.getBaseResourceFor(localResources[0]);
                        for (SVNUrl sourceUrl : sourceUrls) {
                            if (remoteResource.getUrl().toString().startsWith(sourceUrl.toString())) {
                                SVNUrl copyToUrl = null;
                                SVNUrl destinationUrl = command.getDestinationUrl(sourceUrl.toString());
                                if (remoteResource.getUrl().toString().equals(sourceUrl.toString())) {
                                    copyToUrl = destinationUrl;
                                } else {
                                    try {
                                        copyToUrl = new SVNUrl(destinationUrl + remoteResource.getUrl().toString().substring(sourceUrl.toString().length()));
                                    } catch (MalformedURLException e) {
                                    }
                                }
                                if (copyToUrl != null) {
                                    copyToUrls.add(copyToUrl);
                                    copyToMap.put(copyToUrl.toString(), svnExternal.getFile().getAbsolutePath());
                                }
                                break;
                            }
                        }
                    }
                }
            }
            if (copyToUrls.size() > 0) {
                ISVNClientAdapter svnClient = null;
                try {
                    svnClient = provider.getSVNWorkspaceRoot().getRepository().getSVNClient();
                    for (SVNUrl copyToUrl : copyToUrls) {
                        String updatedProperty = getUpdatedSvnExternalsProperty(copyToUrl, copyToMap);
                        ISVNInfo info = svnClient.getInfo(copyToUrl);
                        svnClient.propertySet(copyToUrl, info.getRevision(), "svn:externals", updatedProperty, // $NON-NLS-1$
                        Policy.bind("BranchTagOperation.3"));
                    }
                } catch (Exception e) {
                    throw SVNException.wrapException(e);
                } finally {
                    provider.getSVNWorkspaceRoot().getRepository().returnSVNClient(svnClient);
                }
            }
        }
        SVNUIPlugin.getPlugin().getRepositoryManager().resourceCreated(null, null);
        if (newAlias != null)
            updateBranchTagProperty(resources[0]);
        if (switchAfterTagBranch) {
            for (int i = 0; i < sourceUrls.length; i++) {
                SVNUrl switchDestinationUrl = command.getDestinationUrl(sourceUrls[i].toString());
                // the copy command's destination URL can either be a path to an existing directory
                // or a path to a new directory. In the former case the last path segment of the
                // source path is automatically created at the destination
                GetRemoteResourceCommand getRemoteResourceCommand = new GetRemoteResourceCommand(provider.getSVNWorkspaceRoot().getRepository(), switchDestinationUrl, SVNRevision.HEAD);
                try {
                    getRemoteResourceCommand.run(null);
                } catch (SVNException e) {
                    if (e.getStatus().getCode() == TeamException.UNABLE) {
                        switchDestinationUrl = destinationUrl;
                    } else {
                        throw e;
                    }
                }
                resources = getResources();
                SwitchToUrlCommand switchToUrlCommand = new SwitchToUrlCommand(provider.getSVNWorkspaceRoot(), resources[i], switchDestinationUrl, SVNRevision.HEAD);
                switchToUrlCommand.run(Policy.subMonitorFor(monitor, 100));
            }
        }
    } catch (SVNException e) {
        if (e.operationInterrupted()) {
            showCancelledMessage();
        } else {
            collectStatus(e.getStatus());
        }
    } finally {
        monitor.done();
    }
}
Also used : Path(org.eclipse.core.runtime.Path) MalformedURLException(java.net.MalformedURLException) SwitchToUrlCommand(org.tigris.subversion.subclipse.core.commands.SwitchToUrlCommand) HashMap(java.util.HashMap) SVNUrl(org.tigris.subversion.svnclientadapter.SVNUrl) ArrayList(java.util.ArrayList) SVNExternal(org.tigris.subversion.subclipse.core.SVNExternal) ISVNRemoteResource(org.tigris.subversion.subclipse.core.ISVNRemoteResource) SVNException(org.tigris.subversion.subclipse.core.SVNException) SVNException(org.tigris.subversion.subclipse.core.SVNException) MalformedURLException(java.net.MalformedURLException) TeamException(org.eclipse.team.core.TeamException) BranchTagCommand(org.tigris.subversion.subclipse.core.commands.BranchTagCommand) GetRemoteResourceCommand(org.tigris.subversion.subclipse.core.commands.GetRemoteResourceCommand) ISVNInfo(org.tigris.subversion.svnclientadapter.ISVNInfo) IResource(org.eclipse.core.resources.IResource) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter)

Example 2 with BranchTagCommand

use of org.tigris.subversion.subclipse.core.commands.BranchTagCommand in project subclipse by subclipse.

the class RepositoryBranchTagOperation method execute.

protected void execute(IProgressMonitor monitor) throws SVNException, InterruptedException {
    monitor.beginTask(null, 100);
    try {
        BranchTagCommand command = new BranchTagCommand(svnClient, null, sourceUrls, destinationUrl, message, true, revision);
        command.setMakeParents(makeParents);
        command.setMultipleTransactions(multipleTransactions);
        command.run(Policy.subMonitorFor(monitor, 1000));
        SVNUIPlugin.getPlugin().getRepositoryManager().resourceCreated(null, null);
    } catch (SVNException e) {
        if (e.operationInterrupted()) {
            showCancelledMessage();
        } else {
            collectStatus(e.getStatus());
        }
    } finally {
        monitor.done();
    }
}
Also used : BranchTagCommand(org.tigris.subversion.subclipse.core.commands.BranchTagCommand) SVNException(org.tigris.subversion.subclipse.core.SVNException)

Aggregations

SVNException (org.tigris.subversion.subclipse.core.SVNException)2 BranchTagCommand (org.tigris.subversion.subclipse.core.commands.BranchTagCommand)2 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 IResource (org.eclipse.core.resources.IResource)1 Path (org.eclipse.core.runtime.Path)1 TeamException (org.eclipse.team.core.TeamException)1 ISVNRemoteResource (org.tigris.subversion.subclipse.core.ISVNRemoteResource)1 SVNExternal (org.tigris.subversion.subclipse.core.SVNExternal)1 GetRemoteResourceCommand (org.tigris.subversion.subclipse.core.commands.GetRemoteResourceCommand)1 SwitchToUrlCommand (org.tigris.subversion.subclipse.core.commands.SwitchToUrlCommand)1 ISVNClientAdapter (org.tigris.subversion.svnclientadapter.ISVNClientAdapter)1 ISVNInfo (org.tigris.subversion.svnclientadapter.ISVNInfo)1 SVNUrl (org.tigris.subversion.svnclientadapter.SVNUrl)1