-SVNClientAdapter

Subclipseのライブラリとして、SVNClientAdapterというものがあります。これは、Subversionと同時開発のJavahlというJNIを使ったライブラリおよびPureJavaで別途開発されている代替のJavaSVNと、愚直にコマンドを叩くものをアダプタとしていて、その上位に構築されたSVNJavaクライアントライブラリです。こっちのほうがJavaSVNを直で叩くより無難(?)な感じな気がする。。。javahl+SVNClientAdapterだとJavaSVNがまだ対応していないfile://プロトコルも対応できます。

public class SVNCliantAdapterRD {
    static {
        try {
            JhlClientAdapterFactory.setup();
        } catch (SVNClientException ignore) {
        }
        try {
            JavaSvnClientAdapterFactory.setup();
        } catch (SVNClientException ignore) {
        }
        try {
            CmdLineClientAdapterFactory.setup();
        } catch (SVNClientException ignore) {
        }
    }
    public static void main(String args) 
    		throws MalformedURLException, SVNClientException {
        String type = SVNClientAdapterFactory.getPreferredSVNClientType();
        System.out.println("adapter type: " + type);
        ISVNClientAdapter client = SVNClientAdapterFactory.createSVNClient(type);
        client.setUsername("masataka");
        client.setPassword("gluegent");
        ISVNDirEntry entry = client.getList(
                new SVNUrl("svn://localhost:3690/Maya"), SVNRevision.HEAD, false);
        for(int i = 0; i < entry.length; i++) {
            String path = entry[i].getPath();
            SVNNodeKind kind = entry[i].getNodeKind();
            long revision = entry[i].getLastChangedRevision().getNumber();
            long size = entry[i].getSize(); 
            System.out.println(path + ":" + revision + 
                kind + "[ " + size + "bytes]"); 
        }
    }
}

今回はAuthもしてみました。ちなみに、JavaSVNでは以下のようにAuthします。

repository.setCredentialsProvider(
    new SVNSimpleCredentialsProvider("masataka", "gluegent"));