Class: Winter::Dependency
- Inherits:
-
Object
- Object
- Winter::Dependency
- Defined in:
- lib/winter/dependency.rb
Instance Attribute Summary collapse
-
#artifact ⇒ Object
Returns the value of attribute artifact.
-
#destination ⇒ Object
Returns the value of attribute destination.
-
#group ⇒ Object
Returns the value of attribute group.
-
#offline ⇒ Object
Returns the value of attribute offline.
-
#package ⇒ Object
Returns the value of attribute package.
-
#repositories ⇒ Object
Returns the value of attribute repositories.
-
#transative ⇒ Object
Returns the value of attribute transative.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
- #artifactory_path ⇒ Object
- #dest_file ⇒ Object
- #get ⇒ Object
- #getLocalM2 ⇒ Object
-
#getMaven ⇒ Object
Depricated because its slow and expensive to use…
- #getRestArtifactory ⇒ Object
-
#initialize ⇒ Dependency
constructor
A new instance of Dependency.
- #outputFilename ⇒ Object
- #restRequest(uri) ⇒ Object
Constructor Details
#initialize ⇒ Dependency
Returns a new instance of Dependency.
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/winter/dependency.rb', line 32 def initialize @artifact = nil @group = nil @version = 'LATEST' @repositories = [] @package = 'jar' @offline = false @transative = false @verbose = false @destination = '.' end |
Instance Attribute Details
#artifact ⇒ Object
Returns the value of attribute artifact.
23 24 25 |
# File 'lib/winter/dependency.rb', line 23 def artifact @artifact end |
#destination ⇒ Object
Returns the value of attribute destination.
30 31 32 |
# File 'lib/winter/dependency.rb', line 30 def destination @destination end |
#group ⇒ Object
Returns the value of attribute group.
24 25 26 |
# File 'lib/winter/dependency.rb', line 24 def group @group end |
#offline ⇒ Object
Returns the value of attribute offline.
28 29 30 |
# File 'lib/winter/dependency.rb', line 28 def offline @offline end |
#package ⇒ Object
Returns the value of attribute package.
27 28 29 |
# File 'lib/winter/dependency.rb', line 27 def package @package end |
#repositories ⇒ Object
Returns the value of attribute repositories.
26 27 28 |
# File 'lib/winter/dependency.rb', line 26 def repositories @repositories end |
#transative ⇒ Object
Returns the value of attribute transative.
29 30 31 |
# File 'lib/winter/dependency.rb', line 29 def transative @transative end |
#version ⇒ Object
Returns the value of attribute version.
25 26 27 |
# File 'lib/winter/dependency.rb', line 25 def version @version end |
Instance Method Details
#artifactory_path ⇒ Object
61 62 63 |
# File 'lib/winter/dependency.rb', line 61 def artifactory_path "#{@group.gsub(/\./,'/')}/#{@artifact}/#{@version}/#{@artifact}-#{@version}.#{@package}" end |
#dest_file ⇒ Object
65 66 67 |
# File 'lib/winter/dependency.rb', line 65 def dest_file File.join(@destination,outputFilename) end |
#get ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/winter/dependency.rb', line 44 def get if ! File.directory?(@destination) $LOG.debug "Create the destination folder if its not already there." FileUtils.mkdir_p @destination end #Try and get file in a couple different ways. If we succeed then move on. #Artifacts in your local .m2 ALWAYS take precedence over a remote artifact... #Unless we fail so hard we end up using mvn as a last ditched effort. success = getLocalM2 success = getRestArtifactory if ! success and ! @offline success = getMaven if ! success and system( 'which mvn > /dev/null' ) if ! success $LOG.info "[failed] #{outputFilename}" end return success end |
#getLocalM2 ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/winter/dependency.rb', line 110 def getLocalM2 log_prefix = "[local] " begin artifact = "#{ENV["HOME"]}/.m2/repository/#{artifactory_path}" $LOG.debug "#{log_prefix}#{outputFilename}: Copying #{artifact} to #{dest_file}" FileUtils.cp(artifact,dest_file) rescue Errno::ENOENT $LOG.debug "#{log_prefix}#{outputFilename}: #{artifact} does not exist." rescue SystemCallError => e $LOG.error "#{log_prefix}#{outputFilename}: Failed to copy file from local m2 repository." $LOG.error e else #Yay we got it $LOG.debug "#{log_prefix}#{outputFilename}: Successfully copied from local m2 repository." $LOG.info "#{log_prefix}#{outputFilename}" return true end return false end |
#getMaven ⇒ Object
Depricated because its slow and expensive to use… leaving it here for now.
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/winter/dependency.rb', line 130 def getMaven log_prefix = "[maven] " c = "mvn org.apache.maven.plugins:maven-dependency-plugin:2.5:get " c << " -DremoteRepositories=#{@repositories.join(',').shellescape}" c << " -Dtransitive=#{@transative}" c << " -Dartifact=#{@group.shellescape}:#{@artifact.shellescape}:#{@version.shellescape}:#{@package.shellescape}" c << " -Ddest=#{dest_file.shellescape} &>/dev/null" if @offline c << " --offline" end if !@verbose #quiet mode is default c << " -q" end result = system( c ) if result == false $LOG.error("#{log_prefix}#{outputFilename}: Failed to retrieve artifact. -- #{c}") else $LOG.info "#{log_prefix}#{@group}:#{@artifact}:#{@version}:#{@package}" $LOG.debug "#{log_prefix}#{dest_file}" end return result end |
#getRestArtifactory ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/winter/dependency.rb', line 76 def getRestArtifactory log_prefix = '[remote] ' $LOG.debug "#{log_prefix}#{outputFilename}: Attempting to fetch via the artifactory rest api." #Loop through all the repos until something works @repositories.each { |repo| begin open(dest_file,"wb") { |file| file.write(restRequest(URI.parse("#{repo}/#{artifactory_path}"))) } rescue SocketError,RuntimeError => e # :( Maybe do better handling later. $LOG.error "#{log_prefix}#{outputFilename}: Unable to fetch Artifact from #{repo}/#{artifactory_path}" $LOG.debug e next end #Check to make sure the md5sum of what we downloaded matches what's in the artifactory. begin artifactory_md5 = restRequest(URI.parse("#{repo}/#{artifactory_path}.md5")) my_md5 = Digest::MD5.file("#{dest_file}").hexdigest rescue SocketError, RuntimeError => e # :( Do better handling later. $LOG.error "#{log_prefix}#{outputFilename}: Blew up while attempting to get md5s." else if artifactory_md5 == my_md5 $LOG.debug "#{log_prefix}#{outputFilename}: Successfully fetched via artifactory rest api." $LOG.info "#{log_prefix}#{outputFilename}" return true end $LOG.error "#{log_prefix}#{outputFilename}: Comparing remote MD5 #{artifactory_md5} to local md5 #{my_md5} (#{dest_file})" $LOG.error "#{log_prefix}#{outputFilename}: Comparison failed. Deleting the 'bad' jar and moving on." FileUtils.rm(dest_file) end } return false end |
#outputFilename ⇒ Object
157 158 159 |
# File 'lib/winter/dependency.rb', line 157 def outputFilename "#{@artifact}-#{@version}.#{@package}" end |
#restRequest(uri) ⇒ Object
69 70 71 72 73 74 |
# File 'lib/winter/dependency.rb', line 69 def restRequest(uri) response = Net::HTTP.get_response(uri) return response.body if response.is_a?(Net::HTTPSuccess) $LOG.debug "#{outputFilename}: Rest request to #{uri.inspect} #{response.inspect}" raise "Rest request got a bad response code back [#{response.code}]" end |