buildr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From as...@apache.org
Subject svn commit: r634010 - in /incubator/buildr/trunk: Rakefile buildfile doc/pages/testing.textile lib/buildr/jetty.rb lib/core/addon.rb lib/core/help.rb lib/core/transports.rb
Date Wed, 05 Mar 2008 20:06:53 GMT
Author: assaf
Date: Wed Mar  5 12:06:50 2008
New Revision: 634010

URL: http://svn.apache.org/viewvc?rev=634010&view=rev
Log:
Addons modified to use RubyGems

Modified:
    incubator/buildr/trunk/Rakefile
    incubator/buildr/trunk/buildfile
    incubator/buildr/trunk/doc/pages/testing.textile
    incubator/buildr/trunk/lib/buildr/jetty.rb
    incubator/buildr/trunk/lib/core/addon.rb
    incubator/buildr/trunk/lib/core/help.rb
    incubator/buildr/trunk/lib/core/transports.rb

Modified: incubator/buildr/trunk/Rakefile
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/Rakefile?rev=634010&r1=634009&r2=634010&view=diff
==============================================================================
--- incubator/buildr/trunk/Rakefile (original)
+++ incubator/buildr/trunk/Rakefile Wed Mar  5 12:06:50 2008
@@ -1,4 +1,5 @@
 require 'rubygems'
+require 'rubygems/uninstaller'
 require 'rake/gempackagetask'
 require 'rake/rdoctask'
 require 'spec/rake/spectask'
@@ -51,6 +52,27 @@
 jruby_spec = specify('java')
 jruby_package = Rake::GemPackageTask.new(jruby_spec) { |pkg| pkg.need_tar = pkg.need_zip
= false }
 
+begin
+  require 'rubygems/dependency_installer'
+  def install_gem(gem, options = {})
+    say "Installing #{gem}..."
+    installer = Gem::DependencyInstaller.new(gem, options.delete(:version), options)
+    installer.install
+    installer.installed_gems.each do |spec|
+      Gem::DocManager.new(spec).generate_ri unless options[:ri] == false
+      Gem::DocManager.new(spec).generate_rdoc unless options[:rdoc] == false
+    end
+  end
+rescue LoadError # < rubygems 1.0.1
+  require 'rubygems/remote_installer'
+  def install_gem(gem, options = {})
+    say "Installing #{gem}..."
+    Gem::RemoteInstaller.new.install(gem, options.delete(:version))
+    say 'OK'
+  end
+end
+
+
 # Setup environment for running this Rakefile (RSpec, Docter, etc).
 desc "If you're building from sources, run this task one to setup the necessary dependencies."
 task 'setup' do
@@ -60,18 +82,8 @@
   dependencies << Gem::Dependency.new('docter', '~>1.1')
   dependencies << Gem::Dependency.new('ultraviolet', '~>0.10') unless RUBY_PLATFORM
=~ /java/
   dependencies << Gem::Dependency.new('rcov', '~>0.8') unless RUBY_PLATFORM =~ /java/

-  dependencies.each do |dep|
-    if gems.search(dep.name, dep.version_requirements).empty?
-      puts "Installing dependency: #{dep}"
-      begin
-        require 'rubygems/dependency_installer'
-        Gem::DependencyInstaller.new(dep.name, dep.version_requirements).install
-      rescue LoadError # < rubygems 1.0.1
-        require 'rubygems/remote_installer'
-        Gem::RemoteInstaller.new.install(dep.name, dep.version_requirements)
-      end
-    end
-  end
+  dependencies.select { |dep| gems.search(dep.name, dep.version_requirements).empty? }.
+    each { |dep| install_gem dep.name, :version=>dep.version_requirements }
 end
 
 # Packaging and local installation.
@@ -81,33 +93,18 @@
 
 desc 'Install the package locally'
 task 'install'=>['clobber', 'package'] do |task|
-  if RUBY_PLATFORM =~ /java/ 
-    cmd = %w(jruby -S gem install)
-    pkg = jruby_package
-  else 
-    cmd = %w(gem install)
-    pkg = ruby_package
-  end
-  # This hack is necessary when a new gem shows up in the index but is not
-  # available for download and gem install fails, even though we have a less
-  # recent dependency installed locally.
-  cmd << '--ignore-dependencies' if ENV['IGNORE']
-  cmd << File.expand_path(pkg.gem_file, pkg.package_dir)
-  # Saves us from doing sudo rake install, which requires sudo rake clobber.
-  cmd.unshift 'sudo' unless Gem::win_platform?
-  system *cmd
+  pkg = RUBY_PLATFORM =~ /java/ ? jruby_package : ruby_package
+  options = {}
+  # options[:ri] = options[:rdoc] = false
+  # options[:ignore_dependencies] = true
+  install_gem File.expand_path(pkg.gem_file, pkg.package_dir), options
 end
 
 desc 'Uninstall previously installed packaged'
 task 'uninstall' do |task|
-  if RUBY_PLATFORM =~ /java/ 
-    cmd = %w(jruby -S gem uninstall)
-  else 
-    cmd = %w(gem uninstall)
-  end
-  cmd << ruby_spec.name
-  cmd.unshift 'sudo' unless Gem::win_platform?
-  system *cmd
+  say "Uninstalling #{ruby_spec.name} ... "
+  Gem::Uninstaller.new(ruby_spec.name, :executables=>true, :ignore=>true ).uninstall
+  say 'OK'
 end
 
 

Modified: incubator/buildr/trunk/buildfile
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/buildfile?rev=634010&r1=634009&r2=634010&view=diff
==============================================================================
--- incubator/buildr/trunk/buildfile (original)
+++ incubator/buildr/trunk/buildfile Wed Mar  5 12:06:50 2008
@@ -1,12 +1,64 @@
 require 'buildr/jetty'
 
-repositories.remote << "http://www.ibiblio.org/maven2/"
-
-options = :javac, { :source=>'1.4', :target=>'1.4', :debug=>false }
-define 'java' do
-  require 'java/nailgun'
-  compile.from(FileList['lib/java/**/*.java']).into('lib/java').using(*options).with Buildr::Nailgun.artifact
+def package_addon(project, *files)
+  legal = 'LICENSE', 'DISCLAIMER', 'NOTICE'
+  project.package(:gem).include(legal)
+  project.package(:gem).path('lib').tap do |lib|
+    files.each do |file|
+      lib.include(file, :as=>File.basename(file))
+    end
+  end
+  project.package(:gem).spec do |spec|
+    spec.author             = 'Apache Buildr'
+    spec.email              = 'buildr-user@incubator.apache.org'
+    spec.homepage           = "http://incubator.apache.org/buildr"
+    spec.rubyforge_project  = 'buildr'
+    spec.extra_rdoc_files   = legal
+    spec.rdoc_options << '--webcvs' << 'http://svn.apache.org/repos/asf/incubator/buildr/trunk/'
+    spec.add_dependency 'buildr', '~> 1.3'
+  end
 end
+
 define 'buildr' do
-  compile.from(FileList['lib/buildr/**/*.java']).into('lib/buildr').using(*options).with(Buildr::Jetty::REQUIRES)
+  compile.using :source=>'1.4', :target=>'1.4', :debug=>false
+
+  define 'java' do
+    compile.using(:javac).from(FileList['lib/java/**/*.java']).into('lib/java')
+  end
+
+  desc 'ANTLR grammar generation tasks.'
+  define 'antlr', :version=>'1.0' do
+    package_addon(self, 'lib/buildr/antlr.rb')
+  end
+
+  define 'cobertura', :version=>'1.0' do
+    package_addon(self, 'lib/buildr/cobertura.rb')
+  end
+
+  define 'hibernate', :version=>'1.0' do
+    package_addon(self, 'lib/buildr/hibernate.rb')
+  end
+
+  define 'javacc', :version=>'1.0' do
+    package_addon(self, 'lib/buildr/javacc.rb')
+  end
+
+  define 'jdepend', :version=>'1.0' do
+    package_addon(self, 'lib/buildr/jdepend.rb')
+  end
+
+  desc 'Provides a collection of tasks and methods for using Jetty, specifically as a server
for testing your application.'
+  define 'jetty', :version=>'1.0' do
+    compile.using(:javac).from(FileList['lib/buildr/**/*.java']).into('lib/buildr').with(Buildr::Jetty::REQUIRES)
+    package_addon(self, 'lib/buildr/jetty.rb')
+    package(:gem).path('lib/org/apache/buildr').include(:from=>'lib/buildr/org/apache/buildr/')
+  end
+
+  define 'openjpa', :version=>'1.0' do
+    package_addon(self, 'lib/buildr/openjpa.rb')
+  end
+
+  define 'xmlbeans', :version=>'1.0' do
+    package_addon(self, 'lib/buildr/xmlbeans.rb')
+  end
 end

Modified: incubator/buildr/trunk/doc/pages/testing.textile
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/doc/pages/testing.textile?rev=634010&r1=634009&r2=634010&view=diff
==============================================================================
--- incubator/buildr/trunk/doc/pages/testing.textile (original)
+++ incubator/buildr/trunk/doc/pages/testing.textile Wed Mar  5 12:06:50 2008
@@ -41,6 +41,21 @@
 test classes from the project by looking for classes that either subclass 
 @junit.framework.TestCase@ or include methods annotated with @org.junit.Test@.
 
+The JUnit test framework supports the following options:
+
+|_. Option        |_. Value |
+| @:fork@         | VM forking, defaults to true. |
+| @:clonevm@      | If true clone the VM each time it is forked. |
+| @:properties@   | Hash of system properties available to the test case. |
+| @:environment@  | Hash of environment variables available to the test case. |
+| @:java_args@    | Arguments passed as is to the JVM. |
+
+For example, to pass properties to the test case:
+
+{{{!ruby
+test.using :properties=>{ :currency=>'USD' }
+}}}
+
 There are benefits to running test cases in separate VMs.  The default forking
 mode is @:once@, and you can change it by setting the @:fork@ option.
 
@@ -93,6 +108,12 @@
 @org.testng.annotations.Test@, and generates test reports in
 the @reports/testng@ directory.  At the moment we don't have consolidated HTML
 reports for TestNG.
+
+The TestNG test framework supports the following options:
+
+|_. Option        |_. Value |
+| @:properties@   | Hash of system properties available to the test case. |
+| @:java_args@    | Arguments passed as is to the JVM. |
 
 
 h2. Excluding Tests and Ignoring Failures

Modified: incubator/buildr/trunk/lib/buildr/jetty.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/jetty.rb?rev=634010&r1=634009&r2=634010&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/jetty.rb (original)
+++ incubator/buildr/trunk/lib/buildr/jetty.rb Wed Mar  5 12:06:50 2008
@@ -20,7 +20,6 @@
 require "java/artifact"
 require "java/java"
 require "thread"
-#require "struct"
 
 module Buildr
 

Modified: incubator/buildr/trunk/lib/core/addon.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/core/addon.rb?rev=634010&r1=634009&r2=634010&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/core/addon.rb (original)
+++ incubator/buildr/trunk/lib/core/addon.rb Wed Mar  5 12:06:50 2008
@@ -14,132 +14,131 @@
 # the License.
 
 
-require 'java/artifact'
+require 'tasks/zip'
+$LOADED_FEATURES << 'rubygems/open-uri.rb' # We already have open-uri
+require 'rubygems/source_info_cache'
+require 'rubygems/doc_manager'
+require 'rubygems/format'
+require 'rubygems/dependency_installer'
 
 
 module Buildr
 
-  # Addons are a mechanicm for sharing extensions, tasks and common code across builds,
-  # using remote and local repositories.
-  #
-  # An addon is a collection of files, a ZIP archive when distributed and an exploded
-  # directory when used locally.  They are installed and expanded into the local repository.
-  #
-  # Addons provide functionality in three different ways:
-  # * The addon directory is added to the $LOAD_PATH, and its files can be accessed from
-  #    the build tasks, typically using +require+.
-  # * The +init.rb+ file is required by default, if present.  An addon can use this to
-  #   install project extensions, introduce new tasks, install libraries, etc.
-  # * Task files that go in the +tasks+ sub-directory with the extension +.rake+ are
-  #   automatically loaded after the buildfile.  Use these to introduce addition tasks.
+  # :call-seq:
+  #   addon(id, options?)
+  #   addon(task, options?)
   #
-  # The addon method supports options that are set on the addon on first use.  The +init.rb+
-  # file can access these options through the global variable $ADDON.
+  # Use this to download and install an addon.  The first form takes the addon identifier,
+  # a string that contains the qualified name, colon and version number.  For example:
+  #   addon 'buildr-openjpa', '1.0'
+  # Some addon accept options passed as a hash argument.
   #
-  # Addons are referenced by a qualified name.  For local and remote repositories, the
-  # last part of the qualified name maps to the artifact identifier, the rest is the group
-  # identifier.  For example, 'org.apache.buildr.openjpa:1.0' becomes
-  # 'org.apache.buildr:openjpa:zip:1.0'.
-  class Addon
-
-    class << self
-
-      # Returns all the loaded addons.
-      def list
-        @addons.values
-      end
-
-      def load(from, options = nil) #:nodoc:
-        options ||= {}
-        case from
-        when Rake::FileTask
-          target = from.to_s
-          name = target.pathmap('%n')
-        when String
-          name, version, *rest = from.split(':')
-          fail "Expecting <name>:<version>, found #{from}." unless name &&
version && rest.empty?
-          group = name.split('.')
-          id = group.pop
-          fail "Addon name is qualified, like foo.bar or foo.bar.baz, but not foo." if group.empty?
-          artifact = Buildr.artifact("#{group.join('.')}:#{id}:zip:#{version}")
-          target = artifact.to_s.ext
-          Buildr.unzip(target=>artifact)
-        else
-          fail "Can only load addon from repository (name:version) or file task."
-        end
-        if addon = @addons[name]
-          fail "Attempt to load addon #{name} with two different version numbers, first (#{addon.version})
and now (#{version})." unless
-            addon.version == version
-          false
-        else
-          @addons[name] = new(name, version, target, options)
-          true
+  # The second form takes a file task that points to the directory containing the addon.
+  def addon(name_or_path, version = nil)
+    case name_or_path
+    when Rake::FileTask
+      path = name_or_path.to_s
+      spec = Gem::Format.from_file_by_path(path).spec
+      name, version = spec.name, spec.version
+    when String
+      name = name_or_path
+      spec = Gem::SourceIndex.from_installed_gems.search(name, version).first || Gem::SourceInfoCache.search(name,
version).first
+      fail "Could not find #{name} locally or in remote repository." unless spec
+      version ||= '> 0'
+    else fail "First argument must be Gem name or File task."
+    end
+
+    if Gem::SourceIndex.from_installed_gems.search(name, version).empty?
+      say "Installing #{spec.full_name} ... "
+      cmd = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']), '-S',
'gem', 'install', name_or_path.to_s
+      cmd << '-v' << version.to_s if version
+      cmd.unshift 'sudo' unless Gem.win_platform? || RUBY_PLATFORM =~ /java/
+      sh *cmd.push(:verbose=>false)
+      Gem.source_index.load_gems_in Gem::SourceIndex.installed_spec_directories
+      # NOTE:  The nice thing would be to do a Gem install from the process,
+      #        but installing the documenation requires RDoc, and RDoc defines
+      #        one too many top-level classes which mess with our stuff.
+=begin
+      installer = Gem::DependencyInstaller.new(path || name, version.to_s).tap do |installer|
+        installer.install 
+        say 'Installed'
+        installer.installed_gems.each do |spec|
+          # NOTE:  RI documentation must be generated before RDoc.
+          Gem::DocManager.new(spec, nil).generate_ri
+          Gem::DocManager.new(spec, nil).generate_rdoc
+          Gem.source_index.add_spec spec
         end
       end
-
+=end
     end
+    
+    Gem.activate(name, true, version).tap do
+      spec = Gem.loaded_specs[name]
+      FileList[spec.require_paths.map { |path| File.expand_path("#{path}/*.rb", spec.full_gem_path)
}].
+        map { |path| File.basename(path) }.each { |file| require file }
+      FileList[File.expand_path('tasks/*.rake', spec.full_gem_path)].each do |file| 
+        Rake.application.add_import
+      end
+    end
+  end
+
 
-    @addons = {}
+  class PackageGemTask < ArchiveTask
 
-    # Addon name.
-    attr_reader :name
-    # Version number (may be nil).
-    attr_reader :version
-    # The path for the addon directory.
-    attr_reader :path
-
-    include Enumerable
-
-    def initialize(name, version, path, options) #:nodoc:
-      @name, @version, @options = name, version, options
-      @path = File.expand_path(path)
-      file(@path).invoke
-      raise "#{@path} is not a directory." unless File.directory?(@path)
-      begin
-        $ADDON = self
-        $LOAD_PATH << @path unless $LOAD_PATH.include?(@path)
-        init_file = File.join(@path, 'init.rb')
-        require init_file if File.exist?(init_file)
-        import *FileList[File.join(@path, 'tasks/*.rake')]
-      rescue
-        $LOAD_PATH.delete @path
-      ensure
-        $ADDON = nil
+    def initialize(*args)
+      super
+      @spec = Gem::Specification.new
+    end
+
+    def spec
+      yield @spec if block_given?
+      @spec
+    end
+
+  private
+
+    def create_from(file_map)
+      spec.mark_version
+      spec.validate
+      Gem::Package.open(name, 'w', signer) do |pkg|
+        pkg.metadata = spec.to_yaml
+        file_map.each do |path, content|
+          next if content.nil? || File.directory?(content.to_s)
+          pkg.add_file_simple(path, File.stat(name).mode & 0777, File.size(content.to_s))
do |os|
+              os.write File.open(content.to_s, 'rb') { |f| f.read }
+          end
+        end
       end
     end
 
-    # Returns the value of the option.
-    def [](name)
-      @options[name]
+    def signer
+      # TODO: implement.
     end
+  end
 
-    # Sets the value of the option.
-    def []=(name, value)
-      @options[name] = value
-    end
 
-    def each(&block) #:nodoc:
-      @options.each(&block)
-    end
+  module PackageAsGem
 
-    def to_s #:nodoc:
-      version ? "#{name}:#{version}" : name
+    def package_as_gem(file_name) #:nodoc:
+      PackageGemTask.define_task(file_name).tap do |gem|
+        { 'lib' =>_(:source, :main, :ruby),
+          'test'=>_(:source, :test, :ruby),
+          'doc' =>_(:source, :doc) }.
+          each { |target, source| gem.include :from=>source, :path=>target if File.directory?(source)
}
+        gem.spec do |spec|
+          spec.name = id
+          spec.version = version
+          spec.summary = full_comment
+          spec.has_rdoc = true
+          spec.rdoc_options << '--title' << comment
+          spec.require_path = 'lib'
+        end
+      end
     end
-
   end
 
-  # :call-seq:
-  #   addon(id, options?)
-  #   addon(task, options?)
-  #
-  # Use this to download and install an addon.  The first form takes the addon identifier,
-  # a string that contains the qualified name, colon and version number.  For example:
-  #   addon 'org.apache.buildr.openjpa:1.0'
-  # Some addons accept options passed as a hash argument.
-  #
-  # The second form takes a file task that points to the directory containing the addon.
-  def addon(from, options = nil)
-    Addon.load(from, options)
+  class Buildr::Project
+    include PackageAsGem
   end
 
 end

Modified: incubator/buildr/trunk/lib/core/help.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/core/help.rb?rev=634010&r1=634009&r2=634010&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/core/help.rb (original)
+++ incubator/buildr/trunk/lib/core/help.rb Wed Mar  5 12:06:50 2008
@@ -99,7 +99,7 @@
   task 'projects' do
     width = projects.map(&:name).map(&:size).max
     projects.each do |project|
-      puts project.comment.blank? ? "  #{project.name}" : ("  %-#{width}s  # %s" % [project.name,
project.comment])
+      puts project.comment.to_s.blank? ? "  #{project.name}" : ("  %-#{width}s  # %s" % [project.name,
project.comment])
     end
   end
 

Modified: incubator/buildr/trunk/lib/core/transports.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/core/transports.rb?rev=634010&r1=634009&r2=634010&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/core/transports.rb (original)
+++ incubator/buildr/trunk/lib/core/transports.rb Wed Mar  5 12:06:50 2008
@@ -413,7 +413,7 @@
 
         # To create a path, we need to create all its parent. We use realpath to determine
if
         # the path already exists, otherwise mkdir fails.
-        puts "Creating path #{@base_path}" if Rake.application.options.trace
+        puts "Creating path #{path}" if Rake.application.options.trace
         File.dirname(path).split('/').inject('') do |base, part|
           combined = base + part
           sftp.realpath combined rescue sftp.mkdir combined, {}



Mime
View raw message