SKR
SKR

Reputation: 473

How to get list of folders present in a directory in SVN using java

I am using svnkit-1.3.5.jar in my application. On one of my screens on clicking a button I need to display a jQuery dialog box containing list of folders present at a particular path in SVN. Does svnkit provide any method that retrieves all folder names present at a specific location? How do I achieve this in java?

Upvotes: 2

Views: 5452

Answers (2)

Vivek
Vivek

Reputation: 3613

Here is the code i use for the same purpose (uses svnkit library). Modified version of @mstrap's code for better clarity.

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;
    }

Cheers!!

Upvotes: 6

mstrap
mstrap

Reputation: 17443

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();

Upvotes: 2

Related Questions