Class: Etom::Reference
- Inherits:
-
Object
- Object
- Etom::Reference
- Defined in:
- lib/etom/reference.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
Instance Method Summary collapse
- #artifact_id ⇒ Object
- #binary? ⇒ Boolean
- #file_name ⇒ Object
- #full_name ⇒ Object
- #group_id ⇒ Object
-
#initialize(url) ⇒ Reference
constructor
A new instance of Reference.
- #md5 ⇒ Object
- #name ⇒ Object
- #plugin_name ⇒ Object
- #sha1 ⇒ Object
- #source? ⇒ Boolean
- #to_artifact(local_repo, short = false) ⇒ Object
- #to_pom ⇒ Object
- #valid? ⇒ Boolean
- #version ⇒ Object
- #version_short ⇒ Object
- #version_timestamp ⇒ Object
Constructor Details
#initialize(url) ⇒ Reference
Returns a new instance of Reference.
9 10 11 |
# File 'lib/etom/reference.rb', line 9 def initialize(url) self.file = url end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
7 8 9 |
# File 'lib/etom/reference.rb', line 7 def file @file end |
Instance Method Details
#artifact_id ⇒ Object
65 66 67 |
# File 'lib/etom/reference.rb', line 65 def artifact_id name.split("_")[0].split(".").last end |
#binary? ⇒ Boolean
73 74 75 |
# File 'lib/etom/reference.rb', line 73 def binary?() !source? end |
#file_name ⇒ Object
17 18 19 |
# File 'lib/etom/reference.rb', line 17 def file_name File.basename(file) end |
#full_name ⇒ Object
31 32 33 |
# File 'lib/etom/reference.rb', line 31 def full_name file_name[0..-5] end |
#group_id ⇒ Object
59 60 61 62 63 |
# File 'lib/etom/reference.rb', line 59 def group_id ids = name.split(".") ids.pop ids.join(".") end |
#md5 ⇒ Object
91 92 93 |
# File 'lib/etom/reference.rb', line 91 def md5() Etom::Hasher::md5(file) end |
#name ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/etom/reference.rb', line 35 def name name = full_name.split("_")[0] if(name.end_with?(".source")) name[0..-8] else name end end |
#plugin_name ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/etom/reference.rb', line 21 def plugin_name Zip::ZipFile.open(file, 0) do |zipfile| begin PropertyReader::load_from_string(zipfile.read("plugin.properties"))["bundleName"] rescue file_name end end end |
#sha1 ⇒ Object
95 96 97 |
# File 'lib/etom/reference.rb', line 95 def sha1() Etom::Hasher::sha1(file) end |
#source? ⇒ Boolean
69 70 71 |
# File 'lib/etom/reference.rb', line 69 def source?() full_name.split("_")[0].end_with?(".source") end |
#to_artifact(local_repo, short = false) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/etom/reference.rb', line 99 def to_artifact(local_repo, short = false) # select version selected_version = version if(short) selected_version = version_short end # create path maven_path = File.join("#{local_repo}",group_id.split("."),artifact_id,selected_version) FileUtils.makedirs(maven_path) # copy jar if(source?) maven_artifact_path = "#{maven_path}/#{artifact_id}-#{selected_version}-sources.jar" else maven_artifact_path = "#{maven_path}/#{artifact_id}-#{selected_version}.jar" end FileUtils.cp(file,maven_artifact_path) # create pom if(binary?) maven_pom_path = "#{maven_path}/#{artifact_id}-#{selected_version}.pom" File.open(maven_pom_path, "w") do |pom| pom << to_pom end end end |
#to_pom ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/etom/reference.rb', line 77 def to_pom <<-eos <?xml version="1.0" encoding="UTF-8"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <groupId>#{group_id}</groupId> <artifactId>#{artifact_id}</artifactId> <version>#{version}</version> <name>#{plugin_name}</name> </project> eos end |
#valid? ⇒ Boolean
13 14 15 |
# File 'lib/etom/reference.rb', line 13 def valid? File.exists?(file) end |
#version ⇒ Object
44 45 46 47 48 49 |
# File 'lib/etom/reference.rb', line 44 def version version = full_name.split("_")[1] short = version.split(".")[0..2].join(".") = version.split(".").last "#{short}-#{}" end |
#version_short ⇒ Object
55 56 57 |
# File 'lib/etom/reference.rb', line 55 def version_short version.split("-").first end |
#version_timestamp ⇒ Object
51 52 53 |
# File 'lib/etom/reference.rb', line 51 def version.split("-").last end |