Run and Deploy Custom Check-in policy using TFS SDK 11 for Java
Posted by: Subodh Sohoni ,
on 4/20/2012,
in
Category Visual Studio, VSTS & TFS
Abstract: In this article we will explore how to debug and run a custom check-in policy using TFS SDK 11 and then deploy it on a developer’s machine.
In the last article, we created a custom check-in policy using TFS SDK 11 for Java. In this article we will explore, how to debug / run that policy and then deploy it on a developer’s machine.
Now that the coding of the check-in policy is over, let us see how to debug that. To debug a plugin, we have to create a Run Configuration. Open the Run configuration editor from Run menu.
Click the Eclipse Application and click on the New Run configuration icon. This action will create a configuration and open it for editing. Change the name to CP_Configuration. We can use the same configuration for Debug too from Run > Debug Configurations or you may as well create it as Debug Configuration. In addition to name change, also check the checkbox against the Plugin that I had created earlier (the check-in policy).
Now, when we click on the Run button (or Debug button if we are in Debug configuration), it starts another instance of Eclipse and allows us to Run or Debug the plugin. In this new instance, we can now check if the Check-in Policy is available and does it work or not. Open menu Help > Team Explorer Support.
In the property pages that appears, select Diagnostic Data tab and then under the node of Team Explorer, select Available Check-in Policies. In the list of check-in policies, we can see the newly created custom check-in policy for Code Review.

Clos these pages and select Team Foundation Server Exploring perspective. Then connect to a Team Project (in my case SSGS EMS) and from the settings page, select Check-in Policies. When you click on the Add button, it shows the newly created custom check-in policy.

Just select the newly created custom check-in policy and click OK. Code Review policy is shown as enabled.
To test that check-in policy, we will make a small change in the code of SSGS EMS team project.

Now when we attempt to check-in that pending change, check-in policy evaluation will fail and in the Policy Messages tab, it displays that Check-in is not allowed since Code Review check-in policy is not satisfied.

Deploying the Custom Check-in Policy
Now that we are satisfied that this check-in policy works, let us deploy it. After closing the second instance of Eclipse, export the check-in policy so that it can be deployed. First set the release version to 1.0.0.0 in the manifest (META-INF\MANIFEST.MF). Then select File > Export from menu.
In the wizard that started, select Plug-in development > Deployable Plugin and Features.
In the wizard that started, select Plug-in development > Deployable Plugin and Features.
On the next page, check the checkbox against the created check-in policy plugin and then select the radio button to export it into an archive. Create a folder (D:\Java\Created Plugins) to hold the archives of the plugins that we selected, gave the name to the archive as ‘Code Review Check-in Policy’ and click on the Finish button. In the target folder, this plugin archive is created as a zipped archive.
Now let us deploy it to the regular instance of Eclipse (not the one that is used for plugin development). Open the main folder of Eclipse and drill down to the folder named ‘dropins’ . The JAR that is in the.zip file that was created by the export wizard, is copied in this folder.
Now we can Add the Code Review Check-in Policy from the settings
And if you try to check-in without associating the code review work item the policy gets evaluated and the warning is shown in the Pending Changes window, Policy warnings tab.
Summary:
To create a TFS 11 Custom Check-in Policy, you need to follow these conditions:
1. Download and install
2. Add TEE 11 for Eclipse for Plugin Development too
3. Create a Plugin project
4. Add JAR that is provided in TFS SDK 11 as referenced library
5. Configure plugin with Dependencies and Extension Point
6. Extend the PolicyBase class in to plugin class.
7. Implement all overridable methods. Main logic of check-in policy should go in the Evaluate method
8. Trial Run or Debug can be done using Run / Debug configuration
9. Deploy the plugin by first exporting it in the archive and then copying that JAR in the dropins folder of Eclipse.
Give me a +1 if you think it was a good article. Thanks!