Quick shot for getting the newest file (then the <touch> would also be
helpful).

Jan


<project>

  <!--
      Iterates over filesets and stores the latest timestamp (long value)
      in a specified property.
  -->
  <scriptdef name="newest" language="javascript">
      <attribute name="property"/>
      <element name="fileset" type="fileset"/>
      importClass(Packages.org.apache.tools.ant.Project);
      importClass(Packages.org.apache.tools.ant.DirectoryScanner);
      importClass(Packages.org.apache.tools.ant.types.FileSet);
      importClass(java.io.File);
      lastMod = 0;
      filesets = elements.get("fileset");
      for (i=0; i&lt;filesets.size(); i++) {
          fs = filesets.get(i);
          ds = fs.getDirectoryScanner(project);
          srcFiles = ds.getIncludedFiles();
          basedir = fs.getDir(project);

          for (j=0; j&lt;srcFiles.length; j++) {
              file = new File(basedir, srcFiles[j]);
              lm = file.lastModified();
              project.log(srcFiles[j] + "  : " + lm, Project.MSG_VERBOSE);
              if (lastMod &lt; lm) {
                  lastMod = lm;
              }
          }
      }

      project.setNewProperty(attributes.get("property"), lastMod);
  </scriptdef>


  <!--
      Converts a long value to a readable Date string.
  -->
  <scriptdef name="long2date" language="javascript">
      <attribute name="pattern"/>
      <attribute name="value"/>
      <attribute name="property"/>
      // easier access to attributes
      pattern   = attributes.get("pattern");
      value     = attributes.get("value");
      propName  = attributes.get("property");

      // create a Date object from String
      longValue = java.lang.Long.parseLong(value);
      date = new java.util.Date(longValue);

      // format the value
      formatter = new java.text.SimpleDateFormat(pattern);
      result    = formatter.format(date);

      // store the result
      project.setNewProperty(propName, result);
  </scriptdef>


  <!-- example -->


  <!-- what's the latest date? -->
  <newest property="lastDate">
      <fileset dir="." includes="1"/>
      <fileset dir="." excludes="1"/>
  </newest>

  <!-- make it readable -->
  <long2date property="date" value="${lastDate}" pattern="yyyymmdd
HH:MM:ss"/>

  <!-- print the result -->
  <echo>lastDate = ${lastDate} = ${date}</echo>

</project>




> -----Original Message-----
> From: Rami Ojares [mailto:[EMAIL PROTECTED]
> Sent: Friday, June 11, 2004 11:21 AM
> To: [EMAIL PROTECTED]
> Subject: RE: File Includer
> 
> 
> 
> > The way to resolve your requirement is providing
> > a different task (useful on its own right) that
> > given a fileset it adjust the lastmodified of a target
> > file to be the latest date of the files in the fileset.
> > 
> > Do you think this two things will solve your problem?
> 
> I will have a shot at it.
> 
> - rami
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 

Reply via email to