Permalink
Browse files

Ruby 1.9.1 compatibility:

- erb_transform works well with binding, not proc

- foo = *args fixed to foo = args.last

- Seems that Struct keys are now strings

- Proper Tempfile handling to get around scoped closure variables

- constants returns symbols instead of strings

- mkpath returns array not a string

- Array.nitems no longer exists, Antwrap requires this patch

- Added cover matcher since include? doesn't work on time range

- What we need is instance_exec, new in 1.9 and back-ported by RSpec 1.2.

- Fixed eclipse specs (1.8 and 1.9 don't lookup constants the same way).

Specs should end with _spec.rb (helps distinguish them from helpers and such).

Commented out groups in Scala tests.

git-svn-id: https://svn.apache.org/repos/asf/buildr/trunk@787782 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent 1a6dd60 commit 3caa28648a1a7b10754d9b161fc998560b85affb Assaf Arkin committed Jun 23, 2009
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
View
@@ -16,17 +16,22 @@
$LOADED_FEATURES << 'jruby' unless RUBY_PLATFORM =~ /java/ # Pretend to have JRuby, keeps Nailgun happy.
require 'buildr/jetty'
require 'buildr/nailgun'
+require 'buildr/scala'
repositories.remote << 'http://repo1.maven.org/maven2'
repositories.remote << 'http://scala-tools.org/repo-releases/'
define 'buildr' do
compile.using :source=>'1.4', :target=>'1.4', :debug=>false
- define 'java' do
+ define 'java' do
compile.using(:javac).from(FileList['lib/buildr/java/**/*.java']).into('lib/buildr/java')
end
+ define 'scala' do
+ compile.using(:scalac).from(FileList['lib/buildr/scala/**/*.scala']).into('lib/buildr/scala')
+ end
+
desc 'Buildr extra packages (Antlr, Cobertura, Hibernate, Javacc, JDepend, Jetty, OpenJPA, XmlBeans)'
define 'extra', :version=>'1.0' do
compile.using(:javac).from(FileList['addon/buildr/**/*.java']).into('addon/buildr').with(Buildr::Jetty::REQUIRES, Buildr::Nailgun::ARTIFACT_SPEC)
View
@@ -14,6 +14,11 @@
# the License.
+# TODO: Antwrap 0.7 requires this monkeypatch, have it fixed.
+class Array #:nodoc:
+ alias :nitems :size
+end
+
require 'buildr/core/common'
require 'buildr/core/application'
require 'buildr/core/project'
@@ -244,7 +244,7 @@ def initialize(*args) #:nodoc:
#
# For example:
# compile.from('src/java').into('classes').with('module1.jar')
- def from(*sources)
+ def from(*sources)
@sources |= sources.flatten
guess_compiler if @compiler.nil? && sources.flatten.any? { |source| File.exist?(source) }
self
@@ -285,7 +285,7 @@ def configure(mapper_type, *args, &block)
@config = configurer.call(*args, &block)
else
raise ArgumentError, "Missing hash argument after :#{mapper_type}" unless args.size == 1 && Hash === args[0]
- @config = *args
+ @config = args.first
end
@mapper_type = mapper_type
end
@@ -312,10 +312,8 @@ def callback_transform(content, path = nil)
def erb_transform(content, path = nil)
case config
- when Binding, Proc
+ when Binding
bnd = config
- when Method
- bnd = config.to_proc
when Hash
bnd = OpenStruct.new
table = config.inject({}) { |h, e| h[e.first.to_sym] = e.last; h }
@@ -222,7 +222,7 @@ def define(name, properties, &block) #:nodoc:
@on_define.each { |callback| callback[project] }
end if @on_define
# Enhance the project using the definition block.
- project.enhance { project.instance_eval &block } if block
+ project.enhance { project.instance_exec project, &block } if block
# Top-level project? Invoke the project definition. Sub-project? We don't invoke
# the project definiton yet (allow project calls to establish order of evaluation),
@@ -148,11 +148,10 @@ def download(target, options = nil)
# worse than not having a file at all, so download to temporary
# file and then move over.
modified = File.stat(target).mtime if File.exist?(target)
- temp = nil
- Tempfile.open File.basename(target) do |temp|
- temp.binmode
- read({:progress=>verbose}.merge(options || {}).merge(:modified=>modified)) { |chunk| temp.write chunk }
- end
+ temp = Tempfile.new(File.basename(target))
+ temp.binmode
+ read({:progress=>verbose}.merge(options || {}).merge(:modified=>modified)) { |chunk| temp.write chunk }
+ temp.close
mkpath File.dirname(target)
mv temp.path, target
when File
@@ -537,20 +536,18 @@ def real_path #:nodoc:
def write_internal(options, &block) #:nodoc:
raise ArgumentError, 'Either you\'re attempting to write a file to another host (which we don\'t support), or you used two slashes by mistake, where you should have file:///<path>.' if host
- temp = nil
- Tempfile.open File.basename(path) do |temp|
- temp.binmode
- with_progress_bar options[:progress] && options[:size], path.split('/'), options[:size] || 0 do |progress|
- while chunk = yield(RW_CHUNK_SIZE)
- temp.write chunk
- progress << chunk
- end
+ temp = Tempfile.new(File.basename(path))
+ temp.binmode
+ with_progress_bar options[:progress] && options[:size], path.split('/'), options[:size] || 0 do |progress|
+ while chunk = yield(RW_CHUNK_SIZE)
+ temp.write chunk
+ progress << chunk
end
end
- real_path.tap do |path|
- mkpath File.dirname(path)
- mv temp.path, path
- end
+ temp.close
+ mkpath File.dirname(real_path)
+ mv temp.path, real_path
+ real_path
end
@@schemes['FILE'] = FILE
View
@@ -159,24 +159,54 @@ def command(cmd, *args)
end
-if RUBY_VERSION < '1.9.0'
- module Kernel #:nodoc:
- # Borrowed from Ruby 1.9.
+class Object #:nodoc:
+ unless defined? instance_exec # 1.9
+ module InstanceExecMethods #:nodoc:
+ end
+ include InstanceExecMethods
+
+ # Evaluate the block with the given arguments within the context of
+ # this object, so self is set to the method receiver.
+ #
+ # From Mauricio's http://eigenclass.org/hiki/bounded+space+instance_exec
+ def instance_exec(*args, &block)
+ begin
+ old_critical, Thread.critical = Thread.critical, true
+ n = 0
+ n += 1 while respond_to?(method_name = "__instance_exec#{n}")
+ InstanceExecMethods.module_eval { define_method(method_name, &block) }
+ ensure
+ Thread.critical = old_critical
+ end
+
+ begin
+ send(method_name, *args)
+ ensure
+ InstanceExecMethods.module_eval { remove_method(method_name) } rescue nil
+ end
+ end
+ end
+end
+
+module Kernel #:nodoc:
+ unless defined? tap # 1.9
def tap
yield self if block_given?
self
- end unless method_defined?('tap')
+ end
end
+end
-
- class Symbol #:nodoc:
+class Symbol #:nodoc:
+ unless defined? to_proc # 1.9
# Borrowed from Ruby 1.9.
def to_proc
Proc.new{|*args| args.shift.__send__(self, *args)}
- end unless method_defined?('to_proc')
+ end
end
+end
- # Also borrowed from Ruby 1.9.
+unless defined? BasicObject # 1.9
class BasicObject #:nodoc:
(instance_methods - ['__send__', '__id__', '==', 'send', 'send!', 'respond_to?', 'equal?', 'object_id']).
each do |method|
Binary file not shown.
@@ -39,7 +39,7 @@ def parse(str)
sections = str.split(SECTION_SEPARATOR).reject { |s| s.strip.empty? }
new sections.map { |section|
lines = section.split(LINE_SEPARATOR).inject([]) { |merged, line|
- if line[0] == 32
+ if line[/^ /] == ' '
merged.last << line[1..-1]
else
merged << line
@@ -302,7 +302,7 @@ def initialize(*args) #:nodoc:
@wsdls = []
prepare do
path('META-INF').include @wsdls
- path('META-INF').include @services_xml, :as=>['services.xml'] if @services_xml
+ path('META-INF').include @services_xml, :as=>'services.xml' if @services_xml
path('lib').include Buildr.artifacts(@libs) unless @libs.nil? || @libs.empty?
end
end
View
@@ -134,7 +134,7 @@ def method_missing(sym, *args, &block) #:nodoc:
def __package__(name) #:nodoc:
const = name.split('.').map { |part| part.gsub(/^./) { |char| char.upcase } }.join
- return const_get(const) if constants.include?(const)
+ return const_get(const) if constants.include?(const) || constants.include?(const.to_sym)
package = Module.new
package.extend Package
package.instance_variable_set :@name, name
@@ -736,7 +736,7 @@ def use(*specs)
# Like Hash#fetch
def fetch(name, default = nil, &block)
- block ||= lambda { raise IndexError.new("No artifact found by name #{name.inspect} in namespace #{self}") }
+ block ||= proc { raise IndexError.new("No artifact found by name #{name.inspect} in namespace #{self}") }
real_name = name.to_s[/^[\w\-\.]+$/] ? name : ArtifactRequirement.unversioned_spec(name)
get(real_name.to_sym) || default || block.call(name)
end
@@ -14,7 +14,16 @@
# the License.
-$LOADED_FEATURES.unshift 'ftools' if RUBY_VERSION >= '1.9.0' # Required to properly load RubyZip under Ruby 1.9
+if RUBY_VERSION >= '1.9.0' # Required to properly load RubyZip under Ruby 1.9
+ $LOADED_FEATURES.unshift 'ftools'
+ require 'fileutils'
+ def File.move(source, dest)
+ FileUtils.move source, dest
+ end
+ def File.rm_rf(path)
+ FileUtils.rm_rf path
+ end
+end
require 'zip/zip'
require 'zip/zipfilesystem'
@@ -122,7 +122,8 @@ class Unzip
# Initialize with hash argument of the form target=>zip_file.
def initialize(args)
- @target, arg_names, @zip_file = Buildr.application.resolve_args([args])
+ @target, arg_names, zip_file = Buildr.application.resolve_args([args])
+ @zip_file = zip_file.first
@paths = {}
end
Binary file not shown.
Binary file not shown.
@@ -109,8 +109,9 @@ def run(scalatest, dependencies) #:nodoc:
ant.suite :classname=>suite
ant.reporter :type=>'stdout', :config=>reporter_options
ant.reporter :type=>'file', :filename=> reportFile, :config=>reporter_options
- ant.includes group_includes.join(" ") if group_includes
- ant.excludes group_excludes.join(" ") if group_excludes
+ # TODO: This should be name=>value pairs!
+ #ant.includes group_includes.join(" ") if group_includes
+ #ant.excludes group_excludes.join(" ") if group_excludes
(options[:properties] || []).each { |name, value| ant.property :name=>name, :value=>value }
end
end
View
@@ -32,7 +32,7 @@
end
it 'should return members when requested' do
- @struct.members.sort.should eql(@hash.keys.map(&:to_s).sort)
+ @struct.members.map(&:to_s).sort.should eql(@hash.keys.map(&:to_s).sort)
end
it 'should return valued when requested' do
@@ -293,7 +293,8 @@ def jars
end
it 'should run all source files as prerequisites' do
- file(mkpath('src')).should_receive :invoke_prerequisites
+ mkpath 'src'
+ file('src').should_receive :invoke_prerequisites
compile_task.from('src').invoke
end
View
@@ -333,10 +333,10 @@ def test_task
it 'should execute teardown task' do
lambda { test_task.invoke }.should run_task('foo:test:teardown')
end
-
+
it 'should update the last successful run timestamp' do
before = Time.now ; test_task.invoke ; after = Time.now
- (before-1..after+1).should include(test_task.timestamp)
+ (before-1..after+1).should cover(test_task.timestamp)
end
end
@@ -151,6 +151,7 @@ class << @compiler
return compile
end
end
+ project('foo').compile
end
it 'should set warning option to false by default' do
View
@@ -17,6 +17,16 @@
require File.join(File.dirname(__FILE__), '../spec_helpers')
+JAVA_CONTAINER = 'org.eclipse.jdt.launching.JRE_CONTAINER'
+SCALA_CONTAINER = 'ch.epfl.lamp.sdt.launching.SCALA_CONTAINER'
+
+SCALA_NATURE = 'ch.epfl.lamp.sdt.core.scalanature'
+JAVA_NATURE = 'org.eclipse.jdt.core.javanature'
+
+SCALA_BUILDER = 'ch.epfl.lamp.sdt.core.scalabuilder'
+JAVA_BUILDER = 'org.eclipse.jdt.core.javabuilder'
+
+
module EclipseHelper
def classpath_xml_elements
task('eclipse').invoke
@@ -52,6 +62,7 @@ def project_xml_elements
task('eclipse').invoke
REXML::Document.new(File.open('.project')).root.elements
end
+
end
@@ -60,15 +71,6 @@ def project_xml_elements
describe "eclipse's .project file" do
- JAVA_CONTAINER = 'org.eclipse.jdt.launching.JRE_CONTAINER'
- SCALA_CONTAINER = 'ch.epfl.lamp.sdt.launching.SCALA_CONTAINER'
-
- SCALA_NATURE = 'ch.epfl.lamp.sdt.core.scalanature'
- JAVA_NATURE = 'org.eclipse.jdt.core.javanature'
-
- SCALA_BUILDER = 'ch.epfl.lamp.sdt.core.scalabuilder'
- JAVA_BUILDER = 'org.eclipse.jdt.core.javabuilder'
-
def project_natures
project_xml_elements.collect("natures/nature") { |n| n.text }
end
File renamed without changes.
@@ -14,7 +14,7 @@
# the License.
-require File.join(File.dirname(__FILE__), 'test_coverage_spec')
+require File.join(File.dirname(__FILE__), 'test_coverage_helper')
Sandbox.require_optional_extension 'buildr/java/cobertura'
artifacts(Buildr::Cobertura::dependencies).map(&:invoke)
View
@@ -14,7 +14,7 @@
# the License.
-require File.join(File.dirname(__FILE__), 'test_coverage_spec')
+require File.join(File.dirname(__FILE__), 'test_coverage_helper')
Sandbox.require_optional_extension 'buildr/java/emma'
artifacts(Buildr::Emma::dependencies).map(&:invoke)
@@ -341,7 +341,7 @@ def inspect_meta_inf
package.invoke
assumed = Array(@meta_inf_ignore)
Zip::ZipFile.open(package.to_s) do |zip|
- entries = zip.entries.map(&:to_s).select { |f| File.dirname(f) == 'META-INF' }.map { |f| File.basename(f) }
+ entries = zip.entries.map(&:name).select { |f| File.dirname(f) == 'META-INF' }.map { |f| File.basename(f) }
assumed.each { |f| entries.should include(f) }
yield entries - assumed if block_given?
end
@@ -659,7 +659,7 @@ def inspect_classpath(package)
tmp.write ear.file.read(package)
end
manifest = Buildr::Packaging::Java::Manifest.from_zip('tmp.zip')
- yield manifest.main['Class-Path'].to_s.split(' ')
+ yield manifest.main['Class-Path'].split(' ')
end
end
@@ -911,7 +911,7 @@ def inspect_classpath(package)
package(:ear) << { :jar=>package(:jar) } << { :jar=>package(:jar, :id=>'bar') }
end
inspect_application_xml do |xml|
- jars = xml.get_elements('/application/jar').map(&:texts).map(&:to_s)
+ jars = xml.get_elements('/application/jar').map(&:texts).map(&:join)
jars.should include('jar/foo-1.0.jar', 'jar/bar-1.0.jar')
end
end
Oops, something went wrong.

0 comments on commit 3caa286

Please sign in to comment.