SVN KIT API

1 minute read


package com.xx;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
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.io.SVNRepository;
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
import org.tmatesoft.svn.core.wc.SVNWCUtil;

public class FileSvnInfo
{
Log log = LogFactory.getLog(FileSvnInfo.class);

/*
* Default values:
*/
String url = "http://proddev-svn/svn/norkom/Prototypes/Ref2_Transliteration/trunk";
String name = "xx";
String password = "xx";
String filePath = "changelog.txt";

public FileSvnInfo()
{
SVNRepository repository = createSVNRepository();
log.info(createSVNRepository().getLocation().toString());

getFileInfo(repository,"changelog.txt");
getFileInfo(repository,"./Engineering");

}

private void getFileInfo(SVNRepository repository, String filePath)
{
try
{
SVNNodeKind kind = repository.checkPath(filePath, -1);
if(kind.equals(SVNNodeKind.FILE))
log.info(SVNNodeKind.FILE+" "+filePath);
else if(kind.equals(SVNNodeKind.DIR))
log.info(SVNNodeKind.DIR+" "+filePath);
else if(kind.equals(SVNNodeKind.NONE))
log.info(SVNNodeKind.NONE+" "+filePath);
else if(kind.equals(SVNNodeKind.UNKNOWN))
log.info(SVNNodeKind.UNKNOWN+" "+filePath);
}
catch(SVNException e)
{
e.printStackTrace();
}
}

private SVNRepository createSVNRepository()
{
SVNRepository repository = null;
try {
/*
* Creates an instance of SVNRepository to work with the repository.
* All user's requests to the repository are relative to the
* repository location used to create this SVNRepository.
* SVNURL is a wrapper for URL strings that refer to repository locations.
*/
repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url));
} catch (SVNException svne) {
/*
* Perhaps a malformed URL is the cause of this exception
*/
System.err
.println("error while creating an SVNRepository for the location '"
+ url + "': " + svne.getMessage());
System.exit(1);
}

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

return repository;
}

private static void setupLibrary()
{
/*
* For using over http:// and https://
*/
DAVRepositoryFactory.setup();
/*
* For using over svn:// and svn+xxx://
*/
//SVNRepositoryFactoryImpl.setup();

/*
* For using over file:///
*/
FSRepositoryFactory.setup();
}

/**
* @param args
*/
public static void main(String[] args)
{
setupLibrary();
new FileSvnInfo();
}
}

Categories:

Updated:

Leave a Comment