Java打Tag CvsClient

增量编译的时候需要一个一个文件打Tag,不方便,网上也没发现现成的资料,

还好碰到个参考http://gblyh.bokee.com/6107026.html的,下了jar包,

以下是看了参考文章与jar反编译源代码写的用Java代码打Tag。

(本人写这个目的其实是为了对用wincvs工具cvs -history的导出清单文件进行逐一打tag时方便些,

 不用在Eclipse一个一个文件右击Team-->Tag as version-->...)

 

步骤:

 

1.下载http://javacvs.netbeans.org/files/documents/51/640/org-netbeans-lib-cvsclient.jar

2.相应的代码

   

import org.netbeans.lib.cvsclient.CVSRoot;
import org.netbeans.lib.cvsclient.Client;
import org.netbeans.lib.cvsclient.admin.StandardAdminHandler;
import org.netbeans.lib.cvsclient.command.Command;
import org.netbeans.lib.cvsclient.command.CommandAbortedException;
import org.netbeans.lib.cvsclient.command.GlobalOptions;
import org.netbeans.lib.cvsclient.command.tag.TagCommand;
import org.netbeans.lib.cvsclient.commandLine.BasicListener;
import org.netbeans.lib.cvsclient.connection.AuthenticationException;
import org.netbeans.lib.cvsclient.connection.Connection;
import org.netbeans.lib.cvsclient.connection.ConnectionFactory;

public class CVSClient {

	private Client cvsclient;
	private final CVSRoot cvsroot;
	private Connection connection;
	private String localPath;

	public CVSClient(String connectionString) {
		cvsroot = CVSRoot.parse(connectionString);
	}

	public String getLocalPath() {
		return localPath;
	}

	public void setLocalPath(String localPath) {
		this.localPath = localPath;
	}

	public void openConnection() throws AuthenticationException, CommandAbortedException {
		connection = ConnectionFactory.getConnection(cvsroot);
		connection.open();
	}

	public void closeConnection() throws IOException {
		connection.close();
	}

	public void excute(Command command) throws Exception {
		cvsclient = new Client(connection, new StandardAdminHandler());
		cvsclient.setLocalPath(localPath);
		cvsclient.getEventManager().addCVSListener(new BasicListener());
		System.out.println("Command>>>>>" + command.getCVSCommand());
		cvsclient.executeCommand(command, new GlobalOptions());
	}

	public static void main(String[] args) throws Exception {
		CVSClient cvsclient = new CVSClient(":pserver:username:password@IP:/dir/dir1/dir2");
		cvsclient.setLocalPath("E:/workspace/");
		cvsclient.openConnection();
		TagCommand tagCommon = new TagCommand();
		tagCommon.setTag("TagNameXXXXX");
		tagCommon.setFiles(new File[] { new File("E:/workspace/CVSClient/src/FileVersion.java") });
		tagCommon.setTagByRevision("1.4");// 设定Tag打到哪个版本的文件上,不加的话Tag会默认打到最新版本上
		tagCommon.setOverrideExistingTag(true);// 一定要加这句
		cvsclient.excute(tagCommon);

		cvsclient.closeConnection();
	}
}

/**
 * WARNING TO DEVELOPERS: Please be warned that attempting to reuse one open connection for more commands is not
 * supported by cvs servers very well. You are advised to open a new Connection each time. If you still want to proceed,
 * please do: System.setProperty("javacvs.multiple_commands_warning", "false") That will disable this message.
 */

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值