SVN模型仓库中的资源从一个地方移动到另一个地方的办法(很久才解决)

弄了很久,想使用domove这个操作,但是都失败了。最后给svnkit的邮箱写了封邮件,他们告诉我这样做就成功了。实际上是使用docopy这个函数实现了move操作。
package com.repositoryclient.svnoptions;

import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;
import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory;
import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl;
import org.tmatesoft.svn.core.internal.wc.DefaultSVNOptions;
import org.tmatesoft.svn.core.io.SVNRepository;
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
import org.tmatesoft.svn.core.wc.ISVNOptions;
import org.tmatesoft.svn.core.wc.SVNClientManager;
import org.tmatesoft.svn.core.wc.SVNCopyClient;
import org.tmatesoft.svn.core.wc.SVNCopySource;
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.wc.SVNWCUtil;

public class StoreManagerCheckResourceOption {
    
    private SVNRepository repositoryTrgt;
    private SVNRepository repositorySrc;

    public boolean doMove(String userName,String passwd,String sourceDirUrl,String targetDirUrl){
        SVNClientManager ourClientManager;
        // 初始化支持svn://协议的库
        SVNRepositoryFactoryImpl.setup();
        DAVRepositoryFactory.setup();
        FSRepositoryFactory.setup();
        SVNURL repositorySrcUrl = null;
        SVNURL repositoryTrgtUrl = null;
        
        try {
            SVNWCUtil.createDefaultAuthenticationManager(userName,passwd);
            repositorySrcUrl = SVNURL.parseURIEncoded(sourceDirUrl);
            repositoryTrgtUrl = SVNURL.parseURIEncoded(targetDirUrl);
            repositorySrc = SVNRepositoryFactory.create(repositorySrcUrl);
            repositoryTrgt = SVNRepositoryFactory.create(repositoryTrgtUrl);
            ISVNAuthenticationManager authManager =SVNWCUtil.createDefaultAuthenticationManager(userName,passwd);
            repositorySrc.setAuthenticationManager(authManager);
            repositoryTrgt.setAuthenticationManager(authManager);
            ISVNOptions options = SVNWCUtil.createDefaultOptions(false);
            // 实例化客户端管理类
            ourClientManager = SVNClientManager.newInstance(
                    (DefaultSVNOptions) options, userName, passwd);
            SVNCopyClient copyClient = ourClientManager.getCopyClient();
            SVNCopySource[] copySources = new SVNCopySource[1];
            copySources[0] = new SVNCopySource(SVNRevision.HEAD, SVNRevision.HEAD, repositorySrcUrl);
            
//            SVNDirEntry entry = (SVNDirEntry) srcRepository.getDir(sourceDirUrl, -1, null, (Collection) null);
//            if (entry.getKind() == SVNNodeKind.DIR) {
//                copyClient.doCopy(copySources, repositoryTrgtUrl, true, false, false, "move", null);
//            } else {
//                copyClient.doCopy(copySources, repositoryTrgtUrl, true, false, true, "move", null);
//            }
            copyClient.doCopy(copySources, repositoryTrgtUrl, true, false, false, "move", null);
//            SVNWCClient client = new SVNWCClient(authenticationManager, (ISVNOptions)(SVNWCUtil.createDefaultOptions(true)));
//            SVNCommitInfo svnInfo = ourClientManager.getLogClient().
            
            
            // 要把此目录的内容导入到版本库
//            File sourceDir = new File(sourceDirUrl);

//            File targetDir = new File("relative/" + targetDirUrl);
//            targetDir = targetDir.getAbsoluteFile();
//            sourceDir.setReadable(true);
//            targetDir.setWritable(true);
            // 执行导入操作
//            SVNMoveClient svnMoveClient = ourClientManager.getMoveClient();
//            SVNUpdateClient svnUpdateClient = new SVNUpdateClient(authenticationManager, options);
//            svnMoveClient.doVirtualCopy(sourceDir, targetDir, true);
//            svnMoveClient.doMove(sourceDir, targetDir);
//            svnUpdateClient.doRelocate(sourceDir, repositorySrcUrl, repositoryTrgtUrl, true);
            return true;
        } catch (SVNException e) {
            // TODO: handle exception
            e.printStackTrace();
            return false;
        }
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值