|
View:
New views
7 Messages
—
Rating Filter:
Alert me
|
|
|
factoring out commonality in sequences of tasksSuppose I have an operation which deploys files and I have the option of deploying the files by copying them and deploying using symlinks:
<target name="deploy-using-copy"> <task1> <copy-files-2> <task3> <copy-files-4> <task5> </target> <target name="deploy-using-link"> <task1> <link-files-2> <task3> <link-files-4> <task5> </target> What's the best way to factor out the commonality of these two targets? Note that <task1>, <task3>, etc. are going to be sequence of tasks and not just a single task element. (Is it possible to define a task which is a sequence of tasks?) Thanks, ER |
|
|
Re: factoring out commonality in sequences of tasksjscripter schrieb am 22.06.2009 um 13:46:19 (-0700):
> > Suppose I have an operation which deploys files and I have the option > of deploying the files by copying them and deploying using symlinks: > > <target name="deploy-using-copy"> > <task1> > <copy-files-2> > <task3> > <copy-files-4> > <task5> > </target> > > <target name="deploy-using-link"> > <task1> > <link-files-2> > <task3> > <link-files-4> > <task5> > </target> > > What's the best way to factor out the commonality of these two > targets? > > Note that <task1>, <task3>, etc. are going to be sequence of tasks and > not just a single task element. > (Is it possible to define a task which is a sequence of tasks?) Would target/@depends work for you? You would then factor out your series of tasks to a different target. Isn't a target just a processing unit placed in the dependency graph? <target name="deploy-using-copy" depends="trg1,trg3,trg5"> ... <target name="deploy-using-link" depends="trg1,trg3,trg5"> ... Michael Ludwig --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... |
|
|
Re: factoring out commonality in sequences of tasksI need to preserve the execution order of the tasks, so I don't think that would work. |
|
|
Re: factoring out commonality in sequences of tasksjscripter schrieb am 22.06.2009 um 14:16:24 (-0700):
> > <target name="deploy-using-copy" depends="trg1,trg3,trg5"> > > ... > > > > <target name="deploy-using-link" depends="trg1,trg3,trg5"> > > ... > I need to preserve the execution order of the tasks, so I don't think > that would work. From a recent post of David Weintraub: | You say that B depends upon A, and C depends upon A and that A depends | upon D, and both Ant and Make will calculate out the build order of | your components. If you make a change (Say B now depends upon both A | and C, Ant [...] will adjust the build without major rewriting of your | build script. This suggests you could guarantee execution order by setting up the dependency matrix accordingly. Let your main tasks depend on trg5, which in turn depends on trg3, which in turn depends on trg1. Also, take a look at the manual, which has this example: <target name="A"/> <target name="B" depends="A"/> <target name="C" depends="B"/> <target name="D" depends="C,B,A"/> Suppose we want to execute target D. From its depends attribute, you might think that first target C, then B and then A is executed. Wrong! C depends on B, and B depends on A, so first A is executed, then B, then C, and finally D. http://ant.apache.org/manual/using.html#targets Michael Ludwig --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... |
|
|
Re: factoring out commonality in sequences of tasksThe problem is that task3 has to come after copy-files-2 OR link-files-2 depending on which one I want to execute. So, to use an abbreviated example, I can get most of the execution order specified with the following declarations: <target name="deploy-using-copy" depends="target-1,target-copy-2,target-3">...</target> <target name="deploy-using-link" depends="target-1,target-link-2,target-3">...</target> <target name="target-copy-2" depends=target-1">...</target> <target name="target-link-2" depends="target-1">...</target> but then how do I set up the depends for target-3? |
|
|
Re: factoring out commonality in sequences of tasksThere are several things you can use:
One is the <defmacro> command. If <task1> is actually composed of multiple tasks, then the Macro function might be the way to go. The other is to look into the AntContrib package <http://ant-contrib.sourceforge.net/ant-contrib/manual/#install> and use the <if><then> tasks in the antContrib package: <http://ant-contrib.sourceforge.net/ant-contrib/manual/tasks/> <target name="deploy"> <task1/> <if> <equal arg1="${deployType}" arg2="copy"/> <then> <copy-files-2/> </then> <else> <link-files-2/> </else> </if> <task 3/> <if> <equals arg1="${deployType}" arg2="copy"/> <then> <copy-files-4/> </then> <else> <link-files-4/> </else> </if> <task-5/> </target> Another possibility is to use <antcall> to call the tasks in the order you want: <target name="deploy-with-copy"> <antcall target="task1"/> <antcall target="copy-files-2"/> <antcall target="task3"/> <antcall target="copy-files-4/> </target> Infact, what is the difference between copy/link task #2 and copy/link task #5? Do they do the same thing, but maybe with different filesets? What you might want to do is use defmacro and pass the difference between the two tasks as parameters. Then, you could use the <if> task to simply separate out the link vs. copy stuff. You have a single macro to do the copy/link, and you simply pass along the information you need to copy or link to that macro. That way, your target looks like this: <target name="deploy"> <task1/> <copy.macro deployType="${deploy.type}> <files-to-copy-or-link> <fileset dir="${foo}"/> </files-to-copy-or-link/> </copy.macro> <task3/> <copy.macro deployType="${deploy.type}"> <files-to-copy-or-link> <fileset dir="${bar}"/> </files-to-copy-or-link> </copy.macro> <task5/> </target> <macrodef name="copy.macro"> <attribute name="deployType" required="true"/> <element name="files-to-copy-or-link" /> <sequential> <if> <equals arg1="@{deployType}" arg2="copy"/> <then> <copy file tasks/> </then> <else> <link file tasks/> </else> </if> </sequencial> </macrodef> On Mon, Jun 22, 2009 at 4:46 PM, jscripter<pc88mxer@...> wrote: > > Suppose I have an operation which deploys files and I have the option of > deploying the files by copying them and deploying using symlinks: > > <target name="deploy-using-copy"> > <task1> > <copy-files-2> > <task3> > <copy-files-4> > <task5> > </target> > > <target name="deploy-using-link"> > <task1> > <link-files-2> > <task3> > <link-files-4> > <task5> > </target> > > What's the best way to factor out the commonality of these two targets? > > Note that <task1>, <task3>, etc. are going to be sequence of tasks and not > just a single task element. > (Is it possible to define a task which is a sequence of tasks?) > > Thanks, > ER > > > > -- > View this message in context: http://www.nabble.com/factoring-out-commonality-in-sequences-of-tasks-tp24155135p24155135.html > Sent from the Ant - Users mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@... > For additional commands, e-mail: user-help@... > > -- David Weintraub qazwart@... --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... |
|
|
Re: factoring out commonality in sequences of tasksThanks for pointing out defmacro and antcall. Looks like they could help me out with this problem. ER |
| Free embeddable forum powered by Nabble | Forum Help |