lib/core/artifact.rb in buildr-0.16.0 vs lib/core/artifact.rb in buildr-0.18.0
- old
+ new
@@ -1,7 +1,10 @@
module Buildr
+ desc "Download all artifacts"
+ task "artifacts"
+
# This module gives you a way to access the individual properties of an
# artifact: id, group, type, classifier and version. It also provides other
# methods commonly used on an artifact, specifically #to_hash and #to_spec.
module ActsAsArtifact
@@ -181,45 +184,40 @@
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
- # Returns a hash of all the remote repositories. The key is the repository
- # identifier, and the value is the repository base URL.
+ # Returns an array of all the remote repositories. When downloading an artifact,
+ # the default behavior is to try repositories in the order in which they show in
+ # the array.
def remote()
- @remote ||= {}
+ @remote ||= []
end
- # Sets the remote repositories from a hash. See #remote.
- def remote=(hash)
- case hash
+ # With a string argument, sets the remote repository (only one) to this URL.
+ # With an array argument, sets the remote repository to that set of URLs.
+ # Passing nil is equivalent to an empty array.
+ def remote=(urls)
+ case urls
when nil
- @remote = {}
- when Hash
- @remote = hash.clone
+ @remote = nil
+ when Array
+ @remote = urls.dup
else
- raise ArgumentError, "Expecting a hash" unless Hash === hash
+ @remote = [urls.to_s]
end
end
- # Adds more remote repositories from a hash. See #remote.
- #
- # For example:
- # repositories.remote.add :ibiblio=>"http://www.ibiblio.org/maven2"
- def add(hash)
- remote.merge!(hash)
- end
-
# Attempts to download the artifact from one of the remote repositories
# and store it in the local repository. Returns the path if downloaded,
# otherwise raises an exception.
def download(spec)
spec = Artifact.to_hash(spec) unless Hash === spec
path = locate(spec)
puts "Downloading #{Artifact.to_spec(spec)}" if Rake.application.options.trace
- return path if remote.any? do |repo_id, repo_url|
+ return path if remote.any? do |repo_url|
begin
rel_path = spec[:group].gsub(".", "/") +
"/#{spec[:id]}/#{spec[:version]}/#{Artifact.hash_to_file_name(spec)}"
Transports.perform URI.parse(repo_url.to_s) do |http|
mkpath File.dirname(path), :verbose=>false
@@ -233,11 +231,11 @@
rescue Exception=>error
warn error if Rake.application.options.trace
false
end
end
- fail "Failed to download #{Artifact.to_spec(spec)}, tried the following repositories:\n#{repositories.remote.values.join("\n")}"
+ fail "Failed to download #{Artifact.to_spec(spec)}, tried the following repositories:\n#{repositories.remote.join("\n")}"
end
# Specifies the deployment repository. Accepts a hash with the different
# repository settings (e.g. url, username, password). Anything else is
# interepted as the URL.
@@ -291,10 +289,11 @@
# "http://download.dojotoolkit.org/release-2.0/dojo-2.0-widget.zip")
def artifact(spec, &block)
spec = Artifact.to_hash(spec)
unless task = Artifact.lookup(spec)
task = Artifact.define_task(repositories.locate(spec))
+ Rake::Task["rake:artifacts"].enhance [ task ]
Artifact.register(task)
end
task.apply_spec spec
task.enhance &block
end
@@ -334,14 +333,14 @@
when Hash
set |= [artifact(spec)]
when /:/
set |= [artifact(spec)]
when String
- set |= [file(spec)]
- when Rake::Task
- set |= [spec]
+ set |= [File.expand_path(spec)]
when Project
set |= artifacts(spec.packages)
+ when Rake::Task
+ set |= [spec]
when Array
set |= artifacts(*spec)
else
fail "Invalid artifact specification: #{spec.to_s || 'nil'}"
end