Commit a36916c7 authored by Andrey Filippov's avatar Andrey Filippov

Adding possibility to runs several sequential external tools waiting for

completion, preparing to communicate with external server.
parent 0c056d60
/com
/BuildParamsItem.class
......@@ -266,7 +266,7 @@ public class LaunchCore {
if (!saveAllEditors(true)) {
return;
}
System.out.println("launchInBackground, JOB_NAME="+JOB_NAME);
Job job = new Job(JOB_NAME) {
public IStatus run(final IProgressMonitor monitor) {
try {
......@@ -293,6 +293,7 @@ public class LaunchCore {
if (!saveAllEditors(true)) {
return;
}
System.out.println("launchInForeground, JOB_NAME="+JOB_NAME);
IRunnableWithProgress runnable = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException {
......
......@@ -18,7 +18,6 @@
package com.elphel.vdt.core.launching;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
......@@ -49,6 +48,8 @@ public class VDTLaunchConfigurationDelegate implements ILaunchConfigurationDeleg
) throws CoreException
{
VDTRunner runner = VDTLaunchUtil.getRunner();
if (monitor == null) {
monitor = new NullProgressMonitor();
}
......@@ -71,21 +72,14 @@ public class VDTLaunchConfigurationDelegate implements ILaunchConfigurationDeleg
// resolve working directory
runConfig.setWorkingDirectory(VDTLaunchUtil.getWorkingDirectory(configuration));
runConfig.setProjectPath(VDTLaunchUtil.getProjectPath(configuration));
runConfig.setConfiguration(configuration); // to be resumed
runConfig.setLaunch(launch); // to be resumed
runConfig.setMonitor(monitor); // to be resumed
// done the half of creating arguments phase
monitor.worked(1);
// resolve arguments
List<String> arguments = VDTLaunchUtil.getArguments(configuration);
// get tool is a shell
boolean isShell=VDTLaunchUtil.getIsShell(configuration);
// get patterns for Error parser
String patternErrors= VDTLaunchUtil.getPatternErrors(configuration);
String patternWarnings=VDTLaunchUtil.getPatternWarnings(configuration);
String patternInfo= VDTLaunchUtil.getPatternInfo(configuration);
// check for cancellation
if (monitor.isCanceled()) {
return;
......@@ -93,8 +87,6 @@ public class VDTLaunchConfigurationDelegate implements ILaunchConfigurationDeleg
// done the creating arguments phase
monitor.worked(2);
// resolve resources
// List<String> resources = VDTLaunchUtil.getResources(configuration);
// check for cancellation
if (monitor.isCanceled()) {
......@@ -104,34 +96,22 @@ public class VDTLaunchConfigurationDelegate implements ILaunchConfigurationDeleg
monitor.worked(3);
// resolve arguments
List<String> toolArguments = new ArrayList<String>();
if (arguments != null)
toolArguments.addAll(arguments);
// if (resources != null)
// toolArguments.addAll(resources);
runConfig.setToolArguments((String[])toolArguments.toArray(new String[toolArguments.size()]));
runConfig.setIsShell(isShell);
runConfig.setPatternErrors(patternErrors);
runConfig.setIsShell(VDTLaunchUtil.getIsShell(configuration));
runConfig.setPatternErrors(VDTLaunchUtil.getPatternErrors(configuration));
runConfig.setToolName(VDTLaunchUtil.getToolName(configuration));
runConfig.setPatternWarnings(patternWarnings);
runConfig.setPatternInfo(patternInfo);
runConfig.setPatternWarnings(VDTLaunchUtil.getPatternWarnings(configuration));
runConfig.setPatternInfo(VDTLaunchUtil.getPatternInfo(configuration));
runConfig.setToolProjectPath(VDTLaunchUtil.getToolProjectPath(configuration));
runConfig.setBuildStep(0);
List<String> controlFiles = VDTLaunchUtil.getControlFiles(configuration);
runConfig.setControlFiles((String[])controlFiles.toArray(new String[controlFiles.size()]));
// Launch the configuration - 1 unit of work
VDTRunner runner = VDTLaunchUtil.getRunner();
runner.run(runConfig, launch, monitor);
// check for cancellation
if (monitor.isCanceled()) {
String consoleName=VDTRunner.renderProcessLabel(runConfig.getToolName());
runner.saveUnfinished(consoleName, runConfig );
runner.resumeLaunch(consoleName);
return;
}
monitor.done();
}
public void launch( ILaunchConfiguration configuration
, String mode
......@@ -149,4 +129,5 @@ public class VDTLaunchConfigurationDelegate implements ILaunchConfigurationDeleg
}
}
} // class VDTLaunchConfigurationDelegate
......@@ -43,6 +43,7 @@ import com.elphel.vdt.VerilogUtils;
// import com.elphel.vdt.VDTPlugin;
import com.elphel.vdt.veditor.VerilogPlugin;
import com.elphel.vdt.core.tools.ToolsCore;
import com.elphel.vdt.core.tools.contexts.BuildParamsItem;
import com.elphel.vdt.core.tools.params.Parameter;
import com.elphel.vdt.core.tools.params.Tool;
import com.elphel.vdt.core.tools.params.ToolException;
......@@ -63,8 +64,12 @@ public class VDTLaunchUtil {
* Returns the VDT runner.
*/
public static VDTRunner getRunner() {
if (toolRunner == null)
if (toolRunner == null) {
System.out.println ("Created new VDTRunner()");
toolRunner = new VDTRunner();
} else {
System.out.println ("Reused old VDTRunner()");
}
return toolRunner;
}
......@@ -122,7 +127,8 @@ public class VDTLaunchUtil {
* @throws CoreException if unable to retrieve the associated launch
* configuration attribute, or if unable to resolve any variables
*/
public static List<String> getArguments(ILaunchConfiguration configuration) throws CoreException {
// public static List<String> getArguments(ILaunchConfiguration configuration) throws CoreException {
public static BuildParamsItem[] getArguments(ILaunchConfiguration configuration) throws CoreException {
Tool tool = obtainTool(configuration);
for (Iterator i = tool.getParams().iterator(); i.hasNext(); ) {
......@@ -147,13 +153,19 @@ public class VDTLaunchUtil {
try {
String location = getWorkingDirectory(configuration);
tool.setWorkingDirectory(location);
/*
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;
*/
BuildParamsItem[] paramItemsArray = tool.buildParams();
System.out.println("Andrey: called tool.buildParams() here (from VDTLaunchUtils.java");
return paramItemsArray;
} catch(ToolException e) {
MessageUI.error("Error occured during tool launch: " + e.getMessage(), e);
}
......
......@@ -20,12 +20,27 @@ package com.elphel.vdt.core.launching;
import java.io.File;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
//import org.eclipse.core.resources.IProject;
//import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
......@@ -35,19 +50,39 @@ 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.ILaunchConfiguration;
import org.eclipse.debug.core.model.IProcess;
//import org.eclipse.debug.ui.DebugUITools;
//import org.eclipse.ui.console.ConsolePlugin;
//import org.eclipse.ui.console.IConsoleManager;
//import org.eclipse.ui.console.IPatternMatchListener;
//import org.eclipse.ui.console.MessageConsole;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.ui.console.ConsolePlugin;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.ui.console.IConsole;
//import org.eclipse.debug.ui.console.IConsole;
import org.eclipse.ui.console.ConsolePlugin;
import org.eclipse.ui.console.IConsoleManager;
import org.eclipse.ui.console.IPatternMatchListener;
import org.eclipse.ui.console.MessageConsole;
import org.eclipse.ui.console.IOConsole;
import com.elphel.vdt.Txt;
import com.elphel.vdt.core.tools.contexts.BuildParamsItem;
import com.elphel.vdt.ui.MessageUI;
//import com.elphel.vdt.VDTPlugin;
import com.elphel.vdt.veditor.VerilogPlugin;
import com.elphel.vdt.veditor.preference.PreferenceStrings;
import com.elphel.vdt.core.Utils;
//import com.elphel.vdt.core.Utils;
import org.eclipse.ui.console.IConsoleListener;
/**
* Verilog development tool runner.
......@@ -58,6 +93,181 @@ import com.elphel.vdt.core.Utils;
public class VDTRunner {
// TODO:Remove
VDTRunnerConfiguration runningConfiguration; // multi-step configuration currently active
int nextBuildStep=0;
private Map<String, VDTRunnerConfiguration> unfinishedBuilds;
public VDTRunner(){
unfinishedBuilds = new HashMap<String, VDTRunnerConfiguration>();
IConsoleManager manager = ConsolePlugin.getDefault().getConsoleManager();
// This is not used, just for testing
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());
}
}
});
}
public boolean isUnfinished(String consoleName){
return unfinishedBuilds.containsKey(consoleName);
}
public VDTRunnerConfiguration resumeConfiguration(String consoleName){
VDTRunnerConfiguration conf=unfinishedBuilds.get(consoleName);
unfinishedBuilds.remove(consoleName);
return conf;
}
public void removeConfiguration(String consoleName){
unfinishedBuilds.remove(consoleName);
}
public void saveUnfinished(String consoleName, VDTRunnerConfiguration configuration ){
unfinishedBuilds.put(consoleName, configuration);
}
// make call it when console is closed
private void doResumeLaunch( String consoleName ) throws CoreException {
// System.out.println("--------- resuming "+ consoleName+" ------------");
VDTRunnerConfiguration runConfig=resumeConfiguration(consoleName);
if (runConfig==null){
System.out.println("Turned out nothing to do. Probably a bug");
return;
}
ILaunchConfiguration configuration=runConfig.getConfiguration();
BuildParamsItem[] argumentsItemsArray = VDTLaunchUtil.getArguments(configuration);
int numItem=runConfig.getBuildStep();
System.out.println("--------- resuming "+ consoleName+", numItem="+numItem+" ------------");
ILaunch launch=runConfig.getLaunch();
IProgressMonitor monitor=runConfig.getMonitor();
for (;numItem<argumentsItemsArray.length;numItem++){
List<String> toolArguments = new ArrayList<String>();
List<String> arguments=argumentsItemsArray[numItem].getParamsAsList();
if (arguments != null)
toolArguments.addAll(arguments);
// if (resources != null)
// toolArguments.addAll(resources);
if (argumentsItemsArray[numItem].getConsoleName()!=null){
System.out.println("VDTLaunchConfigurationDelegate.doLaunch: console commands not yet implemented for runner #"+numItem);
continue;
}
runConfig.setToolArguments((String[])toolArguments.toArray(new String[toolArguments.size()]));
// Launch the configuration - 1 unit of work
// VDTRunner runner = VDTLaunchUtil.getRunner();
IProcess process=run(runConfig, launch, monitor);
//Andrey: if there is a single item - launch asynchronously, if more - verify queue is empty
// will not change
// String consoleName=renderProcessLabel(runConfig.getToolName());
// check for cancellation
if (monitor.isCanceled() || (process==null)) {
removeConfiguration(consoleName);
return;
}
if (numItem<(argumentsItemsArray.length-1)){ // Not for the last
// IConsoleManager man = ConsolePlugin.getDefault().getConsoleManager(); // debugging
// IConsole[] consoles=(IConsole[]) man.getConsoles();
IOConsole iCons= (IOConsole) DebugUITools.getConsole(process); // had non-null fPatternMatcher , fType="org.eclipse.debug.ui.ProcessConsoleType"
if (iCons==null){
System.out.println("Could not get a console for the specified process");
continue;
}
System.out.println("consoleName="+consoleName+
"\nprocessConsole name="+iCons.getName());
final IOConsole fiCons=iCons;
// final String fConsoleName=fiCons.getName(); // actual console name - may be already "<terminated> ... "
final String fConsoleName=consoleName; // calculated console name - used for launching external program
// if (!fConsoleName.equals(consoleName)){ // terminated before we added listeners
if (!fConsoleName.equals(fiCons.getName())){ // terminated before we added listeners
System.out.println("Already terminated, proceed to the next item");
continue; // proceed with the next item without pausing
}
/* Prepare to postpone next commands to be resumed by event*/
runConfig.setBuildStep(numItem+1);
saveUnfinished(consoleName, runConfig );
iCons.addPropertyChangeListener( new IPropertyChangeListener() {
public void propertyChange(PropertyChangeEvent event) {
if (!fConsoleName.equals(fiCons.getName())){
fiCons.removePropertyChangeListener(this);
System.out.println(">>> "+fConsoleName+" -> "+fiCons.getName());
VDTRunner runner = VDTLaunchUtil.getRunner();
try {
runner.resumeLaunch(fConsoleName);
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
});
if (!fConsoleName.equals(consoleName)){ // terminated before we added listeners
System.out.println("Fire!");
iCons.firePropertyChange(fiCons,"org.eclipse.jface.text", consoleName, fConsoleName);
}
System.out.println("return - waiting to be awaken");
return;
}
}
monitor.done();
}
/* process.getStreamsProxy().getOutputStreamMonitor().addListener(new IStreamListener(){
public void streamAppended (String text, IStreamMonitor monitor){
//TODO: As per user requirement.
}
});
*/
/*
public void parserSetup(
VDTRunnerConfiguration configuration,
IProcess process
){
iCons= (IOConsole) DebugUITools.getConsole(process); // had non-null fPatternMatcher , fType="org.eclipse.debug.ui.ProcessConsoleType"
if (iCons==null){
System.out.println("Could not get a console for the specified process");
}
}
*/
public void resumeLaunch( String consoleName ) throws CoreException
{
try {
doResumeLaunch(consoleName);
} catch(Exception e) {
MessageUI.error(e);
if(e instanceof CoreException)
throw (CoreException)e;
}
}
/**
* Returns a new process aborting if the process could not be created.
* @param launch the launch the process is contained in
......@@ -78,6 +288,7 @@ public class VDTRunner {
/** @see DebugPlugin#exec(String[], File, String[]) */
// before actual launching?
protected Process exec(String[] cmdLine, File workingDirectory, String[] envp) throws CoreException {
return DebugPlugin.exec(cmdLine, workingDirectory, envp);
}
......@@ -92,7 +303,7 @@ public class VDTRunner {
* @param monitor progress monitor or <code>null</code>
* @exception CoreException if an exception occurs while launching
*/
public void run( VDTRunnerConfiguration configuration
public IProcess run( VDTRunnerConfiguration configuration
, ILaunch launch
, IProgressMonitor monitor
) throws CoreException
......@@ -158,29 +369,34 @@ public class VDTRunner {
// check for cancellation
if (monitor.isCanceled()) {
return;
return null;
}
subMonitor.subTask(Txt.s("Launch.Message.Starting"));
File workingDir = getWorkingDir(configuration); /* /data/vdt/runtime-EclipseApplication/x353 */
Process p = exec(cmdLine, workingDir, envp);
if (p == null) {
return;
return null;
}
// check for cancellation
if (monitor.isCanceled()) {
p.destroy();
return;
return null;
}
/* next actually launches the process */
/* IProcess may set/get client parameters */
VDTErrorParser parser= VerilogPlugin.getVDTErrorParser();
IConsoleManager man = ConsolePlugin.getDefault().getConsoleManager(); // debugging
IConsole[] consoles=(IConsole[]) man.getConsoles();
//[Lorg.eclipse.ui.console.IConsole; cannot be cast to [Lorg.eclipse.debug.ui.console.IConsole;
/* next actually launches the process */
/* IProcess may set/get client parameters */
IProcess process= newProcess( launch
, p
, renderProcessLabel(cmdLine)
// , renderProcessLabel(cmdLine)
, renderProcessLabel(configuration.getToolName())
, getDefaultProcessAttrMap(configuration));
parser.parserSetup(
configuration,
......@@ -189,6 +405,17 @@ public class VDTRunner {
subMonitor.worked(1);
subMonitor.done();
man = ConsolePlugin.getDefault().getConsoleManager(); // debugging
consoles=(IConsole[]) man.getConsoles();
if (consoles.length>1){
// ((IConsole) consoles[1]).setName("Python Consloe");
}
System.out.println(consoles.length+" consoles, processes="+launch.getChildren().length);
return process;
//= consoles
//setImageDescriptor
// getImageDescriptor()
} // run()
private void log(String[] strings,
......@@ -247,7 +474,8 @@ public class VDTRunner {
*/
protected Map 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, Utils.getPureFileName(config.getToolToLaunch()));
map.put(IProcess.ATTR_PROCESS_TYPE,config.getToolName());
return map;
}
......@@ -290,6 +518,10 @@ public class VDTRunner {
String timestamp= DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM).format(new Date(System.currentTimeMillis()));
return Txt.s("Launch.Process.LabelFormat", new String[] {commandLine[0], timestamp});
}
public static String renderProcessLabel(String toolName) {
String timestamp= DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM).format(new Date(System.currentTimeMillis()));
return Txt.s("Launch.Process.LabelFormat", new String[] {toolName, timestamp});
}
protected static String renderCommandLine(String[] commandLine) {
if (commandLine.length == 0)
......
......@@ -17,6 +17,10 @@
*******************************************************************************/
package com.elphel.vdt.core.launching;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import com.elphel.vdt.Txt;
......@@ -45,6 +49,10 @@ public class VDTRunnerConfiguration {
private String toolErrors;
private String toolWarnings;
private String toolInfo;
private int buildStep;
private ILaunchConfiguration configuration;
private ILaunch launch;
private IProgressMonitor monitor;
private static final String[] empty= new String[0];
......@@ -63,6 +71,26 @@ public class VDTRunnerConfiguration {
this.toolToLaunch = toolToLaunch;
}
public void setConfiguration(ILaunchConfiguration configuration){
this.configuration=configuration;
}
public ILaunchConfiguration getConfiguration(){
return configuration;
}
public void setLaunch(ILaunch launch){
this.launch=launch;
}
public ILaunch getLaunch(){
return launch;
}
public void setMonitor(IProgressMonitor monitor){
this.monitor=monitor;
}
public IProgressMonitor getMonitor(){
return monitor;
}
/**
* Returns the name of the class to launch.
*
......@@ -87,10 +115,22 @@ public class VDTRunnerConfiguration {
*
* @param args the list of arguments
*/
public void setToolArguments(String[] args) {
toolArgs= args;
}
public void setBuildStep(int buildStep){
this.buildStep=buildStep;
}
public int getBuildStep(){
return buildStep;
}
public void setIsShell(boolean isShell) {
this.isShell= isShell;
}
......
......@@ -27,6 +27,7 @@ import com.elphel.vdt.core.tools.params.CommandLinesBlock;
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;
public class CommandLinesNodeReader extends AbstractConditionNodeReader {
List<CommandLinesBlock> commandLinesBlocks = new ArrayList<CommandLinesBlock>();
......@@ -70,6 +71,7 @@ public class CommandLinesNodeReader extends AbstractConditionNodeReader {
return new CommandLinesBlock(context.getName(),
name,
dest,
ParamTypeString.KIND.FILE, //Andrey - doesn't know "kind" here yet - TODO: change to attr
sep,
lines,
deleteLines,
......
/*******************************************************************************
* 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 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.
*
* 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.contexts;
import java.util.List;
public class BuildParamsItem implements Cloneable{
private String [] params;
private String consoleName; // null for external tools running in a new console
public BuildParamsItem (
String [] params,
String consoleName) {
this.consoleName=consoleName;
this.params=params; // no need to clone?
}
public BuildParamsItem (BuildParamsItem item){
this (
item.params,
item.consoleName);
}
public BuildParamsItem clone () {
return new BuildParamsItem(this);
}
public String [] getParams(){
return params;
}
public List<String> getParamsAsList(){
List<String> arguments = new java.util.ArrayList<String>(params.length);
for(int i = 0; i < params.length; i++) {
arguments.add(params[i]);
}
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;
}
}
......@@ -190,8 +190,11 @@ public abstract class Context {
// which need to be put into a control file, and puts them to that file
// all other needed params are built into command line array
// that array is then returned
public String[] buildParams() throws ToolException {
List<String> commandLineParams = new ArrayList<String>();
// public String[] buildParams() throws ToolException {
public BuildParamsItem[] buildParams() throws ToolException {
List<BuildParamsItem> buildParamItems = new ArrayList<BuildParamsItem>();
// List<String> commandLineParams = new ArrayList<String>();
Iterator<CommandLinesBlock> commandLinesBlockIter = commandLinesBlocks.iterator(); // command lines block is empty (yes, there is nothing in project output)
createdControlFiles.clear();
......@@ -202,22 +205,31 @@ public abstract class Context {
if(!commandLinesBlock.isEnabled())
continue;
String paramName = commandLinesBlock.getDestination();
String paramName = commandLinesBlock.getDestination(); // Andrey debugging: null?
boolean isConsoleName=commandLinesBlock.isConsoleKind();
String sep = commandLinesBlock.getSeparator();
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));
}
// 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 (isConsoleName) {
// System.out.println("TODO: Enable console command generation here");
printStringsToConsoleLine(commandLineParams, commandSequence);
buildParamItems.add(
new BuildParamsItem (
(String[])commandLineParams.toArray(new String[commandLineParams.size()]),
controlFileName) // find console beginning with this name, send commands there
);
} else {
if(workingDirectory != null)
controlFileName = workingDirectory + File.separator + controlFileName;
......@@ -234,12 +246,21 @@ public abstract class Context {
if(!controlFileExists)
createdControlFiles.add(controlFileName);
}
} else {
// TODO: will need multiple command lines // Andrey
printStringsToCommandLine(commandLineParams, commandSequence);
buildParamItems.add(
new BuildParamsItem (
(String[])commandLineParams.toArray(new String[commandLineParams.size()]),
null) // external tool in a new console
);
}
}
return (String[])commandLineParams.toArray(new String[commandLineParams.size()]);
// return (String[])commandLineParams.toArray(new String[commandLineParams.size()]);
return (BuildParamsItem[])buildParamItems.toArray(new BuildParamsItem[buildParamItems.size()]);
}
protected List<String> buildCommandString(String paramStringTemplate)
......@@ -406,6 +427,25 @@ public abstract class Context {
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);
}
}
}
}
// 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
{
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();
......
......@@ -65,6 +65,10 @@ public abstract class ContextWithoutCommandLine extends Context {
"' cannot contain command line, but destination of its '" +
block.getName() +
"' command block is not specified");
if(!block.isFileKind())
throw new ConfigException("Context '" + name +
"' cannot contain commands for console "+
destination);
}
}
}
......
......@@ -25,6 +25,7 @@ import com.elphel.vdt.core.tools.config.Config;
import com.elphel.vdt.core.tools.config.ConfigException;
import com.elphel.vdt.core.tools.params.conditions.*;
import com.elphel.vdt.core.tools.params.types.ParamTypeString;
import com.elphel.vdt.core.tools.params.types.ParamTypeString.KIND;
public class CommandLinesBlock extends UpdateableStringsContainer
implements Cloneable
......@@ -33,10 +34,12 @@ public class CommandLinesBlock extends UpdateableStringsContainer
private String name;
private String destination;
private String separator;
private KIND kind; //command file name or console name
public CommandLinesBlock(String contextName,
String name,
String destination,
KIND kind,
String sep,
ConditionalStringsList lines,
ConditionalStringsList deleteLines,
......@@ -47,6 +50,7 @@ public class CommandLinesBlock extends UpdateableStringsContainer
this.contextName = contextName;
this.name = name;
this.destination = destination;
this.kind=kind;
this.separator = sep;
if(separator != null) {
......@@ -59,6 +63,7 @@ public class CommandLinesBlock extends UpdateableStringsContainer
this(block.contextName,
block.name,
block.destination,
block.kind,
block.separator,
block.strings != null?
(ConditionalStringsList)block.strings.clone() : null,
......@@ -89,13 +94,20 @@ public class CommandLinesBlock extends UpdateableStringsContainer
"' used for command line of context '" + context.getName() +
"' must be of type '" + ParamTypeString.NAME +
"'");
} else if(((ParamTypeString)param.getType()).getKind() != ParamTypeString.KIND.FILE) {
} else {
kind=((ParamTypeString)param.getType()).getKind();
if(kind != ParamTypeString.KIND.FILE) {
if(((ParamTypeString)param.getType()).getKind() != ParamTypeString.KIND.TEXT) { // Andrey - adding console name option
throw new ConfigException("Destination parameter '" + destination +
"' of type '" + ParamTypeString.NAME +
"' used for command line of context '" + context.getName() +
"' must be of kind '" + ParamTypeString.KIND_FILE_ID +
"' or '" + ParamTypeString.KIND_TEXT_ID +
"'");
}
System.out.println("Got string text kind for command block (for console name)");
}
}
}
}
......@@ -111,6 +123,18 @@ public class CommandLinesBlock extends UpdateableStringsContainer
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);
}
......
......@@ -374,6 +374,12 @@ public class Tool extends Context implements Cloneable, Inheritable {
}
public Parameter findParam(String paramID) {
// System.out.println("findParam("+paramID+")");
// if (paramID==null){
// System.out.println("findParam(null!!!)");
// return null;
// }
Parameter param = super.findParam(paramID); //Andrey: happily finds ProjectContext parameter, thinks it is tool context
/*
* Andrey: Added isChild property to the Property, and still left static inheritance at XML parsing time. Then, during parameter
......@@ -411,7 +417,8 @@ public class Tool extends Context implements Cloneable, Inheritable {
return baseTool;
}
public String[] buildParams() throws ToolException {
// public String[] buildParams() throws ToolException {
public BuildParamsItem[] buildParams() throws ToolException {
if(parentPackage != null)
parentPackage.buildParams();
......
/*******************************************************************************
* 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.params.types;
......
......@@ -251,7 +251,12 @@ public class SelectedResourceManager implements IWindowListener, ISelectionListe
IProject project=getSelectedProject();
if (project==null) return;
IPath path = new Path(fChosenTarget);
IFile file = (path==null)?null:project.getFile(path);
IFile file=null;
try {
file = (path==null)?null:project.getFile(path);
} catch (IllegalArgumentException e) {
// Path must include project and resource name: /x353
}
if ((file != null) && (VerilogUtils.isHhdlFile(file)))
fChosenVerilogFile=file;
else if (fChosenVerilogFile==null)
......
......@@ -40,6 +40,15 @@
icon="gtkwave.ico"
call="iverilog"/>
</menu>
<menuitem name="RemotePython"
label="Run remote Python session"
icon="python.png"
call="RemotePython"/>
<menuitem name="RemotePythonCommand"
label="Send a command to the remote Python session"
icon="my_tool.gif"
call="RemotePythonCommand"/>
<menu name="XDS"
label="Demo XDS Tools"
......
<?xml version="1.0" encoding="UTF-8"?>
<vdt-project>
<interface name="RemoteInterface" extends="project_interface">
</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 -->
<extensions-list>
<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"/>
<input>
<group name="General">
"RemoteHost"
"RemoteUser"
"ShellSwitches"
"PreSSH"
"SSHSwitches"
"RemoteCommand"
"SSHExtra"
</group>
</input>
<output>
<line name="command_line">
"%ShellSwitches"
"%PreSSH"
"ssh"
"-l"
"%RemoteUser"
"%RemoteHost"
"%SSHSwitches"
"'"
"%RemoteCommand"
"'"
"%SSHExtra"
</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 -->
<extensions-list>
<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 = "String"
format = "CopyValue"
default = "print &quot;Hello, World!&quot;"
readonly = "false"
visible = "true"/>
<parameter id="python_console_name" default="RemotePython"
type="String" format="CopyValue" visible="false" />
<input>
<group name="General">
"RemoteCommand"
</group>
</input>
<output>
<line name="command_line">
"-c"
"echo 'Nothing to do, sleepiing 15' ;"
"sleep 15 ;"
"echo 'Nothing to do, awakening' ;"
</line>
<line name="console_line" dest="python_console_name" sep="\n">
"%RemoteCommand"
</line>
<line name="command_line">
"-c"
"echo 'Nothing to do second time, sleeping 25' ;"
"sleep 25 ;"
"echo 'Nothing to do again, awakening after sleep 25' ;"
</line>
</output>
</tool>
</vdt-project>
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