Class: AssemblyInfo

Inherits:
Object
  • Object
show all
Includes:
Albacore::Task, Configuration::AssemblyInfo
Defined in:
lib/albacore/assemblyinfo.rb

Instance Attribute Summary collapse

Attributes included from Logging

#current_log_device, #logger

Instance Method Summary collapse

Methods included from Configuration::AssemblyInfo

asmconfig, #assemblyinfo

Methods included from Albacore::Configuration

included

Methods included from Albacore::Task

clean_dirname, create_rake_task, include_config, included

Methods included from UpdateAttributes

#<<, #update_attributes

Methods included from YAMLConfig

#configure, #load_config_by_task_name

Methods included from Logging

#create_logger, #log_device=, #log_level, #log_level=

Methods included from Failure

#fail_with_message

Constructor Details

#initializeAssemblyInfo

Returns a new instance of AssemblyInfo.



20
21
22
23
24
25
# File 'lib/albacore/assemblyinfo.rb', line 20

def initialize
  @namespaces = []
  @custom_data = []
  super()
  update_attributes assemblyinfo.to_hash
end

Instance Attribute Details

#com_guidObject

Returns the value of attribute com_guid.



12
13
14
# File 'lib/albacore/assemblyinfo.rb', line 12

def com_guid
  @com_guid
end

#com_visibleObject

Returns the value of attribute com_visible.



12
13
14
# File 'lib/albacore/assemblyinfo.rb', line 12

def com_visible
  @com_visible
end

#company_nameObject

Returns the value of attribute company_name.



12
13
14
# File 'lib/albacore/assemblyinfo.rb', line 12

def company_name
  @company_name
end

Returns the value of attribute copyright.



12
13
14
# File 'lib/albacore/assemblyinfo.rb', line 12

def copyright
  @copyright
end

#custom_attributesObject

Returns the value of attribute custom_attributes.



12
13
14
# File 'lib/albacore/assemblyinfo.rb', line 12

def custom_attributes
  @custom_attributes
end

#descriptionObject

Returns the value of attribute description.



12
13
14
# File 'lib/albacore/assemblyinfo.rb', line 12

def description
  @description
end

#file_versionObject

Returns the value of attribute file_version.



12
13
14
# File 'lib/albacore/assemblyinfo.rb', line 12

def file_version
  @file_version
end

#informational_versionObject

Returns the value of attribute informational_version.



12
13
14
# File 'lib/albacore/assemblyinfo.rb', line 12

def informational_version
  @informational_version
end

#input_fileObject

Returns the value of attribute input_file.



12
13
14
# File 'lib/albacore/assemblyinfo.rb', line 12

def input_file
  @input_file
end

#lang_engineObject

Returns the value of attribute lang_engine.



12
13
14
# File 'lib/albacore/assemblyinfo.rb', line 12

def lang_engine
  @lang_engine
end

#languageObject

Returns the value of attribute language.



12
13
14
# File 'lib/albacore/assemblyinfo.rb', line 12

def language
  @language
end

#output_fileObject

Returns the value of attribute output_file.



12
13
14
# File 'lib/albacore/assemblyinfo.rb', line 12

def output_file
  @output_file
end

#product_nameObject

Returns the value of attribute product_name.



12
13
14
# File 'lib/albacore/assemblyinfo.rb', line 12

def product_name
  @product_name
end

#titleObject

Returns the value of attribute title.



12
13
14
# File 'lib/albacore/assemblyinfo.rb', line 12

def title
  @title
end

#trademarkObject

Returns the value of attribute trademark.



12
13
14
# File 'lib/albacore/assemblyinfo.rb', line 12

def trademark
  @trademark
end

#versionObject

Returns the value of attribute version.



12
13
14
# File 'lib/albacore/assemblyinfo.rb', line 12

def version
  @version
end

Instance Method Details

#build_assembly_info_data(data) ⇒ Object



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
# File 'lib/albacore/assemblyinfo.rb', line 85

def build_assembly_info_data(data)
  # data < []
  # requires: @lang_engine.nil? == false

  if data.empty?
      data = build_header
  end

  data = build_using_statements(data) + data

  build_attribute(data, "AssemblyTitle", @title)
  build_attribute(data, "AssemblyDescription", @description)
  build_attribute(data, "AssemblyCompany", @company_name)
  build_attribute(data, "AssemblyProduct", @product_name)
  
  build_attribute(data, "AssemblyCopyright", @copyright)
  build_attribute(data, "AssemblyTrademark", @trademark)
  
  build_attribute(data, "ComVisible", @com_visible)
  build_attribute(data, "Guid", @com_guid)
  
  build_attribute(data, "AssemblyVersion", @version)
  build_attribute(data, "AssemblyFileVersion", @file_version)
  build_attribute(data, "AssemblyInformationalVersion", @informational_version)
  
  data << ""
  if @custom_attributes != nil
    build_custom_attributes(data)
    data << ""
  end

  @custom_data.each do |cdata| 
    data << cdata unless data.include? cdata
  end
  
  data.concat build_footer

  chomp data
end

#build_attribute(data, attr_name, attr_data, allow_empty_args = false) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/albacore/assemblyinfo.rb', line 138

def build_attribute(data, attr_name, attr_data, allow_empty_args = false)
  if !allow_empty_args and attr_data.nil? then return end
  attr_value = @lang_engine.build_attribute(attr_name, attr_data)
  attr_re = @lang_engine.build_attribute_re(attr_name)
  result = nil
  @logger.debug "Build Assembly Info Attribute: " + attr_value
  data.each do |line|
      break unless result.nil?
      result = line.sub! attr_re, attr_value
  end
  data << attr_value if result.nil?
end

#build_custom_attributes(data) ⇒ Object



166
167
168
169
170
# File 'lib/albacore/assemblyinfo.rb', line 166

def build_custom_attributes(data)
  @custom_attributes.each do |key, value|
    build_attribute(data, key, value, true)
  end
end


134
135
136
# File 'lib/albacore/assemblyinfo.rb', line 134

def build_footer
  @lang_engine.respond_to?(:after) ? [@lang_engine.after()] : []
end

#build_headerObject



130
131
132
# File 'lib/albacore/assemblyinfo.rb', line 130

def build_header
  @lang_engine.respond_to?(:before) ? [@lang_engine.before()] : []
end

#build_using_statements(data) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/albacore/assemblyinfo.rb', line 151

def build_using_statements(data)
  @namespaces = [] if @namespaces.nil?
  
  @namespaces << "System.Reflection"
  @namespaces << "System.Runtime.InteropServices"
  @namespaces.uniq!
  
  ns = []
  @namespaces.each do |n|
    ns << @lang_engine.build_using_statement(n) unless data.index { |l| l.match n }
  end
  
  ns
end

#check_lang_engineObject



81
82
83
# File 'lib/albacore/assemblyinfo.rb', line 81

def check_lang_engine
  !@lang_engine.nil?
end

#check_output_file(file) ⇒ Object



66
67
68
69
70
# File 'lib/albacore/assemblyinfo.rb', line 66

def check_output_file(file)
  return true if file
  fail_with_message 'output_file cannot be nil'
  false
end

#chomp(ary) ⇒ Object



125
126
127
128
# File 'lib/albacore/assemblyinfo.rb', line 125

def chomp(ary)
  non_empty_rindex = ary.rindex {|line| !line.empty? } || 0
  ary.slice(0..non_empty_rindex)
end

#executeObject



31
32
33
34
35
36
# File 'lib/albacore/assemblyinfo.rb', line 31

def execute
  unless check_lang_engine then
    @lang_engine = from_language
  end
  write_assemblyinfo @output_file, @input_file
end

#from_languageObject



72
73
74
75
76
77
78
79
# File 'lib/albacore/assemblyinfo.rb', line 72

def from_language
  ({
    "F#" => lambda { FSharpEngine.new },
    "C#" => lambda { CSharpEngine.new },
    "C++.Net" => lambda { CppCliEngine.new },
    "VB.Net" => lambda { VbNetEngine.new }
  }[@language] || lambda { CSharpEngine.new }).call
end

#read_input_file(file) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/albacore/assemblyinfo.rb', line 53

def read_input_file(file)
  data = []
  return data if file.nil?

  File.open(file, 'r') do |f|
      f.each_line do |line|
          data << line.strip
      end
  end

  data
end

#use(file) ⇒ Object



27
28
29
# File 'lib/albacore/assemblyinfo.rb', line 27

def use(file)
  @input_file = @output_file = file
end

#write_assemblyinfo(assemblyinfo_file, input_file) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/albacore/assemblyinfo.rb', line 38

def write_assemblyinfo(assemblyinfo_file, input_file)
  valid = check_output_file assemblyinfo_file
  return if !valid

  input_data = read_input_file input_file
  asm_data = build_assembly_info_data input_data

  @logger.info "Generating Assembly Info File At: " + File.expand_path(assemblyinfo_file)
  File.open(assemblyinfo_file, 'w') do |f|      
    asm_data.each do |line|
      f.puts line
    end
  end
end