class Buildr::Repositories

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:

puts repositories.local
repositories.remote << 'http://example.com/repo'
repositories.release_to = 'sftp://example.com/var/www/public/repo'

Public Instance Methods

local → path click to toggle source

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.

# File lib/buildr/packaging/artifact.rb, line 592
def local
  @local ||= File.expand_path(ENV['M2_REPO'] || ENV['local_repo'] ||
    (Buildr.settings.user['repositories'] && Buildr.settings.user['repositories']['local']) ||
    File.join(ENV['HOME'], '.m2/repository'))
end
local = path click to toggle source

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.

# File lib/buildr/packaging/artifact.rb, line 607
def local=(dir)
  @local = dir ? File.expand_path(dir) : nil
end
locate(spec) → path click to toggle source

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
# File lib/buildr/packaging/artifact.rb, line 620
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
release_to → hash click to toggle source

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] ||= 'sftp://example.com/var/www/repo'

Your private buildr.rb will contain your credentials:

repositories.release_to[:username] = 'john'
repositories.release_to[:password] = 'secret'
# File lib/buildr/packaging/artifact.rb, line 709
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 = url click to toggle source
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 = 'sftp://john:secret@example.com/var/www/repo/'

repositories.release_to = { :url=>'sftp://example.com/var/www/repo/',
                             :username='john', :password=>'secret' }

Or in the settings.yaml file:

repositories:
  release_to: sftp://john:secret@example.com/var/www/repo/

repositories:
  release_to:
    url: sftp://example.com/var/www/repo/
    username: john
    password: secret
# File lib/buildr/packaging/artifact.rb, line 693
def release_to=(options)
  options = { :url=>options } unless Hash === options
  @release_to = options
end
remote → Array click to toggle source

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
# File lib/buildr/packaging/artifact.rb, line 643
def remote
  unless @remote
    @remote = [Buildr.settings.user, Buildr.settings.build].inject([]) { |repos, hash|
      repos | Array(hash['repositories'] && hash['repositories']['remote'])
    }
  end
  @remote
end
remote = Array click to toggle source
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.

# File lib/buildr/packaging/artifact.rb, line 662
def remote=(urls)
  case urls
  when nil then @remote = nil
  when Array then @remote = urls.dup
  else @remote = [urls.to_s]
  end
end