Class: BuildTool::Cfg::ModuleDeclarationNodeVisitor

Inherits:
ListVisitor show all
Defined in:
lib/build-tool/cfg/visitor.rb

Instance Attribute Summary

Attributes inherited from MJ::VisitorBase

#configuration

Instance Method Summary collapse

Methods inherited from ListVisitor

#visit, #visit_nodes

Methods inherited from MJ::VisitorBase

#visit_Object

Constructor Details

#initialize(configuration) ⇒ ModuleDeclarationNodeVisitor

Returns a new instance of ModuleDeclarationNodeVisitor.



537
538
539
540
# File 'lib/build-tool/cfg/visitor.rb', line 537

def initialize( configuration )
    super( configuration )
    @module = nil
end

Instance Method Details

#visit_ApplyPatchesNode(node) ⇒ Object



542
543
544
# File 'lib/build-tool/cfg/visitor.rb', line 542

def visit_ApplyPatchesNode( node )
    @module.patches << node.value
end

#visit_ArchiveDeclarationNode(node) ⇒ Object



546
547
548
549
550
551
552
553
554
# File 'lib/build-tool/cfg/visitor.rb', line 546

def visit_ArchiveDeclarationNode( node )
    vcs = BuildTool::VCS::ArchiveConfiguration.new
    # if @module.vcs_configuration and @module.vcs_configuration.name == "archive"
    #     vcs.copy_configuration( @module.vcs_configuration )
    # end
    @module.vcs_configuration = vcs
    visitor = ArchiveDeclarationNodeVisitor.new( configuration, vcs )
    node.accept( visitor )
end

#visit_BazarDeclarationNode(node) ⇒ Object



611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
# File 'lib/build-tool/cfg/visitor.rb', line 611

def visit_BazarDeclarationNode( node )
    vcs = BuildTool::VCS::BazarConfiguration.new
    if node.options[:inheritance]
        if not @module.vcs_configuration
            raise ConfigurationError,
                "#{@module.name} has no previous bazar configuration!"
        end
        if @module.vcs_configuration.name != "bazar"
            raise ConfigurationError,
                "#{@module.name} has a #{@module.vcs_configuration.name} configuration!"
        end
        vcs.parent = @module.vcs_configuration
    end
    @module.vcs_configuration = vcs
    visitor = BazarDeclarationNodeVisitor.new( configuration, vcs )
    node.accept( visitor )
end

#visit_BuildSystemDeclarationNode(node) ⇒ Object

Raises:



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/cfg/visitor.rb', line 556

def visit_BuildSystemDeclarationNode( node )
    raise ArgumentsError if node.values.length != 2
    name  = node.values[0]
    # We have to create a build-system. There are some possibilities:
    #   1. The module has a build-system. Inherit from that one (Overloading)
    #   2. The module has a parent but no build-system: Create the build-system parentless
    #      so it forwards to the parent module
    #   3. The module has no parent and no build-system. Inherit from the build-system
    #      standard module.
    if @module.our_build_system
        # logger.debug2( "Inherit from previous build-system for #{@module.name}" )
        build_system = configuration.build_system_adjust( name, @module.our_build_system )
    elsif @module.parent
        # logger.debug2( "Inherit without parent for #{@module.name}" )
        build_system = configuration.build_system_adjust( name, nil )
    else
        # logger.debug2( "Inherit from #{name} for #{@module.name}" )
        build_system = configuration.build_system_adjust( name, configuration.build_system_defaults( name ) )
    end
    visitor = BuildSystemDeclarationNodeVisitor.new( configuration, build_system )
    @module.build_system = node.accept( visitor )
    @module.build_system.module = @module
    @module.build_system.feature = configuration.active_feature
end

#visit_EnvironmentDeclarationNode(node) ⇒ Object



588
589
590
591
# File 'lib/build-tool/cfg/visitor.rb', line 588

def visit_EnvironmentDeclarationNode( node )
    visitor = EnvironmentDeclarationNodeVisitor.new( configuration )
    @module.environment = node.accept( visitor )
end

#visit_GitDeclarationNode(node) ⇒ Object



593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
# File 'lib/build-tool/cfg/visitor.rb', line 593

def visit_GitDeclarationNode( node )
    vcs = BuildTool::VCS::GitConfiguration.new
    if node.options[:inheritance]
        if not @module.vcs_configuration
            raise ConfigurationError,
                "#{@module.name} has no previous git configuration!"
        end
        if @module.vcs_configuration.name != "git"
            raise ConfigurationError,
                "#{@module.name} has a #{@module.vcs_configuration.name} configuration!"
        end
        vcs.parent = @module.vcs_configuration
    end
    @module.vcs_configuration = vcs
    visitor = GitDeclarationNodeVisitor.new( configuration, vcs )
    node.accept( visitor )
end

#visit_GitSvnDeclarationNode(node) ⇒ Object



629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
# File 'lib/build-tool/cfg/visitor.rb', line 629

def visit_GitSvnDeclarationNode( node )
    vcs = BuildTool::VCS::GitSvnConfiguration.new
    if node.options[:inheritance]
        if not @module.vcs_configuration
            raise ConfigurationError,
                "#{@module.name} has no previous git-svn configuration!"
        end
        if @module.vcs_configuration.name != "git-svn"
            raise ConfigurationError,
                "#{@module.name} has a #{@module.vcs_configuration.name} configuration!"
        end
        vcs.parent = @module.vcs_configuration
    end
    @module.vcs_configuration = vcs
    visitor = GitSvnDeclarationNodeVisitor.new( configuration, vcs )
    node.accept( visitor )
end

#visit_LongDescriptionNode(node) ⇒ Object



581
582
583
584
585
586
# File 'lib/build-tool/cfg/visitor.rb', line 581

def visit_LongDescriptionNode( node )
    if @module.long_description
        logger.warn "Overwriting long description for module #{@module.name}"
    end
    @module.long_description = node.values
end

#visit_MercurialDeclarationNode(node) ⇒ Object



647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
# File 'lib/build-tool/cfg/visitor.rb', line 647

def visit_MercurialDeclarationNode( node )
    vcs = BuildTool::VCS::MercurialConfiguration.new
    if node.options[:inheritance]
        if not @module.vcs_configuration
            raise ConfigurationError,
                "#{@module.name} has no previous mercurial configuration!"
        end
        if @module.vcs_configuration.name != "mercurial"
            raise ConfigurationError,
                "#{@module.name} has a #{@module.vcs_configuration.name} configuration!"
        end
        vcs.parent = @module.vcs_configuration
    end
    @module.vcs_configuration = vcs
    visitor = MercurialDeclarationNodeVisitor.new( configuration, vcs )
    node.accept( visitor )
end

#visit_ModuleBuildPrefixNode(node) ⇒ Object



665
666
667
# File 'lib/build-tool/cfg/visitor.rb', line 665

def visit_ModuleBuildPrefixNode( node )
    @module.build_prefix = node.value
end

#visit_ModuleDeclarationNode(node) ⇒ Object



669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
# File 'lib/build-tool/cfg/visitor.rb', line 669

def visit_ModuleDeclarationNode( node )
    name = node.values[0]
    inheritance = node.values[1] == :INHERITANCE

    if inheritance
        stmts = node.values[3]
    else
        stmts = node.values[1]
    end

    # Check if the module is alread defined. If yes we reopen it.
    @module = configuration.module( name )
    if @module.nil?
        @module = configuration.create_module( name )

        # Only add a module to a feature if it is the first time declared.
        if !configuration.active_feature.nil?
            @module.feature = configuration.active_feature
            configuration.active_feature.modules << @module
        end

    elsif inheritance

        raise ConfigurationError, "Attempt to change a module #{name} while specifying inheritance!"
    end

    if inheritance
        parentName = node.values[2]
        parent = configuration.module( parentName )
        if parent.nil?
            raise ConfigurationError,
                "Module %s attempts to inherit from not existant module %s" % 
                    [ name, parentName ]
        end
        @module.parent = parent
    end

    # Work on the child nodes.
    begin
        self.visit_nodes( stmts )
    rescue ConfigurationError => e
        raise ConfigurationError, "Module #{@module.name}: #{e.to_s}"
    end
end

#visit_ModuleInstallPrefixNode(node) ⇒ Object



714
715
716
# File 'lib/build-tool/cfg/visitor.rb', line 714

def visit_ModuleInstallPrefixNode( node )
    @module.install_prefix = node.value
end

#visit_ModuleLocalPathNode(node) ⇒ Object



718
719
720
# File 'lib/build-tool/cfg/visitor.rb', line 718

def visit_ModuleLocalPathNode( node )
    @module.local_path = node.value
end

#visit_ModuleTemplateNode(node) ⇒ Object



722
723
724
# File 'lib/build-tool/cfg/visitor.rb', line 722

def visit_ModuleTemplateNode( node )
    @module.is_template = true
end

#visit_ShortDescriptionNode(node) ⇒ Object



726
727
728
729
730
731
# File 'lib/build-tool/cfg/visitor.rb', line 726

def visit_ShortDescriptionNode( node )
    if !@module.description.nil?
        logger.warn "Overwriting short description for module #{@module.name}"
    end
    @module.description = node.values
end

#visit_SvnDeclarationNode(node) ⇒ Object



733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
# File 'lib/build-tool/cfg/visitor.rb', line 733

def visit_SvnDeclarationNode( node )
    vcs = BuildTool::VCS::SvnConfiguration.new
    if node.options[:inheritance]
        if not @module.vcs_configuration
            raise ConfigurationError,
                "#{@module.name} has no previous svn configuration!"
        end
        if @module.vcs_configuration.name != "svn"
            raise ConfigurationError,
                "#{@module.name} has a #{@module.vcs_configuration.name} configuration!"
        end
        vcs.parent = @module.vcs_configuration
    end
    @module.vcs_configuration = vcs
    visitor = SvnDeclarationNodeVisitor.new( configuration, vcs )
    node.accept( visitor )
end

#visit_UseBuildSystemNode(node) ⇒ Object



751
752
753
754
755
756
757
# File 'lib/build-tool/cfg/visitor.rb', line 751

def visit_UseBuildSystemNode( node )
    # logger.debug2( "Inherit from build-system #{node.value} for #{@module.name}" )
    @module.build_system = configuration.build_system_adjust(
        node.value,
        configuration.build_system_defaults( node.value ) )
    @module.build_system.module = @module
end

#visit_UseEnvironmentNode(node) ⇒ Object



759
760
761
762
763
764
# File 'lib/build-tool/cfg/visitor.rb', line 759

def visit_UseEnvironmentNode( node )
    @module.environment = configuration.environment( node.value )
    if @module.environment.nil?
        raise ConfigurationError, "Unknown environment #{node.value} configured for module #{@module.name}!"
    end
end

#visit_UseVcsNode(node) ⇒ Object



766
767
768
# File 'lib/build-tool/cfg/visitor.rb', line 766

def visit_UseVcsNode( node )
    @module.vcs_configuration = configuration.vcs(node.value)
end