Add a Buildr::Util.uuid utility method
authorPeter Donald <donaldp@apache.org>
Mon, 30 Sep 2013 23:12:23 +0000 (23:12 +0000)
committerPeter Donald <donaldp@apache.org>
Mon, 30 Sep 2013 23:12:23 +0000 (23:12 +0000)
git-svn-id: https://svn.apache.org/repos/asf/buildr/trunk@1527820 13f79535-47bb-0310-9956-ffa450edef68

lib/buildr.rb
lib/buildr/core/util.rb

index fbdc283..6cb3e23 100644 (file)
@@ -36,6 +36,7 @@ require 'uri'
 require 'stringio'
 require 'fileutils'
 require 'orderedhash'
+require 'securerandom'
 
 require 'buildr/core/util'
 require 'buildr/core/common'
index 765ab5b..ff9bd6e 100644 (file)
@@ -76,6 +76,14 @@ module Buildr #:nodoc:
       end
     end
 
+    def uuid
+      return SecureRandom.uuid if SecureRandom.respond_to?(:uuid)
+      ary = SecureRandom.random_bytes(16).unpack("NnnnnN")
+      ary[2] = (ary[2] & 0x0fff) | 0x4000
+      ary[3] = (ary[3] & 0x3fff) | 0x8000
+      "%08x-%04x-%04x-%04x-%04x%08x" % ary
+    end
+
     # Return the path to the first argument, starting from the path provided by the
     # second argument.
     #