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?.
- #dirty? ⇒ Boolean
-
#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
131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/build-tool/model/module.rb', line 131 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
179 180 181 |
# File 'lib/build-tool/model/module.rb', line 179 def description @description end |
#environment ⇒ Object
186 187 188 189 190 191 192 193 |
# File 'lib/build-tool/model/module.rb', line 186 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
234 235 236 |
# File 'lib/build-tool/model/module.rb', line 234 def is_template=(value) @is_template = value end |
#long_description ⇒ Object
249 250 251 |
# File 'lib/build-tool/model/module.rb', line 249 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
329 330 331 332 333 334 335 336 337 338 339 |
# File 'lib/build-tool/model/module.rb', line 329 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
315 316 317 318 319 320 321 |
# File 'lib/build-tool/model/module.rb', line 315 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
156 157 158 159 160 161 162 163 164 |
# File 'lib/build-tool/model/module.rb', line 156 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
97 98 99 |
# File 'lib/build-tool/model/module.rb', line 97 def build_directory build_prefix_required.join("bld", local_path) end |
#build_prefix ⇒ Object
113 114 115 116 117 118 119 120 |
# File 'lib/build-tool/model/module.rb', line 113 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
101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/build-tool/model/module.rb', line 101 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
123 124 125 126 |
# File 'lib/build-tool/model/module.rb', line 123 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
149 150 151 152 153 |
# File 'lib/build-tool/model/module.rb', line 149 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
166 167 168 |
# File 'lib/build-tool/model/module.rb', line 166 def checkedout? vcs_required.checkedout? end |
#clean ⇒ Object
ACTIONS
359 360 361 |
# File 'lib/build-tool/model/module.rb', line 359 def clean build_system_required.make( "clean" ) end |
#cleanup_after_vcs_access ⇒ Object
Cleanup after vcs_access
419 420 421 422 423 424 425 426 427 428 |
# File 'lib/build-tool/model/module.rb', line 419 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.
372 373 374 375 376 377 378 379 380 |
# File 'lib/build-tool/model/module.rb', line 372 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
401 402 403 |
# File 'lib/build-tool/model/module.rb', line 401 def configure build_system_required.configure end |
#configured? ⇒ Boolean
170 171 172 173 174 175 176 |
# File 'lib/build-tool/model/module.rb', line 170 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 |
#dirty? ⇒ Boolean
89 90 91 92 93 94 |
# File 'lib/build-tool/model/module.rb', line 89 def dirty? if vcs return vcs.dirty? end return false end |
#environment_required ⇒ Object
Will throw a exception if environment is not set
196 197 198 199 |
# File 'lib/build-tool/model/module.rb', line 196 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.
384 385 386 |
# File 'lib/build-tool/model/module.rb', line 384 def fetch( verbose = false ) vcs_required.fetch( verbose = verbose ) end |
#gc ⇒ Object
Garbage collect
202 203 204 |
# File 'lib/build-tool/model/module.rb', line 202 def gc vcs.gc end |
#install(fast = false) ⇒ Object
414 415 416 |
# File 'lib/build-tool/model/module.rb', line 414 def install( fast = false ) build_system_required.install( fast ) end |
#install_prefix ⇒ Object
219 220 221 222 223 224 225 226 |
# File 'lib/build-tool/model/module.rb', line 219 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
207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/build-tool/model/module.rb', line 207 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
229 230 231 232 |
# File 'lib/build-tool/model/module.rb', line 229 def install_prefix_required return self.install_prefix if self.install_prefix raise ConfigurationError, "No install prefix configured for #{name}!" end |
#is_template? ⇒ Boolean
235 236 237 |
# File 'lib/build-tool/model/module.rb', line 235 def is_template? @is_template end |
#last_success ⇒ Object
300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
# File 'lib/build-tool/model/module.rb', line 300 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
269 270 271 |
# File 'lib/build-tool/model/module.rb', line 269 def lastlog return BuildTool::History::CommandLog.last_by_module( name ) end |
#local_path ⇒ Object
244 245 246 |
# File 'lib/build-tool/model/module.rb', line 244 def local_path @local_path || name end |
#local_path=(local_path) ⇒ Object
239 240 241 242 |
# File 'lib/build-tool/model/module.rb', line 239 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
410 411 412 |
# File 'lib/build-tool/model/module.rb', line 410 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
144 145 146 |
# File 'lib/build-tool/model/module.rb', line 144 def our_build_system @build_system end |
#prepare_for_fetch ⇒ Object
Check if an ssh-key is required and active it if necessary
431 432 433 434 435 436 |
# File 'lib/build-tool/model/module.rb', line 431 def prepare_for_fetch if vcs return vcs.prepare_for_fetch end true end |
#prepare_for_installation ⇒ Object
462 463 464 |
# File 'lib/build-tool/model/module.rb', line 462 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
439 440 441 442 443 444 |
# File 'lib/build-tool/model/module.rb', line 439 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
447 448 449 450 451 452 |
# File 'lib/build-tool/model/module.rb', line 447 def ready_for_fetch if vcs return vcs.ready_for_fetch end true end |
#ready_for_rebase ⇒ Object
454 455 456 457 458 459 |
# File 'lib/build-tool/model/module.rb', line 454 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.
390 391 392 393 394 395 396 397 398 399 |
# File 'lib/build-tool/model/module.rb', line 390 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
405 406 407 |
# File 'lib/build-tool/model/module.rb', line 405 def reconfigure build_system_required.reconfigure end |
#remote_path ⇒ Object
259 260 261 |
# File 'lib/build-tool/model/module.rb', line 259 def remote_path @remote_path || name end |
#remote_path=(remote_path) ⇒ Object
Remote path
254 255 256 257 |
# File 'lib/build-tool/model/module.rb', line 254 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
363 364 365 |
# File 'lib/build-tool/model/module.rb', line 363 def remove_build_directory build_system_required.remove_build_directory end |
#remove_source_directory ⇒ Object
367 368 369 |
# File 'lib/build-tool/model/module.rb', line 367 def remove_source_directory build_system_required.remove_source_directory end |
#shell(command = nil, options = {}) ⇒ Object
466 467 468 469 470 471 472 473 474 |
# File 'lib/build-tool/model/module.rb', line 466 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
263 264 265 |
# File 'lib/build-tool/model/module.rb', line 263 def source_directory build_prefix_required.join("src", local_path) end |
#state ⇒ Object
Returns a current state in string format
274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/build-tool/model/module.rb', line 274 def state log = lastlog return 'UNKNOWN' if log.empty? e = log[0].module_logs.reverse_order.where( :module => name ).first if e.nil? return "UNKNOWN" end if e.state != History::ModuleLog::FINISHED_SUCCESSFUL return "#{e.started_at.strftime("%x %X")}: #{e.state_str} (#{e.event})" else return "#{e.started_at.strftime("%x %X")}: #{e.state_str}" end end |
#state_char ⇒ Object
Return the current state as one char.
290 291 292 293 294 295 296 297 298 |
# File 'lib/build-tool/model/module.rb', line 290 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
476 477 478 |
# File 'lib/build-tool/model/module.rb', line 476 def to_s "#{object_id}: #{name}" end |
#vcs ⇒ Object
323 324 325 326 |
# File 'lib/build-tool/model/module.rb', line 323 def vcs return vcs_configuration.vcs( self ) if vcs_configuration nil end |
#vcs_configuration_required ⇒ Object
341 342 343 344 345 346 347 |
# File 'lib/build-tool/model/module.rb', line 341 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
349 350 351 352 353 354 |
# File 'lib/build-tool/model/module.rb', line 349 def vcs_required if source_directory.nil? raise ConfigurationError, "No source directory specified for module #{name}." end return vcs_configuration_required.vcs( self ) end |