tpkg 2.3.3 → 2.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE +20 -0
  5. data/Portfile +39 -0
  6. data/Portfile.template +39 -0
  7. data/README.md +43 -0
  8. data/Rakefile +468 -18
  9. data/bin/gem2tpkg +2 -2
  10. data/bin/tpkg +18 -13
  11. data/bin/tpkg_uploader +132 -0
  12. data/ca.pem +1 -0
  13. data/control +7 -0
  14. data/depend +3 -0
  15. data/externals-etch/authorized_keys +40 -0
  16. data/externals-etch/group +9 -0
  17. data/externals-etch/iptables +38 -0
  18. data/externals-etch/limits +30 -0
  19. data/externals-etch/nfs +30 -0
  20. data/externals-etch/sudo +30 -0
  21. data/externals-etch/supplemental_groups +8 -0
  22. data/externals-etch/sysctl +30 -0
  23. data/externals-etch/user +41 -0
  24. data/externals/group +39 -0
  25. data/externals/supplemental_groups +48 -0
  26. data/externals/user +39 -0
  27. data/lib/tpkg.rb +260 -991
  28. data/lib/tpkg/os.rb +164 -0
  29. data/lib/tpkg/os/debian.rb +159 -0
  30. data/lib/tpkg/os/freebsd.rb +113 -0
  31. data/lib/tpkg/os/macosx.rb +113 -0
  32. data/lib/tpkg/os/redhat.rb +173 -0
  33. data/lib/tpkg/os/solaris.rb +101 -0
  34. data/lib/tpkg/os/windows.rb +26 -0
  35. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify.rb +67 -0
  36. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/errors.rb +127 -0
  37. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/kwalify.schema.yaml +58 -0
  38. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/main.rb +442 -0
  39. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/messages.rb +173 -0
  40. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/meta-validator.rb +275 -0
  41. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/parser/base.rb +127 -0
  42. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/parser/yaml.rb +841 -0
  43. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/rule.rb +559 -0
  44. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/templates/genclass-java.eruby +222 -0
  45. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/templates/genclass-php.eruby +104 -0
  46. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/templates/genclass-ruby.eruby +113 -0
  47. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/types.rb +156 -0
  48. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util.rb +158 -0
  49. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/assert-text-equal.rb +46 -0
  50. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/hash-interface.rb +18 -0
  51. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/hashlike.rb +51 -0
  52. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/option-parser.rb +220 -0
  53. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/ordered-hash.rb +57 -0
  54. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/testcase-helper.rb +112 -0
  55. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/validator.rb +282 -0
  56. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/yaml-parser.rb +870 -0
  57. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh.rb +219 -0
  58. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/agent.rb +179 -0
  59. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/constants.rb +18 -0
  60. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/key_manager.rb +219 -0
  61. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/abstract.rb +60 -0
  62. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/hostbased.rb +71 -0
  63. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/keyboard_interactive.rb +66 -0
  64. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/password.rb +39 -0
  65. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/publickey.rb +92 -0
  66. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/pageant.rb +183 -0
  67. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/session.rb +134 -0
  68. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/buffer.rb +340 -0
  69. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/buffered_io.rb +198 -0
  70. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/config.rb +205 -0
  71. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/channel.rb +630 -0
  72. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/constants.rb +33 -0
  73. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/session.rb +597 -0
  74. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/term.rb +178 -0
  75. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/errors.rb +85 -0
  76. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/key_factory.rb +102 -0
  77. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/known_hosts.rb +129 -0
  78. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/loggable.rb +61 -0
  79. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/packet.rb +102 -0
  80. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/prompt.rb +93 -0
  81. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/command.rb +75 -0
  82. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/errors.rb +14 -0
  83. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/http.rb +94 -0
  84. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/socks4.rb +70 -0
  85. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/socks5.rb +142 -0
  86. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/ruby_compat.rb +43 -0
  87. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/service/forward.rb +288 -0
  88. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test.rb +89 -0
  89. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/channel.rb +129 -0
  90. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/extensions.rb +152 -0
  91. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/kex.rb +44 -0
  92. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/local_packet.rb +51 -0
  93. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/packet.rb +81 -0
  94. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/remote_packet.rb +38 -0
  95. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/script.rb +157 -0
  96. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/socket.rb +64 -0
  97. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/algorithms.rb +384 -0
  98. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/cipher_factory.rb +97 -0
  99. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/constants.rb +30 -0
  100. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac.rb +31 -0
  101. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/abstract.rb +79 -0
  102. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/md5.rb +12 -0
  103. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/md5_96.rb +11 -0
  104. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/none.rb +15 -0
  105. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/sha1.rb +13 -0
  106. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/sha1_96.rb +11 -0
  107. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/identity_cipher.rb +55 -0
  108. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/kex.rb +13 -0
  109. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +208 -0
  110. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +77 -0
  111. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/openssl.rb +127 -0
  112. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/packet_stream.rb +235 -0
  113. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/server_version.rb +71 -0
  114. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/session.rb +276 -0
  115. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/state.rb +206 -0
  116. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/verifiers/lenient.rb +30 -0
  117. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/verifiers/null.rb +12 -0
  118. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/verifiers/strict.rb +53 -0
  119. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/version.rb +62 -0
  120. data/lib/tpkg/version.rb +3 -0
  121. data/man/man1/cpan2tpkg.1 +82 -0
  122. data/man/man1/gem2tpkg.1 +120 -0
  123. data/man/man1/tpkg.1 +411 -0
  124. data/pkginfo +8 -0
  125. data/postinstall.solaris +11 -0
  126. data/postremove.solaris +16 -0
  127. data/schema/schema-1.0.5.yml +0 -0
  128. data/schema/schema-1.0.6.yml +0 -0
  129. data/schema/schema-1.0.7.yml +0 -0
  130. data/schema/schema-1.0.8.yml +0 -0
  131. data/schema/schema-1.0.9.yml +0 -0
  132. data/schema/schema.yml +0 -0
  133. data/schema/tpkg-1.0.0.dtd +0 -0
  134. data/schema/tpkg-1.0.1.dtd +0 -0
  135. data/schema/tpkg-1.0.2.dtd +0 -0
  136. data/schema/tpkg-1.0.3.dtd +0 -0
  137. data/schema/tpkg-1.0.4.dtd +0 -0
  138. data/schema/tpkg-1.0.5.dtd +0 -0
  139. data/schema/tpkg-1.0.6.dtd +0 -0
  140. data/schema/tpkg-1.0.7.dtd +0 -0
  141. data/schema/tpkg-1.0.8.dtd +0 -0
  142. data/schema/tpkg-1.0.9.dtd +0 -0
  143. data/schema/tpkg.dtd +0 -0
  144. data/test/TODO +30 -0
  145. data/test/premadetestpkg/pkg_without_file_metadata-1.0-1.tpkg +0 -0
  146. data/test/test_checksum.rb +53 -0
  147. data/test/test_compress.rb +55 -0
  148. data/test/test_conflict.rb +41 -0
  149. data/test/test_crontabs.rb +398 -0
  150. data/test/test_dependency.rb +1113 -0
  151. data/test/test_downgrade.rb +80 -0
  152. data/test/test_download.rb +95 -0
  153. data/test/test_encrypt.rb +136 -0
  154. data/test/test_filemetadata.rb +131 -0
  155. data/test/test_initscript.rb +93 -0
  156. data/test/test_install.rb +186 -0
  157. data/test/test_lock.rb +82 -0
  158. data/test/test_make.rb +410 -0
  159. data/test/test_metadata.rb +805 -0
  160. data/test/test_misc.rb +379 -0
  161. data/test/test_options.rb +1711 -0
  162. data/test/test_os.rb +193 -0
  163. data/test/test_os_debian.rb +99 -0
  164. data/test/test_os_freebsd.rb +89 -0
  165. data/test/test_os_macosx.rb +79 -0
  166. data/test/test_os_redhat.rb +124 -0
  167. data/test/test_os_solaris.rb +85 -0
  168. data/test/test_os_windows.rb +26 -0
  169. data/test/test_query.rb +134 -0
  170. data/test/test_remove.rb +539 -0
  171. data/test/test_tar.rb +99 -0
  172. data/test/test_unpack.rb +977 -0
  173. data/test/test_upgrade.rb +398 -0
  174. data/test/test_version.rb +54 -0
  175. data/test/testcmds/crontab +14 -0
  176. data/test/testcmds/debian/apt-cache +145 -0
  177. data/test/testcmds/debian/dpkg-query +16 -0
  178. data/test/testcmds/freebsd/pkg_info +13 -0
  179. data/test/testcmds/macosx/port +35 -0
  180. data/test/testcmds/redhat/rpmbuild +6 -0
  181. data/test/testcmds/redhat/yum +90 -0
  182. data/test/testcmds/solaris/pkginfo +25 -0
  183. data/test/testcmds/solaris/pkgutil +36 -0
  184. data/test/testpkg/reloc/encfile +2 -0
  185. data/test/testpkg/reloc/file +2 -0
  186. data/test/testpkg/reloc/precryptfile +1 -0
  187. data/test/testpkg/reloc/precryptfile.plaintext +3 -0
  188. data/test/testpkg/tpkg-bad-ownergroup.xml +25 -0
  189. data/test/testpkg/tpkg-bad-ownergroup.yml +18 -0
  190. data/test/testpkg/tpkg-default-perms.xml +28 -0
  191. data/test/testpkg/tpkg-default-perms.yml +20 -0
  192. data/test/testpkg/tpkg-good-ownergroup.xml +25 -0
  193. data/test/testpkg/tpkg-good-ownergroup.yml +18 -0
  194. data/test/testpkg/tpkg-nativedeps.yml +13 -0
  195. data/test/testpkg/tpkg-nofiles.xml +14 -0
  196. data/test/testpkg/tpkg-nofiles.yml +9 -0
  197. data/test/testpkg/tpkg.xml +35 -0
  198. data/test/testpkg/tpkg.yml +25 -0
  199. data/test/tpkgtest.rb +300 -0
  200. data/tpkg.conf +16 -0
  201. data/tpkg.gemspec +24 -0
  202. data/tpkg.spec +28 -0
  203. data/tpkg.xml +17 -0
  204. data/tpkg_profile.sh +32 -0
  205. metadata +306 -31
@@ -0,0 +1,222 @@
1
+ <%
2
+
3
+ ###
4
+ ### $Rev$
5
+ ### $Release: 0.7.2 $
6
+ ### copyright(c) 2005-2010 kuwata-lab all rights reserved.
7
+ ###
8
+
9
+ require 'fileutils'
10
+
11
+ if @describe
12
+ sb = []
13
+ sb << " --package=name : package name\n"
14
+ sb << " --extends=name : class name to extend\n"
15
+ sb << " --implements=name,... : interface names to implement\n"
16
+ sb << " --dir=path : directory to locate output file\n"
17
+ sb << " --basedir=path : base directory to locate output file\n"
18
+ sb << " --constructor=false : not print initialize() method\n"
19
+ #sb << " --ggap : use generation gap pattern\n"
20
+ return sb.join
21
+ end
22
+
23
+
24
+ def java_type(rulehash)
25
+ return rulehash['class'] if rulehash['class']
26
+ imports = []
27
+ case rulehash['type']
28
+ when nil ; return 'String'
29
+ when 'str', 'text' ; return 'String'
30
+ when 'char' ; return 'char'
31
+ when 'int' ; return 'int'
32
+ when 'float' ; return 'float'
33
+ when 'bool' ; return 'boolean'
34
+ when 'date' ; return 'Date'
35
+ when 'timestamp' ; return 'Date'
36
+ when 'seq' ; return 'List'
37
+ when 'map' ; return 'Map'
38
+ when 'any' ; return 'Object'
39
+ else
40
+ raise "*** genclass-java.eruby: '#{rulehash['type']}': unknown type.\n"
41
+ end
42
+ end
43
+
44
+
45
+ #def primitive?(type)
46
+ # @primitives ||= %w[int char float boolean double long byte]
47
+ # return @primitives.include?(type)
48
+ #end
49
+
50
+
51
+ def camelize(str, all=true)
52
+ s = str.split(/[^\w]/).collect { |w| w.capitalize }.join()
53
+ s[0,1] = s[0].chr.lower unless all
54
+ return s
55
+ end
56
+
57
+
58
+ def write_file(classname, classdef)
59
+ if @properties[:dir]
60
+ dir = @properties[:dir]
61
+ else
62
+ basedir = @properties[:basedir] || '.'
63
+ dir = basedir.dup
64
+ dir << '/' << @properties[:package].gsub(/\./, '/') if @properties[:package]
65
+ end
66
+ FileUtils.mkdir_p(dir) unless test(?d, dir)
67
+ filename = "#{dir}/#{classname}.java"
68
+ print "generating #{filename}..."
69
+ File.open(filename, 'w') { |f| f.write(classdef) }
70
+ print "done.\n"
71
+ end
72
+
73
+
74
+ def generate_classdef(schema)
75
+ hash = Kwalify::Util::OrderedHash.new
76
+ Kwalify::Util.traverse_schema(schema) do |rulehash|
77
+ if rulehash['class']
78
+ classdef = _generate(rulehash)
79
+ classname = rulehash['class']
80
+ hash[classname] = classdef if !hash[classname] || classdef.length > hash[classname].length
81
+ end
82
+ end
83
+ hash.each do |classname, classdef|
84
+ write_file(classname, classdef)
85
+ end
86
+ print ""
87
+ end
88
+
89
+
90
+ def _generate(rulehash)
91
+ classname = rulehash['class']
92
+ return unless classname
93
+ assert unless rulehash['mapping']
94
+
95
+ ## preamble
96
+ schema_filename = @properties[:schema_filename]
97
+ sb = ''
98
+ sb << "// generated by kwalify from #{schema_filename}\n"
99
+ sb << "\n"
100
+
101
+ ## package and import classes
102
+ package = @properties[:package]
103
+ sb << "package #{package};\n" if package
104
+ sb << "import java.util.*;\n"
105
+ sb << "\n"
106
+
107
+ ## start class declaration
108
+ extends = @properties[:extends] ? " extends #{@properties[:extends] % classname}" : nil
109
+ implements = @properties[:implements] ? " implements #{@properties[:implements]}" : nil
110
+ classname = classname + '_' if @properties[:ggap]
111
+ sb << "/**\n"
112
+ sb << " * #{rulehash['desc']}\n"
113
+ sb << " */\n"
114
+ sb << "public class #{classname}#{extends}#{implements} {\n"
115
+ sb << "\n"
116
+
117
+ ## instance variables
118
+ rulehash['mapping'].each do |name, map_rulehash|
119
+ next unless name =~ /\A[a-zA-Z_][-\w]*\z/
120
+ name2 = name.gsub(/-/, '_')
121
+ type = java_type(map_rulehash)
122
+ if map_rulehash['default'].nil?
123
+ sb << " private #{type} _#{name2};\n"
124
+ else
125
+ sb << " private #{type} _#{name2} = #{map_rulehash['default'].inspect};\n"
126
+ end
127
+ end
128
+ sb << "\n"
129
+
130
+ ## constructors
131
+ if @properties[:constructor] != false
132
+ sb << _generate_constructor(rulehash)
133
+ sb << "\n"
134
+ end #if
135
+
136
+ ## setter/getter
137
+ rulehash['mapping'].each do |name, map_rulehash|
138
+ next unless name =~ /\A[a-zA-Z_][-\w]*\z/
139
+ name2 = name.gsub(/-/, '_')
140
+ type = java_type(map_rulehash)
141
+ get = type == 'boolean' ? 'is' : 'get'
142
+ sb << " public #{type} #{get}#{camelize(name)}() { return _#{name2}; }\n"
143
+ sb << " public void set#{camelize(name)}(#{type} #{name2}_) { _#{name2} = #{name2}_; }\n"
144
+ end
145
+
146
+ ## end of class declaration
147
+ if @properties[:ggap]
148
+ sb << "}\n"
149
+ sb << "public class #{rulehash['class']} < #{classname}\n"
150
+ end
151
+ sb << "}\n"
152
+
153
+ ##
154
+ classdef = sb
155
+ return classdef
156
+ end
157
+
158
+
159
+ def _generate_constructor(rulehash)
160
+ classname = rulehash['class']
161
+ sb = ''
162
+ ## default constructor
163
+ sb << " public #{classname}() {}\n"
164
+ sb << "\n"
165
+ ## constructor
166
+ sb << " public #{classname}(Map map) {\n"
167
+ objdecl = " Object obj;\n"
168
+ seqdecl = " List seq;\n"
169
+ rulehash['mapping'].each do |name, map_rulehash|
170
+ next unless name =~ /\A[a-zA-Z_][-\w]*\z/
171
+ name2 = name.gsub(/-/, '_')
172
+ if map_rulehash['class']
173
+ cname = map_rulehash['class']
174
+ type = java_type(map_rulehash)
175
+ sb << objdecl; objdecl = ''
176
+ sb << " if ((obj = map.get(\"#{name}\")) != null && obj instanceof Map) {\n"
177
+ sb << " _%-8s = new #{cname}((Map)obj);\n" % name2
178
+ sb << " } else {\n"
179
+ sb << " _%-8s = (#{type})obj;\n" % name2
180
+ sb << " }\n"
181
+ elsif map_rulehash['sequence'] && map_rulehash['sequence'][0]['class']
182
+ item_rulehash = map_rulehash['sequence'][0]
183
+ cname = item_rulehash['class']
184
+ type = java_type(item_rulehash)
185
+ sb << seqdecl; seqdecl = ''
186
+ sb << objdecl; objdecl = ''
187
+ sb << " if ((seq = (List)map.get(\"#{name}\")) != null) {\n"
188
+ sb << " for (int i = 0; i < seq.size(); i++) {\n"
189
+ sb << " if ((obj = seq.get(i)) instanceof Map) {\n"
190
+ sb << " seq.set(i, new #{cname}((Map)obj));\n"
191
+ sb << " }\n"
192
+ sb << " }\n"
193
+ sb << " }\n"
194
+ sb << " _%-12s = seq;\n" % name2
195
+ else
196
+ type = java_type(map_rulehash)
197
+ @wrapper_classes ||= {
198
+ 'int' => 'Number', 'short' => 'Number',
199
+ 'float' => 'Number', 'double' => 'Number',
200
+ 'long' => 'Number', 'byte' => 'Number',
201
+ 'char' => 'Character',
202
+ 'boolean' => 'Boolean',
203
+ }
204
+ if (wrapper = @wrapper_classes[type])
205
+ sb << " if (map.get(\"#{name}\") != null) {\n"
206
+ sb << " _%-8s = ((#{wrapper})map.get(\"#{name}\")).#{type}Value();\n" % name2
207
+ sb << " }\n"
208
+ elsif map_rulehash.key?('default')
209
+ sb << " if (map.get(\"#{name}\") != null)\n"
210
+ sb << " _%-8s = (#{type})map.get(\"#{name}\");\n" % name2
211
+ else
212
+ sb << " _%-12s = (#{type})map.get(\"#{name}\");\n" % name2
213
+ end
214
+ end #if
215
+ end #each
216
+ sb << " }\n"
217
+ return sb
218
+ end
219
+
220
+
221
+ %>
222
+ <%= generate_classdef(@schema) %>
@@ -0,0 +1,104 @@
1
+ <%
2
+
3
+ ###
4
+ ### $Rev$
5
+ ### $Release: 0.7.2 $
6
+ ### copyright(c) 2005-2010 kuwata-lab all rights reserved.
7
+ ###
8
+
9
+ if @describe
10
+ sb = []
11
+ sb << " --namespace=name : prefix name of class\n"
12
+ sb << " --extends=name : parent class name\n"
13
+ sb << " --inplements=name: interface name\n"
14
+ sb << " --constructor=false : not print constructor\n"
15
+ #sb << " --ggap : use generation gap pattern\n"
16
+ return sb.join
17
+ end
18
+
19
+
20
+ require 'kwalify/util/ordered-hash'
21
+
22
+ def generate_classdef(schema)
23
+ hash = Kwalify::Util::OrderedHash.new
24
+ #hash.instance_eval { alias []= add }
25
+ Kwalify::Util.traverse_schema(schema) do |rulehash|
26
+ if rulehash['class']
27
+ arr = _generate_classdef(rulehash)
28
+ key = rulehash['class']
29
+ classdef = arr.join()
30
+ #hash[key] = classdef if !hash.key?(key) || classdef != hash[key]
31
+ hash[key] = classdef if !hash.key?(key) || classdef.length > hash[key].length
32
+ end
33
+ end
34
+ sb = "<?php\n"
35
+ sb << "\n"
36
+ hash.each do |classname, classdef|
37
+ sb << classdef
38
+ sb << "\n"
39
+ end
40
+ sb << "?>\n"
41
+ return sb
42
+ end
43
+
44
+
45
+ def _generate_classdef(rulehash)
46
+ return nil unless rulehash['class']
47
+ assert unless rulehash['mapping']
48
+ classname = rulehash['class']
49
+ classname = classname + '_' if @properties[:ggap]
50
+ ns = @properties[:namespace]
51
+ ns = ns + '_' if ns
52
+ flag_init = @properties[:constructor] != false
53
+ v = nil
54
+ arr = ['']
55
+ arr << "/// #{rulehash['desc']}\n"
56
+ arr << "class #{ns}#{classname}"
57
+ arr << " extends #{v}" if v = @properties[:extends]
58
+ arr << " implements #{v}" if v = @properties[:implements]
59
+ arr << " {\n"
60
+ arr2 = [] # assign into instance variables
61
+ rulehash['mapping'].each do |name, map_rulehash|
62
+ next unless name =~ /\A[a-zA-Z_][-\w]*\z/
63
+ name2 = name.gsub(/-/, '_')
64
+ var = "%-10s" % name2
65
+ len = 10 - name2.length
66
+ spc = ' ' * (len >= 0 ? len : 0)
67
+ if map_rulehash.key?('default')
68
+ arr << " var $#{name2} = #{map_rulehash['default'].inspect}; // #{map_rulehash['type'] || 'str'}\n"
69
+ else
70
+ arr << " var $#{name2}; #{spc}// #{map_rulehash['type'] || 'str'}\n"
71
+ end
72
+ if !flag_init
73
+ # pass
74
+ elsif map_rulehash['class']
75
+ cname = map_rulehash['class']
76
+ arr2 << " $this->#{var} = is_array(@$arr['#{name}']) ? new #{cname}($arr['#{name}']) : @$arr['#{name}'];\n"
77
+ elsif map_rulehash['sequence'] && map_rulehash['sequence'][0]['class']
78
+ item_rulehash = map_rulehash['sequence'][0]
79
+ cname = item_rulehash['class']
80
+ arr2 << " if (is_array(@$arr['#{name}']))\n"
81
+ arr2 << " foreach ($arr['#{name}'] as $k=>$v)\n"
82
+ arr2 << " $this->#{name2}[$k] = is_array($v) ? new #{cname}($v) : $v;\n"
83
+ arr2 << " //else\n"
84
+ arr2 << " // $this->#{var} = @$arr['#{name}'];\n"
85
+ elsif map_rulehash.key?('default')
86
+ arr2 << " if (array_key_exists('#{name}', $arr)) $this->#{name2} = $arr['#{name}'];\n"
87
+ else
88
+ arr2 << " $this->#{var} = @$arr['#{name}'];\n"
89
+ end
90
+ end
91
+ arr << " function __construct($arr=NULL) {\n" if flag_init
92
+ arr << " if (! $arr) return;\n" if flag_init
93
+ arr.concat(arr2)
94
+ arr << " }\n" if flag_init
95
+ if @properties[:ggap]
96
+ arr << "}\n"
97
+ arr << "class #{ns}#{rulehash['class']} extends #{ns}#{classname}\n"
98
+ end
99
+ arr << "}\n"
100
+ return arr
101
+ end
102
+
103
+ %>
104
+ <%= generate_classdef(@schema) %>
@@ -0,0 +1,113 @@
1
+ <%
2
+
3
+ ###
4
+ ### $Rev$
5
+ ### $Release: 0.7.2 $
6
+ ### copyright(c) 2005-2010 kuwata-lab all rights reserved.
7
+ ###
8
+
9
+ if @describe
10
+ sb = []
11
+ sb << " --module=name : module name in which class defined\n"
12
+ sb << " --parent=name : parent class name\n"
13
+ sb << " --include=name : module name which all classes include\n"
14
+ sb << " --initialize=false : not print initialize() method\n"
15
+ sb << " --hashlike : include Kwalify::Util::HashLike module\n"
16
+ #sb << " --ggap : use generation gap pattern\n"
17
+ return sb.join
18
+ end
19
+
20
+
21
+ require 'kwalify/util/ordered-hash'
22
+
23
+ def generate_classdef(schema)
24
+ hash = Kwalify::Util::OrderedHash.new
25
+ #hash.instance_eval { alias []= add }
26
+ modname = @properties[:module]
27
+ Kwalify::Util.traverse_schema(schema) do |rulehash|
28
+ if rulehash['class']
29
+ arr = _generate_classdef(rulehash)
30
+ key = rulehash['class']
31
+ classdef = modname ? arr.join(' ') : arr.join()
32
+ #hash[key] = classdef if !hash.key?(key) || classdef != hash[key]
33
+ hash[key] = classdef if !hash.key?(key) || classdef.length > hash[key].length
34
+ end
35
+ end
36
+ sb = ''
37
+ sb << "require 'kwalify/util/hashlike'\n" if @properties[:hashlike]
38
+ sb << "\n" if @properties[:hashlike]
39
+ sb << "module #{@properties[:module]}\n" if modname
40
+ sb << "\n" if modname
41
+ hash.each do |classname, classdef|
42
+ sb << classdef
43
+ sb << "\n"
44
+ end
45
+ sb << "end\n" if modname
46
+ sb << "\n" if modname
47
+ return sb.chomp
48
+ end
49
+
50
+
51
+ def _generate_classdef(rulehash)
52
+ return nil unless rulehash['class']
53
+ assert unless rulehash['mapping']
54
+ classname = rulehash['class']
55
+ classname = classname + '_' if @properties[:ggap]
56
+ extend = @properties[:parent] ? " < #{@properties[:parent]}" : nil
57
+ flag_init = @properties[:initialize] != false
58
+ arr = ['']
59
+ arr << "## #{rulehash['desc']}\n"
60
+ arr << "class #{classname}#{extend}\n"
61
+ arr << " include Kwalify::Util::HashLike\n" if @properties[:hashlike]
62
+ arr << " include #{@properties[:include]}\n" if @properties[:include]
63
+ arr1 = []
64
+ arr2 = [] # accessors
65
+ arr3 = [] # boolean accessors
66
+ arr4 = [] # default values
67
+ v = nil
68
+ rulehash['mapping'].each do |name, map_rulehash|
69
+ next unless name =~ /\A[a-zA-Z_][-\w]*\z/
70
+ name2 = name.gsub(/-/, '_')
71
+ var = "%-16s" % name2
72
+ len = 13 - name2.length
73
+ len = 0 if len < 0
74
+ spc = ' ' * len
75
+ arr2 << " attr_accessor :#{var} # #{map_rulehash['type'] || 'str'}\n"
76
+ flag_bool = (t = map_rulehash['type']) == 'bool' || t == 'boolean'
77
+ arr3 << " def #{name2}?#{spc}; @#{name2}#{spc}; end\n" if flag_bool
78
+ arr4 << " @#{var} = #{v.inspect}\n" unless (v=map_rulehash['default']).nil?
79
+ if !flag_init
80
+ # pass
81
+ elsif map_rulehash['class']
82
+ cname = map_rulehash['class']
83
+ arr1 << " @#{var} = (v=hash['#{name}']) && v.is_a?(Hash) ? #{cname}.new(v) : v\n"
84
+ elsif map_rulehash['sequence'] && map_rulehash['sequence'][0]['class']
85
+ item_rulehash = map_rulehash['sequence'][0]
86
+ cname = item_rulehash['class']
87
+ arr1 << " @#{var} = (v=hash['#{name}']) ? v.map!{|e| e.is_a?(#{cname}) ? e : #{cname}.new(e)} : v\n"
88
+ elsif map_rulehash.key?('default')
89
+ #arr << " @#{var} = hash.key?('#{name}') ? hash['#{name}'] : #{map_rulehash['default'].inspect}\n"
90
+ arr1 << " @#{var} = (v=hash['#{name}']).nil? ? #{map_rulehash['default'].inspect} : v\n"
91
+ else
92
+ arr1 << " @#{var} = hash['#{name}']\n"
93
+ end
94
+ end
95
+ arr << " def initialize(hash=nil)\n" if flag_init
96
+ arr << " if hash.nil?\n" if flag_init
97
+ arr.concat arr4 if flag_init
98
+ arr << " return\n" if flag_init
99
+ arr << " end\n" if flag_init
100
+ arr.concat arr1 if flag_init
101
+ arr << " end\n" if flag_init
102
+ arr.concat(arr2)
103
+ arr.concat(arr3)
104
+ if @properties[:ggap]
105
+ arr << "end\n"
106
+ arr << "class #{rulehash['class']} < #{classname}\n"
107
+ end
108
+ arr << "end\n"
109
+ return arr
110
+ end
111
+
112
+ %>
113
+ <%= generate_classdef(@schema) %>
@@ -0,0 +1,156 @@
1
+ ###
2
+ ### $Rev$
3
+ ### $Release: 0.7.2 $
4
+ ### copyright(c) 2005-2010 kuwata-lab all rights reserved.
5
+ ###
6
+
7
+ require 'date'
8
+
9
+
10
+ module Kwalify
11
+ module Boolean # :nodoc:
12
+ end
13
+ end
14
+ class TrueClass # :nodoc:
15
+ include Kwalify::Boolean
16
+ end
17
+ class FalseClass # :nodoc:
18
+ include Kwalify::Boolean
19
+ end
20
+ #module Boolean; end
21
+ #class TrueClass
22
+ # include Boolean
23
+ #end
24
+ #class FalseClass
25
+ # include Boolean
26
+ #end
27
+
28
+
29
+ module Kwalify
30
+ module Text # :nodoc:
31
+ end
32
+ end
33
+ class String # :nodoc:
34
+ include Kwalify::Text
35
+ end
36
+ class Numeric # :nodoc:
37
+ include Kwalify::Text
38
+ end
39
+ #module Text; end
40
+ #class String
41
+ # include Text
42
+ #end
43
+ #class Numeric
44
+ # include Text
45
+ #end
46
+
47
+
48
+ module Kwalify
49
+ module Scalar # :nodoc:
50
+ end
51
+ end
52
+ class String # :nodoc:
53
+ include Kwalify::Scalar
54
+ end
55
+ class Numeric # :nodoc:
56
+ include Kwalify::Scalar
57
+ end
58
+ class Date # :nodoc:
59
+ include Kwalify::Scalar
60
+ end
61
+ class Time # :nodoc:
62
+ include Kwalify::Scalar
63
+ end
64
+ class TrueClass # :nodoc:
65
+ include Kwalify::Scalar
66
+ end
67
+ class FalseClass # :nodoc:
68
+ include Kwalify::Scalar
69
+ end
70
+ class NilClass # :nodoc:
71
+ include Kwalify::Scalar
72
+ end
73
+ module Kwalify
74
+ module Text # :nodoc:
75
+ include Kwalify::Scalar
76
+ end
77
+ end
78
+
79
+
80
+ module Kwalify
81
+
82
+
83
+ module Types
84
+
85
+
86
+ DEFAULT_TYPE = "str" ## use "str" as default of @type
87
+
88
+ @@type_table = {
89
+ "seq" => Array,
90
+ "map" => Hash,
91
+ "str" => String,
92
+ #"string" => String,
93
+ "text" => Text,
94
+ "int" => Integer,
95
+ #"integer" => Integer,
96
+ "float" => Float,
97
+ "number" => Numeric,
98
+ #"numeric" => Numeric,
99
+ "date" => Date,
100
+ "time" => Time,
101
+ "timestamp" => Time,
102
+ "bool" => Boolean,
103
+ #"boolean" => Boolean,
104
+ #"object" => Object,
105
+ "any" => Object,
106
+ "scalar" => Scalar,
107
+ }
108
+
109
+ def self.type_table
110
+ return @@type_table
111
+ end
112
+
113
+ def self.type_class(type)
114
+ klass = @@type_table[type]
115
+ #assert_error('type=#{type.inspect}') unless klass
116
+ return klass
117
+ end
118
+
119
+ def self.get_type_class(type)
120
+ return type_class(type)
121
+ end
122
+
123
+
124
+
125
+ #--
126
+ #def collection_class?(klass)
127
+ # return klass.is_a?(Array) || klass.is_a?(Hash)
128
+ #end
129
+ #
130
+ #def scalar_class?(klass)
131
+ # return !klass.is_a?(Array) && !klass.is_a?(Hash) && klass != Object
132
+ #end
133
+
134
+ def collection?(val)
135
+ return val.is_a?(Array) || val.is_a?(Hash)
136
+ end
137
+
138
+ def scalar?(val)
139
+ #return !val.is_a?(Array) && !val.is_a?(Hash) && val.class != Object
140
+ return val.is_a?(Kwalify::Scalar) #&& val.class != Object
141
+ end
142
+
143
+ def collection_type?(type)
144
+ return type == 'seq' || type == 'map'
145
+ end
146
+
147
+ def scalar_type?(type)
148
+ return type != 'seq' && type != 'map' && type == 'any'
149
+ end
150
+
151
+ module_function 'collection?', 'scalar?', 'collection_type?', 'scalar_type?'
152
+ end
153
+
154
+ extend Types
155
+
156
+ end