Class: Albacore::Project
- Inherits:
-
Object
- Object
- Albacore::Project
- Includes:
- Logging
- Defined in:
- lib/albacore/project.rb
Overview
a project encapsulates the properties from a xxproj file.
Instance Attribute Summary collapse
-
#proj_filename ⇒ Object
readonly
Returns the value of attribute proj_filename.
-
#proj_path_base ⇒ Object
readonly
Returns the value of attribute proj_path_base.
-
#proj_xml_node ⇒ Object
readonly
Returns the value of attribute proj_xml_node.
Instance Method Summary collapse
-
#asmname ⇒ Object
get the assembly name specified in the project file.
-
#authors ⇒ Object
gets any authors from the project file.
- #declared_packages ⇒ Object
- #declared_projects ⇒ Object
- #description ⇒ Object
-
#fallback_output_path ⇒ Object
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.
- #faulty_refs ⇒ Object
-
#find_packages ⇒ Object
returns enumerable Package.
-
#find_refs ⇒ Object
find the NodeList reference list.
- #has_faulty_refs? ⇒ Boolean
- #has_packages_config? ⇒ Boolean
-
#included_files ⇒ Object
returns a list of the files included in the project.
-
#initialize(proj_path) ⇒ Project
constructor
A new instance of Project.
-
#license ⇒ Object
the license that the project has defined in the metadata in the xxproj file.
-
#name ⇒ Object
(also: #title)
get the project name specified in the project file.
-
#output_dll(conf) ⇒ Object
Gets the relative location (to the project base path) of the dll that it will output.
-
#output_path(conf) ⇒ Object
gets the output path of the project given the configuration or raise an error otherwise.
-
#package_config ⇒ Object
get the path of ‘packages.config’.
-
#path ⇒ Object
get the path of the project file.
-
#save(output = nil) ⇒ Object
save the xml.
- #to_s ⇒ Object
- #try_output_path(conf) ⇒ Object
-
#version ⇒ Object
gets the version from the project file.
Methods included from Logging
#debug, #err, #error, #fatal, #info, #puts, #trace, #warn
Constructor Details
#initialize(proj_path) ⇒ Project
Returns a new instance of Project.
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_filename ⇒ Object (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_base ⇒ Object (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_node ⇒ Object (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
#asmname ⇒ Object
get the assembly name specified in the project file
37 38 39 |
# File 'lib/albacore/project.rb', line 37 def asmname read_property 'AssemblyName' end |
#authors ⇒ Object
gets any authors from the project file
47 48 49 |
# File 'lib/albacore/project.rb', line 47 def read_property 'Authors' end |
#declared_packages ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/albacore/project.rb', line 110 def declared_packages return [] unless has_packages_config? doc = Nokogiri.XML(open(package_config)) doc.xpath("//packages/package").collect { |p| OpenStruct.new(:id => p[:id], :version => p[:version], :target_framework => p[:targetFramework], :semver => Albacore::SemVer.parse(p[:version], '%M.%m.%p', false) ) } end |
#declared_projects ⇒ Object
122 123 124 125 126 127 128 |
# File 'lib/albacore/project.rb', line 122 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 |
#description ⇒ Object
51 52 53 |
# File 'lib/albacore/project.rb', line 51 def description read_property 'Description' end |
#fallback_output_path ⇒ Object
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.
79 80 81 82 83 84 |
# File 'lib/albacore/project.rb', line 79 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_refs ⇒ Object
98 99 100 |
# File 'lib/albacore/project.rb', line 98 def faulty_refs find_refs.to_a.keep_if{ |r| r.children.css("HintPath").empty? } end |
#find_packages ⇒ Object
returns enumerable Package
147 148 149 150 151 152 153 |
# File 'lib/albacore/project.rb', line 147 def find_packages declared_packages.collect do |package| guess = ::Albacore::PackageRepo.new('./src/packages').find_latest package.id debug "#{name}: guess: #{guess} [albacore: project]" guess end end |
#find_refs ⇒ Object
find the NodeList reference list
93 94 95 96 |
# File 'lib/albacore/project.rb', line 93 def find_refs # should always be there @proj_xml_node.css("Project Reference") end |
#has_faulty_refs? ⇒ Boolean
102 103 104 |
# File 'lib/albacore/project.rb', line 102 def has_faulty_refs? faulty_refs.any? end |
#has_packages_config? ⇒ Boolean
106 107 108 |
# File 'lib/albacore/project.rb', line 106 def has_packages_config? File.exists? package_config end |
#included_files ⇒ Object
returns a list of the files included in the project
131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/albacore/project.rb', line 131 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 |
#license ⇒ Object
the license that the project has defined in the metadata in the xxproj file.
56 57 58 |
# File 'lib/albacore/project.rb', line 56 def license read_property 'License' end |
#name ⇒ Object Also known as: title
get the project name specified in the project file
28 29 30 31 |
# File 'lib/albacore/project.rb', line 28 def name prop = read_property 'Name' || asmname prop || asmname end |
#output_dll(conf) ⇒ Object
Gets the relative location (to the project base path) of the dll that it will output
88 89 90 |
# File 'lib/albacore/project.rb', line 88 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
62 63 64 |
# File 'lib/albacore/project.rb', line 62 def output_path conf try_output_path conf || raise(ConfigurationNotFoundError, "could not find configuration '#{conf}'") end |
#package_config ⇒ Object
get the path of ‘packages.config’
167 168 169 |
# File 'lib/albacore/project.rb', line 167 def package_config File.join @proj_path_base, 'packages.config' end |
#path ⇒ Object
get the path of the project file
156 157 158 |
# File 'lib/albacore/project.rb', line 156 def path File.join @proj_path_base, @proj_filename end |
#save(output = nil) ⇒ Object
save the xml
161 162 163 164 |
# File 'lib/albacore/project.rb', line 161 def save(output = nil) output = path unless output File.open(output, 'w') { |f| @proj_xml_node.write_xml_to f } end |
#to_s ⇒ Object
171 172 173 |
# File 'lib/albacore/project.rb', line 171 def to_s path end |
#try_output_path(conf) ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/albacore/project.rb', line 66 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 |
#version ⇒ Object
gets the version from the project file
42 43 44 |
# File 'lib/albacore/project.rb', line 42 def version read_property 'Version' end |