ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dominique Devienne <DDevie...@lgc.com>
Subject RE: Modifying a DirSet (or any AbstractFileSet) from within a <sc ript>
Date Wed, 10 Sep 2003 17:03:43 GMT
So you do want to use <copy>...

Here's a build script that looks rather complex at a glance, and I don't
even recall its exact purpose ;-), but it does use <delete id="..."> and a
<script> to modify the <delete> task to feed it single-file filesets, which
looks rather similar to your problem it seems.

I hope this might help. --DD


<?xml version="1.0"?>

<!-- ANT build file to test a specific feature or bug of ANT.
     Dominique Devienne <ddevienne@lgc.com>         Mar 2003
  -->
<project name="CopyDeletePath" default="init">

  <target name="init">
    <!-- Simulate user-supplied Path -->
    <path id="path">
      <fileset dir="${ant.home}/lib" includes="*.jar" />
    </path>
    <property name="path" refid="path" />

    <!-- Pretty print path-->
    <pathconvert property="formatted-path" refid="path"
                 pathsep="${line.separator}       " />
    <echo message="path = ${formatted-path}" />
  </target>

  <target name="clean">
    <delete dir="${ant.project.name}" quiet="true" />
  </target>

  <target name="copy-path" depends="init">
    <mkdir dir="${ant.project.name}" />
    <antcall target="-copy-path">
      <param name="taskid" value="copy" />
      <reference refid="path" torefid="path2add" />
    </antcall>
  </target>

  <target name="-copy-path" depends="-add-path-element-to-task">
    <copy id="copy" todir="${ant.project.name}" />
  </target>

  <target name="delete-path">
    <mkdir dir="${ant.project.name}" />
    <path id="jars2delete">
      <fileset dir="${ant.project.name}" includes="*.jar" />
    </path>
    <property name="jars2delete" refid="jars2delete" />
    <pathconvert property="formatted-path2" refid="jars2delete"
                 pathsep="${line.separator}           " />
    <echo message="jars2delete = ${formatted-path2}" />

    <antcall target="-delete-path">
      <param name="taskid" value="delete" />
      <reference refid="jars2delete" torefid="path2add" />
    </antcall>
  </target>

  <target name="-delete-path" depends="-add-path-element-to-task">
    <delete id="delete" quiet="true" />
  </target>

  <target name="-add-path-element-to-task">
    <script language="javascript"><![CDATA[
      prj  = self.getProject();
      task = prj.getReference(prj.getProperty("taskid"));
      path = prj.getReference("path2add");
      importPackage(Packages.org.apache.tools.ant.types);
      jars = path.list();
      for (var i = 0; i < jars.length; ++i) {
        fileset = new FileSet();
        fileset.setProject(prj);
        fileset.setFile(new java.io.File(jars[i]));
        task.addFileset(fileset);
      }
    ]]></script>
  </target>

</project>

> -----Original Message-----
> From: Ken Gentle [mailto:j.kenneth.gentle@acm.org]
> Sent: Wednesday, September 10, 2003 11:45 AM
> To: Ant Users List
> Subject: RE: Modifying a DirSet (or any AbstractFileSet) from within a <sc
> ript>
> 
> I'm trying to automate a rather bizarre process by which we create a
> release package for deployment to our production environment.  We
> generally
> have two or more QA releases per PROD release, and the method for creating
> the PROD release is to "combine" QA releases with a few rules into a PROD
> release (yes, I know that PROD should be built from sources in the CM
> system, but that is not the practice here.)
> 
> The "rules" are this:  Take each QA release, in order of increasing build
> number, and copy it to the PROD tree.  Any existing files with the same
> name are overwritten.  The exceptions are the "database scripts" which are
> copied to the PROD structure, but with the build number prepended.
> 
> Our [inherited from antiquity] build/deploy structure looks something like
> this:
> 
>          yyyy-mm-dd/<env>/<release-id>[-<build#>|<patch#>]
> 
> where
>          yyyy-mm-dd      is the targeted release date (a pain when it
> changes!)
>          env             is one of QA or PROD
>          release-id      is MM.mm.pp  (Major.minor.patch)
>          build#          is the QA build number
>          patch#          is the PROD "emergency" patch number
> 
> So we might have a release structure that looks something like this:
> 
>          2003-07-31
>          2003-07-31/QA
>          2003-07-31/QA/3.04.06-01
>          2003-07-31/QA/3.04.06-02
>          2003-07-31/QA/3.04.06-03
>          2003-07-31/QA/3.04.06-04
>          2003-07-31/QA/3.04.06-05
>          2003-07-31/PROD
>          2003-07-31/PROD/3.04.06
> 
> So the problem at the moment is guaranteeing that a list of
> directories/files is in the order of the QA build numbers.
> 
> Once I have that list, then I can use <copy> to perform the actual
> transfer.
> 
>          Ken
> 
> BTW, I already have the "Scripts" exception case handled (see "ONE
> SOLUTION: Convert Bash Script to equivalent Ant tasks?")
> 
> At 12:18 PM 9/10/2003, you wrote:
> >I think it depend in part on what you'll do later on...
> >
> >The only two data types that come to mind would allow you to keep your
> >ordering would be <filelist>, and <path>, but neither is supported by
> <copy>
> >for example.
> >
> >If you wanted to do a copy for example, you'd have to add one single-file
> >fileset per sorted dir you have, as <copy> keeps a vector of fileset, and
> >process them serially (I think). But that requires you to put the <copy>
> in
> >the script... You can also define the <copy> with an ID, and fetch it
> from
> >the <script> and feed it single-file filesets also...
> >
> >I don't think there's any one great solution to your problem.
> >
> >What are you doing at a higher level actually? Sometimes taking a step
> back
> >allows to see other alternate solutions ;-) --DD
> >
> > > -----Original Message-----
> > > From: Ken Gentle [mailto:j.kenneth.gentle@acm.org]
> > > Sent: Wednesday, September 10, 2003 10:02 AM
> > > To: user@ant.apache.org
> > > Subject: Modifying a DirSet (or any AbstractFileSet) from within a
> > > <script>
> > >
> > > Hello all!
> > >
> > > I have a need to ensure that I can process a list of directories in a
> > > particular order (happens to be the "natural" sort order, luckily).
> > > Thanks
> > > to Dominique's post of a while back, I've got a little script that
> will
> > > retrieve the list of directories from the DirSet and sort them.  How
> would
> > > I get them back into the original DirSet (or another DirSet) for use
> by
> > > other tasks?
> > >
> > > Here's the script so far:
> > >
> > >      <script language="javascript">
> > >        <![CDATA[
> > >        prj = self.getProject();
> > >        dirset = prj.getReference("dirset.qa.releases");
> > >
> > >        scanner = dirset.getDirectoryScanner(prj);
> > >        fromDir = dirset.getDir(prj);
> > >        srcDirs = scanner.getIncludedDirectories();
> > >
> > >        importPackage(Packages.java.util);
> > >        Arrays.sort(srcDirs);
> > >        ]]>
> > >      </script>
> > >
> > > I've tried using the relatively undocumented Rhino feature JavaAdapter
> to
> > > extend DirectoryScanner (intending to replace the DirSet's
> > > directoryScanner
> > > with one that will return the sorted array of strings (srcDirs)), but
> I
> > > can't get the JavaAdapter to accept
> > > 'org.apache.tools.ant.DirectoryScanner'
> > > as a valid class - I get the following message:
> > >
> > > file:s:/shared/2003-TEST/js.xml:13: ReferenceError: "org" is not
> defined.
> > > (<ANT>
> > > ; line 13)
> > >
> > > Here's my "extended" script with the offending call:
> > >
> > >      <script language="javascript">
> > >        <![CDATA[
> > >        prj = self.getProject();
> > >        dirset = prj.getReference("dirset.qa.releases");
> > >
> > >        scanner = dirset.getDirectoryScanner(prj);
> > >        fromDir = dirset.getDir(prj);
> > >        srcDirs = scanner.getIncludedDirectories();
> > >
> > >        importPackage(Packages.java.util);
> > >        Arrays.sort(srcDirs);
> > >
> > >        obj = { getIncludedDirectories: function () { return srcDirs;}
> };
> > >        sordidScanner = new
> > > JavaAdapter(org.apache.tools.ant.DirectoryScanner, obj);
> > >        dirset.setupDirectoryScanner(sordidScanner, prj);
> > >        ]]>
> > >      </script>
> > >
> > >
> > > Please excuse my ignorance of JavaScript at this level -- I may be
> doing
> > > something really dumb, and/or I'm unaware of a simpler way to
> accomplish
> > > this.
> > >
> > > Thanks in advance!
> > >
> > >       Ken

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


Mime
View raw message