JAVA統合SVN、アプリケーション更新ログの表示


  • action部
  • 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, true, true);
    			//   
    
    			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() + ")" : "") + "
    "; } } 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部
    ....
    <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("
    ", "<br />"); } } }   ] ], onLoadSuccess : function () {            $(this).datagrid("fixRownumber");            },            onClickRow: function (index, row) {            value=row.logEntry;            if(value != undefined ) { value=value.replaceAll("
    ", "<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.効果スクリーンショット
    JAVA集成SVN,查看应用更新日志_第1张图片