public class CVSClient { /** Cvs clinet instance used to communicate with cvs server */ private Client cvsclient; /** Cvs connect string */ private CVSRoot cvsroot; /** Connection instance to keep connect with cvs server */ private Connection connection; /** Global options to store the requied parameter for cvs server */ private GlobalOptions globalOptions; /** The local path on ur local machine */ private String localPath; /** * Inner class extend CVSAdapter
*
used to get and send message of the CVS server
* */ class BasicListener extends CVSAdapter {? /**? * Stores a tagged line? */? private final StringBuffer taggedLine = new StringBuffer();? /**? * Called when the server wants to send a message to be displayed to the? * user. The message is only for information purposes and clients can? * choose to ignore these messages if they wish.? *? ? * @param e? *? ? ? ? ? ? the event? */? public void messageSent(MessageEvent e) {? String line = e.getMessage();? PrintStream stream = e.isError() ? System.err : System.out;? if (e.isTagged()) {? ? String message = MessageEvent.parseTaggedMessage(taggedLine,? ? ? "Daniel Six");? ? // if we get back a non-null line, we have something? ? // to output. Otherwise, there is more to come and we? ? // should do nothing yet.? ? if (message != null) {? ? stream.println(message);? ? }? } else {? ? stream.println(line);? }? } }? ? /**? ? * Default constructor allows to construct CVSRoot from Properties object.? ? * The names are exactly the same as the attribute names in this class.? ? */ public CVSClient() { }? ? /**? ? * Breaks the string representation of CVSClient into it's components:? ? *? ? * The valid format (from the cederqvist) is:? ? *? ? * :method:[[user][:password]@]hostname[:[port]]/path/to/repository? ? *? ? * e.g. :pserver;username=anonymous;hostname=localhost:/path/to/repository? ? */? public CVSClient(String connectionString) {? cvsroot = CVSRoot.parse(connectionString); } /**? * Get the localPath? * @return localPath the local path to get project from the CVS server? * */ public String getLocalPath() {? return localPath; } /**? * Set the localPath? *? * */ public void setLocalPath(String localPath) {? this.localPath = localPath; }? /**? * Parse the CVSROOT string into CVSRoot object.? *? ? ? * The valid format (from the cederqvist) is:? ? *? ? * :method:[[user][:password]@]hostname[:[port]]/path/to/repository? ? *? ? * e.g. :pserver;username=anonymous;hostname=localhost:/path/to/repository? */ public void createConnection(String connectionString) {? cvsroot = CVSRoot.parse(connectionString); } /**? * Open connection to the cvs server
*? * @return connection to cvs server? * @throws AuthenticationException? * @throws CommandAbortedException? */ public Connection openConnection() throws AuthenticationException,? CommandAbortedException {? connection = ConnectionFactory.getConnection(cvsroot);? connection.open();? return connection; }? /**? * Close connection to the cvs server
* */ public void closeConnection() throws IOException{? connection.close(); }? /**? *
Excute cvs command
*? * @param command to be excute by the cliet? * @throws AuthenticationException? * @throws CommandAbortedException? * @throws IOException? * @throws CommandException? */ public void excute(Command command) throws AuthenticationException,? CommandAbortedException, IOException, CommandException {? cvsclient = new Client(connection, new StandardAdminHandler());? cvsclient.setLocalPath(localPath);? globalOptions = new GlobalOptions();? globalOptions.setCVSRoot("d:/client/java");? cvsclient.getEventManager().addCVSListener(new BasicListener());? //put the command to the console? System.out.println("***Command***"+command.getCVSCommand());? cvsclient.executeCommand(command, globalOptions); } /**? *
Called when need add files
* @param files that indicate to be added? * @return command of add files? */ public Command add(String[] files) {? AddCommand command = new AddCommand();? command.setBuilder(null);? for (int i = 0; i < files.length; i++) {? command.setFiles(new File[] { new File(files[i]) });? }? return command; } /**? * Called when need commit all files under the local path? * @return command command of commit files? */ public Command commit() {? CommitCommand command = new CommitCommand();? command.setBuilder(null);? command.setForceCommit(true);? command.setRecursive(true);? return command; } /**? * Called when need commit files? * @param files need to be commit? * @return command command of commit files? * */ public Command commit(String[] files) {? CommitCommand command = new CommitCommand();? for (int i = 0; i < files.length; i++) {? command.setFiles(new File[] { new File(files[i])});? }? command.setBuilder(null);? command.setForceCommit(true);? command.setRecursive(true);? return command; } /**? * Called when need update the certain files? * @param files need to be update? * @return command command of update files and directoris? * */ public Command update(String[] files) {? UpdateCommand command = new UpdateCommand();? //fetch files from the array? for (int i = 0; i < files.length; i++) {? command.setFiles(new File[] { new File(files[i]) });? }? command.setBuilder(null);? command.setRecursive(true);? command.setBuildDirectories(true);? command.setPruneDirectories(true);? return command; } /**? * Called to show the history list since given date? * @param date Date of the history? *@return command command show history list? * */ public Command historysincedate(String date){? HistoryCommand command=new HistoryCommand();? //Format is yyyymmdd e.g 20070205? command.setSinceDate(date);? return command; }? /**? *Called to show the history list since given version? *@param reversion reversion of the history? *@return command command show history list? **/ public Command historysincerRevision(String reversion){? //Init command? HistoryCommand command=new HistoryCommand();? //set parameters? command.setSinceRevision(reversion);? return command; }? /**? * Called to show the different between two versions? * @param files the files to compare with? * @param revision1 one revision? * @param revision2 another revision? * @return? * */ public Command diffbyreveision(String[] files,String revision1,String revision2){? //Inite command? DiffCommand command=new DiffCommand();? //Set parameters? for(int i=0;i
2018-06-09
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
- 文/潘曉璐 我一進(jìn)店門(mén),熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)稻轨,“玉大人灵莲,你說(shuō)我怎么就攤上這事∨咕悖” “怎么了政冻?”我有些...
- 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)粱挡。 經(jīng)常有香客問(wèn)我赠幕,道長(zhǎng),這世上最難降的妖魔是什么询筏? 我笑而不...
- 正文 為了忘掉前任榕堰,我火速辦了婚禮,結(jié)果婚禮上嫌套,老公的妹妹穿的比我還像新娘逆屡。我一直安慰自己,他們只是感情好踱讨,可當(dāng)我...
- 文/花漫 我一把揭開(kāi)白布魏蔗。 她就那樣靜靜地躺著,像睡著了一般痹筛。 火紅的嫁衣襯著肌膚如雪莺治。 梳的紋絲不亂的頭發(fā)上廓鞠,一...
- 那天,我揣著相機(jī)與錄音谣旁,去河邊找鬼床佳。 笑死,一個(gè)胖子當(dāng)著我的面吹牛榄审,可吹牛的內(nèi)容都是我干的砌们。 我是一名探鬼主播,決...
- 文/蒼蘭香墨 我猛地睜開(kāi)眼搁进,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼浪感!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起饼问,我...
- 序言:老撾萬(wàn)榮一對(duì)情侶失蹤影兽,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后匆瓜,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體赢笨,經(jīng)...
- 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
- 正文 我和宋清朗相戀三年驮吱,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了茧妒。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
- 正文 年R本政府宣布,位于F島的核電站除破,受9級(jí)特大地震影響牧氮,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜瑰枫,卻給世界環(huán)境...
- 文/蒙蒙 一踱葛、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧光坝,春花似錦尸诽、人聲如沸。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至鸳惯,卻和暖如春商蕴,著一層夾襖步出監(jiān)牢的瞬間叠萍,已是汗流浹背。 一陣腳步聲響...
- 正文 我出身青樓部宿,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親瓢湃。 傳聞我的和親對(duì)象是個(gè)殘疾皇子理张,可洞房花燭夜當(dāng)晚...
推薦閱讀更多精彩內(nèi)容
- Spring Cloud為開(kāi)發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見(jiàn)模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn)绵患,斷路器雾叭,智...
- Getting Started Use the Current Stable Version (7.1) Buil...
- 活動(dòng)簡(jiǎn)述: 活動(dòng)時(shí)間:2017.01.10-2017.02.14 活動(dòng)對(duì)象:曙光里附近社區(qū)老年人家庭 活動(dòng)方式:呼...
- 這幾天看《春風(fēng)十里不如你》织狐,看到了軍訓(xùn)中的小玉。一個(gè)來(lái)自鄉(xiāng)下筏勒,第一次到大城市的女孩兒移迫。在軍訓(xùn)時(shí),很多同學(xué)討論的話題...