CapicuaGen 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,77 @@
1
+ =begin
2
+
3
+ CapicuaGen
4
+
5
+ CapicuaGen es un software que ayuda a la creación automática de
6
+ sistemas empresariales a través de la definición y ensamblado de
7
+ diversos generadores de características.
8
+
9
+ El proyecto fue iniciado por José Luis Bautista Martin, el 6 de enero
10
+ del 2016.
11
+
12
+ Puede modificar y distribuir este software, según le plazca, y usarlo
13
+ para cualquier fin ya sea comercial, personal, educativo, o de cualquier
14
+ índole, siempre y cuando incluya este mensaje, y se permita acceso el
15
+ código fuente.
16
+
17
+ Este software es código libre, y se licencia bajo LGPL.
18
+
19
+ Para más información consultar http://www.gnu.org/licenses/lgpl.html
20
+ =end
21
+
22
+ module CapicuaGen
23
+
24
+ # Clase que permite un escalonamiento de propidades de forma que un AttributeMixer
25
+ # puede estar dentro de otro (recursivamente) y permitir acceder a cualquier atributo
26
+ # definido en cualquiera de ellos, permitiendo que se sobreescriban.
27
+ class AttributeMixer
28
+
29
+
30
+ public
31
+
32
+ # Mezclador de la base
33
+ attr_accessor :mixer_base
34
+
35
+ def initialize
36
+ @internal_mixer= {}
37
+ @mixer_base = nil
38
+ end
39
+
40
+ # Recuperamos un valor
41
+ def [](key)
42
+ return @internal_mixer[key] if @internal_mixer[key]
43
+ return @mixer_base[key] if @mixer_base
44
+ return nil
45
+ end
46
+
47
+
48
+ # Añade un hash de valores
49
+ def add(hash={})
50
+ hash.each_pair do |k, v|
51
+ self[k]=v
52
+ end
53
+ end
54
+
55
+
56
+ #agregamos un valor
57
+ def []= (key, value)
58
+ @internal_mixer[key]= value
59
+ end
60
+
61
+ # Indica que un attribute esta definido en la base
62
+ def has_in_base?(attribute)
63
+ return false unless @mixer_base
64
+ return true if @mixer_base.has_in_self?(attribute)
65
+ return @mixer_base.has_in_base?(attribute)
66
+ end
67
+
68
+ # Indica que un attribute esta definido en el objeto mismo
69
+ def has_in_self?(attribute)
70
+ return false unless @internal_mixer
71
+ return (@internal_mixer.has_key?(attribute) and @internal_mixer[attribute])
72
+ end
73
+
74
+ end
75
+
76
+ end
77
+
@@ -0,0 +1,38 @@
1
+ =begin
2
+
3
+ CapicuaGen
4
+
5
+ CapicuaGen es un software que ayuda a la creación automática de
6
+ sistemas empresariales a través de la definición y ensamblado de
7
+ diversos generadores de características.
8
+
9
+ El proyecto fue iniciado por José Luis Bautista Martin, el 6 de enero
10
+ del 2016.
11
+
12
+ Puede modificar y distribuir este software, según le plazca, y usarlo
13
+ para cualquier fin ya sea comercial, personal, educativo, o de cualquier
14
+ índole, siempre y cuando incluya este mensaje, y se permita acceso el
15
+ código fuente.
16
+
17
+ Este software es código libre, y se licencia bajo LGPL.
18
+
19
+ Para más información consultar http://www.gnu.org/licenses/lgpl.html
20
+ =end
21
+
22
+ =begin
23
+ CapicuaGen es una herrmamienta de generacion de codigo basado en caracteristicas
24
+ configurables y extensibles.
25
+ =end
26
+
27
+ require_relative 'version'
28
+ require_relative 'template_feature'
29
+ require_relative 'feature'
30
+ require_relative 'target'
31
+ require_relative 'generator'
32
+ require_relative 'Tools/template_helper'
33
+ require_relative 'template'
34
+ require_relative 'template_target'
35
+ require_relative 'attribute_mixer'
36
+ require_relative 'file_information'
37
+ require_relative 'Tools/message_helper'
38
+ require_relative 'Tools/xml_helper'
@@ -0,0 +1,151 @@
1
+ =begin
2
+
3
+ CapicuaGen
4
+
5
+ CapicuaGen es un software que ayuda a la creación automática de
6
+ sistemas empresariales a través de la definición y ensamblado de
7
+ diversos generadores de características.
8
+
9
+ El proyecto fue iniciado por José Luis Bautista Martin, el 6 de enero
10
+ del 2016.
11
+
12
+ Puede modificar y distribuir este software, según le plazca, y usarlo
13
+ para cualquier fin ya sea comercial, personal, educativo, o de cualquier
14
+ índole, siempre y cuando incluya este mensaje, y se permita acceso el
15
+ código fuente.
16
+
17
+ Este software es código libre, y se licencia bajo LGPL.
18
+
19
+ Para más información consultar http://www.gnu.org/licenses/lgpl.html
20
+ =end
21
+
22
+ require_relative 'Mixins/reflection_mixin'
23
+
24
+ module CapicuaGen
25
+
26
+ class Feature
27
+ include CapicuaGen
28
+
29
+ protected
30
+ attr_accessor :types
31
+
32
+ public
33
+ attr_accessor :name, :generation_attributes
34
+ attr_reader :generator
35
+
36
+ def initialize(attributes= {})
37
+ initialize_properties(attributes, false)
38
+
39
+ # Configuro los parametros de tipo
40
+ @types= []
41
+ if attributes[:types]
42
+ @types= attributes[:types]
43
+ if @types and not @types.instance_of?(Array)
44
+ @types= [types]
45
+ end
46
+ end
47
+
48
+
49
+ #Define los atributos de la generacion
50
+ @generation_attributes= AttributeMixer.new
51
+
52
+ # Generador asociado
53
+ @generator = nil
54
+
55
+ #Ejecuto configuracion en bloque
56
+ yield self if block_given?
57
+ end
58
+
59
+ def clean
60
+ message_helper.puts_generating_feature(self)
61
+ end
62
+
63
+
64
+ def generate
65
+ message_helper.puts_generating_feature(self)
66
+ end
67
+
68
+
69
+ # Devuelve los archivos generados por esta caracteristicas
70
+ def get_out_file_information(values= {})
71
+ return []
72
+ end
73
+
74
+ # Devuelve los archivos generados por esta caracteristicas
75
+ def get_relative_out_files(values= {})
76
+ result= []
77
+ # Obtengo la ruta base
78
+ if values[:directory_base]
79
+ directory_base= values[:directory_base]
80
+ else
81
+ directory_base= @generation_attributes[:out_dir]
82
+ end
83
+
84
+ get_out_file_information(values).each do |f|
85
+ relative_path= f.get_relative_file_path(directory_base)
86
+
87
+ result << relative_path
88
+ end
89
+
90
+
91
+ return result
92
+ end
93
+
94
+ # Indica que el destino es de un tipo determinado
95
+ def is_type?(type)
96
+ return type.include(type)
97
+ end
98
+
99
+ # Indica que el destino es de un tipo determinado
100
+ def is_any_type?(types)
101
+ if types and not types.instance_of?(Array)
102
+ types= [types]
103
+ end
104
+ return (@types & types).length > 0
105
+ end
106
+
107
+
108
+ # Configura el generador y se
109
+ def generator= (value)
110
+
111
+ @generator= value
112
+
113
+ if @generator
114
+ reset_attributes()
115
+ @generation_attributes.mixer_base= generator.generation_attributes
116
+ configure_attributes()
117
+ end
118
+
119
+ end
120
+
121
+ # Resetea los atributos personalizados de la caracteristica (antes de establecer el generador)
122
+ def reset_attributes
123
+
124
+ end
125
+
126
+ # Configura los atributos personalizados de la caracteristica (antes de establecer el generador)
127
+ def configure_attributes()
128
+
129
+ end
130
+
131
+
132
+ def argv_options
133
+ return @generator.argv_options
134
+ end
135
+
136
+ def message_helper
137
+ return MessageHelper.New unless @generator
138
+ return @generator.message_helper
139
+ end
140
+
141
+ def clone(attributes= {})
142
+ result=super()
143
+ result.initialize_properties(attributes, false)
144
+ return result
145
+ end
146
+
147
+
148
+ end
149
+
150
+ end
151
+
@@ -0,0 +1,52 @@
1
+ =begin
2
+
3
+ CapicuaGen
4
+
5
+ CapicuaGen es un software que ayuda a la creación automática de
6
+ sistemas empresariales a través de la definición y ensamblado de
7
+ diversos generadores de características.
8
+
9
+ El proyecto fue iniciado por José Luis Bautista Martin, el 6 de enero
10
+ del 2016.
11
+
12
+ Puede modificar y distribuir este software, según le plazca, y usarlo
13
+ para cualquier fin ya sea comercial, personal, educativo, o de cualquier
14
+ índole, siempre y cuando incluya este mensaje, y se permita acceso el
15
+ código fuente.
16
+
17
+ Este software es código libre, y se licencia bajo LGPL.
18
+
19
+ Para más información consultar http://www.gnu.org/licenses/lgpl.html
20
+ =end
21
+
22
+ require 'pathname'
23
+
24
+ module CapicuaGen
25
+
26
+ # Representa informacion acerca de un archivo
27
+ class FileInformation
28
+
29
+
30
+ public
31
+ attr_accessor :file_name
32
+
33
+ # Inicializa la caracteristica
34
+ def initialize(values= {})
35
+ @file_name= values[:file_name]
36
+ end
37
+
38
+ def get_relative_file_path(directory_base)
39
+
40
+ return file_name unless directory_base
41
+
42
+
43
+ first= Pathname.new directory_base
44
+ second= Pathname.new file_name
45
+
46
+ return second.relative_path_from(first).to_s
47
+
48
+ end
49
+
50
+ end
51
+ end
52
+
@@ -0,0 +1,289 @@
1
+ =begin
2
+
3
+ CapicuaGen
4
+
5
+ CapicuaGen es un software que ayuda a la creación automática de
6
+ sistemas empresariales a través de la definición y ensamblado de
7
+ diversos generadores de características.
8
+
9
+ El proyecto fue iniciado por José Luis Bautista Martin, el 6 de enero
10
+ del 2016.
11
+
12
+ Puede modificar y distribuir este software, según le plazca, y usarlo
13
+ para cualquier fin ya sea comercial, personal, educativo, o de cualquier
14
+ índole, siempre y cuando incluya este mensaje, y se permita acceso el
15
+ código fuente.
16
+
17
+ Este software es código libre, y se licencia bajo LGPL.
18
+
19
+ Para más información consultar http://www.gnu.org/licenses/lgpl.html
20
+ =end
21
+
22
+ require 'active_support/core_ext/object/blank'
23
+ require_relative 'Mixins/reflection_mixin'
24
+ require_relative 'generator_command_line'
25
+
26
+ module CapicuaGen
27
+
28
+
29
+ # Clase generadora, nueclo de CapicuaGen, al que se le configuran todas las caracteristicas
30
+ # y las llama segun corresponda para que generen la parte de codigo asociado a ellas
31
+
32
+ class Generator
33
+ include CapicuaGen
34
+
35
+ public
36
+
37
+ attr_accessor :generation_attributes, :retry_failed, :continue_on_failed, :retries, :local_feature_directory
38
+ attr_accessor :message_helper, :start_time, :end_time, :argv_options
39
+
40
+ # Inicializo el objeto
41
+ def initialize(attributes= {})
42
+ initialize_properties(attributes, false)
43
+
44
+
45
+ # Valores determinados
46
+ @retry_failed = true unless @retry_failed
47
+ @retries = 1 unless @retries
48
+ @continue_on_failed = true unless @continue_on_failed
49
+ @local_feactures_directory= 'Capicua' unless @local_features_directory
50
+
51
+ # Colecciones de caracteristicas que posee el generador
52
+ @features = []
53
+
54
+ # Caraceristicas a ejecutar
55
+ @targets = []
56
+
57
+ # Atributos generales de generacion
58
+ @generation_attributes = AttributeMixer.new
59
+
60
+ # Configuro el gestor de mensajes
61
+ @message_helper = MessageHelper.new
62
+
63
+ # Hora de comienzo y final
64
+ @start_time = Time.now
65
+ @end_time = Time.now
66
+
67
+ # Opciones
68
+ @argv_options =OpenStruct.new
69
+
70
+ # Aranco configuracion si es necesario
71
+ yield self if block_given?
72
+ end
73
+
74
+ # Coleccion de caracteristicas del generador
75
+ def features(values= {})
76
+
77
+ # Configuro los parametros por defecto
78
+ enable_generation= nil
79
+ enable = true
80
+
81
+ # Configuro los parametros
82
+ enable_generation= values[:enable_generation] if values[:enable_generation]
83
+ enable = values[:enable_generation] if values[:enable_generation]
84
+
85
+ return @features
86
+ end
87
+
88
+ # Agrega una caracteristica en el generador
89
+ def add_feature (feature)
90
+ @features<<feature
91
+ end
92
+
93
+ # Quita la caracteristica
94
+ def remove_feature (feature)
95
+ @features.delete(feature)
96
+ end
97
+
98
+ # Quita la caracterisitca en base al nombre
99
+ def remove_feature_by_name(feature_name)
100
+ @features.delete_if { |f| f.name==feature_name }
101
+ end
102
+
103
+ # Obtiene la caracteristica en base al nombre
104
+ def get_feature_by_name(feature_name)
105
+ return @features.detect { |f| f.name==feature_name }
106
+ end
107
+
108
+ # Obtiene las caracteriscas de un tipo
109
+ def get_features_by_type(feature_type)
110
+ return @features.select { |f| f.type==type }
111
+ end
112
+
113
+ # Obtiene el nombre de todos los objetivos
114
+ def targets
115
+ return @targets
116
+ end
117
+
118
+ # Agrega un objetivo
119
+ def add_target(target)
120
+ @targets<<target
121
+ end
122
+
123
+ # Elimina un objetivo
124
+ def remove_target(target)
125
+ @targets.delete(target)
126
+ end
127
+
128
+
129
+ # Agrega una caracteristica y al mismo tiempo la convierte en objetivo
130
+ def add_feature_and_target(*features)
131
+ features.each do |feature|
132
+ add_feature(feature)
133
+ target= Target.new(:name => feature.name)
134
+ add_target(target)
135
+ end
136
+ end
137
+
138
+
139
+ # Obtiene una caracteristica, que a la vez es un objetivo, por su nombre
140
+ def get_feature_by_target_name
141
+ target @targets.detect { |f| f.name==feature_name }
142
+
143
+ return unless target
144
+
145
+ return get_feature_by_name(target.name)
146
+ end
147
+
148
+ # Obtiene una caracteristica, que a la vez es un objetivo, por su tipo
149
+ def get_features_in_targets_by_type(target_types= [])
150
+ features= []
151
+
152
+ @targets.each do |t|
153
+ feature= get_feature_by_name(t.feature_name)
154
+ next unless feature
155
+ next unless t.enable
156
+ features<<feature if target_types.blank? or feature.is_any_type?(target_types)
157
+ end
158
+
159
+ return features
160
+
161
+ end
162
+
163
+
164
+ # Obtiene una caracteristica, que a la vez es un objetivo, por su tipo
165
+ def get_features_in_targets
166
+ return get_features_in_targets_by_type
167
+ end
168
+
169
+ # Genera todos las caracteristicas
170
+ def generate
171
+
172
+ @start_time = Time.now
173
+
174
+ # Reviso argumentos
175
+ argv =ARGV.clone
176
+ @argv_options =parse_command_line(argv)
177
+
178
+ return if @argv_options.exit
179
+
180
+ if @argv_options.clean
181
+ clean
182
+ end
183
+
184
+ return unless @argv_options.generate
185
+
186
+ @targets.each do |t|
187
+
188
+ # configuro todas las asignaciones de generador
189
+
190
+ feature = get_feature_by_name(t.feature_name)
191
+ feature.generator= self
192
+
193
+ end
194
+
195
+ # Clono los objetivos
196
+ targets= [] + @targets
197
+ retries= @retries + 1
198
+
199
+ # Posibles reintentos
200
+ retries.times do
201
+
202
+ # Realizo las generaciones
203
+ @targets.each do |t|
204
+
205
+ next unless targets.include?(t)
206
+
207
+ next unless t.enable_generation and t.enable
208
+
209
+ feature= get_feature_by_name(t.feature_name)
210
+
211
+ next if @argv_options.ignore_features.include? feature.name
212
+
213
+ begin
214
+ feature.generate
215
+ targets.delete(t)
216
+ rescue => e
217
+ $stderr.puts e
218
+ $stderr.puts e.backtrace
219
+ end
220
+ end
221
+
222
+ end
223
+
224
+ @end_time=Time.now
225
+
226
+ puts
227
+ message_helper.puts_end_generate(@start_time, @end_time)
228
+
229
+ end
230
+
231
+
232
+ # Genera todos las caracteristicas
233
+ def clean
234
+
235
+ @start_time = Time.now
236
+
237
+ # Reviso argumentos
238
+ argv =ARGV.clone
239
+ @argv_options =parse_command_line(argv)
240
+
241
+ return if @argv_options.exit
242
+
243
+ @targets.each do |t|
244
+
245
+ # configuro todas las asignaciones de generador
246
+
247
+ feature = get_feature_by_name(t.feature_name)
248
+ feature.generator= self
249
+
250
+ end
251
+
252
+ # Clono los objetivos
253
+ targets= [] + @targets
254
+ retries= @retries + 1
255
+
256
+ # Posibles reintentos
257
+ retries.times do
258
+
259
+ # Realizo las generaciones
260
+ @targets.each do |t|
261
+
262
+ next unless targets.include?(t)
263
+
264
+ next unless t.enable_generation and t.enable
265
+
266
+ feature= get_feature_by_name(t.feature_name)
267
+
268
+ next if @argv_options.ignore_features.include? feature.name
269
+
270
+ begin
271
+ feature.clean
272
+ targets.delete(t)
273
+ rescue => e
274
+ $stderr.puts e
275
+ $stderr.puts e.backtrace
276
+ end
277
+ end
278
+
279
+ end
280
+
281
+ @end_time=Time.now
282
+
283
+ puts
284
+ message_helper.puts_end_generate(@start_time, @end_time)
285
+
286
+ end
287
+
288
+ end
289
+ end