java程式碼獲取svn提交版本號、提交人、提交時間、提交型別、影響程式碼行數
公司最近做大螢幕資料展示,需要獲取svn/git、jira、jenkins、sonar上的資料。本人除了git外,其它工具都不熟,索性網路時代救了我,本人也是查了很多資料來實現自己的專案需求功能。
java獲取svn程式碼,是看到了scdn上的一位大神傑作來修改的,由於本人的粗心,那位大神的連結地址一時間找不到了。以後看到了一定補上鍊接,在這裡對大神說聲抱歉,以下奉上本人修改後的程式碼。
1.獲取svn資料所依賴的jar
<!--svn獲取資料需要jar--> <!-- https://mvnrepository.com/artifact/org.tmatesoft.svnkit/svnkit --> <dependency> <groupId>org.tmatesoft.svnkit</groupId> <artifactId>svnkit</artifactId> <version>1.9.3</version> </dependency> <!--svn獲取需要jar完畢-->
2.存入後臺版本號、當前版本的總影響行數
package com.zkr.cxhjcxt.dto; import com.zkr.cxhjcxt.model.SvnDataAuxiliaryTwo; import lombok.Data; import java.util.ArrayList; import java.util.List; /** * Created by youzongxu on 2018/9/7. */ @Data public class SvnDto { private int sum; private List<SvnDataAuxiliaryTwo> lists = new ArrayList<>(); private long version; }
3.存入後臺版本號、影響行數、檔案路徑、檔案型別
package com.zkr.cxhjcxt.model; import lombok.Data; /** * Created by youzongxu on 2018/9/10. */ @Data public class SvnDataAuxiliaryTwo extends BaseEntity<Long>{ private static final long serialVersionUID = -124865218511677256L; private Long svnReversion; private Integer svnAddlines; private String svnFilepath; private String svnChangetype; }
4.存入後臺提交人、版本號、svn資訊、提交svn時間
package com.zkr.cxhjcxt.model;
import lombok.Data;
import java.util.Date;
/**
* Created by youzongxu on 2018/9/7.
*/
@Data
public class SvnData extends BaseEntity<Long>{
private static final long serialVersionUID = 6041141704397137128L;
private String author;
private Long revision;
private String svnMessage;
private Date svnTime;
}
5.後臺存入資料、藉助的都是下面svn工具類中的方法,這裡面的有些資料需要改成自己所用到的
package com.zkr.cxhjcxt.utils;
import com.google.common.collect.Lists;
import com.zkr.cxhjcxt.constants.SvnTimeConstants;
import com.zkr.cxhjcxt.dao.DataConfigurationDao;
import com.zkr.cxhjcxt.dict.DictConstants;
import com.zkr.cxhjcxt.dto.SvnDto;
import com.zkr.cxhjcxt.model.DataConfiguration;
import com.zkr.cxhjcxt.model.SvnDataAuxiliaryOne;
import com.zkr.cxhjcxt.model.SvnDataAuxiliaryThree;
import com.zkr.cxhjcxt.service.SvnDataService;
import com.zkr.cxhjcxt.service.SysLogService;
import com.zkr.cxhjcxt.timedutils.svnutil;
import lombok.extern.slf4j.Slf4j;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
*
* @author youzongxu
* @date 2018/9/12
*/
@Slf4j
public class SvnUtil {
public void SvnUtil(){
//獲取1:請求路徑2:賬號3:密碼
DataConfigurationDao dataConfigurationDao = SpringUtil.getBean(DataConfigurationDao.class);
List<DataConfiguration> svnget = dataConfigurationDao.dataGetSvn(DictConstants.SVN_DICT);
if(null != svnget){
Date now = new Date();
SvnDataService svnDataService = SpringUtil.getBean(SvnDataService.class);
List<SvnDto> lists = Lists.newArrayList();
int today = 0;
int sevenToday = 0;
int thirtyToday = 0;
int nows = 0;
int ones = 0;
int twos = 0;
int threes = 0;
int fours = 0;
int fives = 0;
int sixs = 0;
int sevens = 0;
for (DataConfiguration ls:svnget) {
Date daysago = new Date(now.getTime()-convertDaysToMilliseconds(Integer.parseInt(ls.getTimeFrame())));
//啟動
svnutil svn = new svnutil(ls.getDataUsername(),ls.getDataPassword(),ls.getDataUrl());
try {
//主表資料儲存
List<SvnDto> svnDtos = svn.staticticsCodeAddByTime(now, fm(daysago));
lists.addAll(svnDtos);
//輔表數儲存
Map<String, Object> map = svn.commitCount();
today += Integer.parseInt(map.get("today").toString());
sevenToday += Integer.parseInt(map.get("sevenToday").toString());
thirtyToday += Integer.parseInt(map.get("thirtyToday").toString());
Map<String, Object> map1 = svn.dmCount();
nows += Integer.parseInt(map1.get("now").toString());
ones += Integer.parseInt(map1.get("one").toString());
twos += Integer.parseInt(map1.get("two").toString());
threes += Integer.parseInt(map1.get("three").toString());
fours += Integer.parseInt(map1.get("four").toString());
fives += Integer.parseInt(map1.get("five").toString());
sixs += Integer.parseInt(map1.get("six").toString());
sevens += Integer.parseInt(map1.get("seven").toString());
} catch (Exception e) {
e.printStackTrace();
}
}
List<SvnDataAuxiliaryOne> svnDataAuxiliaryOnes = getSvnDataAuxiliaryOnes(today, sevenToday, thirtyToday);
List<SvnDataAuxiliaryThree> svnDataAuxiliaryThrees = getSvnDataAuxiliaryThrees(nows, ones, twos, threes, fours, fives, sixs, sevens);
svnDataService.saveData(lists);
svnDataService.saveCommitCount(svnDataAuxiliaryOnes);
svnDataService.saveWeekCommitCount(svnDataAuxiliaryThrees);
}
}
private List<SvnDataAuxiliaryThree> getSvnDataAuxiliaryThrees(int nows, int ones, int twos, int threes, int fours, int fives, int sixs, int sevens) {
List<SvnDataAuxiliaryThree> ls = Lists.newArrayList();
SvnDataAuxiliaryThree svnDataAuxiliaryThree = new SvnDataAuxiliaryThree();
SvnDataAuxiliaryThree svnDataAuxiliaryThree1 = new SvnDataAuxiliaryThree();
SvnDataAuxiliaryThree svnDataAuxiliaryThree2 = new SvnDataAuxiliaryThree();
SvnDataAuxiliaryThree svnDataAuxiliaryThree3 = new SvnDataAuxiliaryThree();
SvnDataAuxiliaryThree svnDataAuxiliaryThree4 = new SvnDataAuxiliaryThree();
SvnDataAuxiliaryThree svnDataAuxiliaryThree5 = new SvnDataAuxiliaryThree();
SvnDataAuxiliaryThree svnDataAuxiliaryThree6 = new SvnDataAuxiliaryThree();
SvnDataAuxiliaryThree svnDataAuxiliaryThree7 = new SvnDataAuxiliaryThree();
svnDataAuxiliaryThree.setName(SvnTimeConstants.Today);
svnDataAuxiliaryThree.setSum(nows);
svnDataAuxiliaryThree1.setName(SvnTimeConstants.ONE);
svnDataAuxiliaryThree1.setSum(ones);
svnDataAuxiliaryThree2.setName(SvnTimeConstants.TWO);
svnDataAuxiliaryThree2.setSum(twos);
svnDataAuxiliaryThree3.setName(SvnTimeConstants.THREE);
svnDataAuxiliaryThree3.setSum(threes);
svnDataAuxiliaryThree4.setName(SvnTimeConstants.FOUR);
svnDataAuxiliaryThree4.setSum(fours);
svnDataAuxiliaryThree5.setName(SvnTimeConstants.FIVE);
svnDataAuxiliaryThree5.setSum(fives);
svnDataAuxiliaryThree6.setName(SvnTimeConstants.SIX);
svnDataAuxiliaryThree6.setSum(sixs);
svnDataAuxiliaryThree7.setName(SvnTimeConstants.SEVEN);
svnDataAuxiliaryThree7.setSum(sevens);
ls.add(svnDataAuxiliaryThree);
ls.add(svnDataAuxiliaryThree1);
ls.add(svnDataAuxiliaryThree2);
ls.add(svnDataAuxiliaryThree3);
ls.add(svnDataAuxiliaryThree4);
ls.add(svnDataAuxiliaryThree5);
ls.add(svnDataAuxiliaryThree6);
ls.add(svnDataAuxiliaryThree7);
return ls;
}
private List<SvnDataAuxiliaryOne> getSvnDataAuxiliaryOnes(int today, int sevenToday, int thirtyToday){
List<SvnDataAuxiliaryOne> ls = Lists.newArrayList();
SvnDataAuxiliaryOne svnDataAuxiliaryOne = new SvnDataAuxiliaryOne();
svnDataAuxiliaryOne.setName(SvnTimeConstants.Today);
svnDataAuxiliaryOne.setSum(today);
SvnDataAuxiliaryOne svnDataAuxiliaryOne1 = new SvnDataAuxiliaryOne();
svnDataAuxiliaryOne1.setName(SvnTimeConstants.Nearlysevendays);
svnDataAuxiliaryOne1.setSum(sevenToday);
SvnDataAuxiliaryOne svnDataAuxiliaryOne2 = new SvnDataAuxiliaryOne();
svnDataAuxiliaryOne2.setName(SvnTimeConstants.NearlyThirtydays);
svnDataAuxiliaryOne2.setSum(thirtyToday);
ls.add(svnDataAuxiliaryOne);
ls.add(svnDataAuxiliaryOne1);
ls.add(svnDataAuxiliaryOne2);
return ls;
}
public long convertDaysToMilliseconds (int days){
return 1000L*3600*24*days;
}
public Date fm(Date daysago){
try {
SimpleDateFormat sdf=new SimpleDateFormat(SvnTimeConstants.fm);
Date parse = sdf.parse(sdf.format(daysago));
return parse;
} catch (ParseException e) {
e.printStackTrace();
}
return daysago;
}
}
6.svn工具類、需要把userName 、password 、urlString 更換稱自己的、我是直接從後臺資料庫中獲取的,自己可以寫個main方法測試下。
package com.zkr.cxhjcxt.timedutils;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.zkr.cxhjcxt.constants.SvnTimeConstants;
import com.zkr.cxhjcxt.dto.ChangeFile;
import com.zkr.cxhjcxt.dto.SvnDto;
import com.zkr.cxhjcxt.model.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import org.springframework.util.CollectionUtils;
import org.tmatesoft.svn.core.*;
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;
import java.io.*;
import java.util.*;
/**
* svn獲取
*
* @author youzongxu
* @date 2018/9/7
*/
@Slf4j
public class svnutil {
private String userName = "";
private String password = "";
private String urlString = "";
/**
* 臨時檔案
*/
private String tempDir = System.getProperty("java.io.tmpdir");
private DefaultSVNOptions options = SVNWCUtil.createDefaultOptions(true);
private Random random = new Random();
private SVNRepository repos;
private ISVNAuthenticationManager authManager;
public svnutil(String u,String p,String url) {
try {
userName = u;
password = p;
urlString = url;
init();
} catch (SVNException e) {
e.printStackTrace();
}
}
public void init() throws SVNException{
log.info("開始載入");
authManager = SVNWCUtil.createDefaultAuthenticationManager(new File(tempDir+"/auth"), userName, password.toCharArray());
options.setDiffCommand("-x -w");
repos = SVNRepositoryFactory.create(SVNURL
.parseURIEncoded(urlString));
repos.setAuthenticationManager(authManager);
log.info("init completed");
}
/**
* 統計一段時間內程式碼增加量
* @param st
* @param et
* @return
* @throws Exception
*/
public List<SvnDto> staticticsCodeAddByTime(Date st, Date et) throws Exception{
SVNLogEntry[] logs = getLogByTime(st, et);
List<SvnDto> ls = Lists.newArrayList();
if(logs.length > 0){
for(SVNLogEntry log:logs){
File logFile = getChangeLog(log.getRevision(), log.getRevision()-1);
SvnDto svnDto = new SvnDto();
svnDto.setAuthor(log.getAuthor());
svnDto.setRevision(log.getRevision());
svnDto.setSvnMessage(StringUtils.isNotBlank(log.getMessage())?log.getMessage():SvnTimeConstants.SvnMessageFlag);
svnDto.setSvnTime(log.getDate());
ls.add(svnDto);
List<SvnDataAuxiliaryFour> fourList = getChangeFileList(log.getRevision());
List<SvnDataAuxiliaryTwo> twoList = staticticsCodeAdd(logFile, log.getRevision());
if(!CollectionUtils.isEmpty(fourList)){
svnDto.setFourList(fourList);
}
if(!CollectionUtils.isEmpty(twoList)){
svnDto.setTwoList(twoList);
}
}
}
return ls;
}
/**獲取某一版本有變動的檔案路徑
* @param version
* @return
* @throws SVNException
*/
public List<SvnDataAuxiliaryFour> getChangeFileList(long version) throws SVNException{
List<SvnDataAuxiliaryFour> ls = Lists.newArrayList();
SVNLogClient logClient = new SVNLogClient( authManager, options );
SVNURL url = SVNURL.parseURIEncoded(urlString);
String[] paths = { "." };
SVNRevision pegRevision = SVNRevision.create( version );
SVNRevision startRevision = SVNRevision.create( version );
SVNRevision endRevision = SVNRevision.create( version );
long limit = 9999L;
ISVNLogEntryHandler handler = new ISVNLogEntryHandler() {
/**
* This method will process when doLog() is done
*/
@Override
public void handleLogEntry( SVNLogEntry logEntry ) {
Map<String, SVNLogEntryPath> maps = logEntry.getChangedPaths();
Set<Map.Entry<String, SVNLogEntryPath>> entries = maps.entrySet();
for(Map.Entry<String, SVNLogEntryPath> entry : entries){
SvnDataAuxiliaryFour svnDataAuxiliaryFour = new SvnDataAuxiliaryFour();
svnDataAuxiliaryFour.setSvnVersion(logEntry.getRevision());
svnDataAuxiliaryFour.setSvnPath(entry.getValue().getPath());
svnDataAuxiliaryFour.setSvnType(String.valueOf(entry.getValue().getType()));
ls.add(svnDataAuxiliaryFour);
}
}
};
try {
logClient.doLog( url, paths, pegRevision, startRevision, endRevision, false, true, limit, handler );
}
catch ( SVNException e ) {
System.out.println( "Error in doLog() " );
e.printStackTrace();
}
return ls;
}
/**獲取一段時間內,所有的commit記錄
* @param st 開始時間
* @param et 結束時間
* @return
* @throws SVNException
*/
public SVNLogEntry[] getLogByTime(Date st, Date et) throws SVNException{
long startRevision = repos.getDatedRevision(st);
long endRevision = repos.getDatedRevision(et);
@SuppressWarnings("unchecked")
Collection<SVNLogEntry> logEntries = repos.log(new String[]{""}, null,
startRevision, endRevision, true, true);
SVNLogEntry[] svnLogEntries = logEntries.toArray(new SVNLogEntry[0]);
SVNLogEntry[] svnLogEntries1 = Arrays.copyOf(svnLogEntries, svnLogEntries.length - 1);
return svnLogEntries1;
}
/**獲取版本比較日誌,並存入臨時檔案
* @param startVersion
* @param endVersion
* @return
*/
public File getChangeLog(long startVersion, long endVersion) {
SVNDiffClient diffClient = new SVNDiffClient(authManager, options);
diffClient.setGitDiffFormat(true);
File tempLogFile;
OutputStream outputStream = null;
String svnDiffFile;
do {
svnDiffFile = tempDir + "/svn_diff_file_"+startVersion+"_"+endVersion+"_"+random.nextInt(10000)+".txt";
tempLogFile = new File(svnDiffFile);
} while (tempLogFile != null && tempLogFile.exists());
try {
tempLogFile.createNewFile();
outputStream = new FileOutputStream(svnDiffFile);
diffClient.doDiff(SVNURL.parseURIEncoded(urlString),
SVNRevision.create(startVersion),
SVNURL.parseURIEncoded(urlString),
SVNRevision.create(endVersion),
SVNDepth.UNKNOWN, true, outputStream);
} catch (Exception e) {
e.printStackTrace();
}finally {
if(outputStream!=null) {
try {
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return tempLogFile;
}
/**分析變更的程式碼,統計程式碼增量
* @param file
* @param revision
* @return
* @throws Exception
*/
public List<SvnDataAuxiliaryTwo> staticticsCodeAdd(File file, long revision) throws Exception{
log.info("開始統計修改程式碼行數");
List<SvnDataAuxiliaryTwo> twoList = Lists.newArrayList();
FileReader fileReader = new FileReader(file);
BufferedReader in = new BufferedReader(fileReader);
String line;
StringBuffer buffer = new StringBuffer(1024);
boolean start = false;
while((line=in.readLine()) != null){
if(line.startsWith("Index:")){
if(start){
ChangeFile changeFile = parseChangeFile(buffer);
if(null!=changeFile){
String filePath = changeFile.getFilePath();
if(getBoolean(filePath)){
int oneSize = staticOneFileChange(changeFile);
SvnDataAuxiliaryTwo svnDataAuxiliaryTwo = new SvnDataAuxiliaryTwo();
svnDataAuxiliaryTwo.setSvnAddlines(oneSize);
svnDataAuxiliaryTwo.setSvnFilepath("/"+changeFile.getFilePath());
svnDataAuxiliaryTwo.setSvnReversion(revision);
twoList.add(svnDataAuxiliaryTwo);
}
}
buffer.setLength(0);
}
start = true;
}
buffer.append(line).append('\n');
}
if(buffer.length() > 0){
ChangeFile changeFile = parseChangeFile(buffer);
if(null!=changeFile){
String filePath = changeFile.getFilePath();
if(getBoolean(filePath)){
int oneSize = staticOneFileChange(changeFile);
SvnDataAuxiliaryTwo svnDataAuxiliaryTwo = new SvnDataAuxiliaryTwo();
svnDataAuxiliaryTwo.setSvnAddlines(oneSize);
svnDataAuxiliaryTwo.setSvnFilepath("/"+changeFile.getFilePath());
svnDataAuxiliaryTwo.setSvnReversion(revision);
twoList.add(svnDataAuxiliaryTwo);
}
}
}
in.close();
fileReader.close();
boolean deleteFile = file.delete();
log.info("-----delete file-----"+deleteFile);
return twoList;
}
public boolean getBoolean(String filePath){
String[] k = {".java", ".html", ".css", ".js", ".jsp", ".properties",".xml",".json",".sql",".wxml",".wxss"};
List<String> strings = Arrays.asList(k);
boolean ba = false;
c:for (String ls:strings) {
if(filePath.contains(ls)){
ba = true;
break c;
}
}
return ba;
}
/**統計單個檔案的增加行數,(先通過過濾器,如檔案字尾、檔案路徑等等),也可根據修改型別來統計等,這裡只統計增加或者修改的檔案
* @param changeFile
* @return
*/
public int staticOneFileChange(ChangeFile changeFile){
char changeType = changeFile.getChangeType();
char A = 'A';
char M = 'M';
if(A == changeType){
return countAddLine(changeFile.getFileContent());
}else if(M == changeType){
return countAddLine(changeFile.getFileContent());
}
return 0;
}
/**解析單個檔案變更日誌:A表示增加檔案,M表示修改檔案,D表示刪除檔案,U表示末知
* @param str
* @return
*/
public ChangeFile parseChangeFile(StringBuffer str){
int index = str.indexOf("\[email protected]@");
if(index > 0){
String header = str.substring(0, index);
String[] headers = header.split("\n");
String filePath = "";
if(StringUtils.isNotBlank(headers[0])){
filePath = headers[0].substring(7);
}
char changeType = 'U';
boolean oldExist = !headers[2].endsWith("(nonexistent)");
boolean newExist = !headers[3].endsWith("(nonexistent)");
if(oldExist && !newExist){
changeType = 'D';
}else if(!oldExist && newExist){
changeType = 'A';
}else if(oldExist && newExist){
changeType = 'M';
}
int bodyIndex = str.indexOf("@@\n")+3;
String body = str.substring(bodyIndex);
if(StringUtils.isNotBlank(filePath)){
ChangeFile changeFile = new ChangeFile(filePath, changeType, body);
return changeFile;
}
}else{
String[] headers = str.toString().split("\n");
log.info("headers"+headers[0]);
if(StringUtils.isNotBlank(headers[0])){
String filePath = headers[0].substring(7);
ChangeFile changeFile = new ChangeFile(filePath, 'U', null);
return changeFile;
}
}
return null;
}
/**通過比較日誌,統計以+號開頭的非空行
* @param content
* @return
*/
public int countAddLine(String content){
int sum = 0;
if(content !=null){
content = '\n' + content +'\n';
char[] chars = content.toCharArray();
int len = chars.length;
//判斷當前行是否以+號開頭
boolean startPlus = false;
//判斷當前行,是否為空行(忽略第一個字元為加號)
boolean notSpace = false;
for(int i=0;i<len;i++){
char ch = chars[i];
if(ch =='\n'){
//噹噹前行是+號開頭,同時其它字元都不為空,則行數+1
if(startPlus && notSpace){
sum++;
notSpace = false;
}
//為下一行做準備,判斷下一行是否以+頭
if(i < len-1 && chars[i+1] == '+'){
startPlus = true;
//跳過下一個字元判斷,因為已經判斷了
i++;
}else{
startPlus = false;
}
}else if(startPlus && ch > ' '){
//如果當前行以+開頭才進行非空行判斷
notSpace = true;
}
}
}
return sum;
}
/**
* 獲取提交次數
* @param dt
* @return
*/
public int countSum(Date dt){
try {
Date now = new Date();
SVNLogEntry[] logByTime = getLogByTime(now, dt);
List<SVNLogEntry> svnLogEntries = Arrays.asList(logByTime);
return svnLogEntries.size();
} catch (SVNException e) {
return 0;
}
}
/**
* 獲取提交量
* @param dt
* @return
*/
public int dmCountSum(Date dt){
int sum = 0;
try {
Date now = new Date();
SVNLogEntry[] logByTime = getLogByTime(now, dt);
List<SVNLogEntry> svnLogEntries = Arrays.asList(logByTime);
sum = 0;
for (SVNLogEntry ls:svnLogEntries) {
sum += ls.getChangedPaths().size();
}
} catch (SVNException e) {
e.printStackTrace();
}
return sum;
}
/**
* 獲取:1:今天 2:近一週 3:近一個月的資料
* @return
*/
public Map<String,Object> commitCount(){
LocalDate localDate = new DateTime().toLocalDate();
LocalDate localDateSeven = new DateTime().minusDays(SvnTimeConstants.seven).toLocalDate();
LocalDate localDateThirty = new DateTime().minusDays(SvnTimeConstants.Thirty).toLocalDate();
int today = countSum(localDate.toDate());
int sevenToday = countSum(localDateSeven.toDate());
int thirtyToday = countSum(localDateThirty.toDate());
Map<String,Object> map = Maps.newHashMap();
map.put("today",today);
map.put("sevenToday",sevenToday);
map.put("thirtyToday",thirtyToday);
return map;
}
public Map<String,Object> dmCount(){
Map<String,Object> map = Maps.newHashMap();
//日期改成時間排列
LocalDate now = new DateTime().toLocalDate();
LocalDate one = new DateTime().minusDays(SvnTimeConstants.one).toLocalDate();
LocalDate two = new DateTime().minusDays(SvnTimeConstants.two).toLocalDate();
LocalDate three = new DateTime().minusDays(SvnTimeConstants.three).toLocalDate();
LocalDate four = new DateTime().minusDays(SvnTimeConstants.four).toLocalDate();
LocalDate five = new DateTime().minusDays(SvnTimeConstants.five).toLocalDate();
LocalDate six = new DateTime().minusDays(SvnTimeConstants.six).toLocalDate();
LocalDate seven = new DateTime().minusDays(SvnTimeConstants.seven).toLocalDate();
int now_count = dmCountSum(now.toDate());
int one_count = dmCountSum(one.toDate())-now_count;
int two_count = dmCountSum(two.toDate())-one_count;
int three_count = dmCountSum(three.toDate())-two_count;
int four_count = dmCountSum(four.toDate())-three_count;
int five_count = dmCountSum(five.toDate())-four_count;
int six_count = dmCountSum(six.toDate())-five_count;
int seven_count = dmCountSum(seven.toDate())-six_count;
map.put("now",now_count);
map.put("one",one_count);
map.put("two",two_count);
map.put("three",three_count);
map.put("four",four_count);
map.put("five",five_count);
map.put("six",six_count);
map.put("seven",seven_count);
return map;
}
}
相關推薦
VS中實時獲取SVN的版本號並寫入到AssemblyInfo.cs中(C#)
art csharp style eve avi exec format sharp 匹配 原文:VS中實時獲取SVN的版本號並寫入到AssemblyInfo.cs中(C#)
java程式碼獲取svn提交版本號、提交人、提交時間、提交型別、影響程式碼行數
公司最近做大螢幕資料展示,需要獲取svn/git、jira、jenkins、sonar上的資料。本人除了git外,其它工具都不熟,索性網路時代救了我,本人也是查了很多資料來實現自己的專案需求功能。 java獲取svn程式碼,是看到了scdn上的一位大神傑作來修改
獲取iOS系統版本號,慎重使用[[[UIDevice currentDevice] systemVersion] floatValue]——【sdk缺陷】
net 版本 ice system family class 失效 color -s iOS 最常見的獲取系統版本的方法是: [[[UIDevice currentDevice] systemVersion] floatValue] 可是。這個floatValue是
java 判斷是否大於指定版本號
ger class oop eat public result val split util public boolean is_version_great_than(String version) { boolean result = false
安卓獲取當前app版本號(versionCode)和版本名稱(versionName)
/** * 獲取當前app version code */ public static long getAppVersionCode(Context context) { long appVersionCode = 0; tr
檢視java class檔案的編譯版本號
用maven做專案依賴管理,依賴了一個其他組開發的一個基礎包。結果,在使用maven進行編譯打包的時候,報了錯: Unsupported major.minor version 51.0。 注:我本機上目前只安裝了 jdk 1.8 使用Eclispse自帶的
PHP 獲取瀏覽器以及版本號
PHP 獲取瀏覽器以及版本號 增加獲取 chrome瀏覽器 各大經典瀏覽器HTTP_USER_AGENT詳細 IE 而IE各個版本典型的userAgent如下: Mozilla/4.0 (compatible; MSIE 8.0; Wi
獲取Windows系統版本號
前言 由於前段時間比較忙,一直沒有來跟大家分享交流技術,實在是抱歉,往後我會不定時跟大家分享一些C++技術。 廢話 有些東西看似簡單,但坑多著呢,所以大家還是要多親自嘗試,不要眼高手低。 核心程式碼 //讀取作業系統的名稱 string GetSystemName() {
獲取android.apk版本號
/** * 獲得手機端版本號 */ public int getVerCode() { int verCode = -1; try { verCode = Login.this.getPackageManager().getPackageInfo(
Qt Creator自動使用svn原始碼版本號編譯
有時我們想在編譯工程時,使用 svn 的原始碼版本號來作為 build 的一個子版本號;或者只是為了識別某個釋出版本,與原始碼對應起來。 在 Linux 下面有很多的解決方案,使用 svn 工具和一些 shell 命令再加上 -D 選項就可以達到上述目的。
c#中獲取檔案的版本號
/// <summary> /// 獲取檔案的版本號 /// </summary> /// <param name="filePath">檔案的完整路徑</param>
Android獲取應用的版本號和Android系統版本號
下面是 Android 獲取應用的版本號,一般來說,我們獲取版本號就是獲取展示給消費者的版本號: //獲取當前程式版本名(對消費者不可見的版本號) public String getAppVersionCode() { String vers
Java實現Android客戶端版本號比較
目錄 前言 早上看了一下CSDN部落格排名,本週最高排名的文章是:Java實現比較版本號。個人認為這篇文章寫的不錯,因為Android客戶端系統中經常用到版本號比較功能,特別是在應用自升級
Android基礎:教你如何獲取軟體自身版本號和Android系統版本號
前言 在Android軟體開發過程中,版本升級常常需要得到軟體版本,與伺服器作對比後決定是否升級,那麼如何獲取軟體版本呢?有時我們需要獲取系統版本已決定載入合適的資原始檔,系統版本又如何得到呢?假如我
git 源碼學習(init-db) 提交版本號 083c516331
ani 修改 函數 新的 define 版本號 html_ clone zlib 寫在前面的廢話: 學完git之後,還是感覺雲裏霧裏的,於是乎,就想到了通過學習git源碼,來加深git的熟練度,同時學習一下c語言編程。 git源碼學習,逐步分析 這篇帖子是逐步分析gi
mybatis 更新、刪除、插入 錯誤的返回影響的行數
當用mybatis 執行 插入、刪除、更新操作要以返回影響的行數來判斷這些操作時是否執行的時候,mybatis返回的行數是一個負數,這主要是有以下幾點原因 原因: 當連續執行兩次相同的更新操作時,msyql客戶端在第一次在執行更新時候,影響返回的值是等於1的,則第二次執行的
磁碟排程演算法;先來先服務排程演算法、最短尋道時間優先排程演算法、掃描排程算
一、 實驗目的和要求1. 瞭解磁碟排程技術的特點2. 掌握磁碟排程演算法,如先來先服務(firstcome first served,FCFS)排程演算法、最短尋道時間優先(shortest seek timefirst,SSTF)排程演算法、掃描(SCAN)排程演算法
php mysql_affected_rows獲取sql執行影響的行數
php mysql_affected_rows函式用於獲取執行某一SQL語句(如INSERT,UPDATE 或 DELETE )所影響的行數,本文章向大家介紹php mysql_affected_rows函式的使用方法和基本使用例項,需要的朋友可以參考一下。 mysql_a
SVN版本號管理工具使用中常見的代碼提交沖突問題的解決方法
而且 spa ise 錯誤 這樣的 合作開發 csdn 新版 span 相信剛開始學習使用SVN的小夥伴在項目合作開發的過程中一定常常遇到一些影響到自己編寫的代碼的苦惱。我這裏列舉了幾種常見的問題以及問題的解決方法: 1.誤刪除和誤操作的問題
Android菜鳥筆記- 獲取未安裝的APK圖標、版本號、包名、名稱、是否安裝、安裝、打開
ack ear 例如 start true intent ble post oca 周末閑來無事,把Android的基礎知識拿出來復習復習,今天主題是《獲取未安裝的APK圖標、版本號、包名、名稱、是否安裝、跳轉安裝、打開》 一、獲取APK圖標 通常讀取APK的圖標能夠用