Class: BuildTool::Module
- Inherits:
-
Object
- Object
- BuildTool::Module
- Defined in:
- lib/build-tool/module.rb
Overview
Represents the information associated with a buildable module.
Instance Attribute Summary collapse
-
#active ⇒ Object
writeonly
Sets the attribute active.
- #build_system ⇒ Object
- #description ⇒ Object
- #environment ⇒ Object
-
#feature ⇒ Object
writeonly
ATTRIBUTES.
-
#is_template ⇒ Object
writeonly
Sets the attribute is_template.
- #long_description ⇒ Object
-
#name ⇒ Object
readonly
The module name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#patches ⇒ Object
readonly
Returns the value of attribute patches.
- #vcs_configuration ⇒ Object
Instance Method Summary collapse
- #active? ⇒ Boolean
-
#build_directory ⇒ Object
not inherited.
- #build_prefix ⇒ Object
- #build_prefix=(path) ⇒ Object
-
#build_prefix_required ⇒ Object
Will throw a exception if build_prefix is not set.
-
#build_system_required ⇒ Object
Will throw a exception if build_system is not set.
- #checkedout? ⇒ Boolean
-
#clean(remove_build_directory = false) ⇒ Object
ACTIONS.
-
#cleanup_after_vcs_access ⇒ Object
Cleanup after vcs_access.
-
#clone ⇒ Object
Clone the repository.
- #configure ⇒ Object
- #configured? ⇒ Boolean
-
#environment_required ⇒ Object
Will throw a exception if environment is not set.
-
#fetch ⇒ Object
Fetch changes from the remote repository.
-
#gc ⇒ Object
Garbage collect.
-
#initialize(name, parent = nil) ⇒ Module
constructor
Create a module.
- #install(fast = false) ⇒ Object
- #install_prefix ⇒ Object
-
#install_prefix=(path) ⇒ Object
Installation prefix.
-
#install_prefix_required ⇒ Object
Will throw a exception if install_prefix is not set.
- #is_template? ⇒ Boolean
- #local_path ⇒ Object
- #local_path=(local_path) ⇒ Object
-
#make(target = nil) ⇒ Object
Call make.
- #our_build_system ⇒ Object
- #prepare_for_installation ⇒ Object
-
#prepare_for_vcs_access ⇒ Object
Check if an ssh-key is required and active it if necessary.
-
#rebase ⇒ Object
Update the local changes with remote changes.
- #reconfigure ⇒ Object
- #remote_path ⇒ Object
-
#remote_path=(remote_path) ⇒ Object
Remote path.
- #repository ⇒ Object
-
#repository=(repository) ⇒ Object
Repository.
- #repository_required ⇒ Object
- #source_directory ⇒ Object (also: #source_directory_required)
- #to_s ⇒ Object
- #vcs ⇒ Object
- #vcs_configuration_required ⇒ Object
- #vcs_required ⇒ Object
Constructor Details
#initialize(name, parent = nil) ⇒ Module
Create a module
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/build-tool/module.rb', line 13 def initialize( name, parent = nil ) if name.nil? raise StandardError, "Module name is required!" end @active = nil @patches = Array.new @name = name @parent = parent @local_path = nil @build_prefix = nil @remote_path = nil @environment = nil @build_system = nil @repository = nil @install_prefix = nil @is_template = false @vcs_configuration = nil @feature = nil @long_description = nil @description = nil end |
Instance Attribute Details
#active=(value) ⇒ Object (writeonly)
Sets the attribute active
40 41 42 |
# File 'lib/build-tool/module.rb', line 40 def active=(value) @active = value end |
#build_system ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/build-tool/module.rb', line 88 def build_system # Return our own buildsystem if there is one return @build_system if @build_system # Return our parents buildsystem if there is one if @parent && @parent.build_system @build_system = @parent.build_system.dup @build_system.module = self return @build_system end # Nothing nil end |
#description ⇒ Object
125 126 127 |
# File 'lib/build-tool/module.rb', line 125 def description @description end |
#environment ⇒ Object
132 133 134 135 136 137 138 139 |
# File 'lib/build-tool/module.rb', line 132 def environment # Return our own buildsystem if there is one return @environment if @environment # Return our parents buildsystem if there is one return @parent.environment if @parent && @parent.environment # Nothing nil end |
#feature=(value) ⇒ Object (writeonly)
ATTRIBUTES
39 40 41 |
# File 'lib/build-tool/module.rb', line 39 def feature=(value) @feature = value end |
#is_template=(value) ⇒ Object (writeonly)
Sets the attribute is_template
176 177 178 |
# File 'lib/build-tool/module.rb', line 176 def is_template=(value) @is_template = value end |
#long_description ⇒ Object
191 192 193 |
# File 'lib/build-tool/module.rb', line 191 def long_description @long_description end |
#name ⇒ Object (readonly)
The module name
196 197 198 |
# File 'lib/build-tool/module.rb', line 196 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
42 43 44 |
# File 'lib/build-tool/module.rb', line 42 def parent @parent end |
#patches ⇒ Object (readonly)
Returns the value of attribute patches.
41 42 43 |
# File 'lib/build-tool/module.rb', line 41 def patches @patches end |
#vcs_configuration ⇒ Object
235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/build-tool/module.rb', line 235 def vcs_configuration return @vcs_configuration if @vcs_configuration if @parent && @parent.vcs_configuration # puts "copying vcs for #{name} from #{@parent.name}" vc = @parent.vcs_configuration.class.new vc.copy_configuration( @parent.vcs_configuration ) @vcs_configuration = vc return vc end nil end |
Instance Method Details
#active? ⇒ Boolean
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/build-tool/module.rb', line 44 def active? # If the module is activated that wins if @active.nil? if @feature.nil? return true else return @feature.active? end else return @active end end |
#build_directory ⇒ Object
not inherited
58 59 60 |
# File 'lib/build-tool/module.rb', line 58 def build_directory build_prefix_required.join("bld", local_path) end |
#build_prefix ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/build-tool/module.rb', line 70 def build_prefix # Return our own buildsystem if there is one return @build_prefix if @build_prefix # Return our parents buildsystem if there is one return @parent.build_prefix if @parent && @parent.build_prefix # Nothing nil end |
#build_prefix=(path) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/build-tool/module.rb', line 62 def build_prefix=( path ) if path @build_prefix = Pathname.new( File.( path ) ) else @build_prefix = nil end end |
#build_prefix_required ⇒ Object
Will throw a exception if build_prefix is not set
80 81 82 83 |
# File 'lib/build-tool/module.rb', line 80 def build_prefix_required return self.build_prefix if self.build_prefix raise ConfigurationError, "No build prefix configured for #{name}!" end |
#build_system_required ⇒ Object
Will throw a exception if build_system is not set
106 107 108 109 110 |
# File 'lib/build-tool/module.rb', line 106 def build_system_required return self.build_system if self.build_system # *TODO* try to guess the build system raise ConfigurationError, "No build system configured for #{name}!" end |
#checkedout? ⇒ Boolean
112 113 114 |
# File 'lib/build-tool/module.rb', line 112 def checkedout? vcs_required.checkedout? end |
#clean(remove_build_directory = false) ⇒ Object
ACTIONS
271 272 273 274 275 276 277 278 279 |
# File 'lib/build-tool/module.rb', line 271 def clean( remove_build_directory = false ) if remove_build_directory logger.info "Removing build directory." build_system_required.remove_build_directory else logger.info "Cleaning build directory." build_system_required.make( "clean" ) end end |
#cleanup_after_vcs_access ⇒ Object
Cleanup after vcs_access
330 331 332 333 334 335 336 337 338 339 |
# File 'lib/build-tool/module.rb', line 330 def cleanup_after_vcs_access if MJ::Tools::SSH::has_keys? logger.info "" logger.info "#### Cleaning up the ssh keys" MJ::Tools::SSH::keys.each do |file| logger.info " - Removing key #{file}" end MJ::Tools::SSH::cleanup() end end |
#clone ⇒ Object
Clone the repository.
283 284 285 286 287 288 289 290 291 |
# File 'lib/build-tool/module.rb', line 283 def clone vcs_required.clone if !patches.empty? if !vcs.patches_supported? raise NotImplementedError, "Patch support not implemented for vcs #{vcs.name}" end vcs_required.apply_patches( patches ) end end |
#configure ⇒ Object
312 313 314 |
# File 'lib/build-tool/module.rb', line 312 def configure build_system_required.configure end |
#configured? ⇒ Boolean
116 117 118 119 120 121 122 |
# File 'lib/build-tool/module.rb', line 116 def configured? if build_system return build_system.configured? else return false end end |
#environment_required ⇒ Object
Will throw a exception if environment is not set
142 143 144 145 |
# File 'lib/build-tool/module.rb', line 142 def environment_required return self.environment if self.environment raise ConfigurationError, "No environment configured for #{name}!" end |
#fetch ⇒ Object
Fetch changes from the remote repository. Do not change the local checkout.
295 296 297 |
# File 'lib/build-tool/module.rb', line 295 def fetch vcs_required.fetch end |
#gc ⇒ Object
Garbage collect
148 149 150 |
# File 'lib/build-tool/module.rb', line 148 def gc vcs.gc end |
#install(fast = false) ⇒ Object
325 326 327 |
# File 'lib/build-tool/module.rb', line 325 def install( fast = false ) build_system_required.install( fast ) end |
#install_prefix ⇒ Object
161 162 163 164 165 166 167 168 |
# File 'lib/build-tool/module.rb', line 161 def install_prefix # Return our own buildsystem if there is one return @install_prefix if @install_prefix # Return our parents buildsystem if there is one return @parent.install_prefix if @parent && @parent.install_prefix # Nothing nil end |
#install_prefix=(path) ⇒ Object
Installation prefix
153 154 155 156 157 158 159 |
# File 'lib/build-tool/module.rb', line 153 def install_prefix=( path ) if path @install_prefix = Pathname.new( File.( path.to_s ) ) else @install_prefix = nil end end |
#install_prefix_required ⇒ Object
Will throw a exception if install_prefix is not set
171 172 173 174 |
# File 'lib/build-tool/module.rb', line 171 def install_prefix_required return self.install_prefix if self.install_prefix raise ConfigurationError, "No install prefix configured for #{name}!" end |
#is_template? ⇒ Boolean
177 178 179 |
# File 'lib/build-tool/module.rb', line 177 def is_template? @is_template end |
#local_path ⇒ Object
186 187 188 |
# File 'lib/build-tool/module.rb', line 186 def local_path @local_path || @name end |
#local_path=(local_path) ⇒ Object
181 182 183 184 |
# File 'lib/build-tool/module.rb', line 181 def local_path=( local_path ) raise ConfigurationError, "Attempt to set local_path for module template #{name}" if is_template? @local_path = local_path end |
#make(target = nil) ⇒ Object
Call make
321 322 323 |
# File 'lib/build-tool/module.rb', line 321 def make( target = nil ) build_system_required.make( target ) end |
#our_build_system ⇒ Object
101 102 103 |
# File 'lib/build-tool/module.rb', line 101 def our_build_system @build_system end |
#prepare_for_installation ⇒ Object
353 354 355 356 357 358 359 360 361 362 363 364 |
# File 'lib/build-tool/module.rb', line 353 def prepare_for_installation prefix = install_prefix_required if !prefix.exist? or !prefix.writable? begin FileUtils.mkdir_p prefix.to_s rescue Errno::EACCES => e logger.error "#{name}: The directory #{prefix.to_s} is not writable! Installation will fail!" return false end end return true end |
#prepare_for_vcs_access ⇒ Object
Check if an ssh-key is required and active it if necessary
342 343 344 345 346 347 348 349 350 351 |
# File 'lib/build-tool/module.rb', line 342 def prepare_for_vcs_access if key = repository_required.sshkey if !MJ::Tools::SSH::has_key? key.file logger.info "" logger.info "#### Adding required ssh-key #{key.file} to ssh-agent." MJ::Tools::SSH::add_key key.file end end return true end |
#rebase ⇒ Object
Update the local changes with remote changes. Do not fetch changes from the remote repository.
301 302 303 304 305 306 307 308 309 310 |
# File 'lib/build-tool/module.rb', line 301 def rebase vcs_required.rebase if !patches.empty? if !vcs.patches_supported? raise NotImplementedError, "Patch support not implemented for vcs #{vcs.name}" end vcs_required.apply_patches( patches ) end build_system_required.after_rebase end |
#reconfigure ⇒ Object
316 317 318 |
# File 'lib/build-tool/module.rb', line 316 def reconfigure build_system_required.reconfigure end |
#remote_path ⇒ Object
204 205 206 |
# File 'lib/build-tool/module.rb', line 204 def remote_path @remote_path || @name end |
#remote_path=(remote_path) ⇒ Object
Remote path
199 200 201 202 |
# File 'lib/build-tool/module.rb', line 199 def remote_path=( remote_path ) raise ConfigurationError, "Attempt to set remote_path for module template #{name}" if is_template? @remote_path = remote_path end |
#repository ⇒ Object
213 214 215 216 |
# File 'lib/build-tool/module.rb', line 213 def repository return @repository if @repository return @parent.repository if @parent && @parent.repository end |
#repository=(repository) ⇒ Object
Repository
209 210 211 |
# File 'lib/build-tool/module.rb', line 209 def repository=( repository ) @repository = repository end |
#repository_required ⇒ Object
218 219 220 221 222 |
# File 'lib/build-tool/module.rb', line 218 def repository_required repo = self.repository return repo if repo raise ConfigurationError, "No repository configured for #{name}!" end |
#source_directory ⇒ Object Also known as: source_directory_required
224 225 226 |
# File 'lib/build-tool/module.rb', line 224 def source_directory build_prefix_required.join("src", local_path) end |
#to_s ⇒ Object
366 367 368 |
# File 'lib/build-tool/module.rb', line 366 def to_s "#{object_id}: #{name}" end |
#vcs ⇒ Object
229 230 231 232 |
# File 'lib/build-tool/module.rb', line 229 def vcs return vcs_configuration.vcs( self ) if vcs_configuration nil end |
#vcs_configuration_required ⇒ Object
247 248 249 250 251 252 253 |
# File 'lib/build-tool/module.rb', line 247 def vcs_configuration_required vc = vcs_configuration if vc.nil? raise ConfigurationError, "No version control system configure for module #{name}." end return vc end |
#vcs_required ⇒ Object
255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/build-tool/module.rb', line 255 def vcs_required if repository.nil? raise ConfigurationError, "No repository specified for module #{name}." end if remote_path.nil? raise ConfigurationError, "No remote path specified for module #{name}." end if source_directory.nil? raise ConfigurationError, "No source directory specified for module #{name}." end return vcs_configuration_required.vcs( self ) end |