ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dominique Devienne <ddevie...@gmail.com>
Subject Re: versioned file task
Date Fri, 01 Jul 2005 01:42:32 GMT
On 6/30/05, Eliot Sykes <eliotsykes@gmail.com> wrote:
> I've got a need in a build process for retrieving the version number
> of a checked out file from CVS and setting a property equal to this
> version number.
> 
> Does anybody know if a task exists that does this already?  If so
> please let me know, otherwise I'm keen for this functionality so may
> find time to build a task to do this.

There's currently no tasks to do this. You can implement this with Ant
using <loadfile> and filterreaders within, especially the regex one.

Here's a set of macros I'm using to load CVS info. You should be able
to adapt it to load the Entries file too. --DD

PS: Sometimes there are several Entries files, which may complicate
the task. I'm not too sure why or when.

  <!-- ====================================================
       Defines macros to make the build itself more readable.
    -->
  <target name="-macros">

    <!-- Assert is given property is indeed set -->
    <macrodef name="assert-set">
      <attribute name="property" />
      <text name="text" optional="true" />
      <sequential>
        <fail unless="@{property}">
          Error: Property '@{property}' not specified!
          @{text}
        </fail>
      </sequential>
    </macrodef>

    <!-- Assert is given property is not already set -->
    <macrodef name="assert-not-set">
      <attribute name="property" />
      <sequential>
        <fail if="@{property}">Internal @{property} property set!</fail>
      </sequential>
    </macrodef>

    <!-- Assert is given file is a file or directory -->
    <macrodef name="assert-exists">
      <attribute name="file" />
      <attribute name="type" />
      <sequential>
        <ac:if>
          <not><available file="@{file}" type="@{type}" /></not>
          <then>
            <fail>Cannot find @{file} directory!</fail>
          </then>
        </ac:if>
      </sequential>
    </macrodef>

    <!-- Assert two values are equal -->
    <macrodef name="assert-equals">
      <attribute name="arg1" />
      <attribute name="arg2" />
      <attribute name="property" />
      <text name="text" optional="true" />
      <sequential>
        <assert-not-set property="@{property}" />
        <condition property="@{property}">
          <equals arg1="@{arg1}" arg2="@{arg2}" />
        </condition>
        <fail unless="@{property}">
          @{text}
        </fail>
      </sequential>
    </macrodef>

    <!-- Assert is given file is a file or directory -->
    <macrodef name="cvs-load-file">
      <attribute name="dir" />
      <attribute name="name" />
      <attribute name="property" />
      <attribute name="required" default="true" />
      <element name="filters" implicit="true" optional="true" />
      <sequential>
        <!-- First, assert we have a CVS/ subdir in the directory -->
        <assert-exists file="@{dir}/CVS" type="dir" />

        <!-- Then assert the property we're setting is not already set -->
        <assert-not-set property="@{property}" />

        <ac:if>
          <available file="@{dir}/CVS/@{name}" type="file" />
          <then>
            <!-- Avoid the FileNotFoundException if the Tag file
                 doesn't exist because it's a HEAD branch
                 (instead of just not failing on error) -->
            <loadfile property="@{property}" srcfile="@{dir}/CVS/@{name}">
              <filterchain>
                <striplinebreaks/>
                <filters />
              </filterchain>
            </loadfile>
          </then>
          <else>
            <bm:sequential ifTrue="@{required}">
              <fail>Error: Cannot read file @{dir}/CVS/@{name}</fail>
            </bm:sequential>
          </else>
        </ac:if>
      </sequential>
    </macrodef>

    <!-- Gets the CVSROOT of a given directory -->
    <macrodef name="cvs-root">
      <attribute name="dir" />
      <attribute name="property" />
      <sequential>
        <cvs-load-file dir="@{dir}" name="Root" property="@{property}" />
      </sequential>
    </macrodef>

    <!-- Gets the CVS repository/module of a given directory -->
    <macrodef name="cvs-repo">
      <attribute name="dir" />
      <attribute name="property" />
      <sequential>
        <cvs-load-file dir="@{dir}" name="Repository" property="@{property}" />
      </sequential>
    </macrodef>

    <!-- Gets the CVS sticky tag of a given directory -->
    <macrodef name="cvs-tag">
      <attribute name="dir" />
      <attribute name="property" />
      <sequential>
        <cvs-load-file dir="@{dir}" name="Tag" property="@{property}"
                       required="false">
          <tokenfilter>
            <replaceregex pattern="^T" replace="" />
          </tokenfilter>
        </cvs-load-file>
        <property name="@{property}" value="HEAD" />
      </sequential>
    </macrodef>

  </target>

  <!-- ==================================================== -->
  <target name="cvs-info" depends="-macros"
          description="Print CVS info for the current directory">

    <!-- Test drive the macros -->
    <cvs-root dir="${user.dir}" property="root" />
    <cvs-repo dir="${user.dir}" property="repo" />
    <cvs-tag  dir="${user.dir}" property="stag" />
    <echo>
      CVS info for sandbox in ${user.dir}:

      CVSROOT ${root}
      module  ${repo}
      tag     ${stag}
    </echo>

  </target>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message