Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » working directory( working directory)
working directory [message #748064] Mon, 24 October 2011 13:11 Go to next message
samir  is currently offline samir Friend
Messages: 27
Registered: September 2011
Junior Member
hello
I describe my problem, I will call my interpreter that is written in ocaml, but the problem is when I run eclipse application changes the working directory, is not that the project xtext. it does not find my interpreter.
Re: working directory [message #748503 is a reply to message #748064] Mon, 24 October 2011 18:23 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
Sorry,
but I don't understand your question. Can you be more specific?
- henrik

On 10/24/11 3:11 PM, samir wrote:
> hello
> I describe my problem, I will call my interpreter that is written in
> ocaml, but the problem is when I run eclipse application changes the
> working directory, is not that the project xtext. it does not find my
> interpreter.
Re: working directory [message #748643 is a reply to message #748503] Mon, 24 October 2011 20:20 Go to previous messageGo to next message
samir  is currently offline samir Friend
Messages: 27
Registered: September 2011
Junior Member
my problem is this:
I have written an interpreter, in ocaml and I want to use it, so I put the executable in the xtext project folder , and when I called the executable from a class of the popup menu package which I created to run my program.
when I run my xtext project, then open a new instance of eclipse
but when I run from the popup menu does not work, then I tried to print the working directory when I run my project, this is different from the working directory of the xtext project.
what I need is how to get the working directory to the xtext project and not the project created in my language.
Re: working directory [message #748676 is a reply to message #748643] Mon, 24 October 2011 20:50 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 10/24/11 10:20 PM, samir wrote:
> my problem is this:
> I have written an interpreter, in ocaml and I want to use it, so I put
> the executable in the xtext project folder , and when I called the
> executable from a class of the popup menu package which I created to run
> my program.

Do you want it to be a separate executable? Or should it run in the
users IDE (same VM)?

> when I run my xtext project, then open a new instance of eclipse
> but when I run from the popup menu does not work, then I tried to print
> the working directory when I run my project, this is different from the
> working directory of the xtext project.
> what I need is how to get the working directory to the xtext project and
> not the project created in my language.
>

Do you want a second IDE instance (with UI and everything) when running
the interpreter? Or, do you want a headless (non RCP, command line only)
executable?

These questions determine what it is you need to do. It is quite
different to run the (interpreted) logic with the same VM as the IDE
compared to running them with a separate executable.

In a headless (so called Standalone setup) many of the IDE concepts do
not apply, and you need to do a bit more work on your own. (Loading,
starting to evaluate somewhere, etc.).

I hope this helps, and enables you to ask even more specific questions.

Or maybe, if all of the above was clear, then you are only asking how to
obtain the File location of the workspace/project/resource?

Regards
- henrik
Re: working directory [message #749488 is a reply to message #748676] Tue, 25 October 2011 08:47 Go to previous messageGo to next message
samir  is currently offline samir Friend
Messages: 27
Registered: September 2011
Junior Member
my goal is to call my interpreter that is written in ocaml so it's an executable, I call the run method


public class Interprete implements IObjectActionDelegate {

private Shell shell;
private String fileName;
private String workingPath;
private String uriPrefix;
private PrintStream stdout = System.out;
private PrintStream silence = new PrintStream(new SilenceIO());

private class SilenceIO extends OutputStream {
@Override
public void write(int b) throws IOException {
}
}

/**
* Constructor for Action1.
*/
public Interprete() {
super();
}

/**
* @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
*/
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
shell = targetPart.getSite().getShell();
}

/**
* @see IActionDelegate#run(IAction)
*/
public void run(IAction action) {

String s = "tipato: ";
Term ty = null;
try {
s += termToString(getProg().getMain()) + "\n";
s += "puro: " + termToStringLci(getProg().getMain());
ty = getProg().getMain();

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String term = termToString(ty);
try {
Runtime.getRuntime().exec(new String[]{"bash","-c","./interp "+term});
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


MessageDialog.openInformation(shell, "systemF.ui", s);

}

/**
* @param fileName
* @param workingPath
* @param uriPrefix
* @see IActionDelegate#selectionChanged(IAction, ISelection)
*/
public void selectionChanged(IAction action, ISelection selection) {

fileName = toFileName(selection.toString());
workingPath = toWorkingPath(selection.toString());
uriPrefix = toUriPrefix(selection.toString());

}

/**
* restituisce la radice dell'albero sintattico
*
* @return la radice dell'albero sintattico
* @throws IOException
*/
private Prog getProg() throws IOException {
echo(false);
StandaloneSetup standalone = new StandaloneSetup();
standalone.setPlatformUri(workingPath);
Injector injector = new MyDslStandaloneSetup()
.createInjectorAndDoEMFRegistration();
XtextResourceSet resourceSet = injector
.getInstance(XtextResourceSet.class);
resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL,
Boolean.TRUE);

Resource resource = resourceSet.createResource(URI.createURI(uriPrefix
+ fileName));
InputStream in = new FileInputStream(workingPath + fileName);

resource.load(in, resourceSet.getLoadOptions());

if (resource.getContents().size() == 0) {
System.out
.println("The file is empty: no folder has been generated");
return null;
}
Prog model = (Prog) resource.getContents().get(0);
echo(true);
return model;
}

/**
* restituisce la stringa che rappresenta il termine Term t il termine
* @return la stringa che rappresenta il termine
*/
private String termToString(Term t) {

if (t instanceof Var) {
return ((Var) t).getName();

} else if (t instanceof Abs) {
return "\\(" + (((Abs) t).getParam()) + ":"
+ typeToString(((Abs) t).getType()) + ")."
+ termToString(((Abs) t).getBody());
} else if (t instanceof App) {
return "(" + termToString(((App) t).getT1()) + ")"
+ termToString(((App) t).getT2());
} else if (t instanceof Uq) {
return "/\\" + (((Uq) t).getVar()) + "."
+ termToString(((Uq) t).getTerm());
} else if (t instanceof Tapp) {
return "(" + termToString(((Tapp) t).getTerm()) + ")"
+ typeToString(((Tapp) t).getType());
} else if (t instanceof Nrif) {
return termToString(((Nrif) t).getNome().getTerm());
} else if (t instanceof Let) {
return "\\((" + (((Let) t).getVar()) + ":" + typeToString((((Let) t).getType()))
+ ")." + termToString(((Let) t).getT2()) + ")"
+ termToString(((Let) t).getT1());
}
return "";
}

/**
* restituisce la stringa che rappresentazione del lambda termine pulito dal
* tipo
* @param t termine
* @return stringa che rappresentazione del lambda termine pulito dal tipo
*/
private String termToStringLci(Term t) {

if (t instanceof Var) {
return ((Var) t).getName();
} else if (t instanceof Abs) {
return "(\\" + (((Abs) t).getParam()) + "."
+ termToStringLci(((Abs) t).getBody()) + ")";
} else if (t instanceof App) {
return "(" + termToStringLci(((App) t).getT1()) + " "
+ termToStringLci(((App) t).getT2()) + ")";
} else if (t instanceof Uq) {
return termToStringLci(((Uq) t).getTerm());
} else if (t instanceof Tapp) {
return termToStringLci(((Tapp) t).getTerm());
} else if (t instanceof Nrif) {
return termToStringLci(((Nrif) t).getNome().getTerm());
} else if (t instanceof Let) {
return "((\\" + (((Let) t).getVar()) + "."
+ termToStringLci(((Let) t).getT2()) + ") "
+ termToStringLci(((Let) t).getT1()) + ")";
}
return "";
}

/**
* restituisce la stringa che rappresenta il tipo
* @param t : t il tipo
* @return a stringa che rappresenta il tipo
*/
private String typeToString(T t) {
if (t instanceof T1) {
String p = ((T1) t).getP();
EList<T> c = ((T1) t).getC();
if (!c.isEmpty()) {
p += "->";
for (T a : c)
p += typeToString(a);
}
return p;
} else if (t instanceof T2) {
String p = "(" + typeToString(((T2) t).getP1()) + ")";
EList<T> c = ((T2) t).getC1();
if (!c.isEmpty()) {
p += "->";
for (T a : c)
p += typeToString(a);
}
return p;

} else if (t instanceof T3) {
return "forall " + (((T3) t).getVar()) + " "
+ typeToString(((T3) t).getT());

} else if (t instanceof Trif) {
return typeToString(((Trif) t).getNome().getType());

}
return "";

}

/* SERVICE METHODS */
private String toFileName(String name) {
int idx = getLastSeparatorIndex(name);

if (idx == -1)
return "";

return name.substring(idx + 1, name.length() - 1);
}

private String toWorkingPath(String name) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
String path = root.getLocation().toString() + "/";

int idx = getLastSeparatorIndex(name);
if (idx == -1)
return "";

return path + name.substring(3, idx) + "/";
}

private String toUriPrefix(String name) {
int idx = name.indexOf('/');
if (idx == -1)
return "";

return "platform:/resource"
+ name.substring(idx, name.lastIndexOf('/')) + "/";
}

private int getLastSeparatorIndex(String name) {
int idx = name.length() - 1;

while (name.charAt(idx) != '/') {
idx--;
if (idx < 0)
return -1;
}

return idx;
}

private void echo(boolean value) {
if (value) {
System.setOut(stdout);
} else {
System.setOut(silence);
}
}

}




The problem is that it can not find my interpreter, who is working in the project xtext directory . because when I run my project xtext changes the working directory.
Re: working directory [message #749509 is a reply to message #749488] Tue, 25 October 2011 09:02 Go to previous message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
This looks like you are using the Standalone setup to run things inside
the IDE - that is not how it is intended to be used. In fact, it is
harmful as the Standalone setup modifies registries.

The StandaloneSetup is to be used in a separate executable (i.e. in a
separate VM / different operating system process). You use the
StandaloneSetup when running JUnit tests, when writing a "headless"
compiler, or interpreter.

If you are running inside the IDE (or an RCP app) you already have
everything initialized, and need to hook into what is already there.

Take a look at eclipse/b3 project, it has an interpreter that is
executed from within the IDE - i.e. it is even possible to evaluate the
dirty state in the editor.

Regards
- henrik

On 10/25/11 10:47 AM, samir wrote:
> my goal is to call my interpreter that is written in ocaml so it's an
> executable, I call the run method

This "run" executes in the same VM ("in the IDE").

>
>
> public class Interprete implements IObjectActionDelegate {
>
> private Shell shell;
> private String fileName;
> private String workingPath;
> private String uriPrefix;
> private PrintStream stdout = System.out;
> private PrintStream silence = new PrintStream(new SilenceIO());
>
> private class SilenceIO extends OutputStream {
> @Override
> public void write(int b) throws IOException {
> }
> }
>
> /**
> * Constructor for Action1.
> */
> public Interprete() {
> super();
> }
>
> /**
> * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
> */
> public void setActivePart(IAction action, IWorkbenchPart targetPart) {
> shell = targetPart.getSite().getShell();
> }
>
> /**
> * @see IActionDelegate#run(IAction)
> */
> public void run(IAction action) {
>
> String s = "tipato: ";
> Term ty = null;
> try {
> s += termToString(getProg().getMain()) + "\n";
> s += "puro: " + termToStringLci(getProg().getMain());
> ty = getProg().getMain();
>
> } catch (IOException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> String term = termToString(ty);
> try {
> Runtime.getRuntime().exec(new String[]{"bash","-c","./interp "+term});
> } catch (IOException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>
>
> MessageDialog.openInformation(shell, "systemF.ui", s);
>
> }
>
> /**
> * @param fileName
> * @param workingPath
> * @param uriPrefix
> * @see IActionDelegate#selectionChanged(IAction, ISelection)
> */
> public void selectionChanged(IAction action, ISelection selection) {
>
> fileName = toFileName(selection.toString());
> workingPath = toWorkingPath(selection.toString());
> uriPrefix = toUriPrefix(selection.toString());
>
> }
>
> /**
> * restituisce la radice dell'albero sintattico
> * * @return la radice dell'albero sintattico
> * @throws IOException
> */
> private Prog getProg() throws IOException {
> echo(false);
> StandaloneSetup standalone = new StandaloneSetup();
> standalone.setPlatformUri(workingPath);
> Injector injector = new MyDslStandaloneSetup()
> .createInjectorAndDoEMFRegistration();
> XtextResourceSet resourceSet = injector
> .getInstance(XtextResourceSet.class);
> resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL,
> Boolean.TRUE);
>
> Resource resource = resourceSet.createResource(URI.createURI(uriPrefix
> + fileName));
> InputStream in = new FileInputStream(workingPath + fileName);
>
> resource.load(in, resourceSet.getLoadOptions());
>
> if (resource.getContents().size() == 0) {
> System.out
> .println("The file is empty: no folder has been generated");
> return null;
> }
> Prog model = (Prog) resource.getContents().get(0);
> echo(true);
> return model;
> }
>
> /**
> * restituisce la stringa che rappresenta il termine Term t il termine
> * @return la stringa che rappresenta il termine
> */
> private String termToString(Term t) {
>
> if (t instanceof Var) {
> return ((Var) t).getName();
>
> } else if (t instanceof Abs) {
> return "\\(" + (((Abs) t).getParam()) + ":"
> + typeToString(((Abs) t).getType()) + ")."
> + termToString(((Abs) t).getBody());
> } else if (t instanceof App) {
> return "(" + termToString(((App) t).getT1()) + ")"
> + termToString(((App) t).getT2());
> } else if (t instanceof Uq) {
> return "/\\" + (((Uq) t).getVar()) + "."
> + termToString(((Uq) t).getTerm());
> } else if (t instanceof Tapp) {
> return "(" + termToString(((Tapp) t).getTerm()) + ")"
> + typeToString(((Tapp) t).getType());
> } else if (t instanceof Nrif) {
> return termToString(((Nrif) t).getNome().getTerm());
> } else if (t instanceof Let) {
> return "\\((" + (((Let) t).getVar()) + ":" + typeToString((((Let)
> t).getType()))
> + ")." + termToString(((Let) t).getT2()) + ")"
> + termToString(((Let) t).getT1());
> }
> return "";
> }
>
> /**
> * restituisce la stringa che rappresentazione del lambda termine pulito dal
> * tipo
> * @param t termine
> * @return stringa che rappresentazione del lambda termine pulito dal tipo
> */
> private String termToStringLci(Term t) {
>
> if (t instanceof Var) {
> return ((Var) t).getName();
> } else if (t instanceof Abs) {
> return "(\\" + (((Abs) t).getParam()) + "."
> + termToStringLci(((Abs) t).getBody()) + ")";
> } else if (t instanceof App) {
> return "(" + termToStringLci(((App) t).getT1()) + " "
> + termToStringLci(((App) t).getT2()) + ")";
> } else if (t instanceof Uq) {
> return termToStringLci(((Uq) t).getTerm());
> } else if (t instanceof Tapp) {
> return termToStringLci(((Tapp) t).getTerm());
> } else if (t instanceof Nrif) {
> return termToStringLci(((Nrif) t).getNome().getTerm());
> } else if (t instanceof Let) {
> return "((\\" + (((Let) t).getVar()) + "."
> + termToStringLci(((Let) t).getT2()) + ") "
> + termToStringLci(((Let) t).getT1()) + ")";
> }
> return "";
> }
>
> /**
> * restituisce la stringa che rappresenta il tipo
> * @param t : t il tipo
> * @return a stringa che rappresenta il tipo
> */
> private String typeToString(T t) {
> if (t instanceof T1) {
> String p = ((T1) t).getP();
> EList<T> c = ((T1) t).getC();
> if (!c.isEmpty()) {
> p += "->";
> for (T a : c)
> p += typeToString(a);
> }
> return p;
> } else if (t instanceof T2) {
> String p = "(" + typeToString(((T2) t).getP1()) + ")";
> EList<T> c = ((T2) t).getC1();
> if (!c.isEmpty()) {
> p += "->";
> for (T a : c)
> p += typeToString(a);
> }
> return p;
>
> } else if (t instanceof T3) {
> return "forall " + (((T3) t).getVar()) + " "
> + typeToString(((T3) t).getT());
>
> } else if (t instanceof Trif) {
> return typeToString(((Trif) t).getNome().getType());
>
> }
> return "";
>
> }
>
> /* SERVICE METHODS */
> private String toFileName(String name) {
> int idx = getLastSeparatorIndex(name);
>
> if (idx == -1)
> return "";
>
> return name.substring(idx + 1, name.length() - 1);
> }
>
> private String toWorkingPath(String name) {
> IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
> String path = root.getLocation().toString() + "/";
>
> int idx = getLastSeparatorIndex(name);
> if (idx == -1)
> return "";
>
> return path + name.substring(3, idx) + "/";
> }
>
> private String toUriPrefix(String name) {
> int idx = name.indexOf('/');
> if (idx == -1)
> return "";
>
> return "platform:/resource"
> + name.substring(idx, name.lastIndexOf('/')) + "/";
> }
>
> private int getLastSeparatorIndex(String name) {
> int idx = name.length() - 1;
>
> while (name.charAt(idx) != '/') {
> idx--;
> if (idx < 0)
> return -1;
> }
>
> return idx;
> }
>
> private void echo(boolean value) {
> if (value) {
> System.setOut(stdout);
> } else {
> System.setOut(silence);
> }
> }
>
> }
>
>
>
>
> The problem is that it can not find my interpreter, who is working in
> the project xtext directory . because when I run my project xtext
> changes the working directory.
Previous Topic:Local variable defined in Entity cannot be referred in operation body
Next Topic:scope problem
Goto Forum:
  


Current Time: Wed May 15 04:37:23 GMT 2024

Powered by FUDForum. Page generated in 0.03679 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top