JAVA集成SVN,查看应用更新日志

来源:互联网 发布:数据库开发前景知乎 编辑:程序博客网 时间:2024/06/05 15:37

  1. action部分

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
public String getSVNLogs() {
        // 版本库初始化
        DAVRepositoryFactory.setup();
 
        // 资源库相关登录配置信息
        String url = "http://172.16.3.68:7777/svn/xxxxx";
        String username = "xxxx";
        String password = "xxxx";
        long startRevision = 0;// 最初版本
        long endRevision = -1;// 最近版本
        long lastRevision = 0;
        // 资源库
        SVNRepository repository = null;
        List<SvnLogModel> svns = new ArrayList<SvnLogModel>();
 
        try {
 
            // 建立一个新的资源库
            repository = DAVRepositoryFactory.create(SVNURL.parseURIEncoded(url));
            // 登录确认信息
            ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(username,
                    password);
            repository.setAuthenticationManager(authManager);
            lastRevision = repository.getLatestRevision();
            // 存放结果
            final Collection logEntries = new ArrayList<SVNLogEntry>();
            startRevision = lastRevision - ((page) * rows) + 1;
            if (startRevision < 0) {
                startRevision = 0;
            }
            endRevision = lastRevision - ((page - 1) * rows);
            repository.log(new String[] { "/" }, logEntries, startRevision, endRevision, truetrue);
            // 遍历
 
            for (Iterator entries = logEntries.iterator(); entries.hasNext();) {
                SVNLogEntry logEntry = (SVNLogEntry) entries.next();
                SvnLogModel svn = new SvnLogModel();
                svn.setMessage(StringUtil.string2Json(logEntry.getMessage()));
                svn.setAuthor(logEntry.getAuthor());
                svn.setDate(logEntry.getDate());
                svn.setRevision(logEntry.getRevision());
                String loge = "";
                if (logEntry.getChangedPaths().size() > 0) {
                    Set changedPathsSet = logEntry.getChangedPaths().keySet();
                    for (Iterator changedPaths = changedPathsSet.iterator(); changedPaths.hasNext();) {
                        SVNLogEntryPath entryPath = logEntry.getChangedPaths().get(changedPaths.next());
                        char entrytype = entryPath.getType();
                        String typeCN = "";
                        if ("M".equals(String.valueOf(entrytype))) {
                            typeCN = "修改";
                        else if ("A".equals(String.valueOf(entrytype))) {
                            typeCN = "新增";
                        else if ("D".equals(String.valueOf(entrytype))) {
                            typeCN = "删除";
                        }
 
                        loge += " "
                                + typeCN
                                " "
                                + entryPath.getPath()
                                + ((entryPath.getCopyPath() != null) ? " (from " + entryPath.getCopyPath()
                                        " revision " + entryPath.getCopyRevision() + ")" "") + "\n";
                    }
                }
                svn.setLogEntry(StringUtil.string2Json(loge));
                svns.add(svn);
            }
        catch (Exception ex) {
            System.out.println(ex.toString());
        }
        Collections.reverse(svns);
        GridModel gridModel = new GridModel();
        gridModel.setRows(svns);
        gridModel.setTotal(lastRevision);
        OutputJson(gridModel);
 
        OutputJson(svns, Constants.TEXT_TYPE_JSON);
        return null;
    }

2.jsp部分

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
....
<script type="text/javascript">
    $(function() {
        $('#dg').datagrid({
            rownumbers : true,
            fit : true,
            pagination : true,
            singleSelect : true,
            border : false,
            pageSize : 50,
            pageList : [20,50,100,500,1000],
            nowrap : false,
            url : "svn/svnAction!getSVNLogs.action",
            columns : [ [ {
                field : 'revision',
                title : '修订版本',
                halign: 'center',
                align : 'right',
                width : 60
            }, {
                field : 'author',
                title : '提交者',
                halign: 'center',
                width : 60
            }, {
                field : 'date',
                title : '日期',
                halign: 'center',
                width : 150,
            }, {
                field : 'message',
                title : '注释信息',
                halign: 'center',
                width : 350,
                formatter : function(value,rowData) {   
                    if(value != undefined ) {
                        return value.replaceAll("\n", "<br />");
                    }
                }
            }   ] ],
            onLoadSuccess : function () {
                  $(this).datagrid("fixRownumber");
              },
              onClickRow: function (index, row) {
                  value=row.logEntry;
                  if(value != undefined ) {
                    value=value.replaceAll("\n", "<br />")
 
                     $("#logfile").html(value);
                }
              }
        });
    });
     
      String.prototype.replaceAll = function(reallyDo, replaceWith, ignoreCase) { 
          if (!RegExp.prototype.isPrototypeOf(reallyDo)) { 
        return this.replace(new RegExp(reallyDo, (ignoreCase ? "gi": "g")), replaceWith); 
        } else { 
        return this.replace(reallyDo, replaceWith); 
        
        
</script>
</head>
<body>
    <div class="easyui-layout" data-options="fit:true">
        <div data-options="region:'north'"
            style="height:50px;border-top-style: none;border-left-style: none;border-right-style: none;">
 
            <div class="well-small" style="margin-left: 5px;margin-top: 5px">
                <span class="badge">提示</span>SVN日志管理集成了SVN,通过SVNKit查看系统开发版本的进度。
            </div>
        </div>
        <div data-options="region:'west',split: true," style="width:700px">
                 <table id="dg" title="SVN更新日志"></table>
          </div>  
        <div data-options="region:'center',split: true," title="受影响的文件、目录">
            <table><tr><td  id="logfile">
             
            </td></tr></table>
        </div>
         
    </div>


3.效果截图


0 0
原创粉丝点击