You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@buildr.apache.org by Andrew Moore <rp...@gmail.com> on 2009/05/19 00:38:19 UTC
Running code after a package task has completed
Hi, I'm struggling to understand how I can run some ruby code after I package
a zip file.
Here is a paired down version of my sub-project definition:
def 'release' do
package(:zip, :file=>_('target/mypackage.zip')).enhance do |zip, file|
run_BEFORE_packaging()
zip.path('mydeploydir/one').include
project('proj:myjar').package(:jar)
zip.path('mydeploydir/two').include 'mytextfiles/*.txt'
zip.path('mydeploydir/three').include
'myotherfiles/fromthisdir/*.pdf'
run_AFTER_packaging()
end
end
I'm not understanding how to invoke my 'run_AFTER_packaging' method after
all my various files are included in my zip. My 'run_BEFORE_packaging'
method runs, followed by my 'run_AFTER_packaging' method, which is then
followed by the actual execution of the package task... (in which all the
various files get added to the zip).
I'm not very familiar with Ruby or Rake... and I've tried searching through
all the Buildr and Rake docs and tutorials I can find. I'm assuming there is
some sort of basic concept I'm not grasping, the docs and tutorials gloss
over something basic or the way of doing this isn't intuitive enough.
Any help in showing me what to do to accomplish this, as well as
enlightening me on what concept I'm missing is much appreciated.
Regards,
Andrew
--
View this message in context: http://n2.nabble.com/Running-code-after-a-package-task-has-completed-tp2936195p2936195.html
Sent from the Apache Buildr - User mailing list archive at Nabble.com.
Re: Running code after a package task has completed
Posted by Andrew Moore <an...@redprairie.com>.
Yeah, that is strange... it seems like that should work.
I don't see why it didn't for me... I ran it a couple times to make
sure that was the case.
I do finally have it working. The buildfile looks something like this
now:
define 'release' do
before_task = task do
puts '[BEFORE]'
end
package(:zip, :file=>_('target/mypackage.zip')).enhance
[before_task] do |zip|
zip.path('mydeploydir/one').include
project('proj:myjar').package(:jar)
zip.path('mydeploydir/two').include 'mytextfiles/*.txt'
zip.path('mydeploydir/three').include 'myotherfiles/
fromthisdir/*.pdf'
zip.enhance do
puts '[AFTER]'
end
end
end
Not sure if having the enhance for the main package task and inside
the package task does the trick?
Thanks for all your help. I finally have it working!
~ Andrew
On May 18, 2009, at 5:34 PM, Alex Boisvert wrote:
> Strange. Here's the Buildfile I used,
>
> repositories.remote << "http://www.ibiblio.org/maven2/"
>
> define "foo" do
> project.version = "1.0"
> project.group = "com.example"
>
> task 'before' do
> puts "BEFORE"
> end
>
> task 'package' => 'before'
>
> package(:zip, :file => 'target/foo.zip').tap do |zip|
> zip.path('/').include 'foo.txt'
> zip.enhance do
> puts "AFTER"
> end
> end
>
> end
>
> and the output,
>
> boisvert@sixtine:~/tmp/before_after$ buildr clean package
> (in /home/boisvert/tmp/before_after, development)
> Cleaning foo
> Building foo
> Compiling foo into /home/boisvert/tmp/before_after/target/classes
> Packaging foo
> BEFORE
> Packaging foo.zip
> AFTER
> Running integration tests...
> Completed in 0.388s
>
> and the resulting archive looks good,
>
> boisvert@sixtine:~/tmp/before_after$ unzip -l target/foo.zip
> Archive: target/foo.zip
> Length Date Time Name
> -------- ---- ---- ----
> 0 05-18-09 16:32 foo.txt
> -------- -------
> 0 1 file
>
> alex
>
> On Mon, May 18, 2009 at 3:38 PM, Andrew Moore <rp.andrew.moore@gmail.com
> >wrote:
>
>>
>> Hi, I'm struggling to understand how I can run some ruby code after I
>> package
>> a zip file.
>>
>> Here is a paired down version of my sub-project definition:
>>
>>
>> def 'release' do
>> package(:zip, :file=>_('target/mypackage.zip')).enhance do |zip,
>> file|
>> run_BEFORE_packaging()
>>
>> zip.path('mydeploydir/one').include
>> project('proj:myjar').package(:jar)
>> zip.path('mydeploydir/two').include 'mytextfiles/*.txt'
>> zip.path('mydeploydir/three').include
>> 'myotherfiles/fromthisdir/*.pdf'
>>
>> run_AFTER_packaging()
>> end
>> end
>>
>>
>>
>> I'm not understanding how to invoke my 'run_AFTER_packaging' method
>> after
>> all my various files are included in my zip. My
>> 'run_BEFORE_packaging'
>> method runs, followed by my 'run_AFTER_packaging' method, which is
>> then
>> followed by the actual execution of the package task... (in which
>> all the
>> various files get added to the zip).
>>
>> I'm not very familiar with Ruby or Rake... and I've tried searching
>> through
>> all the Buildr and Rake docs and tutorials I can find. I'm assuming
>> there
>> is
>> some sort of basic concept I'm not grasping, the docs and tutorials
>> gloss
>> over something basic or the way of doing this isn't intuitive enough.
>>
>> Any help in showing me what to do to accomplish this, as well as
>> enlightening me on what concept I'm missing is much appreciated.
>>
>> Regards,
>>
>> Andrew
>>
>>
>> --
>> View this message in context:
>> http://n2.nabble.com/Running-code-after-a-package-task-has-completed-tp2936195p2936195.html
>> Sent from the Apache Buildr - User mailing list archive at
>> Nabble.com.
>>
>>
Re: Running code after a package task has completed
Posted by Alex Boisvert <bo...@intalio.com>.
Strange. Here's the Buildfile I used,
repositories.remote << "http://www.ibiblio.org/maven2/"
define "foo" do
project.version = "1.0"
project.group = "com.example"
task 'before' do
puts "BEFORE"
end
task 'package' => 'before'
package(:zip, :file => 'target/foo.zip').tap do |zip|
zip.path('/').include 'foo.txt'
zip.enhance do
puts "AFTER"
end
end
end
and the output,
boisvert@sixtine:~/tmp/before_after$ buildr clean package
(in /home/boisvert/tmp/before_after, development)
Cleaning foo
Building foo
Compiling foo into /home/boisvert/tmp/before_after/target/classes
Packaging foo
BEFORE
Packaging foo.zip
AFTER
Running integration tests...
Completed in 0.388s
and the resulting archive looks good,
boisvert@sixtine:~/tmp/before_after$ unzip -l target/foo.zip
Archive: target/foo.zip
Length Date Time Name
-------- ---- ---- ----
0 05-18-09 16:32 foo.txt
-------- -------
0 1 file
alex
On Mon, May 18, 2009 at 3:38 PM, Andrew Moore <rp...@gmail.com>wrote:
>
> Hi, I'm struggling to understand how I can run some ruby code after I
> package
> a zip file.
>
> Here is a paired down version of my sub-project definition:
>
>
> def 'release' do
> package(:zip, :file=>_('target/mypackage.zip')).enhance do |zip, file|
> run_BEFORE_packaging()
>
> zip.path('mydeploydir/one').include
> project('proj:myjar').package(:jar)
> zip.path('mydeploydir/two').include 'mytextfiles/*.txt'
> zip.path('mydeploydir/three').include
> 'myotherfiles/fromthisdir/*.pdf'
>
> run_AFTER_packaging()
> end
> end
>
>
>
> I'm not understanding how to invoke my 'run_AFTER_packaging' method after
> all my various files are included in my zip. My 'run_BEFORE_packaging'
> method runs, followed by my 'run_AFTER_packaging' method, which is then
> followed by the actual execution of the package task... (in which all the
> various files get added to the zip).
>
> I'm not very familiar with Ruby or Rake... and I've tried searching through
> all the Buildr and Rake docs and tutorials I can find. I'm assuming there
> is
> some sort of basic concept I'm not grasping, the docs and tutorials gloss
> over something basic or the way of doing this isn't intuitive enough.
>
> Any help in showing me what to do to accomplish this, as well as
> enlightening me on what concept I'm missing is much appreciated.
>
> Regards,
>
> Andrew
>
>
> --
> View this message in context:
> http://n2.nabble.com/Running-code-after-a-package-task-has-completed-tp2936195p2936195.html
> Sent from the Apache Buildr - User mailing list archive at Nabble.com.
>
>
Re: Running code after a package task has completed
Posted by Andrew Moore <an...@redprairie.com>.
From what I can tell... that seems to have the same effect.
If my before method prints out '[BEFORE]' and my after method prints
out '[AFTER]' then I get the following trace when I do a clean, build,
and package:
** Invoke proj:release:filter (first_time)
** Execute proj:release:filter
[BEFORE]
** Invoke /Users/myuser/source/trunk/release/target/mypackage.zip
(first_time)
.
. (a bunch of 'invoke' statements are here)
.
** Execute /Users/myuser/source/trunk/release/target/mypackage.zip
[AFTER]
Adding mypackage/one/myjar.jar
Adding mypackage/two/file_1.txt
Adding mypackage/two/file_2.txt
Adding mypackage/two/file_3.txt
.
. (a bunch of 'Adding' statements are here)
.
** Execute proj:release:package
** Invoke proj:release:check (first_time)
** Execute proj:release:check
.
. (Buildr continues on...)
.
The adding of my files to the package is still happening after my
'after' method.
Is this a bug maybe? I'm running Buildr 1.3.3. Is it different somehow
when trying this from within a subproject? (In my code I'm defining/
running all of this from within the 'release' sub project as opposed
to in a function or task).
Thanks for your quick response...
Regards,
Andrew
On May 18, 2009, at 4:53 PM, Alex Boisvert wrote:
> Hi Andrew,
>
> To run something before another task, you add a dependency, such as:
>
> task 'before' do
> run_BEFORE_packaging()
> end
>
> task 'package' => 'before'
>
> and to do something after, you can use enhance (as you did) but
> you'll want
> to use 'tap' to configure the package(:zip) task like this:
>
> package(:zip, :file=>_('target/mypackage.zip')).tap do |zip|
> zip.path('mydeploydir/one').include
> project('proj:myjar').package(:jar)
> zip.path('mydeploydir/two').include 'mytextfiles/*.txt'
> zip.path('mydeploydir/three').include 'myotherfiles/fromthisdir/
> *.pdf'
> zip.enhance do
> run_AFTER_packaging()
> end
> end
>
> alex
>
>
> package(:zip, :file=>_('target/mypackage.zip')).enhance do |zip,
> file|
>>
>> run_BEFORE_packaging()
>>
>> zip.path('mydeploydir/one').include
>> project('proj:myjar').package(:jar)
>> zip.path('mydeploydir/two').include 'mytextfiles/*.txt'
>> zip.path('mydeploydir/three').include
>> 'myotherfiles/fromthisdir/*.pdf'
>>
>> run_AFTER_packaging()
>> end
>
>
> On Mon, May 18, 2009 at 3:38 PM, Andrew Moore <rp.andrew.moore@gmail.com
> >wrote:
>
>>
>> Hi, I'm struggling to understand how I can run some ruby code after I
>> package
>> a zip file.
>>
>> Here is a paired down version of my sub-project definition:
>>
>>
>> def 'release' do
>> package(:zip, :file=>_('target/mypackage.zip')).enhance do |zip,
>> file|
>> run_BEFORE_packaging()
>>
>> zip.path('mydeploydir/one').include
>> project('proj:myjar').package(:jar)
>> zip.path('mydeploydir/two').include 'mytextfiles/*.txt'
>> zip.path('mydeploydir/three').include
>> 'myotherfiles/fromthisdir/*.pdf'
>>
>> run_AFTER_packaging()
>> end
>> end
>>
>>
>>
>> I'm not understanding how to invoke my 'run_AFTER_packaging' method
>> after
>> all my various files are included in my zip. My
>> 'run_BEFORE_packaging'
>> method runs, followed by my 'run_AFTER_packaging' method, which is
>> then
>> followed by the actual execution of the package task... (in which
>> all the
>> various files get added to the zip).
>>
>> I'm not very familiar with Ruby or Rake... and I've tried searching
>> through
>> all the Buildr and Rake docs and tutorials I can find. I'm assuming
>> there
>> is
>> some sort of basic concept I'm not grasping, the docs and tutorials
>> gloss
>> over something basic or the way of doing this isn't intuitive enough.
>>
>> Any help in showing me what to do to accomplish this, as well as
>> enlightening me on what concept I'm missing is much appreciated.
>>
>> Regards,
>>
>> Andrew
>>
>>
>> --
>> View this message in context:
>> http://n2.nabble.com/Running-code-after-a-package-task-has-completed-tp2936195p2936195.html
>> Sent from the Apache Buildr - User mailing list archive at
>> Nabble.com.
>>
>>
Re: Running code after a package task has completed
Posted by Assaf Arkin <ar...@intalio.com>.
On Mon, May 18, 2009 at 3:53 PM, Alex Boisvert <bo...@intalio.com> wrote:
> Hi Andrew,
>
> To run something before another task, you add a dependency, such as:
>
> task 'before' do
> run_BEFORE_packaging()
> end
>
> task 'package' => 'before'
>
> and to do something after, you can use enhance (as you did) but you'll want
> to use 'tap' to configure the package(:zip) task like this:
>
> package(:zip, :file=>_('target/mypackage.zip')).tap do |zip|
> zip.path('mydeploydir/one').include project('proj:myjar').package(:jar)
> zip.path('mydeploydir/two').include 'mytextfiles/*.txt'
> zip.path('mydeploydir/three').include 'myotherfiles/fromthisdir/*.pdf'
> zip.enhance do
> run_AFTER_packaging()
> end
> end
>
package(:zip, :file=>_('target/mypackage.zip').enhance do |task|
task.enhance do
run_AFTER_packaging()
end
end
>
>
> alex
>
>
> package(:zip, :file=>_('target/mypackage.zip')).enhance do |zip, file|
> >
> > run_BEFORE_packaging()
> >
> > zip.path('mydeploydir/one').include
> > project('proj:myjar').package(:jar)
> > zip.path('mydeploydir/two').include 'mytextfiles/*.txt'
> > zip.path('mydeploydir/three').include
> > 'myotherfiles/fromthisdir/*.pdf'
> >
> > run_AFTER_packaging()
> > end
>
>
> On Mon, May 18, 2009 at 3:38 PM, Andrew Moore <rp.andrew.moore@gmail.com
> >wrote:
>
> >
> > Hi, I'm struggling to understand how I can run some ruby code after I
> > package
> > a zip file.
> >
> > Here is a paired down version of my sub-project definition:
> >
> >
> > def 'release' do
> > package(:zip, :file=>_('target/mypackage.zip')).enhance do |zip, file|
> > run_BEFORE_packaging()
> >
> > zip.path('mydeploydir/one').include
> > project('proj:myjar').package(:jar)
> > zip.path('mydeploydir/two').include 'mytextfiles/*.txt'
> > zip.path('mydeploydir/three').include
> > 'myotherfiles/fromthisdir/*.pdf'
> >
> > run_AFTER_packaging()
> > end
> > end
> >
> >
> >
> > I'm not understanding how to invoke my 'run_AFTER_packaging' method after
> > all my various files are included in my zip. My 'run_BEFORE_packaging'
> > method runs, followed by my 'run_AFTER_packaging' method, which is then
> > followed by the actual execution of the package task... (in which all the
> > various files get added to the zip).
> >
> > I'm not very familiar with Ruby or Rake... and I've tried searching
> through
> > all the Buildr and Rake docs and tutorials I can find. I'm assuming there
> > is
> > some sort of basic concept I'm not grasping, the docs and tutorials gloss
> > over something basic or the way of doing this isn't intuitive enough.
> >
> > Any help in showing me what to do to accomplish this, as well as
> > enlightening me on what concept I'm missing is much appreciated.
> >
> > Regards,
> >
> > Andrew
> >
> >
> > --
> > View this message in context:
> >
> http://n2.nabble.com/Running-code-after-a-package-task-has-completed-tp2936195p2936195.html
> > Sent from the Apache Buildr - User mailing list archive at Nabble.com.
> >
> >
>
Re: Running code after a package task has completed
Posted by Alex Boisvert <bo...@intalio.com>.
Hi Andrew,
To run something before another task, you add a dependency, such as:
task 'before' do
run_BEFORE_packaging()
end
task 'package' => 'before'
and to do something after, you can use enhance (as you did) but you'll want
to use 'tap' to configure the package(:zip) task like this:
package(:zip, :file=>_('target/mypackage.zip')).tap do |zip|
zip.path('mydeploydir/one').include project('proj:myjar').package(:jar)
zip.path('mydeploydir/two').include 'mytextfiles/*.txt'
zip.path('mydeploydir/three').include 'myotherfiles/fromthisdir/*.pdf'
zip.enhance do
run_AFTER_packaging()
end
end
alex
package(:zip, :file=>_('target/mypackage.zip')).enhance do |zip, file|
>
> run_BEFORE_packaging()
>
> zip.path('mydeploydir/one').include
> project('proj:myjar').package(:jar)
> zip.path('mydeploydir/two').include 'mytextfiles/*.txt'
> zip.path('mydeploydir/three').include
> 'myotherfiles/fromthisdir/*.pdf'
>
> run_AFTER_packaging()
> end
On Mon, May 18, 2009 at 3:38 PM, Andrew Moore <rp...@gmail.com>wrote:
>
> Hi, I'm struggling to understand how I can run some ruby code after I
> package
> a zip file.
>
> Here is a paired down version of my sub-project definition:
>
>
> def 'release' do
> package(:zip, :file=>_('target/mypackage.zip')).enhance do |zip, file|
> run_BEFORE_packaging()
>
> zip.path('mydeploydir/one').include
> project('proj:myjar').package(:jar)
> zip.path('mydeploydir/two').include 'mytextfiles/*.txt'
> zip.path('mydeploydir/three').include
> 'myotherfiles/fromthisdir/*.pdf'
>
> run_AFTER_packaging()
> end
> end
>
>
>
> I'm not understanding how to invoke my 'run_AFTER_packaging' method after
> all my various files are included in my zip. My 'run_BEFORE_packaging'
> method runs, followed by my 'run_AFTER_packaging' method, which is then
> followed by the actual execution of the package task... (in which all the
> various files get added to the zip).
>
> I'm not very familiar with Ruby or Rake... and I've tried searching through
> all the Buildr and Rake docs and tutorials I can find. I'm assuming there
> is
> some sort of basic concept I'm not grasping, the docs and tutorials gloss
> over something basic or the way of doing this isn't intuitive enough.
>
> Any help in showing me what to do to accomplish this, as well as
> enlightening me on what concept I'm missing is much appreciated.
>
> Regards,
>
> Andrew
>
>
> --
> View this message in context:
> http://n2.nabble.com/Running-code-after-a-package-task-has-completed-tp2936195p2936195.html
> Sent from the Apache Buildr - User mailing list archive at Nabble.com.
>
>