1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
   |  
public void cvsUpdate(String localPath, String userName, String password, String hostName, String repository) throws CommandAbortedException, CommandException, AuthenticationException {
		PServerConnection connection = new PServerConnection();
		connection.setUserName(userName);
		connection.setEncodedPassword(password);
		connection.setHostName(hostName);
		connection.setRepository(repository);
		connection.open();
 
		GlobalOptions globalOptions = new GlobalOptions();
	    globalOptions.setCVSRoot(getCVSRoot());
 
		Client client = new Client(connection, new StandardAdminHandler());
		client.setLocalPath(localPath);
		client.getEventManager().addCVSListener(new BasicListener());
		UpdateCommand command = new UpdateCommand();
		command.setBuilder(null);
 
		command.setRecursive(true);
		command.setBuildDirectories(true);
		command.setPruneDirectories(true);
 
		client.executeCommand(command, globalOptions);
	}
 
private String getCVSRoot() {
		String root = null;
		BufferedReader r = null;
		try {
			File f = new File(System.getProperty("user.dir"));
			File rootFile = new File(f, "CVS/Root");
			if (rootFile.exists()) {
				r = new BufferedReader(new FileReader(rootFile));
				root = r.readLine();
			}
		} catch (IOException e) {
			// ignore
		} finally {
			try {
				if (r != null)
					r.close();
			} catch (IOException e) {
				System.err.println("Warning: could not close CVS/Root file!");
			}
		}
		if (root == null) {
			root = System.getProperty("cvs.root");
		}
		return root;
	}
 
public static void main(String[] args) {
CVSUtils.singleton().cvsUpdate("C:\testrepos", "anoncvs", "", "cvs.netbeans.org", "/cvs/javacvs");
} | 
Partager