Last Sequential File

2004-01-02 Thread Jake Ewerdt
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
  groupIdant/groupId
  artifactIdant-apache-bsf/artifactId
  version1.6/version
  propertiesclassloaderroot/classloader/properties
  urlhttp://jakarta.apache.org/bsf//url
/dependency
!-- for the script tag --
dependency
  groupIdbsf/groupId
  artifactIdbsf/artifactId
  version2.2/version
  propertiesclassloaderroot/classloader/properties
  urlhttp://www-124.ibm.com/developerworks/projects/bsf/url
/dependency
!-- for the javascript-specific script tag --
dependency
  groupIdrhino/groupId
  artifactIdjs/artifactId
  version1.5R4-RC3/version
  propertiesclassloaderroot/classloader/properties
  urlhttp://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/loginclude 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(-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]



Re: Last Sequential File

2004-01-02 Thread Gilles Dodinet
Jake Ewerdt wrote:

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

Perhaps you could create a Jelly Tag with one attribute - the directory 
to look in - that would grab the date thanks a FileFilter and then put 
it in the context ?

-- gd

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