RE: How to retrieve the revision of a committed file?

"David Hosier" <[email protected]> Fri, 16 Dec 2005 08:40:22 -0800
Newsgroups gmane.comp.java.netbeans.modules.javacvs.devel
Organization Longview Software
Message-ID <[email protected]>
This is what you can do....

Write a listener that extends the CVSAdapter class.  Specifically, you want
to override the fileInfoGenerated(FileInfoEvent ) method.  I grab the
revision from the FileInfoEvent object and store it in a global variable of
my class and add an accessor method to get the revision when the commit
exits.  To do this you would need to instantiate an instance of your
listener outside of your method that does the committing so you have access
to it when the commit returns.  Here is my code that I use in the
fileInfoGenerated() method:

public void fileInfoGenerated(FileInfoEvent event)
{
	super.fileInfoGenerated(event);
	_revision =
((CommitInformation)event.getInfoContainer()).getRevision();
} 

-----Original Message-----
From: [email protected] [mailto:[email protected]] 
Sent: Friday, December 16, 2005 3:08 AM
To: [email protected]
Subject: [javacvs-dev] How to retrieve the revision of a committed file?

Hi all,

I'm new to the javacvs library, so apologize, if this is a stupid
question...

I want to commit a file to the CVS repository, and read the response of the
server to retrieve the revision of the file just checked in. What is the
state-of-the-art way to do this?

Should I parse one the messages of a messageSent event (such as "new
revision: 1.14; previous revision: 1.13"), or is there a more elegant way? 
I wonder about  the meaning of isTagged()... (never saw "true" in my tests).

Can I use the CommitInformation class for this purpose (and if so, how)?


Thanks a lot,

--
Manni

P.S.: The code of a sample app follows (without imports):

public class TestRetrieveRevision {

	public class InfoListener extends CVSAdapter {
		public void messageSent(MessageEvent e) {
			// parse the message?? Or a more elegant way?
	    	System.out.println("message:  " + e.getMessage()); 
	    	System.out.println("isTagged: " + e.isTagged());  // always
false
		}
	}


    private String cvsroot = ":pserver:mb@Halley:2401/srv/cvs/repository0";
    private String passWord = "xxxxxx";
    private String path     = "D:/tmp/workingdir/testfile.txt";

	private void doIt() throws AuthenticationException, CommandException
{
		GlobalOptions globalOptions = new GlobalOptions();
		globalOptions.setCVSRoot(cvsroot);

		PServerConnection connection = 
			new PServerConnection(CVSRoot.parse(cvsroot),
SocketFactory.getDefault());
		connection.setEncodedPassword(
	
StandardScrambler.getInstance().scramble(passWord));
		connection.open();


		// The files array contains exactly one File
		File[] files = new File[1];
		files[0] = new File(path);

		String localPath = files[0].getParent();

		Client client = new Client(connection, new
StandardAdminHandler());
		client.setLocalPath(localPath);
		client.getEventManager().addCVSListener(new InfoListener());

		// run the commit command
		CommitCommand command = new CommitCommand();
		command.setBuilder(
				new CommitBuilder(client.getEventManager(),
localPath, cvsroot));
		command.setRecursive(false);

		// set the file to be commited
		command.setFiles(files);

		System.out.println(command.getCVSCommand());
		client.executeCommand(command, globalOptions);
	}


	public static void main(String[] args) throws
AuthenticationException, CommandException {
		TestRetrieveRevision test = new TestRetrieveRevision();
		test.doIt();
	}
}

__________________________________________________________________
Nur bis 31.12.: 1&1 DSL mit WEB.DE Preisvorteil! Jetzt einsteigen und die
Vorteile sichern! http://1und1dsl.web.de/?mc=021130


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]