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

Disconnecting stdin instead of terminating parser processes, several

other small changes
parent 1621d905
Loading
Loading
Loading
Loading
+51 −9
Original line number Diff line number Diff line
@@ -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);
+71 −21
Original line number Diff line number Diff line
@@ -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,11 +486,55 @@ public abstract class Context {
        out.close();
    }

    private void printStringsToCommandLine(List<String> commandLineParams, 
    private void printStringsToConsoleLine(
    		List<String> commandLineParams, 
    		List<List<String>> commandSequence,
                                           String mark) 
        throws ToolException
    		String separator,
    		String mark) throws ToolException
    		{
        String sep = (separator != null? separator : " ");
    	boolean useMark=(mark!=null) && (mark.length()>0);
        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(" ");
                    }
                }
                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();
@@ -498,18 +542,21 @@ public abstract class Context {
    		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);
    					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 printStringsToConsoleLine(
    		List<String> commandLineParams, 
 */
    private void printStringsToCommandLine(List<String> commandLineParams, 
                                           List<List<String>> commandSequence,
    		String mark) throws ToolException
                                           String mark) 
        throws ToolException
    {
    	boolean useMark=(mark!=null) && (mark.length()>0);
        for(Iterator<List<String>> li = commandSequence.iterator(); li.hasNext();) {
@@ -518,13 +565,16 @@ public abstract class Context {
            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);
                        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)
+7 −3
Original line number Diff line number Diff line
@@ -57,10 +57,11 @@ public abstract class AbstractGenerator {
        this.suffix = suffix;
        this.forcedMultiline = forcedMultiline;
        this.separator = sep;

        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;
        
+1 −1
Original line number Diff line number Diff line
@@ -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");
+2 −1
Original line number Diff line number Diff line
@@ -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 {
Loading