Commit 28b4f65b authored by Andrey Filippov's avatar Andrey Filippov
Browse files

Added possibility to assign parameters from file contents and from the

results of running external programs.
parent 1849246a
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -226,6 +226,8 @@ public class VDTConsoleRunner{
       		};
        	consoleOutStreamMonitor.addListener((IStreamListener) outputListener );
        }
        //Problems occurred when invoking code from plug-in: "org.eclipse.ui.console".
        //Exception occurred during console property change notification.
        outStream.setColor(new Color(null, 128, 128, 255)); 
        try {
        	for (int i=0;i<arguments.length;i++){
+121 −0
Original line number Diff line number Diff line
@@ -17,8 +17,16 @@
 *******************************************************************************/
package com.elphel.vdt.core.tools.params;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;

import com.elphel.vdt.core.tools.params.recognizers.*;
import com.elphel.vdt.core.tools.params.types.ParamType;
import com.elphel.vdt.core.tools.params.conditions.*;
@@ -28,6 +36,9 @@ import com.elphel.vdt.core.tools.config.ConfigException;
//import com.elphel.vdt.core.tools.generators.SourceListGenerator;
import com.elphel.vdt.core.tools.*;
import com.elphel.vdt.ui.MessageUI;
import com.elphel.vdt.ui.variables.SelectedResourceManager;
import com.elphel.vdt.veditor.VerilogPlugin;
import com.elphel.vdt.veditor.preference.PreferenceStrings;

public class Parameter implements Cloneable, Updateable {
    private String id;
@@ -352,10 +363,120 @@ public class Parameter implements Cloneable, Updateable {
        }

        canonicalizeValue(processedDefaultValue);
    	String filename=null;
    	String command=null;
        if ((processedDefaultValue!=null) && (processedDefaultValue.size()>0)){
        	String firstLine;
        	try {
        		firstLine=processedDefaultValue.get(0);
            	if (firstLine.substring(0,1).equals("@")) {
            		filename=firstLine.substring(1);
            		if (filename.substring(0,1).equals("@")){
            			command=filename.substring(1);
            			filename=null;
            		}
            		
            	}
        	} catch (Exception e) {
        		return processedDefaultValue; 
        	}
        	
// "@" on the first two positions of result string can be escaped with "\", other "@" should not be escaped!        	
        	if ((firstLine!=null) && (firstLine.length()>1) && (firstLine.indexOf("@")>=0)){
        		if (firstLine.substring(0,2).equals("\\@")){
        			firstLine=firstLine.substring(1);
        		}
        		if (firstLine.substring(1,3).equals("\\@")){
        			firstLine=firstLine.substring(0,1)+firstLine.substring(2);
        		}
        		processedDefaultValue.remove(0);
        		processedDefaultValue.add(0,firstLine);
        	}
        }
        if (command!=null) return getCommandValue(command);
        if (filename!=null) return getFileValue(filename);
        
        return processedDefaultValue;
    }
    
    List<String> getFileValue(String filename){
		if (VerilogPlugin.getPreferenceBoolean(PreferenceStrings.DEBUG_OTHER)) {
			System.out.println("Resolving \""+filename+"\"");
		}
    	File file=new File(filename);
    	if (!file.exists()) {
            IResource resource = SelectedResourceManager.getDefault().getSelectedResource();
            if (resource != null) {
                String workspaceRoot=resource.getWorkspace().getRoot().getLocation().toString();
                String full_name = workspaceRoot+resource.getProject().getFullPath().toString()+
                		File.separator+filename;
                file=new File(full_name);
            }
    	}
    	Scanner sc=null;
    	if (file.exists() && file.isFile()) {
    		try {
    			sc = new Scanner(file);
    		} catch (FileNotFoundException e) {
    		}
    	}
		List<String> result=new ArrayList<String>();
		if (sc==null){
			result.add("");
		} else {
			while(sc.hasNextLine()){
				result.add(sc.nextLine());                     
			}
	    	sc.close();
		}
    	return result;
    }
    
    List<String> getCommandValue(String command){
		List<String> result=new ArrayList<String>();
		try {
			result= doGetCommandValue(command);
		} catch (Exception e){
			
		}
		if (result.size()==0){
			result.add("");
		}
    	return result;
    }
    
    List<String> doGetCommandValue(String command) throws IOException, InterruptedException{
		command=command.trim();
		if (VerilogPlugin.getPreferenceBoolean(PreferenceStrings.DEBUG_OTHER)) {
			System.out.println("Evaluating command: "+command);	
		}
		String [] array_args=command.split("\\s+");
		List<String> args=new ArrayList<String>();
		for (int i=0;i<array_args.length;i++){
			args.add(array_args[i]);
		}
		List<String> result=new ArrayList<String>();
		if (args.size()>0){
			Process pr=null;
			ProcessBuilder   ps=new ProcessBuilder(args);
			ps.redirectErrorStream(true);
			pr = ps.start();
			BufferedReader in = new BufferedReader(new 
					InputStreamReader(pr.getInputStream()));
			String line;
			while ((line = in.readLine()) != null) {
				result.add(line);
			}
			pr.waitFor();
			in.close();
		}
		if (result.size()==0){
			result.add("");
		}
    	return result;
    }
    
    
    // returns current value if it is set 
    // otherwise returns default value 
    public List<String> getValue() {
+18 −3
Original line number Diff line number Diff line
@@ -194,9 +194,24 @@ public class Tool extends Context implements Cloneable, Inheritable {
        return newTool; 
    }

    public String getExeName() {
        if(locationSet)
            return absoluteExeName;
    public String getExeName() { // seems to be running in 2 parallel processes!!
    	if ((absoluteExeName !=null) && !absoluteExeName.substring(0,1).equals("/")){
    		String path=System.getenv("PATH");
    		if (path!=null){ // Linux
//    			System.out.println("PATH=\""+path+"\"");
    			String [] dirs = path.split(":");
    			for (int i=0;i<dirs.length;i++){
    				File file=new File(dirs[i]+"/"+absoluteExeName);
    				if (file.isFile() && file.exists()){
    					absoluteExeName=dirs[i]+"/"+absoluteExeName;
    					break;
    				}
    			}
    		}
    	}
    	
        if(locationSet) // true
            return absoluteExeName; // bash
        
        return getResolvedExeName();
    }
+12 −4
Original line number Diff line number Diff line
@@ -285,7 +285,9 @@ public class DesignFlowView extends ViewPart implements ISelectionListener {
        showInstallationPropertiesAction = new Action() {
            public void run() {
                if (openInstallationPropertiesDialog()==Window.OK){
            		if (VerilogPlugin.getPreferenceBoolean(PreferenceStrings.DEBUG_OTHER)) {
            			System.out.println("openInstallationPropertiesDialog()-> OK");
            		}
                	fDesignFlowView.updateLaunchAction();
                }; 
            }
@@ -340,7 +342,9 @@ public class DesignFlowView extends ViewPart implements ISelectionListener {
            	if (LocalContextsAction.openDialog( "Project Parameters"
                                              , selectedItem.getProjectContext() 
                                              , selectedResource.getProject() )==Window.OK){
            		if (VerilogPlugin.getPreferenceBoolean(PreferenceStrings.DEBUG_OTHER)) {
            			System.out.println("LocalContextsAction.openDialog()-> OK");
            		}
                	fDesignFlowView.updateLaunchAction();
                }; 
            }
@@ -357,7 +361,9 @@ public class DesignFlowView extends ViewPart implements ISelectionListener {
        showPropertiesAction = new Action() {
            public void run() {
            	if (openToolPropertiesDialog(selectedItem)==Window.OK){
            		if (VerilogPlugin.getPreferenceBoolean(PreferenceStrings.DEBUG_OTHER)) {
            			System.out.println("openToolPropertiesDialog()-> OK");
            		}
                	fDesignFlowView.updateLaunchAction();
                };  
//              ConsoleView.getDefault().println("Action 1 executed", ConsoleView.MSG_INFORMATION);                
@@ -387,7 +393,9 @@ public class DesignFlowView extends ViewPart implements ISelectionListener {
            public void run() {
                try {
                    int result = openToolLaunchDialog(selectedItem);
            		if (VerilogPlugin.getPreferenceBoolean(PreferenceStrings.DEBUG_OTHER)) {
            			System.out.println("Ran openToolLaunchDialog() ->"+result);
            		}
                	fDesignFlowView.updateLaunchAction();
                } catch (CoreException e) {
                    MessageUI.error(Txt.s("Action.OpenLaunchConfigDialog.Error", 
+5 −3
Original line number Diff line number Diff line
@@ -56,10 +56,12 @@
                          label="Optimize and place design"
                          icon="xilinx.png"
                          call="VivadoOptPlace"/>
                          
                          
                          
        </menu>
           <menuitem name="Test VDT"
             label="Testing some VDT features"
             icon="sample.gif"
             call="VDTTest"/>
                          
    </menu>
    
    <menu name="MainDesignMenu2"
Loading