Commit 10b43301 authored by Andrey Filippov's avatar Andrey Filippov

Disconnecting stdin instead of terminating parser processes, several

other small changes
parent 1621d905
......@@ -39,6 +39,7 @@ import org.eclipse.debug.core.model.IProcess;
import org.eclipse.debug.core.model.IStreamMonitor;
//import org.eclipse.debug.core.model.IStreamListener;
import org.eclipse.debug.core.model.IStreamsProxy;
import org.eclipse.debug.core.model.IStreamsProxy2;
import org.eclipse.swt.graphics.Color;
import org.eclipse.ui.console.IConsole;
//import org.eclipse.debug.ui.console.IConsole;
......@@ -57,11 +58,13 @@ public class VDTConsoleRunner{
private final VDTRunnerConfiguration runConfig; //*
private IProcess processErr=null; //*
private IProcess processOut=null; //*
private IStreamsProxy sendErrorsToStreamProxy=null;
private IStreamsProxy2 sendErrorsToStreamProxy=null;
private Object errorListener=null; //+
private Object outputListener=null; //+
private IStreamsProxy consoleInStreamProxy= null; //+
private IStreamsProxy2 consoleInStreamProxy= null; //+
private Timer timer;
private IStreamsProxy2 stdoutStreamProxy=null;
private IStreamsProxy2 stderrStreamProxy=null;
public VDTConsoleRunner (VDTRunnerConfiguration runConfig){
......@@ -122,7 +125,7 @@ public class VDTConsoleRunner{
runner.log("Writing to console "+iCons.getName()+":", arguments, null, false, false); /* Appears in the console of the parent Eclipse */
IOConsoleOutputStream outStream= iCons.newOutputStream();
IProcess process=((ProcessConsole)iCons).getProcess();
consoleInStreamProxy= process.getStreamsProxy();
consoleInStreamProxy= (IStreamsProxy2)process.getStreamsProxy();
int stderrParserIndex=getParserIndex(buildParamsItem.getStderr());
int stdoutParserIndex=getParserIndex(buildParamsItem.getStdout());
BuildParamsItem stderrParser=(stderrParserIndex>=0)?runConfig.getArgumentsItemsArray()[stderrParserIndex]:null;
......@@ -133,8 +136,10 @@ public class VDTConsoleRunner{
}
processErr=null;
processOut=null;
IStreamsProxy stdoutStreamProxy=null;
IStreamsProxy stderrStreamProxy=null;
// IStreamsProxy2 stdoutStreamProxy=null;
// IStreamsProxy2 stderrStreamProxy=null;
stdoutStreamProxy=null;
stderrStreamProxy=null;
if (stdoutParser!=null){
List<String> toolArgumentsStdout = new ArrayList<String>();
List<String> stdoutArguments=stdoutParser.getParamsAsList();
......@@ -147,7 +152,7 @@ public class VDTConsoleRunner{
launch,
null, //monitor
stdoutParserIndex);
stdoutStreamProxy= processOut.getStreamsProxy();
stdoutStreamProxy= (IStreamsProxy2) processOut.getStreamsProxy();
}
if (stderrParser!=null){
......@@ -162,13 +167,13 @@ public class VDTConsoleRunner{
launch,
null, //monitor);
stderrParserIndex);
stderrStreamProxy= processErr.getStreamsProxy();
stderrStreamProxy= (IStreamsProxy2) processErr.getStreamsProxy();
//TODO: Add error parsers
}
sendErrorsToStreamProxy=(stderrStreamProxy!=null)?stderrStreamProxy:stdoutStreamProxy;
final IStreamsProxy fSendErrorsToStreamProxy=sendErrorsToStreamProxy;
final IStreamsProxy fSendOutputToStreamProxy= stdoutStreamProxy;
final IStreamsProxy2 fSendErrorsToStreamProxy=sendErrorsToStreamProxy;
final IStreamsProxy2 fSendOutputToStreamProxy= stdoutStreamProxy;
// connect input streams of the parsers to the out from the console process
IStreamMonitor consoleOutStreamMonitor=null;
......@@ -270,9 +275,45 @@ public class VDTConsoleRunner{
consoleOutStreamMonitor.removeListener((IStreamListener) outputListener);
}
// terminate parser(s). Do those console listeners (parsers) have to be removed too?
// TODO: Maybe wait for the process (small time) to terminate by disconnecting it's stdin
// Now end of the parsing may be lost if it did not have enough time to finish.
//IStreamsProxy2.closeInputStream()
// Disconnection worked !!
if (stderrStreamProxy!=null){
try {
stderrStreamProxy.closeInputStream();
} catch (IOException e) {
System.out.println("Failed to disconnect stdin of the processErr parser process");
if (processErr!=null){
try {
processErr.terminate();
} catch (DebugException te) {
System.out.println("Failed to terminate processErr parser process");
}
}
}
}
if (stdoutStreamProxy!=null){
try {
stdoutStreamProxy.closeInputStream();
} catch (IOException e) {
System.out.println("Failed to disconnect stdin of the processOut parser process");
if (processOut!=null){
try {
processOut.terminate();
} catch (DebugException te) {
System.out.println("Failed to terminate processOut parser process");
}
}
}
}
/*
if (processErr!=null){
try {
processErr.terminate();
} catch (DebugException e) {
System.out.println("Failed to terminate processErr parser process");
}
......@@ -284,6 +325,7 @@ public class VDTConsoleRunner{
System.out.println("Failed to terminate processOut parser process");
}
}
*/
int thisStep=runConfig.getBuildStep();
if (VerilogPlugin.getPreferenceBoolean(PreferenceStrings.DEBUG_LAUNCHING))
System.out.println("Finished console task, step was "+thisStep);
......
......@@ -240,7 +240,7 @@ public abstract class Context {
parName.getValue().get(0).trim() : null;
if (isConsoleName) {
// System.out.println("TODO: Enable console command generation here");
printStringsToConsoleLine(commandLineParams, commandSequence,mark);
printStringsToConsoleLine(commandLineParams, commandSequence,sep,mark);
buildParamItems.add(
new BuildParamsItem (
(String[])commandLineParams.toArray(new String[commandLineParams.size()]),
......@@ -458,7 +458,7 @@ public abstract class Context {
if(s.length() == 0)
continue;
out.print(useMark?(s.replace(mark,"")):s);
out.print(useMark?(CommandLinesBlock.parseCntrl(s).replace(mark,"")):CommandLinesBlock.parseCntrl(s));
written += s.length();
writtenNow += s.length();
......@@ -486,31 +486,55 @@ public abstract class Context {
out.close();
}
private void printStringsToCommandLine(List<String> commandLineParams,
List<List<String>> commandSequence,
String mark)
throws ToolException
{
private void printStringsToConsoleLine(
List<String> commandLineParams,
List<List<String>> commandSequence,
String separator,
String mark) throws ToolException
{
String sep = (separator != null? separator : " ");
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(useMark?(s.replace(mark,"")):s);
int written = 0;
StringBuilder builder = new StringBuilder();
for(Iterator<List<String>> li = commandSequence.iterator(); li.hasNext();) {
List<String> strList = (List<String>)li.next();
if(strList.size() > 0) {
int writtenNow = 0;
for(Iterator<String> si = strList.iterator(); si.hasNext();) { // "words" in each line
String s = (String)si.next();
if(s.length() == 0)
continue;
builder.append(useMark?(CommandLinesBlock.parseCntrl(s).replace(mark,"")):CommandLinesBlock.parseCntrl(s));
written += s.length();
writtenNow += s.length();
// try to avoid needless spaces
if(writtenNow > 0 && si.hasNext()) { // adding spaces between generator "words" ?
String stripped = s.
replace('\n', ' ').
replace('\t', ' ').
trim();
if(stripped.length() > 0)
builder.append(" ");
}
}
}
}
}
// Andrey: now is the same as command line, but will change to allow last element be prompt
if(writtenNow > 0 && li.hasNext())
builder.append(sep);
}
}
if(written > 0)
builder.append("\n");
commandLineParams.add(builder.toString()); // just a single line
}
/*
* previous version
private void printStringsToConsoleLine(
List<String> commandLineParams,
List<List<String>> commandSequence,
String separator,
String mark) throws ToolException
{
String sep = (separator != null? separator : " ");
boolean useMark=(mark!=null) && (mark.length()>0);
for(Iterator<List<String>> li = commandSequence.iterator(); li.hasNext();) {
List<String> strList = (List<String>)li.next();
......@@ -520,11 +544,37 @@ public abstract class Context {
String s = ((String)si.next()).trim();
if(!s.equals(""))
commandLineParams.add(useMark?(s.replace(mark,"")):s);
commandLineParams.add(useMark?
(CommandLinesBlock.parseCntrl(s).replace(mark,"")):
CommandLinesBlock.parseCntrl(s));
}
}
}
}
*/
private void printStringsToCommandLine(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();
if(strList.size() > 0) {
for(Iterator<String> si = strList.iterator(); si.hasNext();) {
String s = ((String)si.next()).trim();
if(!s.equals(""))
commandLineParams.add(useMark?
(CommandLinesBlock.parseCntrl(s).replace(mark,"")):
CommandLinesBlock.parseCntrl(s));
}
}
}
}
// Andrey: now is the same as command line, but will change to allow last element be prompt
private void checkNotInitialized() throws ConfigException {
if(initialized)
......
......@@ -57,9 +57,10 @@ public abstract class AbstractGenerator {
this.suffix = suffix;
this.forcedMultiline = forcedMultiline;
this.separator = sep;
separator = separator.replace("\\n", "\n");
separator = separator.replace("\\t", "\t");
if (separator!=null) {
separator = separator.replace("\\n", "\n");
separator = separator.replace("\\t", "\t");
}
}
public void setMenuMode(boolean menuMode){
this.menuMode=menuMode;
......@@ -72,6 +73,9 @@ public abstract class AbstractGenerator {
public abstract String getName();
public String[] generate() {
// Andrey: added separator==null option to enable copying list parameter to another list parameter as default
// TODO: Make sure nothing else is broken because of that
if (separator==null) return getStringValues();
boolean multiline = Utils.stringContainsSpace(separator);
String[] output;
......
......@@ -107,7 +107,7 @@ public class CommandLinesBlock extends UpdateableStringsContainer
}
public String parseCntrl(String str){
public static String parseCntrl(String str){
if (str==null) return null;
str=str.replace("\\n" ,"\n");
str=str.replace("\\t", "\t");
......
......@@ -328,7 +328,8 @@ public class Parameter implements Cloneable, Updateable {
FormatProcessor processor = new FormatProcessor(new Recognizer[] {
//new RepeaterRecognizer(),
new SimpleGeneratorRecognizer(menuMode),
new ContextParamRecognizer(context)
new ContextParamListRecognizer(context) // Andrey: returning list as the source parameter
// new ContextParamRecognizer(context)
});
try {
......
/*******************************************************************************
* Copyright (c) 2006 Elphel, Inc and Excelsior, LLC.
* 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.
*
* 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
*******************************************************************************/
package com.elphel.vdt.core.tools.params.recognizers;
import com.elphel.vdt.core.tools.params.Parameter;
import com.elphel.vdt.core.tools.params.ToolException;
import com.elphel.vdt.core.tools.contexts.Context;
import com.elphel.vdt.core.tools.generators.AbstractGenerator;
import com.elphel.vdt.core.tools.generators.ValueGenerator;
public class ContextParamListRecognizer extends ParamRecognizer {
private Context context;
public ContextParamListRecognizer(Context context) {
this.context = context;
}
protected Parameter findParam(String paramID) {
return context.findParam(paramID);
}
protected AbstractGenerator getGenerator(Parameter param) throws ToolException {
return new ValueGenerator(param, "", "", null); // will return list value of the parameter
}
}
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