首页>代码>java获取svn信息的开源框架>/javasvn/src/com/javaniu/Main.java
package com.javaniu;

import java.util.Collection;
import java.util.Iterator;

import org.tmatesoft.svn.core.SVNDirEntry;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNNodeKind;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;
import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory;
import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl;
import org.tmatesoft.svn.core.io.SVNRepository;
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
import org.tmatesoft.svn.core.wc.SVNWCUtil;

public class Main {

	public static void main(String[] args) {
		String url = "http://svn.svnkit.com/repos/svnkit/trunk/svnkit/";
		String name = "anonymous";
		String password = "anonymous";
		setupLibrary();
		SVNRepository repository = null;
		try {
			repository = SVNRepositoryFactory.create(SVNURL
					.parseURIEncoded(url));
		} catch (SVNException svne) {
			System.err
					.println("error while creating an SVNRepository for location '"
							+ url + "': " + svne.getMessage());
			System.exit(1);
		}

		ISVNAuthenticationManager authManager = SVNWCUtil
				.createDefaultAuthenticationManager(name, password);
		repository.setAuthenticationManager(authManager);

		try {
			SVNNodeKind nodeKind = repository.checkPath("", -1);
			if (nodeKind == SVNNodeKind.NONE) {
				System.err.println("There is no entry at '" + url + "'.");
				System.exit(1);
			} else if (nodeKind == SVNNodeKind.FILE) {
				System.err.println("The entry at '" + url
						+ "' is a file while a directory was expected.");
				System.exit(1);
			}
			System.out.println("Repository Root: "
					+ repository.getRepositoryRoot(true));
			System.out.println("Repository UUID: "
					+ repository.getRepositoryUUID(true));
			System.out.println("");

			listEntries(repository, "");
		} catch (SVNException svne) {
			System.err.println("error while listing entries: "
					+ svne.getMessage());
			System.exit(1);
		}
		long latestRevision = -1;
		try {
			latestRevision = repository.getLatestRevision();
		} catch (SVNException svne) {
			System.err
					.println("error while fetching the latest repository revision: "
							+ svne.getMessage());
			System.exit(1);
		}
		System.out.println("");
		System.out.println("---------------------------------------------");
		System.out.println("Repository latest revision: " + latestRevision);
		System.exit(0);

	}

	private static void setupLibrary() {
		DAVRepositoryFactory.setup();
		SVNRepositoryFactoryImpl.setup();
		FSRepositoryFactory.setup();
	}

	public static void listEntries(SVNRepository repository, String path)
			throws SVNException {
		Collection entries = repository.getDir(path, -1, null,
				(Collection) null);
		Iterator iterator = entries.iterator();
		while (iterator.hasNext()) {
			SVNDirEntry entry = (SVNDirEntry) iterator.next();
			System.out.println("/" + (path.equals("") ? "" : path + "/")
					+ entry.getName() + " (author: '" + entry.getAuthor()
					+ "'; revision: " + entry.getRevision() + "; date: "
					+ entry.getDate() + ")");
		}
	}

}
最近下载更多
707518301  LV1 2022年4月1日
hzs4744  LV1 2021年5月27日
哈哈哈哈hhh  LV5 2020年12月1日
600000  LV3 2020年4月21日
248196826  LV13 2019年5月30日
小威尔史密斯  LV10 2019年4月1日
Only_乐  LV1 2019年3月30日
jiqinwei  LV1 2019年3月28日
zhangwei1  LV1 2019年3月13日
xiaoaaa  LV1 2018年12月20日
最近浏览更多
颜菜菜  LV2 2023年12月30日
707518301  LV1 2022年4月1日
crosa_Don  LV18 2022年3月31日
hzs4744  LV1 2021年5月27日
哈哈哈哈hhh  LV5 2020年12月1日
lczd888  LV9 2020年11月2日
agooder  LV1 2020年8月12日
136618075  LV2 2020年5月21日
wuhaigang  LV9 2020年4月26日
600000  LV3 2020年4月21日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友