lib/java/artifact.rb in buildr-1.0.0 vs lib/java/artifact.rb in buildr-1.1.0

- old
+ new

@@ -317,10 +317,48 @@ else @remote = [urls.to_s] end end + # :call-seq: + # proxy() => Hash + # + # Returns the proxy settings used when downloading from remote repositories. + def proxy() + @proxy ||= {} + end + + # :call-seq: + # proxy = Hash + # proxy = String + # proxy = URI + # proxy = nil + # + # Sets the proxy settings used when downloading from remote repositories. + # You can specify proxy settings using a Hash with values for :host, :port, + # :user and :password. + # + # You can also pass a URL as a string or URI object. The settings are converted + # to a hash. + # + # For example: + # repositories.proxy = { :host=>"proxy.acme.com", :port=>8080 } + # repositories.proxy = "proxy.acme.com:8080" + def proxy=(proxy) + case proxy + when Hash, nil + @proxy = proxy || {} + when String + proxy = "http://#{proxy}" unless proxy =~ /^http(s?)/i + proxy = URI.parse(proxy) + @proxy = { :host=>proxy.host, :port=>proxy.port, :user=>proxy.user, :password=>proxy.password } + when URI + @proxy = { :host=>proxy.host, :port=>proxy.port, :user=>proxy.user, :password=>proxy.password } + else + fail "Expecting a Hash, String or URI." + end + end # :call-seq: # download(spec) => boolean # # Downloads an artifact from one of the remote repositories, and stores it in the local @@ -338,11 +376,11 @@ puts "Downloading #{Artifact.to_spec(spec)}" if Rake.application.options.trace 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| + Transports.perform URI.parse(repo_url.to_s), :proxy=>proxy do |http| mkpath File.dirname(path), :verbose=>false http.download(rel_path, path) begin http.download(rel_path.ext("pom"), path.ext("pom")) rescue Transports::NotFound @@ -465,14 +503,12 @@ # # Using artifacts created by a project: # artifact project("my-app") # All packages # artifact project("mu-app").package(:war) # Only the WAR def artifacts(*specs) - specs.inject([]) do |set, spec| + specs.flatten.inject([]) do |set, spec| case spec - when Array - set |= artifacts(*spec) when Hash set |= [artifact(spec)] when /([^:]+:){2,4}/ # A spec as opposed to a file name. set |= [artifact(spec)] when String # Must always expand path. @@ -510,27 +546,26 @@ # # Deploys all the specified artifacts/files. If the last argument is a Hash, it is used to # specify the deployment repository. Otherwise, obtains the deployment repository by calling # Repositories#deploy_to. # + # When deploying files, you can specify a path relative to the deployment URL. Artifacts are + # always deployed to a path that combined the group identifier, artifact identifier and + # version number. + # # For example: # deploy(foo.packages, :url=>"sftp://example.com/var/www/repo") + # deploy(file("LICENSE"), :path=>group.tr(".", "/")) def deploy(*args) # Where do we release to? - if Hash === args.last - options = args.pop - else - options = repositories.deploy_to.clone - options = { :url=>options.to_s } unless Hash === options - end - # Strip all options since the transport requires them separately from the URL. - url = options[:url] - options = options.reject { |k,v| k === :url } - fail "Don't know where to deploy, perhaps you forgot to set repositories.deploy_to" if url.blank? + options = Hash === args.last ? args.pop : {} + deploy_to = options[:url] ? options : repositories.deploy_to + fail "Don't know where to deploy, perhaps you forgot to set repositories.deploy_to" if deploy_to[:url].blank? args.flatten.each { |arg| arg.invoke if arg.respond_to?(:invoke) } - Transports.perform url, options do |session| + # Strip :url and :path, in case the transport checks for valid options. + Transports.perform deploy_to[:url], deploy_to.reject{ |k,v| k == :url || k == :path } do |session| args.flatten.each do |artifact| if artifact.respond_to?(:to_spec) # Upload artifact relative to base URL, need to create path before uploading. puts "Deploying #{artifact.to_spec}" if verbose spec = artifact.to_spec_hash @@ -538,10 +573,10 @@ session.mkpath path session.upload artifact.to_s, path + Artifact.hash_to_file_name(spec) else # Upload artifact to URL. puts "Deploying #{artifact}" if verbose - session.upload artifact.to_s, File.basename(artifact.to_s) + session.upload artifact.to_s, File.join(*(options[:path].to_a + [File.basename(artifact.to_s)]).compact) end end end end