I worked on it last night - added some specs. On Sat, Feb 27, 2010 at 05:30, Anders Janmyr <anders.jan...@jayway.com>wrote:
> Ok, thanks, I'll take a look at it. > > Anders > > On Fri, Feb 26, 2010 at 6:58 PM, Alex Boisvert <alex.boisv...@gmail.com> > wrote: > > Looking into it again this morning, I finally found the mysterious cause > of > > the different behavior I was getting earlier. Turns out that Rake's > file() > > method returns a FileTask with a relative path whereas Buildr's file() > > method returns a FileTask with an absolute path. So you get different > > result if you call file() inside or outside of a project and pass this as > > argument to artifact().from(). > > > > I've also fixed the issue about the artifact being re-downloaded every > time > > even if it exists. > > > > For now, I've attached the patch to > > http://issues.apache.org/jira/browse/BUILDR-383. I didn't commit it > yet > > since I can't run the specs successfully on my laptop since my upgrade to > > rubygems 1.3.6. I'll commit once I've tested it on a different system. > > > > Could you give it a try to make sure it addresses your issue? > > > > thanks, > > alex > > > > > > On Fri, Feb 26, 2010 at 3:24 AM, Anders Janmyr <anders.jan...@jayway.com > >wrote: > > > >> Hi, > >> > >> I have made changes to allow you to write code like this > >> > >> google_zip = download "target/google-collect-1.0.zip" => > >> ' > >> http://google-collections.googlecode.com/files/google-collect-1.0.zip' > >> google_jar = > file("target/zip/google-collect-1.0/google-collect-1.0.jar" > >> => > >> unzip('target/zip'=>google_zip)) > >> google_artifact = > >> artifact('google:google-collect:jar:1.0').from(google_jar) > >> > >> define 'core' do > >> compile.with 'commons-lang:commons-lang:jar:2.4', google_artifact > >> package :jar > >> end > >> > >> instead of code like this. > >> > >> google_artifact = artifact('google:google-collect:jar:1.0').tap do |a| > >> unless a.exist? > >> google_zip = download "target/google-collect-1.0.zip" => > >> ' > >> http://google-collections.googlecode.com/files/google-collect-1.0.zip' > >> google_jar = > >> file("target/zip/google-collect-1.0/google-collect-1.0.jar" => > >> unzip('target/zip'=>google_zip)) > >> a.from(google_jar) > >> end > >> end > >> > >> > >> I cannot however get the tests to work the way I want. > >> > >> > >> The patch is below, I'll attach it to an issue, if you are interested > >> in it. The failing tests are also in the patch. > >> > >> Anders > >> > >> From 5b0247315fceadb544af92812c269a0fa417c5b3 Mon Sep 17 00:00:00 2001 > >> From: Anders Janmyr <anders.jan...@jayway.com> > >> Date: Fri, 26 Feb 2010 12:12:48 +0100 > >> Subject: [PATCH] artifact.from should only be invoked when needed. > >> > >> * It is only needed if the file it is dependent on is newer > >> or if the artifact does not exist at all. > >> * If the artifact exists, but the dependent file does not, > >> skip the dependency. > >> --- > >> lib/buildr/packaging/artifact.rb | 26 ++++++++++++++++---------- > >> spec/packaging/artifact_spec.rb | 17 +++++++++++++++++ > >> 2 files changed, 33 insertions(+), 10 deletions(-) > >> > >> diff --git a/lib/buildr/packaging/artifact.rb > >> b/lib/buildr/packaging/artifact.rb > >> index e3ee045..6d3df6d 100644 > >> --- a/lib/buildr/packaging/artifact.rb > >> +++ b/lib/buildr/packaging/artifact.rb > >> @@ -315,6 +315,10 @@ module Buildr > >> end > >> end > >> > >> + def up_to_date_compared_to?(path) > >> + File.exists?(path) ? test(?<, path, name) : File.exist?(name) > >> + end > >> + > >> # :call-seq: > >> # from(path) => self > >> # > >> @@ -324,16 +328,18 @@ module Buildr > >> # See also Buildr#install and Buildr#upload. > >> def from(path) > >> path = File.expand_path(path.to_s) > >> - enhance [path] do > >> - mkpath File.dirname(name) > >> - pom.invoke unless type == :pom > >> - cp path, name > >> - info "Installed #{path} as #{to_spec}" > >> - end > >> - unless type == :pom > >> - pom.enhance do > >> - mkpath File.dirname(pom.name) > >> - File.open(pom.name, 'w') { |file| file.write pom.pom_xml } > >> + unless up_to_date_compared_to?(path) > >> + enhance [path] do > >> + mkpath File.dirname(name) > >> + pom.invoke unless type == :pom > >> + cp path, name > >> + info "Installed #{path} as #{to_spec}" > >> + end > >> + unless type == :pom > >> + pom.enhance do > >> + mkpath File.dirname(pom.name) > >> + File.open(pom.name, 'w') { |file| file.write pom.pom_xml } > >> + end > >> end > >> end > >> self > >> diff --git a/spec/packaging/artifact_spec.rb > >> b/spec/packaging/artifact_spec.rb > >> index 42e7b9c..45839f2 100644 > >> --- a/spec/packaging/artifact_spec.rb > >> +++ b/spec/packaging/artifact_spec.rb > >> @@ -429,6 +429,23 @@ describe Buildr, '#artifact' do > >> lambda { artifact.invoke }.should change { > >> File.exist?(artifact.to_s) }.to(true) > >> end > >> > >> + > >> + it 'should trigger from dependency if not installed' do > >> + file = 'test.jar' > >> + touch file > >> + artifact = artifact('group:id:jar:1.0').from(file) > >> + lambda { artifact.invoke }.should change { > >> artifact.up_to_date_compared_to?(file) }.to(true) > >> + end > >> + > >> + it 'should not trigger from dependency if installed' do > >> + file = 'test.jar' > >> + touch file > >> + artifact = artifact('group:id:jar:1.0').from(file) > >> + lambda { artifact.invoke }.should change { > >> artifact.up_to_date_compared_to?(file) }.to(true) > >> + lambda { artifact.invoke }.should_not change { > >> artifact.up_to_date_compared_to?(file) }.to(true) > >> + end > >> + > >> + > >> it 'should reference artifacts defined on build.yaml by using ruby > >> symbols' do > >> write 'build.yaml', <<-YAML > >> artifacts: > >> -- > >> 1.6.6 > >> > >> > >> > >> > >> -- > >> http://anders.janmyr.com/ > >> > > > > > > -- > http://anders.janmyr.com/ >