Class: BuildTool::Commands::ModuleBasedCommand

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

Overview

class ModuleProgress

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.



539
540
541
542
543
544
545
# File 'lib/build-tool/commands.rb', line 539

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

Instance Method Details

#clean(mod) ⇒ Object

Call the #clean method of the module.

Parameters:

  • mod (Object)

    The module to use



677
678
679
# File 'lib/build-tool/commands.rb', line 677

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

#clone(mod) ⇒ Object

Call the #clone method of the module.

Parameters:

  • mod (Object)

    The module to use



684
685
686
# File 'lib/build-tool/commands.rb', line 684

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



691
692
693
# File 'lib/build-tool/commands.rb', line 691

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

#do_execute(args) ⇒ Object



579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
# File 'lib/build-tool/commands.rb', line 579

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 if the modules are ready
    logger.info( '#### Checking for obstacles' )
    isready = true
    ModuleProgressbar.new( 'Modules', modules ) do |mod|
        isready &= is_module_ready?( mod )
    end

    if !isready
        logger.error "There were some problems detected. Exiting."
        return -1
    end

    # 2. Prepare the modules for access. Interactive stuff here.
    modules.each do |mod|
        begin
            isready &= prepare_module( mod )
        rescue Interrupt => e
            logger.info( "User Interrupt" )
            return -1
        end
    end

    if !isready
        logger.error "Unexpected problems encountered. 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|

                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
                    break if @stop_on_error
                rescue Exception => e
                    logger.error   "#{e.class}:#{e.message}"
                    logger.verbose e.backtrace.join("\n")
                    @failed_modules << mod.name
                    rc = -1
                    break if @stop_on_error
                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



698
699
700
# File 'lib/build-tool/commands.rb', line 698

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

#initialize_optionsObject



547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
# File 'lib/build-tool/commands.rb', line 547

def initialize_options
    options.on( "--resume-from [module]", "Skip all module before module." ) { |t|
        begin
            @resume_from = complete_module( t )
        rescue UsageError => e
            raise UsageError, "--resume-from: #{e}"
        end
        raise UsageError, "Both --resume-from and --resume-after specified!" if @resume_after
        }
    options.on( "--resume-after [module]", "Skip all module before and including module." ) { |t|
        begin
            @resume_after = complete_module( t )
        rescue UsageError => e
            raise UsageError, "--resume-after: #{e}"
        end
        raise UsageError, "Both --resume-from and --resume-after specified!" if @resume_from
        }
    options.on( "--[no-]stop-on-error", "Break on the first error." ) { |t|
        @stop_on_error = t
        }

    super
end

#install(mod, *args) ⇒ Object

Call the #install method of the module.

Parameters:

  • mod (Object)

    The module to use



705
706
707
# File 'lib/build-tool/commands.rb', line 705

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

#is_module_ready?(mod) ⇒ Boolean

Returns:

  • (Boolean)


571
572
573
# File 'lib/build-tool/commands.rb', line 571

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



712
713
714
# File 'lib/build-tool/commands.rb', line 712

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

#prepare_module(mod) ⇒ Object



575
576
577
# File 'lib/build-tool/commands.rb', line 575

def prepare_module( mod )
    true
end

#rebase(mod) ⇒ Object

Call the #rebase method of the module.

Parameters:

  • mod (Object)

    The module to use



719
720
721
# File 'lib/build-tool/commands.rb', line 719

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



726
727
728
# File 'lib/build-tool/commands.rb', line 726

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

#remove_build_directory(mod) ⇒ Object

Call the #clear_build_directory method of the module.

Parameters:

  • mod (Object)

    The module to use



733
734
735
# File 'lib/build-tool/commands.rb', line 733

def remove_build_directory( mod )
    ModuleActions::RemoveBuildDirectory.new( self, mod ).do
end

#summarizeObject



663
664
665
666
667
668
669
670
671
# File 'lib/build-tool/commands.rb', line 663

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