Class: BuildTool::Module
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- BuildTool::Module
- Defined in:
- lib/build-tool/model/module.rb
Overview
Represents the information associated with a buildable module.
Instance Attribute Summary collapse
- #build_system ⇒ Object
-
#default_active ⇒ Object
The default state of the feature.
- #description ⇒ Object
- #environment ⇒ Object
-
#feature ⇒ Object
ATTRIBUTES.
-
#is_template ⇒ Object
writeonly
Sets the attribute is_template.
- #long_description ⇒ Object
-
#parent ⇒ Object
The previous version of this module.
-
#patches ⇒ Object
readonly
Returns the value of attribute patches.
- #vcs_configuration ⇒ Object
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Modules are sorted by name.
-
#active? ⇒ Boolean
Is the module active?.
- #active_char ⇒ Object
-
#broken? ⇒ Boolean
Return true if the last build failed for whatever reason.
-
#build_directory ⇒ Object
not inherited.
- #build_prefix ⇒ Object
- #build_prefix=(path) ⇒ Object
-
#build_prefix_required ⇒ Object
Will throw a exception if build_prefix is not set.
-
#build_system_required ⇒ Object
Will throw a exception if build_system is not set.
- #checkedout? ⇒ Boolean
-
#clean ⇒ Object
ACTIONS.
-
#cleanup_after_vcs_access ⇒ Object
Cleanup after vcs_access.
-
#clone ⇒ Object
Clone the repository.
- #configure ⇒ Object
- #configured? ⇒ Boolean
-
#default_active? ⇒ Boolean
Is the module active by default?.
-
#environment_required ⇒ Object
Will throw a exception if environment is not set.
-
#fetch(verbose = false) ⇒ Object
Fetch changes from the remote repository.
-
#gc ⇒ Object
Garbage collect.
- #install(fast = false) ⇒ Object
- #install_prefix ⇒ Object
-
#install_prefix=(path) ⇒ Object
Installation prefix.
-
#install_prefix_required ⇒ Object
Will throw a exception if install_prefix is not set.
- #is_template? ⇒ Boolean
- #last_success ⇒ Object
-
#lastlog ⇒ Object
Return the logfile of the last compilation attempt.
- #local_path ⇒ Object
- #local_path=(local_path) ⇒ Object
-
#make(target = nil) ⇒ Object
Call make.
- #my_initialize ⇒ Object
- #our_build_system ⇒ Object
-
#prepare_for_fetch ⇒ Object
Check if an ssh-key is required and active it if necessary.
- #prepare_for_installation ⇒ Object
-
#prepare_for_rebase ⇒ Object
Check if an ssh-key is required and active it if necessary.
-
#ready_for_fetch ⇒ Object
Check if an ssh-key is required and active it if necessary.
- #ready_for_rebase ⇒ Object
-
#rebase(verbose) ⇒ Object
Update the local changes with remote changes.
- #reconfigure ⇒ Object
- #remote_path ⇒ Object
-
#remote_path=(remote_path) ⇒ Object
Remote path.
- #remove_build_directory ⇒ Object
- #remove_source_directory ⇒ Object
- #shell(command = nil, options = {}) ⇒ Object
- #source_directory ⇒ Object (also: #source_directory_required)
-
#state ⇒ Object
Returns a current state in string format.
-
#state_char ⇒ Object
Return the current state as one char.
- #to_s ⇒ Object
- #vcs ⇒ Object
- #vcs_configuration_required ⇒ Object
- #vcs_required ⇒ Object
Instance Attribute Details
#build_system ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/build-tool/model/module.rb', line 124 def build_system # Return our own buildsystem if there is one return @build_system if @build_system # Return our parents buildsystem if there is one if parent && parent.build_system @build_system = parent.build_system.dup @build_system.module = self return @build_system end # Nothing nil end |
#default_active ⇒ Object
The default state of the feature
62 63 64 |
# File 'lib/build-tool/model/module.rb', line 62 def default_active @default_active end |
#description ⇒ Object
172 173 174 |
# File 'lib/build-tool/model/module.rb', line 172 def description @description end |
#environment ⇒ Object
179 180 181 182 183 184 185 186 |
# File 'lib/build-tool/model/module.rb', line 179 def environment # Return our own buildsystem if there is one return @environment if @environment # Return our parents buildsystem if there is one return parent.environment if parent && parent.environment # Nothing nil end |
#feature ⇒ Object
ATTRIBUTES
55 56 57 |
# File 'lib/build-tool/model/module.rb', line 55 def feature @feature end |
#is_template=(value) ⇒ Object (writeonly)
Sets the attribute is_template
227 228 229 |
# File 'lib/build-tool/model/module.rb', line 227 def is_template=(value) @is_template = value end |
#long_description ⇒ Object
242 243 244 |
# File 'lib/build-tool/model/module.rb', line 242 def long_description @long_description end |
#parent ⇒ Object
The previous version of this module.
59 60 61 |
# File 'lib/build-tool/model/module.rb', line 59 def parent @parent end |
#patches ⇒ Object (readonly)
Returns the value of attribute patches.
56 57 58 |
# File 'lib/build-tool/model/module.rb', line 56 def patches @patches end |
#vcs_configuration ⇒ Object
317 318 319 320 321 322 323 324 325 326 327 |
# File 'lib/build-tool/model/module.rb', line 317 def vcs_configuration return @vcs_configuration if @vcs_configuration if parent && parent.vcs_configuration # puts "copying vcs for #{name} from #{parent.name}" vc = parent.vcs_configuration.class.new vc.copy_configuration( parent.vcs_configuration ) @vcs_configuration = vc return vc end nil end |
Instance Method Details
#<=>(other) ⇒ Object
Modules are sorted by name
19 20 21 |
# File 'lib/build-tool/model/module.rb', line 19 def <=>( other ) self.name <=> other.name end |
#active? ⇒ Boolean
Is the module active?
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/build-tool/model/module.rb', line 70 def active? # If the module is explicitely de/activated that wins if active.nil? # if the module is active by default let the feature decide if present. if default_active? if @feature.nil? return true else return @feature.active? end else # The feature is not active by default. return false end else return active end end |
#active_char ⇒ Object
303 304 305 306 307 308 309 |
# File 'lib/build-tool/model/module.rb', line 303 def active_char if active? ANSI::Code.green { "A" } else "I" end end |
#broken? ⇒ Boolean
Return true if the last build failed for whatever reason
149 150 151 152 153 154 155 156 157 |
# File 'lib/build-tool/model/module.rb', line 149 def broken? return true if lastlog.empty? lastlog[0].module_logs.where( :module => name ).each do |e| if e.state != History::ModuleLog::FINISHED_SUCCESSFUL return true end end return false end |
#build_directory ⇒ Object
not inherited
90 91 92 |
# File 'lib/build-tool/model/module.rb', line 90 def build_directory build_prefix_required.join("bld", local_path) end |
#build_prefix ⇒ Object
106 107 108 109 110 111 112 113 |
# File 'lib/build-tool/model/module.rb', line 106 def build_prefix # Return our own buildsystem if there is one return @build_prefix if @build_prefix # Return our parents buildsystem if there is one return parent.build_prefix if parent && parent.build_prefix # Nothing nil end |
#build_prefix=(path) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/build-tool/model/module.rb', line 94 def build_prefix=( path ) if path path = Pathname.new( path.sub( /\$HOME/, '~' ) ) if path.to_s[0] != '~' and path.relative? raise ConfigurationError, "Build-prefix '#{path}' is relative!" end @build_prefix = path. else @build_prefix = nil end end |
#build_prefix_required ⇒ Object
Will throw a exception if build_prefix is not set
116 117 118 119 |
# File 'lib/build-tool/model/module.rb', line 116 def build_prefix_required return self.build_prefix if self.build_prefix raise ConfigurationError, "No build prefix configured for #{name}!" end |
#build_system_required ⇒ Object
Will throw a exception if build_system is not set
142 143 144 145 146 |
# File 'lib/build-tool/model/module.rb', line 142 def build_system_required return self.build_system if self.build_system # *TODO* try to guess the build system raise ConfigurationError, "No build system configured for #{name}!" end |
#checkedout? ⇒ Boolean
159 160 161 |
# File 'lib/build-tool/model/module.rb', line 159 def checkedout? vcs_required.checkedout? end |
#clean ⇒ Object
ACTIONS
347 348 349 |
# File 'lib/build-tool/model/module.rb', line 347 def clean build_system_required.make( "clean" ) end |
#cleanup_after_vcs_access ⇒ Object
Cleanup after vcs_access
407 408 409 410 411 412 413 414 415 416 |
# File 'lib/build-tool/model/module.rb', line 407 def cleanup_after_vcs_access if MJ::Tools::SSH::has_keys? logger.info "" logger.info "#### Cleaning up the ssh keys" MJ::Tools::SSH::keys.each do |file| logger.info " - Removing key #{file}" end MJ::Tools::SSH::cleanup() end end |
#clone ⇒ Object
Clone the repository.
360 361 362 363 364 365 366 367 368 |
# File 'lib/build-tool/model/module.rb', line 360 def clone vcs_required.clone if !patches.empty? if !vcs.patches_supported? raise NotImplementedError, "Patch support not implemented for vcs #{vcs.name}" end vcs_required.apply_patches( patches ) end end |
#configure ⇒ Object
389 390 391 |
# File 'lib/build-tool/model/module.rb', line 389 def configure build_system_required.configure end |
#configured? ⇒ Boolean
163 164 165 166 167 168 169 |
# File 'lib/build-tool/model/module.rb', line 163 def configured? if build_system return build_system.configured? else return false end end |
#default_active? ⇒ Boolean
Is the module active by default?
65 66 67 |
# File 'lib/build-tool/model/module.rb', line 65 def default_active? @default_active end |
#environment_required ⇒ Object
Will throw a exception if environment is not set
189 190 191 192 |
# File 'lib/build-tool/model/module.rb', line 189 def environment_required return self.environment if self.environment raise ConfigurationError, "No environment configured for #{name}!" end |
#fetch(verbose = false) ⇒ Object
Fetch changes from the remote repository. Do not change the local checkout.
372 373 374 |
# File 'lib/build-tool/model/module.rb', line 372 def fetch( verbose = false ) vcs_required.fetch( verbose = verbose ) end |
#gc ⇒ Object
Garbage collect
195 196 197 |
# File 'lib/build-tool/model/module.rb', line 195 def gc vcs.gc end |
#install(fast = false) ⇒ Object
402 403 404 |
# File 'lib/build-tool/model/module.rb', line 402 def install( fast = false ) build_system_required.install( fast ) end |
#install_prefix ⇒ Object
212 213 214 215 216 217 218 219 |
# File 'lib/build-tool/model/module.rb', line 212 def install_prefix # Return our own buildsystem if there is one return @install_prefix if @install_prefix # Return our parents buildsystem if there is one return parent.install_prefix if parent && parent.install_prefix # Nothing nil end |
#install_prefix=(path) ⇒ Object
Installation prefix
200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/build-tool/model/module.rb', line 200 def install_prefix=( path ) if path path = Pathname.new( path.sub( /\$HOME/, '~' ) ) if path.to_s[0] != '~' and path.relative? raise ConfigurationError, "Install-prefix '#{path}' is relative!" end @install_prefix = path. else @install_prefix = nil end end |
#install_prefix_required ⇒ Object
Will throw a exception if install_prefix is not set
222 223 224 225 |
# File 'lib/build-tool/model/module.rb', line 222 def install_prefix_required return self.install_prefix if self.install_prefix raise ConfigurationError, "No install prefix configured for #{name}!" end |
#is_template? ⇒ Boolean
228 229 230 |
# File 'lib/build-tool/model/module.rb', line 228 def is_template? @is_template end |
#last_success ⇒ Object
288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'lib/build-tool/model/module.rb', line 288 def last_success return @last_success if @last_success lastlog = BuildTool::History::CommandLog.last_success_by_module( name ) if not lastlog.nil? @last_success = lastlog[:finished_at] end if @last_success.nil? @last_success = DateTime.new end return @last_success end |
#lastlog ⇒ Object
Return the logfile of the last compilation attempt
262 263 264 |
# File 'lib/build-tool/model/module.rb', line 262 def lastlog return BuildTool::History::CommandLog.last_by_module( name ) end |
#local_path ⇒ Object
237 238 239 |
# File 'lib/build-tool/model/module.rb', line 237 def local_path @local_path || name end |
#local_path=(local_path) ⇒ Object
232 233 234 235 |
# File 'lib/build-tool/model/module.rb', line 232 def local_path=( local_path ) raise ConfigurationError, "Attempt to set local_path for module template #{name}" if is_template? @local_path = local_path end |
#make(target = nil) ⇒ Object
Call make
398 399 400 |
# File 'lib/build-tool/model/module.rb', line 398 def make( target = nil ) build_system_required.make( target ) end |
#my_initialize ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/build-tool/model/module.rb', line 28 def my_initialize() if name.nil? raise StandardError, "Module name is required!" end @active = nil @patches = Array.new @local_path = nil @build_prefix = nil @remote_path = nil @environment = nil @build_system = nil @install_prefix = nil @is_template = false @vcs_configuration = nil @feature = nil @default_active = true @parent = nil @long_description = nil @description = nil @last_success = nil end |
#our_build_system ⇒ Object
137 138 139 |
# File 'lib/build-tool/model/module.rb', line 137 def our_build_system @build_system end |
#prepare_for_fetch ⇒ Object
Check if an ssh-key is required and active it if necessary
419 420 421 422 423 424 |
# File 'lib/build-tool/model/module.rb', line 419 def prepare_for_fetch if vcs return vcs.prepare_for_fetch end true end |
#prepare_for_installation ⇒ Object
450 451 452 |
# File 'lib/build-tool/model/module.rb', line 450 def prepare_for_installation return build_system_required.prepare_for_installation end |
#prepare_for_rebase ⇒ Object
Check if an ssh-key is required and active it if necessary
427 428 429 430 431 432 |
# File 'lib/build-tool/model/module.rb', line 427 def prepare_for_rebase if vcs return vcs.prepare_for_rebase end true end |
#ready_for_fetch ⇒ Object
Check if an ssh-key is required and active it if necessary
435 436 437 438 439 440 |
# File 'lib/build-tool/model/module.rb', line 435 def ready_for_fetch if vcs return vcs.ready_for_fetch end true end |
#ready_for_rebase ⇒ Object
442 443 444 445 446 447 |
# File 'lib/build-tool/model/module.rb', line 442 def ready_for_rebase if vcs return vcs.ready_for_rebase end true end |
#rebase(verbose) ⇒ Object
Update the local changes with remote changes. Do not fetch changes from the remote repository.
378 379 380 381 382 383 384 385 386 387 |
# File 'lib/build-tool/model/module.rb', line 378 def rebase( verbose ) vcs_required.rebase( verbose ) if !patches.empty? if !vcs.patches_supported? raise NotImplementedError, "Patch support not implemented for vcs #{vcs.name}" end vcs_required.apply_patches( patches ) end build_system_required.after_rebase end |
#reconfigure ⇒ Object
393 394 395 |
# File 'lib/build-tool/model/module.rb', line 393 def reconfigure build_system_required.reconfigure end |
#remote_path ⇒ Object
252 253 254 |
# File 'lib/build-tool/model/module.rb', line 252 def remote_path @remote_path || name end |
#remote_path=(remote_path) ⇒ Object
Remote path
247 248 249 250 |
# File 'lib/build-tool/model/module.rb', line 247 def remote_path=( remote_path ) raise ConfigurationError, "Attempt to set remote_path for module template #{name}" if is_template? @remote_path = remote_path end |
#remove_build_directory ⇒ Object
351 352 353 |
# File 'lib/build-tool/model/module.rb', line 351 def remove_build_directory build_system_required.remove_build_directory end |
#remove_source_directory ⇒ Object
355 356 357 |
# File 'lib/build-tool/model/module.rb', line 355 def remove_source_directory build_system_required.remove_source_directory end |
#shell(command = nil, options = {}) ⇒ Object
454 455 456 457 458 459 460 461 462 |
# File 'lib/build-tool/model/module.rb', line 454 def shell( command = nil, = {} ) envvars = [ :envvars ] || {} [ :envvars ] = envvars.merge( { 'BT_SOURCE' => source_directory.to_s } ) environment.shell( command, ) end |
#source_directory ⇒ Object Also known as: source_directory_required
256 257 258 |
# File 'lib/build-tool/model/module.rb', line 256 def source_directory build_prefix_required.join("src", local_path) end |
#state ⇒ Object
Returns a current state in string format
267 268 269 270 271 272 273 274 275 |
# File 'lib/build-tool/model/module.rb', line 267 def state return 'UNKNOWN' if lastlog.empty? lastlog[0].module_logs.where( :module => name ).each do |e| if e.state != History::ModuleLog::FINISHED_SUCCESSFUL return "#{e.state_str} (#{e.event})" end end return History::ModuleLog::state_str( History::ModuleLog::FINISHED_SUCCESSFUL ) end |
#state_char ⇒ Object
Return the current state as one char.
278 279 280 281 282 283 284 285 286 |
# File 'lib/build-tool/model/module.rb', line 278 def state_char return '?' if lastlog.empty? lastlog[0].module_logs.where( :module => name ).each do |e| if e.state != History::ModuleLog::FINISHED_SUCCESSFUL return "#{e.state_char}" end end return History::ModuleLog::state_char( History::ModuleLog::FINISHED_SUCCESSFUL ) end |
#to_s ⇒ Object
464 465 466 |
# File 'lib/build-tool/model/module.rb', line 464 def to_s "#{object_id}: #{name}" end |
#vcs ⇒ Object
311 312 313 314 |
# File 'lib/build-tool/model/module.rb', line 311 def vcs return vcs_configuration.vcs( self ) if vcs_configuration nil end |
#vcs_configuration_required ⇒ Object
329 330 331 332 333 334 335 |
# File 'lib/build-tool/model/module.rb', line 329 def vcs_configuration_required vc = vcs_configuration if vc.nil? raise ConfigurationError, "No version control system configure for module #{name}." end return vc end |
#vcs_required ⇒ Object
337 338 339 340 341 342 |
# File 'lib/build-tool/model/module.rb', line 337 def vcs_required if source_directory.nil? raise ConfigurationError, "No source directory specified for module #{name}." end return vcs_configuration_required.vcs( self ) end |