1. 程式人生 > >java實現starteam配置庫中checkout對應的檔案

java實現starteam配置庫中checkout對應的檔案

1、所屬jar包:starteam-sdk-5.2.jar

2、樣例程式碼

package com.comtop.qcms.base.starteam;

import java.io.IOException;

import com.comtop.qcms.base.util.DateUtil;
import com.starbase.starteam.Folder;
import com.starbase.starteam.Item;
import com.starbase.starteam.Project;
import com.starbase.starteam.Server;
import com.starbase.starteam.StarTeamFinder;
import com.starbase.starteam.View;

/**
 * 從配置庫中checkout對應的檔案
 */
 public class CheckOutStateamFile {

 /** 檢索檔案根目錄 */

 private static final String URL = "/src/main";

 /** 專案名稱 */
 private static final String PROJECT_NAME = "PROJECTNAME";

 public static void main(String[] args) {
  checkOutFile();
 }

 public static void checkOutFile() {

  // 連線伺服器,伺服器地址及埠號
  Server server = new Server("10.10.10.1", 11111);
  server.connect();

  // 登入伺服器,使用者名稱及密碼
  server.logOn("userName", "password");

  // 獲取要CheckOut的專案
  Project[] projects = server.getProjects();
  Project project = null;
  for (int i = 0; i < projects.length; i++) {
   Project next = projects[i];
   if (next.getName().equals(PROJECT_NAME)) {
    project = next;
    break;
   }
  }

  // 獲取要CheckOut的檢視
  View[] views = project.getViews();
  View view = null;
  for (int i = 0; i < views.length; i++) {
   View next = views[i];
   if (next.getName().equals(PROJECT_NAME)) {
    view = next;
    break;
   }
  }

  // 獲取檔案要CheckOut的檔案列表
  Folder folder = StarTeamFinder.findFolder(view.getRootFolder(), URL + DateUtil.getCurrMonth());
  Item[] items = folder.getItems(server.getTypeNames().FILE);

  // 迴圈CheckOut相關檔案
  for (int i = 0; i < items.length; i++) {
   com.starbase.starteam.File file = (com.starbase.starteam.File) items[i];
   try {
    // 第一個引數:0為不鎖定檔案,1為鎖定檔案
    file.checkout(0, false, false, false);
   } catch (IOException e) {
    System.out.println("CheckOut檔案出現問題:" + file.getFullName());
   }
  }
  server.disconnect();
 }
}