You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildr.apache.org by vb...@apache.org on 2008/03/26 01:11:23 UTC
svn commit: r641088 - in /incubator/buildr/trunk: lib/buildr/xmlbeans.rb
lib/java/artifact_namespace.rb spec/artifact_namespace_spec.rb
Author: vborja
Date: Tue Mar 25 17:11:22 2008
New Revision: 641088
URL: http://svn.apache.org/viewvc?rev=641088&view=rev
Log:
Buildr::XMLBeans uses ArtifactNamespace to specify requirements.
Added more namespace specs
Modified:
incubator/buildr/trunk/lib/buildr/xmlbeans.rb
incubator/buildr/trunk/lib/java/artifact_namespace.rb
incubator/buildr/trunk/spec/artifact_namespace_spec.rb
Modified: incubator/buildr/trunk/lib/buildr/xmlbeans.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/xmlbeans.rb?rev=641088&r1=641087&r2=641088&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/xmlbeans.rb (original)
+++ incubator/buildr/trunk/lib/buildr/xmlbeans.rb Tue Mar 25 17:11:22 2008
@@ -20,12 +20,20 @@
module Buildr
# Provides XMLBeans schema compiler. Require explicitly using <code>require "buildr/xmlbeans"</code>.
+ #
+ # You may use ArtifactNamespace to select the artifact version used by this module:
+ #
+ # require 'buildr/xmlbeans'
+ # artifacts[Buildr::XMLBeans].use :xmlbeans => '2.2.0'
+ # define 'some_proj' do
+ # compile_xml_beans _('xsd_dir')
+ # end
module XMLBeans
- Buildr.artifacts(self) do
- need :stax => 'stax:stax-api:jar:>=1.0',
- :xmlbeans => 'org.apache.xmlbeans:xmlbeans:jar:>=2.2'
- default :stax => '1.0', :xmlbeans => '2.3.0'
+ Buildr.artifacts(self) do |ns|
+ ns.need :stax => 'stax:stax-api:jar:>=1',
+ :xmlbeans => 'org.apache.xmlbeans:xmlbeans:jar:>2'
+ ns.default :stax => '1.0.1', :xmlbeans => '2.3.0'
end
class << self
@@ -37,7 +45,7 @@
puts "Running XMLBeans schema compiler" if verbose
Buildr.ant "xmlbeans" do |ant|
ant.taskdef :name=>"xmlbeans", :classname=>"org.apache.xmlbeans.impl.tool.XMLBean",
- :classpath=>requires.join(File::PATH_SEPARATOR)
+ :classpath=>requires.map(&:to_s).join(File::PATH_SEPARATOR)
ant.xmlbeans :srconly=>"true", :srcgendir=>options[:output].to_s, :classgendir=>options[:output].to_s,
:javasource=>options[:javasource] do
args.flatten.each { |file| ant.fileset File.directory?(file) ? { :dir=>file } : { :file=>file } }
@@ -47,8 +55,8 @@
touch options[:output].to_s, :verbose=>false
end
- def requires()
- Buildr.artifacts[XMLBeans].used.each { |artifact| artifact.invoke }.map(&:to_s)
+ def requires
+ Buildr.artifacts[XMLBeans].each { |artifact| artifact.invoke }
end
end
Modified: incubator/buildr/trunk/lib/java/artifact_namespace.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/java/artifact_namespace.rb?rev=641088&r1=641087&r2=641088&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/java/artifact_namespace.rb (original)
+++ incubator/buildr/trunk/lib/java/artifact_namespace.rb Tue Mar 25 17:11:22 2008
@@ -151,7 +151,7 @@
case name
when Array then name = name.join(':')
when Module, Project then name = name.name
- when true then ROOT
+ when :root, 'root', true then ROOT
when false, nil then
task = Thread.current[:rake_chain]
task = task.instance_variable_get(:@value) if task
@@ -181,7 +181,11 @@
include Enumerable
# Return an array of artifacts defined for use
- def values(include_parents = false)
+ # If +include_parents+ is true, all artifacts from this namespace
+ # up are returned.
+ # If +ignore_missing+ is true, artifacts without selected version
+ # are ignored, otherwise an exception is thrown.
+ def values(include_parents = false, ignore_missing = false)
seen = {}
registry = self
while registry
@@ -190,6 +194,15 @@
name = normalize_name(spec)
seen[name] = Buildr.artifact(spec) unless seen.key?(name)
end
+ registry.instance_variable_get(:@requires).values.each do |req|
+ spec = spec(req)
+ raise "No version selected for #{Artifact.to_spec(req)} " +
+ "on namespace #{registry.name}" unless ignore_missing || spec
+ if spec
+ name = normalize_name(spec)
+ seen[name] = Buildr.artifact(spec) unless seen.key?(name)
+ end
+ end
registry = include_parents ? registry.parent : nil
end
seen.values
@@ -241,6 +254,7 @@
# Return the artifact spec (a hash) for the given name
def spec(name)
+ return nil unless name
name = normalize_name(name)
using = @using[name] || @using[@aliases[name]]
if Hash === using
@@ -256,6 +270,7 @@
end
def requirement(name)
+ return nil unless name
name = normalize_name(name)
req = @requires[name] || @requires[@aliases[name]]
if req
@@ -266,6 +281,7 @@
end
def delete(name)
+ return self unless name
name = normalize_name(name)
[name, @aliases[name]].each do |n|
@requires.delete(n); @using.delete(n); @aliases.delete(n)
@@ -555,8 +571,7 @@
requirements.size > 1
end
- # Return the last requirement on this object having a
- # = operator.
+ # Return the last requirement on this object having an = operator.
def default
default = nil
requirements.reverse.find do |r|
Modified: incubator/buildr/trunk/spec/artifact_namespace_spec.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/artifact_namespace_spec.rb?rev=641088&r1=641087&r2=641088&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/artifact_namespace_spec.rb (original)
+++ incubator/buildr/trunk/spec/artifact_namespace_spec.rb Tue Mar 25 17:11:22 2008
@@ -172,4 +172,24 @@
artifacts[Some].spec(:bat)[:version].should == '1.5.6.7'
end
+ it 'should return its artifacts when called the #values method' do
+ artifacts do |ns|
+ ns.use "num:one:jar:1.1", "num:two:jar:2.2"
+ end
+ artifacts('foo') do |ns|
+ ns.need :one => 'num:one:jar:>=1.0'
+ ns.default :one => '1.0'
+ ns.need :three => 'num:three:jar:>=3.0'
+ ns.default :three => '3.0'
+ end
+ foo = artifacts['foo'].values.map(&:to_spec)
+ foo.should include("num:one:jar:1.1", "num:three:jar:3.0")
+ foo = artifacts['foo'].values(true).map(&:to_spec) # including parents
+ foo.should include("num:one:jar:1.1", "num:three:jar:3.0", "num:two:jar:2.2")
+ artifacts['foo'].need :four => 'num:four:jar:>4.0'
+ lambda { artifacts[:foo].values }.should raise_error(Exception, /no version/i)
+ foo = artifacts['foo'].values(false, true).map(&:to_spec) # ignore missing
+ foo.should include("num:one:jar:1.1", "num:three:jar:3.0")
+ end
+
end