puppet 3.4.3 → 3.5.0.rc1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (811) hide show
  1. data/CONTRIBUTING.md +6 -6
  2. data/Gemfile +22 -16
  3. data/LICENSE +1 -1
  4. data/README.md +33 -11
  5. data/Rakefile +1 -1
  6. data/conf/auth.conf +4 -0
  7. data/ext/build_defaults.yaml +1 -1
  8. data/ext/debian/control +6 -6
  9. data/ext/ips/transforms +1 -1
  10. data/ext/nagios/naggen +1 -1
  11. data/ext/project_data.yaml +21 -1
  12. data/ext/puppet-test +3 -3
  13. data/ext/redhat/puppet.spec.erb +28 -2
  14. data/ext/suse/puppet.spec +1 -1
  15. data/ext/upload_facts.rb +1 -1
  16. data/ext/windows/service/daemon.rb +99 -20
  17. data/lib/hiera_puppet.rb +2 -2
  18. data/lib/puppet.rb +68 -5
  19. data/lib/puppet/agent.rb +5 -1
  20. data/lib/puppet/application.rb +20 -11
  21. data/lib/puppet/application/agent.rb +1 -1
  22. data/lib/puppet/application/apply.rb +61 -41
  23. data/lib/puppet/application/cert.rb +3 -3
  24. data/lib/puppet/application/device.rb +7 -8
  25. data/lib/puppet/application/doc.rb +1 -1
  26. data/lib/puppet/application/filebucket.rb +3 -3
  27. data/lib/puppet/application/kick.rb +2 -2
  28. data/lib/puppet/application/master.rb +1 -1
  29. data/lib/puppet/application/queue.rb +9 -9
  30. data/lib/puppet/application/resource.rb +2 -2
  31. data/lib/puppet/bindings.rb +6 -6
  32. data/lib/puppet/configurer.rb +17 -14
  33. data/lib/puppet/configurer/fact_handler.rb +1 -1
  34. data/lib/puppet/confine/any.rb +26 -0
  35. data/lib/puppet/confine/exists.rb +1 -1
  36. data/lib/puppet/confiner.rb +1 -0
  37. data/lib/puppet/context.rb +55 -0
  38. data/lib/puppet/context/trusted_information.rb +56 -0
  39. data/lib/puppet/defaults.rb +97 -26
  40. data/lib/puppet/environments.rb +187 -0
  41. data/lib/puppet/error.rb +2 -1
  42. data/lib/puppet/external/pson/common.rb +1 -1
  43. data/lib/puppet/external/pson/pure/generator.rb +1 -1
  44. data/lib/puppet/external/pson/pure/parser.rb +1 -1
  45. data/lib/puppet/face/config.rb +73 -15
  46. data/lib/puppet/face/file/store.rb +1 -1
  47. data/lib/puppet/face/help.rb +2 -1
  48. data/lib/puppet/face/help/action.erb +1 -0
  49. data/lib/puppet/face/help/face.erb +1 -0
  50. data/lib/puppet/face/help/global.erb +1 -0
  51. data/lib/puppet/face/help/man.erb +9 -8
  52. data/lib/puppet/face/module/list.rb +13 -7
  53. data/lib/puppet/face/node/clean.rb +2 -2
  54. data/lib/puppet/face/parser.rb +11 -5
  55. data/lib/puppet/face/status.rb +1 -1
  56. data/lib/puppet/feature/external_facts.rb +2 -2
  57. data/lib/puppet/feature/libuser.rb +1 -1
  58. data/lib/puppet/feature/msgpack.rb +2 -0
  59. data/lib/puppet/feature/rails.rb +2 -2
  60. data/lib/puppet/file_bucket/dipper.rb +9 -9
  61. data/lib/puppet/file_bucket/file.rb +9 -5
  62. data/lib/puppet/file_serving/base.rb +1 -1
  63. data/lib/puppet/file_serving/configuration.rb +1 -1
  64. data/lib/puppet/file_serving/configuration/parser.rb +3 -3
  65. data/lib/puppet/file_serving/content.rb +2 -2
  66. data/lib/puppet/file_serving/fileset.rb +4 -4
  67. data/lib/puppet/file_serving/metadata.rb +69 -15
  68. data/lib/puppet/file_serving/mount/file.rb +1 -1
  69. data/lib/puppet/file_system.rb +361 -1
  70. data/lib/puppet/file_system/file18.rb +3 -3
  71. data/lib/puppet/file_system/file19.rb +3 -3
  72. data/lib/puppet/file_system/file19windows.rb +18 -23
  73. data/lib/puppet/file_system/file_impl.rb +145 -0
  74. data/lib/puppet/file_system/memory_file.rb +23 -9
  75. data/lib/puppet/file_system/memory_impl.rb +64 -0
  76. data/lib/puppet/forge.rb +4 -3
  77. data/lib/puppet/forge/repository.rb +0 -1
  78. data/lib/puppet/graph/relationship_graph.rb +7 -7
  79. data/lib/puppet/indirector.rb +1 -0
  80. data/lib/puppet/indirector/catalog/compiler.rb +3 -30
  81. data/lib/puppet/indirector/catalog/msgpack.rb +6 -0
  82. data/lib/puppet/indirector/catalog/static_compiler.rb +3 -7
  83. data/lib/puppet/indirector/data_binding/hiera.rb +1 -1
  84. data/lib/puppet/indirector/direct_file_server.rb +2 -2
  85. data/lib/puppet/indirector/exec.rb +1 -1
  86. data/lib/puppet/indirector/face.rb +3 -2
  87. data/lib/puppet/indirector/facts/facter.rb +1 -1
  88. data/lib/puppet/indirector/file_bucket_file/file.rb +25 -15
  89. data/lib/puppet/indirector/file_metadata/file.rb +1 -1
  90. data/lib/puppet/indirector/file_server.rb +1 -1
  91. data/lib/puppet/indirector/indirection.rb +1 -1
  92. data/lib/puppet/indirector/json.rb +4 -4
  93. data/lib/puppet/indirector/key/file.rb +8 -5
  94. data/lib/puppet/indirector/ldap.rb +1 -1
  95. data/lib/puppet/indirector/memory.rb +4 -0
  96. data/lib/puppet/indirector/msgpack.rb +82 -0
  97. data/lib/puppet/indirector/node/exec.rb +1 -1
  98. data/lib/puppet/indirector/node/ldap.rb +3 -3
  99. data/lib/puppet/indirector/node/msgpack.rb +7 -0
  100. data/lib/puppet/indirector/node/yaml.rb +15 -0
  101. data/lib/puppet/indirector/queue.rb +3 -2
  102. data/lib/puppet/indirector/report/msgpack.rb +11 -0
  103. data/lib/puppet/indirector/request.rb +17 -20
  104. data/lib/puppet/indirector/resource/rest.rb +1 -1
  105. data/lib/puppet/indirector/resource_type/parser.rb +3 -13
  106. data/lib/puppet/indirector/rest.rb +6 -7
  107. data/lib/puppet/indirector/ssl_file.rb +7 -7
  108. data/lib/puppet/indirector/yaml.rb +9 -13
  109. data/lib/puppet/metatype/manager.rb +12 -7
  110. data/lib/puppet/module.rb +14 -9
  111. data/lib/puppet/module_tool.rb +21 -26
  112. data/lib/puppet/module_tool/applications/application.rb +1 -1
  113. data/lib/puppet/module_tool/applications/generator.rb +2 -1
  114. data/lib/puppet/module_tool/applications/installer.rb +9 -4
  115. data/lib/puppet/module_tool/applications/uninstaller.rb +10 -7
  116. data/lib/puppet/module_tool/applications/unpacker.rb +1 -1
  117. data/lib/puppet/module_tool/applications/upgrader.rb +11 -8
  118. data/lib/puppet/module_tool/checksums.rb +1 -1
  119. data/lib/puppet/module_tool/contents_description.rb +2 -0
  120. data/lib/puppet/module_tool/dependency.rb +4 -5
  121. data/lib/puppet/module_tool/errors.rb +2 -0
  122. data/lib/puppet/module_tool/install_directory.rb +3 -0
  123. data/lib/puppet/module_tool/metadata.rb +3 -5
  124. data/lib/puppet/module_tool/modulefile.rb +3 -0
  125. data/lib/puppet/module_tool/shared_behaviors.rb +6 -1
  126. data/lib/puppet/module_tool/skeleton.rb +3 -0
  127. data/lib/puppet/module_tool/tar.rb +3 -0
  128. data/lib/puppet/network/auth_config_parser.rb +1 -1
  129. data/lib/puppet/network/authconfig.rb +5 -2
  130. data/lib/puppet/network/authentication.rb +7 -2
  131. data/lib/puppet/network/authorization.rb +2 -2
  132. data/lib/puppet/network/format_support.rb +4 -0
  133. data/lib/puppet/network/formats.rb +9 -14
  134. data/lib/puppet/network/http.rb +11 -0
  135. data/lib/puppet/network/http/api.rb +0 -2
  136. data/lib/puppet/network/http/api/v1.rb +146 -11
  137. data/lib/puppet/network/http/api/v2.rb +32 -0
  138. data/lib/puppet/network/http/api/v2/authorization.rb +13 -0
  139. data/lib/puppet/network/http/api/v2/environments.rb +21 -0
  140. data/lib/puppet/network/http/connection.rb +94 -37
  141. data/lib/puppet/network/http/error.rb +69 -0
  142. data/lib/puppet/network/http/handler.rb +28 -196
  143. data/lib/puppet/network/http/issues.rb +9 -0
  144. data/lib/puppet/network/http/memory_response.rb +13 -0
  145. data/lib/puppet/network/http/rack/rest.rb +10 -18
  146. data/lib/puppet/network/http/request.rb +56 -0
  147. data/lib/puppet/network/http/response.rb +11 -0
  148. data/lib/puppet/network/http/route.rb +91 -0
  149. data/lib/puppet/network/http/webrick.rb +1 -1
  150. data/lib/puppet/network/http/webrick/rest.rb +7 -12
  151. data/lib/puppet/network/http_pool.rb +3 -3
  152. data/lib/puppet/network/rights.rb +4 -4
  153. data/lib/puppet/node.rb +23 -14
  154. data/lib/puppet/node/environment.rb +149 -125
  155. data/lib/puppet/node/facts.rb +6 -5
  156. data/lib/puppet/parameter.rb +1 -1
  157. data/lib/puppet/parser/ast.rb +1 -1
  158. data/lib/puppet/parser/ast/block_expression.rb +1 -6
  159. data/lib/puppet/parser/ast/collexpr.rb +54 -2
  160. data/lib/puppet/parser/ast/lambda.rb +9 -0
  161. data/lib/puppet/parser/ast/leaf.rb +15 -0
  162. data/lib/puppet/parser/ast/pops_bridge.rb +168 -0
  163. data/lib/puppet/parser/code_merger.rb +13 -0
  164. data/lib/puppet/parser/collector.rb +1 -1
  165. data/lib/puppet/parser/compiler.rb +28 -30
  166. data/lib/puppet/parser/e4_parser_adapter.rb +81 -0
  167. data/lib/puppet/parser/e_parser_adapter.rb +0 -1
  168. data/lib/puppet/parser/files.rb +12 -7
  169. data/lib/puppet/parser/functions.rb +36 -29
  170. data/lib/puppet/parser/functions/collect.rb +1 -1
  171. data/lib/puppet/parser/functions/defined.rb +40 -16
  172. data/lib/puppet/parser/functions/each.rb +55 -41
  173. data/lib/puppet/parser/functions/epp.rb +41 -0
  174. data/lib/puppet/parser/functions/extlookup.rb +2 -2
  175. data/lib/puppet/parser/functions/file.rb +1 -1
  176. data/lib/puppet/parser/functions/filter.rb +68 -16
  177. data/lib/puppet/parser/functions/generate.rb +1 -1
  178. data/lib/puppet/parser/functions/include.rb +3 -2
  179. data/lib/puppet/parser/functions/inline_epp.rb +79 -0
  180. data/lib/puppet/parser/functions/inline_template.rb +1 -1
  181. data/lib/puppet/parser/functions/lookup.rb +127 -27
  182. data/lib/puppet/parser/functions/map.rb +64 -12
  183. data/lib/puppet/parser/functions/reduce.rb +40 -16
  184. data/lib/puppet/parser/functions/select.rb +1 -1
  185. data/lib/puppet/parser/functions/slice.rb +42 -23
  186. data/lib/puppet/parser/grammar.ra +3 -0
  187. data/lib/puppet/parser/lexer.rb +10 -9
  188. data/lib/puppet/parser/parser.rb +15 -12
  189. data/lib/puppet/parser/parser_factory.rb +26 -1
  190. data/lib/puppet/parser/parser_support.rb +13 -4
  191. data/lib/puppet/parser/resource.rb +1 -1
  192. data/lib/puppet/parser/scope.rb +246 -97
  193. data/lib/puppet/parser/templatewrapper.rb +1 -1
  194. data/lib/puppet/parser/type_loader.rb +13 -2
  195. data/lib/puppet/pops.rb +15 -1
  196. data/lib/puppet/pops/adapters.rb +64 -32
  197. data/lib/puppet/pops/binder/binder.rb +122 -150
  198. data/lib/puppet/pops/binder/binder_issues.rb +1 -21
  199. data/lib/puppet/pops/binder/bindings_checker.rb +0 -20
  200. data/lib/puppet/pops/binder/bindings_composer.rb +4 -70
  201. data/lib/puppet/pops/binder/bindings_factory.rb +16 -58
  202. data/lib/puppet/pops/binder/bindings_label_provider.rb +0 -3
  203. data/lib/puppet/pops/binder/bindings_loader.rb +13 -4
  204. data/lib/puppet/pops/binder/bindings_model.rb +17 -31
  205. data/lib/puppet/pops/binder/bindings_model_dumper.rb +2 -20
  206. data/lib/puppet/pops/binder/config/binder_config.rb +8 -40
  207. data/lib/puppet/pops/binder/config/binder_config_checker.rb +2 -43
  208. data/lib/puppet/pops/binder/config/issues.rb +1 -21
  209. data/lib/puppet/pops/binder/injector.rb +86 -7
  210. data/lib/puppet/pops/binder/injector_entry.rb +6 -2
  211. data/lib/puppet/pops/binder/key_factory.rb +7 -1
  212. data/lib/puppet/pops/binder/lookup.rb +191 -0
  213. data/lib/puppet/pops/binder/producers.rb +5 -5
  214. data/lib/puppet/pops/binder/scheme_handler/symbolic_scheme.rb +2 -3
  215. data/lib/puppet/pops/binder/system_bindings.rb +4 -16
  216. data/lib/puppet/pops/containment.rb +72 -5
  217. data/lib/puppet/pops/evaluator/access_operator.rb +548 -0
  218. data/lib/puppet/pops/evaluator/closure.rb +57 -0
  219. data/lib/puppet/pops/evaluator/compare_operator.rb +168 -0
  220. data/lib/puppet/pops/evaluator/epp_evaluator.rb +87 -0
  221. data/lib/puppet/pops/evaluator/evaluator_impl.rb +1069 -0
  222. data/lib/puppet/pops/evaluator/external_syntax_support.rb +49 -0
  223. data/lib/puppet/pops/evaluator/relationship_operator.rb +156 -0
  224. data/lib/puppet/pops/evaluator/runtime3_support.rb +489 -0
  225. data/lib/puppet/pops/issue_reporter.rb +8 -4
  226. data/lib/puppet/pops/issues.rb +199 -4
  227. data/lib/puppet/pops/label_provider.rb +5 -0
  228. data/lib/puppet/pops/model/ast_transformer.rb +55 -31
  229. data/lib/puppet/pops/model/ast_tree_dumper.rb +9 -1
  230. data/lib/puppet/pops/model/factory.rb +265 -111
  231. data/lib/puppet/pops/model/model.rb +179 -140
  232. data/lib/puppet/pops/model/model_label_provider.rb +38 -9
  233. data/lib/puppet/pops/model/model_tree_dumper.rb +38 -13
  234. data/lib/puppet/pops/parser/code_merger.rb +17 -0
  235. data/lib/puppet/pops/parser/egrammar.ra +110 -61
  236. data/lib/puppet/pops/parser/eparser.rb +1415 -1092
  237. data/lib/puppet/pops/parser/epp_parser.rb +51 -0
  238. data/lib/puppet/pops/parser/epp_support.rb +247 -0
  239. data/lib/puppet/pops/parser/evaluating_parser.rb +53 -15
  240. data/lib/puppet/pops/parser/heredoc_support.rb +139 -0
  241. data/lib/puppet/pops/parser/interpolation_support.rb +227 -0
  242. data/lib/puppet/pops/parser/lexer.rb +83 -192
  243. data/lib/puppet/pops/parser/lexer2.rb +684 -0
  244. data/lib/puppet/pops/parser/lexer_support.rb +107 -0
  245. data/lib/puppet/pops/parser/locatable.rb +23 -0
  246. data/lib/puppet/pops/parser/locator.rb +291 -0
  247. data/lib/puppet/pops/parser/makefile +1 -8
  248. data/lib/puppet/pops/parser/parser_support.rb +76 -48
  249. data/lib/puppet/pops/parser/slurp_support.rb +95 -0
  250. data/lib/puppet/pops/patterns.rb +13 -4
  251. data/lib/puppet/pops/types/class_loader.rb +2 -2
  252. data/lib/puppet/pops/types/enumeration.rb +34 -0
  253. data/lib/puppet/pops/types/type_calculator.rb +983 -58
  254. data/lib/puppet/pops/types/type_factory.rb +203 -15
  255. data/lib/puppet/pops/types/type_parser.rb +355 -12
  256. data/lib/puppet/pops/types/types.rb +314 -24
  257. data/lib/puppet/pops/utils.rb +23 -7
  258. data/lib/puppet/pops/validation.rb +14 -8
  259. data/lib/puppet/pops/validation/checker3_1.rb +17 -12
  260. data/lib/puppet/pops/validation/checker4_0.rb +514 -0
  261. data/lib/puppet/pops/validation/validator_factory_4_0.rb +31 -0
  262. data/lib/puppet/pops/visitor.rb +146 -4
  263. data/lib/puppet/property.rb +1 -1
  264. data/lib/puppet/property/ensure.rb +1 -1
  265. data/lib/puppet/provider.rb +47 -26
  266. data/lib/puppet/provider/aixobject.rb +3 -3
  267. data/lib/puppet/provider/augeas/augeas.rb +11 -11
  268. data/lib/puppet/provider/cron/crontab.rb +10 -1
  269. data/lib/puppet/provider/exec.rb +1 -1
  270. data/lib/puppet/provider/exec/posix.rb +1 -1
  271. data/lib/puppet/provider/exec/windows.rb +1 -1
  272. data/lib/puppet/provider/file/posix.rb +2 -2
  273. data/lib/puppet/provider/file/windows.rb +15 -9
  274. data/lib/puppet/provider/group/aix.rb +2 -2
  275. data/lib/puppet/provider/macauthorization/macauthorization.rb +3 -3
  276. data/lib/puppet/provider/mount.rb +7 -0
  277. data/lib/puppet/provider/mount/parsed.rb +0 -1
  278. data/lib/puppet/provider/naginator.rb +1 -1
  279. data/lib/puppet/provider/nameservice.rb +3 -3
  280. data/lib/puppet/provider/nameservice/directoryservice.rb +3 -3
  281. data/lib/puppet/provider/package/aix.rb +1 -1
  282. data/lib/puppet/provider/package/appdmg.rb +1 -4
  283. data/lib/puppet/provider/package/apple.rb +1 -1
  284. data/lib/puppet/provider/package/apt.rb +1 -1
  285. data/lib/puppet/provider/package/blastwave.rb +1 -1
  286. data/lib/puppet/provider/package/fink.rb +1 -1
  287. data/lib/puppet/provider/package/gem.rb +3 -3
  288. data/lib/puppet/provider/package/openbsd.rb +6 -4
  289. data/lib/puppet/provider/package/pacman.rb +58 -5
  290. data/lib/puppet/provider/package/pip.rb +2 -2
  291. data/lib/puppet/provider/package/pkgdmg.rb +25 -10
  292. data/lib/puppet/provider/package/pkgin.rb +48 -23
  293. data/lib/puppet/provider/package/pkgutil.rb +1 -1
  294. data/lib/puppet/provider/package/ports.rb +1 -1
  295. data/lib/puppet/provider/package/portupgrade.rb +7 -7
  296. data/lib/puppet/provider/package/rpm.rb +16 -8
  297. data/lib/puppet/provider/package/windows.rb +1 -1
  298. data/lib/puppet/provider/package/windows/package.rb +1 -1
  299. data/lib/puppet/provider/parsedfile.rb +1 -1
  300. data/lib/puppet/provider/selboolean/getsetsebool.rb +1 -1
  301. data/lib/puppet/provider/selmodule/semodule.rb +5 -5
  302. data/lib/puppet/provider/service/base.rb +1 -1
  303. data/lib/puppet/provider/service/bsd.rb +3 -3
  304. data/lib/puppet/provider/service/daemontools.rb +20 -20
  305. data/lib/puppet/provider/service/debian.rb +1 -1
  306. data/lib/puppet/provider/service/freebsd.rb +3 -3
  307. data/lib/puppet/provider/service/gentoo.rb +2 -2
  308. data/lib/puppet/provider/service/init.rb +5 -5
  309. data/lib/puppet/provider/service/launchd.rb +4 -4
  310. data/lib/puppet/provider/service/redhat.rb +2 -2
  311. data/lib/puppet/provider/service/runit.rb +4 -4
  312. data/lib/puppet/provider/service/service.rb +3 -4
  313. data/lib/puppet/provider/service/smf.rb +1 -1
  314. data/lib/puppet/provider/service/src.rb +3 -3
  315. data/lib/puppet/provider/service/systemd.rb +4 -4
  316. data/lib/puppet/provider/service/upstart.rb +22 -7
  317. data/lib/puppet/provider/service/windows.rb +7 -7
  318. data/lib/puppet/provider/ssh_authorized_key/parsed.rb +3 -3
  319. data/lib/puppet/provider/user/aix.rb +5 -5
  320. data/lib/puppet/provider/user/directoryservice.rb +8 -5
  321. data/lib/puppet/provider/user/ldap.rb +1 -1
  322. data/lib/puppet/provider/user/pw.rb +1 -1
  323. data/lib/puppet/provider/user/user_role_add.rb +2 -2
  324. data/lib/puppet/provider/user/useradd.rb +19 -5
  325. data/lib/puppet/provider/yumrepo/inifile.rb +187 -0
  326. data/lib/puppet/provider/zone/solaris.rb +4 -4
  327. data/lib/puppet/rails.rb +16 -11
  328. data/lib/puppet/rails/benchmark.rb +1 -1
  329. data/lib/puppet/rails/resource.rb +5 -1
  330. data/lib/puppet/reference/configuration.rb +1 -1
  331. data/lib/puppet/reference/report.rb +1 -1
  332. data/lib/puppet/relationship.rb +10 -5
  333. data/lib/puppet/reports/http.rb +8 -2
  334. data/lib/puppet/reports/rrdgraph.rb +1 -1
  335. data/lib/puppet/reports/store.rb +3 -3
  336. data/lib/puppet/reports/tagmail.rb +4 -4
  337. data/lib/puppet/resource.rb +37 -44
  338. data/lib/puppet/resource/catalog.rb +18 -20
  339. data/lib/puppet/resource/status.rb +7 -6
  340. data/lib/puppet/resource/type.rb +6 -5
  341. data/lib/puppet/resource/type_collection.rb +2 -2
  342. data/lib/puppet/run.rb +9 -8
  343. data/lib/puppet/settings.rb +395 -244
  344. data/lib/puppet/settings/base_setting.rb +10 -4
  345. data/lib/puppet/settings/config_file.rb +81 -44
  346. data/lib/puppet/settings/directory_setting.rb +1 -2
  347. data/lib/puppet/settings/file_setting.rb +12 -5
  348. data/lib/puppet/settings/ini_file.rb +171 -0
  349. data/lib/puppet/ssl/base.rb +4 -0
  350. data/lib/puppet/ssl/certificate_authority.rb +16 -11
  351. data/lib/puppet/ssl/certificate_authority/interface.rb +3 -2
  352. data/lib/puppet/ssl/certificate_factory.rb +50 -5
  353. data/lib/puppet/ssl/certificate_request.rb +2 -2
  354. data/lib/puppet/ssl/certificate_request_attributes.rb +1 -1
  355. data/lib/puppet/ssl/certificate_revocation_list.rb +3 -1
  356. data/lib/puppet/ssl/host.rb +9 -8
  357. data/lib/puppet/ssl/inventory.rb +1 -1
  358. data/lib/puppet/ssl/key.rb +1 -1
  359. data/lib/puppet/ssl/validator/default_validator.rb +1 -1
  360. data/lib/puppet/status.rb +8 -7
  361. data/lib/puppet/test/test_helper.rb +35 -4
  362. data/lib/puppet/transaction/event.rb +6 -5
  363. data/lib/puppet/transaction/report.rb +10 -10
  364. data/lib/puppet/type.rb +1 -3
  365. data/lib/puppet/type/augeas.rb +2 -1
  366. data/lib/puppet/type/cron.rb +41 -11
  367. data/lib/puppet/type/exec.rb +5 -5
  368. data/lib/puppet/type/file.rb +42 -4
  369. data/lib/puppet/type/file/content.rb +5 -6
  370. data/lib/puppet/type/file/ensure.rb +3 -3
  371. data/lib/puppet/type/file/source.rb +12 -6
  372. data/lib/puppet/type/file/target.rb +5 -5
  373. data/lib/puppet/type/k5login.rb +4 -4
  374. data/lib/puppet/type/mount.rb +1 -1
  375. data/lib/puppet/type/package.rb +79 -3
  376. data/lib/puppet/type/resources.rb +34 -5
  377. data/lib/puppet/type/selboolean.rb +1 -1
  378. data/lib/puppet/type/selmodule.rb +1 -1
  379. data/lib/puppet/type/ssh_authorized_key.rb +2 -1
  380. data/lib/puppet/type/sshkey.rb +2 -1
  381. data/lib/puppet/type/tidy.rb +1 -1
  382. data/lib/puppet/type/user.rb +4 -1
  383. data/lib/puppet/type/yumrepo.rb +219 -344
  384. data/lib/puppet/type/zone.rb +15 -5
  385. data/lib/puppet/util.rb +14 -13
  386. data/lib/puppet/util/adsi.rb +19 -3
  387. data/lib/puppet/util/autoload.rb +27 -24
  388. data/lib/puppet/util/backups.rb +6 -6
  389. data/lib/puppet/util/checksums.rb +2 -2
  390. data/lib/puppet/util/classgen.rb +1 -1
  391. data/lib/puppet/util/colors.rb +4 -12
  392. data/lib/puppet/util/command_line.rb +2 -2
  393. data/lib/puppet/util/command_line/trollop.rb +3 -3
  394. data/lib/puppet/util/docs.rb +2 -2
  395. data/lib/puppet/util/errors.rb +8 -1
  396. data/lib/puppet/util/execution.rb +12 -5
  397. data/lib/puppet/util/filetype.rb +5 -5
  398. data/lib/puppet/util/inifile.rb +19 -4
  399. data/lib/puppet/util/instrumentation/data.rb +5 -0
  400. data/lib/puppet/util/instrumentation/indirection_probe.rb +6 -1
  401. data/lib/puppet/util/instrumentation/listener.rb +6 -1
  402. data/lib/puppet/util/json_lockfile.rb +4 -1
  403. data/lib/puppet/util/ldap/connection.rb +1 -1
  404. data/lib/puppet/util/lockfile.rb +10 -6
  405. data/lib/puppet/util/log.rb +6 -1
  406. data/lib/puppet/util/log/destinations.rb +2 -2
  407. data/lib/puppet/util/metric.rb +9 -4
  408. data/lib/puppet/util/nagios_maker.rb +26 -1
  409. data/lib/puppet/util/network_device.rb +1 -1
  410. data/lib/puppet/util/network_device/config.rb +1 -1
  411. data/lib/puppet/util/network_device/transport/ssh.rb +3 -3
  412. data/lib/puppet/util/plugins.rb +1 -1
  413. data/lib/puppet/util/profiler.rb +13 -1
  414. data/lib/puppet/util/pson.rb +1 -1
  415. data/lib/puppet/util/queue/stomp.rb +2 -2
  416. data/lib/puppet/util/rdoc.rb +1 -1
  417. data/lib/puppet/util/rdoc/generators/puppet_generator.rb +1 -1
  418. data/lib/puppet/util/rdoc/parser/puppet_parser_core.rb +19 -19
  419. data/lib/puppet/util/reference.rb +1 -1
  420. data/lib/puppet/util/resource_template.rb +1 -1
  421. data/lib/puppet/util/retryaction.rb +1 -1
  422. data/lib/puppet/util/selinux.rb +2 -2
  423. data/lib/puppet/util/storage.rb +3 -3
  424. data/lib/puppet/util/symbolic_file_mode.rb +1 -1
  425. data/lib/puppet/util/tag_set.rb +15 -3
  426. data/lib/puppet/util/tagging.rb +12 -17
  427. data/lib/puppet/util/watched_file.rb +1 -1
  428. data/lib/puppet/util/watcher.rb +1 -1
  429. data/lib/puppet/util/windows/error.rb +2 -2
  430. data/lib/puppet/util/windows/file.rb +20 -4
  431. data/lib/puppet/util/windows/registry.rb +2 -2
  432. data/lib/puppet/vendor/safe_yaml/CHANGES.md +1 -1
  433. data/lib/puppet/version.rb +1 -1
  434. data/lib/puppetx.rb +1 -21
  435. data/lib/puppetx/puppet/syntax_checker.rb +1 -1
  436. data/lib/puppetx/puppetlabs/syntax_checkers/json.rb +9 -11
  437. data/spec/fixtures/integration/node/environment/sitedir/00_a.pp +2 -0
  438. data/spec/fixtures/integration/node/environment/sitedir/01_b.pp +6 -0
  439. data/spec/fixtures/{unit/pops/binder/hiera2/yaml_backend/empty/common.yaml → integration/node/environment/sitedir/03_empty.pp} +0 -0
  440. data/spec/fixtures/integration/node/environment/sitedir/04_include.pp +2 -0
  441. data/spec/fixtures/integration/provider/cron/crontab/purged +8 -0
  442. data/spec/fixtures/releases/jamtur01-apache/lib/puppet/provider/a2mod/debian.rb +1 -1
  443. data/spec/fixtures/unit/pops/binder/bindings_composer/ok/binder_config.yaml +3 -12
  444. data/spec/fixtures/unit/pops/binder/bindings_composer/ok/lib/puppet/bindings/confdirtest.rb +10 -0
  445. data/spec/fixtures/unit/pops/binder/bindings_composer/ok/modules/awesome2/lib/puppet/bindings/awesome2/default.rb +20 -0
  446. data/spec/fixtures/unit/pops/binder/bindings_composer/ok/modules/{awesome/lib/puppetx/awesome → awesome2/lib/puppetx/awesome2}/echo_scheme_handler.rb +2 -2
  447. data/spec/fixtures/unit/pops/binder/bindings_composer/ok/modules/bad/lib/puppet/bindings/bad/default.rb +5 -0
  448. data/spec/fixtures/unit/pops/binder/bindings_composer/ok/modules/good/lib/puppet/bindings/good/default.rb +6 -0
  449. data/spec/fixtures/unit/pops/binder/config/binder_config/ok/binder_config.yaml +2 -2
  450. data/spec/fixtures/unit/provider/service/systemd/{list_units → list_units_services} +0 -1
  451. data/spec/integration/agent/logging_spec.rb +1 -1
  452. data/spec/integration/application/apply_spec.rb +78 -3
  453. data/spec/integration/application/doc_spec.rb +3 -2
  454. data/spec/integration/configurer_spec.rb +5 -3
  455. data/spec/integration/directory_environments_spec.rb +50 -0
  456. data/spec/integration/indirector/direct_file_server_spec.rb +1 -1
  457. data/spec/integration/indirector/file_content/file_server_spec.rb +4 -5
  458. data/spec/integration/network/authconfig_spec.rb +4 -4
  459. data/spec/integration/network/formats_spec.rb +1 -1
  460. data/spec/integration/node/environment_spec.rb +67 -15
  461. data/spec/integration/node/facts_spec.rb +1 -1
  462. data/spec/integration/node_spec.rb +1 -1
  463. data/spec/integration/parser/catalog_spec.rb +100 -60
  464. data/spec/integration/parser/compiler_spec.rb +102 -13
  465. data/spec/integration/parser/future_compiler_spec.rb +416 -0
  466. data/spec/integration/parser/parser_spec.rb +44 -105
  467. data/spec/integration/parser/scope_spec.rb +614 -528
  468. data/spec/integration/provider/cron/crontab_spec.rb +21 -0
  469. data/spec/integration/provider/mount_spec.rb +15 -2
  470. data/spec/integration/resource/catalog_spec.rb +1 -1
  471. data/spec/integration/resource/type_collection_spec.rb +3 -4
  472. data/spec/integration/ssl/autosign_spec.rb +1 -1
  473. data/spec/integration/ssl/certificate_revocation_list_spec.rb +1 -1
  474. data/spec/integration/ssl/host_spec.rb +1 -1
  475. data/spec/integration/transaction_spec.rb +13 -13
  476. data/spec/integration/type/exec_spec.rb +2 -2
  477. data/spec/integration/type/file_spec.rb +114 -41
  478. data/spec/integration/type/nagios_spec.rb +80 -0
  479. data/spec/integration/type/tidy_spec.rb +2 -2
  480. data/spec/integration/util/execution_spec.rb +17 -0
  481. data/spec/integration/util/rdoc/parser_spec.rb +1 -1
  482. data/spec/integration/util/settings_spec.rb +1 -1
  483. data/spec/integration/util/windows/security_spec.rb +27 -2
  484. data/spec/lib/matchers/include.rb +27 -0
  485. data/spec/lib/matchers/include_spec.rb +32 -0
  486. data/spec/lib/matchers/json.rb +135 -79
  487. data/spec/lib/matchers/match_tokens2.rb +74 -0
  488. data/spec/lib/matchers/resource.rb +35 -0
  489. data/spec/lib/puppet/indirector/indirector_testing/memory.rb +7 -0
  490. data/spec/lib/puppet/indirector/indirector_testing/msgpack.rb +6 -0
  491. data/spec/lib/puppet/indirector_testing.rb +12 -2
  492. data/spec/lib/puppet_spec/files.rb +1 -0
  493. data/spec/lib/puppet_spec/matchers.rb +5 -0
  494. data/spec/lib/puppet_spec/modules.rb +1 -1
  495. data/spec/lib/puppet_spec/scope.rb +14 -0
  496. data/spec/shared_behaviours/file_server_terminus.rb +2 -2
  497. data/spec/spec_helper.rb +47 -17
  498. data/spec/unit/agent_spec.rb +8 -1
  499. data/spec/unit/application/agent_spec.rb +5 -4
  500. data/spec/unit/application/apply_spec.rb +34 -15
  501. data/spec/unit/application/device_spec.rb +27 -32
  502. data/spec/unit/application/doc_spec.rb +4 -4
  503. data/spec/unit/application/filebucket_spec.rb +1 -1
  504. data/spec/unit/application/master_spec.rb +2 -2
  505. data/spec/unit/application_spec.rb +1 -1
  506. data/spec/unit/configurer/downloader_spec.rb +1 -1
  507. data/spec/unit/configurer/fact_handler_spec.rb +5 -16
  508. data/spec/unit/configurer_spec.rb +2 -2
  509. data/spec/unit/confine/exists_spec.rb +5 -5
  510. data/spec/unit/context/trusted_information_spec.rb +124 -0
  511. data/spec/unit/context_spec.rb +74 -0
  512. data/spec/unit/environments_spec.rb +126 -0
  513. data/spec/unit/face/config_spec.rb +31 -16
  514. data/spec/unit/face/module/build_spec.rb +1 -0
  515. data/spec/unit/face/module/install_spec.rb +21 -104
  516. data/spec/unit/face/module/list_spec.rb +52 -36
  517. data/spec/unit/face/module/uninstall_spec.rb +18 -25
  518. data/spec/unit/face/parser_spec.rb +39 -23
  519. data/spec/unit/file_bucket/dipper_spec.rb +2 -2
  520. data/spec/unit/file_serving/base_spec.rb +9 -13
  521. data/spec/unit/file_serving/configuration/parser_spec.rb +8 -2
  522. data/spec/unit/file_serving/configuration_spec.rb +7 -7
  523. data/spec/unit/file_serving/content_spec.rb +7 -12
  524. data/spec/unit/file_serving/fileset_spec.rb +49 -53
  525. data/spec/unit/file_serving/metadata_spec.rb +83 -32
  526. data/spec/unit/file_serving/mount/file_spec.rb +10 -10
  527. data/spec/unit/file_system/tempfile_spec.rb +3 -3
  528. data/spec/unit/file_system_spec.rb +508 -0
  529. data/spec/unit/forge/errors_spec.rb +1 -1
  530. data/spec/unit/forge/repository_spec.rb +1 -3
  531. data/spec/unit/hiera/scope_spec.rb +6 -2
  532. data/spec/unit/hiera_puppet_spec.rb +13 -6
  533. data/spec/unit/indirector/catalog/msgpack_spec.rb +12 -0
  534. data/spec/unit/indirector/catalog/static_compiler_spec.rb +42 -11
  535. data/spec/unit/indirector/direct_file_server_spec.rb +6 -6
  536. data/spec/unit/indirector/facts/facter_spec.rb +5 -5
  537. data/spec/unit/indirector/file_bucket_file/file_spec.rb +4 -4
  538. data/spec/unit/indirector/file_metadata/file_spec.rb +2 -2
  539. data/spec/unit/indirector/file_server_spec.rb +4 -4
  540. data/spec/unit/indirector/json_spec.rb +6 -6
  541. data/spec/unit/indirector/key/file_spec.rb +8 -8
  542. data/spec/unit/indirector/msgpack_spec.rb +191 -0
  543. data/spec/unit/indirector/node/active_record_spec.rb +1 -1
  544. data/spec/unit/indirector/node/ldap_spec.rb +16 -7
  545. data/spec/unit/indirector/node/msgpack_spec.rb +24 -0
  546. data/spec/unit/indirector/node/plain_spec.rb +1 -1
  547. data/spec/unit/indirector/queue_spec.rb +1 -1
  548. data/spec/unit/indirector/report/msgpack_spec.rb +28 -0
  549. data/spec/unit/indirector/request_spec.rb +16 -8
  550. data/spec/unit/indirector/rest_spec.rb +0 -4
  551. data/spec/unit/indirector/ssl_file_spec.rb +12 -11
  552. data/spec/unit/indirector/yaml_spec.rb +4 -4
  553. data/spec/unit/man_spec.rb +32 -0
  554. data/spec/unit/module_spec.rb +60 -46
  555. data/spec/unit/module_tool/applications/checksummer_spec.rb +1 -1
  556. data/spec/unit/module_tool/applications/installer_spec.rb +53 -16
  557. data/spec/unit/module_tool/applications/uninstaller_spec.rb +26 -25
  558. data/spec/unit/module_tool/tar_spec.rb +1 -1
  559. data/spec/unit/module_tool_spec.rb +17 -90
  560. data/spec/unit/network/authconfig_spec.rb +3 -4
  561. data/spec/unit/network/authentication_spec.rb +20 -6
  562. data/spec/unit/network/authorization_spec.rb +11 -1
  563. data/spec/unit/network/formats_spec.rb +32 -9
  564. data/spec/unit/network/http/api/v1_spec.rb +365 -62
  565. data/spec/unit/network/http/api/v2/authorization_spec.rb +57 -0
  566. data/spec/unit/network/http/api/v2/environments_spec.rb +42 -0
  567. data/spec/unit/network/http/api/v2_spec.rb +14 -0
  568. data/spec/unit/network/http/connection_spec.rb +39 -5
  569. data/spec/unit/network/http/error_spec.rb +30 -0
  570. data/spec/unit/network/http/handler_spec.rb +69 -419
  571. data/spec/unit/network/http/rack/rest_spec.rb +20 -28
  572. data/spec/unit/network/http/route_spec.rb +75 -0
  573. data/spec/unit/network/http/webrick/rest_spec.rb +21 -58
  574. data/spec/unit/network/http_pool_spec.rb +3 -3
  575. data/spec/unit/network/rights_spec.rb +2 -2
  576. data/spec/unit/node/environment_spec.rb +108 -89
  577. data/spec/unit/node/facts_spec.rb +5 -12
  578. data/spec/unit/node_spec.rb +22 -22
  579. data/spec/unit/parser/ast/collection_spec.rb +1 -1
  580. data/spec/unit/parser/ast/leaf_spec.rb +2 -0
  581. data/spec/unit/parser/ast/resource_spec.rb +1 -1
  582. data/spec/unit/parser/compiler_spec.rb +5 -3
  583. data/spec/unit/parser/files_spec.rb +40 -50
  584. data/spec/unit/parser/functions/defined_spec.rb +80 -18
  585. data/spec/unit/parser/functions/epp_spec.rb +88 -0
  586. data/spec/unit/parser/functions/fqdn_rand_spec.rb +4 -1
  587. data/spec/unit/parser/functions/generate_spec.rb +6 -2
  588. data/spec/unit/parser/functions/hiera_array_spec.rb +5 -2
  589. data/spec/unit/parser/functions/hiera_hash_spec.rb +4 -1
  590. data/spec/unit/parser/functions/hiera_include_spec.rb +6 -3
  591. data/spec/unit/parser/functions/hiera_spec.rb +5 -2
  592. data/spec/unit/parser/functions/include_spec.rb +0 -1
  593. data/spec/unit/parser/functions/inline_epp_spec.rb +82 -0
  594. data/spec/unit/parser/functions/lookup_spec.rb +66 -16
  595. data/spec/unit/parser/functions_spec.rb +25 -91
  596. data/spec/unit/parser/lexer_spec.rb +1 -1
  597. data/spec/unit/parser/methods/filter_spec.rb +56 -0
  598. data/spec/unit/parser/methods/map_spec.rb +94 -5
  599. data/spec/unit/parser/methods/reduce_spec.rb +10 -0
  600. data/spec/unit/parser/methods/shared.rb +2 -18
  601. data/spec/unit/parser/methods/slice_spec.rb +39 -1
  602. data/spec/unit/parser/parser_spec.rb +14 -10
  603. data/spec/unit/parser/resource_spec.rb +3 -9
  604. data/spec/unit/parser/scope_spec.rb +81 -78
  605. data/spec/unit/parser/type_loader_spec.rb +0 -4
  606. data/spec/unit/pops/benchmark_spec.rb +142 -0
  607. data/spec/unit/pops/binder/binder_spec.rb +15 -34
  608. data/spec/unit/pops/binder/bindings_checker_spec.rb +0 -41
  609. data/spec/unit/pops/binder/bindings_composer_spec.rb +6 -31
  610. data/spec/unit/pops/binder/config/binder_config_spec.rb +5 -18
  611. data/spec/unit/pops/binder/injector_spec.rb +76 -81
  612. data/spec/unit/pops/evaluator/access_ops_spec.rb +376 -0
  613. data/spec/unit/pops/evaluator/arithmetic_ops_spec.rb +77 -0
  614. data/spec/unit/pops/evaluator/basic_expressions_spec.rb +103 -0
  615. data/spec/unit/pops/evaluator/collections_ops_spec.rb +111 -0
  616. data/spec/unit/pops/evaluator/comparison_ops_spec.rb +256 -0
  617. data/spec/unit/pops/evaluator/conditionals_spec.rb +190 -0
  618. data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +1045 -0
  619. data/spec/unit/pops/evaluator/evaluator_rspec_helper.rb +75 -0
  620. data/spec/unit/pops/evaluator/logical_ops_spec.rb +90 -0
  621. data/spec/unit/pops/evaluator/string_interpolation_spec.rb +44 -0
  622. data/spec/unit/pops/evaluator/variables_spec.rb +194 -0
  623. data/spec/unit/pops/factory_spec.rb +6 -29
  624. data/spec/unit/pops/issues_spec.rb +1 -1
  625. data/spec/unit/pops/model/ast_transformer_spec.rb +6 -9
  626. data/spec/unit/pops/model/model_spec.rb +2 -2
  627. data/spec/unit/pops/parser/epp_parser_spec.rb +86 -0
  628. data/spec/unit/pops/parser/evaluating_parser_spec.rb +4 -2
  629. data/spec/unit/pops/parser/lexer2_spec.rb +428 -0
  630. data/spec/unit/pops/parser/lexer_spec.rb +25 -86
  631. data/spec/unit/pops/parser/parse_basic_expressions_spec.rb +29 -4
  632. data/spec/unit/pops/parser/parse_calls_spec.rb +10 -6
  633. data/spec/unit/pops/parser/parse_conditionals_spec.rb +0 -9
  634. data/spec/unit/pops/parser/parse_containers_spec.rb +43 -12
  635. data/spec/unit/pops/parser/parse_heredoc_spec.rb +73 -0
  636. data/spec/unit/pops/parser/parse_resource_spec.rb +14 -0
  637. data/spec/unit/pops/parser/parser_spec.rb +3 -1
  638. data/spec/unit/pops/transformer/transform_basic_expressions_spec.rb +4 -4
  639. data/spec/unit/pops/transformer/transform_calls_spec.rb +41 -6
  640. data/spec/unit/pops/transformer/transform_conditionals_spec.rb +0 -9
  641. data/spec/unit/pops/transformer/transform_containers_spec.rb +12 -4
  642. data/spec/unit/pops/types/enumeration_spec.rb +50 -0
  643. data/spec/unit/pops/types/type_calculator_spec.rb +1171 -196
  644. data/spec/unit/pops/types/type_factory_spec.rb +108 -4
  645. data/spec/unit/pops/types/type_parser_spec.rb +114 -10
  646. data/spec/unit/pops/validator/validator_spec.rb +36 -1
  647. data/spec/unit/provider/augeas/augeas_spec.rb +39 -16
  648. data/spec/unit/provider/cron/parsed_spec.rb +27 -31
  649. data/spec/unit/provider/file/posix_spec.rb +2 -2
  650. data/spec/unit/provider/group/windows_adsi_spec.rb +1 -0
  651. data/spec/unit/provider/mount_spec.rb +12 -1
  652. data/spec/unit/provider/nameservice/directoryservice_spec.rb +3 -3
  653. data/spec/unit/provider/package/apt_spec.rb +1 -1
  654. data/spec/unit/provider/package/aptrpm_spec.rb +1 -1
  655. data/spec/unit/provider/package/gem_spec.rb +12 -0
  656. data/spec/unit/provider/package/msi_spec.rb +4 -0
  657. data/spec/unit/provider/package/openbsd_spec.rb +10 -10
  658. data/spec/unit/provider/package/pacman_spec.rb +36 -7
  659. data/spec/unit/provider/package/pkgin_spec.rb +57 -55
  660. data/spec/unit/provider/package/rpm_spec.rb +51 -6
  661. data/spec/unit/provider/service/base_spec.rb +4 -4
  662. data/spec/unit/provider/service/daemontools_spec.rb +8 -13
  663. data/spec/unit/provider/service/freebsd_spec.rb +3 -3
  664. data/spec/unit/provider/service/gentoo_spec.rb +24 -24
  665. data/spec/unit/provider/service/init_spec.rb +15 -15
  666. data/spec/unit/provider/service/openbsd_spec.rb +16 -16
  667. data/spec/unit/provider/service/openrc_spec.rb +20 -20
  668. data/spec/unit/provider/service/openwrt_spec.rb +1 -1
  669. data/spec/unit/provider/service/runit_spec.rb +5 -8
  670. data/spec/unit/provider/service/src_spec.rb +4 -4
  671. data/spec/unit/provider/service/systemd_spec.rb +24 -14
  672. data/spec/unit/provider/service/upstart_spec.rb +12 -4
  673. data/spec/unit/provider/service/windows_spec.rb +1 -1
  674. data/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +21 -23
  675. data/spec/unit/provider/user/directoryservice_spec.rb +7 -7
  676. data/spec/unit/provider/user/useradd_spec.rb +43 -15
  677. data/spec/unit/provider/user/windows_adsi_spec.rb +1 -0
  678. data/spec/unit/provider/yumrepo/inifile_spec.rb +105 -0
  679. data/spec/unit/provider/zone/solaris_spec.rb +1 -1
  680. data/spec/unit/provider_spec.rb +120 -62
  681. data/spec/unit/rails/host_spec.rb +1 -1
  682. data/spec/unit/rails/param_value_spec.rb +4 -0
  683. data/spec/unit/relationship_spec.rb +4 -4
  684. data/spec/unit/reports/http_spec.rb +14 -3
  685. data/spec/unit/reports/rrdgraph_spec.rb +0 -1
  686. data/spec/unit/reports/store_spec.rb +2 -2
  687. data/spec/unit/resource/catalog_spec.rb +17 -29
  688. data/spec/unit/resource/status_spec.rb +1 -1
  689. data/spec/unit/resource/type_collection_spec.rb +28 -47
  690. data/spec/unit/resource/type_spec.rb +12 -23
  691. data/spec/unit/resource_spec.rb +54 -93
  692. data/spec/unit/run_spec.rb +3 -3
  693. data/spec/unit/settings/autosign_setting_spec.rb +1 -1
  694. data/spec/unit/settings/config_file_spec.rb +68 -15
  695. data/spec/unit/settings/file_setting_spec.rb +2 -2
  696. data/spec/unit/settings/ini_file_spec.rb +184 -0
  697. data/spec/unit/settings_spec.rb +137 -79
  698. data/spec/unit/ssl/certificate_authority/interface_spec.rb +3 -1
  699. data/spec/unit/ssl/certificate_authority_spec.rb +11 -9
  700. data/spec/unit/ssl/certificate_factory_spec.rb +19 -4
  701. data/spec/unit/ssl/certificate_request_attributes_spec.rb +1 -1
  702. data/spec/unit/ssl/certificate_revocation_list_spec.rb +101 -72
  703. data/spec/unit/ssl/host_spec.rb +8 -20
  704. data/spec/unit/ssl/inventory_spec.rb +2 -2
  705. data/spec/unit/ssl/key_spec.rb +4 -4
  706. data/spec/unit/status_spec.rb +6 -4
  707. data/spec/unit/transaction/additional_resource_generator_spec.rb +3 -11
  708. data/spec/unit/transaction/event_spec.rb +2 -2
  709. data/spec/unit/transaction/report_spec.rb +24 -15
  710. data/spec/unit/transaction/resource_harness_spec.rb +1 -1
  711. data/spec/unit/type/cron_spec.rb +39 -1
  712. data/spec/unit/type/file/content_spec.rb +4 -5
  713. data/spec/unit/type/file/ctime_spec.rb +1 -1
  714. data/spec/unit/type/file/mode_spec.rb +5 -4
  715. data/spec/unit/type/file/mtime_spec.rb +1 -1
  716. data/spec/unit/type/file/source_spec.rb +30 -7
  717. data/spec/unit/type/file_spec.rb +8 -8
  718. data/spec/unit/type/k5login_spec.rb +3 -3
  719. data/spec/unit/type/nagios_spec.rb +6 -0
  720. data/spec/unit/type/package/package_settings_spec.rb +135 -0
  721. data/spec/unit/type/package_spec.rb +13 -1
  722. data/spec/unit/type/resources_spec.rb +155 -0
  723. data/spec/unit/type/service_spec.rb +3 -3
  724. data/spec/unit/type/ssh_authorized_key_spec.rb +96 -93
  725. data/spec/unit/type/sshkey_spec.rb +39 -30
  726. data/spec/unit/type/tidy_spec.rb +19 -12
  727. data/spec/unit/type/user_spec.rb +47 -2
  728. data/spec/unit/type/whit_spec.rb +2 -2
  729. data/spec/unit/type/yumrepo_spec.rb +32 -177
  730. data/spec/unit/type/zone_spec.rb +2 -2
  731. data/spec/unit/type_spec.rb +11 -0
  732. data/spec/unit/util/adsi_spec.rb +48 -1
  733. data/spec/unit/util/autoload_spec.rb +24 -39
  734. data/spec/unit/util/backups_spec.rb +25 -28
  735. data/spec/unit/util/checksums_spec.rb +1 -3
  736. data/spec/unit/util/colors_spec.rb +14 -0
  737. data/spec/unit/util/docs_spec.rb +9 -0
  738. data/spec/unit/util/execution_spec.rb +1 -1
  739. data/spec/unit/util/filetype_spec.rb +7 -7
  740. data/spec/unit/util/instrumentation/data_spec.rb +3 -1
  741. data/spec/unit/util/instrumentation/indirection_probe_spec.rb +2 -0
  742. data/spec/unit/util/instrumentation/listener_spec.rb +3 -2
  743. data/spec/unit/util/json_lockfile_spec.rb +25 -4
  744. data/spec/unit/util/lockfile_spec.rb +49 -7
  745. data/spec/unit/util/log/destinations_spec.rb +1 -0
  746. data/spec/unit/util/log_spec.rb +1 -1
  747. data/spec/unit/util/metric_spec.rb +1 -1
  748. data/spec/unit/util/pidlock_spec.rb +6 -6
  749. data/spec/unit/util/pson_spec.rb +2 -2
  750. data/spec/unit/util/rdoc/parser_spec.rb +32 -29
  751. data/spec/unit/util/resource_template_spec.rb +3 -3
  752. data/spec/unit/util/selinux_spec.rb +5 -5
  753. data/spec/unit/util/storage_spec.rb +4 -4
  754. data/spec/unit/util/tag_set_spec.rb +1 -1
  755. data/spec/unit/util/watcher_spec.rb +1 -4
  756. data/spec/unit/util/yaml_spec.rb +2 -2
  757. data/spec/unit/util_spec.rb +7 -7
  758. data/tasks/benchmark.rake +0 -1
  759. data/tasks/parallel.rake +408 -0
  760. data/tasks/yard.rake +59 -0
  761. metadata +2889 -2782
  762. checksums.yaml +0 -7
  763. data/README_DEVELOPER.md +0 -809
  764. data/lib/puppet/file_system/file.rb +0 -271
  765. data/lib/puppet/network/http/rack/httphandler.rb +0 -13
  766. data/lib/puppet/pops/binder/hiera2.rb +0 -10
  767. data/lib/puppet/pops/binder/hiera2/bindings_provider.rb +0 -148
  768. data/lib/puppet/pops/binder/hiera2/config.rb +0 -69
  769. data/lib/puppet/pops/binder/hiera2/config_checker.rb +0 -68
  770. data/lib/puppet/pops/binder/hiera2/diagnostic_producer.rb +0 -36
  771. data/lib/puppet/pops/binder/hiera2/issues.rb +0 -67
  772. data/lib/puppet/pops/binder/hiera2/json_backend.rb +0 -18
  773. data/lib/puppet/pops/binder/hiera2/yaml_backend.rb +0 -21
  774. data/lib/puppet/pops/binder/scheme_handler/confdir_hiera_scheme.rb +0 -67
  775. data/lib/puppet/pops/binder/scheme_handler/module_hiera_scheme.rb +0 -92
  776. data/lib/puppet/pops/parser/grammar.ra +0 -746
  777. data/lib/puppet/provider/port/parsed.rb +0 -173
  778. data/lib/puppet/type/port.rb +0 -119
  779. data/lib/puppetx/puppet/hiera2_backend.rb +0 -31
  780. data/spec/fixtures/unit/pops/binder/bindings_composer/hiera1config/binder_config.yaml +0 -18
  781. data/spec/fixtures/unit/pops/binder/bindings_composer/hiera1config/hiera.yaml +0 -8
  782. data/spec/fixtures/unit/pops/binder/bindings_composer/hiera1config/modules/good/common.yaml +0 -1
  783. data/spec/fixtures/unit/pops/binder/bindings_composer/hiera1config/modules/good/hiera.yaml +0 -10
  784. data/spec/fixtures/unit/pops/binder/bindings_composer/ok/common.yaml +0 -1
  785. data/spec/fixtures/unit/pops/binder/bindings_composer/ok/hiera.yaml +0 -11
  786. data/spec/fixtures/unit/pops/binder/bindings_composer/ok/localhost.yaml +0 -1
  787. data/spec/fixtures/unit/pops/binder/bindings_composer/ok/modules/awesome/common.yaml +0 -3
  788. data/spec/fixtures/unit/pops/binder/bindings_composer/ok/modules/awesome/hiera.yaml +0 -13
  789. data/spec/fixtures/unit/pops/binder/bindings_composer/ok/modules/awesome/lib/puppet/bindings/awesome/default.rb +0 -4
  790. data/spec/fixtures/unit/pops/binder/bindings_composer/ok/modules/awesome/lib/puppetx/awesome/echo_backend.rb +0 -11
  791. data/spec/fixtures/unit/pops/binder/bindings_composer/ok/modules/awesome/localhost.yaml +0 -1
  792. data/spec/fixtures/unit/pops/binder/bindings_composer/ok/modules/bad/common.yaml +0 -3
  793. data/spec/fixtures/unit/pops/binder/bindings_composer/ok/modules/bad/hiera_config.yaml +0 -9
  794. data/spec/fixtures/unit/pops/binder/bindings_composer/ok/modules/good/common.yaml +0 -2
  795. data/spec/fixtures/unit/pops/binder/bindings_composer/ok/modules/good/hiera.yaml +0 -11
  796. data/spec/fixtures/unit/pops/binder/hiera2/bindings_provider/ok/hiera.yaml +0 -9
  797. data/spec/fixtures/unit/pops/binder/hiera2/bindings_provider/ok/node.example.com.json +0 -9
  798. data/spec/fixtures/unit/pops/binder/hiera2/bindings_provider/ok/node.example.com.yaml +0 -5
  799. data/spec/fixtures/unit/pops/binder/hiera2/config/bad_syntax/hiera.yaml +0 -10
  800. data/spec/fixtures/unit/pops/binder/hiera2/config/malformed_hierarchy/hiera.yaml +0 -8
  801. data/spec/fixtures/unit/pops/binder/hiera2/config/missing/foo.txt +0 -1
  802. data/spec/fixtures/unit/pops/binder/hiera2/config/no_backends/hiera.yaml +0 -7
  803. data/spec/fixtures/unit/pops/binder/hiera2/config/no_hierarchy/hiera.yaml +0 -4
  804. data/spec/fixtures/unit/pops/binder/hiera2/config/not_a_hash/hiera.yaml +0 -2
  805. data/spec/fixtures/unit/pops/binder/hiera2/config/ok/hiera.yaml +0 -8
  806. data/spec/fixtures/unit/pops/binder/hiera2/yaml_backend/invalid/common.yaml +0 -1
  807. data/spec/fixtures/unit/pops/binder/hiera2/yaml_backend/ok/common.yaml +0 -2
  808. data/spec/unit/file_system/file_spec.rb +0 -486
  809. data/spec/unit/pops/binder/hiera2/bindings_provider_spec.rb +0 -74
  810. data/spec/unit/pops/binder/hiera2/config_spec.rb +0 -61
  811. data/spec/unit/pops/binder/hiera2/yaml_backend_spec.rb +0 -33
@@ -0,0 +1,684 @@
1
+ # The Lexer is responsbile for turning source text into tokens.
2
+ # This version is a performance enhanced lexer (in comparison to the 3.x and earlier "future parser" lexer.
3
+ #
4
+ # Old returns tokens [:KEY, value, { locator = }
5
+ # Could return [[token], locator]
6
+ # or Token.new([token], locator) with the same API x[0] = token_symbol, x[1] = self, x[:key] = (:value, :file, :line, :pos) etc
7
+
8
+ require 'strscan'
9
+ require 'puppet/pops/parser/lexer_support'
10
+ require 'puppet/pops/parser/heredoc_support'
11
+ require 'puppet/pops/parser/interpolation_support'
12
+ require 'puppet/pops/parser/epp_support'
13
+ require 'puppet/pops/parser/slurp_support'
14
+
15
+ class Puppet::Pops::Parser::Lexer2
16
+ include Puppet::Pops::Parser::LexerSupport
17
+ include Puppet::Pops::Parser::HeredocSupport
18
+ include Puppet::Pops::Parser::InterpolationSupport
19
+ include Puppet::Pops::Parser::SlurpSupport
20
+ include Puppet::Pops::Parser::EppSupport
21
+
22
+ # ALl tokens have three slots, the token name (a Symbol), the token text (String), and a token text length.
23
+ # All operator and punctuation tokens reuse singleton arrays Tokens that require unique values create
24
+ # a unique array per token.
25
+ #
26
+ # PEFORMANCE NOTES:
27
+ # This construct reduces the amount of object that needs to be created for operators and punctuation.
28
+ # The length is pre-calculated for all singleton tokens. The length is used both to signal the length of
29
+ # the token, and to advance the scanner position (without having to advance it with a scan(regexp)).
30
+ #
31
+ TOKEN_LBRACK = [:LBRACK, '['.freeze, 1].freeze
32
+ TOKEN_LISTSTART = [:LISTSTART, '['.freeze, 1].freeze
33
+ TOKEN_RBRACK = [:RBRACK, ']'.freeze, 1].freeze
34
+ TOKEN_LBRACE = [:LBRACE, '{'.freeze, 1].freeze
35
+ TOKEN_RBRACE = [:RBRACE, '}'.freeze, 1].freeze
36
+ TOKEN_SELBRACE = [:SELBRACE, '{'.freeze, 1].freeze
37
+ TOKEN_LPAREN = [:LPAREN, '('.freeze, 1].freeze
38
+ TOKEN_RPAREN = [:RPAREN, ')'.freeze, 1].freeze
39
+
40
+ TOKEN_EQUALS = [:EQUALS, '='.freeze, 1].freeze
41
+ TOKEN_APPENDS = [:APPENDS, '+='.freeze, 2].freeze
42
+ TOKEN_DELETES = [:DELETES, '-='.freeze, 2].freeze
43
+
44
+ TOKEN_ISEQUAL = [:ISEQUAL, '=='.freeze, 2].freeze
45
+ TOKEN_NOTEQUAL = [:NOTEQUAL, '!='.freeze, 2].freeze
46
+ TOKEN_MATCH = [:MATCH, '=~'.freeze, 2].freeze
47
+ TOKEN_NOMATCH = [:NOMATCH, '!~'.freeze, 2].freeze
48
+ TOKEN_GREATEREQUAL = [:GREATEREQUAL, '>='.freeze, 2].freeze
49
+ TOKEN_GREATERTHAN = [:GREATERTHAN, '>'.freeze, 1].freeze
50
+ TOKEN_LESSEQUAL = [:LESSEQUAL, '<='.freeze, 2].freeze
51
+ TOKEN_LESSTHAN = [:LESSTHAN, '<'.freeze, 1].freeze
52
+
53
+ TOKEN_FARROW = [:FARROW, '=>'.freeze, 2].freeze
54
+ TOKEN_PARROW = [:PARROW, '+>'.freeze, 2].freeze
55
+
56
+ TOKEN_LSHIFT = [:LSHIFT, '<<'.freeze, 2].freeze
57
+ TOKEN_LLCOLLECT = [:LLCOLLECT, '<<|'.freeze, 3].freeze
58
+ TOKEN_LCOLLECT = [:LCOLLECT, '<|'.freeze, 2].freeze
59
+
60
+ TOKEN_RSHIFT = [:RSHIFT, '>>'.freeze, 2].freeze
61
+ TOKEN_RRCOLLECT = [:RRCOLLECT, '|>>'.freeze, 3].freeze
62
+ TOKEN_RCOLLECT = [:RCOLLECT, '|>'.freeze, 2].freeze
63
+
64
+ TOKEN_PLUS = [:PLUS, '+'.freeze, 1].freeze
65
+ TOKEN_MINUS = [:MINUS, '-'.freeze, 1].freeze
66
+ TOKEN_DIV = [:DIV, '/'.freeze, 1].freeze
67
+ TOKEN_TIMES = [:TIMES, '*'.freeze, 1].freeze
68
+ TOKEN_MODULO = [:MODULO, '%'.freeze, 1].freeze
69
+
70
+ TOKEN_NOT = [:NOT, '!'.freeze, 1].freeze
71
+ TOKEN_DOT = [:DOT, '.'.freeze, 1].freeze
72
+ TOKEN_PIPE = [:PIPE, '|'.freeze, 1].freeze
73
+ TOKEN_AT = [:AT , '@'.freeze, 1].freeze
74
+ TOKEN_ATAT = [:ATAT , '@@'.freeze, 2].freeze
75
+ TOKEN_COLON = [:COLON, ':'.freeze, 1].freeze
76
+ TOKEN_COMMA = [:COMMA, ','.freeze, 1].freeze
77
+ TOKEN_SEMIC = [:SEMIC, ';'.freeze, 1].freeze
78
+ TOKEN_QMARK = [:QMARK, '?'.freeze, 1].freeze
79
+ TOKEN_TILDE = [:TILDE, '~'.freeze, 1].freeze # lexed but not an operator in Puppet
80
+
81
+ TOKEN_REGEXP = [:REGEXP, nil, 0].freeze
82
+
83
+ TOKEN_IN_EDGE = [:IN_EDGE, '->'.freeze, 2].freeze
84
+ TOKEN_IN_EDGE_SUB = [:IN_EDGE_SUB, '~>'.freeze, 2].freeze
85
+ TOKEN_OUT_EDGE = [:OUT_EDGE, '<-'.freeze, 2].freeze
86
+ TOKEN_OUT_EDGE_SUB = [:OUT_EDGE_SUB, '<~'.freeze, 2].freeze
87
+
88
+ # Tokens that are always unique to what has been lexed
89
+ TOKEN_STRING = [:STRING, nil, 0].freeze
90
+ TOKEN_DQPRE = [:DQPRE, nil, 0].freeze
91
+ TOKEN_DQMID = [:DQPRE, nil, 0].freeze
92
+ TOKEN_DQPOS = [:DQPRE, nil, 0].freeze
93
+ TOKEN_NUMBER = [:NUMBER, nil, 0].freeze
94
+ TOKEN_VARIABLE = [:VARIABLE, nil, 1].freeze
95
+ TOKEN_VARIABLE_EMPTY = [:VARIABLE, ''.freeze, 1].freeze
96
+
97
+ # HEREDOC has syntax as an argument.
98
+ TOKEN_HEREDOC = [:HEREDOC, nil, 0].freeze
99
+
100
+ # EPP_START is currently a marker token, may later get syntax
101
+ TOKEN_EPPSTART = [:EPP_START, nil, 0].freeze
102
+ TOKEN_EPPEND = [:EPP_END, '%>', 2].freeze
103
+ TOKEN_EPPEND_TRIM = [:EPP_END_TRIM, '-%>', 3].freeze
104
+
105
+ # This is used for unrecognized tokens, will always be a single character. This particular instance
106
+ # is not used, but is kept here for documentation purposes.
107
+ TOKEN_OTHER = [:OTHER, nil, 0]
108
+
109
+ # Keywords are all singleton tokens with pre calculated lengths.
110
+ # Booleans are pre-calculated (rather than evaluating the strings "false" "true" repeatedly.
111
+ #
112
+ KEYWORDS = {
113
+ "case" => [:CASE, 'case', 4],
114
+ "class" => [:CLASS, 'class', 5],
115
+ "default" => [:DEFAULT, 'default', 7],
116
+ "define" => [:DEFINE, 'define', 6],
117
+ "if" => [:IF, 'if', 2],
118
+ "elsif" => [:ELSIF, 'elsif', 5],
119
+ "else" => [:ELSE, 'else', 4],
120
+ "inherits" => [:INHERITS,'inherits', 8],
121
+ "node" => [:NODE, 'node', 4],
122
+ "and" => [:AND, 'and', 3],
123
+ "or" => [:OR, 'or', 2],
124
+ "undef" => [:UNDEF, 'undef', 5],
125
+ "false" => [:BOOLEAN, false, 5],
126
+ "true" => [:BOOLEAN, true, 4],
127
+ "in" => [:IN, 'in', 2],
128
+ "unless" => [:UNLESS, 'unless', 6],
129
+ }
130
+ KEYWORDS.each {|k,v| v[1].freeze; v.freeze }
131
+ KEYWORDS.freeze
132
+
133
+ # Reverse lookup of keyword name to string
134
+ KEYWORD_NAMES = {}
135
+ KEYWORDS.each {|k, v| KEYWORD_NAMES[v[0]] = k }
136
+ KEYWORD_NAMES.freeze
137
+
138
+ PATTERN_WS = %r{[[:blank:]\r]+}
139
+
140
+ # The single line comment includes the line ending.
141
+ PATTERN_COMMENT = %r{#.*\r?}
142
+ PATTERN_MLCOMMENT = %r{/\*(.*?)\*/}m
143
+
144
+ PATTERN_REGEX = %r{/[^/\n]*/}
145
+ PATTERN_REGEX_END = %r{/}
146
+ PATTERN_REGEX_A = %r{\A/} # for replacement to ""
147
+ PATTERN_REGEX_Z = %r{/\Z} # for replacement to ""
148
+ PATTERN_REGEX_ESC = %r{\\/} # for replacement to "/"
149
+
150
+ # The 3x patterns:
151
+ # PATTERN_CLASSREF = %r{((::){0,1}[A-Z][-\w]*)+}
152
+ # PATTERN_NAME = %r{((::)?[a-z0-9][-\w]*)(::[a-z0-9][-\w]*)*}
153
+
154
+ # The NAME and CLASSREF in 4x are strict. Each segment must start with
155
+ # a letter a-z and may not contain dashes (\w includes letters, digits and _).
156
+ #
157
+ PATTERN_CLASSREF = %r{((::){0,1}[A-Z][\w]*)+}
158
+ PATTERN_NAME = %r{((::)?[a-z][\w]*)(::[a-z][\w]*)*}
159
+ PATTERN_BARE_WORD = %r{[a-z_](?:[\w-]*[\w])?}
160
+
161
+ PATTERN_DOLLAR_VAR = %r{\$(::)?(\w+::)*\w+}
162
+ PATTERN_NUMBER = %r{\b(?:0[xX][0-9A-Fa-f]+|0?\d+(?:\.\d+)?(?:[eE]-?\d+)?)\b}
163
+
164
+ # PERFORMANCE NOTE:
165
+ # Comparison against a frozen string is faster (than unfrozen).
166
+ #
167
+ STRING_BSLASH_BSLASH = '\\'.freeze
168
+
169
+ attr_reader :locator
170
+
171
+ def initialize()
172
+ end
173
+
174
+ # Clears the lexer state (it is not required to call this as it will be garbage collected
175
+ # and the next lex call (lex_string, lex_file) will reset the internal state.
176
+ #
177
+ def clear()
178
+ # not really needed, but if someone wants to ensure garbage is collected as early as possible
179
+ @scanner = nil
180
+ @locator = nil
181
+ @lexing_context = nil
182
+ end
183
+
184
+ # Convenience method, and for compatibility with older lexer. Use the lex_string instead which allows
185
+ # passing the path to use without first having to call file= (which reads the file if it exists).
186
+ # (Bad form to use overloading of assignment operator for something that is not really an assignment. Also,
187
+ # overloading of = does not allow passing more than one argument).
188
+ #
189
+ def string=(string)
190
+ lex_string(string, '')
191
+ end
192
+
193
+ def lex_string(string, path='')
194
+ initvars
195
+ @scanner = StringScanner.new(string)
196
+ @locator = Puppet::Pops::Parser::Locator.locator(string, path)
197
+ end
198
+
199
+ # Lexes an unquoted string.
200
+ # @param string [String] the string to lex
201
+ # @param locator [Puppet::Pops::Parser::Locator] the locator to use (a default is used if nil is given)
202
+ # @param escapes [Array<String>] array of character strings representing the escape sequences to transform
203
+ # @param interpolate [Boolean] whether interpolation of expressions should be made or not.
204
+ #
205
+ def lex_unquoted_string(string, locator, escapes, interpolate)
206
+ initvars
207
+ @scanner = StringScanner.new(string)
208
+ @locator = locator || Puppet::Pops::Parser::Locator.locator(string, '')
209
+ @lexing_context[:escapes] = escapes || UQ_ESCAPES
210
+ @lexing_context[:uq_slurp_pattern] = (interpolate || !escapes.empty?) ? SLURP_UQ_PATTERN : SLURP_ALL_PATTERN
211
+ end
212
+
213
+ # Convenience method, and for compatibility with older lexer. Use the lex_file instead.
214
+ # (Bad form to use overloading of assignment operator for something that is not really an assignment).
215
+ #
216
+ def file=(file)
217
+ lex_file(file)
218
+ end
219
+
220
+ # TODO: This method should not be used, callers should get the locator since it is most likely required to
221
+ # compute line, position etc given offsets.
222
+ #
223
+ def file
224
+ @locator ? @locator.file : nil
225
+ end
226
+
227
+ # Initializes lexing of the content of the given file. An empty string is used if the file does not exist.
228
+ #
229
+ def lex_file(file)
230
+ initvars
231
+ contents = Puppet::FileSystem.exist?(file) ? Puppet::FileSystem.read(file) : ""
232
+ @scanner = StringScanner.new(contents.freeze)
233
+ @locator = Puppet::Pops::Parser::Locator.locator(contents, file)
234
+ end
235
+
236
+ def initvars
237
+ @token_queue = []
238
+ # NOTE: additional keys are used; :escapes, :uq_slurp_pattern, :newline_jump, :epp_*
239
+ @lexing_context = {
240
+ :brace_count => 0,
241
+ :after => nil,
242
+ }
243
+ end
244
+
245
+ # Scans all of the content and returns it in an array
246
+ # Note that the terminating [false, false] token is included in the result.
247
+ #
248
+ def fullscan
249
+ result = []
250
+ scan {|token, value| result.push([token, value]) }
251
+ result
252
+ end
253
+
254
+ # A block must be passed to scan. It will be called with two arguments, a symbol for the token,
255
+ # and an instance of LexerSupport::TokenValue
256
+ # PERFORMANCE NOTE: The TokenValue is designed to reduce the amount of garbage / temporary data
257
+ # and to only convert the lexer's internal tokens on demand. It is slightly more costly to create an
258
+ # instance of a class defined in Ruby than an Array or Hash, but the gain is much bigger since transformation
259
+ # logic is avoided for many of its members (most are never used (e.g. line/pos information which is only of
260
+ # value in general for error messages, and for some expressions (which the lexer does not know about).
261
+ #
262
+ def scan
263
+ # PERFORMANCE note: it is faster to access local variables than instance variables.
264
+ # This makes a small but notable difference since instance member access is avoided for
265
+ # every token in the lexed content.
266
+ #
267
+ scn = @scanner
268
+ ctx = @lexing_context
269
+ queue = @token_queue
270
+
271
+ lex_error_without_pos("Internal Error: No string or file given to lexer to process.") unless scn
272
+
273
+ scn.skip(PATTERN_WS)
274
+
275
+ # This is the lexer's main loop
276
+ until queue.empty? && scn.eos? do
277
+ if token = queue.shift || lex_token
278
+ yield [ ctx[:after] = token[0], token[1] ]
279
+ end
280
+ end
281
+
282
+ # Signals end of input
283
+ yield [false, false]
284
+ end
285
+
286
+ # This lexes one token at the current position of the scanner.
287
+ # PERFORMANCE NOTE: Any change to this logic should be performance measured.
288
+ #
289
+ def lex_token
290
+ # Using three char look ahead (may be faster to do 2 char look ahead since only 2 tokens require a third
291
+ scn = @scanner
292
+ ctx = @lexing_context
293
+ before = @scanner.pos
294
+
295
+ # A look ahead of 3 characters is used since the longest operator ambiguity is resolved at that point.
296
+ # PERFORMANCE NOTE: It is faster to peek once and use three separate variables for lookahead 0, 1 and 2.
297
+ #
298
+ la = scn.peek(3)
299
+ return nil if la.empty?
300
+
301
+ # Ruby 1.8.7 requires using offset and length (or integers are returned.
302
+ # PERFORMANCE NOTE.
303
+ # It is slightly faster to use these local variables than accessing la[0], la[1] etc. in ruby 1.9.3
304
+ # But not big enough to warrant two completely different implementations.
305
+ #
306
+ la0 = la[0,1]
307
+ la1 = la[1,1]
308
+ la2 = la[2,1]
309
+
310
+ # PERFORMANCE NOTE:
311
+ # A case when, where all the cases are literal values is the fastest way to map from data to code.
312
+ # It is much faster than using a hash with lambdas, hash with symbol used to then invoke send etc.
313
+ # This case statement is evaluated for most character positions in puppet source, and great care must
314
+ # be taken to not introduce performance regressions.
315
+ #
316
+ case la0
317
+
318
+ when '.'
319
+ emit(TOKEN_DOT, before)
320
+
321
+ when ','
322
+ emit(TOKEN_COMMA, before)
323
+
324
+ when '['
325
+ if ctx[:after] == :NAME && (before == 0 || scn.string[before-1,1] =~ /[[:blank:]\r\n]+/)
326
+ emit(TOKEN_LISTSTART, before)
327
+ else
328
+ emit(TOKEN_LBRACK, before)
329
+ end
330
+
331
+ when ']'
332
+ emit(TOKEN_RBRACK, before)
333
+
334
+ when '('
335
+ emit(TOKEN_LPAREN, before)
336
+
337
+ when ')'
338
+ emit(TOKEN_RPAREN, before)
339
+
340
+ when ';'
341
+ emit(TOKEN_SEMIC, before)
342
+
343
+ when '?'
344
+ emit(TOKEN_QMARK, before)
345
+
346
+ when '*'
347
+ emit(TOKEN_TIMES, before)
348
+
349
+ when '%'
350
+ if la1 == '>' && ctx[:epp_mode]
351
+ scn.pos += 2
352
+ if ctx[:epp_mode] == :expr
353
+ enqueue_completed(TOKEN_EPPEND, before)
354
+ end
355
+ ctx[:epp_mode] = :text
356
+ interpolate_epp
357
+ else
358
+ emit(TOKEN_MODULO, before)
359
+ end
360
+
361
+ when '{'
362
+ # The lexer needs to help the parser since the technology used cannot deal with
363
+ # lookahead of same token with different precedence. This is solved by making left brace
364
+ # after ? into a separate token.
365
+ #
366
+ ctx[:brace_count] += 1
367
+ emit(if ctx[:after] == :QMARK
368
+ TOKEN_SELBRACE
369
+ else
370
+ TOKEN_LBRACE
371
+ end, before)
372
+
373
+ when '}'
374
+ ctx[:brace_count] -= 1
375
+ emit(TOKEN_RBRACE, before)
376
+
377
+ # TOKENS @, @@, @(
378
+ when '@'
379
+ case la1
380
+ when '@'
381
+ emit(TOKEN_ATAT, before) # TODO; Check if this is good for the grammar
382
+ when '('
383
+ heredoc
384
+ else
385
+ emit(TOKEN_AT, before)
386
+ end
387
+
388
+ # TOKENS |, |>, |>>
389
+ when '|'
390
+ emit(case la1
391
+ when '>'
392
+ la2 == '>' ? TOKEN_RRCOLLECT : TOKEN_RCOLLECT
393
+ else
394
+ TOKEN_PIPE
395
+ end, before)
396
+
397
+ # TOKENS =, =>, ==, =~
398
+ when '='
399
+ emit(case la1
400
+ when '='
401
+ TOKEN_ISEQUAL
402
+ when '>'
403
+ TOKEN_FARROW
404
+ when '~'
405
+ TOKEN_MATCH
406
+ else
407
+ TOKEN_EQUALS
408
+ end, before)
409
+
410
+ # TOKENS '+', '+=', and '+>'
411
+ when '+'
412
+ emit(case la1
413
+ when '='
414
+ TOKEN_APPENDS
415
+ when '>'
416
+ TOKEN_PARROW
417
+ else
418
+ TOKEN_PLUS
419
+ end, before)
420
+
421
+ # TOKENS '-', '->', and epp '-%>' (end of interpolation with trim)
422
+ when '-'
423
+ if ctx[:epp_mode] && la1 == '%' && la2 == '>'
424
+ scn.pos += 3
425
+ if ctx[:epp_mode] == :expr
426
+ enqueue_completed(TOKEN_EPPEND_TRIM, before)
427
+ end
428
+ interpolate_epp(:with_trim)
429
+ else
430
+ emit(case la1
431
+ when '>'
432
+ TOKEN_IN_EDGE
433
+ when '='
434
+ TOKEN_DELETES
435
+ else
436
+ TOKEN_MINUS
437
+ end, before)
438
+ end
439
+
440
+ # TOKENS !, !=, !~
441
+ when '!'
442
+ emit(case la1
443
+ when '='
444
+ TOKEN_NOTEQUAL
445
+ when '~'
446
+ TOKEN_NOMATCH
447
+ else
448
+ TOKEN_NOT
449
+ end, before)
450
+
451
+ # TOKENS ~>, ~
452
+ when '~'
453
+ emit(la1 == '>' ? TOKEN_IN_EDGE_SUB : TOKEN_TILDE, before)
454
+
455
+ when '#'
456
+ scn.skip(PATTERN_COMMENT)
457
+ nil
458
+
459
+ # TOKENS '/', '/*' and '/ regexp /'
460
+ when '/'
461
+ case la1
462
+ when '*'
463
+ scn.skip(PATTERN_MLCOMMENT)
464
+ nil
465
+
466
+ else
467
+ # regexp position is a regexp, else a div
468
+ if regexp_acceptable? && value = scn.scan(PATTERN_REGEX)
469
+ # Ensure an escaped / was not matched
470
+ while value[-2..-2] == STRING_BSLASH_BSLASH # i.e. \\
471
+ value += scn.scan_until(PATTERN_REGEX_END)
472
+ end
473
+ regex = value.sub(PATTERN_REGEX_A, '').sub(PATTERN_REGEX_Z, '').gsub(PATTERN_REGEX_ESC, '/')
474
+ emit_completed([:REGEX, Regexp.new(regex), scn.pos-before], before)
475
+ else
476
+ emit(TOKEN_DIV, before)
477
+ end
478
+ end
479
+
480
+ # TOKENS <, <=, <|, <<|, <<, <-, <~
481
+ when '<'
482
+ emit(case la1
483
+ when '<'
484
+ if la2 == '|'
485
+ TOKEN_LLCOLLECT
486
+ else
487
+ TOKEN_LSHIFT
488
+ end
489
+ when '='
490
+ TOKEN_LESSEQUAL
491
+ when '|'
492
+ TOKEN_LCOLLECT
493
+ when '-'
494
+ TOKEN_OUT_EDGE
495
+ when '~'
496
+ TOKEN_OUT_EDGE_SUB
497
+ else
498
+ TOKEN_LESSTHAN
499
+ end, before)
500
+
501
+ # TOKENS >, >=, >>
502
+ when '>'
503
+ emit(case la1
504
+ when '>'
505
+ TOKEN_RSHIFT
506
+ when '='
507
+ TOKEN_GREATEREQUAL
508
+ else
509
+ TOKEN_GREATERTHAN
510
+ end, before)
511
+
512
+ # TOKENS :, ::CLASSREF, ::NAME
513
+ when ':'
514
+ if la1 == ':'
515
+ before = scn.pos
516
+ # PERFORMANCE NOTE: This could potentially be speeded up by using a case/when listing all
517
+ # upper case letters. Alternatively, the 'A', and 'Z' comparisons may be faster if they are
518
+ # frozen.
519
+ #
520
+ if la2 >= 'A' && la2 <= 'Z'
521
+ # CLASSREF or error
522
+ value = scn.scan(PATTERN_CLASSREF)
523
+ if value
524
+ after = scn.pos
525
+ emit_completed([:CLASSREF, value, after-before], before)
526
+ else
527
+ # move to faulty position ('::<uc-letter>' was ok)
528
+ scn.pos = scn.pos + 3
529
+ lex_error("Illegal fully qualified class reference")
530
+ end
531
+ else
532
+ # NAME or error
533
+ value = scn.scan(PATTERN_NAME)
534
+ if value
535
+ emit_completed([:NAME, value, scn.pos-before], before)
536
+ else
537
+ # move to faulty position ('::' was ok)
538
+ scn.pos = scn.pos + 2
539
+ lex_error("Illegal fully qualified name")
540
+ end
541
+ end
542
+ else
543
+ emit(TOKEN_COLON, before)
544
+ end
545
+
546
+ when '$'
547
+ if value = scn.scan(PATTERN_DOLLAR_VAR)
548
+ emit_completed([:VARIABLE, value[1..-1], scn.pos - before], before)
549
+ else
550
+ # consume the $ and let higher layer complain about the error instead of getting a syntax error
551
+ emit(TOKEN_VARIABLE_EMPTY, before)
552
+ end
553
+
554
+ when '"'
555
+ # Recursive string interpolation, 'interpolate' either returns a STRING token, or
556
+ # a DQPRE with the rest of the string's tokens placed in the @token_queue
557
+ interpolate_dq
558
+
559
+ when "'"
560
+ emit_completed([:STRING, slurp_sqstring, before-scn.pos], before)
561
+
562
+ when '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
563
+ value = scn.scan(PATTERN_NUMBER)
564
+ if value
565
+ length = scn.pos - before
566
+ assert_numeric(value, length)
567
+ emit_completed([:NUMBER, value, length], before)
568
+ else
569
+ # move to faulty position ([0-9] was ok)
570
+ scn.pos = scn.pos + 1
571
+ lex_error("Illegal number")
572
+ end
573
+
574
+ when 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
575
+ 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
576
+ value = scn.scan(PATTERN_NAME)
577
+ # NAME or false start because followed by hyphen(s) and word
578
+ if value && !scn.match?(/-+\w/)
579
+ emit_completed(KEYWORDS[value] || [:NAME, value, scn.pos - before], before)
580
+ else
581
+ # Restart and check entire pattern (for ease of detecting non allowed trailing hyphen)
582
+ scn.pos = before
583
+ value = scn.scan(PATTERN_BARE_WORD)
584
+ if value
585
+ emit_completed([:STRING, value, scn.pos - before], before)
586
+ else
587
+ # move to faulty position ([a-z] was ok)
588
+ scn.pos = scn.pos + 1
589
+ lex_error("Illegal name")
590
+ end
591
+ end
592
+
593
+ when 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
594
+ 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
595
+ value = scn.scan(PATTERN_CLASSREF)
596
+ if value
597
+ emit_completed([:CLASSREF, value, scn.pos - before], before)
598
+ else
599
+ # move to faulty position ([A-Z] was ok)
600
+ scn.pos = scn.pos + 1
601
+ lex_error("Illegal class reference")
602
+ end
603
+
604
+ when "\n"
605
+ # If heredoc_cont is in effect there are heredoc text lines to skip over
606
+ # otherwise just skip the newline.
607
+ #
608
+ if ctx[:newline_jump]
609
+ scn.pos = ctx[:newline_jump]
610
+ ctx[:newline_jump] = nil
611
+ else
612
+ scn.pos += 1
613
+ end
614
+ return nil
615
+
616
+ when ' ', "\t", "\r"
617
+ scn.skip(PATTERN_WS)
618
+ return nil
619
+
620
+ else
621
+ # In case of unicode spaces of various kinds that are captured by a regexp, but not by the
622
+ # simpler case expression above (not worth handling those special cases with better performance).
623
+ if scn.skip(PATTERN_WS)
624
+ nil
625
+ else
626
+ # "unrecognized char"
627
+ emit([:OTHER, la0, 1], before)
628
+ end
629
+ end
630
+ end
631
+
632
+ # Emits (produces) a token [:tokensymbol, TokenValue] and moves the scanner's position past the token
633
+ #
634
+ def emit(token, byte_offset)
635
+ @scanner.pos = byte_offset + token[2]
636
+ [token[0], TokenValue.new(token, byte_offset, @locator)]
637
+ end
638
+
639
+ # Emits the completed token on the form [:tokensymbol, TokenValue. This method does not alter
640
+ # the scanner's position.
641
+ #
642
+ def emit_completed(token, byte_offset)
643
+ [token[0], TokenValue.new(token, byte_offset, @locator)]
644
+ end
645
+
646
+ # Enqueues a completed token at the given offset
647
+ def enqueue_completed(token, byte_offset)
648
+ @token_queue << emit_completed(token, byte_offset)
649
+ end
650
+
651
+ # Allows subprocessors for heredoc etc to enqueue tokens that are tokenized by a different lexer instance
652
+ #
653
+ def enqueue(emitted_token)
654
+ @token_queue << emitted_token
655
+ end
656
+
657
+ # Answers after which tokens it is acceptable to lex a regular expression.
658
+ # PERFORMANCE NOTE:
659
+ # It may be beneficial to turn this into a hash with default value of true for missing entries.
660
+ # A case expression with literal values will however create a hash internally. Since a reference is
661
+ # always needed to the hash, this access is almost as costly as a method call.
662
+ #
663
+ def regexp_acceptable?
664
+ case @lexing_context[:after]
665
+
666
+ # Ends of (potential) R-value generating expressions
667
+ when :RPAREN, :RBRACK, :RRCOLLECT, :RCOLLECT
668
+ false
669
+
670
+ # End of (potential) R-value - but must be allowed because of case expressions
671
+ # Called out here to not be mistaken for a bug.
672
+ when :RBRACE
673
+ true
674
+
675
+ # Operands (that can be followed by DIV (even if illegal in grammar)
676
+ when :NAME, :CLASSREF, :NUMBER, :STRING, :BOOLEAN, :DQPRE, :DQMID, :DQPOST, :HEREDOC, :REGEX
677
+ false
678
+
679
+ else
680
+ true
681
+ end
682
+ end
683
+
684
+ end