Author: assaf
Date: Fri Oct 17 12:26:41 2008
New Revision: 705731

URL: http://svn.apache.org/viewvc?rev=705731&view=rev
Log:
BUILDR-155 Lazily load code and 3rd party libraries to improve startup time

Added:
    incubator/buildr/trunk/lib/buildr/core/osx.rb
Modified:
    incubator/buildr/trunk/_buildr
    incubator/buildr/trunk/addon/buildr/nailgun.rb
    incubator/buildr/trunk/lib/buildr.rb
    incubator/buildr/trunk/lib/buildr/core.rb
    incubator/buildr/trunk/lib/buildr/core/application.rb
    incubator/buildr/trunk/lib/buildr/core/common.rb
    incubator/buildr/trunk/lib/buildr/core/filter.rb
    incubator/buildr/trunk/lib/buildr/core/transports.rb
    incubator/buildr/trunk/lib/buildr/core/util.rb
    incubator/buildr/trunk/lib/buildr/ide/idea.rb
    incubator/buildr/trunk/lib/buildr/ide/idea7x.rb
    incubator/buildr/trunk/spec/sandbox.rb

Modified: incubator/buildr/trunk/_buildr
URL: 
http://svn.apache.org/viewvc/incubator/buildr/trunk/_buildr?rev=705731&r1=705730&r2=705731&view=diff
==============================================================================
--- incubator/buildr/trunk/_buildr (original)
+++ incubator/buildr/trunk/_buildr Fri Oct 17 12:26:41 2008
@@ -25,5 +25,6 @@
 spec.dependencies.each do |dep|
   gem dep.name, dep.version_requirements.to_s
 end
+
 require 'buildr'
 Buildr.application.run

Modified: incubator/buildr/trunk/addon/buildr/nailgun.rb
URL: 
http://svn.apache.org/viewvc/incubator/buildr/trunk/addon/buildr/nailgun.rb?rev=705731&r1=705730&r2=705731&view=diff
==============================================================================
--- incubator/buildr/trunk/addon/buildr/nailgun.rb (original)
+++ incubator/buildr/trunk/addon/buildr/nailgun.rb Fri Oct 17 12:26:41 2008
@@ -20,6 +20,7 @@
 require 'rbconfig'
 require 'thread'
 require 'buildr/core/application_cli'
+require 'tempfile'
 
 module Buildr #:nodoc:
 

Modified: incubator/buildr/trunk/lib/buildr.rb
URL: 
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr.rb?rev=705731&r1=705730&r2=705731&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr.rb (original)
+++ incubator/buildr/trunk/lib/buildr.rb Fri Oct 17 12:26:41 2008
@@ -31,6 +31,3 @@
 class Object #:nodoc:
   Buildr.constants.each { |c| const_set c, Buildr.const_get(c) unless 
const_defined?(c) }
 end
-
-# Prevent RSpec runner from running at_exit.
-require 'spec'

Modified: incubator/buildr/trunk/lib/buildr/core.rb
URL: 
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/core.rb?rev=705731&r1=705730&r2=705731&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/core.rb (original)
+++ incubator/buildr/trunk/lib/buildr/core.rb Fri Oct 17 12:26:41 2008
@@ -26,3 +26,4 @@
 require 'buildr/core/checks'
 require 'buildr/core/transports'
 require 'buildr/core/generate'
+require 'buildr/core/osx' if RUBY_PLATFORM =~ /darwin/

Modified: incubator/buildr/trunk/lib/buildr/core/application.rb
URL: 
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/core/application.rb?rev=705731&r1=705730&r2=705731&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/core/application.rb (original)
+++ incubator/buildr/trunk/lib/buildr/core/application.rb Fri Oct 17 12:26:41 
2008
@@ -228,10 +228,6 @@
         else
           @start = Time.now
           top_level_tasks.each { |task_name| invoke_task(task_name) }
-          title, message = "Your build has completed", "#{Dir.pwd}\nbuildr 
[EMAIL PROTECTED](' ')}"
-          @on_completion.each do |block|
-            block.call(title, message) rescue nil
-          end
           if verbose
             elapsed = Time.now - @start
             real = []
@@ -240,6 +236,12 @@
             real << ('%.3fs' % (elapsed % 60))
             puts $terminal.color("Completed in #{real.join}", :green)
           end
+          # On OS X this will load Cocoa and Growl which takes half a second we
+          # don't want to measure, so put this after the console message.
+          title, message = "Your build has completed", "#{Dir.pwd}\nbuildr 
[EMAIL PROTECTED](' ')}"
+          @on_completion.each do |block|
+            block.call(title, message) rescue nil
+          end
         end
       end
     end
@@ -542,34 +544,6 @@
 end
 
 
-# Let's see if we can use Growl.  We do this at the very end, loading Ruby 
Cocoa
-# could slow the build down, so later is better.  We only do this when running 
-# from the console in verbose mode.
-if $stdout.isatty && RUBY_PLATFORM =~ /darwin/
-  begin
-    require 'osx/cocoa'
-    icon = OSX::NSApplication.sharedApplication.applicationIconImage
-    icon = 
OSX::NSImage.alloc.initWithContentsOfFile(File.join(File.dirname(__FILE__), 
'../resources/buildr.icns'))
-
-    # Register with Growl, that way you can turn notifications on/off from 
system preferences.
-    OSX::NSDistributedNotificationCenter.defaultCenter.
-      
postNotificationName_object_userInfo_deliverImmediately(:GrowlApplicationRegistrationNotification,
 nil,
-        { :ApplicationName=>'Buildr', :AllNotifications=>['Completed', 
'Failed'], 
-          :ApplicationIcon=>icon.TIFFRepresentation }, true)
-    
-    notify = lambda do |type, title, message|
-      OSX::NSDistributedNotificationCenter.defaultCenter.
-        
postNotificationName_object_userInfo_deliverImmediately(:GrowlNotification, nil,
-          { :ApplicationName=>'Buildr', :NotificationName=>type,
-            :NotificationTitle=>title, :NotificationDescription=>message }, 
true)
-    end
-    Buildr.application.on_completion { |title, message| notify['Completed', 
title, message] if verbose }
-    Buildr.application.on_failure { |title, message, ex| notify['Failed', 
title, message] if verbose }
-  rescue Exception # No growl
-  end
-end
-
-
 alias :warn_without_color :warn
 
 # Show warning message.

Modified: incubator/buildr/trunk/lib/buildr/core/common.rb
URL: 
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/core/common.rb?rev=705731&r1=705730&r2=705731&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/core/common.rb (original)
+++ incubator/buildr/trunk/lib/buildr/core/common.rb Fri Oct 17 12:26:41 2008
@@ -15,8 +15,6 @@
 
 
 require 'rake'
-require 'open-uri'
-$LOADED_FEATURES << 'rubygems/open-uri.rb' # avoid loading rubygems' open-uri
 require 'buildr/core/util'
 
 

Modified: incubator/buildr/trunk/lib/buildr/core/filter.rb
URL: 
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/core/filter.rb?rev=705731&r1=705730&r2=705731&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/core/filter.rb (original)
+++ incubator/buildr/trunk/lib/buildr/core/filter.rb Fri Oct 17 12:26:41 2008
@@ -14,6 +14,9 @@
 # the License.
 
 
+require 'erb'
+
+
 module Buildr
 
   # A filter knows how to copy files from one directory to another, applying 
mappings to the

Added: incubator/buildr/trunk/lib/buildr/core/osx.rb
URL: 
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/core/osx.rb?rev=705731&view=auto
==============================================================================
--- incubator/buildr/trunk/lib/buildr/core/osx.rb (added)
+++ incubator/buildr/trunk/lib/buildr/core/osx.rb Fri Oct 17 12:26:41 2008
@@ -0,0 +1,49 @@
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+
+# Let's see if we can use Growl.  Must be running from console in verbose mode.
+if $stdout.isatty && verbose
+  notify = lambda do |type, title, message|
+    begin
+      # Loading Ruby Cocoa can slow the build down (hooks on Object class), so 
we're
+      # saving the best for last and only requiring it at the very end.
+      require 'osx/cocoa'
+      icon = OSX::NSApplication.sharedApplication.applicationIconImage
+      icon = 
OSX::NSImage.alloc.initWithContentsOfFile(File.join(File.dirname(__FILE__), 
'../resources/buildr.icns'))
+
+      # Register with Growl, that way you can turn notifications on/off from 
system preferences.
+      OSX::NSDistributedNotificationCenter.defaultCenter.
+        
postNotificationName_object_userInfo_deliverImmediately(:GrowlApplicationRegistrationNotification,
 nil,
+          { :ApplicationName=>'Buildr', :AllNotifications=>['Completed', 
'Failed'], 
+            :ApplicationIcon=>icon.TIFFRepresentation }, true)
+
+      OSX::NSDistributedNotificationCenter.defaultCenter.
+        
postNotificationName_object_userInfo_deliverImmediately(:GrowlNotification, nil,
+          { :ApplicationName=>'Buildr', :NotificationName=>type,
+            :NotificationTitle=>title, :NotificationDescription=>message }, 
true)
+    rescue Exception
+      # We get here in two cases: system doesn't have Growl installed so one 
of the OSX
+      # calls raises an exception; system doesn't have osx/cocoa, e.g. 
MacPorts Ruby 1.9,
+      # so we also need to rescue LoadError.
+    end
+  end  
+  
+  Buildr.application.on_completion { |title, message| notify['Completed', 
title, message] if verbose }
+  Buildr.application.on_failure { |title, message, ex| notify['Failed', title, 
message] if verbose }
+end

Modified: incubator/buildr/trunk/lib/buildr/core/transports.rb
URL: 
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/core/transports.rb?rev=705731&r1=705730&r2=705731&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/core/transports.rb (original)
+++ incubator/buildr/trunk/lib/buildr/core/transports.rb Fri Oct 17 12:26:41 
2008
@@ -22,12 +22,13 @@
 gem 'net-ssh' ; Net.autoload :SSH, 'net/ssh'
 gem 'net-sftp' ; Net.autoload :SFTP, 'net/sftp'
 autoload :CGI, 'cgi'
-autoload :StringIO, 'stringio'
-autoload :ProgressBar, 'buildr/core/progressbar'
 module Digest
   autoload :MD5, 'digest/md5'
   autoload :SHA1, 'digest/sha1'
 end
+require 'stringio'
+autoload :ProgressBar, 'buildr/core/progressbar'
+
 
 # Not quite open-uri, but similar. Provides read and write methods for the 
resource represented by the URI.
 # Currently supports reads for URI::HTTP and writes for URI::SFTP. Also 
provides convenience methods for

Modified: incubator/buildr/trunk/lib/buildr/core/util.rb
URL: 
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/core/util.rb?rev=705731&r1=705730&r2=705731&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/core/util.rb (original)
+++ incubator/buildr/trunk/lib/buildr/core/util.rb Fri Oct 17 12:26:41 2008
@@ -15,12 +15,13 @@
 
 
 require 'rbconfig'
-autoload :Pathname, 'pathname'
+require 'pathname'
 autoload :Tempfile, 'tempfile'
 autoload :YAML, 'yaml'
 autoload :REXML, 'rexml/document'
 gem 'xml-simple' ; autoload :XmlSimple, 'xmlsimple'
 gem 'builder' ; autoload :Builder, 'builder' # A different kind of buildr, one 
we use to create XML.
+require 'highline/import'
 
 
 module Buildr
@@ -35,7 +36,7 @@
     # In order to determine if we are running on a windows OS,
     # prefer this function instead of using Gem.win_platform?.
     #
-    # Gem.win_platform? only checks the RUBY_PLATFORM global,
+    # Gem.win_platform? only checks these RUBY_PLATFORM global,
     # that in some cases like when running on JRuby is not 
     # succifient for our purpose:
     #
@@ -290,4 +291,4 @@
     }.join("\n")
   end
 
-end
+end
\ No newline at end of file

Modified: incubator/buildr/trunk/lib/buildr/ide/idea.rb
URL: 
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/ide/idea.rb?rev=705731&r1=705730&r2=705731&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/ide/idea.rb (original)
+++ incubator/buildr/trunk/lib/buildr/ide/idea.rb Fri Oct 17 12:26:41 2008
@@ -16,7 +16,7 @@
 
 require 'buildr/core/project'
 require 'buildr/packaging'
-autoload :StringIO, 'stringio'
+require 'stringio'
 
 
 module Buildr

Modified: incubator/buildr/trunk/lib/buildr/ide/idea7x.rb
URL: 
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/ide/idea7x.rb?rev=705731&r1=705730&r2=705731&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/ide/idea7x.rb (original)
+++ incubator/buildr/trunk/lib/buildr/ide/idea7x.rb Fri Oct 17 12:26:41 2008
@@ -16,7 +16,7 @@
 
 require 'buildr/core/project'
 require 'buildr/packaging'
-autoload :StringIO, 'stringio'
+require 'stringio'
 
 
 module Buildr

Modified: incubator/buildr/trunk/spec/sandbox.rb
URL: 
http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/sandbox.rb?rev=705731&r1=705730&r2=705731&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/sandbox.rb (original)
+++ incubator/buildr/trunk/spec/sandbox.rb Fri Oct 17 12:26:41 2008
@@ -124,13 +124,7 @@
     Layout.default = @_sandbox[:layout].clone
 
     $LOAD_PATH.replace @_sandbox[:load_path]
-<<<<<<< HEAD:spec/sandbox.rb
-    $LOADED_FEATURES.replace @_sandbox[:loaded_features]
     FileUtils.rm_rf @temp
-=======
-    #$LOADED_FEATURES.replace @_sandbox[:loaded_features]
-    FileUtils.rm_rf Dir.pwd
->>>>>>> This change necessary to run the full test suite, since autoload 
doesn't play nicely with our sandbox.:spec/sandbox.rb
 
     # Get rid of all artifacts.
     @_sandbox[:artifacts].tap { |artifacts| Artifact.class_eval { @artifacts = 
artifacts } }


Reply via email to