Java打Tag CvsClient

阎德业
2023-12-01

增量编译的时候需要一个一个文件打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.
 */

 

 

 类似资料: