reality-generators 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: af0b6c1e51e95d1a9cf3c1e2862eb73abe78c3c8
4
- data.tar.gz: fc0000f5a449741e6e7e6dfc24780979eaab351a
3
+ metadata.gz: 986819e5e78b30b24221b6bf9339dce933b77437
4
+ data.tar.gz: ee5aab0f511adca821bf40cf246ffe4fb46ba3cc
5
5
  SHA512:
6
- metadata.gz: 2786178f4b984919e553adf443cca95d759c6057ddd7d503a789913d3f23fee55af10c2acce08039f380ed896ef45481b84c111d9d608c37e6184fc9ef773982
7
- data.tar.gz: 7fbbf83ba65738e1ed2836465dfc9ba883d7c464215e7a2bb6ed62778e43e7b93ebf2d0657234382019806da1e04684315ee910709ee7aa0d83488e2affef927
6
+ metadata.gz: 7fe93a2c0dd2543ae99ce2b219749637849d07e4871beaa4847bd39deb05e69960ac42eccbd51245ba27e088841651e987110eaa49b83d887371011c2c78f1b5
7
+ data.tar.gz: cca3b4a84461e2604bcf0196922fc75002389b187b540853e5fb66da67659390e3d39862c327e5d229be44b5734d527415816dac0f60c39efad167957793fbc4
@@ -29,5 +29,6 @@ require 'reality/generators/template_set_container'
29
29
  require 'reality/generators/generator'
30
30
  require 'reality/generators/standard_template_set'
31
31
  require 'reality/generators/standard_artifact_dsl'
32
+ require 'reality/generators/rake_integration'
32
33
 
33
34
  require 'reality/generators/buildr_integration'
@@ -0,0 +1,226 @@
1
+ #
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
+ # you may not use this file except in compliance with the License.
4
+ # You may obtain a copy of the License at
5
+ #
6
+ # http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ # See the License for the specific language governing permissions and
12
+ # limitations under the License.
13
+ #
14
+
15
+ module Reality #nodoc
16
+ module Generators #nodoc
17
+ module Rake #nodoc
18
+
19
+ class BaseGenerateTask
20
+ attr_accessor :description
21
+ attr_accessor :namespace_key
22
+ attr_accessor :filter
23
+ attr_writer :verbose
24
+
25
+ attr_reader :root_element_key
26
+ attr_reader :key
27
+ attr_reader :generator_keys
28
+ attr_reader :target_dir
29
+
30
+ attr_reader :task_name
31
+
32
+ def initialize(root_element_key, key, generator_keys, target_dir, buildr_project = nil)
33
+ @root_element_key = root_element_key
34
+ @key = key
35
+ @generator_keys = generator_keys
36
+ @namespace_key = self.default_namespace_key
37
+ @filter = nil
38
+ @template_map = {}
39
+ # Turn on verbose messages if buildr is turned on tracing
40
+ @verbose = trace?
41
+ @target_dir = target_dir
42
+ yield self if block_given?
43
+ define
44
+ @templates = self.generator_container.generator.load_templates_from_template_sets(generator_keys)
45
+ Reality::Generators::Buildr.configure_buildr_project(buildr_project, task_name, @templates, target_dir)
46
+ end
47
+
48
+ protected
49
+
50
+ def default_namespace_key
51
+ Generators.error('default_namespace_key should be implemented')
52
+ end
53
+
54
+ def generator_container
55
+ Generators.error('generator_container should be implemented')
56
+ end
57
+
58
+ def root_element_type
59
+ Generators.error('root_element_type should be implemented')
60
+ end
61
+
62
+ def log_container
63
+ Generators.error('log_container should be implemented')
64
+ end
65
+
66
+ def instance_container
67
+ Generators.error('instance_container should be implemented')
68
+ end
69
+
70
+ def root_elements_key
71
+ Reality::Naming.pluralize(root_element_type)
72
+ end
73
+
74
+ def validate_root_element(element)
75
+ end
76
+
77
+ def root_element
78
+ element = nil
79
+ if self.root_element_key
80
+ element = self.instance_container.send(:"#{self.root_element_key}_by_name", self.root_element_key)
81
+ if self.instance_container.send(self.root_elements_key).size == 1
82
+ self.log_container.warn("Task #{full_task_name} specifies a #{self.root_element_type}_key parameter but it can be be derived as there is only a single repository. The parameter should be removed.")
83
+ end
84
+ elsif self.root_element_key.nil?
85
+ elements = self.instance_container.send(self.root_elements_key)
86
+ if 1 == elements.size
87
+ element = elements[0]
88
+ else
89
+ self.log_container.error("Task #{full_task_name} does not specify a #{self.root_element_type}_key parameter and it can not be derived. Candidate #{self.root_elements_key} include #{elements.collect { |r| r.name }.inspect}")
90
+ end
91
+ end
92
+
93
+ validate_root_element(element)
94
+
95
+ element
96
+ end
97
+
98
+ private
99
+
100
+ def verbose?
101
+ !!@verbose
102
+ end
103
+
104
+ def full_task_name
105
+ "#{self.namespace_key}:#{self.key}"
106
+ end
107
+
108
+ def define
109
+ desc self.description || "Generates the #{key} artifacts."
110
+ namespace self.namespace_key do
111
+ t = task self.key => ["#{self.namespace_key}:load"] do
112
+ begin
113
+
114
+ Reality::Logging.set_levels(verbose? ? ::Logger::DEBUG : ::Logger::WARN,
115
+ self.log_container.const_get(:Logger),
116
+ Reality::Generators::Logger,
117
+ Reality::Facets::Logger) do
118
+ self.log_container.info "Generator started: Generating #{self.generator_keys.inspect}"
119
+ self.generator_container.generator.
120
+ generate(self.root_element_type, self.root_element, self.target_dir, @templates, self.filter)
121
+ end
122
+ rescue Reality::Generators::GeneratorError => e
123
+ puts e.message
124
+ if e.cause
125
+ puts e.cause.class.name.to_s
126
+ puts e.cause.backtrace.join("\n")
127
+ end
128
+ raise e.message
129
+ end
130
+ end
131
+ @task_name = t.name
132
+ Reality::Generators::Rake::TaskRegistry.get_aggregate_task(self.namespace_key).enhance([t.name])
133
+ end
134
+ end
135
+ end
136
+
137
+ class BaseLoadDescriptor
138
+ attr_accessor :description
139
+ attr_accessor :namespace_key
140
+ attr_writer :verbose
141
+
142
+ attr_reader :filename
143
+
144
+ def initialize(filename)
145
+ @filename = filename
146
+ @namespace_key = self.default_namespace_key
147
+ yield self if block_given?
148
+ define
149
+ end
150
+
151
+ protected
152
+
153
+ def default_namespace_key
154
+ Generators.error('default_namespace_key should be implemented')
155
+ end
156
+
157
+ def log_container
158
+ Generators.error('log_container should be implemented')
159
+ end
160
+
161
+ def pre_load
162
+ end
163
+
164
+ def post_load
165
+ end
166
+
167
+ private
168
+
169
+ def verbose?
170
+ !!@verbose
171
+ end
172
+
173
+ def define
174
+ namespace self.namespace_key do
175
+ task :preload
176
+
177
+ task :postload
178
+
179
+ desc self.description
180
+ task :load => [:preload, self.filename] do
181
+ begin
182
+ self.pre_load
183
+ Reality::Logging.set_levels(verbose? ? ::Logger::DEBUG : ::Logger::WARN,
184
+ self.log_container.const_get(:Logger),
185
+ Reality::Generators::Logger,
186
+ Reality::Facets::Logger) do
187
+
188
+ require self.filename
189
+ end
190
+ rescue Exception => e
191
+ print "An error occurred loading repository\n"
192
+ puts $!
193
+ puts $@
194
+ raise e
195
+ ensure
196
+ self.post_load
197
+ end
198
+ task("#{self.namespace_key}:postload").invoke
199
+ end
200
+ Reality::Generators::Rake::TaskRegistry.get_aggregate_task(self.namespace_key)
201
+ end
202
+ end
203
+ end
204
+
205
+ class TaskRegistry
206
+ class << self
207
+ def get_aggregate_task(namespace)
208
+ all_task = namespace_tasks[namespace.to_s]
209
+ unless all_task
210
+ desc "Generate all #{namespace} artifacts"
211
+ all_task = task('all')
212
+ namespace_tasks[namespace.to_s] = all_task
213
+ end
214
+ all_task
215
+ end
216
+
217
+ private
218
+
219
+ def namespace_tasks
220
+ @namespace_tasks ||= {}
221
+ end
222
+ end
223
+ end
224
+ end
225
+ end
226
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{reality-generators}
5
- s.version = '1.6.0'
5
+ s.version = '1.7.0'
6
6
  s.platform = Gem::Platform::RUBY
7
7
 
8
8
  s.authors = ['Peter Donald']
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
22
22
  s.rdoc_options = %w(--line-numbers --inline-source --title reality-generators)
23
23
 
24
24
  s.add_dependency 'reality-core', '>= 1.7.0'
25
- s.add_dependency 'reality-naming', '>= 1.6.0'
25
+ s.add_dependency 'reality-naming', '>= 1.9.0'
26
26
  s.add_dependency 'reality-orderedhash', '>= 1.0.0'
27
27
 
28
28
  s.add_development_dependency(%q<minitest>, ['= 5.9.1'])
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reality-generators
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Donald
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-28 00:00:00.000000000 Z
11
+ date: 2017-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: reality-core
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 1.6.0
33
+ version: 1.9.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 1.6.0
40
+ version: 1.9.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: reality-orderedhash
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -100,6 +100,7 @@ files:
100
100
  - lib/reality/generators/core.rb
101
101
  - lib/reality/generators/erb_template.rb
102
102
  - lib/reality/generators/generator.rb
103
+ - lib/reality/generators/rake_integration.rb
103
104
  - lib/reality/generators/render_context.rb
104
105
  - lib/reality/generators/ruby_template.rb
105
106
  - lib/reality/generators/standard_artifact_dsl.rb