You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildr.apache.org by do...@apache.org on 2013/10/22 11:23:50 UTC

svn commit: r1534553 - in /buildr/trunk: CHANGELOG doc/packaging.textile doc/settings_profiles.textile lib/buildr/packaging/artifact.rb spec/packaging/artifact_spec.rb spec/sandbox.rb

Author: donaldp
Date: Tue Oct 22 09:23:50 2013
New Revision: 1534553

URL: http://svn.apache.org/r1534553
Log:
BUILDR-679 - Support uploading to a snapshot repository defined by repositories.snapshot_to if the artifact is a snapshot. 
					
Submitted by Jean-Philippe Caruana.

Modified:
    buildr/trunk/CHANGELOG
    buildr/trunk/doc/packaging.textile
    buildr/trunk/doc/settings_profiles.textile
    buildr/trunk/lib/buildr/packaging/artifact.rb
    buildr/trunk/spec/packaging/artifact_spec.rb
    buildr/trunk/spec/sandbox.rb

Modified: buildr/trunk/CHANGELOG
URL: http://svn.apache.org/viewvc/buildr/trunk/CHANGELOG?rev=1534553&r1=1534552&r2=1534553&view=diff
==============================================================================
--- buildr/trunk/CHANGELOG (original)
+++ buildr/trunk/CHANGELOG Tue Oct 22 09:23:50 2013
@@ -1,4 +1,7 @@
 1.4.15 (Pending)
+* Added:  BUILDR-679 - Support uploading to a snapshot repository
+          defined by repositories.snapshot_to if the artifact is
+          a snapshot. Submitted by Jean-Philippe Caruana.
 * Change: Update the jaxb_xjc addon to add output directory to
           generated IDEA project files.
 * Change: Update the default output directory used in the jaxb_xjc

Modified: buildr/trunk/doc/packaging.textile
URL: http://svn.apache.org/viewvc/buildr/trunk/doc/packaging.textile?rev=1534553&r1=1534552&r2=1534553&view=diff
==============================================================================
--- buildr/trunk/doc/packaging.textile (original)
+++ buildr/trunk/doc/packaging.textile Tue Oct 22 09:23:50 2013
@@ -585,6 +585,14 @@ Of course, you'll need to tell Buildr ab
 repositories.release_to = 'sftp://john:secret@release/usr/share/repo'
 {% endhighlight %}
 
+If you have separate repositories for releases and snapshots, you can specify them accordingly. Buildr takes care of picking the correct one.
+
+{% highlight ruby %}
+repositories.release_to = 'sftp://john:secret@release/usr/share/repo/releases'
+repositories.snapshot_to = 'sftp://john:secret@release/usr/share/repo/snapshots'
+{% endhighlight %}
+
+
 This example uses the SFTP protocol.  In addition, you can use the HTTP protocol -- Buildr supports HTTP and HTTPS, Basic Authentication and uploads using PUT -- or point to a directory on your file system.
 
 The URL in this example contains the release server ("release"), path to repository ("user/share/repo") and username/password for access.  The way SFTP works, you specify the path on the release server, and give the user permissions to create directories and files inside the repository.  The file system path is different from the path you use to download these artifacts through an HTTP server, and starts at the root, not the user's home directory.

Modified: buildr/trunk/doc/settings_profiles.textile
URL: http://svn.apache.org/viewvc/buildr/trunk/doc/settings_profiles.textile?rev=1534553&r1=1534552&r2=1534553&view=diff
==============================================================================
--- buildr/trunk/doc/settings_profiles.textile (original)
+++ buildr/trunk/doc/settings_profiles.textile Tue Oct 22 09:23:50 2013
@@ -58,6 +58,7 @@ repositories.release_to[:username] = ENV
 repositories.release_to[:password] = ENV['PASSWORD']
 {% endhighlight %}
 
+The same works for the @repositories.snapshot_to@ hash.
 
 h2(#personal). Personal Settings
 

Modified: buildr/trunk/lib/buildr/packaging/artifact.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/packaging/artifact.rb?rev=1534553&r1=1534552&r2=1534553&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/packaging/artifact.rb (original)
+++ buildr/trunk/lib/buildr/packaging/artifact.rb Tue Oct 22 09:23:50 2013
@@ -179,7 +179,8 @@ module Buildr #:nodoc:
     #
     # Uploads the artifact, its POM and digital signatures to remote server.
     #
-    # In the first form, uses the upload options specified by repositories.release_to.
+    # In the first form, uses the upload options specified by repositories.release_to
+    # or repositories.snapshot_to if the subject is a snapshot artifact.
     # In the second form, uses a URL that includes all the relevant information.
     # In the third form, uses a hash with the options :url, :username, :password,
     # and :permissions. All but :url are optional.
@@ -188,6 +189,7 @@ module Buildr #:nodoc:
     end
 
     def upload_task(upload_to = nil)
+      upload_to ||= Buildr.repositories.snapshot_to if snapshot? && Buildr.repositories.snapshot_to != nil && Buildr.repositories.snapshot_to[:url] != nil
       upload_to ||= Buildr.repositories.release_to
       upload_to = { :url=>upload_to } unless Hash === upload_to
       raise ArgumentError, 'Don\'t know where to upload, perhaps you forgot to set repositories.release_to' unless upload_to[:url]
@@ -715,6 +717,54 @@ module Buildr #:nodoc:
       @release_to
     end
 
+    # :call-seq:
+    #   snapshot_to = url
+    #   snapshot_to = hash
+    #
+    # Specifies the release server. Accepts a Hash with different repository settings
+    # (e.g. url, username, password), or a String to only set the repository URL.
+    #
+    # Besides the URL, all other settings depend on the transport protocol in use.
+    #
+    # For example:
+    #   repositories.snapshot_to = 'sftp://john:secret@example.com/var/www/repo/'
+    #
+    #   repositories.snapshot_to = { :url=>'sftp://example.com/var/www/repo/',
+    #                                :username='john', :password=>'secret' }
+    # Or in the settings.yaml file:
+    #   repositories:
+    #     snapshot_to: sftp://john:secret@example.com/var/www/repo/
+    #
+    #   repositories:
+    #     snapshot_to:
+    #       url: sftp://example.com/var/www/repo/
+    #       username: john
+    #       password: secret
+    def snapshot_to=(options)
+      options = { :url=>options } unless Hash === options
+      @snapshot_to = options
+    end
+
+    # :call-seq:
+    #   snapshot_to => hash
+    #
+    # Returns the current snapshot release server setting as a Hash. This is a more convenient way to
+    # configure the settings, as it allows you to specify the settings progressively.
+    #
+    # For example, the Buildfile will contain the repository URL used by all developers:
+    #   repositories.snapshot_to[:url] ||= 'sftp://example.com/var/www/repo'
+    # Your private buildr.rb will contain your credentials:
+    #   repositories.snapshot_to[:username] = 'john'
+    #   repositories.snapshot_to[:password] = 'secret'
+    def snapshot_to
+      unless @snapshot_to
+        value = (Buildr.settings.user['repositories'] && Buildr.settings.user['repositories']['snapshot_to']) \
+          || (Buildr.settings.build['repositories'] && Buildr.settings.build['repositories']['snapshot_to'])
+        @snapshot_to = Hash === value ? value.inject({}) { |hash, (key, value)| hash.update(key.to_sym=>value) } : { :url=>Array(value).first }
+      end
+      @snapshot_to
+    end
+
   end
 
   # :call-seq:

Modified: buildr/trunk/spec/packaging/artifact_spec.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/spec/packaging/artifact_spec.rb?rev=1534553&r1=1534552&r2=1534553&view=diff
==============================================================================
--- buildr/trunk/spec/packaging/artifact_spec.rb (original)
+++ buildr/trunk/spec/packaging/artifact_spec.rb Tue Oct 22 09:23:50 2013
@@ -510,6 +510,51 @@ describe Repositories, 'release_to' do
   end
 end
 
+describe Repositories, 'snapshot_to' do
+  it 'should accept URL as first argument' do
+    repositories.snapshot_to = 'http://buildr.apache.org/repository/noexist'
+    repositories.snapshot_to.should == { :url=>'http://buildr.apache.org/repository/noexist' }
+  end
+
+  it 'should accept hash with options' do
+    repositories.snapshot_to = { :url=>'http://buildr.apache.org/repository/noexist', :username=>'john' }
+    repositories.snapshot_to.should == { :url=>'http://buildr.apache.org/repository/noexist', :username=>'john' }
+  end
+
+  it 'should allow the hash to be manipulated' do
+    repositories.snapshot_to = 'http://buildr.apache.org/repository/noexist'
+    repositories.snapshot_to.should == { :url=>'http://buildr.apache.org/repository/noexist' }
+    repositories.snapshot_to[:username] = 'john'
+    repositories.snapshot_to.should == { :url=>'http://buildr.apache.org/repository/noexist', :username=>'john' }
+  end
+
+  it 'should load URL from settings file' do
+    write 'home/.buildr/settings.yaml', <<-YAML
+    repositories:
+      snapshot_to: http://john:secret@buildr.apache.org/repository/noexist
+    YAML
+    repositories.snapshot_to.should == { :url=>'http://john:secret@buildr.apache.org/repository/noexist' }
+  end
+
+  it 'should load URL from build settings file' do
+    write 'build.yaml', <<-YAML
+    repositories:
+      snapshot_to: http://john:secret@buildr.apache.org/repository/noexist
+    YAML
+    repositories.snapshot_to.should == { :url=>'http://john:secret@buildr.apache.org/repository/noexist' }
+  end
+
+  it 'should load URL, username and password from settings file' do
+    write 'home/.buildr/settings.yaml', <<-YAML
+    repositories:
+      snapshot_to:
+        url: http://buildr.apache.org/repository/noexist
+        username: john
+        password: secret
+    YAML
+    repositories.snapshot_to.should == { :url=>'http://buildr.apache.org/repository/noexist', :username=>'john', :password=>'secret' }
+  end
+end
 
 describe Buildr, '#artifact' do
   before do
@@ -885,7 +930,7 @@ describe ActsAsArtifact, '#upload' do
     lambda { artifact.upload }.should raise_error(Exception, /where to upload/)
   end
 
-  it 'should accept repositories.upload setting' do
+  it 'should accept repositories.release_to setting' do
     artifact = artifact('com.example:library:jar:2.0')
     # Prevent artifact from downloading anything.
     write repositories.locate(artifact)
@@ -896,6 +941,45 @@ describe ActsAsArtifact, '#upload' do
     lambda { artifact.upload }.should_not raise_error
   end
 
+  it 'should use repositories.release_to setting even for snapshots when snapshot_to is not set' do
+    artifact = artifact('com.example:library:jar:2.0-SNAPSHOT')
+    # Prevent artifact from downloading anything.
+    write repositories.locate(artifact)
+    write repositories.locate(artifact.pom)
+    URI.should_receive(:upload).once.
+      with(URI.parse('sftp://buildr.apache.org/repository/noexist/base/com/example/library/2.0-SNAPSHOT/library-2.0-SNAPSHOT.pom'), artifact.pom.to_s, anything)
+    URI.should_receive(:upload).once.
+      with(URI.parse('sftp://buildr.apache.org/repository/noexist/base/com/example/library/2.0-SNAPSHOT/library-2.0-SNAPSHOT.jar'), artifact.to_s, anything)
+    repositories.release_to = 'sftp://buildr.apache.org/repository/noexist/base'
+    artifact.upload
+    lambda { artifact.upload }.should_not raise_error
+  end
+
+  it 'should use repositories.snapshot_to setting when snapshot_to is set' do
+    artifact = artifact('com.example:library:jar:2.0-SNAPSHOT')
+    # Prevent artifact from downloading anything.
+    write repositories.locate(artifact)
+    write repositories.locate(artifact.pom)
+    URI.should_receive(:upload).once.
+      with(URI.parse('sftp://buildr.apache.org/repository/noexist/snapshot/com/example/library/2.0-SNAPSHOT/library-2.0-SNAPSHOT.pom'), artifact.pom.to_s, anything)
+    URI.should_receive(:upload).once.
+      with(URI.parse('sftp://buildr.apache.org/repository/noexist/snapshot/com/example/library/2.0-SNAPSHOT/library-2.0-SNAPSHOT.jar'), artifact.to_s, anything)
+    repositories.release_to = 'sftp://buildr.apache.org/repository/noexist/base'
+    repositories.snapshot_to = 'sftp://buildr.apache.org/repository/noexist/snapshot'
+    artifact.upload
+    lambda { artifact.upload }.should_not raise_error
+  end
+
+  it 'should complain when only a snapshot repo is set but the artifact is not a snapshot' do
+    artifact = artifact('com.example:library:jar:2.0')
+    # Prevent artifact from downloading anything.
+    write repositories.locate(artifact)
+    write repositories.locate(artifact.pom)
+    repositories.snapshot_to = 'sftp://buildr.apache.org/repository/noexist/snapshot'
+    lambda { artifact.upload }.should raise_error(Exception, /where to upload/)
+  end
+
+
 end
 
 

Modified: buildr/trunk/spec/sandbox.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/spec/sandbox.rb?rev=1534553&r1=1534552&r2=1534553&view=diff
==============================================================================
--- buildr/trunk/spec/sandbox.rb (original)
+++ buildr/trunk/spec/sandbox.rb Tue Oct 22 09:23:50 2013
@@ -162,7 +162,7 @@ module Sandbox
     # since we don't want to remotely download artifacts into the sandbox over and over
     Buildr.repositories.instance_eval do
       @remote = ["file://" + @local]
-      @local = @release_to = nil
+      @local = @release_to = @snapshot_to = nil
     end
     Buildr.options.proxy.http = nil