Author: assaf
Date: Sun Aug 30 00:32:47 2009
New Revision: 809233

URL: http://svn.apache.org/viewvc?rev=809233&view=rev
Log:
Make package(:jar) accessor behavior work when the package was originally 
defined using :file. Fixes BUILDR-304.

Also includes fixes for some packaging specs that relied on the old behavior, 
following Assaf's explicit id recommendation.

Modified:
    buildr/trunk/lib/buildr/packaging/package.rb
    buildr/trunk/spec/java/packaging_spec.rb
    buildr/trunk/spec/packaging/packaging_spec.rb

Modified: buildr/trunk/lib/buildr/packaging/package.rb
URL: 
http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/packaging/package.rb?rev=809233&r1=809232&r2=809233&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/packaging/package.rb (original)
+++ buildr/trunk/lib/buildr/packaging/package.rb Sun Aug 30 00:32:47 2009
@@ -129,6 +129,7 @@
     #   end
     def package(*args)
       spec = Hash === args.last ? args.pop.dup : {}
+      no_options = spec.empty? # since spec is mutated
       if spec[:file]
         rake_check_options spec, :file, :type
         spec[:type] = args.shift || spec[:type] || spec[:file].split('.').last
@@ -147,7 +148,10 @@
           spec = send("package_as_#{spec[:type]}_spec", spec) if 
respond_to?("package_as_#{spec[:type]}_spec")
           file_name = path_to(:target, Artifact.hash_to_file_name(spec))
         end
-        package = packages.find { |pkg| pkg.name == file_name } || 
packager.call(file_name)
+
+        package = (no_options && packages.detect { |pkg| pkg.type == 
spec[:type] }) ||
+          packages.find { |pkg| pkg.name == file_name }                        
     ||
+          packager.call(file_name)
       else
         Buildr.application.deprecated "We changed the way package_as methods 
are implemented.  See the package method documentation for more details."
         file_name ||= path_to(:target, Artifact.hash_to_file_name(spec))

Modified: buildr/trunk/spec/java/packaging_spec.rb
URL: 
http://svn.apache.org/viewvc/buildr/trunk/spec/java/packaging_spec.rb?rev=809233&r1=809232&r2=809233&view=diff
==============================================================================
--- buildr/trunk/spec/java/packaging_spec.rb (original)
+++ buildr/trunk/spec/java/packaging_spec.rb Sun Aug 30 00:32:47 2009
@@ -941,7 +941,7 @@
   it 'should update EJB component classpath to include libraries' do
     define 'foo', :version=>'1.0' do
       package(:ear) << package(:jar, :id=>'lib1') << package(:jar, :id=>'lib2')
-      package(:ear).add :ejb=>package(:jar)
+      package(:ear).add :ejb=>package(:jar, :id=>'foo')
     end
     inspect_classpath 'ejb/foo-1.0.jar' do |classpath|
       classpath.should include('../lib/lib1-1.0.jar', '../lib/lib2-1.0.jar')
@@ -951,7 +951,7 @@
   it 'should update JAR component classpath to include libraries' do
     define 'foo', :version=>'1.0' do
       package(:ear) << package(:jar, :id=>'lib1') << package(:jar, :id=>'lib2')
-      package(:ear).add :jar=>package(:jar)
+      package(:ear).add :jar=>package(:jar, :id=>'foo')
     end
     inspect_classpath 'jar/foo-1.0.jar' do |classpath|
       classpath.should include('../lib/lib1-1.0.jar', '../lib/lib2-1.0.jar')
@@ -961,7 +961,7 @@
   it 'should deal with very long classpaths' do
     define 'foo', :version=>'1.0' do
       20.times { |i| package(:ear) << package(:jar, :id=>"lib#{i}") }
-      package(:ear).add :jar=>package(:jar)
+      package(:ear).add :jar=>package(:jar, :id=>'foo')
     end
     inspect_classpath 'jar/foo-1.0.jar' do |classpath|
       classpath.should include('../lib/lib1-1.0.jar', '../lib/lib2-1.0.jar')

Modified: buildr/trunk/spec/packaging/packaging_spec.rb
URL: 
http://svn.apache.org/viewvc/buildr/trunk/spec/packaging/packaging_spec.rb?rev=809233&r1=809232&r2=809233&view=diff
==============================================================================
--- buildr/trunk/spec/packaging/packaging_spec.rb (original)
+++ buildr/trunk/spec/packaging/packaging_spec.rb Sun Aug 30 00:32:47 2009
@@ -299,6 +299,35 @@
     lambda { task('artifacts').invoke }.should_not raise_error
   end
 
+  describe "existing package access" do
+    it "should return the same instance for identical optionless invocations" 
do
+      define 'foo', :version => '1.0' do
+        package(:zip).should equal(package(:zip))
+      end
+      project('foo').packages.size.should == 1
+    end
+
+    it "should return the exactly matching package identical invocations with 
options" do
+      define 'foo', :version => '1.0' do
+        package(:zip, :id => 'src')
+        package(:zip, :id => 'bin')
+      end
+      project('foo').package(:zip, :id => 'src').should 
equal(project('foo').packages.first)
+      project('foo').package(:zip, :id => 'bin').should 
equal(project('foo').packages.last)
+      project('foo').packages.size.should == 2
+    end
+
+    it "should return the first of the same type for subsequent optionless 
invocations" do
+      define 'foo', :version => '1.0' do
+        package(:zip, :file => 'override.zip')
+        package(:jar, :file => 'another.jar')
+      end
+      project('foo').package(:zip).name.should == 'override.zip'
+      project('foo').package(:jar).name.should == 'another.jar'
+      project('foo').packages.size.should == 2
+    end
+  end
+
 end
 
 


Reply via email to