Commit 743b1642 authored by Andrey Filippov's avatar Andrey Filippov

Working on communicating with remote program, capturing stderr/stdout to

separate external program
parent ad2afc3e
/com
/BuildParamsItem.class
......@@ -148,4 +148,6 @@ public class VDT {
public static final String GENERATOR_ID_CURRENT_BASE = "CurrentFileBase";
public static final String GENERATOR_ID_CHOSEN_ACTION = "ChosenActionIndex";
public static final String GENERATOR_ID_BUILD_STAMP = "BuildStamp";
public static final String GENERATOR_ID_BLANK = "Blank";
public static final String GENERATOR_ID_NEWLINE = "NewLine";
} // class VDT
......@@ -328,7 +328,10 @@ public class LaunchCore {
launch.setAttribute(DebugPlugin.ATTR_CAPTURE_OUTPUT, null);
DebugPlugin.getDefault().getLaunchManager().addLaunch(launch);
VDTRunner runner = VDTLaunchUtil.getRunner();
runner.run(configuration, launch, null);
runner.run(configuration,
VDTRunner.renderProcessLabel(configuration.getToolName()), // toolname + (date)
launch,
null);
} // launch()
......
......@@ -29,6 +29,7 @@ import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
import com.elphel.vdt.Txt;
import com.elphel.vdt.core.tools.contexts.BuildParamsItem;
import com.elphel.vdt.ui.MessageUI;
......@@ -95,8 +96,8 @@ public class VDTLaunchConfigurationDelegate implements ILaunchConfigurationDeleg
// done the creating arguments phase
monitor.worked(3);
// resolve arguments
// resolve arguments, save them
runConfig.setArgumentsItemsArray(VDTLaunchUtil.getArguments(configuration)); // calculates all parameters
runConfig.setIsShell(VDTLaunchUtil.getIsShell(configuration));
runConfig.setPatternErrors(VDTLaunchUtil.getPatternErrors(configuration));
runConfig.setToolName(VDTLaunchUtil.getToolName(configuration));
......
......@@ -39,6 +39,7 @@ import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.IStreamListener;
//import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.model.IProcess;
//import org.eclipse.debug.ui.DebugUITools;
......@@ -47,10 +48,12 @@ import org.eclipse.debug.core.model.IProcess;
//import org.eclipse.ui.console.IPatternMatchListener;
//import org.eclipse.ui.console.MessageConsole;
import org.eclipse.debug.core.model.IStreamMonitor;
import org.eclipse.debug.core.model.IStreamsProxy;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.ui.console.IConsole;
//import org.eclipse.debug.ui.console.IConsole;
import org.eclipse.ui.console.ConsolePlugin;
......@@ -71,12 +74,6 @@ import com.elphel.vdt.veditor.preference.PreferenceStrings;
//import com.elphel.vdt.core.Utils;
import org.eclipse.ui.console.IConsoleListener;
......@@ -102,14 +99,12 @@ public class VDTRunner {
System.out.println("***Addded console listeners");
manager.addConsoleListener(new IConsoleListener(){
public void consolesAdded(IConsole[] consoles){
VDTRunner runner = VDTLaunchUtil.getRunner();
for (int i=0;i<consoles.length;i++){
System.out.println("+++ Added: "+consoles[i].getName());
// Only shows added consoles
}
}
public void consolesRemoved(IConsole[] consoles){
VDTRunner runner = VDTLaunchUtil.getRunner();
for (int i=0;i<consoles.length;i++){
System.out.println("--- Removed: "+consoles[i].getName());
......@@ -146,14 +141,16 @@ public class VDTRunner {
System.out.println("Turned out nothing to do. Probably a bug");
return;
}
ILaunchConfiguration configuration=runConfig.getConfiguration();
BuildParamsItem[] argumentsItemsArray = VDTLaunchUtil.getArguments(configuration);
// ILaunchConfiguration configuration=runConfig.getConfiguration();
// BuildParamsItem[] argumentsItemsArray = VDTLaunchUtil.getArguments(configuration); // calculates all parameters
BuildParamsItem[] argumentsItemsArray = runConfig.getArgumentsItemsArray(); // uses already calculated
int numItem=runConfig.getBuildStep();
System.out.println("--------- resuming "+ consoleName+", numItem="+numItem+" ------------");
ILaunch launch=runConfig.getLaunch();
IProgressMonitor monitor=runConfig.getMonitor();
for (;numItem<argumentsItemsArray.length;numItem++){
runConfig.setBuildStep(numItem); // was not updated if was not sleeping
List<String> toolArguments = new ArrayList<String>();
List<String> arguments=argumentsItemsArray[numItem].getParamsAsList();
if (arguments != null)
......@@ -165,10 +162,19 @@ public class VDTRunner {
runConsole(argumentsItemsArray[numItem].getConsoleName(),runConfig, launch, monitor);
continue;
}
if (argumentsItemsArray[numItem].getNameAsParser()!=null){
// parsers should be launched by the console scripts, in parallel to them
System.out.println("Skipping parser "+argumentsItemsArray[numItem].getNameAsParser());
continue;
}
// Launch the configuration - 1 unit of work
// VDTRunner runner = VDTLaunchUtil.getRunner();
IProcess process=run(runConfig, launch, monitor);
IProcess process=run(
runConfig,
renderProcessLabel(runConfig.getToolName()), // toolname + (date)
launch,
monitor);
//Andrey: if there is a single item - launch asynchronously, if more - verify queue is empty
// will not change
......@@ -229,12 +235,25 @@ public class VDTRunner {
monitor.done();
}
private BuildParamsItem getParser(VDTRunnerConfiguration configuration, String parserName){
if (parserName==null) return null;
BuildParamsItem[] buildParamsItems = configuration.getArgumentsItemsArray(); // uses already calculated
if (buildParamsItems==null) return null;
for (int i=0;i<buildParamsItems.length;i++){
if (parserName.equals(buildParamsItems[i].getNameAsParser()))
return buildParamsItems[i];
}
return null;
}
public IOConsole runConsole(String consolePrefix
, VDTRunnerConfiguration configuration
, ILaunch launch
, IProgressMonitor monitor
) throws CoreException{
int numItem=configuration.getBuildStep();
// BuildParamsItem buildParamsItem= VDTLaunchUtil.getArguments(configuration.getConfiguration())[numItem];
BuildParamsItem buildParamsItem = configuration.getArgumentsItemsArray()[numItem]; // uses already calculated
//TODO: Handle monitor
// Find console with name starting with consolePrefix
IConsoleManager man = ConsolePlugin.getDefault().getConsoleManager(); // debugging
......@@ -253,26 +272,114 @@ public class VDTRunner {
// try to send
String[] arguments = configuration.getToolArguments();
if (arguments == null) arguments=new String[0];
if (VerilogPlugin.getPreferenceBoolean(PreferenceStrings.DEBUG_LAUNCHING)) {
// System.out.println("patternErrors= \""+ configuration.getPatternErrors()+"\"");
// System.out.println("patternWarnings= \""+configuration.getPatternWarnings()+"\"");
// System.out.println("patternInfo= \"" +configuration.getPatternInfo()+"\"");
if (arguments!=null){
for (int i=0;i<arguments.length;i++){
System.out.println("Console line "+i+" = \""+arguments[i]+"\"");
}
}
}
log("Writing to console "+iCons.getName()+":", arguments, null, false, true); /* Appears in the console of the target Eclipse (immediately erased) */
log("Writing to console "+iCons.getName()+":", arguments, null, false, false); /* Appears in the console of the parent Eclipse */
// IOConsoleInputStream inStream= iCons.getInputStream();
IOConsoleOutputStream outStream= iCons.newOutputStream();
IProcess process=((ProcessConsole)iCons).getProcess();
IStreamsProxy iStreamProxy= process.getStreamsProxy();
IStreamsProxy consoleInStreamProxy= process.getStreamsProxy();
BuildParamsItem stderrParser=getParser(configuration, buildParamsItem.getStderr()); // re-parses all - why?
BuildParamsItem stdoutParser=getParser(configuration, buildParamsItem.getStdout());
System.out.println("Using parser for stderr: "+((stderrParser!=null)?stderrParser.getNameAsParser():"none")); // actually may be the same as stdout
System.out.println("Using parser for stdout: "+((stdoutParser!=null)?stdoutParser.getNameAsParser():"none"));
// basically use
// IProcess process=run(configuration, launch, monitor);
// renderProcessLabel(configuration.getToolName()+":out")
IProcess processErr=null;
IProcess processOut=null;
IStreamsProxy stdoutStreamProxy=null;
IStreamsProxy stderrStreamProxy=null;
if (stdoutParser!=null){
List<String> toolArgumentsStdout = new ArrayList<String>();
List<String> stdoutArguments=stdoutParser.getParamsAsList();
if (stdoutArguments != null)
toolArgumentsStdout.addAll(stdoutArguments);
// overwriting configuration, but this is done sequentially, so OK
configuration.setToolArguments((String[])toolArgumentsStdout.toArray(new String[toolArgumentsStdout.size()]));
processOut=run(configuration,
renderProcessLabel(configuration.getToolName()+":out"),
launch,
null); //monitor);
stdoutStreamProxy= processOut.getStreamsProxy();
//TODO: Add error parsers
}
if (stderrParser!=null){
List<String> toolArgumentsStderr = new ArrayList<String>();
List<String> stderrArguments=stderrParser.getParamsAsList();
if (stderrArguments != null)
toolArgumentsStderr.addAll(stderrArguments);
// overwriting configuration, but this is done sequentially, so OK
configuration.setToolArguments((String[])toolArgumentsStderr.toArray(new String[toolArgumentsStderr.size()]));
processErr=run(configuration,
renderProcessLabel(configuration.getToolName()+":err"),
launch,
null); //monitor);
stderrStreamProxy= processErr.getStreamsProxy();
//TODO: Add error parsers
}
final IStreamsProxy fSendErrorsToStreamProxy=(stderrStreamProxy!=null)?stderrStreamProxy:stdoutStreamProxy;
final IStreamsProxy fSendOutputToStreamProxy= stdoutStreamProxy;
// connect input streams of the parsers to the out from the console process
IStreamMonitor consoleOutStreamMonitor=null;
IStreamMonitor consoleErrStreamMonitor=null;
if (fSendErrorsToStreamProxy!=null){
consoleErrStreamMonitor=consoleInStreamProxy.getErrorStreamMonitor();
consoleErrStreamMonitor.addListener(new IStreamListener(){
public void streamAppended(String text, IStreamMonitor monitor){
System.out.println("Err:'"+text+"'");
try {
fSendErrorsToStreamProxy.write(text);
} catch (IOException e) {
System.out.println("Can not write errors");
}
}
});
}
if (fSendOutputToStreamProxy!=null){
consoleOutStreamMonitor=consoleInStreamProxy.getOutputStreamMonitor();
consoleOutStreamMonitor.addListener(new IStreamListener(){
public void streamAppended(String text, IStreamMonitor monitor){
System.out.println("Out:'"+text+"'");
try {
fSendOutputToStreamProxy.write(text);
} catch (IOException e) {
System.out.println("Can not write output");
}
}
});
}
try {
for (int i=0;i<arguments.length;i++){
if (VerilogPlugin.getPreferenceBoolean(PreferenceStrings.LOCAL_ECHO)) {
outStream.setColor(new Color(null, 128, 128, 255));
outStream.write(arguments[i]+"\n"); // writes to console itself
outStream.setColor(null);
}
iStreamProxy.write(arguments[i]+"\n");
consoleInStreamProxy.write(arguments[i]+"\n");
}
} catch (IOException e) {
System.out.println("Can not write to outStream of console "+iCons.getName());
}
return iCons;
}
......@@ -317,6 +424,12 @@ public class VDTRunner {
return DebugPlugin.exec(cmdLine, workingDirectory, envp);
}
private String combinePatterns (String thisPattern, String toolPattern){
String pattern=thisPattern;
if (pattern==null) pattern=toolPattern;
if ((pattern!=null) && (pattern.length()==0)) pattern=null;
return pattern;
}
/**
* Launches a Verilog development tool as specified in the given
* configuration, contributing results (processes), to the given
......@@ -328,6 +441,7 @@ public class VDTRunner {
* @exception CoreException if an exception occurs while launching
*/
public IProcess run( VDTRunnerConfiguration configuration
, String consoleLabel
, ILaunch launch
, IProgressMonitor monitor
) throws CoreException
......@@ -335,6 +449,12 @@ public class VDTRunner {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
int numItem=configuration.getBuildStep();
// BuildParamsItem buildParamsItem= VDTLaunchUtil.getArguments(configuration.getConfiguration())[numItem];
BuildParamsItem buildParamsItem = configuration.getArgumentsItemsArray()[numItem]; // uses already calculated
String patternErrors= combinePatterns(buildParamsItem.getErrors(), configuration.getPatternErrors()) ;
String patternWarnings=combinePatterns(buildParamsItem.getWarnings(),configuration.getPatternWarnings()) ;
String patternInfo= combinePatterns(buildParamsItem.getInfo(), configuration.getPatternInfo()) ;
IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1);
subMonitor.beginTask(Txt.s("Launch.Message.Launching"), 2);
......@@ -344,9 +464,9 @@ public class VDTRunner {
String[] arguments = configuration.getToolArguments();
boolean isShell= configuration.getIsShell();
if (VerilogPlugin.getPreferenceBoolean(PreferenceStrings.DEBUG_LAUNCHING)) {
System.out.println("patternErrors= \""+ configuration.getPatternErrors()+"\"");
System.out.println("patternWarnings= \""+configuration.getPatternWarnings()+"\"");
System.out.println("patternInfo= \"" +configuration.getPatternInfo()+"\"");
System.out.println("patternErrors= \""+ patternErrors+"\"");
System.out.println("patternWarnings= \""+patternWarnings+"\"");
System.out.println("patternInfo= \"" +patternInfo+"\"");
System.out.println((isShell?"Shell":"Tool")+" to launch=\""+toolTolaunch+"\"");
if (arguments!=null){
for (int i=0;i<arguments.length;i++){
......@@ -420,11 +540,14 @@ public class VDTRunner {
IProcess process= newProcess( launch
, p
// , renderProcessLabel(cmdLine)
, renderProcessLabel(configuration.getToolName())
, consoleLabel // renderProcessLabel(configuration.getToolName())
, getDefaultProcessAttrMap(configuration));
parser.parserSetup(
configuration,
process
process,
patternErrors,
patternWarnings,
patternInfo
);
subMonitor.worked(1);
......@@ -500,7 +623,7 @@ public class VDTRunner {
*
* @return default process attribute map for Java processes
*/
protected Map getDefaultProcessAttrMap(VDTRunnerConfiguration config) {
protected Map<String, String> getDefaultProcessAttrMap(VDTRunnerConfiguration config) {
Map<String, String> map = new HashMap<String, String>();
// map.put(IProcess.ATTR_PROCESS_TYPE, Utils.getPureFileName(config.getToolToLaunch()));
map.put(IProcess.ATTR_PROCESS_TYPE,config.getToolName());
......
......@@ -22,6 +22,7 @@ import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import com.elphel.vdt.Txt;
import com.elphel.vdt.core.tools.contexts.BuildParamsItem;
/**
......@@ -53,8 +54,16 @@ public class VDTRunnerConfiguration {
private ILaunchConfiguration configuration;
private ILaunch launch;
private IProgressMonitor monitor;
private BuildParamsItem[] argumentsItemsArray; // calculate once for the launch of the sequence
public BuildParamsItem[] getArgumentsItemsArray(){
return argumentsItemsArray;
}
public void setArgumentsItemsArray(BuildParamsItem[] argumentsItemsArray){
this.argumentsItemsArray=argumentsItemsArray;
}
private static final String[] empty= new String[0];
......
......@@ -28,6 +28,7 @@ import com.elphel.vdt.core.tools.params.conditions.Condition;
import com.elphel.vdt.core.tools.params.conditions.ConditionalStringsList;
import com.elphel.vdt.core.tools.params.conditions.NamedConditionalStringsList;
import com.elphel.vdt.core.tools.params.types.ParamTypeString;
import com.elphel.vdt.core.tools.params.types.ParamTypeString.KIND;
public class CommandLinesNodeReader extends AbstractConditionNodeReader {
List<CommandLinesBlock> commandLinesBlocks = new ArrayList<CommandLinesBlock>();
......@@ -49,13 +50,21 @@ public class CommandLinesNodeReader extends AbstractConditionNodeReader {
}
}
}
/*
*/
private CommandLinesBlock readCommandLinesBlock(Node node, Condition condition)
throws ConfigException
{
String name = XMLConfig.getAttributeValue(node, XMLConfig.CONTEXT_LINEBLOCK_NAME_ATTR);
String dest = XMLConfig.getAttributeValue(node, XMLConfig.CONTEXT_LINEBLOCK_DEST_ATTR);
String sep = XMLConfig.getAttributeValue(node, XMLConfig.CONTEXT_LINEBLOCK_SEP_ATTR);
String mark = XMLConfig.getAttributeValue(node, XMLConfig.CONTEXT_LINEBLOCK_MARK_ATTR);
String errors = XMLConfig.getAttributeValue(node, XMLConfig.CONTEXT_LINEBLOCK_ERRORS_ATTR);
String warnings = XMLConfig.getAttributeValue(node, XMLConfig.CONTEXT_LINEBLOCK_WARNINGS_ATTR);
String info = XMLConfig.getAttributeValue(node, XMLConfig.CONTEXT_LINEBLOCK_INFO_ATTR);
String prompt = XMLConfig.getAttributeValue(node, XMLConfig.CONTEXT_LINEBLOCK_PROMPT_ATTR);
String stderr = XMLConfig.getAttributeValue(node, XMLConfig.CONTEXT_LINEBLOCK_STDERR_ATTR);
String stdout = XMLConfig.getAttributeValue(node, XMLConfig.CONTEXT_LINEBLOCK_STDOUT_ATTR);
if(name == null)
throw new ConfigException("Unnamed lines block definition in context '" +
......@@ -73,11 +82,15 @@ public class CommandLinesNodeReader extends AbstractConditionNodeReader {
dest,
ParamTypeString.KIND.FILE, //Andrey - doesn't know "kind" here yet - TODO: change to attr
sep,
mark,
errors,
warnings,
info,
prompt,
stderr,
stdout,
lines,
deleteLines,
insertLines);
}
}
......@@ -127,6 +127,14 @@ public class XMLConfig extends Config {
static final String CONTEXT_LINEBLOCK_DEST_ATTR = "dest";
static final String CONTEXT_LINEBLOCK_SEP_ATTR = "sep";
static final String CONTEXT_LINEBLOCK_MARK_ATTR = "mark";
static final String CONTEXT_LINEBLOCK_ERRORS_ATTR = "errors";
static final String CONTEXT_LINEBLOCK_WARNINGS_ATTR = "warnings";
static final String CONTEXT_LINEBLOCK_INFO_ATTR = "info";
static final String CONTEXT_LINEBLOCK_PROMPT_ATTR = "prompt";
static final String CONTEXT_LINEBLOCK_STDERR_ATTR = "stderr";
static final String CONTEXT_LINEBLOCK_STDOUT_ATTR = "stdout";
static final String CONTEXT_STRINGS_DELETE_TAG = "delete";
static final String CONTEXT_STRINGS_INSERT_TAG = "insert";
static final String CONTEXT_STRINGS_INSERT_AFTER_ATTR = "after";
......
......@@ -17,21 +17,63 @@
*******************************************************************************/
package com.elphel.vdt.core.tools.contexts;
import java.util.Iterator;
import java.util.List;
public class BuildParamsItem implements Cloneable{
private String [] params;
private String consoleName; // null for external tools running in a new console
private String nameAsParser; // name as a parser, null if not used as a parser
// private String mark; // remove this sequence on the output only (to preserve white spaces) Already applied
private String toolErrors; // Eclipse pattern for pattern recognizer
private String toolWarnings; // Eclipse pattern for pattern recognizer
private String toolInfo; // Eclipse pattern for pattern recognizer
// for commands being sent to opened remote console:
private String prompt; // relevant for commands sent to remote console - double prompt means "done" (extra separator on input)
private String stderr; // name of the command to (command line block) to launch in a separate process/console
// and connect to stderr of the terminal session
private String stdout; // name of the command to (command line block) to launch in a separate process/console
// and connect to stderr of the terminal session
public BuildParamsItem (
String [] params,
String consoleName) {
String consoleName,
String nameAsParser,
// String mark,
String toolErrors,
String toolWarnings,
String toolInfo,
String prompt,
String stderr,
String stdout
) {
this.consoleName=consoleName;
this.params=params; // no need to clone?
this.nameAsParser=nameAsParser;
// this.mark=mark;
this.toolErrors=toolErrors;
this.toolWarnings=toolWarnings;
this.toolInfo=toolInfo;
this.prompt=prompt;
this.stderr=stderr;
this.stdout=stdout;
}
public BuildParamsItem (BuildParamsItem item){
this (
item.params,
item.consoleName);
item.consoleName,
item.nameAsParser,
// item.mark,
item.toolErrors,
item.toolWarnings,
item.toolInfo,
item.prompt,
item.stderr,
item.stdout
);
}
public BuildParamsItem clone () {
......@@ -48,19 +90,44 @@ public class BuildParamsItem implements Cloneable{
}
return arguments;
}
/*
String[] paramArray = tool.buildParams();
System.out.println("Andrey: called tool.buildParams() here (from VDTLaunchUtils.java");
List<String> arguments = new ArrayList<String>(paramArray.length);
for(int i = 0; i < paramArray.length; i++) {
arguments.add(paramArray[i]);
}
return arguments;
*/
public String getConsoleName(){
return consoleName;
}
/*
public void applyMark(){
if ((mark==null) || (mark.length()==0)) return;
if (params!=null) {
for (int i=0;i<params.length;i++){
params[i].replace(mark, "");
}
}
if (prompt!=null) prompt.replace(mark, "");
}
*/
public void removeNonParser(List<BuildParamsItem> items){
// if (items==null) return; should never happen as the list includes itself
if (nameAsParser==null) return;
if (consoleName==null) { // console script can not be a parser
Iterator<BuildParamsItem> itemsIter = items.iterator(); // command lines block is empty (yes, there is nothing in project output)
while(itemsIter.hasNext()) {
BuildParamsItem item = (BuildParamsItem)itemsIter.next();
if(
nameAsParser.equals(item.stderr) ||
nameAsParser.equals(item.stdout)){
return; // do nothing - keep nameAsParser
}
}
}
nameAsParser=null;
}
public String getNameAsParser(){ return nameAsParser; }
// public String getMark() { return mark; }
public String getErrors() { return toolErrors; }
public String getWarnings() { return toolWarnings; }
public String getInfo() { return toolInfo; }
public String getPrompt() { return prompt; }
public String getStderr() { return stderr; }
public String getStdout() { return stdout; }
}
......@@ -204,62 +204,94 @@ public abstract class Context {
if(!commandLinesBlock.isEnabled())
continue;
String paramName = commandLinesBlock.getDestination(); // Andrey debugging: null?
String destName = commandLinesBlock.getDestination();
boolean isConsoleName=commandLinesBlock.isConsoleKind();
String sep = commandLinesBlock.getSeparator();
String name=commandLinesBlock.getName();
String mark=commandLinesBlock.getMark();
String toolErrors=commandLinesBlock.getErrors();
String toolWarnings=commandLinesBlock.getWarnings();
String toolInfo=commandLinesBlock.getInfo();
String stderr=commandLinesBlock.getStderr();
String stdout=commandLinesBlock.getStdout();
String prompt=buildSimpleString(commandLinesBlock.getPrompt());
if ((prompt !=null ) && (mark!=null)) prompt=prompt.replace(mark, "");
List<String> lines = commandLinesBlock.getLines(); // [%Param_Shell_Options, echo BuildDir=%BuildDir ;, echo SimulationTopFile=%SimulationTopFile ;, echo SimulationTopModule=%SimulationTopModule ;, echo BuildDir=%BuildDir;, %Param_PreExe, %Param_Exe, %Param_TopModule, %TopModulesOther, %ModuleLibrary, %LegacyModel, %NoSpecify, %v, %SourceList, %ExtraFiles, %Filter_String]
List<List<String>> commandSequence = new ArrayList<List<String>>();
for(Iterator<String> lineIter = lines.iterator(); lineIter.hasNext();) {
String line = (String)lineIter.next();
commandSequence.add(buildCommandString(line));
commandSequence.add(buildCommandString(line)); // TODO: parses them here? VERIFY
}
// parse prompt?
// Here - already resolved to empty
List<String> commandLineParams = new ArrayList<String>();
if(paramName != null) {
Parameter commandFileParam = findParam(paramName);
String controlFileName = commandFileParam != null?
commandFileParam.getValue().get(0).trim() : null;
if(destName != null) {
Parameter parName = findParam(destName); // command file or console name
String controlFileName = parName != null?
parName.getValue().get(0).trim() : null;
if (isConsoleName) {
// System.out.println("TODO: Enable console command generation here");
printStringsToConsoleLine(commandLineParams, commandSequence);
printStringsToConsoleLine(commandLineParams, commandSequence,mark);
buildParamItems.add(
new BuildParamsItem (
(String[])commandLineParams.toArray(new String[commandLineParams.size()]),
controlFileName) // find console beginning with this name, send commands there
controlFileName, // find console beginning with this name, send commands there
name, //nameAsParser
// mark,
toolErrors,
toolWarnings,
toolInfo,
prompt,
stderr,
stdout)
);
} else {
} else { // processing command file
if(workingDirectory != null)
controlFileName = workingDirectory + File.separator + controlFileName;
// check param type first
if(!(commandFileParam.getType() instanceof ParamTypeString))
throw new ToolException("Parameter '" + commandFileParam.getID() +
"' specified in the description of context '" + name +
if(!(parName.getType() instanceof ParamTypeString))
throw new ToolException("Parameter '" + parName.getID() +
"' specified in the description of context '" + parName +
"' must be of type '" + ParamTypeString.NAME + "'");
// write strings to control file
boolean controlFileExists = controlFileExists(controlFileName);
printStringsToFile(controlFileName, controlFileExists, commandSequence, sep);
printStringsToFile(controlFileName, controlFileExists, commandSequence, sep, mark);
if(!controlFileExists)
createdControlFiles.add(controlFileName);
}
} else {
// TODO: will need multiple command lines // Andrey
printStringsToCommandLine(commandLineParams, commandSequence);
} else { // processing command line
printStringsToCommandLine(commandLineParams, commandSequence, mark);
buildParamItems.add(
new BuildParamsItem (
(String[])commandLineParams.toArray(new String[commandLineParams.size()]),
null) // external tool in a new console
null, // external tool in a new console
name, //nameAsParser
// mark,
toolErrors,
toolWarnings,
toolInfo,
prompt,
stderr,
stdout)
);
}
}
// return (String[])commandLineParams.toArray(new String[commandLineParams.size()]);
// keep names only for commands that are referenced in console scripts, others make null
Iterator<BuildParamsItem> buildParamItemsIter = buildParamItems.iterator(); // command lines block is empty (yes, there is nothing in project output)
while(buildParamItemsIter.hasNext()) {
BuildParamsItem buildParamsItem = (BuildParamsItem)buildParamItemsIter.next();
buildParamsItem.removeNonParser(buildParamItems);
}
return (BuildParamsItem[])buildParamItems.toArray(new BuildParamsItem[buildParamItems.size()]);
}
......@@ -276,6 +308,24 @@ public abstract class Context {
return processor.process(paramStringTemplate);
}
protected String buildSimpleString(String stringTemplate)
throws ToolException
{
if (stringTemplate==null) return null;
FormatProcessor processor = new FormatProcessor(new Recognizer[] {
new SimpleGeneratorRecognizer(),
// new RepeaterRecognizer()
// new ContextParamRecognizer(this),
// new ContextParamRepeaterRecognizer(this)
});
List<String> result= processor.process(stringTemplate);
if (result.size()==0) return "";
return result.get(0);
}
protected void initControlInterface() throws ConfigException {
if(controlInterfaceName != null) {
controlInterface = config.findControlInterface(controlInterfaceName);
......@@ -364,9 +414,11 @@ public abstract class Context {
private void printStringsToFile(String controlFileName,
boolean append,
List<List<String>> commandString,
String separator)
String separator,
String mark)
throws ToolException
{
boolean useMark=(mark!=null) && (mark.length()>0);
FileOutputStream outputStream = null;
try {
......@@ -391,8 +443,7 @@ public abstract class Context {
if(s.length() == 0)
continue;
out.print(s);
out.print(useMark?(s.replace(mark,"")):s);
written += s.length();
writtenNow += s.length();
......@@ -421,28 +472,31 @@ public abstract class Context {
}
private void printStringsToCommandLine(List<String> commandLineParams,
List<List<String>> commandSequence)
List<List<String>> commandSequence,
String mark)
throws ToolException
{
boolean useMark=(mark!=null) && (mark.length()>0);
for(Iterator<List<String>> li = commandSequence.iterator(); li.hasNext();) {
List<String> strList = (List<String>)li.next();
if(strList.size() > 0) {
for(Iterator<String> si = strList.iterator(); si.hasNext();) {
String s = ((String)si.next()).trim();
if(!s.equals(""))
commandLineParams.add(s);
commandLineParams.add(useMark?(s.replace(mark,"")):s);
}
}
}
}
// Andrey: now is the same as command line, but will change to allow last element be prompt
private void printStringsToConsoleLine(List<String> commandLineParams,
List<List<String>> commandSequence)
throws ToolException
private void printStringsToConsoleLine(
List<String> commandLineParams,
List<List<String>> commandSequence,
String mark) throws ToolException
{
boolean useMark=(mark!=null) && (mark.length()>0);
for(Iterator<List<String>> li = commandSequence.iterator(); li.hasNext();) {
List<String> strList = (List<String>)li.next();
......@@ -451,7 +505,7 @@ public abstract class Context {
String s = ((String)si.next()).trim();
if(!s.equals(""))
commandLineParams.add(s);
commandLineParams.add(useMark?(s.replace(mark,"")):s);
}
}
}
......
/*******************************************************************************
* Copyright (c) 2006 Elphel, Inc and Excelsior, LLC.
* Copyright (c) 2014 Elphel, Inc.
* This file is a part of Eclipse/VDT plug-in.
* Eclipse/VDT plug-in is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your option)
* any later version.
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Eclipse/VDT plug-in is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
* Eclipse/VDT plug-in is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with Eclipse VDT plug-in; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
package com.elphel.vdt.core.tools.generators;
......
/*******************************************************************************
* Copyright (c) 2006 Elphel, Inc and Excelsior, LLC.
* Copyright (c) 2014 Elphel, Inc.
* This file is a part of Eclipse/VDT plug-in.
* Eclipse/VDT plug-in is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your option)
* any later version.
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Eclipse/VDT plug-in is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
* Eclipse/VDT plug-in is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with Eclipse VDT plug-in; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
package com.elphel.vdt.core.tools.generators;
import org.eclipse.core.resources.IFile;
//import org.eclipse.core.resources.IResource;
//import org.eclipse.ui.IPageLayout;
import org.eclipse.core.runtime.Path;
import com.elphel.vdt.VDT;
import com.elphel.vdt.ui.variables.SelectedResourceManager;
......@@ -34,7 +28,6 @@ public class CurrentFileBaseGenerator extends AbstractGenerator {
}
protected String[] getStringValues() {
// IResource resource = SelectedResourceManager.getDefault().getSelectedResource();
String name=SelectedResourceManager.getDefault().getChosenShort(); // last segment of the file name
if (name!=null){
int dot = name.lastIndexOf('.');
......
/*******************************************************************************
* Copyright (c) 2006 Elphel, Inc and Excelsior, LLC.
* Copyright (c) 2014 Elphel, Inc.
* This file is a part of Eclipse/VDT plug-in.
* Eclipse/VDT plug-in is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your option)
* any later version.
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Eclipse/VDT plug-in is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
* Eclipse/VDT plug-in is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with Eclipse VDT plug-in; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
package com.elphel.vdt.core.tools.generators;
......@@ -26,22 +26,9 @@ import com.elphel.vdt.ui.variables.SelectedResourceManager;
public class CurrentFileGenerator extends AbstractGenerator {
private static final String NAME = VDT.GENERATOR_ID_CURRENT_FILE;
// private boolean menuMode=false; // managing menu items, not running tool
public String getName() {
return NAME;
}
/*
public CurrentFileGenerator(boolean menuMode){
super();
this.menuMode=menuMode;
}
*/
/*
public void setMenuMode(boolean menuMode){
this.menuMode=menuMode;
}
*/
protected String[] getStringValues() {
IResource resource;
if (getMenuMode()) {
......
......@@ -32,15 +32,36 @@ public class CommandLinesBlock extends UpdateableStringsContainer
{
private String contextName;
private String name;
private String destination;
private String destination; // now references either file for command file, or console name prefix to send data to
private String separator;
private KIND kind; //command file name or console name
private String mark; // remove this sequence on the output only (to preserve white spaces)
private String toolErrors; // Eclipse pattern for pattern recognizer
private String toolWarnings; // Eclipse pattern for pattern recognizer
private String toolInfo; // Eclipse pattern for pattern recognizer
// for commands being sent to opened remote console:
private String prompt; // relevant for commands sent to remote console - double prompt means "done" (extra separator on input)
private String stderr; // name of the command to (command line block) to launch in a separate process/console
// and connect to stderr of the terminakl session
private String stdout; // name of the command to (command line block) to launch in a separate process/console
// and connect to stderr of the terminal session
// If both are specified and pointing to the same command block - two instances/consoles will be launched.
// if only stdout - both stdout and stdin of a session will go to the same process/console
public CommandLinesBlock(String contextName,
String name,
String destination,
KIND kind,
String sep,
String mark,
String toolErrors,
String toolWarnings,
String toolInfo,
String prompt,
String stderr,
String stdout,
ConditionalStringsList lines,
ConditionalStringsList deleteLines,
List<NamedConditionalStringsList> insertLines)
......@@ -52,6 +73,13 @@ public class CommandLinesBlock extends UpdateableStringsContainer
this.destination = destination;
this.kind=kind;
this.separator = sep;
this.mark=mark;
this.toolErrors=toolErrors;
this.toolWarnings=toolWarnings;
this.toolInfo=toolInfo;
this.prompt=prompt;
this.stderr=stderr;
this.stdout=stdout;
if(separator != null) {
separator = separator.replace("\\n", "\n");
......@@ -65,6 +93,13 @@ public class CommandLinesBlock extends UpdateableStringsContainer
block.destination,
block.kind,
block.separator,
block.mark,
block.toolErrors,
block.toolWarnings,
block.toolInfo,
block.prompt,
block.stderr,
block.stdout,
block.strings != null?
(ConditionalStringsList)block.strings.clone() : null,
block.deleteStrings != null?
......@@ -105,7 +140,7 @@ public class CommandLinesBlock extends UpdateableStringsContainer
"' or '" + ParamTypeString.KIND_TEXT_ID +
"'");
}
System.out.println("Got string text kind for command block (for console name)");
// System.out.println("Got string text kind for command block (for console name)");
}
}
}
......@@ -119,38 +154,25 @@ public class CommandLinesBlock extends UpdateableStringsContainer
return name.equals(((CommandLinesBlock)other).name);
}
public String getDestination() {
return destination;
}
public KIND getKind() {
return kind;
}
public boolean isFileKind() {
return kind == ParamTypeString.KIND.FILE;
}
public String getDestination() { return destination; }
public KIND getKind() { return kind;}
public boolean isFileKind() {return kind == ParamTypeString.KIND.FILE; }
public boolean isConsoleKind() { return kind == ParamTypeString.KIND.TEXT; }
public List<String> getLines() { return ConditionUtils.resolveConditionStrings(strings); }
public String getName() { return name; }
public String getSeparator() { return separator; }
public String getMark() { return mark; }
public String getErrors() { return toolErrors; }
public String getWarnings() { return toolWarnings; }
public String getInfo() { return toolInfo; }
public String getPrompt() { return prompt; }
public String getStderr() { return stderr; }
public String getStdout() { return stdout; }
public boolean isConsoleKind() {
return kind == ParamTypeString.KIND.TEXT;
}
public List<String> getLines() {
return ConditionUtils.resolveConditionStrings(strings);
}
public String getName() {
return name;
}
public String getSeparator() {
return separator;
}
public boolean isEnabled() {
if(destination == null) // command line
return true;
return !destination.equals("");
}
......
......@@ -80,7 +80,7 @@ public class FormatProcessor {
if(template.startsWith(CONTROL_SEQ, pos)) {
pos += CONTROL_SEQ_LEN;
RecognizerResult result = recognize(template, pos);
RecognizerResult result = recognize(template, pos); // Already skipped blank lines (and spaces in each line, added separators - no, on deifferent level
if(result != null && result.getGenerator() != null) {
assert result.getNewPos() > pos;
......@@ -167,7 +167,7 @@ public class FormatProcessor {
// we need to check if 'firstLineToAdd' ends with a blank space
// in such a case we just add all the generated lines in the list
// otherwise, we glue the line with first of additional ones
if(!Utils.stringEndsWithSpace(firstLineToAdd)) {
if(!Utils.stringEndsWithSpace(firstLineToAdd)) { //last character is space or \n
glueToLastLine(lines, processedLines.get(0));
addFrom = 1;
}
......@@ -175,7 +175,7 @@ public class FormatProcessor {
for(int i = addFrom; i < processedLines.size(); i++) {
String line = processedLines.get(i);
if(!line.equals(""))
if(!line.equals("")) // Why drop blank lines?
lines.add(line);
}
}
......
......@@ -52,51 +52,6 @@ public class Parameter implements Cloneable, Updateable {
private boolean isChild; // Andrey: trying to resolve double inheritance - at configuration time and when generating output
private String sourceXML; // Andrey: For error reporting - individual to parameter
/*
public Parameter(String id,
String outid,
String typeName,
String syntaxName,
String defaultValue,
String label,
String omitValue,
String readonly,
String visible,
Condition relevant){
this(id,
outid,
typeName,
syntaxName,
defaultValue,
label,
omitValue,
readonly,
visible,
relevant,
null);
}
public Parameter(String id,
String outid,
String typeName,
String syntaxName,
String defaultValue,
String label,
String omitValue,
String readonly,
String visible)
{
this(id,
outid,
typeName,
syntaxName,
defaultValue,
label,
omitValue,
readonly,
visible,
null);
}
*/
public Parameter(String id,
String outid,
String typeName,
......
......@@ -34,7 +34,9 @@ public class SimpleGeneratorRecognizer implements Recognizer {
new CurrentFileGenerator(),
new CurrentFileBaseGenerator(),
new ChosenActionGenerator(),
new BuildStampGenerator()
new BuildStampGenerator(),
new BlankGenerator(),
new NewLineGenerator()
};
public SimpleGeneratorRecognizer(){
......
......@@ -4,81 +4,42 @@
<interface name="RemoteInterface" extends="project_interface">
<syntax name="ProgramSyntax" format="%(%%ParamValue%|\n%)" />
</interface>
<tool name = "RemotePython"
project = "FPGA_project"
label = "RemotePython"
shell = "/bin/bash"
interface = "RemoteInterface"
description = "Launching remote Python in console"
errors = "(.*):([0-9]+): [a-z ]*error: (.*)"
warnings = "(.*):([0-9]+): warning: (.*)"
info = "(.*):([0-9]+): info: (.*)"> <!--does not actually exist -->
<tool name="RemotePython" project="FPGA_project" label="RemotePython"
shell="/bin/bash" interface="RemoteInterface" description="Launching remote Python in console"
errors="(.*):([0-9]+): [a-z ]*error: (.*)" warnings="(.*):([0-9]+): warning: (.*)"
info="(.*):([0-9]+): info: (.*)"> <!--does not actually exist -->
<extensions-list>
<extension mask="v"/>
<extension mask="tf"/>
<extension mask="v" />
<extension mask="tf" />
</extensions-list>
<action-menu>
<action label="Remote Python" resource="" icon="python.png" />
</action-menu>
<parameter id = "RemoteHost"
label = "Remote Host IP"
type = "String"
format = "CopyValue"
default = "192.168.0.66"
readonly = "false"
visible = "true"/>
<parameter id = "RemoteUser"
label = "Remote user name"
type = "String"
format = "CopyValue"
default = ""
readonly = "false"
visible = "true"/>
<parameter id = "PreSSH"
label = "pre-ssh shell parameters"
type = "String"
format = "CopyValue"
default = ""
readonly = "false"
visible = "true"/>
<parameter id = "ShellSwitches"
label = "Shell switches"
type = "String"
format = "CopyValue"
default = "-c"
readonly = "false"
visible = "true"/>
<parameter id = "SSHSwitches"
label = "Remote ssh switches"
type = "String"
format = "CopyValue"
default = ""
readonly = "false"
visible = "true"/>
<parameter id = "RemoteCommand"
label = "Remote ssh command"
type = "String"
format = "CopyValue"
default = "python -i -u"
readonly = "false"
visible = "true"/>
<parameter id = "SSHExtra"
label = "ssh extra parameters"
type = "String"
format = "CopyValue"
default = ""
readonly = "false"
visible = "true"/>
<parameter id="RemoteHost" label="Remote Host IP" type="String"
format="CopyValue" default="192.168.0.66" readonly="false" visible="true" />
<parameter id="RemoteUser" label="Remote user name" type="String"
format="CopyValue" default="" readonly="false" visible="true" />
<parameter id="PreSSH" label="pre-ssh shell parameters"
type="String" format="CopyValue" default="" readonly="false" visible="true" />
<parameter id="ShellSwitches" label="Shell switches" type="String"
format="CopyValue" default="-c" readonly="false" visible="true" />
<parameter id="SSHSwitches" label="Remote ssh switches"
type="String" format="CopyValue" default="" readonly="false" visible="true" />
<parameter id="RemoteCommand" label="Remote ssh command"
type="String" format="CopyValue" default="python -i -u" readonly="false"
visible="true" />
<parameter id="SSHExtra" label="ssh extra parameters" type="String"
format="CopyValue" default="" readonly="false" visible="true" />
<input>
<group name="General">
......@@ -108,31 +69,22 @@
</line>
</output>
</tool>
<tool name = "RemotePythonCommand"
project = "FPGA_project"
label = "RemotePythonCommand"
shell = "/bin/bash"
interface = "RemoteInterface"
description = "Sending command to a ermote Python session"
errors = "(.*):([0-9]+): [a-z ]*error: (.*)"
warnings = "(.*):([0-9]+): warning: (.*)"
info = "(.*):([0-9]+): info: (.*)"> <!--does not actually exist -->
<tool name="RemotePythonCommand" project="FPGA_project" label="RemotePythonCommand"
shell="/bin/bash" interface="RemoteInterface"
description="Sending command to a ermote Python session" errors="(.*):([0-9]+): [a-z ]*error: (.*)"
warnings="(.*):([0-9]+): warning: (.*)" info="(.*):([0-9]+): info: (.*)"> <!--does not actually exist -->
<extensions-list>
<extension mask="v"/>
<extension mask="tf"/>
<extension mask="v" />
<extension mask="tf" />
</extensions-list>
<action-menu>
<action label="Remote Python Command" resource="" icon="python.png" />
</action-menu>
<parameter id = "RemoteCommand"
label = "Remote Command to send"
type = "Stringlist"
format = "ProgramSyntax"
default = "print &quot;Hello, World!, 2*2=&quot;,2*2"
readonly = "false"
visible = "true"/>
<parameter id="RemoteCommand" label="Remote Command to send"
type="Stringlist" format="ProgramSyntax" default="print &quot;Hello, World!, 2*2=&quot;,2*2"
readonly="false" visible="true" />
<parameter id="python_console_name" default="RemotePython"
type="String" format="CopyValue" visible="false" />
......@@ -144,21 +96,38 @@
</input>
<output>
<line name="command_line">
<line name="command_line_01">
"-c"
"echo 'Nothing to do, sleeping 5' ;"
"sleep 5 ;"
"echo 'Nothing to do, awakening' ;"
</line>
<line name="console_line" dest="python_console_name" sep="\n">
<!-- prompt: recognizer should trim spaces too -->
<!-- stdout - both with stderr, stderr only ..., both to the same - to separate console instances -->
<line name="console_line_01"
dest="python_console_name"
mark="``"
sep="\n"
prompt=">>>"
stdout="parser_001">
"%RemoteCommand"
"``" <!-- two new lines should generate a pair of prompts from the remote -->
</line>
<line name="command_line">
<line name="command_line_02">
"-c"
"echo 'Nothing to do second time, sleeping 10' ;"
"sleep 10 ;"
"echo 'Nothing to do again, awakening after sleep 10' ;"
</line>
<!-- parser_01 being referenced should be launched in an asynchronous process/console, removed from the launch sequence -->
<line name="parser_001"
errors="(.*):([0-9]+): [a-z ]*error: (.*)"
warnings="(.*):([0-9]+): warning: (.*)"
info="(.*):([0-9]+): info: (.*)">
"-c"
"grep --line-buffered 'End'"
</line>
</output>
</tool>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment