Class: Buildr::Repositories
- Includes:
- Singleton
- Defined in:
- lib/buildr/packaging/artifact.rb
Overview
Holds the path to the local repository, URLs for remote repositories, and settings for release server.
You can access this object from the #repositories method. For example:
repositories.remote << 'http://example.com/repo'
Instance Method Summary collapse
-
#local ⇒ Object
:call-seq: local => path.
-
#local=(dir) ⇒ Object
:call-seq: local = path.
-
#locate(spec) ⇒ Object
:call-seq: locate(spec) => path.
-
#mirrors ⇒ Object
:call-seq: mirrors => Array.
-
#mirrors=(urls) ⇒ Object
:call-seq: remote = Array remote = url remote = nil.
-
#release_to ⇒ Object
:call-seq: release_to => hash.
-
#release_to=(options) ⇒ Object
:call-seq: release_to = url release_to = hash.
-
#remote ⇒ Object
:call-seq: remote => Array.
-
#remote=(urls) ⇒ Object
:call-seq: remote = Array remote = url remote = nil.
-
#remote_uri ⇒ Object
:call-seq: remote_uri => Array.
-
#snapshot_to ⇒ Object
:call-seq: snapshot_to => hash.
-
#snapshot_to=(options) ⇒ Object
:call-seq: snapshot_to = url snapshot_to = hash.
Instance Method Details
#local ⇒ Object
:call-seq:
local => path
Returns the path to the local repository.
The default path is .m2/repository relative to the home directory. You can set this using the M2_REPO environment variable or the repositories/local value in your settings.yaml file.
654 655 656 657 658 |
# File 'lib/buildr/packaging/artifact.rb', line 654 def local @local ||= File.(ENV['M2_REPO'] || ENV['local_repo'] || (Buildr.settings.user['repositories'] && Buildr.settings.user['repositories']['local']) || File.join(ENV['HOME'], '.m2/repository')) end |
#local=(dir) ⇒ Object
:call-seq:
local = path
Sets the path to the local repository.
The best place to set the local repository path is from a buildr.rb file located in the .buildr directory under your home directory. That way all your projects will share the same path, without affecting other developers collaborating on these projects.
669 670 671 |
# File 'lib/buildr/packaging/artifact.rb', line 669 def local=(dir) @local = dir ? File.(dir) : nil end |
#locate(spec) ⇒ Object
:call-seq:
locate(spec) => path
Locates an artifact in the local repository based on its specification, and returns a file path.
For example:
locate :group=>'log4j', :id=>'log4j', :version=>'1.1'
=> ~/.m2/repository/log4j/log4j/1.1/log4j-1.1.jar
682 683 684 685 |
# File 'lib/buildr/packaging/artifact.rb', line 682 def locate(spec) spec = Artifact.to_hash(spec) File.join(local, spec[:group].split('.'), spec[:id], spec[:version], Artifact.hash_to_file_name(spec)) end |
#mirrors ⇒ Object
: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
698 699 700 701 702 703 704 705 |
# File 'lib/buildr/packaging/artifact.rb', line 698 def mirrors unless @mirrors @mirrors = [Buildr.settings.user, Buildr.settings.build].inject([]) { |repos, hash| repos | Array(hash['repositories'] && hash['repositories']['mirrors']) } end @mirrors end |
#mirrors=(urls) ⇒ Object
: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.
717 718 719 720 721 722 723 |
# File 'lib/buildr/packaging/artifact.rb', line 717 def mirrors=(urls) case urls when nil then @mirrors = nil when Array then @mirrors = urls.dup else @mirrors = [urls.to_s] end end |
#release_to ⇒ Object
:call-seq:
release_to => hash
Returns the current 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.release_to[:url] ||= 'https://example.com/var/www/repo'
Your private buildr.rb will contain your credentials:
repositories.release_to[:username] = 'john'
repositories.release_to[:password] = 'secret'
857 858 859 860 861 862 863 864 |
# File 'lib/buildr/packaging/artifact.rb', line 857 def release_to unless @release_to value = (Buildr.settings.user['repositories'] && Buildr.settings.user['repositories']['release_to']) \ || (Buildr.settings.build['repositories'] && Buildr.settings.build['repositories']['release_to']) @release_to = Hash === value ? value.inject({}) { |hash, (key, value)| hash.update(key.to_sym=>value) } : { :url=>Array(value).first } end @release_to end |
#release_to=(options) ⇒ Object
:call-seq:
release_to = url
release_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.release_to = { :url=>'https://example.com/var/www/repo/',
:username='john', :password=>'secret' }
Or in the settings.yaml file:
repositories:
release_to: https://john:[email protected]/var/www/repo/
repositories:
release_to:
url: https://example.com/var/www/repo/
username: john
password: secret
841 842 843 844 |
# File 'lib/buildr/packaging/artifact.rb', line 841 def release_to=() = { :url=> } unless Hash === @release_to = end |
#remote ⇒ Object
:call-seq:
remote => Array
Returns an array of all the remote repository URLs.
When downloading artifacts, repositories are accessed in the order in which they appear here. The best way is to add repositories individually, for example:
repositories.remote << 'http://example.com/repo'
You can also specify remote repositories in the settings.yaml (per user) and build.yaml (per build) files. Both sets of URLs are loaded by default into this array, URLs from the personal setting showing first.
For example:
repositories:
remote:
- http://example.com/repo
- http://elsewhere.com/repo
743 744 745 746 747 748 749 750 751 752 753 754 |
# File 'lib/buildr/packaging/artifact.rb', line 743 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']) } end @remote end |
#remote=(urls) ⇒ Object
: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.
812 813 814 815 816 817 818 |
# File 'lib/buildr/packaging/artifact.rb', line 812 def remote=(urls) case urls when nil then @remote = nil when Array then @remote = urls.dup else @remote = [urls.to_s] end end |
#remote_uri ⇒ Object
: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" }
766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 |
# File 'lib/buildr/packaging/artifact.rb', line 766 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 |
#snapshot_to ⇒ Object
: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] ||= 'https://example.com/var/www/repo'
Your private buildr.rb will contain your credentials:
repositories.snapshot_to[:username] = 'john'
repositories.snapshot_to[:password] = 'secret'
905 906 907 908 909 910 911 912 |
# File 'lib/buildr/packaging/artifact.rb', line 905 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 |
#snapshot_to=(options) ⇒ Object
: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 = 'https://john:[email protected]/var/www/repo/'
repositories.snapshot_to = { :url=>'https://example.com/var/www/repo/',
:username='john', :password=>'secret' }
Or in the settings.yaml file:
repositories:
snapshot_to: https://john:[email protected]/var/www/repo/
repositories:
snapshot_to:
url: https://example.com/var/www/repo/
username: john
password: secret
889 890 891 892 |
# File 'lib/buildr/packaging/artifact.rb', line 889 def snapshot_to=() = { :url=> } unless Hash === @snapshot_to = end |