java实现SVN检出功能源码

/**
* 功能说明:SVN检出功能工具类
*
* @date 2016-3-29
* @author malin
*
*/
public class DoCheckOutUtil {

//声明SVN客户端管理类   
private static SVNClientManager ourClientManager;

public static void main(String[] args) throws Exception {

    //初始化支持svn://协议的库。 必须先执行此操作。         
    Properties properties = System.getProperties();  
    properties.setProperty("svnkit.http.methods", "Basic,Digest,NTLM"); 
    DAVRepositoryFactory.setup();

    //相关变量赋值
    SVNURL repositoryURL = null;
    try {
        repositoryURL = SVNURL.parseURIEncoded("SVN检出地址initsql/base/lib");
    } catch (SVNException e) {
        //
    }
    String name = "用户名";
    String password = "登录密码";       
    ISVNOptions options = SVNWCUtil.createDefaultOptions(true);

    //实例化客户端管理类
    ourClientManager = SVNClientManager.newInstance(
            (DefaultSVNOptions) options, name, password);

    //要把版本库的内容check out到的目录
    File wcDir = new File("e:/svntest/wc");

    //通过客户端管理类获得updateClient类的实例。
    SVNUpdateClient updateClient = ourClientManager.getUpdateClient();
    /*
     * sets externals not to be ignored during the checkout
     */
    updateClient.setIgnoreExternals(false);

    //执行check out 操作,返回工作副本的版本号。
    long workingVersion= updateClient
            .doCheckout(repositoryURL, wcDir, SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.INFINITY,false);

    System.out.println("把版本:"+workingVersion+" check out 到目录:"+wcDir+"中。");

}



SVN的API查询官网在http://svnkit.com/javadoc/overview-summary.html

目前是1。8

=====================
后面的处理:/**
* 设置环境
*/
public static void setupLibrary() {
DAVRepositoryFactory.setup();
SVNRepositoryFactoryImpl.setup();
FSRepositoryFactory.setup();
try {
repository = SVNRepositoryFactory.create(SVNURL
.parseURIEncoded(url));
} catch (SVNException e) {
System.out.println(e.getErrorMessage());
}
// 身份验证
ISVNAuthenticationManager authManager = SVNWCUtil
.createDefaultAuthenticationManager(name, password);
repository.setAuthenticationManager(authManager);
}
/**
* 过滤条件
* @throws Exception
*/
public static void filterCommitHistory() throws Exception {
final Set set=new HashSet();

    long endRevision = -1;// 表示最后一个版本
    //final List<String> history = new ArrayList<String>();
    // String[] 为过滤的文件路径前缀,为空表示不进行过滤
    // repository.l
    repository.log(new String[] { "" }, startRevision, endRevision, true,
            true, new ISVNLogEntryHandler() {
                @Override
                public void handleLogEntry(SVNLogEntry svnlogentry)
                        throws SVNException {
                    // 依据提交时间进行过滤
                    //if (svnlogentry.getDate().after(begin)&& svnlogentry.getDate().before(end)) {
                        // 依据提交人过滤
                        if (!"".equals(author)) {
                            if (author.equals(svnlogentry.getAuthor())) {
                                fillResult(svnlogentry);
                            }
                        } else {
                            fillResult(svnlogentry);
                        }
                    //}
                }
                public void fillResult(SVNLogEntry svnlogentry) {
                    // getChangedPaths为提交的历史记录MAP key为文件名,value为文件详情
                    Iterator<?> it = svnlogentry.getChangedPaths().keySet()
                            .iterator();
                    if (it.hasNext()) {
                        SVNLogEntryPath entryPath = (SVNLogEntryPath) svnlogentry
                                .getChangedPaths().get(it.next());
                        String str=entryPath.getPath().substring(6);//路径
                        if("D".equals(String.valueOf(entryPath.getType()))){
                            str=str+" 删除";
                        }
                        if(!set.contains(str)&&svnlogentry.getMessage().contains(ModifedNum)){
                            set.add(str);
                            System.out.println(str);
                        }
                    }
                }
            });

}
public static void main(String[] args) {
    System.setProperty("svnkit.http.methods", "Basic,Digest,NTLM");
    setupLibrary();
    try {
        filterCommitHistory();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

}

svnkit.jar 这个lib

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

苦思冥想行则将至

穷,有钱的大爷上个两分钱吧

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值