SVNKIT操作SVN版本库的完整例子

Model:

package com.wjy.model;

public class RepositoryInfo {
    public static String storeUrl="http://10.13.30.22/svn/SVNRepository/Checked/";
    public static String buffUrl="http://10.13.30.22/svn/SVNRepository/UnChecked/";
    public static String sysInfoUrl="http://10.13.30.22/svn/SVNRepository/Log/";
}

Option:

package com.wjy.modeloption;

import java.awt.List;
import java.io.File;

import org.tmatesoft.svn.core.SVNDepth;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl;
import org.tmatesoft.svn.core.internal.wc.DefaultSVNOptions;
import org.tmatesoft.svn.core.internal.wc17.db.SVNWCDb.ReposInfo;
import org.tmatesoft.svn.core.wc.ISVNOptions;
import org.tmatesoft.svn.core.wc.SVNClientManager;
import org.tmatesoft.svn.core.wc.SVNCommitClient;
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.SVNUpdateClient;
import org.tmatesoft.svn.core.wc.SVNWCUtil;

import com.wjy.model.RepositoryInfo;

public class ModelOption {
    private SVNClientManager ourClientManager;
    private SVNURL repositoryOptUrl;
    private String userName;
    private String passwd;
    public ModelOption(String userName,String passwd){
        this.userName=userName;
        this.passwd=passwd;
    }
    private void setUpSVNClient(String userName,String passwd){
        SVNRepositoryFactoryImpl.setup();
        ISVNOptions options = SVNWCUtil.createDefaultOptions(true);
        ourClientManager = SVNClientManager.newInstance(
                (DefaultSVNOptions) options, userName, passwd);
    }
    /**
     * 上传模型
     * @param dirPath
     */
    public void uploadMoel(String dirPath,String modelName){
        setUpSVNClient(userName,passwd);
        File impDir = new File(dirPath);
        SVNCommitClient commitClient = ourClientManager.getCommitClient();
        commitClient.setIgnoreExternals(false);
        try {
            repositoryOptUrl=SVNURL.parseURIEncoded(RepositoryInfo.buffUrl+modelName);
            commitClient.doImport(impDir,
                    repositoryOptUrl, "import operation!", null, true, true,
                    SVNDepth.INFINITY);
        } catch (SVNException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    
    /**
     * 下载模型
     */
    public void downloadModel(String downloadModelName,String dirPath){
        setUpSVNClient(userName,passwd);
        File outDir=new File(dirPath+"/"+downloadModelName);
        //outDir.mkdirs();//创建目录
        SVNUpdateClient updateClient=ourClientManager.getUpdateClient();
        updateClient.setIgnoreExternals(false);
        
        try {
            repositoryOptUrl=SVNURL.parseURIEncoded(RepositoryInfo.storeUrl+downloadModelName);
            updateClient.doExport(repositoryOptUrl, outDir, SVNRevision.HEAD, SVNRevision.HEAD, "downloadModel",true,true);
        } catch (SVNException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    
    /**
     * 删除模型
     */
    public void deleteModel(String deleteModelName){
        setUpSVNClient(userName,passwd);
        SVNCommitClient commitClient=ourClientManager.getCommitClient();
        commitClient.setIgnoreExternals(false);
        
        try {
            repositoryOptUrl=SVNURL.parseURIEncoded(RepositoryInfo.storeUrl+deleteModelName);
            SVNURL deleteUrls[]=new SVNURL[1];
            deleteUrls[0]=repositoryOptUrl;
            commitClient.doDelete(deleteUrls, "delete model");
        } catch (SVNException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
    }
    
    /**
     * 移动模型
     */
    public void moveModel(String modelName){
        setUpSVNClient(userName,passwd);
        SVNCopyClient copyClient=ourClientManager.getCopyClient();
        copyClient.setIgnoreExternals(false);
        
        try {
            repositoryOptUrl=SVNURL.parseURIEncoded(RepositoryInfo.buffUrl+modelName);
            SVNURL destUrl=SVNURL.parseURIEncoded(RepositoryInfo.storeUrl+modelName);
            SVNCopySource[] copySources = new SVNCopySource[1];
            copySources[0] = new SVNCopySource(SVNRevision.HEAD, SVNRevision.HEAD, repositoryOptUrl);
            
            copyClient.doCopy(copySources, destUrl, true, false, false, "move", null);
        } catch (SVNException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
    }
}

测试:

package com.wjy.test;

import com.wjy.modeloption.ModelOption;

public class MainTest {
    public static void main(String args[]){
        ModelOption modelOption=new ModelOption("harry", "harryssecret");
        
//        modelOption.uploadMoel("E://LoveEyes","ModelSB");
        
//        modelOption.moveModel("ModelSB");
    
//        modelOption.downloadModel("ModelSB","E://download/");
        
//        modelOption.deleteModel("ModelSB");
    }
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值