NullPointerException calling SvnAnt's Copy.setRevision

74 views Asked by At

I'm trying to perform SVN copy operation (creating a tag from a branch) using Java.

I'm getting the below exception.

"Exception in thread "main" java.lang.NullPointerException

at org.tigris.subversion.svnant.SvnFacade.getFacade(Unknown Source)

at org.tigris.subversion.svnant.SvnFacade.getSetting(Unknown Source)

at org.tigris.subversion.svnant.SvnFacade.getDateFormatter(Unknown Source)

at org.tigris.subversion.svnant.commands.SvnCommand.getDateFormatter(Unknown Source)

at org.tigris.subversion.svnant.commands.SvnCommand.getRevisionFrom(Unknown Source)

at org.tigris.subversion.svnant.commands.Copy.setRevision(Unknown Source)

at svnOperation.createTags.commitTags(createTags.java:55)

at svnOperation.createTags.main(createTags.java:23)"

I'm using the latest SVN JAR files.

Could someone please suggest how to correct this or what mistake I'm doing here.

Here is my code:

Project p = new Project();
p.setProperty("username", "automation");
p.setProperty("password", "automation");
p.setProperty("javahl", "true");
p.setProperty("javahl", "true");
SvnTask svn = new SvnTask();

Copy C1 = new Copy();

C1.setDescription("Creating tags");
C1.setSrcUrl(new SVNUrl("SrcUrl"));
C1.setDestUrl(new SVNUrl("DestUrl"));
C1.setMessage("message");
C1.setRevision("1234"); 
C1.setProject(p);

svn.addCopy(C1);
svn.setProject(p);
svn.execute();
1

There are 1 answers

7
Chad Nouis On

SvnAnt is designed to be used from Ant scripts. However, it appears you're trying to interact with Subversion with Java code.

SVNKit is the better way to access Subversion features from within a Java application.

Here is an example of creating a Subversion tag:

SVNCopyClient copyClient =
    SVNClientManager.newInstance().getCopyClient();

SVNURL srcURL = SVNURL.parseURIEncoded("http://example.com/repos/trunk");
SVNURL dstURL = SVNURL.parseURIEncoded("http://example.com/repos/tags/tag");
SVNCopySource copySource =
    new SVNCopySource(SVNRevision.HEAD, SVNRevision.HEAD, srcURL);

copyClient.doCopy(new SVNCopySource[] {copySource}, dstURL,
    false, false, true, "message", null); 

See Getting Started With SVNKit for more.