Class: Bake::AdaptConfig
- Inherits:
-
Object
- Object
- Bake::AdaptConfig
- Defined in:
- lib/adapt/config/loader.rb
Constant Summary collapse
- @@filenames =
[]
Instance Attribute Summary collapse
-
#referencedConfigs ⇒ Object
readonly
Returns the value of attribute referencedConfigs.
Class Method Summary collapse
Instance Method Summary collapse
- #chooseProjectFilenames(potentialAdapts) ⇒ Object
- #getPotentialAdaptionProjects ⇒ Object
- #load ⇒ Object
- #loadProjMeta(filename, filenum) ⇒ Object
Instance Attribute Details
#referencedConfigs ⇒ Object (readonly)
Returns the value of attribute referencedConfigs.
8 9 10 |
# File 'lib/adapt/config/loader.rb', line 8 def referencedConfigs @referencedConfigs end |
Class Method Details
.checkSyntax(configs, filename, isLocalAdapt = false) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/adapt/config/loader.rb', line 38 def self.checkSyntax(configs, filename, isLocalAdapt = false) Bake::Configs::Checks::commonMetamodelCheck(configs, filename, true) configs.each do |c| if not c.extends.empty? Bake.formatter.printError("Attribute 'extends' must not be used in adapt config.",c) ExitHelper.exit(1) end if c.name.empty? Bake.formatter.printError("Configs must be named.",c) ExitHelper.exit(1) end if c.project.empty? Bake.formatter.printError("The corresponding project must be specified.",c) ExitHelper.exit(1) end if !isLocalAdapt if not ["replace", "remove", "extend", "push_front"].include?c.type Bake.formatter.printError("Allowed types are 'replace', 'remove', 'extend' and 'push_front'.",c) ExitHelper.exit(1) end if not ["", "yes", "no", "all"].include?c.mergeInc Bake.formatter.printError("Allowed modes are 'all', 'yes', 'no' and unset.",c) ExitHelper.exit(1) end end end |
.filenames ⇒ Object
12 13 14 |
# File 'lib/adapt/config/loader.rb', line 12 def self.filenames @@filenames end |
Instance Method Details
#chooseProjectFilenames(potentialAdapts) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/adapt/config/loader.rb', line 81 def chooseProjectFilenames(potentialAdapts) @@filenames = [] Bake..adapt.each do |aComplete| aComplete.gsub!(/\\/,"/") a = aComplete.gsub(/\[.*\]/,"") projFilter = aComplete.scan(/\[(.*)\]/) if projFilter && projFilter.length > 0 projFilter = projFilter[0][0].split(";").map {|a| a.strip} end found = false # from working dir if File.exist?(a) && File.file?(a) @@filenames << {:file => File.(a), :projs => projFilter} found = true end next if found # from main dir Dir.chdir Bake..main_dir do if File.exist?(a) && File.file?(a) @@filenames << {:file => (Bake..main_dir + "/" + a), :projs => projFilter} found = true end end next if found # from roots Bake..roots.each do |root| r = root.dir Dir.chdir r do if File.exist?(a) && File.file?(a) @@filenames << {:file => (r + "/" + a), :projs => projFilter} found = true end end break if found end next if found # old style adapts = potentialAdapts.find_all { |p| p.include?("/"+a+"/Adapt.meta") or p == a+"/Adapt.meta" } if adapts.empty? Bake.formatter.printError("Adaption project #{a} not found") ExitHelper.exit(1) else @@filenames << {:file => adapts[0], :projs => projFilter} if (adapts.length > 1) Bake.formatter.printWarning("Adaption project #{a} exists more than once") chosen = " (chosen)" adapts.each do |f| Bake.formatter.printWarning(" #{File.dirname(f)}#{chosen}") chosen = "" end end end end end |
#getPotentialAdaptionProjects ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/adapt/config/loader.rb', line 64 def getPotentialAdaptionProjects() potentialAdapts = [] Bake..roots.each do |root| r = root.dir if (r.length == 3 && r.include?(":/")) r = r + Bake..main_project_name # glob would not work otherwise on windows (ruby bug?) end Bake..adapt.each do |a| adaptBaseName = File.(a.gsub(/\(.*\)/,"") + "/Adapt.meta") potentialAdapts << adaptBaseName if File.exist?adaptBaseName end potentialAdapts.concat(Root.search_to_depth(r, "Adapt.meta", root.depth)) end potentialAdapts.uniq end |
#load ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/adapt/config/loader.rb', line 142 def load() @@filenames = [] return [] if Bake..adapt.empty? @loader = Loader.new potentialProjects = getPotentialAdaptionProjects() chooseProjectFilenames(potentialProjects) configs = [] @@filenames.each_with_index do |f,i| loadProjMeta(f[:file], i+1).each do |c| configs << {:config => c, :projs => f[:projs]} end end return configs end |
#loadProjMeta(filename, filenum) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/adapt/config/loader.rb', line 16 def loadProjMeta(filename, filenum) Bake::Configs::Checks.symlinkCheck(filename) Bake::Configs::Checks.sanityFolderName(filename) f = @loader.load(filename) if f.root_elements.any? { |re| ! Metamodel::Adapt === re } Bake.formatter.printError("Config file must have only 'Adapt' elements as roots", filename) ExitHelper.exit(1) end f.root_elements.each do |a| Bake::Config::checkVer(a.requiredBakeVersion) end configs = [] f.root_elements.each { |re| configs.concat(re.getConfig) } AdaptConfig::checkSyntax(configs, filename) configs end |