0

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();
Chad Nouis
  • 6,861
  • 1
  • 27
  • 28
  • 1
    Possible duplicate of [What is a NullPointerException, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – Rafael May 02 '17 at 13:25

1 Answers1

0

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.

Chad Nouis
  • 6,861
  • 1
  • 27
  • 28
  • We added Authentication to svn url and we are facing Exception in thread "main" org.tmatesoft.svn.core.SVNException: svn: File not found: revision 1540882, path 'srcURL' svn: '/svn/sag/!svn/bc/1540882/srcURL' path not found: 404 Not Found (http://svnva.ame.ad.sag:1818) . Please let me know if anything else i need to add to copy srcURL to dstURL. – Vinayak Mulgund May 04 '17 at 10:27
  • Authentication 'DAVRepositoryFactory.setup(); SVNRepository repository = null; repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded("Repository URL")); ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager("auto", "auto"); repository.setAuthenticationManager(authManager);' – Vinayak Mulgund May 04 '17 at 10:30
  • Calling SVNCopyClient 'SVNURL srcUrl =SVNURL.parseURIEncoded("SrcURL"); SVNURL dstUrl=SVNURL.parseURIEncoded("DstUrl"); SVNClientManager SM = SVNClientManager.newInstance(); SM.setAuthenticationManager(authManager); SM.createRepository(SVNURL.parseURIEncoded("RepoUrl"), true);SVNCopyClient copyClient=SM.getCopyClient(); SVNCopySource copySource=new SVNCopySource(SVNRevision.HEAD, SVNRevision.HEAD, srcUrl); SVNProperties P = new SVNProperties(); P.put("username","auto"); P.put("password","auto"); copyClient.doCopy(new SVNCopySource[]{copySource},destUrl,false,true,false,"message",P);' – Vinayak Mulgund May 04 '17 at 10:35
  • And we have given valid srcURL – Vinayak Mulgund May 04 '17 at 10:38
  • For example srcURL is http://{host}/svn/aaa/eb/tags/99main. I'm facing svn: File not found: revision 1540902, path '/eb/tags/99main/eb/tags/99main'(appending the srcURL to srcURL not sure why) /1540902/eb/tags/99main' path not found: 404 Not Found (http://{}host:{port}). – Vinayak Mulgund May 04 '17 at 12:25
  • This line isn't right: `SVNURL srcUrl =SVNURL.parseURIEncoded("SrcURL")`. It should be: `SVNURL srcUrl =SVNURL.parseURIEncoded("http://{host}/svn/aaa/eb/{your_branch_here}")`. – Chad Nouis May 04 '17 at 13:24
  • Hi , Line is correct just for sake of example i mentioned SVNURL srcUrl =SVNURL.parseURIEncoded("SrcURL"); we are using SVNURL srcUrl =SVNURL.parseURIEncoded("http://{host}/svn/aaa/eb/{your_bran‌​ch_here}"); as you mentioned in previous comment. we assume that some where in "SVNCopySource" or "doCopy" , scrURL is getting appended again. – Vinayak Mulgund May 04 '17 at 15:03