Author: vborja
Date: Tue Mar 25 17:10:22 2008
New Revision: 641086

URL: http://svn.apache.org/viewvc?rev=641086&view=rev
Log:
Removed ArtifactNamespace::AryMixin#namespace in favor of using #[]

Modified:
    incubator/buildr/trunk/lib/java/artifact_namespace.rb
    incubator/buildr/trunk/spec/artifact_namespace_spec.rb

Modified: incubator/buildr/trunk/lib/java/artifact_namespace.rb
URL: 
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/java/artifact_namespace.rb?rev=641086&r1=641085&r2=641086&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/java/artifact_namespace.rb (original)
+++ incubator/buildr/trunk/lib/java/artifact_namespace.rb Tue Mar 25 17:10:22 
2008
@@ -28,10 +28,11 @@
   # their parent projects. 
   #
   # To open the namespace for the current context just provide a block
-  # to the Buildr.artifacts method (see ArtifactNamespace.instance):
+  # to the Buildr.artifacts method (see ArtifactNamespace.instance) or
+  # index the resulting array by a non-numeric argument (see AryMixin#[])
   #
   #    -- buildfile --
-  #    # open the root namespace, equivalent to artifacts[nil]
+  #    # open the root namespace, equivalent to artifacts[:root]
   #    artifacts do |ns|
   #       # later referenced by name
   #       ns.use :spring => 'org.springframework:spring:jar:2.5'
@@ -98,20 +99,12 @@
       #
       #   ary = artifacts('some:art:jar:1.0')
       #   ary[0] -> Artifact
-      #   ary[nil] -> root ArtifactNamespace
+      #   ary[nil] -> currently running ArtifactNamespace
+      #   ary[true] -> root ArtifactNamespace
       #   ary['some:name:space'] -> 'some:name:space' ArtifactNamespace
       def [](idx)
-        Numeric === idx ? super : namespace(idx)
+        Numeric === idx ? super : ArtifactNamespace.instance(idx)
       end
-      
-      # :call-seq:
-      #   artifacts.namespace -> namespace
-      #   artifacts.namespace(name) -> namespace
-      def namespace(*a, &b)
-        ArtifactNamespace.instance(*a, &b)
-      end
-      
-      alias_method :ns, :namespace
     end
     
     ROOT = :root
@@ -158,7 +151,8 @@
         case name
         when Array then name = name.join(':')
         when Module, Project then name = name.name
-        when nil then
+        when true then ROOT
+        when false, nil then
           task = Thread.current[:rake_chain]
           task = task.instance_variable_get(:@value) if task
           name = case task
@@ -171,7 +165,7 @@
         name = ROOT if name.to_s.blank?
         @instances ||= Hash.new { |h, k| h[k] = new(k) }
         instance = @instances[name.to_sym]
-        instance.tap(&block) if block
+        yield(instance) if block
         instance
       end
       
@@ -242,25 +236,19 @@
     # Test if named requirement has been satisfied
     def satisfied?(name)
       req, spec = requirement(name), spec(name)
-      if req && spec
-        req[:version].satisfied_by?(spec[:version])
-      else
-        false
-      end
+      req && spec && req[:version].satisfied_by?(spec[:version])
     end
 
     # Return the artifact spec (a hash) for the given name
     def spec(name)
       name = normalize_name(name)
       using = @using[name] || @[EMAIL PROTECTED]
-      if using
-        if using.kind_of?(Hash)
-          spec = using.dup
-        else
-          spec = @requires[name] || @[EMAIL PROTECTED]
-          spec = spec ? spec.dup : {}
-          spec[:version] = using.dup
-        end
+      if Hash === using
+        using.dup
+      elsif using
+        spec = @requires[name] || @[EMAIL PROTECTED]
+        spec = spec ? spec.dup : {}
+        spec[:version] = using.dup
         spec
       elsif parent
         parent.spec(name) || parent.spec(@aliases[name])
@@ -337,16 +325,16 @@
           named[nil] = Artifact.to_hash(spec)
         end
         named.each_pair do |name, spec|
+          unvers = normalize_name(spec)
           spec[:version] = VersionRequirement.create(spec[:version])
-          unvers = Artifact.to_spec(spec.merge(:version => '-')).to_sym
           @requires[unvers] = spec
           if name
             name = name.to_sym
             using = @using[name] || @[EMAIL PROTECTED]
             using = { :version  => using } if using.kind_of?(String) && 
VersionRequirement.version?(using)
             fail_unless_satisfied(spec, using)
-            @aliases[name.to_sym] = unvers
-            @aliases[unvers] = name.to_sym
+            @aliases[name] = unvers
+            @aliases[unvers] = name
           end
         end
       end
@@ -636,13 +624,10 @@
     end
   end # VersionRequirement
 
+  # Search best artifact version from remote repositories
   module ArtifactSearch
     extend self
     
-    def enabled=(bool); @enabled = true & bool; end
-    def enabled?; @enabled; end
-    self.enabled = true
-    
     def include(method = nil)
       (@includes ||= []).tap { push method if method }
     end
@@ -677,8 +662,7 @@
       end
       result ||= requirement.default
       raise "Could not find #{Artifact.to_spec(spec)}"  +
-        "\n You may need to use an specific version instead of a requirement" +
-        "\n More Docu." unless result
+        "\n You may need to use an specific version instead of a requirement" 
unless result
       spec.merge :version => result
     end
     

Modified: incubator/buildr/trunk/spec/artifact_namespace_spec.rb
URL: 
http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/artifact_namespace_spec.rb?rev=641086&r1=641085&r2=641086&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/artifact_namespace_spec.rb (original)
+++ incubator/buildr/trunk/spec/artifact_namespace_spec.rb Tue Mar 25 17:10:22 
2008
@@ -25,21 +25,12 @@
     expected = be_kind_of(ArtifactNamespace)
     artifacts { |ns| ns.name.should == ArtifactNamespace::ROOT }
     artifacts { |ns| ns.should expected }.should expected
-    artifacts { self.should expected }
   end
 
   it 'should tap root namespace when given a block and nil argument' do
     artifacts(nil) { |ns| ns.name.should == ArtifactNamespace::ROOT }
   end
 
-  it 'should return an array responding to #namespace if no block given' do
-    ary = artifacts
-    ary.should be_kind_of(Array)
-    ary.should respond_to(:namespace)
-    ary.namespace.should be_kind_of(ArtifactNamespace)
-    ary.namespace.name.should === ArtifactNamespace::ROOT
-  end
-  
   it 'should return an array whose non-numeric indices are namespaces' do
     ary = artifacts("foo:bar:jar:1.0")
     ary.should be_kind_of(Array)
@@ -87,12 +78,12 @@
   end
 
   it 'should have no parent if its the root namespace' do
-    root = artifacts.namespace
+    root = artifacts[nil]
     root.parent.should be_nil
   end
 
   it 'should reference it\'s parent' do
-    root = artifacts.namespace
+    root = artifacts[nil]
     define 'foo' do
       foo = artifacts { |ns| ns.parent.should == root }
       define 'bar' do
@@ -124,16 +115,16 @@
   end
 
   it 'should set defaults witht the #default method' do 
-    artifacts do
-      use :bar => 'foo:bar:jar:2.0'
-      spec(:bar)[:version].should == '2.0'
-      default :bar => 'foo:bar:jar:1.9'
-      spec(:bar)[:version].should == '2.0'
-      default :baz => 'foo:baz:jar:1.8'
-      spec(:baz)[:version].should == '1.8'
-      need :bat => 'foo:bat:jar:>1.0'
-      default :bat => 'foo:bat:jar:1.5'
-      spec(:bat)[:version].should == '1.5'
+    artifacts do |ns|
+      ns.use :bar => 'foo:bar:jar:2.0'
+      ns.spec(:bar)[:version].should == '2.0'
+      ns.default :bar => 'foo:bar:jar:1.9'
+      ns.spec(:bar)[:version].should == '2.0'
+      ns.default :baz => 'foo:baz:jar:1.8'
+      ns.spec(:baz)[:version].should == '1.8'
+      ns.need :bat => 'foo:bat:jar:>1.0'
+      ns.default :bat => 'foo:bat:jar:1.5'
+      ns.spec(:bat)[:version].should == '1.5'
     end
   end
 
@@ -161,19 +152,19 @@
   end
 
   it 'should select compatible artifacts defined on parent namespaces' do
-    artifacts do
-      use :foo => 'foo:bar:jar:3.0'
-      use :baz => 'foo:baz:jar:1.0'
-      use 'foo:bat:jar:1.5.6.7'
+    artifacts do |ns|
+      ns.use :foo => 'foo:bar:jar:3.0'
+      ns.use :baz => 'foo:baz:jar:1.0'
+      ns.use 'foo:bat:jar:1.5.6.7'
     end
     module Some
-      Buildr.artifacts(self) do
-        need :foo => 'foo:bar:jar:>=1.0'
-        need :baz => 'foo:baz:jar:>=2.0'
-        need :bat => 'foo:bat:jar:>1.5 & <1.6'
-        default :foo => '2.0'
-        default :baz => '2.0'
-        default :bat => '1.5.5'
+      Buildr.artifacts(self) do |ns|
+        ns.need :foo => 'foo:bar:jar:>=1.0'
+        ns.need :baz => 'foo:baz:jar:>=2.0'
+        ns.need :bat => 'foo:bat:jar:>1.5 & <1.6'
+        ns.default :foo => '2.0'
+        ns.default :baz => '2.0'
+        ns.default :bat => '1.5.5'
       end
     end
     artifacts[Some].spec(:foo)[:version].should == '3.0'


Reply via email to