Class: Application
- Inherits:
-
Object
- Object
- Application
- Defined in:
- lib/conan/application.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#artifact_id ⇒ Object
Returns the value of attribute artifact_id.
-
#artifact_meta_data ⇒ Object
Returns the value of attribute artifact_meta_data.
-
#extension ⇒ Object
Returns the value of attribute extension.
-
#group_id ⇒ Object
Returns the value of attribute group_id.
-
#id ⇒ Object
Returns the value of attribute id.
-
#infra ⇒ Object
Returns the value of attribute infra.
-
#org ⇒ Object
Returns the value of attribute org.
-
#platform_type ⇒ Object
Returns the value of attribute platform_type.
-
#sha1 ⇒ Object
Returns the value of attribute sha1.
-
#url_segment ⇒ Object
Returns the value of attribute url_segment.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
- #compareVersion(target_version, deployed_version) ⇒ Object
- #download(location) ⇒ Object
- #findRequestedVersion(requested_version = 'LATEST') ⇒ Object
-
#initialize(id, project_name, platform_type, options, url_segment = nil) ⇒ Application
constructor
A new instance of Application.
- #isDeployedAt(url) ⇒ Object
- #readArtifactMetadata(xml) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(id, project_name, platform_type, options, url_segment = nil) ⇒ Application
Returns a new instance of Application.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/conan/application.rb', line 7 def initialize(id, project_name, platform_type, , url_segment=nil) @id = id @platform_type = platform_type @url_segment = url_segment || id mvn_id = project_name.split(':') @options = @org = [:'deploy-shipcloud'].split('-')[0] @infra = [:'deploy-shipcloud'].split('-')[1] @environment = [:environment] @group_id = mvn_id[0] @artifact_id = mvn_id[1] end |
Instance Attribute Details
#artifact_id ⇒ Object
Returns the value of attribute artifact_id.
4 5 6 |
# File 'lib/conan/application.rb', line 4 def artifact_id @artifact_id end |
#artifact_meta_data ⇒ Object
Returns the value of attribute artifact_meta_data.
4 5 6 |
# File 'lib/conan/application.rb', line 4 def @artifact_meta_data end |
#extension ⇒ Object
Returns the value of attribute extension.
4 5 6 |
# File 'lib/conan/application.rb', line 4 def extension @extension end |
#group_id ⇒ Object
Returns the value of attribute group_id.
4 5 6 |
# File 'lib/conan/application.rb', line 4 def group_id @group_id end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/conan/application.rb', line 4 def id @id end |
#infra ⇒ Object
Returns the value of attribute infra.
4 5 6 |
# File 'lib/conan/application.rb', line 4 def infra @infra end |
#org ⇒ Object
Returns the value of attribute org.
4 5 6 |
# File 'lib/conan/application.rb', line 4 def org @org end |
#platform_type ⇒ Object
Returns the value of attribute platform_type.
4 5 6 |
# File 'lib/conan/application.rb', line 4 def platform_type @platform_type end |
#sha1 ⇒ Object
Returns the value of attribute sha1.
4 5 6 |
# File 'lib/conan/application.rb', line 4 def sha1 @sha1 end |
#url_segment ⇒ Object
Returns the value of attribute url_segment.
4 5 6 |
# File 'lib/conan/application.rb', line 4 def url_segment @url_segment end |
#version ⇒ Object
Returns the value of attribute version.
4 5 6 |
# File 'lib/conan/application.rb', line 4 def version @version end |
Instance Method Details
#compareVersion(target_version, deployed_version) ⇒ Object
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/conan/application.rb', line 99 def compareVersion(target_version, deployed_version) target = Gem::Version.new(target_version) begin found = Gem::Version.new(deployed_version) target > found rescue => e puts "Error parsing version number: #{e}" false end end |
#download(location) ⇒ Object
54 55 56 57 |
# File 'lib/conan/application.rb', line 54 def download(location) puts "- Provision #{group_id}:#{artifact_id}:#{extension}:#{version}" @artifact_repo.downloadArtifact(location, group_id, artifact_id, extension, version, sha1) end |
#findRequestedVersion(requested_version = 'LATEST') ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/conan/application.rb', line 20 def findRequestedVersion(requested_version='LATEST') puts("Finding requested version: #{requested_version}") extension = case platform_type when :jvm "jar" when :rails_zip "tar.gz" else raise "Unsupported platform type: #{platform_type}" end readArtifactMetadata(@artifact_repo.resolveArtifact(group_id, artifact_id, extension, requested_version)) puts "- Found version #{version} #{@id} artifact\n"+ " Artifact: #{self}\n" + " Checksum: #{@sha1}" end |
#isDeployedAt(url) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/conan/application.rb', line 59 def isDeployedAt(url) # only deploy if an older version is found, or no app found res = false begin response = RestClient::Request.new( :method => :get, :url => url, :headers => { 'accept' => :json, 'content_type' => :json }, :timeout => 5, :open_timeout => 5 ).execute if (response.code == 200) = JSON.parse(response.to_str) puts '' puts "+- Currently at #{url}:" printM = ->(s) { puts " | #{s}: #{[s]}" } printM.call 'Implementation-Title' printM.call 'Build-Version' printM.call 'Build-Url' printM.call 'Git-Commit' current_ver = ["Build-Version"] end #TODO make sure the artifact id matches too, currently finding "Implementation-Title": "apollo" in build metadata if (compareVersion(@version, current_ver)) puts "#{@artifact_id} #{@version} is newer than version found at #{url}: #{current_ver}" else puts "#{@artifact_id} #{@version} found at #{url}. (skipping deployment)" res = true end rescue => e puts "#{@artifact_id} not found at #{url}: #{e}" end res end |
#readArtifactMetadata(xml) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/conan/application.rb', line 36 def readArtifactMetadata(xml) @artifact_meta_data = xml begin doc = REXML::Document.new(xml) rescue Exception => e puts "Failed to parse meta-data: #{e}" puts "--------------------------------" puts xml puts "--------------------------------" raise "Unreadable artifact meta-data for #{self}" end = doc.elements['/artifact-resolution/data'] @version = .elements['version'].text @sha1 = .elements['sha1'].text @extension = .elements['extension'].text end |
#to_s ⇒ Object
110 111 112 |
# File 'lib/conan/application.rb', line 110 def to_s "#{artifact_id}-#{version}.#{extension}" end |