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.
Direct Known Subclasses
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.
-
#assembly_info_path ⇒ Object
Get AssemblyInfo path.
-
#authors ⇒ Object
gets any authors from the project file.
- #declared_packages ⇒ Object
- #declared_projects ⇒ Object
-
#default_assembly_version ⇒ Object
Reads assembly version information Returns 1.0.0.0 if AssemblyVersion is not found.
- #description ⇒ Object
-
#fallback_output_path ⇒ Object
This is the output path if the project file doesn’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
Find all packages that have been declared and can be found in ./src/packages.
-
#find_refs ⇒ Object
find the NodeList reference list.
-
#guid ⇒ Object
Get the project GUID without ‘or ‘’ characters.
-
#guid_raw ⇒ Object
Get the project GUID as it is in the project file.
- #has_faulty_refs? ⇒ Boolean
- #has_packages_config? ⇒ Boolean
- #has_paket_deps? ⇒ Boolean
- #has_paket_refs? ⇒ Boolean
-
#id ⇒ Object
Get the project id specified in the project file.
-
#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.
-
#namespace ⇒ Object
Get the root namespace of the project.
-
#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 full path of ‘packages.config’.
-
#paket_deps ⇒ Object
Get the full path of ‘paket.dependencies’.
-
#paket_refs ⇒ Object
Get the full path of ‘paket.references’.
-
#path ⇒ Object
get the path of the project file.
-
#save(output = nil) ⇒ Object
save the xml.
-
#target_framework ⇒ Object
the target .NET Framework / .NET Standard version.
-
#to_s ⇒ Object
Gets the path of the project file.
- #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.
20 21 22 23 24 25 26 |
# File 'lib/albacore/project.rb', line 20 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.
18 19 20 |
# File 'lib/albacore/project.rb', line 18 def proj_filename @proj_filename end |
#proj_path_base ⇒ Object (readonly)
Returns the value of attribute proj_path_base.
18 19 20 |
# File 'lib/albacore/project.rb', line 18 def proj_path_base @proj_path_base end |
#proj_xml_node ⇒ Object (readonly)
Returns the value of attribute proj_xml_node.
18 19 20 |
# File 'lib/albacore/project.rb', line 18 def proj_xml_node @proj_xml_node end |
Instance Method Details
#asmname ⇒ Object
get the assembly name specified in the project file
54 55 56 |
# File 'lib/albacore/project.rb', line 54 def asmname read_property 'AssemblyName' end |
#assembly_info_path ⇒ Object
Get AssemblyInfo path
220 221 222 223 224 225 226 227 228 |
# File 'lib/albacore/project.rb', line 220 def assembly_info_path result=@proj_xml_node.css("Compile[Include*='AssemblyInfo']").first # p = if result.nil? @proj_path_base else File.(File.join(@proj_path_base, '/', Albacore::Paths.normalise_slashes(result.attributes["Include"].value))) end p end |
#authors ⇒ Object
gets any authors from the project file
69 70 71 |
# File 'lib/albacore/project.rb', line 69 def read_property 'Authors' end |
#declared_packages ⇒ Object
146 147 148 |
# File 'lib/albacore/project.rb', line 146 def declared_packages return nuget_packages || paket_packages || [] end |
#declared_projects ⇒ Object
150 151 152 153 154 155 156 157 158 |
# File 'lib/albacore/project.rb', line 150 def declared_projects @proj_xml_node.css("ProjectReference").collect do |proj_ref| debug do ref_name = proj_ref.css("Name").inner_text "found project reference: #{name} => #{ref_name} [albacore: project]" end Project.new(File.join(@proj_path_base, Albacore::Paths.normalise_slashes(proj_ref['Include']))) end end |
#default_assembly_version ⇒ Object
Reads assembly version information Returns 1.0.0.0 if AssemblyVersion is not found
235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/albacore/project.rb', line 235 def default_assembly_version begin info= File.read(assembly_info_path) v = info.each_line .select { |l| !(l.start_with?('//')||l.start_with?('/*')) && l.include?('AssemblyVersion(') }.first reg = /"(.*?)"/ reg.match(v).captures.first rescue '1.0.0.0' end end |
#description ⇒ Object
73 74 75 |
# File 'lib/albacore/project.rb', line 73 def description read_property 'Description' end |
#fallback_output_path ⇒ Object
This is the output path if the project file doesn’t have a configured ‘Configuration’ condition like all default project files have that come from Visual Studio/Xamarin Studio.
107 108 109 110 111 112 |
# File 'lib/albacore/project.rb', line 107 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
126 127 128 |
# File 'lib/albacore/project.rb', line 126 def faulty_refs find_refs.to_a.keep_if { |r| r.children.css("HintPath").empty? } end |
#find_packages ⇒ Object
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
179 180 181 182 183 184 185 |
# File 'lib/albacore/project.rb', line 179 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_refs ⇒ Object
find the NodeList reference list
121 122 123 124 |
# File 'lib/albacore/project.rb', line 121 def find_refs # should always be there @proj_xml_node.css("Project Reference") end |
#guid ⇒ Object
Get the project GUID without ‘or ‘’ characters.
29 30 31 |
# File 'lib/albacore/project.rb', line 29 def guid guid_raw.gsub /[\{\}]/, '' end |
#guid_raw ⇒ Object
Get the project GUID as it is in the project file.
34 35 36 |
# File 'lib/albacore/project.rb', line 34 def guid_raw read_property 'ProjectGuid' end |
#has_faulty_refs? ⇒ Boolean
130 131 132 |
# File 'lib/albacore/project.rb', line 130 def has_faulty_refs? faulty_refs.any? end |
#has_packages_config? ⇒ Boolean
134 135 136 |
# File 'lib/albacore/project.rb', line 134 def has_packages_config? File.exists? package_config end |
#has_paket_deps? ⇒ Boolean
138 139 140 |
# File 'lib/albacore/project.rb', line 138 def has_paket_deps? File.exists? paket_deps end |
#has_paket_refs? ⇒ Boolean
142 143 144 |
# File 'lib/albacore/project.rb', line 142 def has_paket_refs? File.exists? paket_refs end |
#id ⇒ Object
Get the project id specified in the project file. Defaults to #name.
39 40 41 |
# File 'lib/albacore/project.rb', line 39 def id (read_property 'Id') || name end |
#included_files ⇒ Object
returns a list of the files included in the project
161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/albacore/project.rb', line 161 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( :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.
78 79 80 |
# File 'lib/albacore/project.rb', line 78 def license read_property 'License' end |
#name ⇒ Object 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.
46 47 48 |
# File 'lib/albacore/project.rb', line 46 def name (read_property 'Name') || asmname end |
#namespace ⇒ Object
Get the root namespace of the project
59 60 61 |
# File 'lib/albacore/project.rb', line 59 def namespace read_property 'RootNamespace' end |
#output_dll(conf) ⇒ Object
Gets the relative location (to the project base path) of the dll that it will output
116 117 118 |
# File 'lib/albacore/project.rb', line 116 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
89 90 91 |
# File 'lib/albacore/project.rb', line 89 def output_path conf try_output_path conf || raise(ConfigurationNotFoundError, "could not find configuration '#{conf}'") end |
#package_config ⇒ Object
get the full path of ‘packages.config’
199 200 201 |
# File 'lib/albacore/project.rb', line 199 def package_config File.join @proj_path_base, 'packages.config' end |
#paket_deps ⇒ Object
Get the full path of ‘paket.dependencies’
204 205 206 |
# File 'lib/albacore/project.rb', line 204 def paket_deps File.join @proj_path_base, 'paket.dependencies' end |
#paket_refs ⇒ Object
Get the full path of ‘paket.references’
209 210 211 |
# File 'lib/albacore/project.rb', line 209 def paket_refs File.join @proj_path_base, 'paket.references' end |
#path ⇒ Object
get the path of the project file
188 189 190 |
# File 'lib/albacore/project.rb', line 188 def path File.join @proj_path_base, @proj_filename end |
#save(output = nil) ⇒ Object
save the xml
193 194 195 196 |
# File 'lib/albacore/project.rb', line 193 def save(output = nil) output = path unless output File.open(output, 'w') { |f| @proj_xml_node.write_xml_to f } end |
#target_framework ⇒ Object
the target .NET Framework / .NET Standard version
83 84 85 |
# File 'lib/albacore/project.rb', line 83 def target_framework read_property 'TargetFrameworkVersion' end |
#to_s ⇒ Object
Gets the path of the project file
214 215 216 |
# File 'lib/albacore/project.rb', line 214 def to_s path end |
#try_output_path(conf) ⇒ Object
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/albacore/project.rb', line 93 def try_output_path conf default_platform = @proj_xml_node.css('Project PropertyGroup Platform').first.inner_text || 'AnyCPU' path = @proj_xml_node.css("Project PropertyGroup[Condition*='#{conf}|#{default_platform}'] 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
64 65 66 |
# File 'lib/albacore/project.rb', line 64 def version read_property 'Version' end |