[[Main]] .+ [[What_Is_Subversion_For|What Is Subversion For]] .+ [[Setting_Up_A_Subversion_Repository|Setting Up A Subversion Repository]] .+ [[SVNKit_Architecture|SVNKit Architecture]] .+ [[Getting_Started_With_SVNKit|Getting Started With SVNKit]] .+ [[Authentication]] .+ [[Managing_Repository_With_SVNKit|Managing Repository With SVNKit]] .- Printing Out A Subversion Repository Tree .+ [[Printing_Out_File_Contents|Printing Out File Contents]] .+ [[Printing_Out_Repository_History|Printing Out Repository History]] .+ [[Committing_To_A_Repository|Editing operation: committing to a repository]] .+ [[Updating_From_A_Repository|Editing Operation: receiving changes from a repository]] .+ [[Replicating_An_Existing_Repository|Replicating An Existing Repository]] .+ [[Managing_A_Working_Copy|Managing A Working Copy]] ---- = Printing out a Subversion repository tree = The first thing we will try - observing a Subversion repository. First we need to set up the library to use the protocol which we would like to access a repository through. In this example we will use the {{{http://}}} protocol to observe a world-readable repository: {{{#!java import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory; ... public class DisplayRepositoryTree { public static void main(String[] args) { DAVRepositoryFactory.setup(); ... }}} We need a URL of the repository and credentials (here we use some dummy ones since we think an Apache will let us read repository contents, but you may change them to some valid credentials to observe repositories closed to unregistered persons). Having these parameters we create an [[http://svnkit.com/kb/javadoc/org/tmatesoft/svn/core/io/SVNRepository.html|SVNRepository]] driver for the selected location: {{{#!java ... String url = "http://svn.svnkit.com/repos/svnkit/trunk/doc"; String name = "anonymous"; String password = "anonymous"; SVNRepository repository = null; try { repository = SVNRepositoryFactory.create( SVNURL.parseURIDecoded( url ) ); ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager( name , password ); repository.setAuthenticationManager( authManager ); ... }}} We have got a repository access driver with a default authentication manager. Let's print out some information identifying the repository itself - its root location path and UUID: {{{#!java ... System.out.println( "Repository Root: " + repository.getRepositoryRoot( true ) ); System.out.println( "Repository UUID: " + repository.getRepositoryUUID( true ) ); ... }}} If everything is Ok (we connected to our repository successfully and cached its UUID and root location), we are moving further. Now we will check whether the url we are going to use corresponds to a directory. If it does not, we are finished. {{{#!java ... 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 ); } ... }}} Repository nodes are represented by [[http://svnkit.com/kb/javadoc/org/tmatesoft/svn/core/SVNNodeKind.html|SVNNodeKind]] enum objects. Here and later we use an invalid revision number -1 to mean that the latest revision must be used. The next step - writing a function which will recursively call itself to traverse the repository tree starting at a particular path (parameter) and print out all contents: {{{#!java 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( ) + ")" ); if ( entry.getKind() == SVNNodeKind.DIR ) { listEntries( repository, ( path.equals( "" ) ) ? entry.getName( ) : path + "/" + entry.getName( ) ); } } } }}} This function receives a path of a repository subtree which is to be printed out. Using a {{{getDir(...)}}} method of the repository access driver passed it reads the contents of the current path which are represented by [[http://svnkit.com/kb/javadoc/org/tmatesoft/svn/core/SVNDirEntry.html|SVNDirEntry]] objects. If an entry is a directory the function recursively calls itself with the path of that directory. And so on. Collected '''SVNDirEntry''' objects contain such information as the last change revision, author, and date-stamp. From our {{{main()}}} program we call {{{listEntries()}}} passing our driver object and the current path that the driver is bound to: {{{#!java ... listEntries( repository , "" ); ... }}} At the end of the program we can finish with printing the latest revision of our repository: {{{#!java ... latestRevision = repository.getLatestRevision( ); System.out.println( "Repository latest revision: " + latestRevision ); ... } catch ( SVNException svne ) { //handle exception } } } }}} And finally we run the program and have the following output in our console: {{{ Repository Root: http://svn.svnkit.com/repos/svnkit Repository UUID: 0a862816-5deb-0310-9199-c792c6ae6c6e /examples (author: 'sa'; revision: 2794; date: Tue Nov 14 03:21:11 NOVT 2006) /examples/svnkit-examples.iml (author: 'alex'; revision: 2775; date: Fri Nov 10 02:08:45 NOVT 2006) /examples/src (author: 'sa'; revision: 2794; date: Tue Nov 14 03:21:11 NOVT 2006) /examples/src/org (author: 'sa'; revision: 2794; date: Tue Nov 14 03:21:11 NOVT 2006) /examples/src/org/tmatesoft (author: 'sa'; revision: 2794; date: Tue Nov 14 03:21:11 NOVT 2006) /examples/src/org/tmatesoft/svn (author: 'sa'; revision: 2794; date: Tue Nov 14 03:21:11 NOVT 2006) /examples/src/org/tmatesoft/svn/examples (author: 'sa'; revision: 2794; date: Tue Nov 14 03:21:11 NOVT 2006) /examples/src/org/tmatesoft/svn/examples/wc (author: 'alex'; revision: 2776; date: Fri Nov 10 02:25:08 NOVT 2006) ...................................................... --------------------------------------------- Repository latest revision: 2802 }}} ---- Download the [[http://svn.svnkit.com/repos/svnkit/tags/1.3.5/doc/examples/src/org/tmatesoft/svn/examples/repository/DisplayRepositoryTree.java |example program source code]].