开发者

Generate MetaData with Ant

开发者 https://www.devze.com 2022-12-28 17:02 出处:网络
I have a folder structure that contains multiple javascript files, each of these files need a standard piece of text at the top = //@include \"includes.js\"

I have a folder structure that contains multiple javascript files, each of these files need a standard piece of text at the top = //@include "includes.js"

Each folder needs to contain a file named includes.js that has an include entry for each file in its directory and and entry for the include file in its parent directory.

I'm trying to achieve this using ant and it's not going too well. So far I have the following, which does the job of inserting the header but not without actually moving or copying the file. I have heard people mentioning the <replace> task to do this but am a bit stumped.

<?xml version="1.0" encoding="UTF-8"?>

<project name="JavaContentAssist" default="start" basedir=".">

    <taskdef resource="net/sf/antcontrib/antcontrib.properties">
      <classpath>
        <pathelement location="C:/dr_workspaces/Maven Repository/.m2/repository/ant-contrib/ant-contrib/20020829/ant-contrib-20020829.jar"/>
      </classpath>
    </taskdef>

    <target name="start">

        <foreach target="strip" para开发者_如何学运维m="file">

            <fileset dir="${basedir}">
                <include name="**/*.js"/>
                <exclude name="**/includes.js"/>
            </fileset>

        </foreach>

    </target> 

    <target name="strip">

        <move file="${file}" tofile="${a_location}" overwrite="true">

            <filterchain>
                <striplinecomments>
                    <comment value="//@" />
                </striplinecomments>
                <concatfilter prepend="${basedir}/header.txt">
                </concatfilter>
            </filterchain>
        </move>


    </target>

</project> 

As for the generation of the include files in the dir I'm not sure where to start at all. I'd appreciate if somebody could point me in the right direction.


This seems to satisfy the problem description:

<project default="addincludes">
  <taskdef resource="net/sf/antcontrib/antcontrib.properties">
    <classpath>
      <pathelement location="ant-contrib/ant-contrib-1.0b3.jar"/>
    </classpath>
  </taskdef>

  <target name="addincludes">
    <foreach target="perdir" param="dir">
      <path>
        <dirset dir="src" includes="**"/>
      </path>
    </foreach>
  </target>

  <target name="perdir">
    <echo file="${dir}/includes.js">//@include "../includes.js"&#10;</echo>
    <foreach target="perfile" param="file">
      <path>
        <fileset dir="${dir}" includes="*.js" excludes="includes.js"/>
      </path>
    </foreach>
  </target>

  <target name="perfile">
    <basename property="basename" file="${file}"/>
    <echo file="${dir}/includes.js" append="true">//@include "${basename}"&#10;</echo>
    <move file="${file}" tofile="${file}.tmp" overwrite="true">
      <filterchain>
        <striplinecomments>
          <comment value="//@" />
        </striplinecomments>
        <concatfilter prepend="header.txt"/>
      </filterchain>
    </move>
    <move file="${file}.tmp" tofile="${file}" overwrite="true"/>
  </target>
</project>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号