Class: Buildr::Application

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

Overview

:nodoc:

Constant Summary collapse

DEFAULT_BUILDFILES =
['buildfile', 'Buildfile', 'buildfile.rb', 'Buildfile.rb']

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeApplication

Returns a new instance of Application.



114
115
116
117
118
119
120
121
122
123
# File 'lib/buildr/core/application.rb', line 114

def initialize
  super
  @rakefiles = DEFAULT_BUILDFILES.dup
  @top_level_tasks = []
  @home_dir = File.expand_path('.buildr', ENV['HOME'])
  mkpath @home_dir if !File.exist?(@home_dir) && File.writable?(ENV['HOME'])
  @settings = Settings.new(self)
  @on_completion = []
  @on_failure = []
end

Instance Attribute Details

#gemsObject (readonly)

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



146
147
148
# File 'lib/buildr/core/application.rb', line 146

def gems
  @gems
end

#home_dirObject (readonly)

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



149
150
151
# File 'lib/buildr/core/application.rb', line 149

def home_dir
  @home_dir
end

#settingsObject (readonly)

Returns the Settings associated with this build.



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

def settings
  @settings
end

Instance Method Details

#build_completed(title, message) ⇒ Object

Call on_completion hooks with the given title and message



183
184
185
186
187
# File 'lib/buildr/core/application.rb', line 183

def build_completed(title, message)
  @on_completion.each do |block|
    block.call(title, message) rescue nil
  end
end

#build_failed(title, message, ex = nil) ⇒ Object

Call on_failure hooks with the given title, message and exception



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

def build_failed(title, message, ex = nil)
  @on_failure.each do |block|
    block.call(title, message, ex) rescue nil
  end
end

#build_filesObject

Files that complement the buildfile itself



167
168
169
170
# File 'lib/buildr/core/application.rb', line 167

def build_files #:nodoc:
  deprecated 'Please call buildfile.prerequisites instead'
  buildfile.prerequisites
end

#buildfileObject

:call-seq:

buildfile

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



162
163
164
# File 'lib/buildr/core/application.rb', line 162

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

#environmentObject

Copied from BUILD_ENV.



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

def environment
  ENV['BUILDR_ENV']
end

#on_completion(&block) ⇒ Object

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



173
174
175
# File 'lib/buildr/core/application.rb', line 173

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

#on_failure(&block) ⇒ Object

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



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

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

#runObject



125
126
127
128
129
130
131
132
# File 'lib/buildr/core/application.rb', line 125

def run
  @start = Time.now
  standard_exception_handling do
    init 'Buildr'
    load_buildfile
    top_level
  end
end

#switch_to_namespace(names) ⇒ Object

Not for external consumption.



135
136
137
138
139
140
141
142
# File 'lib/buildr/core/application.rb', line 135

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