// parseLog方法内部的代码不能改动
public static void parseLog(String log) {
System.out.println(log + ":" + (System.currentTimeMillis() / 1000));
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
/**
* 根据文件目录检出文件
*
* @param desPath
*/
private static void checkOut(String desPath) {
SVNClientManager ourClientManager;
//初始化支持svn://协议的库。 必须先执行此操作。
SVNRepositoryFactoryImpl.setup();
//相关变量赋值
SVNURL repositoryURL = null;
try {
repositoryURL = SVNURL.parseURIEncoded("http://112.124.45.101/svn/finance/项目文档/8_算法实验室/测试文档/兴业数金使用手册V0.1.docx");
} catch (SVNException e) {
System.out.println(e.getMessage());
System.exit(1);
}
ISVNOptions options = SVNWCUtil.createDefaultOptions(true);
//实例化客户端管理类
ourClientManager = SVNClientManager.newInstance((DefaultSVNOptions) options, "xuanxuan.zhang", "zxx2017");
//要把版本库的内容check out到的目录
File desFile = new File(desPath);
//通过客户端管理类获得updateClient类的实例。
SVNUpdateClient updateClient = ourClientManager.getUpdateClient();
updateClient.setIgnoreExternals(false);
try {
//返回工作版本号
long workingVersion = updateClient.doCheckout(repositoryURL, desFile, SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.INFINITY, true);
System.out.println("把版本:" + workingVersion + " check out 到目录:" + desPath + "中");
} catch (SVNException e) {
System.out.println("检出代码出错" + e);
System.exit(1);
}
/**
* 根据提交版本拉文件
*/
public static void checkOutByRevsion (String version, String url, String path, String name, String pwd) throws
Exception {
SVNClientManager ourClientManager;
//初始化支持svn://协议的库。 必须先执行此操作。
DAVRepositoryFactory.setup();
//相关变量赋值
SVNURL repositoryURL;
repositoryURL = SVNURL.parseURIEncoded(url);
ISVNOptions options = SVNWCUtil.createDefaultOptions(true);
//实例化客户端管理类
ourClientManager = SVNClientManager.newInstance((DefaultSVNOptions) options, name, pwd);
//要把版本库的内容check out到的目录"d:/test/"
String substring = url.substring(url.lastIndexOf("/"));
substring.replace("/", File.separator);
File delteDir = new File(path + substring);
if (delteDir.exists()) {
delteDir.delete();
}
path.replace("/", File.separator);
// path.replace("\\", File.separator);
File wcDir = new File(path);
//通过客户端管理类获得updateClient类的实例。
SVNUpdateClient updateClient = ourClientManager.getUpdateClient();
updateClient.setIgnoreExternals(false);
//执行check out 操作,返回工作副本的版本号。
long workingVersion = updateClient.doExport(repositoryURL, wcDir, SVNRevision.HEAD, SVNRevision.parse(version), "", true, false);
System.out.println("把版本:" + workingVersion + " check out 到目录:" + wcDir + "中。");
}
// 从svn 上获取提交文件记录 *
//@param scriptDefine 此参数可以不用(这里用来取地址的)
// @param userName svn 账号
//@param pwd svn 密码
// @return
//@throws Exception
public static List<ScriptVersion> filterCommitHistoryTest (ScriptDefine scriptDefine, String userName, String
pwd) throws Exception {
SVNRepository repository = null;
DAVRepositoryFactory.setup();
SVNRepositoryFactoryImpl.setup();
FSRepositoryFactory.setup();
//svn 上存放文件的地址 例如:http://112.124.45.101/svn/finance/产品/产品设计/测试
String url = scriptDefine.getUrl() + "/" + scriptDefine.getName();
repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url));
// 身份验证
ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(userName, pwd);
repository.setAuthenticationManager(authManager);
// 过滤条件
final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm");
long startRevision = 0;
long endRevision = -1;//表示最后一个版本
final List<String> history = new ArrayList<String>();
List<SVNLogEntry> list = new ArrayList<>();
//String[] 为过滤的文件路径前缀,为空表示不进行过滤
repository.log(new String[]{""},
startRevision,
endRevision,
true,
true,
new ISVNLogEntryHandler() {
@Override
public void handleLogEntry(SVNLogEntry svnlogentry) throws SVNException {
fillResult(svnlogentry);
}
void fillResult(SVNLogEntry svnlogentry) {
//getChangedPaths为提交的历史记录MAP key为文件名,value为文件详情
history.addAll(svnlogentry.getChangedPaths().keySet());
list.add(svnlogentry);
}
});
List<ScriptVersion> versionlist = new ArrayList<>();
for (SVNLogEntry svnLogEntry : list) {
Map<String, SVNLogEntryPath> changedPaths = svnLogEntry.getChangedPaths();
// + svnLogEntry.getAuthor() + "---时间:" + svnLogEntry.getDate() +"---消息:" + svnLogEntry.getMessage()+"--版本号:"+svnLogEntry.getRevision()*/
log.info("文件:" + changedPaths.keySet() + " & 提交者" + svnLogEntry.getAuthor() + " & 提交时间:" + svnLogEntry.getDate() + " & 提交消息:" + svnLogEntry.getMessage() + " & 版本号:" + svnLogEntry.getRevision());
ScriptVersion scriptVersion = new ScriptVersion();
scriptVersion.setUpdateTime(svnLogEntry.getDate());
scriptVersion.setVersionNum(String.valueOf(svnLogEntry.getRevision()));
scriptVersion.setMsg(svnLogEntry.getMessage());
scriptVersion.setAuthor(svnLogEntry.getAuthor());
versionlist.add(scriptVersion);
}
Collections.sort(versionlist);
return versionlist;
}