Class: BuildTool::Module

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/build-tool/model/module.rb

Overview

Represents the information associated with a buildable module.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#build_systemObject



127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/build-tool/model/module.rb', line 127

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_activeObject

The default state of the feature



65
66
67
# File 'lib/build-tool/model/module.rb', line 65

def default_active
  @default_active
end

#descriptionObject



176
177
178
# File 'lib/build-tool/model/module.rb', line 176

def description
    @description
end

#environmentObject



183
184
185
186
187
188
189
190
# File 'lib/build-tool/model/module.rb', line 183

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

#featureObject

ATTRIBUTES



55
56
57
# File 'lib/build-tool/model/module.rb', line 55

def feature
  @feature
end

#found_in_recipeObject

Signals wether the module was found in the recipe or only in the database.



62
63
64
# File 'lib/build-tool/model/module.rb', line 62

def found_in_recipe
  @found_in_recipe
end

#is_template=(value) ⇒ Object (writeonly)

Sets the attribute is_template

Parameters:

  • value

    the value to set the attribute is_template to.



231
232
233
# File 'lib/build-tool/model/module.rb', line 231

def is_template=(value)
  @is_template = value
end

#long_descriptionObject



246
247
248
# File 'lib/build-tool/model/module.rb', line 246

def long_description
    @long_description
end

#parentObject

The previous version of this module.



59
60
61
# File 'lib/build-tool/model/module.rb', line 59

def parent
  @parent
end

#patchesObject (readonly)

Returns the value of attribute patches.



56
57
58
# File 'lib/build-tool/model/module.rb', line 56

def patches
  @patches
end

#vcs_configurationObject



303
304
305
306
307
308
309
310
311
312
313
# File 'lib/build-tool/model/module.rb', line 303

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?

Returns:

  • (Boolean)


73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/build-tool/model/module.rb', line 73

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_charObject



289
290
291
292
293
294
295
# File 'lib/build-tool/model/module.rb', line 289

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

Returns:

  • (Boolean)


152
153
154
155
156
157
158
159
160
161
# File 'lib/build-tool/model/module.rb', line 152

def broken?
    lastlog = BuildTool::History::CommandLog.last_by_module( name )
    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_directoryObject

not inherited



93
94
95
# File 'lib/build-tool/model/module.rb', line 93

def build_directory
    build_prefix_required.join("bld", local_path)
end

#build_prefixObject



109
110
111
112
113
114
115
116
# File 'lib/build-tool/model/module.rb', line 109

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



97
98
99
100
101
102
103
104
105
106
107
# File 'lib/build-tool/model/module.rb', line 97

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.expand_path
    else
        @build_prefix = nil
    end
end

#build_prefix_requiredObject

Will throw a exception if build_prefix is not set

Raises:



119
120
121
122
# File 'lib/build-tool/model/module.rb', line 119

def build_prefix_required
    return self.build_prefix if self.build_prefix
    raise ConfigurationError, "No build prefix configured for #{name}!"
end

#build_system_requiredObject

Will throw a exception if build_system is not set

Raises:



145
146
147
148
149
# File 'lib/build-tool/model/module.rb', line 145

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

Returns:

  • (Boolean)


163
164
165
# File 'lib/build-tool/model/module.rb', line 163

def checkedout?
    vcs_required.checkedout?
end

#cleanObject

ACTIONS



333
334
335
# File 'lib/build-tool/model/module.rb', line 333

def clean
    build_system_required.make( "clean" )
end

#cleanup_after_vcs_accessObject

Cleanup after vcs_access



393
394
395
396
397
398
399
400
401
402
# File 'lib/build-tool/model/module.rb', line 393

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

#cloneObject

Clone the repository.



346
347
348
349
350
351
352
353
354
# File 'lib/build-tool/model/module.rb', line 346

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

#configureObject



375
376
377
# File 'lib/build-tool/model/module.rb', line 375

def configure
    build_system_required.configure
end

#configured?Boolean

Returns:

  • (Boolean)


167
168
169
170
171
172
173
# File 'lib/build-tool/model/module.rb', line 167

def configured?
    if build_system
        return build_system.configured?
    else
        return false
    end
end

#default_active?Boolean

Is the module active by default?

Returns:

  • (Boolean)


68
69
70
# File 'lib/build-tool/model/module.rb', line 68

def default_active?
    @default_active
end

#environment_requiredObject

Will throw a exception if environment is not set

Raises:



193
194
195
196
# File 'lib/build-tool/model/module.rb', line 193

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.



358
359
360
# File 'lib/build-tool/model/module.rb', line 358

def fetch( verbose = false )
    vcs_required.fetch( verbose = verbose )
end

#gcObject

Garbage collect



199
200
201
# File 'lib/build-tool/model/module.rb', line 199

def gc
    vcs.gc
end

#install(fast = false) ⇒ Object



388
389
390
# File 'lib/build-tool/model/module.rb', line 388

def install( fast = false )
    build_system_required.install( fast )
end

#install_prefixObject



216
217
218
219
220
221
222
223
# File 'lib/build-tool/model/module.rb', line 216

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



204
205
206
207
208
209
210
211
212
213
214
# File 'lib/build-tool/model/module.rb', line 204

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.expand_path
    else
        @install_prefix = nil
    end
end

#install_prefix_requiredObject

Will throw a exception if install_prefix is not set

Raises:



226
227
228
229
# File 'lib/build-tool/model/module.rb', line 226

def install_prefix_required
    return self.install_prefix if self.install_prefix
    raise ConfigurationError, "No install prefix configured for #{name}!"
end

#is_template?Boolean

Returns:

  • (Boolean)


232
233
234
# File 'lib/build-tool/model/module.rb', line 232

def is_template?
    @is_template
end

#local_pathObject



241
242
243
# File 'lib/build-tool/model/module.rb', line 241

def local_path
    @local_path || name
end

#local_path=(local_path) ⇒ Object

Raises:



236
237
238
239
# File 'lib/build-tool/model/module.rb', line 236

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



384
385
386
# File 'lib/build-tool/model/module.rb', line 384

def make( target = nil )
    build_system_required.make( target )
end

#my_initializeObject



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
    @found_in_recipe = false
    @parent = nil

    @long_description = nil
    @description = nil
end

#our_build_systemObject



140
141
142
# File 'lib/build-tool/model/module.rb', line 140

def our_build_system
    @build_system
end

#prepare_for_fetchObject

Check if an ssh-key is required and active it if necessary



405
406
407
408
409
410
# File 'lib/build-tool/model/module.rb', line 405

def prepare_for_fetch
    if vcs
        return vcs.prepare_for_fetch
    end
    true
end

#prepare_for_installationObject



436
437
438
# File 'lib/build-tool/model/module.rb', line 436

def prepare_for_installation
    return build_system_required.prepare_for_installation
end

#prepare_for_rebaseObject

Check if an ssh-key is required and active it if necessary



413
414
415
416
417
418
# File 'lib/build-tool/model/module.rb', line 413

def prepare_for_rebase
    if vcs
        return vcs.prepare_for_rebase
    end
    true
end

#ready_for_fetchObject

Check if an ssh-key is required and active it if necessary



421
422
423
424
425
426
# File 'lib/build-tool/model/module.rb', line 421

def ready_for_fetch
    if vcs
        return vcs.ready_for_fetch
    end
    true
end

#ready_for_rebaseObject



428
429
430
431
432
433
# File 'lib/build-tool/model/module.rb', line 428

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.



364
365
366
367
368
369
370
371
372
373
# File 'lib/build-tool/model/module.rb', line 364

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

#reconfigureObject



379
380
381
# File 'lib/build-tool/model/module.rb', line 379

def reconfigure
    build_system_required.reconfigure
end

#remote_pathObject



256
257
258
# File 'lib/build-tool/model/module.rb', line 256

def remote_path
    @remote_path || name
end

#remote_path=(remote_path) ⇒ Object

Remote path

Raises:



251
252
253
254
# File 'lib/build-tool/model/module.rb', line 251

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_directoryObject



337
338
339
# File 'lib/build-tool/model/module.rb', line 337

def remove_build_directory
    build_system_required.remove_build_directory
end

#remove_source_directoryObject



341
342
343
# File 'lib/build-tool/model/module.rb', line 341

def remove_source_directory
    build_system_required.remove_source_directory
end

#source_directoryObject Also known as: source_directory_required



260
261
262
# File 'lib/build-tool/model/module.rb', line 260

def source_directory
    build_prefix_required.join("src", local_path)
end

#stateObject

Returns a current state in string format



266
267
268
269
270
271
272
273
274
275
# File 'lib/build-tool/model/module.rb', line 266

def state
    lastlog = BuildTool::History::CommandLog.last_by_module( name )
    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_charObject

Return the current state as one char.



278
279
280
281
282
283
284
285
286
287
# File 'lib/build-tool/model/module.rb', line 278

def state_char
    lastlog = BuildTool::History::CommandLog.last_by_module( name )
    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_sObject



440
441
442
# File 'lib/build-tool/model/module.rb', line 440

def to_s
    "#{object_id}: #{name}"
end

#vcsObject



297
298
299
300
# File 'lib/build-tool/model/module.rb', line 297

def vcs
    return vcs_configuration.vcs( self ) if vcs_configuration
    nil
end

#vcs_configuration_requiredObject



315
316
317
318
319
320
321
# File 'lib/build-tool/model/module.rb', line 315

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_requiredObject



323
324
325
326
327
328
# File 'lib/build-tool/model/module.rb', line 323

def vcs_required
    if source_directory.nil?
        raise ConfigurationError, "No source directory specified for module #{name}."
    end
    return vcs_configuration_required.vcs( self )
end