You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildr.apache.org by to...@apache.org on 2016/08/17 07:37:13 UTC
buildr git commit: BUILDR-572 Allow to upload unique version
(timestamp based) snapshot artifacts to a repository. Submitted by Brice
Figureau.
Repository: buildr
Updated Branches:
refs/heads/master 749acfe1e -> 0ba77e344
BUILDR-572 Allow to upload unique version (timestamp based) snapshot artifacts to a repository. Submitted by Brice Figureau.
Project: http://git-wip-us.apache.org/repos/asf/buildr/repo
Commit: http://git-wip-us.apache.org/repos/asf/buildr/commit/0ba77e34
Tree: http://git-wip-us.apache.org/repos/asf/buildr/tree/0ba77e34
Diff: http://git-wip-us.apache.org/repos/asf/buildr/diff/0ba77e34
Branch: refs/heads/master
Commit: 0ba77e344b99122dddc6e7062452c58effbb2d51
Parents: 749acfe
Author: Antoine Toulme <an...@lunar-ocean.com>
Authored: Wed Aug 17 00:37:03 2016 -0700
Committer: Antoine Toulme <an...@lunar-ocean.com>
Committed: Wed Aug 17 00:37:03 2016 -0700
----------------------------------------------------------------------
CHANGELOG | 1 +
lib/buildr/packaging/artifact.rb | 39 ++++++++++++++++++++++++++++++++++-
spec/packaging/artifact_spec.rb | 34 ++++++++++++++++++++++++++----
3 files changed, 69 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/buildr/blob/0ba77e34/CHANGELOG
----------------------------------------------------------------------
diff --git a/CHANGELOG b/CHANGELOG
index c4fed37..51786d0 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -17,6 +17,7 @@
* Added: BUILDR-523 Issue a warning when Java.classpath is modified after Java.load has happened
* Added: BUILDR-594 Added support for changing the verification mode of SSL certificates
* Added: BUILDR-595 Added support to providing custom SSL certificates
+* Added: BUILDR-572 Allow to upload unique version (timestamp based) snapshot artifacts to a repository. Submitted by Brice Figureau.
* Fixed: BUILDR-207 remove 'Skipping tests' messages
* Added: BUILDR-703 release: allow THIS_VERSION to be defined in another file
* Fixed: BUILDR-674 Artifacts with bundle extension cannot be downloaded by Buildr
http://git-wip-us.apache.org/repos/asf/buildr/blob/0ba77e34/lib/buildr/packaging/artifact.rb
----------------------------------------------------------------------
diff --git a/lib/buildr/packaging/artifact.rb b/lib/buildr/packaging/artifact.rb
index 90c0197..97c5de3 100644
--- a/lib/buildr/packaging/artifact.rb
+++ b/lib/buildr/packaging/artifact.rb
@@ -35,6 +35,7 @@ module Buildr #:nodoc:
module ActsAsArtifact
ARTIFACT_ATTRIBUTES = [:group, :id, :type, :classifier, :version]
+ MAVEN_METADATA = "maven_metadata.xml"
class << self
private
@@ -75,6 +76,11 @@ module Buildr #:nodoc:
def snapshot?
version =~ /-SNAPSHOT$/
end
+
+ def final_version
+ return version unless snapshot?
+ Time.now.strftime("%Y%m%d.%H%M%S")
+ end
# :call-seq:
# to_spec_hash => Hash
@@ -151,6 +157,27 @@ module Buildr #:nodoc:
end
end
end
+
+ # :call-seq:
+ # maven_metadata_xml => string
+ #
+ # Creates Maven Metadata XML content for this artifact.
+ def maven_metadata_xml
+ xml = Builder::XmlMarkup.new(:indent=>2)
+ xml.instruct!
+ xml.metadata do
+ xml.groupId group
+ xml.artifactId id
+ xml.version version
+ xml.versioning do
+ xml.snapshot do
+ xml.timestamp final_version
+ xml.buildNumber 1
+ end
+ xml.lastupdated Time.now.strftime("%Y%m%d%H%M%S")
+ end
+ end
+ end
def install
invoke
@@ -201,7 +228,7 @@ module Buildr #:nodoc:
uri.user = upload_to[:username] if upload_to[:username]
uri.password = upload_to[:password] if upload_to[:password]
- path = group.gsub('.', '/') + "/#{id}/#{version}/#{File.basename(name)}"
+ path = group.gsub('.', '/') + "/#{id}/#{version}/#{upload_name}"
unless task = Buildr.application.lookup(uri+path)
deps = [self]
@@ -212,6 +239,10 @@ module Buildr #:nodoc:
options = upload_to[:options] || {:permissions => upload_to[:permissions]}
info "Deploying #{to_spec}"
URI.upload uri + path, name, options
+ if snapshot? && pom != self
+ maven_metadata = group.gsub('.', '/') + "/#{id}/#{version}/#{MAVEN_METADATA}"
+ URI.upload uri + maven_metadata, MAVEN_METADATA, :permissions => upload_to[:permissions]
+ end
end
end
task
@@ -230,6 +261,11 @@ module Buildr #:nodoc:
group.gsub('.', '/')
end
+ def upload_name
+ return File.basename(name) unless snapshot?
+ return File.basename(name).gsub(/SNAPSHOT/, "#{final_version}-1")
+ end
+
def extract_type(type)
return :jar if type == :bundle
type
@@ -400,6 +436,7 @@ module Buildr #:nodoc:
unless @content
enhance do
write name, self.content
+ write MAVEN_METADATA, maven_metadata_xml if snapshot?
end
class << self
http://git-wip-us.apache.org/repos/asf/buildr/blob/0ba77e34/spec/packaging/artifact_spec.rb
----------------------------------------------------------------------
diff --git a/spec/packaging/artifact_spec.rb b/spec/packaging/artifact_spec.rb
index 53f36cb..79cd67b 100644
--- a/spec/packaging/artifact_spec.rb
+++ b/spec/packaging/artifact_spec.rb
@@ -1026,6 +1026,24 @@ describe ActsAsArtifact, '#upload' do
write repositories.locate(artifact.pom)
lambda { artifact.upload }.should raise_error(Exception, /where to upload/)
end
+
+ it 'should upload SNAPSHOT with timestamped unique version and maven metadata' do
+ artifact = artifact('com.example:library:jar:2.0-SNAPSHOT')
+ # Prevent artifact from downloading anything.
+ write repositories.locate(artifact)
+ write repositories.locate(artifact.pom)
+
+ time = Time.gm(2011,"mar",11,14,02,36,123)
+ Time.stub(:now).and_return(time)
+
+ URI.should_receive(:upload).once.
+ with(URI.parse('sftp://example.com/base/com/example/library/2.0-SNAPSHOT/library-2.0-20110311.140236-1.pom'), artifact.pom.to_s, anything)
+ URI.should_receive(:upload).once.
+ with(URI.parse('sftp://example.com/base/com/example/library/2.0-SNAPSHOT/library-2.0-20110311.140236-1.jar'), artifact.to_s, anything)
+ URI.should_receive(:upload).once.
+ with(URI.parse('sftp://example.com/base/com/example/library/2.0-SNAPSHOT/maven_metadata.xml'), "maven_metadata.xml", anything)
+ verbose(false) { artifact.upload(:url=>'sftp://example.com/base') }
+ end
it 'should accept repositories.release_to setting' do
artifact = artifact('com.example:library:jar:2.0')
@@ -1039,28 +1057,36 @@ describe ActsAsArtifact, '#upload' do
end
it 'should use repositories.release_to setting even for snapshots when snapshot_to is not set' do
+ time = Time.gm(2016,"nov",11,14,02,36,123)
+ Time.stub(:now).and_return(time)
artifact = artifact('com.example:library:jar:2.0-SNAPSHOT')
# Prevent artifact from downloading anything.
write repositories.locate(artifact)
write repositories.locate(artifact.pom)
URI.should_receive(:upload).once.
- with(URI.parse('sftp://buildr.apache.org/repository/noexist/base/com/example/library/2.0-SNAPSHOT/library-2.0-SNAPSHOT.pom'), artifact.pom.to_s, anything)
+ with(URI.parse('sftp://buildr.apache.org/repository/noexist/base/com/example/library/2.0-SNAPSHOT/library-2.0-20161111.140236-1.pom'), artifact.pom.to_s, anything)
+ URI.should_receive(:upload).once.
+ with(URI.parse('sftp://buildr.apache.org/repository/noexist/base/com/example/library/2.0-SNAPSHOT/library-2.0-20161111.140236-1.jar'), artifact.to_s, anything)
URI.should_receive(:upload).once.
- with(URI.parse('sftp://buildr.apache.org/repository/noexist/base/com/example/library/2.0-SNAPSHOT/library-2.0-SNAPSHOT.jar'), artifact.to_s, anything)
+ with(URI.parse('sftp://buildr.apache.org/repository/noexist/base/com/example/library/2.0-SNAPSHOT/maven_metadata.xml'), "maven_metadata.xml", anything)
repositories.release_to = 'sftp://buildr.apache.org/repository/noexist/base'
artifact.upload
lambda { artifact.upload }.should_not raise_error
end
it 'should use repositories.snapshot_to setting when snapshot_to is set' do
+ time = Time.gm(2016,"nov",11,14,02,36,123)
+ Time.stub(:now).and_return(time)
artifact = artifact('com.example:library:jar:2.0-SNAPSHOT')
# Prevent artifact from downloading anything.
write repositories.locate(artifact)
write repositories.locate(artifact.pom)
URI.should_receive(:upload).once.
- with(URI.parse('sftp://buildr.apache.org/repository/noexist/snapshot/com/example/library/2.0-SNAPSHOT/library-2.0-SNAPSHOT.pom'), artifact.pom.to_s, anything)
+ with(URI.parse('sftp://buildr.apache.org/repository/noexist/snapshot/com/example/library/2.0-SNAPSHOT/library-2.0-20161111.140236-1.pom'), artifact.pom.to_s, anything)
URI.should_receive(:upload).once.
- with(URI.parse('sftp://buildr.apache.org/repository/noexist/snapshot/com/example/library/2.0-SNAPSHOT/library-2.0-SNAPSHOT.jar'), artifact.to_s, anything)
+ with(URI.parse('sftp://buildr.apache.org/repository/noexist/snapshot/com/example/library/2.0-SNAPSHOT/library-2.0-20161111.140236-1.jar'), artifact.to_s, anything)
+ URI.should_receive(:upload).once.
+ with(URI.parse('sftp://buildr.apache.org/repository/noexist/base/com/example/library/2.0-SNAPSHOT/maven_metadata.xml'), "maven_metadata.xml", anything)
repositories.release_to = 'sftp://buildr.apache.org/repository/noexist/base'
repositories.snapshot_to = 'sftp://buildr.apache.org/repository/noexist/snapshot'
artifact.upload