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

Added possibility to assign parameters from file contents and from the

results of running external programs.
parent 1849246a
......@@ -226,7 +226,9 @@ public class VDTConsoleRunner{
};
consoleOutStreamMonitor.addListener((IStreamListener) outputListener );
}
outStream.setColor(new Color(null, 128, 128, 255));
//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++){
if (VerilogPlugin.getPreferenceBoolean(PreferenceStrings.LOCAL_ECHO)) {
......
......@@ -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() {
......
......@@ -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();
}
......
......@@ -285,7 +285,9 @@ public class DesignFlowView extends ViewPart implements ISelectionListener {
showInstallationPropertiesAction = new Action() {
public void run() {
if (openInstallationPropertiesDialog()==Window.OK){
System.out.println("openInstallationPropertiesDialog()-> 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){
System.out.println("LocalContextsAction.openDialog()-> 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){
System.out.println("openToolPropertiesDialog()-> 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);
System.out.println("Ran openToolLaunchDialog() ->"+result);
if (VerilogPlugin.getPreferenceBoolean(PreferenceStrings.DEBUG_OTHER)) {
System.out.println("Ran openToolLaunchDialog() ->"+result);
}
fDesignFlowView.updateLaunchAction();
} catch (CoreException e) {
MessageUI.error(Txt.s("Action.OpenLaunchConfigDialog.Error",
......
......@@ -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>
<menu name="MainDesignMenu2"
......
<?xml version="1.0" encoding="UTF-8"?>
<vdt-project>
<!-- name shold be the same as VivadoConsole parameter -->
<!-- name should be the same as VivadoConsole parameter -->
<tool name="Vivado"
label="Launch Vivado"
project="FPGA_project"
......
<?xml version="1.0" encoding="UTF-8"?>
<vdt-project>
<interface name="VDTTestInterface" extends="FPGAPprojectInterface">
</interface>
<tool name="VDTTest"
label="VDT Test"
shell="/bin/bash"
interface="VDTTestInterface"
description="Testing VDT features">
<action-menu>
<action label="Test VDT" resource="" icon="sample.gif" />
</action-menu>
<parameter id="file1" label="File1 (for list)" default=""
type="String" format="CopyValue" visible="true" readonly="false" />
<parameter id="file2" label="File2 (for single)" default=""
type="String" format="CopyValue" visible="true" readonly="false" />
<parameter id="command1" label="Command1 (for list)" default=""
type="String" format="CopyValue" visible="true" readonly="false" />
<parameter id="command2" label="Command2 (for single)" default=""
type="String" format="CopyValue" visible="true" readonly="false" />
<parameter id="file1Contents" label="File1 contents" default="@%file1"
type="Stringlist" format="ProgramSyntax" visible="true" readonly="false" />
<parameter id="file2Contents" label="File2 contents" default="@%file2"
type="String" format="CopyValue" visible="true" readonly="false" />
<parameter id="command1Contents" label="Command1 contents" default="@@%command1"
type="Stringlist" format="ProgramSyntax" visible="true" readonly="false" />
<parameter id="command2Contents" label="Command2 contents" default="@@%command2"
type="String" format="CopyValue" visible="true" readonly="false" />
<input>
<group name="General">
"file1"
"file2"
"command1"
"command2"
"file1Contents"
"file2Contents"
"command1Contents"
"command2Contents"
</group>
</input>
<output>
<line name="test">
"-c"
"echo \"file1=%file1\";"
"echo \"file2=%file2\";"
"echo \"command1=%command1\";"
"echo \"command2=%command2\";"
"echo \"file1Contents=%file1Contents\";"
"echo \"file2Contents=%file2Contents\";"
"echo \"command1Contents=%command1Contents\";"
"echo \"command2Contents=%command2Contents\";"
</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