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/04/09 01:48:56 UTC
svn commit: r646140 - in /incubator/buildr/trunk: lib/buildr/core/
lib/buildr/ide/ lib/buildr/packaging/ spec/
Author: assaf
Date: Tue Apr 8 16:48:55 2008
New Revision: 646140
URL: http://svn.apache.org/viewvc?rev=646140&view=rev
Log:
Buildr.settings is now alias for Buildr.application.settings which provides access to settings.yaml, build.yaml and profiles.yaml.
Using settings.yaml and build.yaml for local, remote and release_to repository settings.
Removed:
incubator/buildr/trunk/spec/addon_spec.rb
Modified:
incubator/buildr/trunk/lib/buildr/core/application.rb
incubator/buildr/trunk/lib/buildr/core/compile.rb
incubator/buildr/trunk/lib/buildr/core/environment.rb
incubator/buildr/trunk/lib/buildr/ide/eclipse.rb
incubator/buildr/trunk/lib/buildr/ide/idea.rb
incubator/buildr/trunk/lib/buildr/ide/idea7x.rb
incubator/buildr/trunk/lib/buildr/packaging/artifact.rb
incubator/buildr/trunk/spec/application_spec.rb
incubator/buildr/trunk/spec/artifact_spec.rb
incubator/buildr/trunk/spec/compile_spec.rb
incubator/buildr/trunk/spec/sandbox.rb
incubator/buildr/trunk/spec/spec_helpers.rb
Modified: incubator/buildr/trunk/lib/buildr/core/application.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/core/application.rb?rev=646140&r1=646139&r2=646140&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/core/application.rb (original)
+++ incubator/buildr/trunk/lib/buildr/core/application.rb Tue Apr 8 16:48:55 2008
@@ -48,6 +48,65 @@
module Buildr
+ # Provide settings that come from three sources.
+ #
+ # User settings are placed in the .buildr/settings.yaml file located in the user's home directory.
+ # The should only be used for settings that are specific to the user and applied the same way
+ # across all builds. Example for user settings are preferred repositories, path to local repository,
+ # user/name password for uploading to remote repository.
+ #
+ # Build settings are placed in the build.yaml file located in the build directory. They help keep
+ # the buildfile and build.yaml file simple and readable, working to the advantages of each one.
+ # Example for build settings are gems, repositories and artifacts used by that build.
+ #
+ # Profile settings are placed in the profiles.yaml file located in the build directory. They provide
+ # settings that differ in each environment the build runs in. For example, URLs and database
+ # connections will be different when used in development, test and production environments.
+ # The settings for the current environment are obtained by calling #profile.
+ class Settings
+
+ def initialize(application) #:nodoc:
+ @application = application
+ @user = load_from('settings', @application.home_dir)
+ @build = load_from('build')
+ @profiles = load_from('profiles')
+ # .inject({}) { |hash, (name, value)|
+ # value ||= {}
+ # raise 'Each profile must be empty or contain name/value pairs.' unless Hash === value
+ # hash.update(name=>value) }
+ end
+
+ # User settings loaded from setting.yaml file in user's home directory.
+ attr_reader :user
+
+ # Build settings loaded from build.yaml file in build directory.
+ attr_reader :build
+
+ # Profiles loaded from profiles.yaml file in build directory.
+ attr_reader :profiles
+
+ # :call-seq:
+ # profile => hash
+ #
+ # Returns the profile for the current environment.
+ def profile
+ profiles[@application.environment] ||= {}
+ end
+
+ private
+
+ def load_from(base_name, dir = nil)
+ file_name = ['yaml', 'yml'].map { |ext| File.expand_path("#{base_name}.#{ext}", dir) }.find { |fn| File.exist?(fn) }
+ return {} unless file_name
+ yaml = YAML.load(File.read(file_name)) || {}
+ fail "Expecting #{file_name} to be a map (name: value)!" unless Hash === yaml
+ @application.build_files << file_name
+ yaml
+ end
+
+ end
+
+
class Application < Rake::Application #:nodoc:
DEFAULT_BUILDFILES = ['buildfile', 'Buildfile'] + DEFAULT_RAKEFILES
@@ -81,48 +140,9 @@
# Copied from BUILD_ENV.
attr_reader :environment
- # User settings loaded from settings.yaml (Hash).
+ # Returns the Settings associated with this build.
def settings
- unless @settings
- file_name = ['settings.yaml', 'settings.yml'].map { |fn| File.expand_path(fn, home_dir) }.find { |fn| File.exist?(fn) }
- @settings = file_name && YAML.load(File.read(file_name)) || {}
- fail "Expecting #{file_name} to be a hash!" unless Hash === @settings
- end
- @settings
- end
-
- # Configuration loaded from build.yaml (Hash).
- def configuration
- unless @config
- file_name = ['build.yaml', 'build.yml'].map { |fn| File.expand_path(fn, File.dirname(buildfile)) }.find { |fn| File.exist?(fn) }
- @config = file_name && YAML.load(File.read(file_name)) || {}
- fail "Expecting #{file_name} to be a hash!" unless Hash === @config
- end
- @config
- end
-
- # :call-seq:
- # profile => hash
- #
- # Returns the profile for the current environment.
- def profile
- profiles[environment] ||= {}
- end
-
- # :call-seq:
- # profiles => hash
- #
- # Returns all the profiles loaded from the profiles.yaml file.
- def profiles
- unless @profiles
- file_name = ['profiles.yaml', 'profiles.yml'].map { |fn| File.expand_path(fn, File.dirname(buildfile)) }.find { |fn| File.exist?(fn) }
- @profiles = file_name && YAML.load(File.read(file_name)) || {}
- fail "Expecting #{file_name} to be a hash!" unless Hash === @profiles
- @profiles = profiles.inject({}) { |hash, (name, value)| value ||= {}
- raise 'Each profile must be empty or contain name/value pairs.' unless Hash === value
- hash.merge(name=>(value || {})) }
- end
- @profiles
+ @settings ||= Settings.new(self)
end
# :call-seq:
@@ -142,7 +162,7 @@
# Returns Gem::Specification for every listed and installed Gem, Gem::Dependency
# for listed and uninstalled Gem, which is the installed before loading the buildfile.
def listed_gems #:nodoc:
- Array(configuration['gems']).map do |dep|
+ Array(settings.build['gems']).map do |dep|
name, trail = dep.scan(/^\s*(\S*)\s*(.*)\s*$/).first
versions = trail.scan(/[=><~!]{0,2}\s*[\d\.]+/)
versions = ['>= 0'] if versions.empty?
@@ -280,14 +300,6 @@
class << self
- # :call-seq:
- # build_files => files
- #
- # Returns a list of build files. These are files used by the build,
- def build_files
- Buildr.application.build_files
- end
-
task 'buildr:initialize' do
Buildr.load_tasks_and_local_files
end
@@ -299,6 +311,10 @@
def application=(app)
Rake.application = app
+ end
+
+ def settings
+ Buildr.application.settings
end
end
Modified: incubator/buildr/trunk/lib/buildr/core/compile.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/core/compile.rb?rev=646140&r1=646139&r2=646140&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/core/compile.rb (original)
+++ incubator/buildr/trunk/lib/buildr/core/compile.rb Tue Apr 8 16:48:55 2008
@@ -401,7 +401,7 @@
def initialize(*args) #:nodoc:
super
@filter = Buildr::Filter.new
- @filter.using Buildr.profile['filter'] if Buildr.profile['filter']
+ @filter.using Buildr.settings.profile['filter'] if Hash === Buildr.settings.profile['filter']
enhance do
filter.run if target && !sources.empty?
end
@@ -479,7 +479,6 @@
resources = ResourcesTask.define_task('resources')
resources.send :associate_with, project, :main
project.path_to(:source, :main, :resources).tap { |dir| resources.from dir if File.exist?(dir) }
- resources.filter.using Buildr.profile
compile = CompileTask.define_task('compile'=>resources)
compile.send :associate_with, project, :main
Modified: incubator/buildr/trunk/lib/buildr/core/environment.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/core/environment.rb?rev=646140&r1=646139&r2=646140&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/core/environment.rb (original)
+++ incubator/buildr/trunk/lib/buildr/core/environment.rb Tue Apr 8 16:48:55 2008
@@ -117,8 +117,4 @@
Buildr.options
end
- def profile
- application.profile
- end
-
end
Modified: incubator/buildr/trunk/lib/buildr/ide/eclipse.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/ide/eclipse.rb?rev=646140&r1=646139&r2=646140&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/ide/eclipse.rb (original)
+++ incubator/buildr/trunk/lib/buildr/ide/eclipse.rb Tue Apr 8 16:48:55 2008
@@ -42,7 +42,7 @@
# the Buildfile (buildr.rb, separate file listing dependencies, etc), so we add anything required
# after the Buildfile. So which don't know where Buildr shows up exactly, ignore files that show
# in $LOADED_FEATURES that we cannot resolve.
- sources = Buildr.build_files.map { |file| File.expand_path(file) }.select { |file| File.exist?(file) }
+ sources = Buildr.application.build_files.map { |file| File.expand_path(file) }.select { |file| File.exist?(file) }
sources << File.expand_path(Buildr.application.buildfile, root_path) if Buildr.application.buildfile
# Check if project has scala facet
Modified: incubator/buildr/trunk/lib/buildr/ide/idea.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/ide/idea.rb?rev=646140&r1=646139&r2=646140&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/ide/idea.rb (original)
+++ incubator/buildr/trunk/lib/buildr/ide/idea.rb Tue Apr 8 16:48:55 2008
@@ -43,7 +43,7 @@
# the Buildfile (buildr.rb, separate file listing dependencies, etc), so we add anything required
# after the Buildfile. So which don't know where Buildr shows up exactly, ignore files that show
# in $LOADED_FEATURES that we cannot resolve.
- sources = Buildr.build_files.map { |file| File.expand_path(file) }.select { |file| File.exist?(file) }
+ sources = Buildr.application.build_files.map { |file| File.expand_path(file) }.select { |file| File.exist?(file) }
sources << File.expand_path(Buildr.application.buildfile, root_path) if Buildr.application.buildfile
# Find a path relative to the project's root directory.
Modified: incubator/buildr/trunk/lib/buildr/ide/idea7x.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/ide/idea7x.rb?rev=646140&r1=646139&r2=646140&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/ide/idea7x.rb (original)
+++ incubator/buildr/trunk/lib/buildr/ide/idea7x.rb Tue Apr 8 16:48:55 2008
@@ -49,7 +49,7 @@
# We need paths relative to the top project's base directory.
root_path = lambda { |p| f = lambda { |p| p.parent ? f[p.parent] : p.base_dir }; f[p] }[project]
- sources = Buildr.build_files.map { |file| File.expand_path(file) }.select { |file| File.exist?(file) }
+ sources = Buildr.application.build_files.map { |file| File.expand_path(file) }.select { |file| File.exist?(file) }
sources << File.expand_path(Buildr.application.buildfile, root_path) if Buildr.application.buildfile
# Find a path relative to the project's root directory.
Modified: incubator/buildr/trunk/lib/buildr/packaging/artifact.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/packaging/artifact.rb?rev=646140&r1=646139&r2=646140&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/packaging/artifact.rb (original)
+++ incubator/buildr/trunk/lib/buildr/packaging/artifact.rb Tue Apr 8 16:48:55 2008
@@ -424,8 +424,12 @@
# 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.
def local
- @local ||= File.expand_path(ENV['M2_REPO'] || ENV['local_repo'] || File.join(ENV['HOME'], '.m2/repository'))
+ @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
# :call-seq:
@@ -462,8 +466,23 @@
# 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
def remote
- @remote ||= []
+ unless @remote
+ @remote = [Buildr.settings.user, Buildr.settings.build].inject([]) { |repos, hash|
+ repos | Array(hash['repositories'] && hash['repositories']['remote'])
+ }
+ end
+ @remote
end
# :call-seq:
@@ -478,12 +497,9 @@
# With nil, clears the array.
def remote=(urls)
case urls
- when nil
- @remote = nil
- when Array
- @remote = urls.dup
- else
- @remote = [urls.to_s]
+ when nil then @remote = nil
+ when Array then @remote = urls.dup
+ else @remote = [urls.to_s]
end
end
@@ -498,8 +514,18 @@
#
# 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
def release_to=(options)
options = { :url=>options } unless Hash === options
@release_to = options
@@ -517,7 +543,11 @@
# repositories.release_to[:username] = 'john'
# repositories.release_to[:password] = 'secret'
def release_to
- @release_to ||= {}
+ unless @release_to
+ value = Buildr.settings.user['repositories'] && Buildr.settings.user['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
end
Modified: incubator/buildr/trunk/spec/application_spec.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/application_spec.rb?rev=646140&r1=646139&r2=646140&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/application_spec.rb (original)
+++ incubator/buildr/trunk/spec/application_spec.rb Tue Apr 8 16:48:55 2008
@@ -18,114 +18,15 @@
describe Buildr::Application do
- before :each do
- @app = Buildr.application
- end
-
describe 'home_dir' do
it 'should point to ~/.buildr' do
- @app.home_dir.should eql(File.expand_path('.buildr', ENV['HOME']))
+ Buildr.application.home_dir.should eql(File.expand_path('.buildr', ENV['HOME']))
end
it 'should point to existing directory' do
- File.directory?(@app.home_dir).should be_true
- end
- end
-
-
- describe 'settings' do
- it 'should be empty hash if no settings.yaml file' do
- @app.settings.should == {}
- end
-
- it 'should return loaded settings.yaml file' do
- write 'home/.buildr/settings.yaml', 'foo: bar'
- @app.settings.should == { 'foo'=>'bar' }
- end
-
- it 'should fail if settings.yaml file is not a hash' do
- write 'home/.buildr/settings.yaml', 'foo bar'
- lambda { @app.settings }.should raise_error(RuntimeError, /expecting.*settings.yaml/i)
- end
-
- it 'should be empty hash if settings.yaml file is empty' do
- write 'home/.buildr/settings.yaml'
- @app.settings.should == {}
- end
- end
-
-
- describe 'configuration' do
- it 'should be empty hash if no build.yaml file' do
- @app.configuration.should == {}
- end
-
- it 'should return loaded build.yaml file' do
- write 'build.yaml', 'foo: bar'
- @app.configuration.should == { 'foo'=>'bar' }
- end
-
- it 'should fail if build.yaml file is not a hash' do
- write 'build.yaml', 'foo bar'
- lambda { @app.configuration }.should raise_error(RuntimeError, /expecting.*build.yaml/i)
- end
-
- it 'should be empty hash if build.yaml file is empty' do
- write 'build.yaml'
- @app.configuration.should == {}
- end
- end
-
-
- describe 'profiles' do
- it 'should be empty hash if no profiles.yaml file' do
- @app.profiles.should == {}
- end
-
- it 'should return loaded profiles.yaml file' do
- write 'profiles.yaml', <<-YAML
- development:
- foo: bar
- YAML
- @app.profiles.should == { 'development'=> { 'foo'=>'bar' } }
- end
-
- it 'should fail if profiles.yaml file is not a hash' do
- write 'profiles.yaml', 'foo bar'
- lambda { @app.profiles }.should raise_error(RuntimeError, /expecting.*profiles.yaml/i)
- end
-
- it 'should be empty hash if profiles.yaml file is empty' do
- write 'profiles.yaml'
- @app.profiles.should == {}
- end
- end
-
-
- describe 'profile' do
- it 'should be empty hash if no profiles.yaml' do
- @app.profile.should == {}
- end
-
- it 'should be empty hash if no matching profile' do
- write 'profiles.yaml', <<-YAML
- test:
- foo: bar
- YAML
- @app.profile.should == {}
+ File.directory?(Buildr.application.home_dir).should be_true
end
-
- it 'should return profile matching environment name' do
- write 'profiles.yaml', <<-YAML
- development:
- foo: bar
- test:
- foo: baz
- YAML
- @app.profile.should == { 'foo'=>'bar' }
- end
-
end
@@ -137,32 +38,32 @@
- rspec
- rake >= 0.8
YAML
- @app.load_gems
+ Buildr.application.load_gems
end
it 'should return empty array if no gems specified' do
- @app.load_gems
- @app.gems.should be_empty
+ Buildr.application.load_gems
+ Buildr.application.gems.should be_empty
end
it 'should return one entry for each gem specified in buildr.yaml' do
load_with_yaml
- @app.gems.size.should be(2)
+ Buildr.application.gems.size.should be(2)
end
it 'should return a Gem::Specification for each installed gem' do
load_with_yaml
- @app.gems.each { |gem| gem.should be_kind_of(Gem::Specification) }
+ Buildr.application.gems.each { |gem| gem.should be_kind_of(Gem::Specification) }
end
it 'should parse Gem name correctly' do
load_with_yaml
- @app.gems.map(&:name).should include('rake', 'rspec')
+ Buildr.application.gems.map(&:name).should include('rake', 'rspec')
end
it 'should find installed version of Gem' do
load_with_yaml
- @app.gems.each { |gem| gem.version.should eql(Gem.loaded_specs[gem.name].version) }
+ Buildr.application.gems.each { |gem| gem.version.should eql(Gem.loaded_specs[gem.name].version) }
end
end
@@ -176,100 +77,100 @@
end
it 'should do nothing if no gems specified' do
- lambda { @app.load_gems }.should_not raise_error
+ lambda { Buildr.application.load_gems }.should_not raise_error
end
it 'should install nothing if specified gems already installed' do
- @app.should_receive(:listed_gems).and_return([Gem.loaded_specs['rspec']])
+ Buildr.application.should_receive(:listed_gems).and_return([Gem.loaded_specs['rspec']])
Util.should_not_receive(:ruby)
- lambda { @app.load_gems }.should_not raise_error
+ lambda { Buildr.application.load_gems }.should_not raise_error
end
it 'should fail if required gem not found in remote repository' do
- @app.should_receive(:listed_gems).and_return([Gem::Dependency.new('foo', '>=1.1')])
+ Buildr.application.should_receive(:listed_gems).and_return([Gem::Dependency.new('foo', '>=1.1')])
Gem::SourceInfoCache.should_receive(:search).and_return([])
- lambda { @app.load_gems }.should raise_error(LoadError, /cannot be found/i)
+ lambda { Buildr.application.load_gems }.should raise_error(LoadError, /cannot be found/i)
end
it 'should fail if need to install gem and not running in interactive mode' do
- @app.should_receive(:listed_gems).and_return([Gem::Dependency.new('foo', '>=1.1')])
+ Buildr.application.should_receive(:listed_gems).and_return([Gem::Dependency.new('foo', '>=1.1')])
Gem::SourceInfoCache.should_receive(:search).and_return([@spec])
$stdout.should_receive(:isatty).and_return(false)
- lambda { @app.load_gems }.should raise_error(LoadError, /this build requires the gems/i)
+ lambda { Buildr.application.load_gems }.should raise_error(LoadError, /this build requires the gems/i)
end
it 'should ask permission before installing required gems' do
- @app.should_receive(:listed_gems).and_return([Gem::Dependency.new('foo', '>=1.1')])
+ Buildr.application.should_receive(:listed_gems).and_return([Gem::Dependency.new('foo', '>=1.1')])
Gem::SourceInfoCache.should_receive(:search).and_return([@spec])
$terminal.should_receive(:agree).with(/install/, true)
- lambda { @app.load_gems }.should raise_error
+ lambda { Buildr.application.load_gems }.should raise_error
end
it 'should fail if permission not granted to install gem' do
- @app.should_receive(:listed_gems).and_return([Gem::Dependency.new('foo', '>=1.1')])
+ Buildr.application.should_receive(:listed_gems).and_return([Gem::Dependency.new('foo', '>=1.1')])
Gem::SourceInfoCache.should_receive(:search).and_return([@spec])
$terminal.should_receive(:agree).and_return(false)
- lambda { @app.load_gems }.should raise_error(LoadError, /cannot build without/i)
+ lambda { Buildr.application.load_gems }.should raise_error(LoadError, /cannot build without/i)
end
it 'should install gem if permission granted' do
- @app.should_receive(:listed_gems).and_return([Gem::Dependency.new('foo', '>=1.1')])
+ Buildr.application.should_receive(:listed_gems).and_return([Gem::Dependency.new('foo', '>=1.1')])
Gem::SourceInfoCache.should_receive(:search).and_return([@spec])
$terminal.should_receive(:agree).and_return(true)
Util.should_receive(:ruby) do |*args|
args.should include('install', 'foo', '-v', '1.2')
end
- @app.should_receive(:gem).and_return(false)
- @app.load_gems
+ Buildr.application.should_receive(:gem).and_return(false)
+ Buildr.application.load_gems
end
it 'should reload gem cache after installing required gems' do
- @app.should_receive(:listed_gems).and_return([Gem::Dependency.new('foo', '>=1.1')])
+ Buildr.application.should_receive(:listed_gems).and_return([Gem::Dependency.new('foo', '>=1.1')])
Gem::SourceInfoCache.should_receive(:search).and_return([@spec])
$terminal.should_receive(:agree).and_return(true)
Util.should_receive(:ruby)
Gem.source_index.should_receive(:load_gems_in).with(Gem::SourceIndex.installed_spec_directories)
- @app.should_receive(:gem).and_return(false)
- @app.load_gems
+ Buildr.application.should_receive(:gem).and_return(false)
+ Buildr.application.load_gems
end
it 'should load previously installed gems' do
- @app.should_receive(:listed_gems).and_return([Gem.loaded_specs['rspec']])
- @app.should_receive(:gem).with('rspec', Gem.loaded_specs['rspec'].version.to_s)
- @app.load_gems
+ Buildr.application.should_receive(:listed_gems).and_return([Gem.loaded_specs['rspec']])
+ Buildr.application.should_receive(:gem).with('rspec', Gem.loaded_specs['rspec'].version.to_s)
+ Buildr.application.load_gems
end
it 'should load newly installed gems' do
- @app.should_receive(:listed_gems).and_return([Gem::Dependency.new('foo', '>=1.1')])
+ Buildr.application.should_receive(:listed_gems).and_return([Gem::Dependency.new('foo', '>=1.1')])
Gem::SourceInfoCache.should_receive(:search).and_return([@spec])
$terminal.should_receive(:agree).and_return(true)
Util.should_receive(:ruby)
- @app.should_receive(:gem).with('foo', @spec.version.to_s)
- @app.load_gems
+ Buildr.application.should_receive(:gem).with('foo', @spec.version.to_s)
+ Buildr.application.load_gems
end
it 'should default to >=0 version requirement if not specified' do
write 'build.yaml', 'gems: foo'
Gem::SourceInfoCache.should_receive(:search).with(Gem::Dependency.new('foo', '>=0')).and_return([])
- lambda { @app.load_gems }.should raise_error
+ lambda { Buildr.application.load_gems }.should raise_error
end
it 'should parse exact version requirement' do
write 'build.yaml', 'gems: foo 2.5'
Gem::SourceInfoCache.should_receive(:search).with(Gem::Dependency.new('foo', '=2.5')).and_return([])
- lambda { @app.load_gems }.should raise_error
+ lambda { Buildr.application.load_gems }.should raise_error
end
it 'should parse range version requirement' do
write 'build.yaml', 'gems: foo ~>2.3'
Gem::SourceInfoCache.should_receive(:search).with(Gem::Dependency.new('foo', '~>2.3')).and_return([])
- lambda { @app.load_gems }.should raise_error
+ lambda { Buildr.application.load_gems }.should raise_error
end
it 'should parse multiple version requirements' do
write 'build.yaml', 'gems: foo >=2.0 !=2.1'
Gem::SourceInfoCache.should_receive(:search).with(Gem::Dependency.new('foo', ['>=2.0', '!=2.1'])).and_return([])
- lambda { @app.load_gems }.should raise_error
+ lambda { Buildr.application.load_gems }.should raise_error
end
end
@@ -283,4 +184,101 @@
ENV['BUILDR_ENV'].should eql('development')
end
end
+end
+
+
+describe Buildr, 'settings' do
+
+ describe 'user' do
+
+ it 'should be empty hash if no settings.yaml file' do
+ Buildr.settings.user.should == {}
+ end
+
+ it 'should return loaded settings.yaml file' do
+ write 'home/.buildr/settings.yaml', 'foo: bar'
+ Buildr.settings.user.should == { 'foo'=>'bar' }
+ end
+
+ it 'should fail if settings.yaml file is not a hash' do
+ write 'home/.buildr/settings.yaml', 'foo bar'
+ lambda { Buildr.settings.user }.should raise_error(RuntimeError, /expecting.*settings.yaml/i)
+ end
+
+ it 'should be empty hash if settings.yaml file is empty' do
+ write 'home/.buildr/settings.yaml'
+ Buildr.settings.user.should == {}
+ end
+ end
+
+ describe 'configuration' do
+ it 'should be empty hash if no build.yaml file' do
+ Buildr.settings.build.should == {}
+ end
+
+ it 'should return loaded build.yaml file' do
+ write 'build.yaml', 'foo: bar'
+ Buildr.settings.build.should == { 'foo'=>'bar' }
+ end
+
+ it 'should fail if build.yaml file is not a hash' do
+ write 'build.yaml', 'foo bar'
+ lambda { Buildr.settings.build }.should raise_error(RuntimeError, /expecting.*build.yaml/i)
+ end
+
+ it 'should be empty hash if build.yaml file is empty' do
+ write 'build.yaml'
+ Buildr.settings.build.should == {}
+ end
+ end
+
+ describe 'profiles' do
+ it 'should be empty hash if no profiles.yaml file' do
+ Buildr.settings.profiles.should == {}
+ end
+
+ it 'should return loaded profiles.yaml file' do
+ write 'profiles.yaml', <<-YAML
+ development:
+ foo: bar
+ YAML
+ Buildr.settings.profiles.should == { 'development'=> { 'foo'=>'bar' } }
+ end
+
+ it 'should fail if profiles.yaml file is not a hash' do
+ write 'profiles.yaml', 'foo bar'
+ lambda { Buildr.settings.profiles }.should raise_error(RuntimeError, /expecting.*profiles.yaml/i)
+ end
+
+ it 'should be empty hash if profiles.yaml file is empty' do
+ write 'profiles.yaml'
+ Buildr.settings.profiles.should == {}
+ end
+ end
+
+ describe 'profile' do
+ it 'should be empty hash if no profiles.yaml' do
+ Buildr.settings.profile.should == {}
+ end
+
+ it 'should be empty hash if no matching profile' do
+ write 'profiles.yaml', <<-YAML
+ test:
+ foo: bar
+ YAML
+ Buildr.settings.profile.should == {}
+ end
+
+ it 'should return profile matching environment name' do
+ write 'profiles.yaml', <<-YAML
+ development:
+ foo: bar
+ test:
+ foo: baz
+ YAML
+ Buildr.settings.profile.should == { 'foo'=>'bar' }
+ end
+
+ end
+
end
Modified: incubator/buildr/trunk/spec/artifact_spec.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/artifact_spec.rb?rev=646140&r1=646139&r2=646140&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/artifact_spec.rb (original)
+++ incubator/buildr/trunk/spec/artifact_spec.rb Tue Apr 8 16:48:55 2008
@@ -128,7 +128,7 @@
end
-describe 'repositories.local' do
+describe Repositories, 'local' do
it 'should default to .m2 path' do
# For convenience, sandbox actually sets the local repository to a temp directory
repositories.local = nil
@@ -157,10 +157,18 @@
repositories.locate(:group=>'com.example', :id=>'library', :version=>'2.0').should eql(
File.expand_path('~/.m2/repository/com/example/library/2.0/library-2.0.jar'))
end
+
+ it 'should load path from settings file' do
+ write 'home/.buildr/settings.yaml', <<-YAML
+ repositories:
+ local: my_repo
+ YAML
+ repositories.local.should eql(File.expand_path('my_repo'))
+ end
end
-describe 'repositories.remote' do
+describe Repositories, 'remote' do
before do
@repos = [ 'http://www.ibiblio.org/maven2', 'http://repo1.maven.org/maven2' ]
end
@@ -295,10 +303,44 @@
lambda { artifact('com.example:library:jar:2.1-SNAPSHOT').invoke }.should raise_error(RuntimeError, /Failed to download/)
File.exist?(File.join(repositories.local, 'com/example/library/2.1-SNAPSHOT/library-2.1-SNAPSHOT.jar')).should be_false
end
+
+ it 'should load with all repositories specified in settings file' do
+ write 'home/.buildr/settings.yaml', <<-YAML
+ repositories:
+ remote:
+ - http://example.com
+ - http://example.org
+ YAML
+ repositories.remote.should include('http://example.com', 'http://example.org')
+ end
+
+ it 'should load with all repositories specified in build.yaml file' do
+ write 'build.yaml', <<-YAML
+ repositories:
+ remote:
+ - http://example.com
+ - http://example.org
+ YAML
+ repositories.remote.should include('http://example.com', 'http://example.org')
+ end
+
+ it 'should load with all repositories specified in settings and build.yaml files' do
+ write 'home/.buildr/settings.yaml', <<-YAML
+ repositories:
+ remote:
+ - http://example.com
+ YAML
+ write 'build.yaml', <<-YAML
+ repositories:
+ remote:
+ - http://example.org
+ YAML
+ repositories.remote.should include('http://example.com', 'http://example.org')
+ end
end
-describe 'repositories.release_to' do
+describe Repositories, 'release_to' do
it 'should accept URL as first argument' do
repositories.release_to = 'http://example.com'
repositories.release_to.should == { :url=>'http://example.com' }
@@ -314,6 +356,25 @@
repositories.release_to.should == { :url=>'http://example.com' }
repositories.release_to[:username] = 'john'
repositories.release_to.should == { :url=>'http://example.com', :username=>'john' }
+ end
+
+ it 'should load URL from settings file' do
+ write 'home/.buildr/settings.yaml', <<-YAML
+ repositories:
+ release_to: http://john:secret@example.com
+ YAML
+ repositories.release_to.should == { :url=>'http://john:secret@example.com' }
+ end
+
+ it 'should load URL, username and password from settings file' do
+ write 'home/.buildr/settings.yaml', <<-YAML
+ repositories:
+ release_to:
+ url: http://example.com
+ username: john
+ password: secret
+ YAML
+ repositories.release_to.should == { :url=>'http://example.com', :username=>'john', :password=>'secret' }
end
end
Modified: incubator/buildr/trunk/spec/compile_spec.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/compile_spec.rb?rev=646140&r1=646139&r2=646140&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/compile_spec.rb (original)
+++ incubator/buildr/trunk/spec/compile_spec.rb Tue Apr 8 16:48:55 2008
@@ -547,10 +547,12 @@
it 'should use current profile for filtering' do
write 'profiles.yaml', <<-YAML
-development:
- foo: bar
-test:
- foo: baz
+ development:
+ filter:
+ foo: bar
+ test:
+ filter:
+ foo: baz
YAML
write 'src/main/resources/foo', '${foo}'
define('foo').compile.invoke
Modified: incubator/buildr/trunk/spec/sandbox.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/sandbox.rb?rev=646140&r1=646139&r2=646140&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/sandbox.rb (original)
+++ incubator/buildr/trunk/spec/sandbox.rb Tue Apr 8 16:48:55 2008
@@ -17,7 +17,9 @@
# The local repository we use for testing is void of any artifacts, which will break given
# that the code requires several artifacts. So we establish them first using the real local
# repository and cache these across test cases.
+Buildr.application.instance_eval { @rakefile = File.expand_path('buildfile') }
repositories.remote << 'http://repo1.maven.org/maven2'
+require 'buildr/java/groovyc'
Java.load # Anything added to the classpath.
artifacts(TestFramework.frameworks.map(&:dependencies).flatten).each { |a| file(a).invoke }
@@ -79,6 +81,12 @@
@_sandbox[:env_keys] = ENV.keys
['DEBUG', 'TEST', 'HTTP_PROXY', 'USER'].each { |k| ENV.delete(k) ; ENV.delete(k.downcase) }
+ # Remove testing local repository, and reset all repository settings.
+ Buildr.repositories.instance_eval do
+ @local = @remote = @release_to = nil
+ end
+ Buildr.options.proxy.http = nil
+
# Don't output crap to the console.
trace false
verbose false
@@ -87,13 +95,6 @@
# Call this from teardown.
def reset
- # Remove testing local repository, and reset all repository settings.
- Buildr.repositories.local = nil
- Buildr.repositories.remote = nil
- Buildr.repositories.release_to = nil
- Buildr.options.proxy.http = nil
- Buildr.instance_eval { @profiles = nil }
-
# Get rid of all the projects and the on_define blocks we used.
Project.clear
on_define = @_sandbox[:on_define]
Modified: incubator/buildr/trunk/spec/spec_helpers.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/spec_helpers.rb?rev=646140&r1=646139&r2=646140&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/spec_helpers.rb (original)
+++ incubator/buildr/trunk/spec/spec_helpers.rb Tue Apr 8 16:48:55 2008
@@ -22,11 +22,6 @@
$LOAD_PATH.unshift File.expand_path('../lib', File.dirname(__FILE__))
require 'buildr'
- # Load additional files for optional specs
- if rspec_options.argv.any? { |s| s =~ /groovy_compilers_spec/ }
- require 'buildr/java/groovyc'
- end
-
require File.expand_path('sandbox', File.dirname(__FILE__))
module SpecHelpers