Class: Albacore::Project

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/albacore/project.rb

Overview

a project encapsulates the properties from a xxproj file.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#debug, #err, #error, #fatal, #info, #puts, #trace, #warn

Constructor Details

#initialize(proj_path) ⇒ Project

Returns a new instance of Project.

Raises:

  • (ArgumentError)


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

def initialize proj_path
  raise ArgumentError, 'project path does not exist' unless File.exists? proj_path.to_s
  proj_path = proj_path.to_s unless proj_path.is_a? String
  @proj_xml_node = Nokogiri.XML(open(proj_path))
  @proj_path_base, @proj_filename = File.split proj_path
  sanity_checks
end

Instance Attribute Details

#proj_filenameObject (readonly)

Returns the value of attribute proj_filename.



17
18
19
# File 'lib/albacore/project.rb', line 17

def proj_filename
  @proj_filename
end

#proj_path_baseObject (readonly)

Returns the value of attribute proj_path_base.



17
18
19
# File 'lib/albacore/project.rb', line 17

def proj_path_base
  @proj_path_base
end

#proj_xml_nodeObject (readonly)

Returns the value of attribute proj_xml_node.



17
18
19
# File 'lib/albacore/project.rb', line 17

def proj_xml_node
  @proj_xml_node
end

Instance Method Details

#asmnameObject

get the assembly name specified in the project file



45
46
47
# File 'lib/albacore/project.rb', line 45

def asmname
  read_property 'AssemblyName'
end

#authorsObject

gets any authors from the project file



55
56
57
# File 'lib/albacore/project.rb', line 55

def authors
  read_property 'Authors'
end

#declared_packagesObject



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

def declared_packages
  return nuget_packages || paket_packages || []
end

#declared_projectsObject



130
131
132
133
134
135
136
# File 'lib/albacore/project.rb', line 130

def declared_projects
  @proj_xml_node.css("ProjectReference").collect do |proj|
    debug "#{name}: found project reference: #{proj.css("Name").inner_text} [albacore: project]"
    Project.new(File.join(@proj_path_base, Albacore::Paths.normalise_slashes(proj['Include'])))
    #OpenStruct.new :name => proj.inner_text
  end
end

#descriptionObject



59
60
61
# File 'lib/albacore/project.rb', line 59

def description
  read_property 'Description'
end

#fallback_output_pathObject

This is the output path if the project file doens’t have a configured ‘Configuration’ condition like all default project files have that come from Visual Studio/Xamarin Studio.



87
88
89
90
91
92
# File 'lib/albacore/project.rb', line 87

def fallback_output_path
  fallback = @proj_xml_node.css("Project PropertyGroup OutputPath").first
  condition = fallback.parent['Condition'] || 'No \'Condition\' specified'
  warn "chose an OutputPath in: '#{self}' for Configuration: <#{condition}> [albacore: project]"
  fallback.inner_text
end

#faulty_refsObject



106
107
108
# File 'lib/albacore/project.rb', line 106

def faulty_refs
  find_refs.to_a.keep_if{ |r| r.children.css("HintPath").empty? }
end

#find_packagesObject

Find all packages that have been declared and can be found in ./src/packages. This is mostly useful if you have that repository structure. returns enumerable Package



157
158
159
160
161
162
163
# File 'lib/albacore/project.rb', line 157

def find_packages
  declared_packages.collect do |package|
    guess = ::Albacore::PackageRepo.new(%w|./packages ./src/packages|).find_latest package.id
    debug "#{name}: guess: #{guess} [albacore: project]"
    guess
  end
end

#find_refsObject

find the NodeList reference list



101
102
103
104
# File 'lib/albacore/project.rb', line 101

def find_refs
  # should always be there
  @proj_xml_node.css("Project Reference")
end

#has_faulty_refs?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/albacore/project.rb', line 110

def has_faulty_refs?
  faulty_refs.any?
end

#has_packages_config?Boolean

Returns:

  • (Boolean)


114
115
116
# File 'lib/albacore/project.rb', line 114

def has_packages_config?
  File.exists? package_config
end

#has_paket_deps?Boolean

Returns:

  • (Boolean)


118
119
120
# File 'lib/albacore/project.rb', line 118

def has_paket_deps?
  File.exists? paket_deps
end

#has_paket_refs?Boolean

Returns:

  • (Boolean)


122
123
124
# File 'lib/albacore/project.rb', line 122

def has_paket_refs?
  File.exists? paket_refs
end

#idObject

Get the project id specified in the project file. Defaults to #name.



28
29
30
31
# File 'lib/albacore/project.rb', line 28

def id
  debug { "Id: #{read_property('Id')}" }
  (read_property 'Id') || name
end

#included_filesObject

returns a list of the files included in the project



139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/albacore/project.rb', line 139

def included_files
  ['Compile','Content','EmbeddedResource','None'].map { |item_name|
    proj_xml_node.xpath("/x:Project/x:ItemGroup/x:#{item_name}",
      'x' => "http://schemas.microsoft.com/developer/msbuild/2003").collect { |f|
      debug "#{name}: #included_files looking at '#{f}' [albacore: project]"
      link = f.elements.select{ |el| el.name == 'Link' }.map { |el| el.content }.first
      OpenStruct.new(:include => f[:Include], 
        :item_name => item_name.downcase,
        :link      => link,
        :include   => f['Include']
      )
    }
  }.flatten
end

#licenseObject

the license that the project has defined in the metadata in the xxproj file.



64
65
66
# File 'lib/albacore/project.rb', line 64

def license
  read_property 'License'
end

#nameObject Also known as: title

Get the project name specified in the project file. This is the same as the title of the nuspec and, if Id is not specified, also the id of the nuspec.



36
37
38
39
# File 'lib/albacore/project.rb', line 36

def name
  debug { "Name: #{read_property('Name')}" }
  (read_property 'Name') || asmname
end

#output_dll(conf) ⇒ Object

Gets the relative location (to the project base path) of the dll that it will output



96
97
98
# File 'lib/albacore/project.rb', line 96

def output_dll conf
  Paths.join(output_path(conf) || fallback_output_path, "#{asmname}.dll")
end

#output_path(conf) ⇒ Object

gets the output path of the project given the configuration or raise an error otherwise



70
71
72
# File 'lib/albacore/project.rb', line 70

def output_path conf
  try_output_path conf || raise(ConfigurationNotFoundError, "could not find configuration '#{conf}'")
end

#package_configObject

get the full path of ‘packages.config’



177
178
179
# File 'lib/albacore/project.rb', line 177

def package_config
  File.join @proj_path_base, 'packages.config'
end

#paket_depsObject

Get the full path of ‘paket.dependencies’



182
183
184
# File 'lib/albacore/project.rb', line 182

def paket_deps
  File.join @proj_path_base, 'paket.dependencies'
end

#paket_refsObject

Get the full path of ‘paket.references’



187
188
189
# File 'lib/albacore/project.rb', line 187

def paket_refs
  File.join @proj_path_base, 'paket.references'
end

#pathObject

get the path of the project file



166
167
168
# File 'lib/albacore/project.rb', line 166

def path
  File.join @proj_path_base, @proj_filename
end

#save(output = nil) ⇒ Object

save the xml



171
172
173
174
# File 'lib/albacore/project.rb', line 171

def save(output = nil)
  output = path unless output
  File.open(output, 'w') { |f| @proj_xml_node.write_xml_to f }
end

#to_sObject

Gets the path of the project file



192
193
194
# File 'lib/albacore/project.rb', line 192

def to_s
  path
end

#try_output_path(conf) ⇒ Object



74
75
76
77
78
79
80
81
82
# File 'lib/albacore/project.rb', line 74

def try_output_path conf
  path = @proj_xml_node.css("Project PropertyGroup[Condition*='#{conf}|'] OutputPath")
  # path = @proj_xml_node.xpath("//Project/PropertyGroup[matches(@Condition, '#{conf}')]/OutputPath")

  debug { "#{name}: output path node[#{conf}]: #{ (path.empty? ? 'empty' : path.inspect) } [albacore: project]" }

  return path.inner_text unless path.empty?
  nil
end

#versionObject

gets the version from the project file



50
51
52
# File 'lib/albacore/project.rb', line 50

def version
  read_property 'Version'
end