I'm currenly working on moving a build system that comprises mainly of shell scripts 
to maven.  One of the things that the current system does is create a changelog file 
(changelog.${build.number}) that contains all CVS commit logs since the last release.  
We use build numbers, but releases are around every 100 builds, so the number is not 
sequential.

The code I have currently works, but it's not easy to understand and it seems like 
there should be an easier way.  Below is an example goal that works! and gets the last 
modified time from the last sequential file, which in my build process is used to get 
commit log entries from CVS.


------project.xml snippet-------
    <!-- for the script tag -->
    <dependency>
      <groupId>ant</groupId>
      <artifactId>ant-apache-bsf</artifactId>
      <version>1.6</version>
      <properties><classloader>root</classloader></properties>
      <url>http://jakarta.apache.org/bsf/</url>
    </dependency>
    <!-- for the script tag -->
    <dependency>
      <groupId>bsf</groupId>
      <artifactId>bsf</artifactId>
      <version>2.2</version>
      <properties><classloader>root</classloader></properties>
      <url>http://www-124.ibm.com/developerworks/projects/bsf</url>
    </dependency>
    <!-- for the javascript-specific script tag -->
    <dependency>
      <groupId>rhino</groupId>
      <artifactId>js</artifactId>
      <version>1.5R4-RC3</version>
      <properties><classloader>root</classloader></properties>
      <url>http://www.mozilla.org/rhino/</url>
    </dependency>


------maven.xml snippet------
  <goal name="last-sequential-file" description="Finds the last file in a directory" >
    <taskdef name="script" classname="org.apache.tools.ant.taskdefs.optional.Script" />

    <!-- the oldest messages log, last sequentially (just an example, not actual use) 
-->
    <fileset id="files" dir="/var/log"><include name="messages.*.gz"/></fileset>

    <!-- Get the count of files -->
    <script language="javascript"> <![CDATA[
      project.setProperty("count", 
files.getDirectoryScanner(project).getIncludedFiles().length);
    ]]> </script>

    <!-- if no file found, output all changelog entries since the beginning -->
    <j:if test="${count == 0}">
      <echo taskname="count" message="No files were found"/>
    </j:if>

    <j:if test="${count != 0}">
      <!-- find the last file in that directory -->
      <script language="javascript"> <![CDATA[
        srcFiles = files.getDirectoryScanner(project).getIncludedFiles();
        filename = new java.lang.String(srcFiles[0]);
        for (i = 1; i != srcFiles.length; i++) {
          var j = filename.compareTo(srcFiles[i]);
          // the jelly parser can't have a greater than or less than sign or ampersand 
in the script section?
          if (j != 0) if (j != Math.abs(j)) filename = srcFiles[i];
        }
        project.setProperty("file", filename);
      ]]> </script>

      <!-- Get the last modification time of the last file -->
      <echo message="Last file (/var/log/${file})"/>
      <u:file name="/var/log/${file}" var="lastfile"/>
      <j:set var="mseconds" value="${lastfile.lastModified()}"/>

      <!-- transform from seconds to regular time -->
      <script language="javascript"> <![CDATA[
        importClass(java.lang.Long);
        importClass(java.text.SimpleDateFormat);
        var formatter = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm");
        project.setProperty("from", formatter.format(new 
java.util.Date(Long.parseLong(project.getProperty("mseconds")))));
      ]]> </script>

      <echo message="The last file was modified at ${from}"/>
    </j:if>
  </goal>

------END------


I've looked through ant, jelly, and maven documentation, but I couldn't find an easier 
way to do this.  Any ideas?

-jake


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to