You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by arijit <gh...@wipro.com> on 2007/06/20 16:19:14 UTC

Using for loop

I am trying to dynamically generate build2.xml by executing build1.xml. I
have a build2_template.xml file and a property file. build2.xml is generated
by reading the build2_template.xml and providing inputs to it through the
property file.

a series of similar code needs to be written in build2.xml file which is a
repititive work. So I was thinking of using some for - loop to write codes
like 

<property name="testN" value="TEST-N"/>

in build2_template.xml

where N could be from 1 to some value which is defined in the property file.
the property file is loaded in build1.xml

Any suggestion ?


-- 
View this message in context: http://www.nabble.com/Using-for-loop-tf3952686.html#a11214404
Sent from the Ant - Users mailing list archive at Nabble.com.


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


Re: AW: Using for loop

Posted by arijit <gh...@wipro.com>.
thanks.. let me try to get the ant-contrib to work..


Knuplesch, Jürgen wrote:
> 
> Use the for Task of the antcontrib Extension for Ant.
> 
> 
> Download: http://sourceforge.net/project/showfiles.php?group_id=36177
> 
> Tasks: http://ant-contrib.sourceforge.net/tasks/tasks/index.html
> 
> You need to add antcontrib using the taskdef task (sometimes more tricky
> than it should), sth. Like:
>   <!-- antcontrib Tasks (z.B. for-Task)-->
>   <taskdef resource="net/sf/antcontrib/antlib.xml">
>     <classpath>
>       <pathelement location="${ant.contrib.jar}" />
>     </classpath>
>   </taskdef>
> 
> 
> Here is a sample from the manual:
> 
> Example:
>   <!-- Reiner Testtarget für den for Task -->
>   <target name="testfor">
>     <for list="a,b,c,d,e,1" param="letter" parallel="false">
>       <sequential>
>         <echo>Letter @{letter}</echo>
>       </sequential>
>     </for>
>   </target> 
> 
> 
> -- 
> Jürgen Knuplesch                    www.icongmbh.de
> icon Systemhaus GmbH                Tel. +49 711 806098-275
> Sophienstraße 40                    
> D-70178 Stuttgart                   Fax. +49 711 806098-299
> 
> Geschäftsführer: Uwe Seltmann
> HRB Stuttgart 17655
> USt-IdNr.: DE 811944121 
> -----Ursprüngliche Nachricht-----
> Von: arijit [mailto:ghosh.arijit@wipro.com] 
> Gesendet: Mittwoch, 20. Juni 2007 16:19
> An: user@ant.apache.org
> Betreff: Using for loop
> 
> 
> I am trying to dynamically generate build2.xml by executing build1.xml. I
> have a build2_template.xml file and a property file. build2.xml is
> generated by reading the build2_template.xml and providing inputs to it
> through the property file.
> 
> a series of similar code needs to be written in build2.xml file which is a
> repititive work. So I was thinking of using some for - loop to write codes
> like 
> 
> <property name="testN" value="TEST-N"/>
> 
> in build2_template.xml
> 
> where N could be from 1 to some value which is defined in the property
> file.
> the property file is loaded in build1.xml
> 
> Any suggestion ?
> 
> 
> --
> View this message in context:
> http://www.nabble.com/Using-for-loop-tf3952686.html#a11214404
> Sent from the Ant - Users mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Using-for-loop-tf3952686.html#a11214910
Sent from the Ant - Users mailing list archive at Nabble.com.


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


AW: Using for loop

Posted by Knuplesch, Jürgen <Ju...@icongmbh.de>.
Use the for Task of the antcontrib Extension for Ant.


Download: http://sourceforge.net/project/showfiles.php?group_id=36177

Tasks: http://ant-contrib.sourceforge.net/tasks/tasks/index.html

You need to add antcontrib using the taskdef task (sometimes more tricky than it should), sth. Like:
  <!-- antcontrib Tasks (z.B. for-Task)-->
  <taskdef resource="net/sf/antcontrib/antlib.xml">
    <classpath>
      <pathelement location="${ant.contrib.jar}" />
    </classpath>
  </taskdef>


Here is a sample from the manual:

Example:
  <!-- Reiner Testtarget für den for Task -->
  <target name="testfor">
    <for list="a,b,c,d,e,1" param="letter" parallel="false">
      <sequential>
        <echo>Letter @{letter}</echo>
      </sequential>
    </for>
  </target> 


-- 
Jürgen Knuplesch                    www.icongmbh.de
icon Systemhaus GmbH                Tel. +49 711 806098-275
Sophienstraße 40                    
D-70178 Stuttgart                   Fax. +49 711 806098-299

Geschäftsführer: Uwe Seltmann
HRB Stuttgart 17655
USt-IdNr.: DE 811944121 
-----Ursprüngliche Nachricht-----
Von: arijit [mailto:ghosh.arijit@wipro.com] 
Gesendet: Mittwoch, 20. Juni 2007 16:19
An: user@ant.apache.org
Betreff: Using for loop


I am trying to dynamically generate build2.xml by executing build1.xml. I have a build2_template.xml file and a property file. build2.xml is generated by reading the build2_template.xml and providing inputs to it through the property file.

a series of similar code needs to be written in build2.xml file which is a repititive work. So I was thinking of using some for - loop to write codes like 

<property name="testN" value="TEST-N"/>

in build2_template.xml

where N could be from 1 to some value which is defined in the property file.
the property file is loaded in build1.xml

Any suggestion ?


--
View this message in context: http://www.nabble.com/Using-for-loop-tf3952686.html#a11214404
Sent from the Ant - Users mailing list archive at Nabble.com.


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


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


Creating a Zip File Programmatically

Posted by Dempsey K Bullock <de...@us.ibm.com>.
I'm fairly new to extending Ant using custom tasks.  I need to create a 
Zip Task programmatically in order to package a set of directories.  So 
far, I've come up with the following.  Basically, I'm creating a Zip Task. 
 Then I'm adding ZipFileSets to the Zip Task.  Everything blows up then I 
try to execute.

Can anyone see any mistakes or point me in the right direction?  Thanks in 
advance!



Zip zip = new Zip();
zip.setDestFile(new File("C:/archive_temp/" + moduleFolderName
                + "App.zip"));

Iterator zipIterator = dependencySet.iterator();

DirectoryScanner ds = new DirectoryScanner();
ds.setBasedir(new File("C:/copy_temp"));
 
while (zipIterator.hasNext()) {
        String modulePath = workspacePath + "\\" + zipIterator.next();
        log("Adding Dependency Folder: " + modulePath);

        ZipFileSet zipFileSet = new ZipFileSet();
        zipFileSet.setDir(new File(modulePath));
        zipFileSet.setDirMode("true");
        zipFileSet.setupDirectoryScanner(ds, this.getProject());
      log(String.valueOf(zipFileSet.hasDirModeBeenSet()));

        zip.addZipfileset(zipFileSet);
}

try {
        zip.executeMain();
} catch (RuntimeException e) {
        e.printStackTrace();
}

The following is the resulting error stack:

java.lang.NullPointerException
at org.apache.tools.ant.types.AbstractFileSet.setupDirectoryScanner(
AbstractFileSet.java:382)
at org.apache.tools.ant.types.AbstractFileSet.getDirectoryScanner(
AbstractFileSet.java:356)
at org.apache.tools.ant.types.ZipFileSet.getDirectoryScanner(
ZipFileSet.java:192)
at org.apache.tools.ant.taskdefs.Zip.grabResources(Zip.java:949)
at org.apache.tools.ant.taskdefs.Zip.getResourcesToAdd(Zip.java:799)
at org.apache.tools.ant.taskdefs.Zip.executeMain(Zip.java:425)
at gov.dcgsa.build.util.ScaDependantUtil.execute(ScaDependantUtil.java:174
)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.tools.ant.Target.performTasks(Target.java:369)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(
DefaultExecutor.java:40)
at 
org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(
EclipseDefaultExecutor.java:32)
at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(
InternalAntRunner.java:423)
at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(
InternalAntRunner.java:137)

Re: Using for loop

Posted by Doug Lochart <dl...@capecomputing.com>.
If you need to generate something dynamically using a template I would 
use Velocity.  It is easy to make a velocity task (I believe by now one 
might exist) and you can use it.  You can feed Velocity a context of 
parameters and spit out a new build file very easily.

just a thought

Peter Reilly wrote:
> Yes,
> with ant1.6's <macrodef> and <import>, and with
> ant-contib's <if>, <var> and <for>, there
> should be no need to generate a build file.
>
> Peter
>
>
> On 6/20/07, Anderson, Rob (Global Trade) <Ro...@nike.com> wrote:
>> Generating a build2.xml file from another build file seems like a weird
>> thing to do. This is probably not the advice you are looking for, but I
>> suggest finding a different way to accomplish your goals. I cannot think
>> of a schenario that would require this, and I think you may be able to
>> accomplish your goals a lot easier.
>>
>> -Rob A
>>
>> > -----Original Message-----
>> > From: arijit [mailto:ghosh.arijit@wipro.com]
>> > Sent: Wednesday, June 20, 2007 7:19 AM
>> > To: user@ant.apache.org
>> > Subject: Using for loop
>> >
>> >
>> > I am trying to dynamically generate build2.xml by executing
>> > build1.xml. I have a build2_template.xml file and a property
>> > file. build2.xml is generated by reading the
>> > build2_template.xml and providing inputs to it through the
>> > property file.
>> >
>> > a series of similar code needs to be written in build2.xml
>> > file which is a repititive work. So I was thinking of using
>> > some for - loop to write codes like
>> >
>> > <property name="testN" value="TEST-N"/>
>> >
>> > in build2_template.xml
>> >
>> > where N could be from 1 to some value which is defined in the
>> > property file.
>> > the property file is loaded in build1.xml
>> >
>> > Any suggestion ?
>> >
>> >
>> > --
>> > View this message in context:
>> > http://www.nabble.com/Using-for-loop-tf3952686.html#a11214404
>> > Sent from the Ant - Users mailing list archive at Nabble.com.
>> >
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> > For additional commands, e-mail: user-help@ant.apache.org
>> >
>> >
>> >
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>


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


Re: Using for loop

Posted by Peter Reilly <pe...@gmail.com>.
Yes,
with ant1.6's <macrodef> and <import>, and with
ant-contib's <if>, <var> and <for>, there
should be no need to generate a build file.

Peter


On 6/20/07, Anderson, Rob (Global Trade) <Ro...@nike.com> wrote:
> Generating a build2.xml file from another build file seems like a weird
> thing to do. This is probably not the advice you are looking for, but I
> suggest finding a different way to accomplish your goals. I cannot think
> of a schenario that would require this, and I think you may be able to
> accomplish your goals a lot easier.
>
> -Rob A
>
> > -----Original Message-----
> > From: arijit [mailto:ghosh.arijit@wipro.com]
> > Sent: Wednesday, June 20, 2007 7:19 AM
> > To: user@ant.apache.org
> > Subject: Using for loop
> >
> >
> > I am trying to dynamically generate build2.xml by executing
> > build1.xml. I have a build2_template.xml file and a property
> > file. build2.xml is generated by reading the
> > build2_template.xml and providing inputs to it through the
> > property file.
> >
> > a series of similar code needs to be written in build2.xml
> > file which is a repititive work. So I was thinking of using
> > some for - loop to write codes like
> >
> > <property name="testN" value="TEST-N"/>
> >
> > in build2_template.xml
> >
> > where N could be from 1 to some value which is defined in the
> > property file.
> > the property file is loaded in build1.xml
> >
> > Any suggestion ?
> >
> >
> > --
> > View this message in context:
> > http://www.nabble.com/Using-for-loop-tf3952686.html#a11214404
> > Sent from the Ant - Users mailing list archive at Nabble.com.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> > For additional commands, e-mail: user-help@ant.apache.org
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>

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


RE: Using for loop

Posted by "Anderson, Rob (Global Trade)" <Ro...@nike.com>.
Generating a build2.xml file from another build file seems like a weird
thing to do. This is probably not the advice you are looking for, but I
suggest finding a different way to accomplish your goals. I cannot think
of a schenario that would require this, and I think you may be able to
accomplish your goals a lot easier.

-Rob A 

> -----Original Message-----
> From: arijit [mailto:ghosh.arijit@wipro.com] 
> Sent: Wednesday, June 20, 2007 7:19 AM
> To: user@ant.apache.org
> Subject: Using for loop
> 
> 
> I am trying to dynamically generate build2.xml by executing 
> build1.xml. I have a build2_template.xml file and a property 
> file. build2.xml is generated by reading the 
> build2_template.xml and providing inputs to it through the 
> property file.
> 
> a series of similar code needs to be written in build2.xml 
> file which is a repititive work. So I was thinking of using 
> some for - loop to write codes like 
> 
> <property name="testN" value="TEST-N"/>
> 
> in build2_template.xml
> 
> where N could be from 1 to some value which is defined in the 
> property file.
> the property file is loaded in build1.xml
> 
> Any suggestion ?
> 
> 
> --
> View this message in context: 
> http://www.nabble.com/Using-for-loop-tf3952686.html#a11214404
> Sent from the Ant - Users mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 
> 
> 


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