Android Eclipse使用外部工具在代码上运行脚本 [英] Android Eclipse Use external tools to run a script on the code

查看:104
本文介绍了Android Eclipse使用外部工具在代码上运行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现解决许多未解答问题的方法是在代码上运行一个Perl脚本,以便执行一些更改,这些更改对于使用正则表达式或更简单的操作,不如我提供给DalVik的一些建议。



所以这将是一个自我回答的问题,我告诉你我如何设法做到这一点,一步一步即可。我希望这将帮助人们解决他们的一些问题。

解决方案

目标是从Eclipse内运行以下命令行在我当前打开的文件中,刷新它以查看结果:



perl -S -pi.bak myscript.pl



我将使用外部工具配置。
本指南基于Eclipse 3.7.1


  1. 打开运行 - > 外部工具 - > 外部工具配置...
    (或者,您可以使用拐角处的小红色工具箱从运行图标打开它)

  2. 选择节目

  3. 添加新建启动配置(第一个图标,右上角或右上角的小加号点击程序 - > 新建

  4. 你应该看到这样:

  5. 填写名称

  6. 要启动的工具的路径(在本例中为perl: C:\Perl\bin\perl.exe

  7. 在工作中方向性选择变量... $ {container_loc} ,这是目前IDE上文件的目录

  8. 作为参数: -S -pi.bak $ {file_prompt:选择Perl脚本:D:\marcelo\Perl\bin\myscript.pl} $ {container_name}
    再次,您不必键入$ {container_name}或$ {file_prompt ...},您可以从变量...

  9. 应用
    您现在应该看到:

  10. 转到刷新标签,然后检查完成后刷新资源,然后从选项所选资源中选择

  11. 转到构建标签,然后取消选中启动前构建

我们完成了,现在有几个注释:




  • 常用标签中可以在添加到收藏夹菜单下检查外部工具,您的脚本将显示在外部工具子菜单中,而不会导致havin您可以先运行它。

  • 您可能已经注意到还有很多其他选项,请随意尝试

  • 此示例仅修改文件IDE。 myscript.pl的内容是:





next / i /;

s / \bint\s +(\w +)/ int n_ $ 1 / g;

s / \bString\s +(\w +)/ String s_ $ 1 / g;






  • $ {file_prompt :选择Perl脚本:D:\marcelo\Perl\bin\myscript.pl} 打开一个对话框,您可以在其中选择要运行的perl脚本。

  • 如果要运行总是相同的脚本,只需使用脚本名称

  • 替换 $ {file_prompt ...} ,我安装了 EPIC插件在Eclipse上,所以我可以编辑perl文件以及


  • 你没有限制修改你的资源。您只需运行一个从当前文件生成输出的脚本。脚本的输出,也遇到任何错误,都会显示在控制台
    提示:如果要同时将新文件写入并为用户打印消息,则在perl中,使用STDERR打印出消息和STDOUT打印文件。



I found out that a solution to many of my unanswered questions was to run a perl script on the code to perform some changes that are hard to impossible to do with regexs or musch simpler than some advices I got to hook into DalVik.

So this is going to be a self-answered question were I tell you how I manage to do it, step by step. I hope this will help people to solve some of their problems.

解决方案

The target is to run the following command line from within Eclipse on my currently opened file and refresh it to see the results:

perl -S -pi.bak myscript.pl

I am going to use an External Tools configuration. this guide is based on Eclipse 3.7.1

  1. Open Run -> External Tools -> External Tools Configuration ... (Alternatively you can open it from the Run icon with the small red toolbox on the corner)
  2. Select Program
  3. Add a New Launch Configuration (First Icon with the little plus on the top right corner or right click on Program -> New)
  4. You should see this:
  5. Fill the Name
  6. On the location put the path to the tool you want to launch (in this case perl: C:\Perl\bin\perl.exe)
  7. In the working direectory choose from the Variables..., ${container_loc} which is the directory of the file currently on the IDE
  8. As arguments put: -S -pi.bak ${file_prompt:Select Perl Script:D:\marcelo\Perl\bin\myscript.pl} ${container_name}
    Again you don't have to type ${container_name} or ${file_prompt...} you can choose it from Variables...
  9. Press Apply
    You should see this now:
  10. Go to the Refresh tab and check Refresh resources upon completion and choose from the options The selected resource
  11. Go to the Build tab and uncheck Build before launch

We are done, now several notes:

  • In the Common tab you can check External Tools under Add to favorites menu and your script will appear on the External Tools submenu, without having to run it first.
  • You probably noticed there are a lot of other options, feel free to experiment
  • This example just modifies the file in the IDE. The contents of myscript.pl are:

next unless /Log.i/;
s/\bint\s+(\w+)/int n_$1/g;
s/\bString\s+(\w+)/String s_$1/g;

  • The ${file_prompt:Select Perl Script:D:\marcelo\Perl\bin\myscript.pl} opens a dialog box where you can select the perl script to run.
  • If you want to run always the same script just replace the ${file_prompt...} with the script name
  • I installed the EPIC plugin on Eclipse so I can edit perl files as well

  • You are not constrained to modify you resource. You can just run a script that generates outputs from the current file. The output of the script, also any errors encountered, are displayed in the Console
    Tip: In perl if you want to both write the new file out and also print out a message for the user, use STDERR to print out the message and STDOUT to print out the file.

这篇关于Android Eclipse使用外部工具在代码上运行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆