Author: boisvert
Date: Sat Oct 23 15:19:49 2010
New Revision: 1026628

URL: http://svn.apache.org/viewvc?rev=1026628&view=rev
Log:
BUILDR-543 POMs are installed and uploaded twice when using artifacts with 
classifier

Note:  I've changed things such that Buildr will only implicitly install and
upload poms along with the main artifact (i.e., an artifact without classifier).
For the cases where only artifacts with classifiers are used, the POM must be
explicitly installed/uploaded if desired.

Modified:
    buildr/trunk/CHANGELOG
    buildr/trunk/lib/buildr/packaging/artifact.rb
    buildr/trunk/spec/packaging/artifact_spec.rb

Modified: buildr/trunk/CHANGELOG
URL: 
http://svn.apache.org/viewvc/buildr/trunk/CHANGELOG?rev=1026628&r1=1026627&r2=1026628&view=diff
==============================================================================
--- buildr/trunk/CHANGELOG (original)
+++ buildr/trunk/CHANGELOG Sat Oct 23 15:19:49 2010
@@ -1,8 +1,10 @@
 1.4.4 (Pending)
 * Added:  BUILDR-537 Shell tasks should use JAVA_OPTS by default
 * Added:  BUILDR-538 Shell tasks should support passing :java_args
-* Fixed:  BUILDR-542 Release task:  SVN tagging fails if parent tag
-          directory does not exist yet (Gerolf Seitz)
+* Fixed:  BUILDR-542 Release task:  SVN tagging fails if parent tag directory
+          does not exist yet (Gerolf Seitz)
+* Fixed:  BUILDR-543 POMs are installed and uploaded twice when using artifacts
+          with classifier
 
 1.4.3 (2010-10-15)
 * Added:  BUILDR-514 New 'run' local task. 
http://buildr.apache.org/more_stuff.html#run

Modified: buildr/trunk/lib/buildr/packaging/artifact.rb
URL: 
http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/packaging/artifact.rb?rev=1026628&r1=1026627&r2=1026628&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/packaging/artifact.rb (original)
+++ buildr/trunk/lib/buildr/packaging/artifact.rb Sat Oct 23 15:19:49 2010
@@ -160,11 +160,11 @@ module Buildr
     def install
       invoke
       in_local_repository = Buildr.repositories.locate(self)
+      if pom && pom != self && classifier.nil?
+        pom.invoke
+        pom.install
+      end
       if name != in_local_repository
-        if pom && pom != self
-          pom.invoke
-          pom.install
-        end
         mkpath File.dirname(in_local_repository)
         cp name, in_local_repository, :preserve => false
         info "Installed #{name} to #{in_local_repository}"
@@ -174,7 +174,7 @@ module Buildr
     def uninstall
       installed = Buildr.repositories.locate(self)
       rm installed if File.exist?(installed)
-      pom.uninstall if pom && pom != self
+      pom.uninstall if pom && pom != self && classifier.nil?
     end
 
     # :call-seq:
@@ -208,7 +208,7 @@ module Buildr
 
       unless task = Buildr.application.lookup(uri+path)
         deps = [self]
-        deps << pom.upload_task( upload_to ) if pom && pom != self
+        deps << pom.upload_task( upload_to ) if pom && pom != self && 
classifier.nil?
 
         task = Rake::Task.define_task uri + path => deps do
           # Upload artifact relative to base URL, need to create path before 
uploading.
@@ -353,7 +353,7 @@ module Buildr
           if download_needed? task
             info "Downloading #{to_spec}"
             download
-            pom.invoke rescue nil if pom && pom != self
+            pom.invoke rescue nil if pom && pom != self && classifier.nil?
           end
         end
       end
@@ -869,16 +869,15 @@ module Buildr
   #   install artifact('group:id:jar:1.0').from('some_jar.jar')
   #   $ buildr install
   def install(*args, &block)
-    artifacts = artifacts(args)
+    artifacts = artifacts(args).uniq
     raise ArgumentError, 'This method can only install artifacts' unless 
artifacts.all? { |f| f.respond_to?(:to_spec) }
-    all = (artifacts + artifacts.map { |artifact| artifact.pom }).uniq
     task('install').tap do |install|
-      install.enhance(all) do
-        all.each(&:install)
+      install.enhance(artifacts) do
+        artifacts.each(&:install)
       end
       install.enhance &block if block
       task('uninstall') do
-        all.map(&:to_s ).each { |file| rm file if File.exist?(file) }
+        artifacts.map(&:to_s ).each { |file| rm file if File.exist?(file) }
       end
     end
   end

Modified: buildr/trunk/spec/packaging/artifact_spec.rb
URL: 
http://svn.apache.org/viewvc/buildr/trunk/spec/packaging/artifact_spec.rb?rev=1026628&r1=1026627&r2=1026628&view=diff
==============================================================================
--- buildr/trunk/spec/packaging/artifact_spec.rb (original)
+++ buildr/trunk/spec/packaging/artifact_spec.rb Sat Oct 23 15:19:49 2010
@@ -252,7 +252,7 @@ describe Repositories, 'remote' do
 
   it 'should support artifact classifier' do
     repositories.remote = 'http://example.com'
-    URI.should_receive(:download).twice.and_return { |uri, target, options| 
write target }
+    URI.should_receive(:download).once.and_return { |uri, target, options| 
write target }
     lambda { artifact('com.example:library:jar:all:2.0').invoke }.
       should change { File.exist?(File.join(repositories.local, 
'com/example/library/2.0/library-2.0-all.jar')) }.to(true)
   end
@@ -752,13 +752,22 @@ describe Buildr, '#install' do
     snapshot.invoke
   end
 
-  it 'should install POM alongside artifact' do
+  it 'should install POM alongside artifact (if artifact has no classifier)' do
     pom = artifact(@spec).pom
     write @file
     install artifact(@spec).from(@file)
     lambda { install.invoke }.should change { 
File.exist?(repositories.locate(pom)) }.to(true)
   end
 
+  it 'should not install POM alongside artifact if artifact has classifier' do
+    @spec = 'group:id:jar:all:1.0'
+    pom = artifact(@spec).pom
+    write @file
+    p method(:install)
+    install artifact(@spec).from(@file)
+    lambda { install.invoke }.should_not change { 
File.exist?(repositories.locate(pom)) }.to(true)
+  end
+
   it 'should reinstall POM alongside artifact' do
     pom = artifact(@spec).pom
     write @file
@@ -812,14 +821,11 @@ describe ActsAsArtifact, '#upload' do
     verbose(false) { artifact.upload(:url=>'sftp://example.com/base') }
   end
 
-  it 'should support artifact classifier' do
+  it 'should support artifact classifier and should not upload pom if artifact 
has classifier' do
     artifact = artifact('com.example:library:jar:all:2.0')
     # Prevent artifact from downloading anything.
     write repositories.locate(artifact)
-    write repositories.locate(artifact.pom)
-    URI.should_receive(:upload).at_least(:once).
-      
with(URI.parse('sftp://example.com/base/com/example/library/2.0/library-2.0.pom'),
 artifact.pom.to_s, anything)
-    URI.should_receive(:upload).at_least(:once).
+    URI.should_receive(:upload).exactly(:once).
       
with(URI.parse('sftp://example.com/base/com/example/library/2.0/library-2.0-all.jar'),
 artifact.to_s, anything)
     verbose(false) { artifact.upload(:url=>'sftp://example.com/base') }
   end
@@ -842,6 +848,7 @@ describe ActsAsArtifact, '#upload' do
     artifact.upload
     lambda { artifact.upload }.should_not raise_error
   end
+
 end
 
 


Reply via email to