Class: Maven::Tools::Artifact
- Inherits:
-
Hash
- Object
- Hash
- Maven::Tools::Artifact
- Defined in:
- lib/maven/tools/artifact.rb
Defined Under Namespace
Classes: Helper
Class Method Summary collapse
- .from(type, *args) ⇒ Object
- .from_coordinate(coord) ⇒ Object
- .new_local(path, type, options = {}) ⇒ Object
Instance Method Summary collapse
- #exclusions ⇒ Object
- #gav ⇒ Object
-
#initialize(group_id, artifact_id, type, version = nil, classifier = nil, exclusions = nil, options = {}) ⇒ Artifact
constructor
A new instance of Artifact.
- #to_coordinate ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(group_id, artifact_id, type, version = nil, classifier = nil, exclusions = nil, options = {}) ⇒ Artifact
Returns a new instance of Artifact.
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 128 129 130 131 |
# File 'lib/maven/tools/artifact.rb', line 99 def initialize( group_id, artifact_id, type, version = nil, classifier = nil, exclusions = nil, = {} ) if exclusions.nil? if version.nil? and !classifier.nil? version = classifier classifier = nil elsif classifier.is_a?( Array ) exclusions = classifier#version #version = classifier classifier = nil end end self[ :type ] = type self[ :group_id ] = group_id self[ :artifact_id ] = artifact_id self[ :version ] = version self[ :classifier ] = classifier if classifier self[ :exclusions ] = exclusions if exclusions if self[ :group_id ] ||= [ :group_id ] self[ :artifact_id ] ||= [ :artifact_id ] self[ :version ] ||= [ :version ] self[ :classifier ] ||= [ :classifier ] if [ :classifier ] self[ :exclusions ] ||= [ :exclusions ] if [ :exclusions ] .delete( :group_id ) .delete( :artifact_id ) .delete( :version ) .delete( :classifier ) .delete( :exclusions ) self.merge!( ) end end |
Class Method Details
.from(type, *args) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 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 |
# File 'lib/maven/tools/artifact.rb', line 44 def self.from( type, *args ) if args.last.is_a? Hash = args.last.dup args = args[0..-2] end helper = Helper.new case args.size when 1 # jar "asd:Asd:123 # jar "asd:Asd:123:test" # jar "asd:Asd:123:[dsa:rew,fe:fer]" # jar "asd:Asd:123:test:[dsa:rew,fe:fer]" group_id, artifact_id, version, classifier, exclusions = args[0].split( /:/ ) self.new( group_id, artifact_id, type, version, classifier, exclusions, ) when 2 # jar "asd:Asd", 123 # jar "asd:Asd:test", 123 # jar "asd:Asd:[dsa:rew,fe:fer]", 123 # jar "asd:Asd:test:[dsa:rew,fe:fer]", 123 group_id, artifact_id, classifier, exclusions = args[0].split( /:/ ) self.new( group_id, artifact_id, type, helper.to_version( args[ 1 ] ), classifier, exclusions, ) when 3 # jar "asd:Asd",'>123', '<345' # jar "asd:Asd:test",'>123', '<345' # jar "asd:Asd:[dsa:rew,fe:fer]",'>123', '<345' # jar "asd:Asd:test:[dsa:rew,fe:fer]",'>123', '<345' # jar "asd:Asd:test:[dsa:rew,fe:fer]", '123', 'source' v = helper.to_version( *args[1..-1] ) case v when String group_id, artifact_id, classifier, exclusions = args[0].split( /:/ ) self.new( group_id, artifact_id, type, v, classifier, exclusions, ) else group_id, artifact_id = args[0].split( /:/ ) self.new( group_id, artifact_id, type, args[1], args[2], nil, ) end else nil end end |
.from_coordinate(coord) ⇒ Object
94 95 96 97 |
# File 'lib/maven/tools/artifact.rb', line 94 def self.from_coordinate( coord ) args = coord.split( /:/ ) new( *args ) end |
.new_local(path, type, options = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/maven/tools/artifact.rb', line 30 def self.new_local( path, type, = {} ) name = File.basename( path ).sub( /.#{type}$/, '' ) if ind = name.rindex( '-' ) version = name[ind + 1..-1] name = name[0..ind - 1] else version = '0' end self.new( "ruby.maven-tools.#{type}", name, type, nil, version, nil, .merge( { :system_path => path, :scope => :system } ) ) end |
Instance Method Details
#exclusions ⇒ Object
137 138 139 140 141 |
# File 'lib/maven/tools/artifact.rb', line 137 def exclusions if key?( :exclusions ) self[:exclusions].inspect.gsub( /[\[\]" ]/, '' ).split /,/ end end |
#gav ⇒ Object
133 134 135 |
# File 'lib/maven/tools/artifact.rb', line 133 def gav [ self[:group_id], self[:artifact_id], self[:version], self[:classifier] ].select { |o| o }.join( ':' ) end |
#to_coordinate ⇒ Object
143 144 145 |
# File 'lib/maven/tools/artifact.rb', line 143 def to_coordinate [ self[:group_id], self[:artifact_id], self[:type], self[:classifier], self[:version] ].select { |o| o }.join( ':' ) end |
#to_s ⇒ Object
147 148 149 |
# File 'lib/maven/tools/artifact.rb', line 147 def to_s [ self[:group_id], self[:artifact_id], self[:type], self[:classifier], self[:version], key?( :exclusions )? self[:exclusions].inspect.gsub( /[" ]/, '' ) : nil ].select { |o| o }.join( ':' ) end |