svnkit获取svn相关信息
2013-01-24 14:09
239 查看
public class SVNOperationServiceBean implements SVNOperationService { private final DataVoiceLogger logger = DataVoiceLogFactory.getLogger(getClass()); private SVNRepository repository = null; @PostConstruct public void initSVNOperationService() { DAVRepositoryFactory.setup(); SVNRepositoryFactoryImpl.setup(); FSRepositoryFactory.setup(); } public void login(String username, String password, String url) throws Exception { password = new String(Base64.decode(password.getBytes())); this.repository = SVNRepositoryFactory.create(SVNURL.parseURIDecoded(url)); ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(username, password); this.repository.setAuthenticationManager(authManager); testConnection(); } private void testConnection() throws SVNException { this.repository.testConnection(); } @Override public boolean testRepositoryConnected(SvnConfigInfo conf) { boolean isSucceed = false; try { login(conf.getUserAccount(), conf.getUserPassword(), conf.getConfigCodePath()); String[] codepath = getCodePaths(conf.getConfigCodePath()); SVNDirEntry dir = getTargetInfo(codepath[0], -1); if (dir != null) { isSucceed = true; logger.info(conf.getConfigCodePath() + " testlogin success "); } } catch (SVNAuthenticationException e) { logger.error("login error" + e.getMessage()); } catch (Exception e) { logger.error(e.getMessage()); } return isSucceed; } public SVNDirEntry getTargetInfo(String path, long revision) { SVNDirEntry collect = null; try { collect = this.repository.info(path, revision); } catch (SVNException e) { collect = null; logger.error(e.getMessage()); } return collect; } public List<SVNLogEntry> getSVNLog(long startRevision, long endRevision, String[] codePaths) { List<SVNLogEntry> entries = new ArrayList<SVNLogEntry>(); try { this.repository.log(codePaths, entries, startRevision, endRevision, true, true); } catch (SVNException e) { logger.error(e.getMessage()); } return entries; } public SvnLogFileInfo getLastFileRevision(SvnLogFileInfo fInfo) { SvnLogFileInfo fileInfo = null; List<SVNFileRevision> s = new ArrayList<SVNFileRevision>(); int index = -2; try { this.repository.getFileRevisions(fInfo.getFilename(), s, 0, fInfo.getRevision()); } catch (SVNException e) { logger.error(e.getMessage()); } index = s.size() + index; if (index >= 0) { SVNFileRevision revision = s.get(index); fileInfo = new SvnLogFileInfo(); fileInfo.setFilename(revision.getPath(),this.getRepositoryType()); fileInfo.setRevision(revision.getRevision()); } return fileInfo; } public boolean copyFile(String workspace, String type, SvnLogFileInfo fileInfo) { FileOutputStream fo = null; boolean isSuccess = false; try { SVNProperties pro = new SVNProperties(); File file = new File(workspace + "\\" + type + "\\" + fileInfo.getShortFileName()); fo = new FileOutputStream(file); try { this.repository.getFile(fileInfo.getFilename(), fileInfo.getRevision(), pro, fo); } catch (SVNException e) { logger.error("query the file "+fileInfo.getShortFileName()+"'info from repository, but file copy failed!"); } fo.close(); isSuccess = true; } catch (Exception e) { logger.error(e.getMessage()); } finally { try { if (fo != null) { fo.close(); } } catch (IOException e) { logger.error(e.getMessage()); } } return isSuccess; } public long getLatestRevision() { long lastRevision = 0; try { lastRevision = this.repository.getLatestRevision(); } catch (SVNException e) { logger.error("Lastest revision of this repository is not exists!"); } return lastRevision; } public String getSvnRoot() { SVNURL url = null; try { url = this.repository.getRepositoryRoot(false); return url.getPath(); } catch (SVNException e) { e.printStackTrace(); logger.error("You have no right get this repository root url !!!"); } return null; } public String[] getCodePaths(String url) { String codepath = getSvnRoot(); int homeIndex = url.indexOf(codepath); return new String[] { url.substring(homeIndex + codepath.length()) }; } @Override public String getRepositoryType() { return RepositoryOperation.IREP_TYPE_SVN; } }
相关文章推荐
- svnkit获取svn相关信息
- 利用pysvn 获取SVN的一些相关信息
- postgrep 获取几何图形相关信息
- vc 通过POST发送信息到网站获取相关信息
- c++ 使用wmi 获取系统相关信息
- 黄聪:WordPress 多站点建站教程(四):获取子站点相关信息(站点的注册时间,修改时间,总文章数,URL等)
- wmi协议支持远程执行cmd命令,并返回获取命令相关信息
- Android 使用ContentResolver获取手机图片和照片的相关信息
- 使用Google Geocoding API来进行关键字搜索,获取相关的地理位置信息
- iphone开发之通过unix系统底层获取和系统相关的硬件信息
- iOS 获取通讯录相关信息
- 苹果设备相关信息获取方法
- wxWidgets获取本机IP,计算机名等相关信息 推荐
- C# 根据ip获取城市等相关信息
- 老生常谈,获取数据库服务器的相关信息。
- JAVA调用svnkit获取svn树节点
- 使用VMware VSphere WebService SDK进行开发 (四)——获取集群(Cluster, ComputeResource)的相关信息
- ios开发-获取手机相关信息
- 获取设备相关信息工具包
- 用curl模拟登陆获取页面信息以及相关知识点