Java统计svn管理的代码

package util;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;

import org.tmatesoft.svn.core.ISVNLogEntryHandler;
import org.tmatesoft.svn.core.SVNDirEntry;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNLogEntry;
import org.tmatesoft.svn.core.SVNLogEntryPath;
import org.tmatesoft.svn.core.SVNNodeKind;
import org.tmatesoft.svn.core.SVNProperties;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
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.SVNDiffClient;
import org.tmatesoft.svn.core.wc.SVNLogClient;
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.wc.SVNWCUtil;

public class SvnStatistical {
    //svn账号
    private static String userName = "";
    //svn密码
    private static String password = "";
    //svn地址,注意地址以svn开始和以https开始的调用的方法是不一样的,SVNRepository jar里会自动区分
    private static String urlString = "";
    //临时文件存放地址
    private static String tempDir = "E:\\demo\\";
    //提交人
    private static String submitAuth = "";
    private static DefaultSVNOptions options = SVNWCUtil.createDefaultOptions(true);
    //临时文件名
    private static Random random = new Random();
    private static SVNRepository repos;
    private static ISVNAuthenticationManager authManager;
    //新增文件数量
    private static int addFileNum = 0;
    //修改文件数量
    private static int updateFileNum = 0;
    
    public static void main(String[] args) throws ParseException, SVNException {
        authManager = SVNWCUtil.createDefaultAuthenticationManager(new File(tempDir+"/auth"), userName, password.toCharArray());
        options.setDiffCommand("-x -w");
        repos = SVNRepositoryFactory.create(SVNURL
                 .parseURIEncoded(urlString));
        repos.setAuthenticationManager(authManager);
        Calendar calendar = Calendar.getInstance();

        if(calendar.get(Calendar.DAY_OF_WEEK)==2) {//如果当天是周一则需要统计周五至周天的数据
            calendar.add(Calendar.DAY_OF_MONTH, -3);
        } else {
            calendar.add(Calendar.DAY_OF_MONTH, -1);
        }
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        //统计昨天代码提交情况
        Date after = format.parse(format.format(new Date()));
        Date before = format.parse(format.format(calendar.getTime()));
        try {
            int sum = staticticsCodeAddByTime(before, after);
            submitAuth = submitAuth.substring(1,submitAuth.length());
            int total = updateFileNum+addFileNum;
            System.out.println("代码提交明细\n"+format.format(before)+" 00:00:00 to "+format.format(before)+" 23:59:59"
                                + "\n提交行数:sum="+sum+""
                                + "\n涉及文件"+total+"个,其中修改文件"+updateFileNum+"个,新增文件"+addFileNum+"个"
                                + "\n提交人:"+submitAuth);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    //获取(st,et)时间内的提交记录
    public static SVNLogEntry[] getLogByTime(Date st, Date et) throws SVNException{
        long startRevision

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用 SVNKit 可以在 Java 中操作 SVN 代码仓库,包括拉取代码、提交代码、查看日志等等。下面是一个简单的示例代码,演示如何使用 SVNKit 拉取 SVN 代码: ```java import org.tmatesoft.svn.core.*; import org.tmatesoft.svn.core.auth.*; import org.tmatesoft.svn.core.wc.*; import java.io.File; public class SVNTest { public static void main(String[] args) { // SVN 用户名和密码 String username = "your_username"; String password = "your_password"; // SVN 代码仓库地址 String svnUrl = "svn://svnserver/svn/repo"; // 本地代码保存路径 String localPath = "/path/to/local/folder"; // 初始化 SVN 客户端管理SVNClientManager clientManager = SVNClientManager.newInstance(); // 设置 SVN 用户名和密码 ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(username, password); clientManager.setAuthenticationManager(authManager); // 创建本地代码保存路径 File localFolder = new File(localPath); if (!localFolder.exists()) { localFolder.mkdirs(); } try { // 拉取代码到本地 SVNURL svnUrlObj = SVNURL.parseURIDecoded(svnUrl); SVNUpdateClient updateClient = clientManager.getUpdateClient(); updateClient.setIgnoreExternals(false); updateClient.doCheckout(svnUrlObj, localFolder, SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.INFINITY, true); System.out.println("SVN code checkout complete."); } catch (SVNException e) { e.printStackTrace(); } } } ``` 需要注意的是,使用 SVNKit 操作 SVN 代码仓库需要导入相应的依赖包,具体可以参考 SVNKit 的官方文档。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值