PolicyDefinition result return empty collection using Java SDK of TFS 2015 “tp.getCheckinPolicies()” or “vcc.getCheckinPoliciesForServerPaths()”

我是研究僧i 提交于 2019-12-11 07:35:23

问题


Does anyone tried to retrieve PolicyDefinition using Java SDK of TFS 2015?

I have used following code to retrieve the PolicyDefinition under intelliJ Plugin. Code execute fine but I am getting empty collection of PolicyDefinition. I am working on CustomPath Policy and I know on particular team project customPath Policy is applied.

Before allowing user checkin I want to validate that weather this policy is applied or not.

Sample Code:

Project myProject = policyContext.getProject(); // PolicyContext is received from intelliJ and I got Project
                                                // object opened in intelliJ

Workstation workstation = Workstation.getInstance(); // Workspace Info, it depeneds how many workspaces created
                                                        // to map TFS solution
Collection<WorkspaceInfo> workspaceInfos = workstation
        .findWorkspacesCached(TfsFileUtil.getFilePath(myProject.getBaseDir()), false); // This will return the
                                                                                        // workspace info based
                                                                                        // on project path.

WorkspaceInfo workspaceInfo = workspaceInfos.iterator().next();
Collection<String> serverFolderPaths = workspaceInfo
        .findServerPathsByLocalPath(VcsUtil.getFilePath(myProject.getBasePath()), false, myProject); // This
                                                                                                        // will
                                                                                                        // return$/TeamProjectCollection/TeamProject/ProjectFolder

ServerInfo serverInfo = workspaceInfo.getServer();
TfsSdkManager tfsSdkManager = TfsSdkManager.getInstance(); // intelliJ provide TfsSdkManager to get cached
                                                            // information about TFS, like credential
Credentials credentials = tfsSdkManager.getCredentials(serverInfo);
URI uri = new URI(serverInfo.getPresentableUri());

TFSTeamProjectCollection tpc = new TFSTeamProjectCollection(uri, credentials);
tpc.ensureAuthenticated();
VersionControlClient vcc;

vcc = forcePluginClassLoader(() -> tpc.getVersionControlClient()); // intelliJ has SOX issue if call is not
                                                                    // wrapped using forcePluginClassLoader()
                                                                    // method;
String teamProjectServerPath = "$/TeamProjectCollection"; // Tried to pass "$/TeamProjectCollection/TeamProject"
                                                            // as well but same result, getting emppty
//line: 15                                                          // collection of PlicyDefinition
PolicyDefinition[] results = vcc.getCheckinPoliciesForServerPaths(new String[] { teamProjectServerPath });

String serverProjectPath = serverFolderPaths.iterator().next();

// Another way to get policy
Item item = vcc.getItem("$/TeamProjectCollection");
TeamProject tp = new TeamProject(item, vcc);

String projectName = tp.getName();

//line: 20
PolicyDefinition[] ps = tp.getCheckinPolicies();
for (PolicyDefinition pd : ps) {
    int pi = pd.getPriority();

}

Line 15 & 20 both returns empty Policy definition.

Anyone faced this issue?

来源:https://stackoverflow.com/questions/47840712/policydefinition-result-return-empty-collection-using-java-sdk-of-tfs-2015-tp-g

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!