NAnt Examples

Examples of programs integrating with Vault and Fortress API. Also, information on integrating with NAnt, CruiseControl.Net and other third-party tools

Moderator: SourceGear

Post Reply
shannon

NAnt Examples

Post by shannon » Mon Jun 11, 2007 2:55 pm

The following NAnt example scripts were written for version 4.0.1.

The first four scripts will work with either Vault or Fortress, but the last two highlight bug tracking tasks and require Fortress.

Code: Select all

<project name="testSourceControl" default="testSourceControlTasks" xmlns="http://nant.sf.net/schemas/nant.xsd">
  <!--This script demonstrates basic source control tasks:  setting the login options, adding a repository, connecting to a repository, creating a folder, and adding files.-->
  <target name="testSourceControlTasks">
    <!--Load the Fortress or Vault Nant tasks-->
    <loadtasks path="c:/path/to/nant/tasks/dll" verbose="true" />
    <!--Set the login options:  username, password, and server url-->
    <vaultsetloginoptions user="username" password="password" URL="http://VaultServer/VaultService" />
    <!--Add a repository.-->
    <vaultaddrepository newReposName="NantTestRep" />
    <!--Connect to NantTestRep-->
    <vaultsetrepository repositoryName="NantTestRep" />
    <!--Create a folder.-->
    <vaultcreatefolder comment="Create someNewFolder." newFolderPath="$/someNewFolder/" />
    <!--Add two files to someNewFolder.-->
    <vaultadd comment="Add two files to someNewFolder." folderPath="$/someNewFolder/" >
      <fileset>
        <include name="c:/path/to/some/file" />
        <include name="c:/path/to/another/file" />
      </fileset>
    </vaultadd>
  </target>
</project>

Code: Select all

<project name="testSourceControl" default="testSourceControlTasks" xmlns="http://nant.sf.net/schemas/nant.xsd">
  <!--This script demonstrates the following tasks:  setting a working folder, get, checkout, checkin, list checkouts, and history.-->
  <target name="testSourceControlTasks">
    <loadtasks path="c:/path/to/nant/tasks/dll" verbose="true" />
    <!--Set login options:  username, password, url, repository.-->
    <vaultsetloginoptions user="username" password="password" URL="http://VaultServer/VaultService" repository="NantTestRep" />
    <!--Set a working folder.-->
    <vaultsetworkingfolder repositoryFolderPath="$/someNewFolder" diskPath="c:/your/working/folder/" createDiskPath="true" />
    <!--Do a get on the working folder.-->
    <vaultget>
      <vaultfileset>
        <include name="c:/your/working/folder/" />
      </vaultfileset>
      <getoptions Recursive="true" />
    </vaultget>
    <!--Exclusively check out a file.-->
    <vaultcheckout checkoutExclusive="true">
      <vaultfileset>
        <include name="$/someNewFolder/someFile" />
      </vaultfileset>
    </vaultcheckout>
    <!--List all checkouts.-->
    <vaultlistcheckouts />
    <!--Check in the file we just checked out, set the unchanged handler to check in the item (the default unchanged op is Undo Checkout).-->
    <vaultcheckin unchanged="CheckIn">
      <vaultfileset>
        <include name="$/someNewFolder/someFile" />
      </vaultfileset>
    </vaultcheckin>
    <!--Query the file history so we can view the checkin.  Set beginVersion=endVersion=-1 to display all versions.-->
    <vaulthistory objectPath="$/someNewFolder/someFile" beginVersion="-1" endVersion="-1" />
  </target>
</project>

Code: Select all

<?xml version="1.0" encoding="utf-16"?>
<project name="testSourceControl" default="testSourceControlTasks" xmlns="http://nant.sf.net/schemas/nant.xsd">
  <!--This script demonstrates vaultgettolocationoutsideworkingfolder.-->
  <target name="testSourceControlTasks">
    <!--Load the Fortress or Vault Nant tasks-->
    <loadtasks path="c:/path/to/nant/tasks" verbose="true" />
    <!--Set the login options:  username, password, and server url-->
    <vaultsetloginoptions user="username" password="password" URL="http://VaultServer/VaultService" repository="NantTestRep" />
    <!--Get files.-->
    <vaultgettolocationoutsideworkingfolder destPath="C:/dest/path/on/disk">
      <vaultfileset>
        <include name="$/path/to/some/file" />
      </vaultfileset>
    </vaultgettolocationoutsideworkingfolder>
  </target>
</project>

Code: Select all

<project name="testSourceControl" default="testSourceControlTasks" xmlns="http://nant.sf.net/schemas/nant.xsd">
  <!--This script demonstrates the following tasks:  get wildcard and get wildcard to nonworking folder.-->
  <target name="testSourceControlTasks">
    <loadtasks path="c:/path/to/nant/tasks/dll" />
    <!--Set the login options:  username, password, server url, and repository.-->
    <vaultsetloginoptions user="username" password="password" URL="http://VaultServer/VaultService" repository="NantTestRep" />
    <!--Add some files to try wildcard tasks on.-->
    <vaultadd comment="Add wildcard files." folderPath="$/someNewFolder/" >
      <fileset>
        <include name="c:/path/to/wildcard1.txt" />
        <include name="c:/path/to/wildcard2.txt" />
        <include name="c:/path/to/wildcardWithLetters.txt" />
      </fileset>
    </vaultadd>
    <!--Get wildcard1.txt and wildcard2.txt to a nonworking folder.-->
    <vaultgetwildcardtononworkingfolder folderPath="$/someNewFolder/" destPath="c:/path/to/nonWF/">
      <vaultwildcardarray>
        <include name="wildcard*.txt" />
      </vaultwildcardarray>
    </vaultgetwildcardtononworkingfolder>
    <!--Get all three wildcard files to the working folder.-->
    <vaultgetwildcard folderPath="c:/path/to/workingfolder/" >
      <vaultwildcardarray>
        <include name="wildcard?.txt" />
      </vaultwildcardarray>
    </vaultgetwildcard>
  </target>
</project>

Code: Select all

<?xml version="1.0" encoding="utf-16"?>
<project name="testNant" default="testLabel" xmlns="http://nant.sf.net/schemas/nant.xsd">
    <!--This script demonstrates the following tasks:  label and get label to location outside working folder.-->
    <target name="testLabel">
        <loadtasks path="c:/path/to/nant/tasks" verbose="true" />
        <!--Set the login options:  username, password, server url and repository.-->
        <vaultsetloginoptions user="username" password="password" URL="http://VaultServer/VaultService" repository="A Repository" />
        <!--Label an item.-->
        <vaultlabel objectPath="$/path/to/folderToLabel" labelName="LabeledFolder" />
        <!--Get label to a location on disk.-->
        <vaultgetlabeltolocationoutsideworkingfolder objectPath="$/path/to/folderToLabel" label="LabeledFolder" destPath="c:/temp/labeledFolder" />
    </target>
</project>
The following two scripts require FortressTasks.dll.

Code: Select all

<?xml version="1.0" encoding="utf-16"?>
<project name="testFortressItemTracking" default="testFortressTasks" xmlns="http://nant.sf.net/schemas/nant.xsd">
    <!--This script demonstrates how to list the open items for a project and add a new item to a project.-->
    <target name="testFortressTasks">
        <loadtasks path="c:/path/to/nant/tasks/dll" verbose="true" />
        <!--Set the login options:  username, password, and server url.-->
        <vaultsetloginoptions user="username" password="password" URL="http://FortressServer/VaultService" />
        <!--List the open items for anotherProject.-->
        <vaultlistopenfortressitems projectName="anotherProject" />
        <!--Add an item to anotherProject.-->
        <vaultaddfortressitem>
            <fortressitemexpanded ProjectName="anotherProject" ItemType="Feature" Status="Open" Platform="Windows" TimeEstimate="Unknown" Description="feature created from nant build script" Priority="Low" Details="some details" />
        </vaultaddfortressitem>
        <!--List the open items for anotherProject.-->
        <vaultlistopenfortressitems projectName="anotherProject" />
    </target>
</project>
Note: Starting with version 4.0.2 the xpath for the xmlpeek task in the following script must be changed to "/root/vaulthistory/bugsreferenced"

Code: Select all

<?xml version="1.0" encoding="utf-16"?>
<project name="testFortressItemTracking" default="testFortressTasks" xmlns="http://nant.sf.net/schemas/nant.xsd">
    <!--This script demonstrates the following tasks:  list object properties, history, and add fortress item comment.-->
    <target name="testFortressTasks">
        <loadtasks path="c:/path/to/nant/tasks" verbose="true" />
        <!--Set the login options:  username, password, and server url.-->
        <vaultsetloginoptions user="username" password="password" URL="http://FortressServer/VaultService" repository="Initial Repository" />
        <!--List the properties for a file.-->
        <vaultlistobjectproperties objectPath="$/path/to/someFile" outputfile="c:/temp/fileProperties" />
        <!--Extract the current version from the file properties.-->
        <xmlpeek file="c:/temp/fileProperties" xpath="/root/vaultlistobjectproperties/vaulttreeobject/version" property="currentVersion" />
        <!--Using currentVersion, get the most recent history for that file.-->
        <vaulthistory objectPath="$/path/to/someFile" beginVersion="${currentVersion}" endVersion="${currentVersion}" outputfile="c:/temp/historyfile" />
        <!--Extract the bugsreferenced element from the history.-->
        <xmlpeek file="c:/temp/historyfile" xpath="/root/vaulthistory/history/bugsreferenced" property="bugIds" />
        <!--Loop over bugIds and modify each item.-->
        <foreach item="String" in="${bugIds}" delim=" ," property="bugid">
            <vaultaddfortressitemcomment bugID="${bugid}" comment="This item was referenced in build 1.1.x" />
        </foreach>
    </target>
</project>

Post Reply