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 2014/07/31 07:12:16 UTC

[02/50] git commit: BUILDR-679 - Support uploading to a snapshot repository defined by repositories.snapshot_to if the artifact is a snapshot.

BUILDR-679 - Support uploading to a snapshot repository defined by repositories.snapshot_to if the artifact is a snapshot. 
					
Submitted by Jean-Philippe Caruana.


git-svn-id: https://svn.apache.org/repos/asf/buildr/trunk@1534553 13f79535-47bb-0310-9956-ffa450edef68


Project: http://git-wip-us.apache.org/repos/asf/buildr/repo
Commit: http://git-wip-us.apache.org/repos/asf/buildr/commit/8f1faa44
Tree: http://git-wip-us.apache.org/repos/asf/buildr/tree/8f1faa44
Diff: http://git-wip-us.apache.org/repos/asf/buildr/diff/8f1faa44

Branch: refs/heads/master
Commit: 8f1faa443accfc48d323047bed0e13516001cf58
Parents: 5ff8f45
Author: Peter Donald <do...@apache.org>
Authored: Tue Oct 22 09:23:50 2013 +0000
Committer: Peter Donald <do...@apache.org>
Committed: Tue Oct 22 09:23:50 2013 +0000

----------------------------------------------------------------------
 CHANGELOG                        |  3 ++
 doc/packaging.textile            |  8 ++++
 doc/settings_profiles.textile    |  1 +
 lib/buildr/packaging/artifact.rb | 52 ++++++++++++++++++++-
 spec/packaging/artifact_spec.rb  | 86 ++++++++++++++++++++++++++++++++++-
 spec/sandbox.rb                  |  2 +-
 6 files changed, 149 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/buildr/blob/8f1faa44/CHANGELOG
----------------------------------------------------------------------
diff --git a/CHANGELOG b/CHANGELOG
index 6f8574b..aed397f 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -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

http://git-wip-us.apache.org/repos/asf/buildr/blob/8f1faa44/doc/packaging.textile
----------------------------------------------------------------------
diff --git a/doc/packaging.textile b/doc/packaging.textile
index dd13012..9c0f4bb 100644
--- a/doc/packaging.textile
+++ b/doc/packaging.textile
@@ -585,6 +585,14 @@ Of course, you'll need to tell Buildr about the release server:
 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.

http://git-wip-us.apache.org/repos/asf/buildr/blob/8f1faa44/doc/settings_profiles.textile
----------------------------------------------------------------------
diff --git a/doc/settings_profiles.textile b/doc/settings_profiles.textile
index 675e9c3..52bd8ab 100644
--- a/doc/settings_profiles.textile
+++ b/doc/settings_profiles.textile
@@ -58,6 +58,7 @@ repositories.release_to[:username] = ENV['USERNAME']
 repositories.release_to[:password] = ENV['PASSWORD']
 {% endhighlight %}
 
+The same works for the @repositories.snapshot_to@ hash.
 
 h2(#personal). Personal Settings
 

http://git-wip-us.apache.org/repos/asf/buildr/blob/8f1faa44/lib/buildr/packaging/artifact.rb
----------------------------------------------------------------------
diff --git a/lib/buildr/packaging/artifact.rb b/lib/buildr/packaging/artifact.rb
index d49df57..2189969 100644
--- a/lib/buildr/packaging/artifact.rb
+++ b/lib/buildr/packaging/artifact.rb
@@ -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:

http://git-wip-us.apache.org/repos/asf/buildr/blob/8f1faa44/spec/packaging/artifact_spec.rb
----------------------------------------------------------------------
diff --git a/spec/packaging/artifact_spec.rb b/spec/packaging/artifact_spec.rb
index 7685399..b97622b 100644
--- a/spec/packaging/artifact_spec.rb
+++ b/spec/packaging/artifact_spec.rb
@@ -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
 
 

http://git-wip-us.apache.org/repos/asf/buildr/blob/8f1faa44/spec/sandbox.rb
----------------------------------------------------------------------
diff --git a/spec/sandbox.rb b/spec/sandbox.rb
index 594228d..599784d 100644
--- a/spec/sandbox.rb
+++ b/spec/sandbox.rb
@@ -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