Class: BuildTool::Configuration
- Inherits:
-
Object
- Object
- BuildTool::Configuration
- Defined in:
- lib/build-tool/configuration.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#active_feature ⇒ Object
Returns the value of attribute active_feature.
-
#environments ⇒ Object
readonly
Returns the value of attribute environments.
-
#features ⇒ Object
readonly
Returns the value of attribute features.
-
#modules ⇒ Object
readonly
Returns the value of attribute modules.
-
#recipe ⇒ Object
Returns the value of attribute recipe.
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
Class Method Summary collapse
Instance Method Summary collapse
- #add_build_system(bs) ⇒ Object
- #add_environment(env) ⇒ Object
- #add_repository(repo) ⇒ Object
- #add_server(server) ⇒ Object
- #add_setting(s) ⇒ Object
- #add_sshkey(key) ⇒ Object
- #build_system_adjust(name, parent = nil, *args) ⇒ Object
- #build_system_defaults(name, *args) ⇒ Object
-
#complete_buildsets(name) ⇒ Object
Complete buildsets.
- #complete_module(name, include_templates = false, all = false, resume_from = nil, resume_after = nil) ⇒ Object
- #complete_modules(name, include_templates = false, all = false, resume_from = nil, resume_after = nil) ⇒ Object
- #create_build_system(name, parent = nil, *args) ⇒ Object
- #create_feature(name, parent = active_feature) ⇒ Object
- #create_module(name) ⇒ Object
- #environment(name) ⇒ Object
- #feature(name) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #log_directory ⇒ Object
- #log_directory=(path) ⇒ Object
-
#migrate ⇒ Object
Execute the necessary steps to adapt the configuration to the current state of the recipe.
- #module(name) ⇒ Object
- #repository(name) ⇒ Object
- #save ⇒ Object
- #server(name) ⇒ Object
- #sshkey(name) ⇒ Object
- #truncate ⇒ Object
- #vcs(name) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/build-tool/configuration.rb', line 157 def initialize() @recipe = nil @server = {} @log_directory = nil @environments = {} @module = {} @modules = [] @build_system = {} @repository = {} @sshkey = {} @active_feature = nil @features = {} @settings = {} @cached_modules = {} @cached_features = {} base_load() end |
Instance Attribute Details
#active_feature ⇒ Object
Returns the value of attribute active_feature.
54 55 56 |
# File 'lib/build-tool/configuration.rb', line 54 def active_feature @active_feature end |
#environments ⇒ Object (readonly)
Returns the value of attribute environments.
52 53 54 |
# File 'lib/build-tool/configuration.rb', line 52 def environments @environments end |
#features ⇒ Object (readonly)
Returns the value of attribute features.
53 54 55 |
# File 'lib/build-tool/configuration.rb', line 53 def features @features end |
#modules ⇒ Object (readonly)
Returns the value of attribute modules.
51 52 53 |
# File 'lib/build-tool/configuration.rb', line 51 def modules @modules end |
#recipe ⇒ Object
Returns the value of attribute recipe.
50 51 52 |
# File 'lib/build-tool/configuration.rb', line 50 def recipe @recipe end |
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
55 56 57 |
# File 'lib/build-tool/configuration.rb', line 55 def settings @settings end |
Class Method Details
.edit(only = []) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/build-tool/configuration.rb', line 29 def self.edit( only = [] ) settings = BuildTool::Setting::export( BuildTool::Application.instance.configuration.settings, only ) editor = MJ::Tools::TmpFileEditor.new( YAML::dump( settings ) ) editor.edit() if not Pathname.new( editor.path() ).exist? info( "File deleted!" ) return 0 end values = YAML::load( File.open( editor.path(), 'r:UTF-8' ) ) BuildTool::Setting::import( BuildTool::Application.instance.configuration.settings, values ) return 0 end |
Instance Method Details
#add_build_system(bs) ⇒ Object
226 227 228 |
# File 'lib/build-tool/configuration.rb', line 226 def add_build_system( bs ) return @build_system[bs.name] = bs end |
#add_environment(env) ⇒ Object
74 75 76 |
# File 'lib/build-tool/configuration.rb', line 74 def add_environment( env) @environments[env.name] = env end |
#add_repository(repo) ⇒ Object
133 134 135 |
# File 'lib/build-tool/configuration.rb', line 133 def add_repository( repo ) @repository[repo.name] = repo end |
#add_server(server) ⇒ Object
141 142 143 |
# File 'lib/build-tool/configuration.rb', line 141 def add_server( server ) @server[ server.name ] = server end |
#add_setting(s) ⇒ Object
153 154 155 |
# File 'lib/build-tool/configuration.rb', line 153 def add_setting( s ) @settings[s.name] = s end |
#add_sshkey(key) ⇒ Object
149 150 151 |
# File 'lib/build-tool/configuration.rb', line 149 def add_sshkey( key ) @sshkey[key.name] = key end |
#build_system_adjust(name, parent = nil, *args) ⇒ Object
215 216 217 218 219 |
# File 'lib/build-tool/configuration.rb', line 215 def build_system_adjust( name, parent = nil, *args ) bs = create_build_system( name, parent ) bs.defaults = build_system_defaults( name ) return bs end |
#build_system_defaults(name, *args) ⇒ Object
221 222 223 224 |
# File 'lib/build-tool/configuration.rb', line 221 def build_system_defaults( name, *args ) return @build_system[name] if @build_system[name] add_build_system( create_build_system( name ) ) end |
#complete_buildsets(name) ⇒ Object
Complete buildsets
297 298 299 300 301 |
# File 'lib/build-tool/configuration.rb', line 297 def complete_buildsets( name ) if name == ':all' return complete_modules( '*' ) end end |
#complete_module(name, include_templates = false, all = false, resume_from = nil, resume_after = nil) ⇒ Object
303 304 305 306 307 308 309 310 |
# File 'lib/build-tool/configuration.rb', line 303 def complete_module( name, include_templates = false, all = false, resume_from = nil, resume_after = nil ) modules = complete_modules( name, include_templates, all, resume_from, resume_after ) case modules.size when 0 then return nil when 1 then return modules[0] else raise BuildTool::ConfigurationError, "#{name} is ambiguous. Please be more specific" end end |
#complete_modules(name, include_templates = false, all = false, resume_from = nil, resume_after = nil) ⇒ Object
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 |
# File 'lib/build-tool/configuration.rb', line 312 def complete_modules( name, include_templates = false, all = false, resume_from = nil, resume_after = nil ) if name.start_with? ':' return complete_buildsets( name ) end res = [] found = false should_be_unique = false resume = ( resume_from.nil? and resume_after.nil? ) modules.each do |mod| take_module = false next if ( !include_templates and mod.is_template? ) # We match on the following conditions: # 1. name = mod.name # 2. name/ matches beginning of mod.name # 3. name equals last part of mod.name (behind /) and is unique if name.end_with?('/') and ( mod.name.index "/#{name}" or mod.name.start_with? name ) found = true # Now check if it is active. next if !( mod.active? || all ) take_module = true elsif mod.name == name or mod.name.end_with?( "/#{name}" ) found = true should_be_unique = true take_module = true elsif name == '*' found = true # Now check if it is active. next if !( mod.active? || @all ) take_module = true end if not resume and resume_from and mod.name == resume_from.name resume = true end res << mod if resume and take_module if not resume and resume_after and mod.name == resume_after.name resume = true end end # Raise an error if the module was not found if !found raise BuildTool::ConfigurationError, "Unknown module/package #{name}" end # Raise an error if the result should be unique but is not. if should_be_unique if res.size > 1 raise BuildTool::ConfigurationError, "#{name} is ambiguous (#{res.map { |m| m.name }.join( ', ' ) })." end mod = res[0] # If the module is inactive make sure the feature is active if not ( mod.active? || mod.feature.nil? || mod.feature.active? ) raise BuildTool::ConfigurationError, "Can't select module %s from inactive feature %s" % [ mod.name, mod.feature.name ] end end # Give a warning if all modules where warn( "All modules for #{name} are inactive! Will ignore it." ) if res.empty? return res end |
#create_build_system(name, parent = nil, *args) ⇒ Object
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/build-tool/configuration.rb', line 194 def create_build_system( name, parent = nil, *args ) return case name when "none" BuildTool::BuildSystem::None.new( parent, *args ) when "cmake" BuildTool::BuildSystem::CMake.new( parent, *args ) when "kdel10n" BuildTool::BuildSystem::KdeL10n.new( parent, *args ) when "qt" BuildTool::BuildSystem::Qt.new( parent, *args ) when "qmake" BuildTool::BuildSystem::QMake.new( parent, *args ) when "custom" BuildTool::BuildSystem::Custom.new( parent, *args ) when "autoconf" BuildTool::BuildSystem::AutoConf.new( parent, *args ) else raise StandardError, "Unknown Version Control System #{name}" end end |
#create_feature(name, parent = active_feature) ⇒ Object
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 |
# File 'lib/build-tool/configuration.rb', line 82 def create_feature( name, parent = active_feature ) if parent path = "#{parent.path}/#{name}" else path = "#{name}" end if @features.has_key?( path ) raise StandardError, "Attempt to create already existing feature #{name}" end if @cached_features.has_key?( path ) # Found in cache. Add it for real and remove from cache. logger.debug( "Getting feature #{path} from cache" ) add_feature( @cached_features[ path] ) @cached_features.delete( path) else logger.debug( "Creating feature #{path}" ) add_feature( BuildTool::Feature.create( :name => name, :parent => parent ) ) end @features[path] end |
#create_module(name) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/build-tool/configuration.rb', line 112 def create_module( name ) if @module.has_key?( name ) raise StandardError, "Attempt to create already existing module #{name}" end if @cached_modules.has_key?( name ) # Found in cache. Add it for real and remove from cache. logger.debug( "Getting module #{name} from cache" ) add_module( @cached_modules[ name ] ) @cached_modules.delete( name ) else logger.debug( "Creating module #{name}" ) add_module( BuildTool::Module.create( { :name => name } ) ) end @module[name] end |
#environment(name) ⇒ Object
70 71 72 |
# File 'lib/build-tool/configuration.rb', line 70 def environment( name ) @environments[name] end |
#feature(name) ⇒ Object
78 79 80 |
# File 'lib/build-tool/configuration.rb', line 78 def feature( name ) @features[name] end |
#log_directory ⇒ Object
57 58 59 60 |
# File 'lib/build-tool/configuration.rb', line 57 def log_directory return @log_directory if @log_directory raise BuildTool::ConfigurationError, "No log directory configured" end |
#log_directory=(path) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/build-tool/configuration.rb', line 62 def log_directory=( path ) path = Pathname.new( path.sub( /\$HOME/, '~' ) ) if path.to_s[0] != '~' and path.relative? raise ConfigurationError, "Log directory '#{path}' is relative!" end @log_directory = path. end |
#migrate ⇒ Object
Execute the necessary steps to adapt the configuration to the current state of the recipe.
The recipe has to be loaded before calling this method. With the configuration given. The method removes obsolete stuff from the database.
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/build-tool/configuration.rb', line 268 def migrate() logger.debug( 'Checking for obsolete modules in db.' ) for mod in @cached_modules.values() do logger.info 'Module %s no longer supported by recipe. Removing it from db.' % [ mod.name ] # Remove it from the db mod.destroy() end @cached_modules = {} logger.debug( 'Checking for obsolete features in db.' ) for feat in @cached_features.values() do logger.info 'Feature %s no longer supported by recipe. Removing it from db.' % [ feat.path ] # Remove it from the db feat.destroy() end @cached_features = {} logger.debug( 'Checking for obsolete settings in db.' ) settings.each do |n, s| if not s.seen and not n.start_with? 'BUILD_TOOL.' logger.info 'Setting %s no longer supported by recipe. Removing it from db.' % [ s.name ] s.destroy() end end end |
#module(name) ⇒ Object
108 109 110 |
# File 'lib/build-tool/configuration.rb', line 108 def module( name ) @module[name] end |
#repository(name) ⇒ Object
129 130 131 |
# File 'lib/build-tool/configuration.rb', line 129 def repository( name ) @repository[name] end |
#save ⇒ Object
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/build-tool/configuration.rb', line 230 def save logger.debug "Saving features to database." @features.each do |name, f| logger.debug2( " Feature %s (%s)" % [ f.name, f.parent_id ] ) if f.changed? f.save! if f.changed? end logger.debug "Saving modules to database." @modules.each do |m| logger.debug2( " Module %s" % [ m.name ] ) if m.changed? m.save! if m.changed? end logger.debug "Saving settings to database." @settings.each do |n, s| logger.debug2( " Setting %s: %s" % [ s.name, s.value ] ) if s.changed? s.save! if s.changed? end end |
#server(name) ⇒ Object
137 138 139 |
# File 'lib/build-tool/configuration.rb', line 137 def server( name ) @server[name] end |
#sshkey(name) ⇒ Object
145 146 147 |
# File 'lib/build-tool/configuration.rb', line 145 def sshkey( name ) @sshkey[name] end |
#truncate ⇒ Object
248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/build-tool/configuration.rb', line 248 def truncate logger.debug "Deleting all features from database." BuildTool::Feature.delete_all() @features = {} @cached_features = {} logger.debug "Deleting all modules from database." BuildTool::Module.delete_all() @module = {} @modules = [] @cached_modules = {} logger.debug "Deleting all settings from database." BuildTool::Setting.delete_all() @settings = {} end |
#vcs(name) ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/build-tool/configuration.rb', line 175 def vcs( name ) case name when "git-svn" return BuildTool::VCS::GitSvnConfiguration.new when "git" return BuildTool::VCS::GitConfiguration.new when "svn" return BuildTool::VCS::SvnConfiguration.new when "archive" return BuildTool::VCS::ArchiveConfiguration.new when "mercurial" return BuildTool::VCS::MercurialConfiguration.new when "bazar" return BuildTool::VCS::BazarConfiguration.new else raise StandardError, "Unknown Version Control System #{name}" end end |