Pages

Friday, August 28, 2009

Well, I din expect i will have a topic to write so soon after join for MS course. But, thanks to Dr. Li I had a chance to work with java again!!! I love java! So, here goes a tutorial which explains how to use javacvs lib.

I will explain important snippets here, will provide the complete source at the end of the tutorial.

Step 1: Create the CVS Root object defining the meta data such as username, host etc To do this, we have to read the CVS/Root file.

LogListenerIt extends BasicListener, and overrides the messageSent with an empty definition. It also overrides the fileInfoGenerated method, where the actual processing of each file is done. That is log each of file. The snippet is below.

//Handle control to Super class. super.fileInfoGenerated(fileinfoevent);

logToExcel is a simple method that writes the log to the file. The datastructure LogInformation has data related to the file being processed, all the revisions of the file, head revision, the message associated with each revision and lot of more details. I use only the ones I mentioned.The complete code including the LogListener is below. Ignore the logic that is being done at logToExcel method, that some thing related to my work. But, the goal is to know that fileInfoEvent has LogInformation, that can be used to see data. You can write different listeners, builders in the similar way.

/* * Create a client that can execute the cvs log command, and register the listener to be invoked for CVS outputs. */ Client client = new Client(connection, new StandardAdminHandler()); client.setLocalPath(cvsPath); client.getEventManager().addCVSListener(new LogListener());

/* * The log command that does the job of getting the log for every file in the * directory. * The log builder is responsible to invoke fileinfo events on the loglistner. */ LogCommand command = new LogCommand(); command.setRecursive(true); Builder builder = new LogBuilder(client.getEventManager(), command); command.setBuilder(builder);