How to apply an external formatting script to files in eclipse?
I'd like to run an external beautifier over m开发者_JS百科y code that's open and replace the contents of the document with the output. Is there a plugin or something I can exploit to do this? I thought it would be a no-brainer under the formatter preferences, but it looks like you can only use internal templates.
One solution is the following:
Create an ant builder on your project. See this article about how to do that. The important things you should know after you read the article:
- Add a new ant builder by right click on project and properties. See the implicit variables your ant script will have. The variables will contain one or more resource name and path. So be prepared for collections.
- Filter the resouces in the "Build options" tab. This is important, since launching a JVM (or a new task inside IDE JVM) for the change of every file (filetype) is not so fast. So filter resources to be processed like this:
- The third thing is to ask eclipse to refresh the resource after the script is run. Like this:
- Set the target of the ant script to be run as automatic build (third option). You can set all the four anyway it will be ok:
- Write your script. You will find the log of the ant script in console, and you may redirect the log into a file as well. You can see the option on the second picture. Start your script with an echoproperties tag to see what your script gets from eclipse.
I used such builders a lot, it works like it should. I like them. Good luck. Consider accepting your answers, 42 % is not too much :D
精彩评论