Java批量從svn導(dǎo)出多個(gè)項(xiàng)目代碼實(shí)例
近期工作中要對(duì)很多項(xiàng)目加相同的依賴,需要將很多項(xiàng)目都從svn導(dǎo)出,感覺一個(gè)個(gè)導(dǎo)太慢了,由于不會(huì)寫腳本就從晚上找到svn拉代碼的程序,稍作修改很快就拉完了所有代碼。直接上必要代碼
必要pom
<dependency> <groupId>org.tmatesoft.svnkit</groupId> <artifactId>svnkit</artifactId> <version>1.10.1</version> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.8</version> </dependency>
必要代碼
@Slf4j public class SvnService { private SVNClientManager clientManager; public void checkOut(final SvnConfig config) { final String user = config.getSourceSvnUser(); final String password = config.getSourceSvnPassword(); final String sourceSvn = config.getSourceSvn() + config.getSourceProject(); try { //初始化支持svn://協(xié)議的庫。 必須先執(zhí)行此操作。 SVNRepositoryFactoryImpl.setup(); //相關(guān)變量賦值 SVNURL repositoryURL = SVNURL.parseURIEncoded(sourceSvn); ISVNOptions options = SVNWCUtil.createDefaultOptions(true); //實(shí)例化客戶端管理類 this.clientManager = SVNClientManager.newInstance( (DefaultSVNOptions) options, user, password); //要把版本庫的內(nèi)容check out到的目錄 File wcDir = new File(config.getSourceCheckOutDir()); //通過客戶端管理類獲得updateClient類的實(shí)例。 SVNUpdateClient updateClient = this.clientManager.getUpdateClient(); // sets externals not to be ignored during the checkout updateClient.setIgnoreExternals(false); //執(zhí)行check out操作,返回工作副本的版本號(hào)。 long workingVersion = updateClient.doCheckout( repositoryURL, wcDir, SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.INFINITY, false); log.info("VERSION:{} check out to {}", workingVersion, wcDir); } catch (Exception e) { log.error("SvnService.doCheckOut error: ", e); } } public void update(final SvnConfig config) { final String user = config.getSourceSvnUser(); final String password = config.getSourceSvnPassword(); final String sourceSvn = config.getSourceSvn() + config.getSourceProject(); try { //初始化支持svn://協(xié)議的庫。 必須先執(zhí)行此操作。 SVNRepositoryFactoryImpl.setup(); //相關(guān)變量賦值 SVNURL.parseURIEncoded(sourceSvn); ISVNOptions options = SVNWCUtil.createDefaultOptions(true); //實(shí)例化客戶端管理類 this.clientManager = SVNClientManager.newInstance( (DefaultSVNOptions) options, user, password); //要更新的文件 File updateFile = new File(config.getSourceCheckOutDir()); //獲得updateClient的實(shí)例 SVNUpdateClient updateClient = this.clientManager.getUpdateClient(); updateClient.setIgnoreExternals(false); //執(zhí)行更新操作 long versionNum = updateClient.doUpdate(updateFile, SVNRevision.HEAD, SVNDepth.INFINITY, false, false); log.info("updated version is {}", versionNum); } catch (Exception e) { log.info(e.getMessage() + "{}", e); } } public void commit(final SvnConfig config) { final String user = config.getSourceSvnUser(); final String password = config.getSourceSvnPassword(); final String sourceSvn = config.getSourceSvn() + config.getSourceProject(); try { //初始化支持svn://協(xié)議的庫。 必須先執(zhí)行此操作。 SVNRepositoryFactoryImpl.setup(); //相關(guān)變量賦值 SVNURL.parseURIEncoded(sourceSvn); ISVNOptions options = SVNWCUtil.createDefaultOptions(true); //實(shí)例化客戶端管理類 this.clientManager = SVNClientManager.newInstance( (DefaultSVNOptions) options, user, password); //要提交的文件 File commitFile = new File(config.getSourceCheckOutDir()); //獲取此文件的狀態(tài)(是文件做了修改還是新添加的文件?) SVNStatus status = this.clientManager.getStatusClient().doStatus(commitFile, true); //如果此文件是新增加的則先把此文件添加到版本庫,然后提交。 if (status.getContentsStatus() == SVNStatusType.STATUS_UNVERSIONED) { //把此文件增加到版本庫中 this.clientManager.getWCClient().doAdd(commitFile, false, false, false, SVNDepth.INFINITY, false, false); //提交此文件 this.clientManager.getCommitClient().doCommit( new File[]{commitFile}, true, "", null, null, true, false, SVNDepth.INFINITY); System.out.println("add"); } //如果此文件不是新增加的,直接提交。 else { this.clientManager.getCommitClient().doCommit( new File[]{commitFile}, true, "", null, null, true, false, SVNDepth.INFINITY); System.out.println("commit"); } System.out.println(status.getContentsStatus()); } catch (Exception e) { log.error(e.getMessage() + "{}", e); } } }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
通過案例了解靜態(tài)修飾符static使用場(chǎng)景
這篇文章主要介紹了通過案例了解靜態(tài)修飾符static使用場(chǎng)景,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-10-10Spring Security UserDetails實(shí)現(xiàn)原理詳解
這篇文章主要介紹了Spring Security UserDetails實(shí)現(xiàn)原理詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-09-09一文徹底弄懂零拷貝原理以及java實(shí)現(xiàn)
零拷貝(英語: Zero-copy) 技術(shù)是指計(jì)算機(jī)執(zhí)行操作時(shí),CPU不需要先將數(shù)據(jù)從某處內(nèi)存復(fù)制到另一個(gè)特定區(qū)域,下面這篇文章主要給大家介紹了關(guān)于零拷貝原理以及java實(shí)現(xiàn)的相關(guān)資料,需要的朋友可以參考下2021-08-08在CentOS系統(tǒng)上安裝Java的openjdk的方法
這篇文章主要介紹了在CentOS系統(tǒng)上安裝Java的openjdk的方法,同樣適用于Fedora等其他RedHat系的Linux系統(tǒng),需要的朋友可以參考下2015-06-06JSP頁面pageEncoding和contentType屬性
有關(guān)于JSP頁面中pageEncoding和contentType屬性。2013-04-04解決Springboot 2 的@RequestParam接收數(shù)組異常問題
這篇文章主要介紹了解決Springboot 2 的@RequestParam接收數(shù)組異常問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-08-08java實(shí)現(xiàn)靜默加載Class示例代碼
這篇文章主要給大家介紹了關(guān)于java實(shí)現(xiàn)靜默加載Class的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用java具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2017-10-10