Class: MavenCentralRepo
- Inherits:
-
Object
- Object
- MavenCentralRepo
- Defined in:
- lib/mvn-get/mvn-get.rb
Instance Attribute Summary collapse
-
#artifactId ⇒ Object
readonly
Returns the value of attribute artifactId.
-
#groupId ⇒ Object
readonly
Returns the value of attribute groupId.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#pom ⇒ Object
readonly
Returns the value of attribute pom.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
-
#dependencies(ignore_test_lib = true) ⇒ Object
def dependencies_url dependencies.map{|x| MavenCentral.extract_url_from_id(x, “pom”) } end.
- #download(path = ".") ⇒ Object
-
#initialize(id) ⇒ MavenCentralRepo
constructor
A new instance of MavenCentralRepo.
- #inspect ⇒ Object
- #jar_url ⇒ Object
- #recursive_dependencies(ignore_test_lib = true, only_select_lastest_version = true) ⇒ Object
Constructor Details
#initialize(id) ⇒ MavenCentralRepo
Returns a new instance of MavenCentralRepo.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/mvn-get/mvn-get.rb', line 80 def initialize(id) @id = id d = MavenCentral.id2dict(@id) raise "not a correct id.\n please use 'groupId:artifactId' or 'groupId:artifactId:version'" if d.nil? # use lastest version by default if d["version"] == nil || d["version"].strip == "" d["version"] = MavenCentral.fetch_lastest_version(d["groupId"], d["artifactId"]) @id = MavenCentral.dict2id(d) end @groupId, @artifactId, @version = d["groupId"], d["artifactId"], d["version"] pom_url = MavenCentral.extract_url_from_dict(d) # puts pom_url body = MavenCentral.request(pom_url) @pom = Hash.from_xml( body ) end |
Instance Attribute Details
#artifactId ⇒ Object (readonly)
Returns the value of attribute artifactId.
74 75 76 |
# File 'lib/mvn-get/mvn-get.rb', line 74 def artifactId @artifactId end |
#groupId ⇒ Object (readonly)
Returns the value of attribute groupId.
74 75 76 |
# File 'lib/mvn-get/mvn-get.rb', line 74 def groupId @groupId end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
74 75 76 |
# File 'lib/mvn-get/mvn-get.rb', line 74 def id @id end |
#pom ⇒ Object (readonly)
Returns the value of attribute pom.
74 75 76 |
# File 'lib/mvn-get/mvn-get.rb', line 74 def pom @pom end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
74 75 76 |
# File 'lib/mvn-get/mvn-get.rb', line 74 def version @version end |
Instance Method Details
#<=>(other) ⇒ Object
172 173 174 |
# File 'lib/mvn-get/mvn-get.rb', line 172 def <=>(other) id <=> other.id end |
#==(other) ⇒ Object
168 169 170 |
# File 'lib/mvn-get/mvn-get.rb', line 168 def ==(other) other.class == MavenCentralRepo and id == other.id end |
#dependencies(ignore_test_lib = true) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/mvn-get/mvn-get.rb', line 105 def dependencies(ignore_test_lib = true) return [] if @pom["project"]["dependencies"].nil? or (@pom["project"]["dependencies"].class == String and @pom["project"]["dependencies"].strip == "") [@pom["project"]["dependencies"]["dependency"]].flatten.map{|x| next if ignore_test_lib and x["scope"] and x["scope"].strip == "test" # puts "dep #{@id}\n#{x}" if x["version"] =~ /\s*[$]{\s*project[.]version\s*}\s*/ x["version"] = @version end "#{x["groupId"]}:#{x["artifactId"]}:#{x["version"]}" }.compact.sort! end |
#download(path = ".") ⇒ Object
176 177 178 179 180 181 |
# File 'lib/mvn-get/mvn-get.rb', line 176 def download(path = ".") url = jar_url open(File.join(path, url.split("/").last), "w") { |f| f.write MavenCentral.request(url) } end |
#inspect ⇒ Object
164 165 166 |
# File 'lib/mvn-get/mvn-get.rb', line 164 def inspect @id end |
#jar_url ⇒ Object
118 119 120 |
# File 'lib/mvn-get/mvn-get.rb', line 118 def jar_url MavenCentral.extract_url_from_id(@id, "jar") end |
#recursive_dependencies(ignore_test_lib = true, only_select_lastest_version = true) ⇒ Object
122 123 124 125 126 127 128 129 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 156 157 158 159 160 161 162 |
# File 'lib/mvn-get/mvn-get.rb', line 122 def recursive_dependencies(ignore_test_lib = true, only_select_lastest_version = true) return [] if dependencies(ignore_test_lib) == [] return @_recursive_dependencies[ignore_test_lib][only_select_lastest_version] if @_recursive_dependencies and @_recursive_dependencies[ignore_test_lib] and @_recursive_dependencies[ignore_test_lib][only_select_lastest_version] res = [] deps = dependencies(ignore_test_lib) while not deps.empty? d = deps.shift # puts "deps #{d}" if not res.map{|x| x.id }.include?(d) r = MavenCentralRepo.new(d) if not res.include?(r) if only_select_lastest_version == false or (only_select_lastest_version == true and ( not res.any?{|x| r.groupId == x.groupId and r.artifactId == x.artifactId } or res.any?{|x| r.groupId == x.groupId and r.artifactId == x.artifactId and r.version < x.version }) # lexicographic order ) deps += r.dependencies res << r end end end end # if only_select_lastest_version # res = res.group_by{|x| "#{x.groupId}:#{x.artifactId}" }.map{|k, v| v.reduce{|s, x| if s.version > x.version then s else x end } }.flatten # end res.sort! @_recursive_dependencies ||= {} @_recursive_dependencies[ignore_test_lib] ||= {} @_recursive_dependencies[ignore_test_lib][only_select_lastest_version] = res return res # dependencies.map{|x| # repo = MavenCentralRepo.new(x) # puts "--- #{@id} ---" # puts repo.dependencies # [repo, repo.recursive_dependencies] # }.flatten end |