buildr-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Anders Janmyr <anders.jan...@jayway.com>
Subject Patch for artifact.from
Date Fri, 26 Feb 2010 11:24:02 GMT
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.janmyr@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/

Mime
View raw message