Colin的Checkin插件是自定義簽入策略,TFS支持這種自定義簽入策略。因此,您可以使用適用於Java的SDK構建類似的自定義簽入策略。
開發之前辦理登機手續的政策,您需要:
下載並安裝
爲Eclipse添加TEE的插件開發過
創建一個插件項目
這裏是一個blog,可提供詳細的步驟來開發,測試和部署Eclipse IDE和TFS的自定義註釋檢查策略。你可以把它作爲參考。
此外,下面的代碼(捕獲來自this article)是代碼審查的例子赤,在2012年TFS的政策,這將有助於您:
package com.ssgs.tfs.policies.codereview;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import com.microsoft.tfs.core.checkinpolicies.PolicyBase;
import com.microsoft.tfs.core.checkinpolicies.PolicyContext;
import com.microsoft.tfs.core.checkinpolicies.PolicyContextKeys;
import com.microsoft.tfs.core.checkinpolicies.PolicyEditArgs;
import com.microsoft.tfs.core.checkinpolicies.PolicyEvaluationCancelledException;
import com.microsoft.tfs.core.checkinpolicies.PolicyFailure;
import com.microsoft.tfs.core.checkinpolicies.PolicyType;
import com.microsoft.tfs.core.checkinpolicies.events.PolicyStateChangedListener;
import com.microsoft.tfs.core.clients.versioncontrol.soapextensions.WorkItemCheckinInfo;
import com.microsoft.tfs.core.clients.workitem.WorkItem;
import com.microsoft.tfs.core.memento.Memento;
import com.microsoft.tfs.core.pendingcheckin.PendingCheckin;
public class CodeReviewCheckinPolicyClass extends PolicyBase {
private final static PolicyType TYPE = new PolicyType(
"com.ssgs.tfs.policies.codereview.CodeReviewCheckinPolicyInstance",
"Code Review Checkin Policy","Disallows checkin if Code Review work item with approved state is not associated with the check-in",
"This check-in policy forces developers to get their code reviewed from experts before it can be checked in. "
+ "It checks for associated work item of the type Code Review that has state of approved.",
"Download the check-in policy package and install it in your Eclipse");
public CodeReviewCheckinPolicyClass() {
super();
}
@Override
public void close() {
// TODO Auto-generated method stub
}
@Override
public void activate(PolicyFailure arg0, PolicyContext context) {
final Shell shell = (Shell) context.getProperty(PolicyContextKeys.SWT_SHELL);
if (shell == null)
{
return;
}
/*
* activate() is called on the UI thread, so we don't have to explicitly
* run our work on the UI thread.
*/
final MessageBox helpMessageBox = new MessageBox(shell, SWT.ICON_INFORMATION);
helpMessageBox.setText("Activation Dialog");
helpMessageBox.setMessage("Policy activated.");
helpMessageBox.open();
}
@Override
public void addPolicyStateChangedListener(PolicyStateChangedListener arg0) {
// TODO Auto-generated method stub
}
@Override
public boolean canEdit() {
return false;
}
@Override
public void displayHelp(PolicyFailure arg0, PolicyContext context) {
final Shell shell = (Shell) context.getProperty(PolicyContextKeys.SWT_SHELL);
if (shell == null)
{
return;
}
/*
* displayHelp() is called on the UI thread, so we don't have to
* explicitly run our work on the UI thread.
*/
final MessageBox helpMessageBox = new MessageBox(shell, SWT.ICON_INFORMATION);
helpMessageBox.setText("Code Review Check-in Policy Help");
helpMessageBox.setMessage("Associate a code review check-in policy with Approved state to successfully checking in the pending changes");
helpMessageBox.open();
}
@Override
public boolean edit(PolicyEditArgs arg0) {
return false;
}
@Override
public PolicyFailure[] evaluate(PolicyContext context)
throws PolicyEvaluationCancelledException
{
final PendingCheckin pc = getPendingCheckin();
final List<PolicyFailure> failures = new ArrayList<PolicyFailure>();
final WorkItemCheckinInfo[] AssociatedWorkItems = pc.getWorkItems().getCheckedWorkItems();
WorkItem AssociatedCodeReview = null;
String failureReason = "";
for (int i=0; i<AssociatedWorkItems.length; i++)
{
AssociatedCodeReview = AssociatedWorkItems[i].getWorkItem();
if (AssociatedCodeReview.getType().getName() == "Code Review")
{
break;
}
}
if (AssociatedCodeReview != null)
{
if (AssociatedCodeReview.getFields().getField("System.State").getValue().toString().equals("Not Approved"))
{
failureReason = "Code Review Work Item associated but that is not approved by expert";
failures.add(new PolicyFailure(failureReason, this));
}
}
else
{
failureReason = "Code Review Work Item not associated";
failures.add(new PolicyFailure(failureReason, this));
}
return failures.toArray(new PolicyFailure[failures.size()]);
}
@Override
public PolicyType getPolicyType() {
return CodeReviewCheckinPolicyClass.TYPE;
}
@Override
public void removePolicyStateChangedListener(PolicyStateChangedListener arg0) {
// TODO Auto-generated method stub
}
@Override
public void loadConfiguration(Memento arg0) {
// TODO Auto-generated method stub
}
@Override
public void saveConfiguration(Memento arg0) {
// TODO Auto-generated method stub
}
}
這解決了一個問題,在那裏我可以執行代碼簽入策略,另一個問題是我想從eclipse編輯器中創建代碼審查請求。科林代碼審查插件有。我如何從Eclipse編輯器創建代碼審閱請求? –