Wednesday, September 29, 2010

How to Get VSS files via Java Code?

Most of the time, to access VSS we’ll either use Command Line arguments or some build scripts from Java. Now, this is actually possible through java codes by using ANT APIs, which does the command line process in the background.

In this post I’m using an example on how to get files from VSS (check-in and check-out will be more or less the same) using ANT API. To make it possible, you need to make use of the “org.apache.tools.ant.taskdefs.optional.vss” package which contains classes to access VSS. Class “MSVSSGET” and some methods of its super class “MSVSS” will be used to carry out the Get process.
Let me explain the code fragment line-by-line:

  1. setLogin – This method is from the abstract class MSVSS used for authentication purpose. The String parameter has to be formatted as “username,password”.
  2. setSsdir – Is also from the class MSVSS which specifies the location of SS.EXE (VSS executable file).
  3. setRecursive – This method is from MSVSSGET class which enables to retrieve all sub-projects of the project specified in VSS path
  4. setProject – This is a method from the superclass ProjectComponent, used to specify a project for the VSS activity.
  5. setServerpath – A method from MSVSS class used to specify the VSS repository’s path (folder which contains the file called srcsafe.ini)
  6. setTaskName - A method from superclass Task used to assign a task name for the VSS activity.
  7. setDescription – A method from superclass ProjectComponent used to specify the description of the activity.
  8. setLocalpath – Method from the class MSVSSGET to assign the location on where to store the files retrieved from VSS.
  9. setVsspath – Method from superclass MSVSS used to assign the project path within the VSS repository. (e.g $/YourProject).
  10. execute – method from the superclass MSVSS used to run the command line argument to execute SS.EXE
For further understanding on the “org.apache.tools.ant.taskdefs.optional.vss” package, kindly refer to this site:

Reference:
Author: Thiagu