Class: RakeDotNet::AssemblyInfoTask

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/rake_dotnet.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) {|_self| ... } ⇒ AssemblyInfoTask

Returns a new instance of AssemblyInfoTask.

Yields:

  • (_self)

Yield Parameters:



306
307
308
309
310
# File 'lib/rake_dotnet.rb', line 306

def initialize(params={})
	@src_dir = params[:src_dir] || SRC_DIR
	yield self if block_given?
	define
end

Instance Attribute Details

#company_nameObject

Returns the value of attribute company_name.



304
305
306
# File 'lib/rake_dotnet.rb', line 304

def company_name
  @company_name
end

#configurationObject

Returns the value of attribute configuration.



304
305
306
# File 'lib/rake_dotnet.rb', line 304

def configuration
  @configuration
end

#product_nameObject

Returns the value of attribute product_name.



304
305
306
# File 'lib/rake_dotnet.rb', line 304

def product_name
  @product_name
end

#versionObject

Returns the value of attribute version.



304
305
306
# File 'lib/rake_dotnet.rb', line 304

def version
  @version
end

Instance Method Details

#asm_info_to_generate(pn_entry) ⇒ Object



359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
# File 'lib/rake_dotnet.rb', line 359

def asm_info_to_generate pn_entry
	if (pn_entry == '.' || pn_entry == '..' || pn_entry == '.svn')
		return nil
	end
	if (pn_entry == 'AssemblyInfo.cs.template' || pn_entry == 'AssemblyInfo.vb.template')
		return nil
	end

	proj = FileList.new("#{@src_dir}/#{pn_entry}/*.*proj").first
	return nil if proj.nil?

	proj_ext = Pathname.new(proj).extname
	path =
			case proj_ext
				when '.csproj' then
					File.join(@src_dir, pn_entry, 'Properties', 'AssemblyInfo.cs')
				when '.vbproj' then
					File.join(@src_dir, pn_entry, 'My Project', 'AssemblyInfo.vb')
				else
					nil
			end
	return path
end

#defineObject



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
# File 'lib/rake_dotnet.rb', line 312

def define
	src_dir_regex = RakeDotNet::regexify(@src_dir)
	rule(/#{src_dir_regex}\/[\w\.\d]+\/Properties\/AssemblyInfo.cs/) do |r|
		dir = Pathname.new(r.name).dirname
		mkdir_p dir
		nextdoor = Pathname.new(r.name + '.template')
		common = Pathname.new(File.join(@src_dir, 'AssemblyInfo.cs.template'))
		if (nextdoor.exist?)
			generate(nextdoor, r.name)
		elsif (common.exist?)
			generate(common, r.name)
		end
	end

	rule(/#{src_dir_regex}\/[\w\.\d]+\/My Project\/AssemblyInfo.vb/) do |r|
		dir = Pathname.new(r.name).dirname
		mkdir_p dir
		nextdoor = Pathname.new(r.name + '.template')
		common = Pathname.new(File.join(@src_dir, 'AssemblyInfo.vb.template'))
		if (nextdoor.exist?)
			generate(nextdoor, r.name)
		elsif (common.exist?)
			generate(common, r.name)
		end
	end

	desc 'Generate the AssemblyInfo.cs file from the template closest'
	task :assembly_info do |t|
		Pathname.new(@src_dir).entries.each do |e|
			asm_info = asm_info_to_generate(e)
			Rake::FileTask[asm_info].invoke unless asm_info.nil?
		end
	end

	self
end

#generate(template_file, destination) ⇒ Object



349
350
351
352
353
354
355
356
357
# File 'lib/rake_dotnet.rb', line 349

def generate(template_file, destination)
	content = template_file.read
	token_replacements.each do |key, value|
		content = content.gsub(/(\$\{#{key}\})/, value.to_s)
	end
	of = Pathname.new(destination)
	of.delete if of.exist?
	of.open('w') { |f| f.puts content }
end

#token_replacementsObject



383
384
385
386
387
388
389
390
391
# File 'lib/rake_dotnet.rb', line 383

def token_replacements
	r = {}
	r[:built_on] = Time.now
	r[:product] = product_name
	r[:configuration] = configuration
	r[:company] = company_name
	r[:version] = version
	return r
end