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
Views: 71093
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.

run-configuration

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).

 

select-plugin

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.

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.

available-checkin-policy

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.

code-review-checkin

Just select the newly created custom check-in policy and click OK. Code Review policy is shown as enabled.

code-review-enabled

To test that check-in policy, we will make a small change in the code of SSGS EMS team project.

code-change

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.

pending-changes

 

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.

export-policy

In the wizard that started, select Plug-in development > Deployable Plugin and Features. deployable-plugin

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. plugins-fragments 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. export Now we can  Add the Code Review Check-in Policy from the settings checkin-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.

policy-warning

Summary:

To create a TFS 11 Custom Check-in Policy, you need to follow these conditions:

1. Download and install

  • Team Explorer Everywhere 11 in Eclipse
  • Eclipse for Plugin Development
  • TFS SDK 11 (for Java)

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!
Recommended Articles
Subodh Sohoni, Team System MVP, is an MCTS – Microsoft Team Foundation Server – Configuration and Development and also is a Microsoft Certified Trainer(MCT) since 2004. Subodh has his own company and conducts a lot of corporate trainings. He is an M.Tech. in Aircraft Production from IIT Madras. He has over 20 years of experience working in sectors like Production, Marketing, Software development and now Software Training. Follow him on twitter @subodhsohoni


Page copy protected against web site content infringement by Copyscape


User Feedback
Comment posted by Brandon on Friday, June 1, 2012 5:37 AM
@Subodh - Congratulations on your site completing 5 years. I have gained immensly from your tutorials and I just wanted to say "thank you"
Comment posted by Subodh Sohoni on Tuesday, June 5, 2012 12:14 PM
Thanks Brandon!
Comment posted by ram on Saturday, June 23, 2012 3:06 PM
Hi Subodh, I hope you can help me in this.
I want get TFS certified professional and have few questions in mind so could please answer below questions for me:
1)How many papers do i have attempt ?
2)What is the fee for exam ?
3)From where i can get study materials ?

Thanks
Comment posted by Subodh Sohoni on Sunday, June 24, 2012 10:33 AM
Hi Ram,
For TFS 2010 there is only one certification and one exam for that. It is 70-512 which is for TFS 2010 Administration. There is no exam for using TFS. For TFS 2012 there will be 3 exams which will be ready in another 4-5 months or so. You need to give this exam at Prommetric center. You can find one in your city. They will be charging aprx. USD 100 worth in your local currency (Aprx. 5000 Rupees if you are in India). Study material is not muc available. You can find the syallabus on Microsoft Learning site and for many of the topics you will find some videos on our website (http://www.ssgsonline.com/downloads.aspx).
Comment posted by Stu on Monday, May 13, 2013 1:27 PM
Hello, Great article thanks.  If a conflict should arise after evaluate method is called (I'm copying files from source at this point) and the developer decided to cancel checkin, do you have an idea on how the copy (already executed) could be rolled back?
Thanks!

Post your comment
Name:  
E-mail: (Will not be displayed)
Comment:
Insert Cancel