Выполнение команды cleartool в java - runtime().exec
Попытка реализовать плагин jenkins, который должен отображать базовые линии под указанным VOB
с помощью команды cleartool cleartool lstpye -kind lbtype -s -inv \VOB
но получаю ошибки в процессе выполнения команды (VOB
является входным параметром). Не знаю точно, где проблема или я делаю что-то не так в коде. Я буду признателен за ваши предложения.
Вот код
public class MakeViewDefinition extends SimpleParameterDefinition{
private String vob;
public static String getVob(String vob) throws IOException{
try{
String[] cmd = {"cmd.exe", "/C", "cleartool", "lstype", "-kind", "lbtype", "-s", "-inv", "\\", vob};
Process p=Runtime.getRuntime().exec(cmd);
BufferedReader reader=new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
String output = "";
while((line=reader.readLine()) != null){
output +=line+ "\n";
}
return output;
}
catch ( IOException ioe )
{
System.out.println("ERROR: " + ioe);
}
return "WARNING: End of getVob()\n";
}
@DataBoundConstructor
public MakeViewDefinition(String name, String description, String vob){
super(name, description);
this.vob= vob;
}
protected static List<String> getList (String output){
return getList(output);
}
@Extension
static public class DescriptorImpl extends ParameterDescriptor{
@Override
public String getDisplayName(){
return Messages.MakeViewDefinition_DisplayName();
}
public FormValidation doCheckVob(@QueryParameter String vob){
if (StringUtils.isBlank(vob)){
return FormValidation.error(Messages.MakeViewDefinition_vob_empty());
}
return FormValidation.ok();
}
public FormValidation doTest(@QueryParameter String output) throws IOException{
List<String> filelist = getList(getVob(output));
if(filelist.isEmpty()){
return FormValidation.ok("(No File matched)");
}
return FormValidation.ok(StringUtils.join(filelist, '\n'));
}
}
@Override
public ParameterValue createValue(String value) {
// TODO Auto-generated method stub
return null;
}
@Override
public ParameterValue createValue(StaplerRequest req, JSONObject jo) {
// TODO Auto-generated method stub
return null;
}
}
config.jelly
<f:entry title="${%Name}" field="name">
<f:textbox />
</f:entry>
<f:entry title="${%Description}" field="description">
<f:textarea />
</f:entry>
<f:entry title="${%VoB Directory}" field="vob">
<f:textbox />
</f:entry>
<f:validateButton
method="test"
title="${%List Files Now}"
progress="${%Checking...}"
with="vob"
/>
index.jelly
<f:entry title="${it.name}" description="${it.description}">
<div name="parameter" description="${it.description}">
<input type="hidden" name="name" value="${it.name}" />
<j:scope>
<j:set var="instance" value="${it.defaultParameterValue}" />
<myF:staticSelect
name="value"
field="value"
vob="${it.vob}"
/>
</j:scope>
</div>
</f:entry>
Вот сообщения об ошибках:
Caused by: java.lang.NullPointerException
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at de.bosch.MakeView.MakeViewDefinition.getVob(MakeViewDefinition.java:34)
at de.bosch.MakeView.MakeViewDefinition$DescriptorImpl.doTest(MakeViewDefinition.java:80)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java:298)
at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:161)
at org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.java:96)
at org.kohsuke.stapler.MetaClass$1.doDispatch(MetaClass.java:120)
at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:53)
at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:728)
... 69 more
1 ответ
Сначала вам нужно убедиться, что VOB смонтирован (если вы используете динамические представления), и ваша команда должна использовать "\\"+vob
не "\\", vob
,
Как упомянуто здесь, NPE означает один из аргументов, если ноль, что имеет место, если вы введете неправильное имя (например, 'xxx
' вместо \xxx
,
Если это так, вы можете пропустить\\
' в вашем cmd
массив.