1 | if /cygwin|mingw|mswin32|bccwin32/.match(RUBY_PLATFORM) |
---|
2 | $LOAD_PATH.each do |load_path| |
---|
3 | svn_ext_path = File.join(load_path, "svn", "ext") |
---|
4 | if File.exists?(svn_ext_path) |
---|
5 | svn_ext_path_win = File.expand_path(svn_ext_path) |
---|
6 | svn_ext_path_win = svn_ext_path.gsub(File::SEPARATOR, File::ALT_SEPARATOR) |
---|
7 | unless ENV["PATH"].split(";").find {|path| path == svn_ext_path_win} |
---|
8 | ENV["PATH"] = "#{svn_ext_path_win};#{ENV['PATH']}" |
---|
9 | end |
---|
10 | end |
---|
11 | end |
---|
12 | end |
---|
13 | |
---|
14 | require 'tempfile' |
---|
15 | |
---|
16 | unless respond_to?(:__send!) |
---|
17 | module Kernel |
---|
18 | alias __send! __send__ |
---|
19 | end |
---|
20 | end |
---|
21 | |
---|
22 | module Svn |
---|
23 | module Util |
---|
24 | module_function |
---|
25 | def to_ruby_class_name(name) |
---|
26 | name.split("_").collect do |x| |
---|
27 | "#{x[0,1].upcase}#{x[1..-1].downcase}" |
---|
28 | end.join("") |
---|
29 | end |
---|
30 | |
---|
31 | def to_ruby_const_name(name) |
---|
32 | name.upcase |
---|
33 | end |
---|
34 | |
---|
35 | def valid_rev?(rev) |
---|
36 | rev and rev >= 0 |
---|
37 | end |
---|
38 | |
---|
39 | def copy?(copyfrom_path, copyfrom_rev) |
---|
40 | Util.valid_rev?(copyfrom_rev) && !copyfrom_path.nil? |
---|
41 | end |
---|
42 | |
---|
43 | def hash_to_prop_array(hash) |
---|
44 | hash.collect do |key, value| |
---|
45 | Svn::Core::Prop.new(key, value) |
---|
46 | end |
---|
47 | end |
---|
48 | |
---|
49 | def set_constants(ext_mod, target_mod=self) |
---|
50 | target_name = nil |
---|
51 | ext_mod.constants.each do |const| |
---|
52 | target_name = nil |
---|
53 | case const |
---|
54 | when /^SVN__/ |
---|
55 | # ignore private constants |
---|
56 | when /^SVN_(?:#{target_mod.name.split("::").last.upcase}_)?/ |
---|
57 | target_name = $POSTMATCH |
---|
58 | when /^SWIG_SVN_/ |
---|
59 | target_name = $POSTMATCH |
---|
60 | when /^Svn_(?:#{target_mod.name.split("::").last.downcase}_)?(.+)_t$/ |
---|
61 | target_name = to_ruby_class_name($1) |
---|
62 | when /^Svn_(?:#{target_mod.name.split("::").last.downcase}_)?/ |
---|
63 | target_name = to_ruby_const_name($POSTMATCH) |
---|
64 | # else |
---|
65 | # puts const |
---|
66 | end |
---|
67 | unless target_name.nil? |
---|
68 | target_mod.const_set(target_name, ext_mod.const_get(const)) |
---|
69 | end |
---|
70 | end |
---|
71 | end |
---|
72 | |
---|
73 | def set_methods(ext_mod, target_mod=self) |
---|
74 | target_name = nil |
---|
75 | ext_mod.public_methods(false).each do |meth| |
---|
76 | target_name = nil |
---|
77 | case meth |
---|
78 | when /^svn_(?:#{target_mod.name.split("::").last.downcase}_)?/ |
---|
79 | target_name = $POSTMATCH |
---|
80 | when /^apr_/ |
---|
81 | target_name = meth |
---|
82 | end |
---|
83 | unless target_name.nil? |
---|
84 | target_mod.module_eval(<<-EOC, __FILE__, __LINE__ + 1) |
---|
85 | def #{target_name}(*args, &block) |
---|
86 | #{ext_mod.name}.#{meth}(*args, &block) |
---|
87 | end |
---|
88 | module_function :#{target_name} |
---|
89 | EOC |
---|
90 | end |
---|
91 | end |
---|
92 | end |
---|
93 | |
---|
94 | def filename_to_temp_file(filename) |
---|
95 | file = Tempfile.new("svn-ruby") |
---|
96 | file.binmode |
---|
97 | file.print(File.open(filename, "rb") {|f| f.read}) |
---|
98 | file.close |
---|
99 | file.open |
---|
100 | file.binmode |
---|
101 | file |
---|
102 | end |
---|
103 | |
---|
104 | def reset_message_directory |
---|
105 | if /cygwin|mingw|mswin32|bccwin32/.match(RUBY_PLATFORM) |
---|
106 | top_directory = File.join(File.dirname(__FILE__), "..", "..") |
---|
107 | top_directory = File.expand_path(top_directory) |
---|
108 | locale_directory = File.join(top_directory, "share", "locale") |
---|
109 | locale_directory_win = locale_directory.tr(File::SEPARATOR, |
---|
110 | File::ALT_SEPARATOR) |
---|
111 | GetText.bindtextdomain(locale_directory_win) |
---|
112 | end |
---|
113 | end |
---|
114 | |
---|
115 | def validate_options(options, optional_keys, required_keys=[]) |
---|
116 | unknown_keys = options.keys - (optional_keys + required_keys) |
---|
117 | unless unknown_keys.empty? |
---|
118 | raise(ArgumentError, "Unknown key(s): #{unknown_keys.join(", ")}") |
---|
119 | end |
---|
120 | missing_keys = [] |
---|
121 | required_keys.each do |key| |
---|
122 | missing_keys << key if options[key].nil? |
---|
123 | end |
---|
124 | unless missing_keys.empty? |
---|
125 | raise(ArgumentError, "Missing key(s): #{missing_keys.join(", ")}") |
---|
126 | end |
---|
127 | end |
---|
128 | end |
---|
129 | end |
---|