Repository: buildr
Updated Branches:
  refs/heads/master 0d2d1faf9 -> 95936baa5


BUILDR-577 Allow remote repo to be added with http basic auth support.


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

Branch: refs/heads/master
Commit: 95936baa599a4c9151585d14fc50c9e78be4f734
Parents: 0d2d1fa
Author: Antoine Toulme <[email protected]>
Authored: Mon May 2 21:02:59 2016 -0700
Committer: Antoine Toulme <[email protected]>
Committed: Mon May 2 21:02:59 2016 -0700

----------------------------------------------------------------------
 CHANGELOG                        |  1 +
 lib/buildr/packaging/artifact.rb | 48 ++++++++++++++++++++++++++++++++++-
 spec/packaging/artifact_spec.rb  | 21 ++++++++++++++-
 3 files changed, 68 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/buildr/blob/95936baa/CHANGELOG
----------------------------------------------------------------------
diff --git a/CHANGELOG b/CHANGELOG
index 7882bfd..09d52d9 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -9,6 +9,7 @@
 * Change: Update jekyll to 3.1.3
 * Change: Update rdoc to 4.2.2
 * Added:  Travis badge to README.rdoc
+* Added: BUILDR-577 Allow remote repo to be added with http basic auth 
support. Submitted by Michael Guymon.
 
 
 1.4.25 (2016-04-18)

http://git-wip-us.apache.org/repos/asf/buildr/blob/95936baa/lib/buildr/packaging/artifact.rb
----------------------------------------------------------------------
diff --git a/lib/buildr/packaging/artifact.rb b/lib/buildr/packaging/artifact.rb
index 2189969..f696c61 100644
--- a/lib/buildr/packaging/artifact.rb
+++ b/lib/buildr/packaging/artifact.rb
@@ -426,7 +426,7 @@ module Buildr #:nodoc:
     # which they are returned from #remote, until successful.
     def download
       trace "Downloading #{to_spec}"
-      remote = Buildr.repositories.remote.map { |repo_url| URI === repo_url ? 
repo_url : URI.parse(repo_url) }
+      remote = Buildr.repositories.remote_uri
       remote = remote.each { |repo_url| repo_url.path += '/' unless 
repo_url.path[-1] == '/' }
       fail "Unable to download #{to_spec}. No remote repositories defined." if 
remote.empty?
       exact_success = remote.find do |repo_url|
@@ -650,6 +650,52 @@ module Buildr #:nodoc:
       end
       @remote
     end
+    
+    # :call-seq:
+    #   remote_uri => Array
+    #
+    # Returns an array of all the remote repositories as instances of URI
+    #
+    # Supports 
+    #  * String urls: "http://example.com/repo";
+    #  * URI: URI.parse( "http://example.com/repo"; )
+    #  * Hash: { :url => "http://example.com/repo";, :user => "user", :pass => 
"pass" }
+    #
+    def remote_uri
+      remote
+      
+      uris = []
+      @remote.each do |repo|
+        case repo
+        when nil then
+          # ignore nil
+        when URI then
+          uris << repo
+        when Hash then
+          url = (repo[:url] || repo['url'] )
+          if url
+            uri = URI.parse(url)
+            if ( username = (repo[:username] || repo['username'] || 
repo[:user] || repo['user']) )
+              uri.user = username
+            end
+            
+            if ( password = (repo[:password] || repo['password'] || 
repo[:pass] || repo['pass']) )
+              uri.password = password
+            end
+            uris << uri
+          else
+            fail( "Repository Hash format missing url: #{repo}" )
+          end
+          
+        when String then 
+          uris << URI.parse(repo)
+        else 
+          fail( "Unsupported Repository format: #{repo}" )
+        end
+      end
+      
+      uris
+    end
 
     # :call-seq:
     #   remote = Array

http://git-wip-us.apache.org/repos/asf/buildr/blob/95936baa/spec/packaging/artifact_spec.rb
----------------------------------------------------------------------
diff --git a/spec/packaging/artifact_spec.rb b/spec/packaging/artifact_spec.rb
index 6a28397..c00bdc4 100644
--- a/spec/packaging/artifact_spec.rb
+++ b/spec/packaging/artifact_spec.rb
@@ -209,6 +209,26 @@ describe Repositories, 'local' do
   end
 end
 
+describe Repositories, 'remote_uri' do
+  before do
+    Buildr.repositories.instance_eval do
+      @local = @remote = @release_to = nil
+    end
+
+    @repos = [ 'https://oss.sonatype.org/', 'http://www.ibiblio.org/maven2', { 
:url => 'http://repo1.maven.org/maven2', :username => 'user', :password => 
'password' } ]
+  end
+  
+  it 'should convert remote to array of uri' do
+      uri = URI.parse( 'http://repo1.maven.org/maven2' )
+      uri.user = 'user' 
+      uri.password = 'password'
+    
+      uris = [ URI.parse( 'https://oss.sonatype.org/'), URI.parse( 
'http://www.ibiblio.org/maven2' ), uri ]
+      
+      repositories.remote = @repos
+      repositories.remote_uri.should eql(uris)
+  end
+end
 
 describe Repositories, 'remote' do
   before do
@@ -855,7 +875,6 @@ describe Buildr, '#install' 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

Reply via email to