ClearCase変更セットクラスの表示
みんなに自分で書いたClearCaseを共有して変更セットのものを見ます.
私が書いたClearCaseは変更セットのクラスを見て、ある時間からccのあるストリームのどのファイルを修正したのかを見ることができて、出力のフォーマットは自分で修正することができて、私が設定した出力フォーマットはwas更新のコードリストで、私たちの開発者にとってとても便利です.libパッケージを使うには大きすぎて送れないので、C:Program FilesIBMIMsharedで見つけることができます.
私が書いたClearCaseは変更セットのクラスを見て、ある時間からccのあるストリームのどのファイルを修正したのかを見ることができて、出力のフォーマットは自分で修正することができて、私が設定した出力フォーマットはwas更新のコードリストで、私たちの開発者にとってとても便利です.libパッケージを使うには大きすぎて送れないので、C:Program FilesIBMIMsharedで見つけることができます.
package com.chruan.clearcase.cm.client;
/**
* clearcase 9
* doPrint()
*
* @author chruan( )
* @date 2012-8-8
*
*/
public class RifmsChangeSet {
public static void main(String[] args) {
ChangeSetView changeSetView = new ChangeSetView(
"http://ccweb.chruan.com.cn/TeamWeb/services/Team", "ex_username",
"ex_password");
try {
// (null )
changeSetView.setStartDate(DateOp.strToDate("2012/05/01 00:00:00"));
// ( )
changeSetView
.setFileExtFilter(new String[] { ".java", ".jsp", ".xml" });
// ( )
changeSetView.setFileNoFilter(new String[] { "CardReaderAction.java",
"Host8888.java", "EsbHostService.java",
"TranService777015.java" });
// , 。null ,
// cc , 。
// changeSetView.setViewNamesFilter(new String[]{"ex_ifms7_Dev_RIFMS_2012_9 _ "});
// cc lc08 D:\CCWORK\chruan_Dev_CHRUAN_2012_9 \vobs\CHRUAN_VOB\CHRUAN\sys\src
changeSetView.setVobRoot("vobs/CHRUAN_VOB/sys/src/");
//
changeSetView.setWebNames(new String[]{"tika","lucene","hbase"});
// ClearCase ,
// ClearCase 。
changeSetView
.printChangeSet("stream:Dev_CHRUAN_2012_9 @/vobs/PV_OPS");
}finally{
changeSetView.terminate();
}
}
}
package com.chruan.clearcase.cm.client;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.wvcm.ProviderFactory;
import javax.wvcm.ResourceList;
import javax.wvcm.Version;
import javax.wvcm.WvcmException;
import javax.wvcm.PropertyRequestItem.PropertyRequest;
import javax.wvcm.ProviderFactory.Callback;
import com.ibm.rational.wvcm.stp.StpLocation;
import com.ibm.rational.wvcm.stp.StpProvider;
import com.ibm.rational.wvcm.stp.cc.CcActivity;
import com.ibm.rational.wvcm.stp.cc.CcProvider;
import com.ibm.rational.wvcm.stp.cc.CcStream;
import com.ibm.rational.wvcm.stp.cc.CcVersion;
import com.ibm.rational.wvcm.stp.cc.CcView;
/**
* clearcase
*
* cc C:\Program Files\IBM\IMShared\plugins\com.ibm.rational.teamapi_7.1.1.v201006120047
* @author chruan( )
* @version v1.0
* @date 2012-7-6
*
*/
public class ChangeSetView {
private String password;
private String userName;
private String serverUrl;
private MyAuthorCallback callback;
private StpProvider stpProvider;
//
private Map ownViewList = new HashMap();
//
private Map ownActivityList = new HashMap();
//
private Map changeSet = new HashMap();
//
private Date startDate = null;
// ( )
private String[] fileExt=null;
// ( )
private String[] fileNo=null;
private String[] filterViewNames=null;
// cc lc08 D:\CCWORK\ex_ruanch_Dev_IFMS_2012_9 \vobs\IFMS_VOB\IFMS\sys\src
private String vobRoot=null;
//
private String[] webNames;
/**
*
* @param serverUrl cc
* @param userName cc
* @param password cc
*/
public ChangeSetView(String serverUrl, String userName, String password) {
// TODO Auto-generated constructor stub
this.serverUrl = serverUrl;
this.userName = userName;
this.password = password;
initProvider();
}
private void initProvider() {
// TODO Auto-generated method stub
this.callback = new MyAuthorCallback(userName, password);
try {
stpProvider = (StpProvider) ProviderFactory.createProvider(
CcProvider.CC_ONLY_PROVIDER_CLASS, callback);
stpProvider.ccProvider().setServerUrl(serverUrl);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
*
* @param stream
*/
public void printChangeSet(String stream) {
try {
//
CcStream ccstream = getccStream(stream);
//
doViewList(ccstream);
//
doActivityList(ccstream);
//
doChangeSet();
//
doPrint();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
private void doPrint() {
// TODO Auto-generated method stub
List changeList = sort(changeSet);
changeList = doFilter(changeList);
//
System.out.println(" :");
for (int idx = 0, size = changeList.size(); idx < size; idx++)
System.out.println(changeList.get(idx));
for (int idx=0,size=webNames.length;idx<size;idx++)
doFilter2(changeList,webNames[idx]);
}
/**
*
* @param list
* @return
*/
private List doFilter(List list) {
// TODO Auto-generated method stub
List result = new ArrayList();
for (int idx = 0, size = list.size(); idx < size; idx++) {
String item = (String) list.get(idx);
// filter file extends
boolean find = false;
for (int i = 0; i < fileExt.length; i++) {
if (item.endsWith(fileExt[i])) {
// System.out.println(item+" "+fileExt[i]);
find = true;
break;
}
}
for (int i = 0; i < fileNo.length; i++) {
if (item.endsWith(fileNo[i])) {
find = false;
break;
}
}
if (find)
result.add(item);
}
return result;
}
/**
* web
* @param list
* @param web
*/
private void doFilter2(List list,String web) {
// TODO Auto-generated method stub
System.out.println("============ " + web + " ===========");
String root = vobRoot + web + "/";
String webroot = root + "WebRoot/";
int wlen = webroot.length();
String srcroot = root + "src/";
int slen = srcroot.length();
List rl = new ArrayList();
Iterator iter = list.iterator();
while (iter.hasNext()) {
String item = (String) iter.next();
// filter root
if (item.startsWith(root)) {
if (item.startsWith(webroot))
item = item.substring(wlen);
else if (item.startsWith(srcroot))
item = "WEB-INF/classes/" + item.substring(slen);
if (item.endsWith(".java"))
item = item.substring(0, item.length() - 4) + "class";
// System.out.println(item);
rl.add(item);
}
}
Collections.sort(rl);
for (int idx = 0, size = rl.size(); idx < size; idx++)
System.out.println(rl.get(idx));
System.out.println("
");
}
/**
*
* @param changeSet2
* @return
*/
private List sort(Map changeSet2) {
// TODO Auto-generated method stub
List list = new ArrayList();
Iterator iter = changeSet2.keySet().iterator();
while (iter.hasNext()) {
String key = (String) iter.next();
list.add(key);
}
Collections.sort(list);
return list;
}
/**
*
*/
private void doChangeSet() {
// TODO Auto-generated method stub
Iterator viter = ownViewList.keySet().iterator();
while (viter.hasNext()) {
CcView view = (CcView) viter.next();
Iterator aiter = ownActivityList.keySet().iterator();
while (aiter.hasNext()) {
CcActivity act = (CcActivity) aiter.next();
doChangeSet(view, act);
}
}
}
/**
*
* @param view
* @param act
*/
private void doChangeSet(CcView view, CcActivity act) {
// TODO Auto-generated method stub
try {
PropertyRequest feedback = new PropertyRequest(
CcActivity.LATEST_VERSION_LIST);
act = (CcActivity) act.doReadProperties(view, feedback);
ResourceList<Version> versionList = act.getLatestVersionList();
for (int idx = 0, size = versionList.size(); idx < size; idx++) {
CcVersion version = (CcVersion) versionList.get(idx);
doVersion(view, version);
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
/**
*
* @param view
* @param version
*/
private void doVersion(CcView view, CcVersion version) {
// TODO Auto-generated method stub
try {
PropertyRequest feedback = new PropertyRequest(
CcVersion.DISPLAY_NAME, CcVersion.VIEW_RELATIVE_PATH,
CcVersion.CREATION_DATE);
version = (CcVersion) version.doReadProperties(view, feedback);
Date cdate = version.getCreationDate();
if ((startDate == null)
|| (startDate != null && cdate.after(startDate)))
changeSet.put(version.getViewRelativePath(), null);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
/**
*
* @param ccstream
*/
private void doActivityList(CcStream ccstream) {
// TODO Auto-generated method stub
try {
PropertyRequest feedback = new PropertyRequest(
CcStream.ACTIVITY_LIST);
ccstream = (CcStream) ccstream.doReadProperties(feedback);
ResourceList<CcActivity> actList = ccstream.getActivityList();
// System.out.println(actList);
for (int idx = 0, size = actList.size(); idx < size; idx++) {
CcActivity act = actList.get(idx);
doActivity(act);
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
/**
*
* @param act
*/
private void doActivity(CcActivity act) {
// TODO Auto-generated method stub
try {
PropertyRequest feedback = new PropertyRequest(
CcActivity.CREATOR_LOGIN_NAME);
act = (CcActivity) act.doReadProperties(feedback);
String login = act.getCreatorLoginName();
// System.out.println(login);
//
if (userName.equals(login))
ownActivityList.put(act, null);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
/**
*
* @param ccstream
*/
private void doViewList(CcStream ccstream) {
// TODO Auto-generated method stub
try {
PropertyRequest feedback = new PropertyRequest(CcStream.VIEW_LIST);
ccstream = (CcStream) ccstream.doReadProperties(feedback);
ResourceList<CcView> viewList = ccstream.getViewList();
// System.out.println(viewList);
for (int idx = 0, size = viewList.size(); idx < size; idx++) {
CcView view = viewList.get(idx);
doView(view);
// break;
}
// System.out.println(ownViewList.size());
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
/**
* ,
* @param view
*/
private void doView(CcView view) {
// TODO Auto-generated method stub
try {
PropertyRequest feedback = new PropertyRequest(CcView.DISPLAY_NAME,
CcView.CREATOR_LOGIN_NAME);
view = (CcView) view.doReadProperties(feedback);
view.getCreatorLoginName();
String name = view.getDisplayName();
if (filterViewNames !=null && filterViewNames.length>0){
for (int idx=0;idx< filterViewNames.length;idx++){
if (name.equals(filterViewNames[idx])){
ownViewList.put(view, null);
System.out.println(" :"+name);
break;
}
}
}else{
ownViewList.put(view, null);
System.out.println(" :"+name);
}
} catch (Exception e) {
// TODO: handle exception
// e.printStackTrace();
}
}
/**
* provider
*/
public void terminate() {
if (stpProvider != null)
try {
stpProvider.terminate();
} catch (WvcmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
*
* @param location
* @return
*/
private CcStream getccStream(String location) {
// TODO Auto-generated method stub
try {
StpLocation loc = stpProvider.stpLocation(location);
return (CcStream) stpProvider.ccProvider().ccStream(loc);
} catch (WvcmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
private static class MyAuthorCallback implements Callback {
private final String loginName;
private final String password;
public MyAuthorCallback(String loginName, String password) {
// TODO Auto-generated constructor stub
this.loginName = loginName;
this.password = password;
}
public Authentication getAuthentication(String realm, int retryCount)
throws WvcmException {
// TODO Auto-generated method stub
return new Authentication() {
public String loginName() {
// TODO Auto-generated method stub
return loginName;
}
public String password() {
// TODO Auto-generated method stub
return password;
}
};
}
}
/**
* ( )
* @param fileExt
*/
public void setFileExtFilter(String[] fileExt) {
// TODO Auto-generated method stub
this.fileExt = fileExt;
}
/**
* ( )
* @param fileNo
*/
public void setFileNoFilter(String[] fileNo) {
// TODO Auto-generated method stub
this.fileNo = fileNo;
}
/**
* (null )
* @param startDate
*/
public void setStartDate(Date startDate) {
// TODO Auto-generated method stub
this.startDate = startDate;
}
public void setWebNames(String[] webNames) {
// TODO Auto-generated method stub
this.webNames = webNames;
}
public String[] getFilterViewNames() {
return filterViewNames;
}
public void setViewNamesFilter(String[] filterViewNames) {
this.filterViewNames = filterViewNames;
}
public String getVobRoot() {
return vobRoot;
}
public void setVobRoot(String vobRoot) {
this.vobRoot = vobRoot;
}
}