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信息
利用svnkit操作svn,实现对版本修改文件的导出,可以导出多个版本,.java文件将会在本地取出.class文件,导出后压缩成压缩包,主要用于服务器上的资源更新,不需要开发人员去找到对应的.class文件或其他文件压缩然后...
svnkit操作svn,没有跑成功,是将别人的代码整合了一下
svnKit java操作svn :上传 下载 提交 更新 版本
需要svnkit 使用方法 SVNUtil.getHistoryByDate("https://127.0.0.1:8443/svn/Test/mytestprotect/", "username", "password"); 如果jar 在我的其它资源里
svnkit svn api jar 源码 1.7.11
纯java操作svn--svnkit API!
svnkit插件开发包 包含svn插件jar包
svnkit 1.8.11- javadoc(svn java编程文档)
自己写的使用svnkit操作svn库,对比版本号、文件等等,并把需要的信息组装成json。
svnkit1.3.5完整包svnkit1.3.5完整包
使用类SVNRepository可以检查一个subversion仓库中是否存在制定的文件(SVNRepository.checkPath)、获取一个 ISVNEdirot向subversion仓库中commit(SVNRepository.getCommitEditor)等等。 PS: 有两个使用svnkit...
其他SVNKit的操作包括CheckOut,DoCommit,DoDiff,DoImport,DoUpdate,查看上次备注信息(message/log),DisplayFile(查看svn文件属性)DisplayRepositoryTree(查看某路径下的所有文件)
基于javasvnkit 功能 1.实现了几个基础操作 2.提供了日志操作
SVNKit (JavaSVN) 是一个纯 Java 的 SVN 客户端库,使用 SVNKit 无需安装任何 SVN 的客户端,支持各种操作系统。 这不是一个开源的类库,但你可以免费使用。 通过SVNKit,你可以在SVN上开发出自己的应用
svnkit,可以通过该jar获取svn上传历史信息,提交明细等。
SVNKit (JavaSVN) 是一个纯 Java 的 SVN 客户端库,使用 SVNKit 无需安装任何 SVN 的客户端,支持各种操作系统。 这不是一个开源的类库,但你可以免费使用。 通过SVNKit,你可以在SVN上开发出自己的应用。
SVNKit实例包括所有SVN相关的基本操作,完整项目,导入即可运行
svn插件site-1.6.18版本和site-1.8.22版本两个版本的插件压缩包。欢迎下载
svnkit-1.8.6.jar