reality-generators 1.0.0 → 1.1.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: 7679877e032f2d62e74287861197e3bd37f398c6
4
- data.tar.gz: 61eb90fff98fb5be6bf5d44294053130a59b1f37
3
+ metadata.gz: 03bc2bd3ea71e9f986d52a15efa87b778ab98758
4
+ data.tar.gz: e6e5fed040e98cd4584b7a8e9c389b09e7f20a96
5
5
  SHA512:
6
- metadata.gz: 00a7962634b8441945b234bc75b4359143de2997656ada6452216d2df037b6609c6c3b0b1c76e491e676c653de1355d80d79ff9cdb585826c687b0e7633df3ec
7
- data.tar.gz: 9d21cb01a34549f6293a40df37bae961dfd5cd5242df5f8996ca4ffb299a644421f2a6d28cd6a7aa9d5df576b693f2570fdd56d9184a35f46b8caec039fead09
6
+ metadata.gz: bd5609694d0b1cb8d3d9976e2c87de06d4d329deef9e8a0c1e9e458d3d54c1658ba21d387d049f76ab8a1034c9a4994137f2453937d19ce94f82b97cd1a0d9c7
7
+ data.tar.gz: f619d71a563afd4ec8332df622b95bb1fa4eff470fa66eb1dbf87e52079767e2edbb4843e7c16265f5b8cc7dd0fc51a5b9bf4401e0155ae241f9b420d0c0e931
data/.gitignore CHANGED
@@ -6,3 +6,4 @@
6
6
  /patch.diff
7
7
  /pkg
8
8
  /rdoc
9
+ /tmp
@@ -0,0 +1,105 @@
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 Generator
18
+ class << self
19
+ # This method is called from a Rake or Buildr task to configure the Buildr
20
+ # project so that it knows the location of all the generated artifacts and
21
+ # adds them to the appropriate compile paths etc.
22
+ def configure_buildr_project(buildr_project, generator_task, templates, target_dir)
23
+ if buildr_project.nil?
24
+ task('clean') do
25
+ rm_rf target_dir
26
+ end
27
+ else
28
+ buildr_project.clean { rm_rf target_dir }
29
+ file(File.expand_path(target_dir) => [generator_task])
30
+
31
+ # Is there java source generated in project?
32
+ if templates.any? { |template| template.output_path =~ /^main\/java\/.*/ }
33
+ main_java_dir = "#{target_dir}/main/java"
34
+ file(main_java_dir => [generator_task]) do
35
+ mkdir_p main_java_dir
36
+ end
37
+ buildr_project.compile.using :javac
38
+ buildr_project.compile.from main_java_dir
39
+ # Need to force this as it may have already been cached and thus will not recalculate
40
+ buildr_project.iml.main_generated_source_directories << main_java_dir if buildr_project.iml?
41
+ end
42
+
43
+ # Is there resources generated in project?
44
+ if templates.any? { |template| template.output_path =~ /^main\/resources\/.*/ }
45
+ main_resources_dir = "#{target_dir}/main/resources"
46
+ file(main_resources_dir => [generator_task]) do
47
+ mkdir_p main_resources_dir
48
+ end
49
+ buildr_project.resources.enhance([generator_task])
50
+ buildr_project.resources.filter.into buildr_project.path_to(:target, :main, :resources) unless buildr_project.resources.target
51
+ buildr_project.resources do |t|
52
+ t.enhance do
53
+ if File.exist?(main_resources_dir)
54
+ FileUtils.mkdir_p buildr_project.resources.target.to_s
55
+ FileUtils.cp_r "#{main_resources_dir}/.", buildr_project.resources.target.to_s
56
+ end
57
+ end
58
+ end
59
+ buildr_project.iml.main_generated_resource_directories << main_resources_dir if buildr_project.iml?
60
+ end
61
+
62
+ # Is there assets generated in project?
63
+ if templates.any? { |template| template.output_path =~ /^main\/webapp\/.*/ }
64
+ webapp_dir = File.expand_path("#{target_dir}/main/webapp")
65
+ buildr_project.assets.enhance([generator_task])
66
+ buildr_project.assets.paths << file(webapp_dir => [generator_task]) do
67
+ mkdir_p webapp_dir
68
+ end
69
+ end
70
+
71
+ # Is there test java source generated in project?
72
+ if templates.any? { |template| template.output_path =~ /^test\/java\/.*/ }
73
+ test_java_dir = "#{target_dir}/test/java"
74
+ file(test_java_dir => [generator_task]) do
75
+ mkdir_p test_java_dir
76
+ end
77
+ buildr_project.test.compile.from test_java_dir
78
+ # Need to force this as it may have already been cached and thus will not recalculate
79
+ buildr_project.iml.test_generated_source_directories << test_java_dir if buildr_project.iml?
80
+ end
81
+
82
+ # Is there resources generated in project?
83
+ if templates.any? { |template| template.output_path =~ /^test\/resources\/.*/ }
84
+ test_resources_dir = "#{target_dir}/test/resources"
85
+ file(test_resources_dir => [generator_task]) do
86
+ mkdir_p test_resources_dir
87
+ end
88
+ buildr_project.test.resources.enhance([generator_task])
89
+ buildr_project.test.resources.filter.into buildr_project.path_to(:target, :test, :resources) unless buildr_project.test.resources.target
90
+ buildr_project.test.resources do |t|
91
+ t.enhance do
92
+ if File.exist?(test_resources_dir)
93
+ FileUtils.mkdir_p buildr_project.test.resources.target.to_s
94
+ FileUtils.cp_r "#{test_resources_dir}/.", buildr_project.test.resources.target.to_s
95
+ end
96
+ end
97
+ end
98
+ buildr_project.iml.test_generated_resource_directories << test_resources_dir if buildr_project.iml?
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,122 @@
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
+
18
+ module Generator
19
+ class << self
20
+
21
+ # Return a list of templates loaded from specified template_set_keys
22
+ def load_templates_from_template_sets(template_set_container, template_set_keys)
23
+ template_map = {}
24
+ load_templates(template_set_container, template_map, template_set_keys, [])
25
+ template_map.values
26
+ end
27
+
28
+ # Actually perform the generation of files from specified templates.
29
+ # Files are generated to the specified target directory. Any files that
30
+ # are not generated by this process are deleted. The files generated are
31
+ # based on the specified templates.
32
+ # The traversal starts from a root element of specified element_type and
33
+ # traverses all elements that are contained transitively by the root element.
34
+ # The templates then generate files from traversed elements.
35
+ def generate(template_set_container, element_type, element, directory, templates, filter)
36
+ unprocessed_files = (Dir["#{directory}/**/*.*"] + Dir["#{directory}/**/*"]).uniq
37
+
38
+ Generators.debug "Templates to process: #{templates.collect { |t| t.name }.inspect}"
39
+
40
+ targets = {}
41
+ collect_generation_targets(template_set_container, element_type, element, element, targets)
42
+
43
+ templates.each do |template|
44
+ Generators.debug "Evaluating template: #{template.name}"
45
+ elements = targets[template.target]
46
+
47
+ elements.each do |element_pair|
48
+ element = element_pair[1]
49
+ if template.applicable?(element_pair[0]) && (filter.nil? || filter.call(template.target, element))
50
+ template.generate(directory, element, unprocessed_files)
51
+ end
52
+ end if elements
53
+ end
54
+
55
+ unprocessed_files.sort.reverse.each do |file|
56
+ if File.directory?(file)
57
+ if (Dir.entries(file) - %w(. ..)).empty?
58
+ Generators.debug "Removing #{file} as no longer generated"
59
+ FileUtils.rmdir file
60
+ end
61
+ else
62
+ Generators.debug "Removing #{file} as no longer generated"
63
+ FileUtils.rm_f file
64
+ end
65
+ end
66
+
67
+ Generators.info 'Generator completed'
68
+ end
69
+
70
+ private
71
+
72
+ def load_templates(template_set_container, template_map, template_set_keys, processed_template_sets)
73
+ template_set_keys.each do |template_set_key|
74
+ next if processed_template_sets.include?(template_set_key)
75
+ template_set = template_set_container.template_set_by_name(template_set_key)
76
+ processed_template_sets << template_set_key
77
+ load_templates(template_set_container, template_map, template_set.required_template_sets, processed_template_sets)
78
+ template_set.templates.each do |template|
79
+ template_map[template.name] = template
80
+ end
81
+ end
82
+ end
83
+
84
+ # Collect all generation targets. This is a map of type to an array of element pairs of that type.
85
+ # The element pair includes two elements, the "parent" standard element that is facet as per normal
86
+ # and the actual element that is used for generation. The first element is used when checking if
87
+ # element is applicable? to be generated while the second is basis of generation.
88
+ # i.e.
89
+ #
90
+ # {
91
+ # :repository => [ [repository, repository] ],
92
+ # :data_module => [ [module1, module1], [module2, module2]],
93
+ # :entity => [[entity1, entity1], [entity2, entity2]],
94
+ # :'keycloak.client' => [[repository, client]],
95
+ # ...
96
+ # }
97
+ #
98
+ def collect_generation_targets(template_set_container, element_type, scope_element, element, targets)
99
+ (targets[element_type] ||= []) << [scope_element, element]
100
+
101
+ template_set_container.target_manager.targets_by_container(element_type).each do |target|
102
+ subelements = nil
103
+ subscope = nil
104
+ if target.standard?
105
+ subelements = element.send(target.access_method)
106
+ elsif element.facet_enabled?(target.facet_key)
107
+ subelements = element.send(target.facet_key).send(target.access_method)
108
+ subscope = element
109
+ end
110
+
111
+ next unless subelements
112
+ subelements = [subelements] unless subelements.is_a?(Array)
113
+
114
+ subelements.each do |subelement|
115
+ collect_generation_targets(template_set_container, target.qualified_key, subscope || subelement, subelement, targets)
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
@@ -112,7 +112,7 @@ module Reality #nodoc
112
112
  class SingleFileOutputTemplate < Template
113
113
  attr_reader :output_filename_pattern
114
114
 
115
- def initialize(template_set, facets, target, template_key, output_filename_pattern, helpers, options = {})
115
+ def initialize(template_set, facets, target, template_key, output_filename_pattern, helpers = [], options = {})
116
116
  super(template_set, facets, target, template_key, helpers, options)
117
117
  @output_filename_pattern = output_filename_pattern
118
118
  end
@@ -26,3 +26,6 @@ require 'reality/generators/ruby_template'
26
26
  require 'reality/generators/erb_template'
27
27
  require 'reality/generators/template_set'
28
28
  require 'reality/generators/template_set_container'
29
+ require 'reality/generators/generator'
30
+
31
+ require 'reality/generators/buildr_integration'
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{reality-generators}
5
- s.version = '1.0.0'
5
+ s.version = '1.1.0'
6
6
  s.platform = Gem::Platform::RUBY
7
7
 
8
8
  s.authors = ['Peter Donald']
@@ -0,0 +1,280 @@
1
+ require File.expand_path('../../helper', __FILE__)
2
+ require 'date'
3
+
4
+ class Reality::Generators::TestGenerator < Reality::TestCase
5
+
6
+ class Attribute < Reality.base_element(:name => true, :container_key => :entity)
7
+ def qualified_name
8
+ "#{entity.qualified_name}.#{name}"
9
+ end
10
+ end
11
+
12
+ class Entity < Reality.base_element(:name => true, :container_key => :repository)
13
+ def qualified_name
14
+ "#{repository.name}.#{name}"
15
+ end
16
+
17
+ def attribute(name, options = {}, &block)
18
+ attribute_map[name.to_s] = Attribute.new(self, name, options, &block)
19
+ end
20
+
21
+ def attributes
22
+ attribute_map.values
23
+ end
24
+
25
+ def attribute_map
26
+ @attribute_map ||= {}
27
+ end
28
+ end
29
+
30
+ class PersistenceUnit < Reality.base_element(:name => true, :container_key => :jpa_repository)
31
+ end
32
+
33
+ class JpaRepository < Reality.base_element(:container_key => :repository)
34
+
35
+ def unit(name, options = {}, &block)
36
+ unit_map[name.to_s] = PersistenceUnit.new(self, name, options, &block)
37
+ end
38
+
39
+ def units
40
+ unit_map.values
41
+ end
42
+
43
+ def unit_map
44
+ @unit_map ||= {}
45
+ end
46
+ end
47
+
48
+ class Repository < Reality.base_element(:name => true)
49
+ def entity(name, options = {}, &block)
50
+ entity_map[name.to_s] = Entity.new(self, name, options, &block)
51
+ end
52
+
53
+ def entities
54
+ entity_map.values
55
+ end
56
+
57
+ def entity_map
58
+ @entity_map ||= {}
59
+ end
60
+
61
+ def facet_enabled?(facet)
62
+ facet == :jpa ? !!@jpa : false
63
+ end
64
+
65
+ def jpa
66
+ @jpa
67
+ end
68
+
69
+ def enable_jpa!
70
+ @jpa = JpaRepository.new(self)
71
+ end
72
+ end
73
+
74
+ def test_collect_generation_targets
75
+ repository = Repository.new(:MyRepo) do |r|
76
+ r.entity(:MyEntityA) do |e|
77
+ e.attribute(:MyAttr1)
78
+ e.attribute(:MyAttr2)
79
+ end
80
+
81
+ r.entity(:MyEntityB) do |e|
82
+ e.attribute(:MyAttr3)
83
+ e.attribute(:MyAttr4)
84
+ end
85
+ end
86
+
87
+ TestTemplateSetContainer.target_manager.target(:repository)
88
+ TestTemplateSetContainer.target_manager.target(:entity, :repository)
89
+ TestTemplateSetContainer.target_manager.target(:attribute, :entity)
90
+ TestTemplateSetContainer.target_manager.target(:unit, :repository, :facet_key => :jpa)
91
+
92
+ targets = {}
93
+ Reality::Generators::Generator.send(:collect_generation_targets, TestTemplateSetContainer, :repository, repository, repository, targets)
94
+
95
+ assert_equal true, targets.include?(:repository)
96
+ assert_equal true, targets.include?(:entity)
97
+ assert_equal true, targets.include?(:attribute)
98
+ assert_equal 3, targets.size
99
+
100
+ assert_equal 1, targets[:repository].size
101
+ assert_equal 2, targets[:entity].size
102
+ assert_equal 4, targets[:attribute].size
103
+
104
+ assert_equal :MyRepo, targets[:repository][0][0].name
105
+ assert_equal :MyRepo, targets[:repository][0][1].name
106
+ assert_equal 'MyRepo.MyEntityA', targets[:entity][0][0].qualified_name
107
+ assert_equal 'MyRepo.MyEntityA', targets[:entity][0][1].qualified_name
108
+ assert_equal 'MyRepo.MyEntityB', targets[:entity][1][0].qualified_name
109
+ assert_equal 'MyRepo.MyEntityB', targets[:entity][1][1].qualified_name
110
+ assert_equal 'MyRepo.MyEntityA.MyAttr1', targets[:attribute][0][0].qualified_name
111
+ assert_equal 'MyRepo.MyEntityA.MyAttr1', targets[:attribute][0][1].qualified_name
112
+ assert_equal 'MyRepo.MyEntityA.MyAttr2', targets[:attribute][1][0].qualified_name
113
+ assert_equal 'MyRepo.MyEntityA.MyAttr2', targets[:attribute][1][1].qualified_name
114
+ assert_equal 'MyRepo.MyEntityB.MyAttr3', targets[:attribute][2][0].qualified_name
115
+ assert_equal 'MyRepo.MyEntityB.MyAttr3', targets[:attribute][2][1].qualified_name
116
+ assert_equal 'MyRepo.MyEntityB.MyAttr4', targets[:attribute][3][0].qualified_name
117
+ assert_equal 'MyRepo.MyEntityB.MyAttr4', targets[:attribute][3][1].qualified_name
118
+
119
+ repository.enable_jpa!
120
+
121
+ targets = {}
122
+ Reality::Generators::Generator.send(:collect_generation_targets, TestTemplateSetContainer, :repository, repository, repository, targets)
123
+
124
+ # No units have been defined so no extra targets
125
+ assert_equal 3, targets.size
126
+
127
+ repository.jpa.unit(:MyUnit1)
128
+ repository.jpa.unit(:MyUnit2)
129
+
130
+ targets = {}
131
+ Reality::Generators::Generator.send(:collect_generation_targets, TestTemplateSetContainer, :repository, repository, repository, targets)
132
+
133
+ assert_equal true, targets.include?(:repository)
134
+ assert_equal true, targets.include?(:entity)
135
+ assert_equal true, targets.include?(:attribute)
136
+ assert_equal true, targets.include?(:'jpa.unit')
137
+ assert_equal 4, targets.size
138
+
139
+ assert_equal 1, targets[:repository].size
140
+ assert_equal 2, targets[:entity].size
141
+ assert_equal 4, targets[:attribute].size
142
+ assert_equal 2, targets[:'jpa.unit'].size
143
+
144
+ assert_equal :MyRepo, targets[:'jpa.unit'][0][0].name
145
+ assert_equal :MyUnit1, targets[:'jpa.unit'][0][1].name
146
+ assert_equal :MyRepo, targets[:'jpa.unit'][1][0].name
147
+ assert_equal :MyUnit2, targets[:'jpa.unit'][1][1].name
148
+ end
149
+
150
+ class RepositoryTemplate < Reality::Generators::SingleFileOutputTemplate
151
+ def render_to_string(context_binding)
152
+ eval('"Repository: #{repository.name}"', context_binding)
153
+ end
154
+ end
155
+
156
+ class EntityTemplate < Reality::Generators::SingleFileOutputTemplate
157
+ def render_to_string(context_binding)
158
+ eval('"Entity: #{entity.name}"', context_binding)
159
+ end
160
+ end
161
+
162
+ class AttributeTemplate < Reality::Generators::SingleFileOutputTemplate
163
+ def render_to_string(context_binding)
164
+ eval('"Attribute: #{attribute.name}"', context_binding)
165
+ end
166
+ end
167
+
168
+ class UnitTemplate < Reality::Generators::SingleFileOutputTemplate
169
+ def render_to_string(context_binding)
170
+ eval('"Unit: #{unit.name}"', context_binding)
171
+ end
172
+ end
173
+
174
+ def test_generate
175
+ repository = Repository.new(:MyRepo) do |r|
176
+ r.entity(:MyEntityA) do |e|
177
+ e.attribute(:MyAttr1)
178
+ e.attribute(:MyAttr2)
179
+ end
180
+
181
+ r.entity(:MyEntityB) do |e|
182
+ e.attribute(:MyAttr3)
183
+ e.attribute(:MyAttr4)
184
+ end
185
+ end
186
+
187
+ TestTemplateSetContainer.target_manager.target(:repository)
188
+ TestTemplateSetContainer.target_manager.target(:entity, :repository)
189
+ TestTemplateSetContainer.target_manager.target(:attribute, :entity)
190
+ TestTemplateSetContainer.target_manager.target(:unit, :repository, :facet_key => :jpa)
191
+
192
+ template_set = TestTemplateSetContainer.template_set(:test) do |template_set|
193
+ RepositoryTemplate.new(template_set, [], :repository, 'repository.java', 'main/java/#{repository.name}.java')
194
+
195
+ EntityTemplate.new(template_set, [], :entity, 'entity.java', 'main/java/#{entity.qualified_name.gsub(".","/")}.java', [], :guard => 'entity.qualified_name == "MyRepo.MyEntityB"')
196
+ AttributeTemplate.new(template_set, [], :attribute, 'attribute.java', 'main/java/#{attribute.qualified_name.gsub(".","/")}.java')
197
+ UnitTemplate.new(template_set, [], :'jpa.unit', 'unit.java', 'main/java/units/#{unit.name.gsub(".","/")}.java', [], {})
198
+ end
199
+
200
+ target_directory = "#{temp_dir}/generated/erb_template"
201
+
202
+ FileUtils.mkdir_p "#{target_directory}/some/dir/to/delete"
203
+ FileUtils.mkdir_p "#{target_directory}/main/java"
204
+ FileUtils.touch "#{target_directory}/main/java/Touched.java"
205
+ repo_file = "#{target_directory}/main/java/MyRepo.java"
206
+ File.open(repo_file, 'wb') do |f|
207
+ f.write 'Repository: MyRepo'
208
+ end
209
+ File.utime(File.atime(repo_file), DateTime.new(2001, 2, 3).to_time, repo_file)
210
+ original_mtime = File.mtime(repo_file)
211
+
212
+ filter = Proc.new { |artifact_type, artifact| artifact_type != :attribute || %w(MyAttr1 MyAttr2).include?(artifact.name.to_s) }
213
+ Reality::Generators::Generator.
214
+ generate(TestTemplateSetContainer, :repository, repository, target_directory, template_set.templates, filter)
215
+
216
+ assert_equal false, File.directory?("#{target_directory}/some")
217
+ assert_equal false, File.exist?("#{target_directory}/main/java/Touched.java")
218
+ assert_equal true, File.directory?("#{target_directory}/main/java")
219
+ assert_equal true, File.exist?(repo_file)
220
+ assert_equal 'Repository: MyRepo', IO.read(repo_file)
221
+
222
+ # Ensure the file is not updated if contents identical
223
+ assert_equal original_mtime, File.mtime(repo_file)
224
+
225
+ # The guard says no for next element
226
+ assert_equal false, File.exist?("#{target_directory}/main/java/MyRepo/MyEntityA.java")
227
+
228
+ assert_equal true, File.exist?("#{target_directory}/main/java/MyRepo/MyEntityB.java")
229
+ assert_equal 'Entity: MyEntityB', IO.read("#{target_directory}/main/java/MyRepo/MyEntityB.java")
230
+
231
+ assert_equal true, File.exist?("#{target_directory}/main/java/MyRepo/MyEntityA/MyAttr1.java")
232
+ assert_equal 'Attribute: MyAttr1', IO.read("#{target_directory}/main/java/MyRepo/MyEntityA/MyAttr1.java")
233
+
234
+ assert_equal true, File.exist?("#{target_directory}/main/java/MyRepo/MyEntityA/MyAttr2.java")
235
+ assert_equal 'Attribute: MyAttr2', IO.read("#{target_directory}/main/java/MyRepo/MyEntityA/MyAttr2.java")
236
+
237
+ # The filters says no
238
+ assert_equal false, File.exist?("#{target_directory}/main/java/MyRepo/MyEntityB/MyAttr3.java")
239
+ assert_equal false, File.exist?("#{target_directory}/main/java/MyRepo/MyEntityB/MyAttr4.java")
240
+ end
241
+
242
+ def test_load_templates_from_template_sets
243
+
244
+ TestTemplateSetContainer.target_manager.target(:repository)
245
+ TestTemplateSetContainer.target_manager.target(:entity, :repository)
246
+ TestTemplateSetContainer.target_manager.target(:attribute, :entity)
247
+ TestTemplateSetContainer.target_manager.target(:unit, :repository, :facet_key => :jpa)
248
+
249
+ TestTemplateSetContainer.template_set(:template_set_1) do |template_set|
250
+ RepositoryTemplate.new(template_set, [], :repository, 'repository1.java', 'main/java/#{repository.name}1.java')
251
+
252
+ EntityTemplate.new(template_set, [], :entity, 'entity.java', 'main/java/#{entity.qualified_name.gsub(".","/")}.java', [], :guard => 'entity.qualified_name == "MyRepo.MyEntityB"')
253
+ AttributeTemplate.new(template_set, [], :attribute, 'attribute.java', 'main/java/#{attribute.qualified_name.gsub(".","/")}.java')
254
+ UnitTemplate.new(template_set, [], :'jpa.unit', 'unit.java', 'main/java/units/#{unit.name.gsub(".","/")}.java', [], {})
255
+ end
256
+
257
+ TestTemplateSetContainer.template_set(:template_set_2) do |template_set|
258
+ RepositoryTemplate.new(template_set, [], :repository, 'repository2.java', 'main/java/#{repository.name}2.java')
259
+ end
260
+
261
+ TestTemplateSetContainer.template_set(:template_set_3) do |template_set|
262
+ RepositoryTemplate.new(template_set, [], :repository, 'repository3.java', 'main/java/#{repository.name}3.java')
263
+ end
264
+
265
+ TestTemplateSetContainer.template_set(:template_set_4) do |template_set|
266
+ RepositoryTemplate.new(template_set, [], :repository, 'repository4.java', 'main/java/#{repository.name}3.java')
267
+
268
+ AttributeTemplate.new(template_set, [], :attribute, 'attribute4.java', 'main/java/#{attribute.qualified_name.gsub(".","/")}4.java')
269
+ end
270
+
271
+ template_set_keys = [:template_set_1, :template_set_4]
272
+ templates = Reality::Generators::Generator.
273
+ load_templates_from_template_sets(TestTemplateSetContainer, template_set_keys)
274
+
275
+ assert_equal 6, templates.size
276
+ assert_equal %w(template_set_1:attribute.java template_set_1:entity.java template_set_1:repository1.java template_set_1:unit.java template_set_4:attribute4.java template_set_4:repository4.java),
277
+ templates.collect{|t| t.name}.sort
278
+
279
+ end
280
+ end
data/test/helper.rb CHANGED
@@ -37,7 +37,7 @@ class Reality::TestCase < Minitest::Test
37
37
  def temp_dir
38
38
  if @temp_dir.nil?
39
39
  base_temp_dir = ENV['TEST_TMP_DIR'] || File.expand_path("#{File.dirname(__FILE__)}/../tmp")
40
- @temp_dir = "#{base_temp_dir}/generators-#{Time.now.to_i}"
40
+ @temp_dir = "#{base_temp_dir}/tests/generators-#{Time.now.to_i}"
41
41
  FileUtils.mkdir_p @temp_dir
42
42
  end
43
43
  @temp_dir
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.0.0
4
+ version: 1.1.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-04 00:00:00.000000000 Z
11
+ date: 2016-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: reality-core
@@ -96,8 +96,10 @@ files:
96
96
  - README.md
97
97
  - Rakefile
98
98
  - lib/reality/generators.rb
99
+ - lib/reality/generators/buildr_integration.rb
99
100
  - lib/reality/generators/core.rb
100
101
  - lib/reality/generators/erb_template.rb
102
+ - lib/reality/generators/generator.rb
101
103
  - lib/reality/generators/render_context.rb
102
104
  - lib/reality/generators/ruby_template.rb
103
105
  - lib/reality/generators/target_manager.rb
@@ -108,6 +110,7 @@ files:
108
110
  - test/generators/templates/mytemplate.java.erb
109
111
  - test/generators/templates/rubytemplate.rb
110
112
  - test/generators/test_erb_template.rb
113
+ - test/generators/test_generator.rb
111
114
  - test/generators/test_render_context.rb
112
115
  - test/generators/test_ruby_template.rb
113
116
  - test/generators/test_target_manager.rb