svnkit获取SVN信息


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;
}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值