Module: Buildr::ActsAsArtifact
- Included in:
- Artifact
- Defined in:
- lib/buildr/packaging/artifact.rb
Overview
Mixin with a task to make it behave like an artifact. Implemented by the packaging tasks.
An artifact has an identifier, group identifier, type, version number and optional classifier. All can be used to locate it in the local repository, download from or upload to a remote repository.
The #to_spec and #to_hash methods allow it to be used everywhere an artifact is accepted.
Constant Summary collapse
- ARTIFACT_ATTRIBUTES =
[:group, :id, :type, :classifier, :version]
Instance Attribute Summary collapse
-
#classifier ⇒ Object
readonly
Optional artifact classifier.
-
#group ⇒ Object
readonly
The group identifier.
-
#id ⇒ Object
readonly
The artifact identifier.
-
#type ⇒ Object
readonly
The file type.
-
#version ⇒ Object
readonly
The version number.
Instance Method Summary collapse
- #install ⇒ Object
-
#pom ⇒ Object
:call-seq: pom => Artifact.
-
#pom_xml ⇒ Object
:call-seq: pom_xml => string.
- #snapshot? ⇒ Boolean
-
#sources_artifact ⇒ Object
:call-seq: sources_artifact => Artifact.
-
#to_spec ⇒ Object
:call-seq: to_spec => String.
-
#to_spec_hash ⇒ Object
(also: #to_hash)
:call-seq: to_spec_hash => Hash.
- #uninstall ⇒ Object
-
#upload(upload_to = nil) ⇒ Object
:call-seq: upload upload(url) upload(options).
Instance Attribute Details
#classifier ⇒ Object (readonly)
Optional artifact classifier.
58 59 60 |
# File 'lib/buildr/packaging/artifact.rb', line 58 def classifier @classifier end |
#group ⇒ Object (readonly)
The group identifier.
52 53 54 |
# File 'lib/buildr/packaging/artifact.rb', line 52 def group @group end |
#id ⇒ Object (readonly)
The artifact identifier.
50 51 52 |
# File 'lib/buildr/packaging/artifact.rb', line 50 def id @id end |
#type ⇒ Object (readonly)
The file type. (Symbol)
54 55 56 |
# File 'lib/buildr/packaging/artifact.rb', line 54 def type @type end |
Instance Method Details
#install ⇒ Object
127 128 129 130 131 132 133 134 135 136 |
# File 'lib/buildr/packaging/artifact.rb', line 127 def install pom.install if pom && pom != self invoke installed = Buildr.repositories.locate(self) unless installed == name # If not already in local repository. mkpath File.dirname(installed) cp name, installed info "Installed #{installed}" end end |
#pom ⇒ Object
95 96 97 98 |
# File 'lib/buildr/packaging/artifact.rb', line 95 def pom return self if type == :pom Buildr.artifact(:group=>group, :id=>id, :version=>version, :type=>:pom) end |
#pom_xml ⇒ Object
:call-seq:
pom_xml => string
Creates POM XML for this artifact.
115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/buildr/packaging/artifact.rb', line 115 def pom_xml xml = Builder::XmlMarkup.new(:indent=>2) xml.instruct! xml.project do xml.modelVersion '4.0.0' xml.groupId group xml.artifactId id xml.version version xml.classifier classifier if classifier end end |
#snapshot? ⇒ Boolean
60 61 62 |
# File 'lib/buildr/packaging/artifact.rb', line 60 def snapshot? version =~ /-SNAPSHOT$/ end |
#sources_artifact ⇒ Object
104 105 106 107 108 109 |
# File 'lib/buildr/packaging/artifact.rb', line 104 def sources_artifact sources_spec = to_spec_hash.merge(:classifier=>'sources') sources_task = OptionalArtifact.define_task(Buildr.repositories.locate(sources_spec)) sources_task.send :apply_spec, sources_spec sources_task end |
#to_spec ⇒ Object
:call-seq:
to_spec => String
Returns the artifact specification, in the structure:
<group>:<artifact>:<type>:<version>
or
<group>:<artifact>:<type>:<classifier>:<version>
87 88 89 |
# File 'lib/buildr/packaging/artifact.rb', line 87 def to_spec classifier ? "#{group}:#{id}:#{type}:#{classifier}:#{version}" : "#{group}:#{id}:#{type}:#{version}" end |
#to_spec_hash ⇒ Object Also known as: to_hash
:call-seq:
to_spec_hash => Hash
Returns the artifact specification as a hash. For example:
com.example:app:jar:1.2
becomes:
{ :group=>'com.example',
:id=>'app',
:type=>:jar,
:version=>'1.2' }
74 75 76 77 |
# File 'lib/buildr/packaging/artifact.rb', line 74 def to_spec_hash base = { :group=>group, :id=>id, :type=>type, :version=>version } classifier ? base.merge(:classifier=>classifier) : base end |
#uninstall ⇒ Object
138 139 140 141 142 |
# File 'lib/buildr/packaging/artifact.rb', line 138 def uninstall installed = Buildr.repositories.locate(self) rm installed if File.exist?(installed) pom.uninstall if pom && pom != self end |
#upload(upload_to = nil) ⇒ Object
:call-seq:
upload
upload(url)
upload()
Uploads the artifact, its POM and digital signatures to remote server.
In the first form, uses the upload options specified by repositories.release_to. In the second form, uses a URL that includes all the relevant information. In the third form, uses a hash with the options :url, :username, :password, and :permissions. All but :url are optional.
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/buildr/packaging/artifact.rb', line 155 def upload(upload_to = nil) # Where do we release to? upload_to ||= Buildr.repositories.release_to upload_to = { :url=>upload_to } unless Hash === upload_to raise ArgumentError, 'Don\'t know where to upload, perhaps you forgot to set repositories.release_to' unless upload_to[:url] invoke # Make sure we exist. # Upload POM ahead of package, so we don't fail and find POM-less package (the horror!) pom.upload(upload_to) if pom && pom != self # Set the upload URI, including mandatory slash (we expect it to be the base directory). # Username/password may be part of URI, or separate entities. uri = URI.parse(upload_to[:url].clone) uri.path = uri.path + '/' unless uri.path[-1] == '/' uri.user = upload_to[:username] if upload_to[:username] uri.password = upload_to[:password] if upload_to[:password] # Upload artifact relative to base URL, need to create path before uploading. info "Deploying #{to_spec}" path = group.gsub('.', '/') + "/#{id}/#{version}/#{File.basename(name)}" URI.upload uri + path, name, :permissions=>upload_to[:permissions] end |