Class: Buildr::Application

Inherits:
Rake::Application
  • Object
show all
Includes:
CommandLineInterface
Defined in:
lib/buildr/core/application.rb

Overview

:nodoc:

Constant Summary collapse

DEFAULT_BUILDFILES =
['buildfile', 'Buildfile'] + DEFAULT_RAKEFILES

Constants included from CommandLineInterface

CommandLineInterface::OPTIONS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CommandLineInterface

#collect_tasks, #command_line_options, #do_option, #help, #parse_options, #usage, #version

Constructor Details

#initializeApplication

Returns a new instance of Application.



117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/buildr/core/application.rb', line 117

def initialize
  super
  @rakefiles = DEFAULT_BUILDFILES
  @name = 'Buildr'
  @requires = []
  @top_level_tasks = []
  parse_options
  collect_tasks
  @home_dir = File.expand_path('.buildr', ENV['HOME'])
  mkpath @home_dir, :verbose=>false unless File.exist?(@home_dir)
  @environment = ENV['BUILDR_ENV'] ||= 'development'
  @on_completion = []
  @on_failure = []
end

Instance Attribute Details

#environmentObject (readonly)

Copied from BUILD_ENV.



140
141
142
# File 'lib/buildr/core/application.rb', line 140

def environment
  @environment
end

#gemsObject (readonly)

Returns list of Gems associated with this buildfile, as listed in build.yaml. Each entry is of type Gem::Specification.



134
135
136
# File 'lib/buildr/core/application.rb', line 134

def gems
  @gems
end

#home_dirObject (readonly)

Buildr home directory, .buildr under user’s home directory.



137
138
139
# File 'lib/buildr/core/application.rb', line 137

def home_dir
  @home_dir
end

Instance Method Details

#build_filesObject

Files that complement the buildfile itself



156
157
158
# File 'lib/buildr/core/application.rb', line 156

def build_files #:nodoc:
  buildfile.prerequisites
end

#buildfileObject

:call-seq:

buildfile

Returns the buildfile as a task that you can use as a dependency.



151
152
153
# File 'lib/buildr/core/application.rb', line 151

def buildfile
  @buildfile_task ||= BuildfileTask.define_task(File.expand_path(rakefile))
end

#deprecated(message) ⇒ Object

:call-seq:

deprecated(message)

Use with deprecated methods and classes. This method automatically adds the file name and line number, and the text ‘Deprecated’ before the message, and eliminated duplicate warnings. It only warns when running in verbose mode.

For example:

deprecated 'Please use new_foo instead of foo.'


205
206
207
208
209
210
211
212
213
214
# File 'lib/buildr/core/application.rb', line 205

def deprecated(message) #:nodoc:
  return unless verbose
  "#{caller[1]}: Deprecated: #{message}".tap do |message|
    @deprecated ||= {}
    unless @deprecated[message]
      @deprecated[message] = true
      warn message
    end
  end
end

#on_completion(&block) ⇒ Object

Yields to block on successful completion. Primarily used for notifications.



177
178
179
# File 'lib/buildr/core/application.rb', line 177

def on_completion(&block)
  @on_completion << block
end

#on_failure(&block) ⇒ Object

Yields to block on failure with exception. Primarily used for notifications.



182
183
184
# File 'lib/buildr/core/application.rb', line 182

def on_failure(&block)
  @on_failure << block
end

#runObject



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/buildr/core/application.rb', line 160

def run
  standard_exception_handling do
    find_buildfile
    load_gems
    load_artifacts
    load_tasks
    load_requires
    load_buildfile
    load_imports
    task('buildr:initialize').invoke
    top_level
  end
  title, message = 'Your build has completed', "#{Dir.pwd}\nbuildr #{@top_level_tasks.join(' ')}"
  @on_completion.each { |block| block.call(title, message) rescue nil }
end

#settingsObject

Returns the Settings associated with this build.



143
144
145
146
# File 'lib/buildr/core/application.rb', line 143

def settings
  fail "Internal error: Called Buildr.settings before buildfile located" unless rakefile
  @settings ||= Settings.new(self)
end

#switch_to_namespace(names) ⇒ Object

Not for external consumption.



187
188
189
190
191
192
193
194
# File 'lib/buildr/core/application.rb', line 187

def switch_to_namespace(names) #:nodoc:
  current, @scope = @scope, names
  begin
    yield
  ensure
    @scope = current
  end
end