如何使用Java SDK将文件签入TFS

时间:2016-06-30 07:57:53

标签: java tfs tfs2010

我打算使用websevice将TFS与另一个应用程序集成。 我是TFS的新手。所以我下载了TFS Java SDK 2010.我一直在编写示例程序来检查文件到TFS。但没有成功。在互联网上也没有太多有用的Java端SDK样本帖子。

以下是我写的代码: -

public static void main(String[] args) {
    // TODO Auto-generated method stub

    TFSTeamProjectCollection tpc = SnippetSettings.connectToTFS(); //got the connection to TFS
    VersionControlClient vcc = tpc.getVersionControlClient();
    //WorkspaceInfo wi = Workstation.Current.GetLocalWorkspaceInfo(Environment.CurrentDirectory);
    //vcc.get
    String[] paths =new String[1];

    paths[0]="D:\\Tools\testfile.txt"; //wants to checkin this local file 


    Workspace ws = vcc.createWorkspace(null,"Testworkspacename3", null, "","Testcomment",null, null);  // this is workspace created at path local C:\ProgramData\Microsoft Team Foundation Local Workspaces


    int item = ws.pendAdd(paths, true, null, LockLevel.NONE,  GetOptions.GET_ALL,  PendChangesOptions.GET_LATEST_ON_CHECKOUT); // this line gives me 0 count. so this is problematic . 0 means nothing is being added.
    PendingSet pd = ws.getPendingChanges();  

    PendingChange[] pendingChanges = pd.getPendingChanges();
    ws.checkIn(pendingChanges, "samashti comment");


    Project project = tpc.getWorkItemClient().getProjects().get(SnippetSettings.PROJECT_NAME);
    System.out.println();

请在这里帮忙......这里有什么不对。有些人可以使用JAVA为新文件签入和现有文件签入提供正确的工作样本。

2 个答案:

答案 0 :(得分:0)

请参阅以下步骤:

  1. 连接到团队项目集合
  2. 获取版本控制客户端
  3. 创建新工作区
  4. 将文件添加到工作区
  5. 获取待定更改
  6. 签入待定更改
  7. 以下是有关TFS SDK for JAVA的一些链接供您参考:

答案 1 :(得分:0)

请参阅根据TFS-SDK-14.0.3创建和映射工作区的代码段

    public static Workspace createAndMapWorkspace(final TFSTeamProjectCollection tpc) {
    final String workspaceName = "SampleVCWorkspace" + System.currentTimeMillis(); //$NON-NLS-1$
    Workspace workspace = null;

    // Get the workspace
    workspace = tpc.getVersionControlClient().tryGetWorkspace(ConsoleSettings.MAPPING_LOCAL_PATH);

    // Create and map the workspace if it does not exist
    if (workspace == null) {
        workspace = tpc.getVersionControlClient().createWorkspace(
            null,
            workspaceName,
            "Sample workspace comment", //$NON-NLS-1$
            WorkspaceLocation.SERVER,
            null,
            WorkspacePermissionProfile.getPrivateProfile());

        // Map the workspace
        final WorkingFolder workingFolder = new WorkingFolder(
            ConsoleSettings.MAPPING_SERVER_PATH,
            LocalPath.canonicalize(ConsoleSettings.MAPPING_LOCAL_PATH));
        workspace.createWorkingFolder(workingFolder);
    }

    System.out.println("Workspace '" + workspaceName + "' now exists and is mapped"); //$NON-NLS-1$ //$NON-NLS-2$

    return workspace;
}