我想在ClearCase源代码管理下更新文件。这需要从Ant脚本发生。
我已经为此创建了一个快照视图。 ccupdate
更新就好了。
我已尝试使用cccheckout
,但失败并出现以下错误cleartool: Error: To operate on UCM branch, must be set to an activity and a UCM view.
。
有没有办法在快照视图中签出文件,替换它并签入新版本?如果这涉及创建/切换到活动,请在答案中包含此内容。
答案 0 :(得分:1)
Apache Ant ClearCase Tasks(2003!)是UCM前的区域 这意味着他们没有“UCM视图”(快照或动态)或活动的概念。
如果您要使用ant,您可以尝试(未测试)像clearantlib这样的任务库,它允许您执行任何cleartool命令(使用ccexec
)
这样您就可以使用cleartool setact
在UCM视图中设置UCM活动
只有在设置了活动时,您的结帐才能继续。
答案 1 :(得分:1)
由于clearantlib只是一个围绕cleartool命令行的薄包装,因此您可以自己动手。下面是“结帐部分”的一些生产代码片段,这对编写自己的ant任务可能会有所帮助 - 否则您需要使用一堆调用cleartool的ant <exec>
部件。在clearcase snapshotview中签出特定版本意味着创建并设置configspec。对于更新部分,请使用ProcessBuilder和相关的cleartool命令:
/**
*
* @param modulinfos
* @param jobid
* @param snapshotpath
*/
private void createConfSpec(ArrayList<String> modulinfos, String jobid, String snapshotpath)
{
/*
element * CHECKEDOUT
element "/at_vobt2/Foo/.../" v_1_4_00_49a
element "/at_vobt2/FooBar/.../" v_1_3_02_06c
element "/at_vobt2/Foo Base/.../" v_1_3_01_28b
element * /main/LATEST
load "/vobt2/Foo"
load "/vobt2/FooBar"
load "/vobt2/FooBase"
*/
StringBuilder sb = new StringBuilder("element * CHECKEDOUT");
for (String string : modulinfos)
{
sb.append(nl).append("element \"/" + string.split("#")[0] + "/" + string.split("#")[1] + "/.../\" " + string.split("#")[2]);
}
sb.append(nl).append("element * /main/LATEST");
for (String string : modulinfos)
{
sb.append(nl).append("load \"/" + string.split("#")[0] + "/" + string.split("#")[1] + "\"");
}
sb.append(nl);
File file = new File(snapshotpath + "\\" + jobid + ".confspec");
BufferedWriter writer = null;
try
{
writer = new BufferedWriter(new FileWriter(file));
writer.write(sb.toString());
writer.close();
getLogger().debug("Create ConfigSpec : " + nl + sb.toString() + "File => " + file.getPath());
} catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
*
* @param snapshotpath
* @return
* @throws IOException
*/
private boolean checkSnapshotView(String snapshotpath) throws IOException
{
boolean isReady = false;
// use pushd/popd cause cmd doesn't support UNC !
ProcessBuilder pb = new ProcessBuilder
(
"cmd", "/c",
"pushd " + snapshotpath + " && cleartool lsview -l -pro -cview && popd"
);
pb.redirectErrorStream(true);
Process p = pb.start();
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
StringBuilder sb = new StringBuilder();
String line = "";
while ((line = br.readLine()) != null)
{
sb.append(line).append(nl);
}
isReady = !StringUtils.containsIgnoreCase(sb.toString(), "cleartool: Error: Cannot get view info for current view");
getLogger().debug("Check Snapshotview : " + snapshotpath + nl + sb.toString());
return isReady;
}
/**
*
* @param jobid
* @param snapshotpath
* @throws IOException
*/
private void createSnapshotView(String jobid, String snapshotpath) throws IOException
{
ProcessBuilder pb = new ProcessBuilder
(
"cmd", "/c",
"cleartool mkview -snapshot -tag " + "snapshot" + jobid + " " + snapshotpath
);
pb.redirectErrorStream(true);
Process p = pb.start();
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
StringBuilder sb = new StringBuilder();
String line = "";
while ((line = br.readLine()) != null)
{
sb.append(line).append(nl);
}
getLogger().debug("Create Snapshotview : " + nl + sb.toString());
}
/**
*
* @param snapshotpath
* @param configspecpath
* @throws IOException
*/
private void setConfigSpec(String snapshotpath, String configspecpath) throws IOException
{
// use pushd/popd cause cmd doesn't support UNC !
ProcessBuilder pb = new ProcessBuilder
(
"cmd", "/c",
"pushd " + snapshotpath + " && cleartool setcs " + configspecpath + " && popd"
);
pb.redirectErrorStream(true);
Process p = pb.start();
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
StringBuilder sb = new StringBuilder();
String line = "";
while ((line = br.readLine()) != null)
{
sb.append(line).append(nl);
}
getLogger().debug("Update Snapshotview : " + nl + sb.toString());
}