Android Eclipse Use external tools to run a script on the code

前端 未结 1 1337
野的像风
野的像风 2021-01-13 12:35

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

相关标签:
1条回答
  • 2021-01-13 13:21

    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: External Tools Configuration Dialog
    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: enter image description here
    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.

    0 讨论(0)
提交回复
热议问题