buildr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lac...@apache.org
Subject svn commit: r707477 - in /incubator/buildr/trunk: CHANGELOG lib/buildr/packaging/artifact.rb spec/core/compile_spec.rb spec/packaging/artifact_spec.rb
Date Thu, 23 Oct 2008 21:17:26 GMT
Author: lacton
Date: Thu Oct 23 14:17:25 2008
New Revision: 707477

URL: http://svn.apache.org/viewvc?rev=707477&view=rev
Log:
BUILDR-164 New 'sources' task to download source code

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

Modified: incubator/buildr/trunk/CHANGELOG
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/CHANGELOG?rev=707477&r1=707476&r2=707477&view=diff
==============================================================================
--- incubator/buildr/trunk/CHANGELOG (original)
+++ incubator/buildr/trunk/CHANGELOG Thu Oct 23 14:17:25 2008
@@ -1,5 +1,7 @@
 1.3.4 (Pending)
 * Added:  BUILDR-159 Improved 'check' to accept both tar and tgz archives.
+* Added:  BUILDR-164 New 'sources' task to download source code
+          for artifact jars.
 * Change: Introduced new options from Rake 0.8.3: -I (libdir), -R (rakelib),
           --rules, --no-search, --silent.
 * Changed: Upgraded to Rubyforge 1.0.1.

Modified: incubator/buildr/trunk/lib/buildr/packaging/artifact.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/packaging/artifact.rb?rev=707477&r1=707476&r2=707477&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/packaging/artifact.rb (original)
+++ incubator/buildr/trunk/lib/buildr/packaging/artifact.rb Thu Oct 23 14:17:25 2008
@@ -24,6 +24,9 @@
   desc 'Download all artifacts'
   task 'artifacts'
 
+  desc "Download all artifacts' sources"
+  task 'sources'
+
   # Mixin with a task to make it behave like an artifact. Implemented by the packaging tasks.
   #
   # An artifact has an identifier, group identifier, type, version number and
@@ -110,15 +113,6 @@
       end
     end
     
-    # :call-seq:
-    #   sources_artifact => Artifact
-    # 
-    # Convenience method that returns the sources artifact corresponding to this artifact.
-    def sources_artifact
-      return self if type == :sources
-      Buildr.artifact(:group=>group, :id=>id, :version=>version, :type=>:sources)
-    end
-
     def install
       pom.install if pom && pom != self
       invoke
@@ -414,6 +408,38 @@
       fail "Failed to download #{to_spec}, tried the following repositories:\n#{remote_uris.join("\n")}"
     end
   end
+  
+  
+  # An artifact that is optional.
+  # If downloading fails, the user will be informed but it will not raise an exception.
+  class OptionalArtifact < Artifact
+    
+    class << self
+      
+      # :call-seq:
+      #   register_source_artifact_for(spec)
+      #
+      # Register the source artifact corresponding to the provided artifact spec
+      # so that the 'sources' task will try to download it.
+      def register_source_artifact_for(spec)
+        sources_spec = spec.merge(:classifier=>'sources')
+        sources_task = OptionalArtifact.define_task(Buildr.repositories.locate(sources_spec))
+        sources_task.send :apply_spec, sources_spec
+        Rake::Task['sources'].enhance [sources_task]
+      end
+      
+    end
+    
+    protected
+    
+    # If downloading fails, the user will be informed but it will not raise an exception.
+    def download
+      super
+    rescue 
+      info "Failed to download #{to_spec}. Skipping it."
+    end
+    
+  end
 
 
   # Holds the path to the local repository, URLs for remote repositories, and settings for
release server.
@@ -601,6 +627,7 @@
       task.send :apply_spec, spec
       Rake::Task['rake:artifacts'].enhance [task]
       Artifact.register(task)
+      OptionalArtifact.register_source_artifact_for(spec)
     end
     task.enhance &block
   end

Modified: incubator/buildr/trunk/spec/core/compile_spec.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/core/compile_spec.rb?rev=707477&r1=707476&r2=707477&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/core/compile_spec.rb (original)
+++ incubator/buildr/trunk/spec/core/compile_spec.rb Thu Oct 23 14:17:25 2008
@@ -379,7 +379,7 @@
   it 'should complain if source directories and no compiler selected' do
     mkpath 'sources'
     define 'bar' do
-      lambda { compile.from('sources').invoke }.should raise_error(RuntimeError, /no compiler
selected/i)
+      lambda { compile.from(_('sources')).invoke }.should raise_error(RuntimeError, /no compiler
selected/i)
     end
   end
 end

Modified: incubator/buildr/trunk/spec/packaging/artifact_spec.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/packaging/artifact_spec.rb?rev=707477&r1=707476&r2=707477&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/packaging/artifact_spec.rb (original)
+++ incubator/buildr/trunk/spec/packaging/artifact_spec.rb Thu Oct 23 14:17:25 2008
@@ -75,10 +75,6 @@
     @classified.pom.to_hash.should == @classified.to_hash.merge(:type=>:pom).except(:classifier)
   end
   
-  it 'should have associated sources artifact' do
-    @artifact.sources_artifact.to_hash.should == @artifact.to_hash.merge(:type=>:sources)
-  end
-
   it 'should download file if file does not exist' do
     lambda { @artifact.invoke }.should raise_error(Exception, /No remote repositories/)
     lambda { @classified.invoke }.should raise_error(Exception, /No remote repositories/)
@@ -643,7 +639,32 @@
 
 
 describe Rake::Task, ' sources' do
-  it 'should download all sources'
+
+  before do
+    task('sources').clear
+    repositories.remote = 'http://example.com'
+    artifact 'group:id:jar:1.0'
+  end
+  
+  it 'should download sources for all specified artifacts' do
+    URI.should_receive(:download).any_number_of_times.and_return { |uri, target| write target
}
+    lambda { task('sources').invoke }.should change { File.exist?('home/.m2/repository/group/id/1.0/id-1.0-sources.jar')
}.to(true)
+  end
+  
+  describe 'when the source artifact does not exist' do
+    
+    before do
+      URI.should_receive(:download).any_number_of_times.and_raise(URI::NotFoundError)
+    end
+    
+    it 'should not fail' do
+      lambda { task('sources').invoke }.should_not raise_error
+    end
+    
+    it 'should inform the user' do
+      lambda { task('sources').invoke }.should show_info('Failed to download group:id:jar:sources:1.0.
Skipping it.')
+    end
+  end
 end
 
 



Mime
View raw message