You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildr.apache.org by as...@apache.org on 2008/01/04 01:19:27 UTC
svn commit: r608685 - in /incubator/buildr/trunk: ./ lib/ lib/core/
lib/java/ lib/tasks/ spec/
Author: assaf
Date: Thu Jan 3 16:19:23 2008
New Revision: 608685
URL: http://svn.apache.org/viewvc?rev=608685&view=rev
Log:
BUILDR-14
Modified:
incubator/buildr/trunk/CHANGELOG
incubator/buildr/trunk/lib/buildr.rb
incubator/buildr/trunk/lib/core/environment.rb
incubator/buildr/trunk/lib/core/transports.rb
incubator/buildr/trunk/lib/java/artifact.rb
incubator/buildr/trunk/lib/java/packaging.rb
incubator/buildr/trunk/lib/tasks/zip.rb
incubator/buildr/trunk/spec/common_spec.rb
incubator/buildr/trunk/spec/compile_spec.rb
incubator/buildr/trunk/spec/sandbox.rb
incubator/buildr/trunk/spec/transport_spec.rb
Modified: incubator/buildr/trunk/CHANGELOG
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/CHANGELOG?rev=608685&r1=608684&r2=608685&view=diff
==============================================================================
--- incubator/buildr/trunk/CHANGELOG (original)
+++ incubator/buildr/trunk/CHANGELOG Thu Jan 3 16:19:23 2008
@@ -2,6 +2,7 @@
* Added: Mechanism to simplify creating extensions (see Extension module).
* Added: To run all test cases 'rake spec'. Test coverage reports will show up in html/coverage. To run failing tests against, 'rake failing'.
* Added: Layout class for controlling the project layout. Also cleaned up places where paths were used instead of path names.
+* Added: HTTP Basic authentication support (Yuen-Chi Lian).
* Changed: Upgraded to Rake 0.8 and RSpec 1.1.
* Changed: Resources are now copied to target/resources instead of target/classes, and target/test/resources instead of target/test-resources.
* Changed: Test cases are not compiled into target/test/classes instead of target/test-classes.
Modified: incubator/buildr/trunk/lib/buildr.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr.rb?rev=608685&r1=608684&r2=608685&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr.rb (original)
+++ incubator/buildr/trunk/lib/buildr.rb Thu Jan 3 16:19:23 2008
@@ -6,19 +6,15 @@
require 'highline'
require 'highline/import'
-# &:symbol goodness.
-require 'facet/symbol/to_proc'
-# blank? on string and nil
-require 'facet/string/blank'
-require 'facet/nilclass/blank'
-# What it says.
-require 'facet/kernel/__DIR__'
-require 'facet/module/alias_method_chain'
-require 'facet/array/head'
-require 'facet/string/starts_with'
-require 'facet/openobject'
-require 'facets/core/kernel/tap'
-require 'facets/core/enumerable/uniq_by'
+require 'facets/symbol/to_proc'
+require 'facets/string/blank'
+require 'facets/kernel/__DIR__'
+require 'facets/module/alias_method_chain'
+require 'facets/string/starts_with'
+require 'facets/openobject'
+require 'facets/kernel/tap'
+require 'facets/enumerable/uniq_by'
+
# A different kind of buildr, one we use to create XML.
require 'builder'
Modified: incubator/buildr/trunk/lib/core/environment.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/core/environment.rb?rev=608685&r1=608684&r2=608685&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/core/environment.rb (original)
+++ incubator/buildr/trunk/lib/core/environment.rb Thu Jan 3 16:19:23 2008
@@ -1,5 +1,4 @@
require 'yaml'
-require 'facet/openobject'
module Buildr
Modified: incubator/buildr/trunk/lib/core/transports.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/core/transports.rb?rev=608685&r1=608684&r2=608685&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/core/transports.rb (original)
+++ incubator/buildr/trunk/lib/core/transports.rb Thu Jan 3 16:19:23 2008
@@ -1,12 +1,13 @@
require "cgi"
require "net/http"
+require "net/https"
require "net/ssh"
require "net/sftp"
require "uri"
require "uri/sftp"
require "digest/md5"
require "digest/sha1"
-require "facet/progressbar"
+require "facets/progressbar"
require "highline"
require "tempfile"
require "uri/sftp"
@@ -309,54 +310,50 @@
# See URI::Generic#read
def read(options = nil, &block)
options ||= {}
-
headers = { "If-Modified-Since" => CGI.rfc1123_date(options[:modified].utc) } if options[:modified]
- result = nil
- request = lambda do |http|
- puts "Requesting #{self}" if Rake.application.options.trace
- http.request_get(path, headers) do |response|
- case response
- when Net::HTTPNotModified
- # No modification, nothing to do.
- puts "Not modified since last download" if Rake.application.options.trace
-
- when Net::HTTPRedirection
- # Try to download from the new URI, handle relative redirects.
- puts "Redirected to #{response['Location']}" if Rake.application.options.trace
- result = (self + URI.parse(response["location"])).read(options, &block)
-
- when Net::HTTPOK
- puts "Downloading #{self}" if verbose
- with_progress_bar options[:progress], path.split("/").last, response.content_length do |progress|
- if block
- response.read_body do |chunk|
- block.call chunk
- progress << chunk
- end
- else
- result = ""
- response.read_body do |chunk|
- result << chunk
- progress << chunk
- end
- end
- end
- when Net::HTTPNotFound
- raise NotFoundError, "Looking for #{self} and all I got was a 404!"
+ if proxy = proxy_uri
+ proxy = URI.parse(proxy) if String === proxy
+ http = Net::HTTP.new(host, port, proxy.host, proxy.port, proxy.user, proxy.password)
+ else
+ http = Net::HTTP.new(host, port)
+ end
+ http.use_ssl = true if self.instance_of? URI::HTTPS
+
+ puts "Requesting #{self}" if Rake.application.options.trace
+ request = Net::HTTP::Get.new(path.blank? ? '/' : path, headers)
+ request.basic_auth self.user, self.password if self.user
+ case response = http.request(request)
+ when Net::HTTPNotModified
+ # No modification, nothing to do.
+ puts "Not modified since last download" if Rake.application.options.trace
+ nil
+ when Net::HTTPRedirection
+ # Try to download from the new URI, handle relative redirects.
+ puts "Redirected to #{response['Location']}" if Rake.application.options.trace
+ (self + URI.parse(response["location"])).read(options, &block)
+ when Net::HTTPOK
+ puts "Downloading #{self}" if verbose
+ with_progress_bar options[:progress], path.split("/").last, response.content_length do |progress|
+ if block
+ response.read_body do |chunk|
+ block.call chunk
+ progress << chunk
+ end
else
- raise RuntimeError, "Failed to download #{self}: #{response.message}"
+ result = ""
+ response.read_body do |chunk|
+ result << chunk
+ progress << chunk
+ end
end
end
- end
-
- if proxy = proxy_uri
- proxy = URI.parse(proxy) if String === proxy
- Net::HTTP.start(host, port, proxy.host, proxy.port, proxy.user, proxy.password) { |http| request[http] }
+ result
+ when Net::HTTPNotFound
+ raise NotFoundError, "Looking for #{self} and all I got was a 404!"
else
- Net::HTTP.start(host, port) { |http| request[http] }
+ raise RuntimeError, "Failed to download #{self}: #{response.message}"
end
- result
end
end
@@ -455,7 +452,7 @@
# See URI::Generic#read
def read(options = nil, &block)
options ||= {}
- raise ArgumentError, "Either you're attempting to read a file from another host (which we don't support), or you used two slashes by mistake, where you should have file:///<path>." unless host.blank?
+ raise ArgumentError, "Either you're attempting to read a file from another host (which we don't support), or you used two slashes by mistake, where you should have file:///<path>." unless host.to_s.blank?
path = real_path
# TODO: complain about clunky URLs
@@ -482,7 +479,7 @@
protected
def write_internal(options, &block) #:nodoc:
- raise ArgumentError, "Either you're attempting to write a file to another host (which we don't support), or you used two slashes by mistake, where you should have file:///<path>." unless host.blank?
+ raise ArgumentError, "Either you're attempting to write a file to another host (which we don't support), or you used two slashes by mistake, where you should have file:///<path>." unless host.to_s.blank?
temp = nil
Tempfile.open File.basename(path) do |temp|
temp.binmode
Modified: incubator/buildr/trunk/lib/java/artifact.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/java/artifact.rb?rev=608685&r1=608684&r2=608685&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/java/artifact.rb (original)
+++ incubator/buildr/trunk/lib/java/artifact.rb Thu Jan 3 16:19:23 2008
@@ -53,7 +53,7 @@
# :version=>"1.2" }
def to_spec_hash()
base = { :group=>group, :id=>id, :type=>type, :version=>version }
- classifier.blank? ? base : base.merge(:classifier=>classifier)
+ classifier.to_s.blank? ? base : base.merge(:classifier=>classifier)
end
alias_method :to_hash, :to_spec_hash
@@ -65,7 +65,7 @@
# or
# <group>:<artifact>:<type>:<classifier><:version>
def to_spec()
- classifier.blank? ? "#{group}:#{id}:#{type}:#{version}" : "#{group}:#{id}:#{type}:#{classifier}:#{version}"
+ classifier.to_s.blank? ? "#{group}:#{id}:#{type}:#{version}" : "#{group}:#{id}:#{type}:#{classifier}:#{version}"
end
# :call-seq:
@@ -108,7 +108,7 @@
# Where do we release to?
upload_to ||= Buildr.repositories.release_to
upload_to = { :url=>upload_to } unless Hash === upload_to
- raise ArgumentError, "Don't know where to upload, perhaps you forgot to set repositories.release_to" if upload_to[:url].blank?
+ raise ArgumentError, "Don't know where to upload, perhaps you forgot to set repositories.release_to" if upload_to[:url].to_s.blank?
# Set the upload URI, including mandatory slash (we expect it to be the base directory).
# Username/password may be part of URI, or separate entities.
@@ -203,10 +203,10 @@
rake_check_options spec, :id, :group, :type, :classifier, :version
# Sanitize the hash and check it's valid.
spec = ARTIFACT_ATTRIBUTES.inject({}) { |h, k| h[k] = spec[k].to_s if spec[k] ; h }
- fail "Missing group identifier for #{spec.inspect}" if spec[:group].blank?
- fail "Missing artifact identifier for #{spec.inspect}" if spec[:id].blank?
- fail "Missing version for #{spec.inspect}" if spec[:version].blank?
- spec[:type] = spec[:type].blank? ? DEFAULT_TYPE : spec[:type].to_sym
+ fail "Missing group identifier for #{spec.inspect}" if spec[:group].to_s.blank?
+ fail "Missing artifact identifier for #{spec.inspect}" if spec[:id].to_s.blank?
+ fail "Missing version for #{spec.inspect}" if spec[:version].to_s.blank?
+ spec[:type] = spec[:type].to_s.blank? ? DEFAULT_TYPE : spec[:type].to_sym
spec
elsif String === spec
group, id, type, version, *rest = spec.split(":")
@@ -228,8 +228,8 @@
# a string, hash or any object that responds to to_spec.
def to_spec(hash)
hash = to_hash(hash) unless Hash === hash
- version = ":#{hash[:version]}" unless hash[:version].blank?
- classifier = ":#{hash[:classifier]}" unless hash[:classifier].blank?
+ version = ":#{hash[:version]}" unless hash[:version].to_s.blank?
+ classifier = ":#{hash[:classifier]}" unless hash[:classifier].to_s.blank?
"#{hash[:group]}:#{hash[:id]}:#{hash[:type] || DEFAULT_TYPE}#{classifier}#{version}"
end
@@ -238,8 +238,8 @@
#
# Convert a hash spec to a file name.
def hash_to_file_name(hash)
- version = "-#{hash[:version]}" unless hash[:version].blank?
- classifier = "-#{hash[:classifier]}" unless hash[:classifier].blank?
+ version = "-#{hash[:version]}" unless hash[:version].to_s.blank?
+ classifier = "-#{hash[:classifier]}" unless hash[:classifier].to_s.blank?
"#{hash[:id]}#{version}#{classifier}.#{hash[:type] || DEFAULT_TYPE}"
end
Modified: incubator/buildr/trunk/lib/java/packaging.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/java/packaging.rb?rev=608685&r1=608684&r2=608685&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/java/packaging.rb (original)
+++ incubator/buildr/trunk/lib/java/packaging.rb Thu Jan 3 16:19:23 2008
@@ -17,7 +17,7 @@
module WithManifest #:nodoc:
def self.included(base)
- base.alias_method_chain :initialize, :manifest
+ base.send :alias_method_chain, :initialize, :manifest
end
MANIFEST_HEADER = ["Manifest-Version: 1.0", "Created-By: Buildr"]
Modified: incubator/buildr/trunk/lib/tasks/zip.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/tasks/zip.rb?rev=608685&r1=608684&r2=608685&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/tasks/zip.rb (original)
+++ incubator/buildr/trunk/lib/tasks/zip.rb Thu Jan 3 16:19:23 2008
@@ -16,7 +16,7 @@
def initialize(root, path)
@root = root
- @path = path.blank? ? path : "#{path}/"
+ @path = path.to_s.blank? ? path : "#{path}/"
@includes = FileList[]
@excludes = []
# Expand source files added to this path.
@@ -108,7 +108,7 @@
# Returns a Path relative to this one.
def path(path)
- return self if path.blank?
+ return self if path.to_s.blank?
return root.path(path[1..-1]) if path[0] == ?/
root.path("#{@path}#{path}")
end
@@ -215,7 +215,7 @@
mkpath File.dirname(name), :verbose=>false
begin
@paths.each do |name, object|
- @file_map[name] = nil unless name.blank?
+ @file_map[name] = nil unless name.to_s.blank?
object.add_files(@file_map)
end
create_from @file_map
@@ -299,7 +299,7 @@
# path("foo").path("bar") == path("foo/bar")
# path("foo").root == root
def path(name)
- return @paths[""] if name.blank?
+ return @paths[""] if name.to_s.blank?
normalized = name.split("/").inject([]) do |path, part|
case part
when ".", nil, ""
Modified: incubator/buildr/trunk/spec/common_spec.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/common_spec.rb?rev=608685&r1=608684&r2=608685&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/common_spec.rb (original)
+++ incubator/buildr/trunk/spec/common_spec.rb Thu Jan 3 16:19:23 2008
@@ -80,7 +80,11 @@
describe Buildr.method(:download) do
- before { @content = "we has download!" }
+ before do
+ @content = "we has download!"
+ @http = mock('http')
+ @http.stub!(:request).and_return(Net::HTTPNotModified.new(nil, nil, nil))
+ end
def tasks()
[ download("http://localhost/download"), download("downloaded"=>"http://localhost/download") ]
@@ -155,19 +159,19 @@
end
it "should execute without a proxy if none specified" do
- Net::HTTP.should_receive(:start).with("localhost", 80).twice
+ Net::HTTP.should_receive(:new).with("localhost", 80).twice.and_return(@http)
tasks.each(&:invoke)
end
it "should pass Buildr proxy options" do
Buildr.options.proxy.http = "http://proxy:8080"
- Net::HTTP.should_receive(:start).with("localhost", 80, "proxy", 8080, nil, nil).twice
+ Net::HTTP.should_receive(:new).with("localhost", 80, "proxy", 8080, nil, nil).twice.and_return(@http)
tasks.each(&:invoke)
end
it "should set HTTP proxy from HTTP_PROXY environment variable" do
ENV["HTTP_PROXY"] = "http://proxy:8080"
- Net::HTTP.should_receive(:start).with("localhost", 80, "proxy", 8080, nil, nil).twice
+ Net::HTTP.should_receive(:new).with("localhost", 80, "proxy", 8080, nil, nil).twice.and_return(@http)
tasks.each(&:invoke)
end
end
@@ -440,6 +444,8 @@
@uri = URI("http://#{@host}")
@no_proxy_args = [@host, 80]
@proxy_args = @no_proxy_args + ["myproxy", 8080, nil, nil]
+ @http = mock('http')
+ @http.stub!(:request).and_return(Net::HTTPNotModified.new(nil, nil, nil))
end
it "should be an array" do
@@ -460,35 +466,35 @@
end
it "should use proxy when not excluded" do
- Net::HTTP.should_receive(:start).with(*@proxy_args)
+ Net::HTTP.should_receive(:new).with(*@proxy_args).and_return(@http)
@uri.read :proxy=>options.proxy
end
it "should use proxy unless excluded" do
options.proxy.exclude = "not.#{@domain}"
- Net::HTTP.should_receive(:start).with(*@proxy_args)
+ Net::HTTP.should_receive(:new).with(*@proxy_args).and_return(@http)
@uri.read :proxy=>options.proxy
end
it "should not use proxy if excluded" do
options.proxy.exclude = @host
- Net::HTTP.should_receive(:start).with(*@no_proxy_args)
+ Net::HTTP.should_receive(:new).with(*@no_proxy_args).and_return(@http)
@uri.read :proxy=>options.proxy
end
it "should support multiple host names" do
options.proxy.exclude = ["optimus", "prime"]
- Net::HTTP.should_receive(:start).with("optimus", 80)
+ Net::HTTP.should_receive(:new).with("optimus", 80).and_return(@http)
URI("http://optimus").read :proxy=>options.proxy
- Net::HTTP.should_receive(:start).with("prime", 80)
+ Net::HTTP.should_receive(:new).with("prime", 80).and_return(@http)
URI("http://prime").read :proxy=>options.proxy
- Net::HTTP.should_receive(:start).with("bumblebee", *@proxy_args.tail)
+ Net::HTTP.should_receive(:new).with("bumblebee", *@proxy_args[1..-1]).and_return(@http)
URI("http://bumblebee").read :proxy=>options.proxy
end
it "should support glob pattern on host name" do
options.proxy.exclude = "*.#{@domain}"
- Net::HTTP.should_receive(:start).with(*@no_proxy_args)
+ Net::HTTP.should_receive(:new).with(*@no_proxy_args).and_return(@http)
@uri.read :proxy=>options.proxy
end
end
Modified: incubator/buildr/trunk/spec/compile_spec.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/compile_spec.rb?rev=608685&r1=608684&r2=608685&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/compile_spec.rb (original)
+++ incubator/buildr/trunk/spec/compile_spec.rb Thu Jan 3 16:19:23 2008
@@ -749,7 +749,7 @@
make_sources
define 'foo'
project('foo').javadoc.exclude @sources.first
- project('foo').javadoc.source_files.sort.should == @sources.tail #[1..-1]
+ project('foo').javadoc.source_files.sort.should == @sources[1..-1]
end
it 'should respond to using() and return self' do
Modified: incubator/buildr/trunk/spec/sandbox.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/sandbox.rb?rev=608685&r1=608684&r2=608685&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/sandbox.rb (original)
+++ incubator/buildr/trunk/spec/sandbox.rb Thu Jan 3 16:19:23 2008
@@ -111,7 +111,7 @@
def all_ran?()
@remaining ||= $executed.inject(@expecting) do |expecting, executed|
- expecting.map { |tasks| tasks.first == executed ? tasks.tail : tasks }.reject(&:empty?)
+ expecting.map { |tasks| tasks.first == executed ? tasks[1..-1] : tasks }.reject(&:empty?)
end
@remaining.empty?
end
Modified: incubator/buildr/trunk/spec/transport_spec.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/transport_spec.rb?rev=608685&r1=608684&r2=608685&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/transport_spec.rb (original)
+++ incubator/buildr/trunk/spec/transport_spec.rb Thu Jan 3 16:19:23 2008
@@ -209,58 +209,60 @@
@uri = URI("http://#{@host_domain}")
@no_proxy_args = [@host_domain, 80]
@proxy_args = @no_proxy_args + ["myproxy", 8080, "john", "smith"]
+ @http = mock('http')
+ @http.stub!(:request).and_return(Net::HTTPNotModified.new(nil, nil, nil))
end
it "should not use proxy unless proxy is set" do
- Net::HTTP.should_receive(:start).with(*@no_proxy_args)
+ Net::HTTP.should_receive(:new).with(*@no_proxy_args).and_return(@http)
@uri.read
end
it "should use proxy from environment variable HTTP_PROXY" do
ENV["HTTP_PROXY"] = @proxy
- Net::HTTP.should_receive(:start).with(*@proxy_args)
+ Net::HTTP.should_receive(:new).with(*@proxy_args).and_return(@http)
@uri.read
end
it "should not use proxy for hosts from environment variable NO_PROXY" do
ENV["HTTP_PROXY"] = @proxy
ENV["NO_PROXY"] = @host_domain
- Net::HTTP.should_receive(:start).with(*@no_proxy_args)
+ Net::HTTP.should_receive(:new).with(*@no_proxy_args).and_return(@http)
@uri.read
end
it "should use proxy for hosts other than those specified by NO_PROXY" do
ENV["HTTP_PROXY"] = @proxy
ENV["NO_PROXY"] = "whatever"
- Net::HTTP.should_receive(:start).with(*@proxy_args)
+ Net::HTTP.should_receive(:new).with(*@proxy_args).and_return(@http)
@uri.read
end
it "should support comma separated list in environment variable NO_PROXY" do
ENV["HTTP_PROXY"] = @proxy
ENV["NO_PROXY"] = "optimus,prime"
- Net::HTTP.should_receive(:start).with("optimus", 80)
+ Net::HTTP.should_receive(:new).with("optimus", 80).and_return(@http)
URI("http://optimus").read
- Net::HTTP.should_receive(:start).with("prime", 80)
+ Net::HTTP.should_receive(:new).with("prime", 80).and_return(@http)
URI("http://prime").read
- Net::HTTP.should_receive(:start).with("bumblebee", *@proxy_args.tail)
+ Net::HTTP.should_receive(:new).with("bumblebee", *@proxy_args[1..-1]).and_return(@http)
URI("http://bumblebee").read
end
it "should support glob pattern in NO_PROXY" do
ENV["HTTP_PROXY"] = @proxy
ENV["NO_PROXY"] = "*.#{@domain}"
- Net::HTTP.should_receive(:start).once.with(*@no_proxy_args)
+ Net::HTTP.should_receive(:new).once.with(*@no_proxy_args).and_return(@http)
@uri.read
end
it "should support specific port in NO_PROXY" do
ENV["HTTP_PROXY"] = @proxy
ENV["NO_PROXY"] = "#{@host_domain}:80"
- Net::HTTP.should_receive(:start).with(*@no_proxy_args)
+ Net::HTTP.should_receive(:new).with(*@no_proxy_args).and_return(@http)
@uri.read
ENV["NO_PROXY"] = "#{@host_domain}:800"
- Net::HTTP.should_receive(:start).with(*@proxy_args)
+ Net::HTTP.should_receive(:new).with(*@proxy_args).and_return(@http)
@uri.read
end