2
我在我的應用程序中使用svnkit-1.3.5.jar。在我點擊一個按鈕的屏幕上,我需要顯示一個jQuery對話框,其中包含SVN中特定路徑中存在的文件夾列表。 svnkit是否提供了檢索存在於特定位置的所有文件夾名稱的方法?我如何在java中實現這一點?如何使用java獲取SVN目錄中的文件夾列表
我在我的應用程序中使用svnkit-1.3.5.jar。在我點擊一個按鈕的屏幕上,我需要顯示一個jQuery對話框,其中包含SVN中特定路徑中存在的文件夾列表。 svnkit是否提供了檢索存在於特定位置的所有文件夾名稱的方法?我如何在java中實現這一點?如何使用java獲取SVN目錄中的文件夾列表
final URL url = ...
final SVNRevision revision = ...
final SvnOperationFactory operationFactory = ...
final SvnList list = operationFactory.createList();
list.setDepth(SVNDepth.IMMEDIATES);
list.setRevision(revision);
list.addTarget(SvnTarget.fromURL(url, revision);
list.setReceiver(new ISvnObjectReceiver<SVNDirEntry>() {
public void receive(SvnTarget target, SVNDirEntry object) throws SVNException {
final String name = object.getRelativePath();
System.out.println(name);
}
});
list.run();
這裏是我用於相同目的的代碼(使用svnkit library)。 @ mstrap代碼的修改版本更好的清晰度。
public static String NAME = "svnusername";
public static String PASSWORD = "svnpass";
public final String TRUNK_VERSION_PATH = "svn://192.168.1.1/path";
public static List<String> apiVersions;
public List<String> getApiVersion() {
logger.info("Getting API Version list....");
apiVersions = new ArrayList<String>();
SVNURL repositoryURL = null;
try {
repositoryURL = SVNURL.parseURIEncoded(TRUNK_VERSION_PATH);
} catch (SVNException e) {
logger.error(e);
}
SVNRevision revision = SVNRevision.HEAD;
SvnOperationFactory operationFactory = new SvnOperationFactory();
operationFactory.setAuthenticationManager(new BasicAuthenticationManager(NAME, PASSWORD));
SvnList list = operationFactory.createList();
list.setDepth(SVNDepth.IMMEDIATES);
list.setRevision(revision);
list.addTarget(SvnTarget.fromURL(repositoryURL, revision));
list.setReceiver(new ISvnObjectReceiver<SVNDirEntry>() {
public void receive(SvnTarget target, SVNDirEntry object) throws SVNException {
String name = object.getRelativePath();
if(name!=null && !name.isEmpty()){
apiVersions.add(name);
}
}
});
try {
list.run();
} catch (SVNException ex) {
logger.error(ex);
}
return apiVersions;
}
乾杯!
Svnkit 1.3.5沒有這段代碼中提到的任何類(除了SVNDepth)。有沒有其他的方法來實現這個使用svnkit-1.3.5的類? – SKR
爲什麼不使用SVN 1.7版本的SVNKit?它也支持SVN 1.6。 – mstrap
感謝您的想法。如果你可以完成代碼而不是放置...供用戶選擇,那將會更好。 :) – Vivek