如何使用 Ant 脚本 check-out/check-in 将文件放入 ClearCase 快照视图?
How to check-out/check-in a file into a ClearCase snapshot view using an Ant script?
我想更新 ClearCase 源代码管理下的文件。这需要通过 Ant 脚本进行。
我为此创建了一个快照视图。 ccupdate
更新就好了。
我试过使用 cccheckout
但失败并出现以下错误 cleartool: Error: To operate on UCM branch, must be set to an activity and a UCM view.
。
有没有办法在快照视图中签出文件、替换它并签入新版本?如果这涉及 creating/switching 到 activity,请将其包含在您的回答中。
Apache Ant ClearCase Tasks (2003!) 是预 UCM 区域。
这意味着他们没有 "UCM view"(快照或动态)或活动的概念。
如果你继续使用 ant,你可以尝试(未测试)像 clearantlib, which allows you to execute any cleartool command (with ccexec
)
这样的任务库
这样您就可以使用 cleartool setact
在 UCM 视图中设置 UCM activity。
仅当设置 activity 时,您的结帐才会继续。
由于 clearantlib 只是 cleartool 命令行的薄包装,所以您只能靠自己了。遵循 'checkout part' 的一些生产代码片段,这可能有助于编写您自己的 ant 任务 - 否则您需要使用一堆 ant <exec>
部分来调用 cleartool。在 clearcase 快照视图中检出特定版本意味着创建和设置配置规范。对于更新部分,请将 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());
}
我想更新 ClearCase 源代码管理下的文件。这需要通过 Ant 脚本进行。
我为此创建了一个快照视图。 ccupdate
更新就好了。
我试过使用 cccheckout
但失败并出现以下错误 cleartool: Error: To operate on UCM branch, must be set to an activity and a UCM view.
。
有没有办法在快照视图中签出文件、替换它并签入新版本?如果这涉及 creating/switching 到 activity,请将其包含在您的回答中。
Apache Ant ClearCase Tasks (2003!) 是预 UCM 区域。
这意味着他们没有 "UCM view"(快照或动态)或活动的概念。
如果你继续使用 ant,你可以尝试(未测试)像 clearantlib, which allows you to execute any cleartool command (with ccexec
)
这样您就可以使用 cleartool setact
在 UCM 视图中设置 UCM activity。
仅当设置 activity 时,您的结帐才会继续。
由于 clearantlib 只是 cleartool 命令行的薄包装,所以您只能靠自己了。遵循 'checkout part' 的一些生产代码片段,这可能有助于编写您自己的 ant 任务 - 否则您需要使用一堆 ant <exec>
部分来调用 cleartool。在 clearcase 快照视图中检出特定版本意味着创建和设置配置规范。对于更新部分,请将 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());
}