walkmod-core
walkmod-core copied to clipboard
Allow having walkmod.xml outside of sources
Not a big deal but I would like to keep one walkmod.xml for several projects and be able to specify path to it using WALKMOD_OPTS. I would submit a pull request but don't really understand all those getting/setting of user.dir, also new File(System.getProperty("user.dir"))
found on several places - this I believe is equal to new File("")
Any suggestion to improve walkmod is always welcome!
When you are creating a file with a relative path in java using 'new File("foo")', java resolves the absolute path with the value of the execution dir ("user.dir") and the value of the relative path. In order to conserve correct paths when walkmod is executed recursively (e.g for maven modules), walkmod modifies the value of the "user.dir".
Yes, you can do it with WALKMOD_OPTS checking if the environment variable exists and there is a value for it.
However, walkmod can be executed from a maven plugin or embedded in another system (e.g Eclipse IDE or forge) and people that participate into the project probably want to have the configuration file in another place (e.g a subdirectory). For that reason, I think that this feature would also be implemented with a new optional parameter into all the commands (e.g -f).
Anyway, let's start from just modifying WALKMOD_OPTS :+1:
Please, in order to do so, use the dev branch (at this moment is in the same commit than master).
Thanks again for your contributions :)
I am not sure I understand the use of "user.dir" because I am getting some weird behaviour, and maybe this it is expected. I created a project to demo it.
- I have a folder with what would be a normal walkmod project in it under
test/resources
: https://github.com/abelsromero/walkmod-tests/tree/master/src/test/resources. - Then I execute Walkmod using the Java interface and I set
user.dir
to the previous folder here: https://github.com/abelsromero/walkmod-tests/blob/master/src/main/java/org/abelsromero/walkmod/WalkmodRunner.java#L32-L34. - I set my walkmod.xml to take into consideration
user.dir
: https://github.com/abelsromero/walkmod-tests/blob/master/src/test/resources/walkmod.xml#L18
But debugging I see that the initialisation in the Facade works properly, but If I check the ScriptProcessor (here: https://github.com/rpau/walkmod-core/blob/master/src/main/java/org/walkmod/scripting/ScriptProcessor.java#L108) I see that it searches from the root path of the project, and I access to user.dir
it points to the root of the project and not the value I set previously.
So, I don't know If I should be setting it i another way or is some bug?
Btw, when the script is not found no error or message is shown.