You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildr.apache.org by do...@apache.org on 2013/10/01 01:12:24 UTC

svn commit: r1527820 - in /buildr/trunk/lib: buildr.rb buildr/core/util.rb

Author: donaldp
Date: Mon Sep 30 23:12:23 2013
New Revision: 1527820

URL: http://svn.apache.org/r1527820
Log:
Add a Buildr::Util.uuid  utility method

Modified:
    buildr/trunk/lib/buildr.rb
    buildr/trunk/lib/buildr/core/util.rb

Modified: buildr/trunk/lib/buildr.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr.rb?rev=1527820&r1=1527819&r2=1527820&view=diff
==============================================================================
--- buildr/trunk/lib/buildr.rb (original)
+++ buildr/trunk/lib/buildr.rb Mon Sep 30 23:12:23 2013
@@ -36,6 +36,7 @@ require 'uri'
 require 'stringio'
 require 'fileutils'
 require 'orderedhash'
+require 'securerandom'
 
 require 'buildr/core/util'
 require 'buildr/core/common'

Modified: buildr/trunk/lib/buildr/core/util.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/core/util.rb?rev=1527820&r1=1527819&r2=1527820&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/core/util.rb (original)
+++ buildr/trunk/lib/buildr/core/util.rb Mon Sep 30 23:12:23 2013
@@ -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.
     #