IntelliJ Plugin Working Directory

I created a plugin.
It first changes the directory to my project folder.
Then it opens SBT and does the command gen-idea no-sbt-build-module.

When I run it in a scala worksheet, it works.
When I run it from the menu were the plugin interacts, it changes back to default-0ce3ae. (Default directory of IDE?)
Any help?

Thank you,
Erick

7 comments

This is java running commandline running sbt.
// this was a tricky one to program, haha.
Note: I would simply specify the directory however the location will be different on each computer using it.

Runtime rt = Runtime.getRuntime();
BufferedReader stdInput = new BufferedReader(new InputStreamReader(
                    rt.exec("cmd.exe /c dir || start cmd.exe /c " +
                            "FOR /F \"delims==\" %G IN ('dir /s/b MyWorkingDirectory') " +
                            "DO cd %G & " +
                            "dir & " +
                            "sbt clean compile \"gen-idea no-sbt-build-module\" & " +
                            "dir").getInputStream()));
-----------------------------------------------------------------------------------------------------------------
I apologize for the cryptic format. Bash/Java people should be able to understand it though.
It searches for the working directory, changes to that directory, then executes the sbt stuff.
[info] Set current project to default-0ce3ae (in build file:/C:/Program%20Files%20(x86)/JetBrains/IntelliJ%20IDEA%20Community%20Edition%2012.1.3/bin/)
This is the output just after the dir is shown and before the sbt.

Thanks again,
Erick

0

Hi Erick,

I'm afraid I don't quite understand the problem. Please correct me if I'm wrong but as far as I see you run an external 'cmd' process via Runtime.exec(), execute 'cd' to the target dir there and then run 'sbt' but 'sbt' process uses another dir as a 'working dir', right?

Denis

0

That is correct sbt is accessing the working directory of IntelliJ rather then the directory I change it to.

0

I don't see how that is related to the ide then - you just work with external processes via standard java api.

Denis

0

@ Denis,

My thoughts are that the IDE is changing the working directory to it's default. Rather than maintaining the current directory. I don't know if there is a way to change the target of the default directory or if I can disable the change to default location.
As far as I can tell, SBT and the java commands are unrelated to the changing of the directory(the change back to default location) only leaving the IDE as the candidate for the difficulty. (This is likely an intentional feature?)

Thank you,
Erick

0

Please correct me if I'm wrong but as far as I understand you start external process which has nothing to do with the ide. There you execute 'cd' with subsequent 'sbt' and 'sbt' doesn't work with current directory. I really doubt the ide resets working dir between 'cd' and 'sbt' commands execution.

May be it's related to sbt setup, i.e. it's configured to use particular directory when run under ide but I'm not sure about that. Will ask our scala guys to have a look here.

Denis

0

Turns out the cd was incorrectly implemented as you said. It worked in the worksheet because it did not actually cd.
It did not work in the plugin for the same reason.

Thank you for all of your help,
Erick

0

Please sign in to leave a comment.