Using JS script method in Ant build

Ant build scripts can embed scripts, including JS , Groovy , Ruby , etc.
Take the build script released by the integration platform 3.0 as an example to illustrate how Ant builds embedded JS .

1. Introduce dependency packages
        ant-contrib-1.0b3.jar
        bsf-2.4.0.jar
        js.jar

2. Syntax

<script language="javascript">
      <classpath />
      <![CDATA[
        {js代码}
      ]]>
  </script>


   Language optional javascript , groovy , ruby ​​.
   Javascript script introduces js.jar , and groovy introduces groovy.jar .

3. JS variable access
Project is a built-in variable that can be accessed directly. The properties defined in ant can be obtained with the following code project.getProperty("release.local.export.path"); of course, you can also modify the properties of ant project.setProperty("source.view.dir", files[0]) ; 4. The case illustrates the release rules of the integrated platform 3.0 , copying the code of the development flow to the release flow, and the directory with release date and version information. The directory where the code is released changes metamorphically, and the name of the directory changes every time a version is released. The distribution program needs to call the build script in the distribution code, so the difficulty of obtaining the distribution directory must be solved. The following script gets the release code directory through JS code.






  <!-- 找出最新的发布流程序保存的目录名称 -->
  <target name="init.path" depends="export.release">
    <script language="javascript">
      <classpath refid="js.classpath" />
      <![CDATA[
        importClass(java.io.File);
        importClass(java.io.FilenameFilter);
        importClass(java.util.regex.Matcher);
        importClass(java.util.regex.Pattern);        path = project.getProperty("release.local.export.path");        root = new File(path);        if(root.exists() && root.isDirectory()){        files = root.listFiles();        if(files.length>0){          project.setProperty("source.view.dir",files[0]);        }      }
            








      ]]>
    </script>
    <echo>${source.view.dir}</echo>
  </target>

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327037660&siteId=291194637