Repository: buildr Updated Branches: refs/heads/master 42a016d97 -> 24724f998
BUILDR-476 Buildr doesn't respect company repository manager Project: http://git-wip-us.apache.org/repos/asf/buildr/repo Commit: http://git-wip-us.apache.org/repos/asf/buildr/commit/24724f99 Tree: http://git-wip-us.apache.org/repos/asf/buildr/tree/24724f99 Diff: http://git-wip-us.apache.org/repos/asf/buildr/diff/24724f99 Branch: refs/heads/master Commit: 24724f998a6697ee3ef3ee59bebaf15da0bbb4b9 Parents: 42a016d Author: Antoine Toulme <[email protected]> Authored: Sat Aug 13 23:23:01 2016 -0700 Committer: Antoine Toulme <[email protected]> Committed: Sat Aug 13 23:23:01 2016 -0700 ---------------------------------------------------------------------- CHANGELOG | 1 + lib/buildr/packaging/artifact.rb | 42 ++++++++++++++++++++ spec/packaging/artifact_spec.rb | 74 +++++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/buildr/blob/24724f99/CHANGELOG ---------------------------------------------------------------------- diff --git a/CHANGELOG b/CHANGELOG index 03e5ee5..4a49eb6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -21,6 +21,7 @@ * Fixed: BUILDR-621 ZipTask creates zip file with entries not sorted by path causing very slow unzipping. * Fixed: BUILDR-695 transitive doesn't support ${project.parent.version} in POM. * Fixed: BUILDR-653 Using Eclipse compiler (ECJ) +* Fixed: BUILDR-476 Buildr doesn't respect company repository manager * Change: Update the custom_pom addon to generate poms with exclusions section that excludes all transitive dependencies. This is required as buildr dependencies are not transitive while Maven's dependencies are transitive by default. http://git-wip-us.apache.org/repos/asf/buildr/blob/24724f99/lib/buildr/packaging/artifact.rb ---------------------------------------------------------------------- diff --git a/lib/buildr/packaging/artifact.rb b/lib/buildr/packaging/artifact.rb index 4f18be3..90c0197 100644 --- a/lib/buildr/packaging/artifact.rb +++ b/lib/buildr/packaging/artifact.rb @@ -628,6 +628,44 @@ module Buildr #:nodoc: spec = Artifact.to_hash(spec) File.join(local, spec[:group].split('.'), spec[:id], spec[:version], Artifact.hash_to_file_name(spec)) end + + # :call-seq: + # mirrors => Array + # + # Returns an array of all the mirror repository URLs. + # + # Mirrors override remote repositories defined in the project. + # The best way is to add repositories to the user settings file under '$HOME/.buildr/settings.yaml'. + # For example: + # repositories: + # mirrors: + # - http://example.com/repository + def mirrors + unless @mirrors + @mirrors = [Buildr.settings.user, Buildr.settings.build].inject([]) { |repos, hash| + repos | Array(hash['repositories'] && hash['repositories']['mirrors']) + } + end + @mirrors + end + + # :call-seq: + # remote = Array + # remote = url + # remote = nil + # + # With a String argument, clears the array and set it to that single URL. + # + # With an Array argument, clears the array and set it to these specific URLs. + # + # With nil, clears the array. + def mirrors=(urls) + case urls + when nil then @mirrors = nil + when Array then @mirrors = urls.dup + else @mirrors = [urls.to_s] + end + end # :call-seq: # remote => Array @@ -648,6 +686,10 @@ module Buildr #:nodoc: # - http://example.com/repo # - http://elsewhere.com/repo def remote + unless mirrors.empty? + info "Remote repositories overridden by mirrors #{mirrors.map(&:to_s).join(", ")}" + mirrors + end unless @remote @remote = [Buildr.settings.user, Buildr.settings.build].inject([]) { |repos, hash| repos | Array(hash['repositories'] && hash['repositories']['remote']) http://git-wip-us.apache.org/repos/asf/buildr/blob/24724f99/spec/packaging/artifact_spec.rb ---------------------------------------------------------------------- diff --git a/spec/packaging/artifact_spec.rb b/spec/packaging/artifact_spec.rb index b6bd84d..53f36cb 100644 --- a/spec/packaging/artifact_spec.rb +++ b/spec/packaging/artifact_spec.rb @@ -230,6 +230,80 @@ describe Repositories, 'remote_uri' do end end +describe Repositories, 'mirrors' do + before do + Buildr.repositories.instance_eval do + @local = @remote = @release_to = @mirrors = nil + end + + @repos = [ 'http://www.ibiblio.org/maven2', 'http://repo1.maven.org/maven2' ] + end + + it 'should be empty initially' do + repositories.mirrors.should be_empty + end + + it 'should be settable' do + repositories.mirrors = @repos.first + repositories.mirrors.should eql([@repos.first]) + end + + it 'should be settable from array' do + repositories.mirrors = @repos + repositories.mirrors.should eql(@repos) + end + + it 'should add and return repositories in order' do + @repos.each { |url| repositories.mirrors << url } + repositories.mirrors.should eql(@repos) + end + + it 'should log that it is overridding the remote repositories with the mirrors' do + @repos.each { |url| repositories.mirrors << url } + lambda { repositories.remote }.should show_info /Remote repositories overridden by mirrors / + end + + it 'should load with all repositories specified in settings file' do + write 'home/.buildr/settings.yaml', <<-YAML + repositories: + mirrors: + - http://example.com/repository/noexist + remote: + - http://foobar.com + YAML + repositories.mirrors.should include('http://example.com/repository/noexist') + end + + it 'should load with all repositories specified in build.yaml file' do + write 'build.yaml', <<-YAML + repositories: + mirrors: + - http://example.com/repository/noexist + remote: + - http://foobar.com + YAML + repositories.mirrors.should include('http://example.com/repository/noexist') + end + + it 'should load with all repositories specified in settings and build.yaml files' do + write 'home/.buildr/settings.yaml', <<-YAML + repositories: + mirrors: + - http://example.com/repository/noexist + remote: + - http://foobar.com + YAML + write 'build.yaml', <<-YAML + repositories: + mirrors: + - http://example.com/repo2 + remote: + - http://foobar.com + YAML + repositories.mirrors.should include('http://example.com/repository/noexist', 'http://example.com/repo2') + end +end + describe Repositories, 'remote' do before do Buildr.repositories.instance_eval do
