Class: BuildTool::Commands::ModuleBasedCommand

Inherits:
Standard
  • Object
show all
Defined in:
lib/build-tool/commands.rb

Overview

class Standard

Instance Attribute Summary

Attributes inherited from Base

#cmd, #options, #parent

Instance Method Summary collapse

Methods inherited from Standard

#complete_module, #complete_modules, #log_directory, #while_logging_to

Methods inherited from Base

#<=>, #applicable?, #cleanup_after_vcs_access, #complete, #complete_arguments, #complete_readline_1_8, #complete_readline_1_9, #configuration, #do_complete_1_8, #do_complete_1_9, #each_option, #execute, #fullname, #log?, #say, #setup_command, #show_help, #skip_command, #teardown_command, #usage

Methods included from HelpText

#cmdalias, #description, included, #long_description, #name

Constructor Details

#initialize(*args) ⇒ ModuleBasedCommand

Returns a new instance of ModuleBasedCommand.



488
489
490
491
492
# File 'lib/build-tool/commands.rb', line 488

def initialize( *args )
    super( *args )
    @failed_modules = []
    @resume_from  = nil
end

Instance Method Details

#clean(mod, *args) ⇒ Object

Call the #clean method of the module.

Parameters:

  • mod (Object)

    The module to use



595
596
597
# File 'lib/build-tool/commands.rb', line 595

def clean( mod, *args )
    ModuleActions::Clean.new( self, mod, *args ).do
end

#clone(mod) ⇒ Object

Call the #clone method of the module.

Parameters:

  • mod (Object)

    The module to use



602
603
604
# File 'lib/build-tool/commands.rb', line 602

def clone( mod )
    ModuleActions::Clone.new( self, mod ).do
end

#configure(mod) ⇒ Object

Call the #configure method of the module.

Parameters:

  • mod (Object)

    The module to use



609
610
611
# File 'lib/build-tool/commands.rb', line 609

def configure( mod )
    ModuleActions::Configure.new( self, mod ).do
end

#do_execute(args) ⇒ Object



506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
# File 'lib/build-tool/commands.rb', line 506

def do_execute( args )

    if args.length == 0
        # *TODO* print better message
        return usage( "Not enough arguments." )
    end

    # 1. Resolve the modules
    modules = []
    args.each do |arg|
        complete_modules( arg ).each do |mod|
            modules << mod
        end
    end

    # 2. Check prerequisites
    isready = true
    modules.each do |mod|
        isready &= is_module_ready?( mod )
    end

    if !isready
        logger.error "Found problems. Exiting"
        return -1
    end

    rc = 0      # Our return code.

    @failed_modules = []

    while_logging_to nil, 'build-status', :info do

        begin

            modules.each_with_index do |mod, index|

                if not @resume_from.nil?
                    if mod.name == @resume_from.name
                        @resume_from = nil
                    else
                        logger.info "Skipping module #{mod.name} (#{index+1}/#{modules.size})"
                        next
                    end
                end

                begin

                    logger.info ""
                    logger.info "#### Module #{mod.name} (#{index+1}/#{modules.size})"
                    do_execute_module( mod )
                rescue Interrupt => e
                    raise e
                rescue BuildTool::Error => e
                    logger.error   e.message
                    logger.verbose e.backtrace.join("\n")
                    @failed_modules << mod.name
                    rc = -1
                rescue Exception => e
                    logger.error   "#{e.class}:#{e.message}"
                    logger.verbose e.backtrace.join("\n")
                    @failed_modules << mod.name
                    rc = -1
                ensure
                    logger.info "#### Module #{mod.name} finished"
                end
            end

        end

    end

    return rc;

end

#fetch(mod) ⇒ Object

Call the #fetch method of the module.

Parameters:

  • mod (Object)

    The module to use



616
617
618
# File 'lib/build-tool/commands.rb', line 616

def fetch( mod )
    ModuleActions::Fetch.new( self, mod ).do
end

#initialize_optionsObject



494
495
496
497
498
499
500
# File 'lib/build-tool/commands.rb', line 494

def initialize_options
    options.on( "--resume-from [module]", "Skip all module before module." ) { |t|
        @resume_from = complete_module( t )
        }

    super
end

#install(mod, *args) ⇒ Object

Call the #install method of the module.

Parameters:

  • mod (Object)

    The module to use



623
624
625
# File 'lib/build-tool/commands.rb', line 623

def install( mod, *args )
    ModuleActions::Install.new( self, mod, *args ).do
end

#is_module_ready?(mod) ⇒ Boolean

Returns:

  • (Boolean)


502
503
504
# File 'lib/build-tool/commands.rb', line 502

def is_module_ready?( mod )
    true
end

#make(mod, *args) ⇒ Object

Call the #make method of the module.

Parameters:

  • mod (Object)

    The module to use



630
631
632
# File 'lib/build-tool/commands.rb', line 630

def make( mod, *args )
    ModuleActions::Make.new( self, mod, *args ).do
end

#rebase(mod) ⇒ Object

Call the #rebase method of the module.

Parameters:

  • mod (Object)

    The module to use



637
638
639
# File 'lib/build-tool/commands.rb', line 637

def rebase( mod )
    ModuleActions::Rebase.new( self, mod ).do
end

#reconfigure(mod) ⇒ Object

Call the #reconfigure method of the module.

Parameters:

  • mod (Object)

    The module to use



644
645
646
# File 'lib/build-tool/commands.rb', line 644

def reconfigure( mod )
    ModuleActions::Reconfigure.new( self, mod ).do
end

#summarizeObject



581
582
583
584
585
586
587
588
589
# File 'lib/build-tool/commands.rb', line 581

def summarize
    logger.info ""
    if !@failed_modules.empty?
        logger.info "#### Finished with errors"
        logger.info "Failed modules:\n\t#{ @failed_modules.join( "\n\t" ) }"
    else
        logger.info "#### Finished without errors"
    end
end