1

有没有人尝试PolicyDefinition使用 TFS 2015 的 Java SDK 进行检索?

我使用以下代码检索了 intelliJ 插件下的 PolicyDefinition。代码执行良好,但我得到了 PolicyDefinition 的空集合。我正在研究 CustomPath Policy,并且我知道在特定的团队项目中应用了 customPath Policy。

在允许用户签入之前,我想验证是否应用了此策略。

示例代码:

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();

}

第 15 行和第 20 行都返回空策略定义。

有人遇到过这个问题吗?

4

0 回答 0