lib/java/artifact.rb in buildr-1.2.6 vs lib/java/artifact.rb in buildr-1.2.7

- old
+ new

@@ -4,11 +4,10 @@ module Buildr desc "Download all artifacts" task "artifacts" - task "artifacts:refresh" # 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, @@ -253,10 +252,38 @@ end end end end + # :call-seq: + # 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. + def from(path) + path = File.expand_path(path.to_s) + enhance [path] do + verbose false do + mkpath File.dirname(name) + pom.invoke unless type == :pom + cp path, name + puts "Installed #{path} as #{to_spec}" if verbose + end + end + unless type == :pom + pom.enhance do + verbose false do + mkpath File.dirname(pom.name) + File.open(pom.name, 'w') { |file| file.write pom.pom_xml } + end + end + end + self + end + protected # :call-seq: # download() # @@ -583,9 +610,51 @@ # group %w{xbean xbean_xpath xmlpublic}, :under=>"xmlbeans", :version=>"2.1.0" def group(*args) hash = args.pop args.flatten.map { |id| artifact :group=>hash[:under], :version=>hash[:version], :id=>id } end + + # :call-seq: + # install(artifacts) + # + # Installs the specified artifacts in the local repository as part of the install task. + # + # You can use this to install various files in the local repository, for example: + # install artifact('group:id:jar:1.0').from('some_jar.jar') + # $ buildr install + def install(*args, &block) + artifacts = artifacts(args) + raise ArgumentError, 'This method can only install artifacts' unless artifacts.all? { |f| f.respond_to?(:to_spec) } + all = (artifacts + artifacts.map { |artifact| artifact.pom }).uniq + task('install').tap do |task| + task.enhance all, &block + task 'uninstall' do + verbose false do + all.map(&:to_s ).each { |file| rm file if File.exist?(file) } + end + end + end + end + + # :call-seq: + # upload(artifacts) + # + # Uploads the specified artifacts to the release server as part of the upload task. + # + # You can use this to upload various files to the release server, for example: + # upload artifact('group:id:jar:1.0').from('some_jar.jar') + # $ buildr upload + def upload(*args, &block) + artifacts = artifacts(args) + raise ArgumentError, 'This method can only upload artifacts' unless artifacts.all? { |f| f.respond_to?(:to_spec) } + all = (artifacts + artifacts.map { |artifact| artifact.pom }).uniq + task('upload').tap do |task| + task.enhance &block if block + task.enhance all do + all.each { |artifact| artifact.upload } + end + end + end # *Deprecated* For artifact, call it's upload method; for anything else, use URI.upload. def deploy(*args) warn_deprecated "If it's an artifact, call it's upload method directly. Otherwise, use URI.upload." # Where do we release to?