You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rh...@apache.org on 2008/11/14 22:27:02 UTC

svn commit: r714152 - in /incubator/qpid/trunk/qpid/ruby: Rakefile lib/qpid/config.rb lib/qpid/spec010.rb

Author: rhs
Date: Fri Nov 14 13:27:02 2008
New Revision: 714152

URL: http://svn.apache.org/viewvc?rev=714152&view=rev
Log:
added config.rb for packaging customization of spec location

Added:
    incubator/qpid/trunk/qpid/ruby/lib/qpid/config.rb
Modified:
    incubator/qpid/trunk/qpid/ruby/Rakefile
    incubator/qpid/trunk/qpid/ruby/lib/qpid/spec010.rb

Modified: incubator/qpid/trunk/qpid/ruby/Rakefile
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/ruby/Rakefile?rev=714152&r1=714151&r2=714152&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/ruby/Rakefile (original)
+++ incubator/qpid/trunk/qpid/ruby/Rakefile Fri Nov 14 13:27:02 2008
@@ -8,12 +8,6 @@
 PKG_VERSION='0.10.2'
 GEM_NAME='qpid'
 
-AMQP_SPEC_SRC=Pathname.new("../specs").realpath
-AMQP_SPEC_PATH=["/usr/share/amqp", AMQP_SPEC_SRC].join(File::PATH_SEPARATOR)
-AMQP_SPEC_FILES = FileList["amqp.0-10-qpid-errata.xml"]
-
-ENV["AMQP_SPEC_PATH"] = AMQP_SPEC_PATH unless ENV["AMQP_SPEC_PATH"]
-
 #
 # Additional files for clean/clobber
 #

Added: incubator/qpid/trunk/qpid/ruby/lib/qpid/config.rb
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/ruby/lib/qpid/config.rb?rev=714152&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/ruby/lib/qpid/config.rb (added)
+++ incubator/qpid/trunk/qpid/ruby/lib/qpid/config.rb Fri Nov 14 13:27:02 2008
@@ -0,0 +1,33 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+module Qpid
+  module Config
+
+    def self.amqp_spec
+      dirs = [File::expand_path(File::join(File::dirname(__FILE__), "../../../specs")),
+              "/usr/share/amqp"]
+      dirs.each do |d|
+        spec = File::join(d, "amqp.0-10-qpid-errata.xml")
+        return spec if File::exists? spec
+      end
+    end
+
+  end
+end

Modified: incubator/qpid/trunk/qpid/ruby/lib/qpid/spec010.rb
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/ruby/lib/qpid/spec010.rb?rev=714152&r1=714151&r2=714152&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/ruby/lib/qpid/spec010.rb (original)
+++ incubator/qpid/trunk/qpid/ruby/lib/qpid/spec010.rb Fri Nov 14 13:27:02 2008
@@ -25,8 +25,6 @@
 
   include Qpid::Spec
 
-  AMQP_SPEC_DEFAULT_DIR = "/usr/share/amqp"
-
   # XXX: workaround for ruby bug/missfeature
   Reference = Reference
   Loader = Loader
@@ -435,63 +433,53 @@
 
   # XXX: could be shared
   def self.load(spec = nil)
-      return spec if spec.is_a?(Qpid::Spec010::Spec)
-      if spec.nil?
-          # FIXME: Need to add a packaging setup in here so we know where
-          # the installed spec is going to be.
-          specfile = nil
-          if ENV['AMQP_SPEC']
-              specfile = ENV['AMQP_SPEC']
-          else
-              topdir = File::dirname(File::dirname(File::expand_path(__FILE__)))
-              specfile = File::join(topdir, "../../specs", "amqp.0-10-qpid-errata.xml")
-          end
+    return spec if spec.is_a?(Qpid::Spec010::Spec)
+    if spec.nil?
+      # FIXME: Need to add a packaging setup in here so we know where
+      # the installed spec is going to be.
+      specfile = nil
+      if ENV['AMQP_SPEC']
+        specfile = ENV['AMQP_SPEC']
       else
-          specfile = spec
+        require "qpid/config"
+        specfile = Qpid::Config.amqp_spec
       end
+    else
+      specfile = spec
+    end
 
-      unless Pathname.new(specfile).absolute?
-          path = ENV["AMQP_SPEC_PATH"] || AMQP_SPEC_DEFAULT_DIR
+    specfile_cache = spec_cache(specfile)
+    # FIXME: Check that cache is newer than specfile
+    if File::exist?(specfile_cache)
+      begin
+        spec = File::open(specfile_cache, "r") do |f|
+          Marshal::load(f)
+        end
+        return spec
+      rescue
+        # Ignore, will load from XML
+      end
+    end
 
-          p = path.split(File::PATH_SEPARATOR).collect { |p|
-              Pathname.new(p).join(specfile)
-          }.find { |p| p.file? }
-          raise "Can not find file for spec #{spec}" unless p
-          specfile = p.to_s
-      end
-
-      specfile_cache = spec_cache(specfile)
-      # FIXME: Check that cache is newer than specfile
-      if File::exist?(specfile_cache)
-          begin
-              spec = File::open(specfile_cache, "r") do |f|
-                  Marshal::load(f)
-              end
-              return spec
-          rescue
-              # Ignore, will load from XML
-          end
-      end
-
-      doc = File::open(specfile, "r") { |f| Document.new(f) }
-      spec = Loader010.new().load(doc.root)
-      spec.traverse! do |o|
-          if o.is_a?(Reference)
-              o.resolve(spec)
-          else
-              o
-          end
+    doc = File::open(specfile, "r") { |f| Document.new(f) }
+    spec = Loader010.new().load(doc.root)
+    spec.traverse! do |o|
+      if o.is_a?(Reference)
+        o.resolve(spec)
+      else
+        o
       end
+    end
 
-      spec.children.each { |c| c.parent = spec }
+    spec.children.each { |c| c.parent = spec }
 
-      begin
-          FileUtils::mkdir_p(File::dirname(specfile_cache))
-          File::open(specfile_cache, "w") { |f| Marshal::dump(spec, f) }
-      rescue
-          # Ignore, we are fine without the cached spec
-      end
-      return spec
+    begin
+      FileUtils::mkdir_p(File::dirname(specfile_cache))
+      File::open(specfile_cache, "w") { |f| Marshal::dump(spec, f) }
+    rescue
+      # Ignore, we are fine without the cached spec
+    end
+    return spec
   end
 
 end