Svnkit Learning-using the high-level API to manage working copy samples (vi)

Source: Internet
Author: User
Tags create directory tojson

This article is a Svnkit high-level API-based operation for working copy, similar to the SVN graphical interface and command line.

High-level API Class Diagram:

Core idea:

 All operations are managed by a variety of svn*client, and the Svnclientmanager class encapsulates all svn*client, so we usually have two approaches (more toward the latter):

1. Various svn*client classes can be instantiated separately. 2. Instantiate a Svnclientmanager class, which actually instantiates each svn*client class when it first requests the Svnclient class.

Sample code:

 PackageCom.demo;ImportCom.google.gson.Gson;ImportOrg.tmatesoft.svn.core.*;ImportOrg.tmatesoft.svn.core.auth.ISVNAuthenticationManager;Importorg.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;ImportOrg.tmatesoft.svn.core.wc.*;ImportJava.io.File;/*** Using the Hign-level API to manipulate working Copy, it is relatively easy to understand because all operations are closer to the SVN command line and client-side operations. * Different operations for working copy are categorized into different svn*client, Svnclientmanager classes contain these svn*client, so it is often convenient to manage them with Svnclientmanager classes svn* Client * So we have two options for manipulating working copy: 1. You can instantiate various svn*client classes separately. 2. Instantiate a Svnclientmanager class, which actually instantiates each svn*client class when it first requests the Svnclient class. * Detailed structure See class diagram*/ Public classmanageworkingcopy {Private StaticSvnclientmanager Svnclientmanager; Private Static FinalGson Gson =NewGson ();  Public Static voidMain (string[] args)throwsexception{//1. Initial chemical plant According to the access AgreementDavrepositoryfactory.setup (); //2. Use the default optionsIsvnoptions isvnoptions = svnwcutil.createdefaultoptions (true); //3. Initialize PermissionsString username = "Wly"; String Password= "Wly"; Char[] pwd =Password.tochararray (); Isvnauthenticationmanager Isvnauthenticationmanager=Svnwcutil.createdefaultauthenticationmanager (USERNAME,PWD); //4. Create an instance of SvnclientmanagerSvnclientmanager =svnclientmanager.newinstance (Isvnoptions,isvnauthenticationmanager); //=========================================demo start=======================================//1. Import-import//Doimport (); //2. Check out-checkout//docheckout (); //3. Create a directory-mkdir//Domkdir (); //4. Submit-commit//Docommit (); //5. Update-update//doupdate (); //6. Toggle Branch-switch//7. Add-add, which is reflected in commit, before submission, no version control files need to be added to version control//8. Lock-lock//DoLock (); //9. Delete-delete//DoDelete (); //10. Copy-copy//docopy (); //11. Status-status//Dostatus (); //12. Information-info//doinfo ();    }    /** Import-import * @throws svnexception*/    Private Static voidDoimport ()throwssvnexception{svnproperties svnproperties=Newsvnproperties (); BooleanUseglobalignores =true; BooleanIgnoreunknownnodetypes =true; Svncommitinfo Svncommitinfo= Svnclientmanager.getcommitclient (). Doimport (NewFile ("E:\\svnworkspace\\commonproject"), svnurl.parseuriencoded ("Https://wlyfree-PC:8443/svn/testRepository/trunk"), "Initialize import", svnproperties,useglobalignores,ignoreunknownnodetypes,svndepth.infinity); System.out.println ("The import operation was successful and the results were imported:" +Gson.tojson (svncommitinfo)); }    /*** Check out-checkout * Parameters: * Warehouse Address * Local Working copy address * Peg Revision * Revision * Check out depth, general recursive check Out * Whether to allow no version of the obstacle, true to allow, false is not allowed, false in checkout if there is an obstacle will stop checking out, so is generally true * return value: Long current version number *@throwssvnexception*/    Private Static voidDocheckout ()throwssvnexception{LongNowrevision = Svnclientmanager.getupdateclient (). Docheckout (svnurl.parseuriencoded ("https://wlyfree-PC:8443/svn/ Testrepository/trunk "),NewFile ("E:\\svnworkspace\\projectworkingcopy"), Svnrevision.head,svnrevision.head,svndepth.infinity,true); System.out.println ("The execution of the checkout operation succeeded, the currently checked out version number is:" +nowrevision); }    /*** Create directory-mkdir *@throwssvnexception*/    Private Static voidDomkdir ()throwssvnexception{String commitmessage= "Create a directory"; Svncommitinfo Svncommitinfo= Svnclientmanager.getcommitclient (). Domkdir (Newsvnurl[]{svnurl.parseuriencoded ("Https://wlyfree-PC:8443/svn/testRepository/trunk/aaa"), svnurl.parseuriencoded ("HTTPS://WLYFREE-PC:8443/SVN/TESTREPOSITORY/TRUNK/BBB")},commitmessage); System.out.println ("Perform mkdir operation successfully, operation result:" +Gson.tojson (svncommitinfo)); }    /*** Commit-commit * Commit to change a file, if the file itself exists, you need to submit its parent directory *@throwssvnexception*/    Private Static voidDocommit ()throwssvnexception{file[] Files=Newfile[]{NewFile ("E:\\svnworkspace\\projectworkingcopy"),NewFile ("E:\\SVNWORKSPACE\\PROJECTWORKINGCOPY\\CCC")}; //do not perform an add operation without a version number         for(File tempfile:files) {svnstatus status= Svnclientmanager.getstatusclient (). Dostatus (Tempfile,true);            SYSTEM.ERR.PRINTLN (status); if(Status = =NULL|| Status.getcontentsstatus () = =svnstatustype.status_unversioned) {System.out.println ("File" + tempfile.getname () + "No version number"); Svnclientmanager.getwcclient (). Doadd (Tempfile,false,false,false, Svndepth.infinity,false,false); }        }        //perform a commit operationSvnclientmanager.getcommitclient (). Setignoreexternals (false); Svnproperties svnproperties=Newsvnproperties (); String[] Changelists=Newstring[]{}; Svncommitinfo Svncommitinfo= Svnclientmanager.getcommitclient (). Docommit (Files,false, "Submit action", Svnproperties,changelists,false,false, Svndepth.fromrecurse (true)); System.out.println ("The commit operation succeeded, operation result:" +Gson.tojson (svncommitinfo)); }    /*** Update-update *@throwssvnexception*/    Private Static voidDoUpdate ()throwssvnexception{LongNowrevision = Svnclientmanager.getupdateclient (). DoUpdate (NewFile ("E:\\svnworkspace\\projectworkingcopy"), Svnrevision.head, Svndepth.infinity,true,false); System.out.println ("The update operation was performed successfully, the current version number:" +nowrevision); }    /*** Lock-lock *@throwssvnexception*/    Private Static voidDoLock ()throwssvnexception{//svnclientmanager.getwcclient (). DoLock (New svnurl[]{svnurl.parseuriencoded ("Https://wlyfree-PC: 8443/svn/testrepository/trunk/bbb/aa.txt ")},true," Add Lock to File ");Svnclientmanager.getwcclient (). DoLock (Newfile[]{NewFile ("E:\\svnworkspace\\projectworkingcopy\\bbb\\aa.txt")},true, "Lock the file"); System.out.println ("Lock file successfully"); }    /*** Delete-delete *@throwssvnexception*/    Private Static voidDoDelete ()throwssvnexception{svncommitinfo svncommitinfo= Svnclientmanager.getcommitclient (). DoDelete (Newsvnurl[]{svnurl.parseuriencoded ("https://wlyfree-PC:8443/svn/testRepository/trunk/bbb"), svnurl.parseuriencoded ("Https://wlyfree-PC:8443/svn/testRepository/trunk/b.txt")}, "Perform the delete operation, delete a directory bbb a file B.txt"); System.out.println ("Execute delete operation succeeded, operation result:" +Gson.tojson (svncommitinfo)); }    /*** Copy-copy *@throwssvnexception*/    Private Static voidDocopy ()throwssvnexception{Svncopysource SvnCopySource1=NewSvncopysource (svnrevision.head,svnrevision.head,svnurl.parseuriencoded ("https://wlyfree-PC:8443/svn/ Testrepository/trunk/aaa/aa.txt ")); Svncopysource SvnCopySource2=NewSvncopysource (svnrevision.head,svnrevision.head,svnurl.parseuriencoded ("https://wlyfree-PC:8443/svn/ Testrepository/trunk/aaa/bb.txt ")); Svnclientmanager.getcopyclient (). Docopy (NewSvncopysource[]{svncopysource1,svncopysource2},NewFile ("e:\\svnworkspace\\projectworkingcopy\\bbb"),false,false,true); System.out.println ("Execute copy operation succeeded"); }    /*** Status-status *@throwssvnexception*/    Private Static voidDostatus ()throwssvnexception{svnstatus svnstatus= Svnclientmanager.getstatusclient (). Dostatus (NewFile ("E:\\svnworkspace\\projectworkingcopy\\a.txt"),true); System.out.println ("Execution status operation succeeded, operation result:" +Gson.tojson (svnstatus)); }    /*** Information-info *@throwssvnexception*/    Private Static voidDoinfo ()throwssvnexception{svninfo svninfo= Svnclientmanager.getwcclient (). Doinfo (NewFile ("E:\\svnworkspace\\projectworkingcopy\\a.txt"), svnrevision.head); System.out.println ("Execute info operation succeeded, operation result:" +Gson.tojson (svninfo)); }}

Svnkit Learning-using the high-level API to manage working copy samples (vi)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.