lib/buildr/packaging/artifact.rb in vic-buildr-1.3.3 vs lib/buildr/packaging/artifact.rb in vic-buildr-1.3.4
- old
+ new
@@ -12,21 +12,23 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
-require 'builder'
require 'buildr/core/project'
require 'buildr/core/transports'
require 'buildr/packaging/artifact_namespace'
module Buildr
desc 'Download all artifacts'
task 'artifacts'
+ desc "Download all artifacts' sources"
+ task 'artifacts:sources'
+
# 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.
@@ -79,11 +81,11 @@
# to_spec => String
#
# Returns the artifact specification, in the structure:
# <group>:<artifact>:<type>:<version>
# or
- # <group>:<artifact>:<type>:<classifier><:version>
+ # <group>:<artifact>:<type>:<classifier>:<version>
def to_spec
classifier ? "#{group}:#{id}:#{type}:#{classifier}:#{version}" : "#{group}:#{id}:#{type}:#{version}"
end
# :call-seq:
@@ -94,10 +96,21 @@
return self if type == :pom
Buildr.artifact(:group=>group, :id=>id, :version=>version, :type=>:pom)
end
# :call-seq:
+ # sources_artifact => Artifact
+ #
+ # Convenience method that returns a sources artifact.
+ 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
+
+ # :call-seq:
# pom_xml => string
#
# Creates POM XML for this artifact.
def pom_xml
xml = Builder::XmlMarkup.new(:indent=>2)
@@ -108,11 +121,11 @@
xml.artifactId id
xml.version version
xml.classifier classifier if classifier
end
end
-
+
def install
pom.install if pom && pom != self
invoke
installed = Buildr.repositories.locate(self)
unless installed == name # If not already in local repository.
@@ -310,11 +323,11 @@
# from(path) => self
#
# Use this when you want to install or upload an artifact from a given file, for example:
# test = artifact('group:id:jar:1.0').from('test.jar')
# install test
- # See also Buildr#install and Buildr#deploy.
+ # See also Buildr#install and Buildr#upload.
def from(path)
path = File.expand_path(path.to_s)
enhance [path] do
verbose false do
mkpath File.dirname(name)
@@ -338,15 +351,14 @@
# :call-seq:
# download
#
# Downloads an artifact from one of the remote repositories, and stores it in the local
- # repository. Accepts a String or Hash artifact specification, and returns a path to the
- # artifact in the local repository. Raises an exception if the artifact is not found.
+ # repository. Raises an exception if the artifact is not found.
#
# This method attempts to download the artifact from each repository in the order in
- # which they are returned from #remote, until successful. It always downloads the POM first.
+ # which they are returned from #remote, until successful.
def download
trace "Downloading #{to_spec}"
remote = Buildr.repositories.remote.map { |repo_url| URI === repo_url ? repo_url : URI.parse(repo_url) }
remote = remote.each { |repo_url| repo_url.path += '/' unless repo_url.path[-1] == '/' }
fail 'No remote repositories defined!' if remote.empty?
@@ -405,10 +417,26 @@
def fail_download(remote_uris)
fail "Failed to download #{to_spec}, tried the following repositories:\n#{remote_uris.join("\n")}"
end
end
+
+
+ # An artifact that is optional.
+ # If downloading fails, the user will be informed but it will not raise an exception.
+ class OptionalArtifact < Artifact
+
+ protected
+
+ # If downloading fails, the user will be informed but it will not raise an exception.
+ def download
+ super
+ rescue
+ info "Failed to download #{to_spec}. Skipping it."
+ end
+
+ end
# Holds the path to the local repository, URLs for remote repositories, and settings for release server.
#
# You can access this object from the #repositories method. For example:
@@ -592,9 +620,10 @@
unless task = Artifact.lookup(spec)
task = Artifact.define_task(repositories.locate(spec))
task.send :apply_spec, spec
Rake::Task['rake:artifacts'].enhance [task]
Artifact.register(task)
+ Rake::Task['artifacts:sources'].enhance [task.sources_artifact] unless spec[:type] == :pom
end
task.enhance &block
end
# :call-seq: