caterpillar 1.3.1 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
-
3
-
4
2
  #--
5
3
  # (c) Copyright 2008 Mikael Lammentausta
6
4
  # See the file LICENSES.txt included with the distribution for
@@ -22,7 +20,6 @@ module Caterpillar
22
20
  # Changes the path variables to a format supported by the Rails-portlet.
23
21
  def portlets(routes=@routes)
24
22
  raise 'No configuration' unless @config
25
- raise 'No routes provided' unless routes
26
23
  portlets = []
27
24
 
28
25
  @config.instances.flatten.each do |portlet|
@@ -49,7 +46,7 @@ module Caterpillar
49
46
  portlet.update( :reqs => {} )
50
47
  portlet.update( :vars => [] )
51
48
 
52
- else
49
+ else # parse path from routes
53
50
  begin
54
51
  _r = routes.select{
55
52
  |route| route[:name]==portlet[:name].to_sym
@@ -57,10 +54,13 @@ module Caterpillar
57
54
  path = _r.first[:path] # take only the first segments
58
55
  raise if path.nil?
59
56
  rescue
60
- STDERR.puts ' !! no route for %s' % portlet[:name]
57
+ $stderr.puts ' !! no route for %s' % portlet[:name]
61
58
  next
62
59
  end
63
-
60
+
61
+ # getting de default values from wildcards (:controller, :action, :other)
62
+ portlet.update(:defaults => _r.first[:defaults])
63
+
64
64
  ### requirements - controller & action
65
65
  portlet.update( :reqs => _r.first[:reqs] )
66
66
 
@@ -74,9 +74,11 @@ module Caterpillar
74
74
  portlet.update( :vars => vars )
75
75
 
76
76
  # delete the route from routes
77
- _r.each do |r|
78
- routes.delete(r)
79
- end
77
+ if routes
78
+ _r.each do |r|
79
+ routes.delete(r)
80
+ end
81
+ end
80
82
  end
81
83
  portlet.update( :path => path )
82
84
 
@@ -92,10 +94,11 @@ module Caterpillar
92
94
  # leftover named routes
93
95
  if @config.include_all_named_routes==true
94
96
  portlets << routes
95
- portlets.flatten!
96
97
  end
97
98
 
98
99
  # sanity check
100
+ portlets.flatten!
101
+ portlets.compact!
99
102
  portlets.each do |portlet|
100
103
  ### hostname
101
104
  portlet[:host] ||= @config.host
@@ -1,40 +1,23 @@
1
1
  # encoding: utf-8
2
2
  #--
3
3
  # (c) Copyright 2008, 2010 Mikael Lammentausta
4
+ # 2010 Tulio Ornelas
4
5
  # See the file LICENSES.txt included with the distribution for
5
6
  # software license details.
6
7
  #++
8
+
9
+ if RUBY_PLATFORM =~ /java/
10
+ gem 'jrexml'
11
+ require 'jrexml'
12
+ else
13
+ require "rexml/document"
14
+ end
7
15
 
8
16
  module Caterpillar
9
17
  # Formulates generic JSR286 portlet XML
10
18
  class Portlet
11
19
  class << self
12
20
 
13
- # Creates portlet XML
14
- def xml(portlets)
15
- session =
16
- begin
17
- {
18
- :key => Caterpillar::Security.get_session_key(),
19
- :secret => Caterpillar::Security.get_secret()
20
- }
21
- rescue nil
22
- end
23
-
24
- xml = self.header
25
- portlets.each do |p|
26
- xml << self.template(p,session)
27
- end
28
- xml << self.footer
29
- return xml
30
- end
31
-
32
- def debug(config,routes) # :nodoc:
33
- routes.select{|r| !r[:name].empty?}.each do |route|
34
- puts '%s: %s' % [route[:name], route[:path]]
35
- end
36
- end
37
-
38
21
  # Rails-portlet Java class
39
22
  def portlet_class
40
23
  'com.celamanzi.liferay.portlets.rails286.Rails286Portlet'
@@ -45,100 +28,162 @@ module Caterpillar
45
28
  'com.celamanzi.liferay.portlets.rails286.Rails286PortletFilter'
46
29
  end
47
30
 
48
- # JSR 286 portlet XML header. Opens portlet-app.
49
- def header
50
- xml = '<?xml version="1.0" encoding="UTF-8"?>' +"\n"
51
- xml << '<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
52
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
53
- xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
54
- version="2.0">'
55
- xml << "\n\n"
56
- return xml
57
- end
31
+ # Creates <portlet-app> XML document for portlet-ext.xml.
32
+ #
33
+ # @param portlets is an Array of Hashes
34
+ # @returns String
35
+ def xml(portlets)
36
+ # create a new XML document
37
+ doc = REXML::Document.new
38
+ doc << REXML::XMLDecl.new('1.0', 'utf-8')
39
+ app = REXML::Element.new('portlet-app', doc)
40
+ app.attributes['version'] = '2.0'
41
+ app.attributes['xmlns'] = 'http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd'
42
+ app.attributes['xmlns:xsi'] = 'http://www.w3.org/2001/XMLSchema-instance'
43
+ app.attributes['xsi:schemaLocation'] = 'http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd'
44
+
45
+ # create session values, common for all portlets
46
+ session =
47
+ begin
48
+ {
49
+ :key => Caterpillar::Security.get_session_key(),
50
+ :secret => Caterpillar::Security.get_secret()
51
+ }
52
+ rescue
53
+ nil
54
+ end
58
55
 
59
- # Closes portlet-app.
60
- def footer
61
- '</portlet-app>' + "\n"
56
+ # create XML element tree
57
+ portlets.each do |portlet|
58
+ # <portlet>
59
+ app.elements << self.portlet_element(portlet, session, app)
60
+ # <filter>
61
+ app.elements << self.filter_element(portlet)
62
+ # filter mapping
63
+ app.elements << self.filter_mapping(portlet)
64
+ end
65
+ xml = ''
66
+ #doc.write(xml, -1) # no indentation, tag and text should be on same line
67
+ doc.write(xml, 4) # without identation is very dificult to reconfigure those files in production
68
+ return xml.gsub('\'', '"') # fix rexml attribute single quotes to double quotes
62
69
  end
63
70
 
64
- # portlet.xml template.
71
+ # <portlet> element.
65
72
  # session is a hash containing session key and secret from Rails.
66
- def template(portlet,session=nil)
67
- # add roles
68
- # TODO: move into portlet hash
69
- # administrator, power-user, user
70
- roles = %w{ administrator }
71
- xml = " <!-- %s -->\n" % portlet[:title]
73
+ def portlet_element(portlet, session = nil, app = nil)
74
+ element = REXML::Element.new('portlet')
75
+ # NOTE: to pass validation, the elements need to be in proper order!
76
+
77
+ REXML::Element.new('portlet-name', element).text = portlet[:name]
78
+ REXML::Element.new('portlet-class', element).text = self.portlet_class
72
79
 
73
- xml << " <portlet>\n"
74
- ### identification
75
- xml << " <portlet-name>%s</portlet-name>\n" % portlet[:name]
76
- xml << " <portlet-class>%s</portlet-class>\n" % self.portlet_class
77
- ### supported portlet modes
78
- xml << " <supports>\n"
79
- xml << " <mime-type>text/html</mime-type>\n"
80
- xml << " <portlet-mode>view</portlet-mode>\n"
81
- if portlet[:edit_mode] == true
82
- xml << " <portlet-mode>edit</portlet-mode>\n"
83
- end
84
- xml << " </supports>\n"
85
- ### title for portlet container
86
- xml << " <portlet-info>\n"
87
- xml << " <title>%s</title>\n" % portlet[:title]
88
- xml << " </portlet-info>\n"
89
- ### init parameters, XXX: fails xsd test
90
- #=begin
91
80
  # insert session key
92
81
  unless session.nil?
93
- xml << " <init-param>\n"+\
94
- " <name>session_key</name>\n"+\
95
- " <value>#{session[:key]}</value>\n"+\
96
- " </init-param>\n"
82
+ param = REXML::Element.new('init-param', element)
83
+ REXML::Element.new('name', param).text = 'session_key'
84
+ REXML::Element.new('value', param).text = session[:key]
85
+
86
+ param = REXML::Element.new('init-param', element)
87
+ REXML::Element.new('name', param).text = 'secret'
88
+ REXML::Element.new('value', param).text = session[:secret]
97
89
  end
98
- # insert secret
99
- unless session.nil?
100
- xml << " <init-param>\n"+\
101
- " <name>secret</name>\n"+\
102
- " <value>#{session[:secret]}</value>\n"+\
103
- " </init-param>\n"
90
+
91
+ supports = REXML::Element.new('supports', element)
92
+ REXML::Element.new('mime-type', supports).text = 'text/html'
93
+ ### supported portlet modes
94
+ REXML::Element.new('portlet-mode', supports).text = 'view'
95
+ if portlet[:edit_mode] == true
96
+ REXML::Element.new('portlet-mode', supports).text = 'edit'
104
97
  end
105
- #=end
98
+
99
+ # Public Render Parameters
100
+ if portlet[:public_render_parameters] and portlet[:public_render_parameters].length > 0
101
+ portlet[:public_render_parameters].each do |param|
102
+ REXML::Element.new('supported-public-render-parameter', element).text = param
103
+ end
104
+ end
105
+
106
+ info = REXML::Element.new('portlet-info', element)
107
+ ### title for portlet container
108
+ REXML::Element.new('title', info).text = portlet[:title]
109
+
110
+ # add roles
111
+ # TODO: move into portlet hash
112
+ # administrator, power-user, user
113
+ roles = %w{ administrator }
106
114
  roles.each do |role|
107
- xml << " <security-role-ref>\n"
108
- xml << " <role-name>#{role}</role-name>\n"
109
- xml << " </security-role-ref>\n"
115
+ ref = REXML::Element.new('security-role-ref', element)
116
+ REXML::Element.new('role-name', ref).text = role
110
117
  end
111
- xml << " </portlet>\n\n"
112
118
 
113
- ### portlet filters
114
- xml << " <filter>\n"
119
+ # Public Render Parameters
120
+ if (not app.nil?) and portlet[:public_render_parameters] and portlet[:public_render_parameters].length > 0
121
+ portlet[:public_render_parameters].each do |param|
122
+ prp = REXML::Element.new('public-render-parameter', app)
123
+ REXML::Element.new('identifier', prp).text = param
124
+ qname = REXML::Element.new('qname', prp)
125
+ qname.text = "x:#{param}"
126
+ qname.attributes['xmlns:x'] = 'http://www.liferay.com/public-render-parameters'
127
+ end
128
+ end
129
+
130
+ return element
131
+ end
132
+
133
+ # <filter> element.
134
+ def filter_element(portlet)
115
135
  # the filter reads the settings and sets the portlet session
116
- xml << " <filter-name>%s_filter</filter-name>\n" % portlet[:name]
117
- xml << " <filter-class>%s</filter-class>\n" % self.portlet_filter_class
118
- xml << " <lifecycle>RENDER_PHASE</lifecycle>\n"
119
- xml << " <lifecycle>RESOURCE_PHASE</lifecycle>\n"
136
+ element = REXML::Element.new('filter')
137
+
138
+ REXML::Element.new('filter-name', element).text = "#{portlet[:name]}_filter"
139
+ REXML::Element.new('filter-class', element).text = self.portlet_filter_class
140
+ REXML::Element.new('lifecycle', element).text = 'RENDER_PHASE'
141
+ REXML::Element.new('lifecycle', element).text = 'RESOURCE_PHASE'
120
142
 
121
143
  # define host, servlet and route (path to be more precise)
122
- xml << " <init-param>\n"
123
- xml << " <name>host</name>\n"
124
- xml << " <value>%s</value>\n" % portlet[:host] || ""
125
- xml << " </init-param>\n"
126
- xml << " <init-param>\n"
127
- xml << " <name>servlet</name>\n"
128
- xml << " <value>%s</value>\n" % portlet[:servlet]
129
- xml << " </init-param>\n"
130
- xml << " <init-param>\n"
131
- xml << " <name>route</name>\n"
132
- xml << " <value>%s</value>\n" % portlet[:path].gsub(/&/,"&amp;")
133
- xml << " </init-param>\n"
134
-
135
- xml << " </filter>\n\n"
136
-
137
- xml << " <filter-mapping>\n"
138
- xml << " <filter-name>%s_filter</filter-name>\n" % portlet[:name]
139
- xml << " <portlet-name>%s</portlet-name>\n" % portlet[:name]
140
- xml << " </filter-mapping>\n"
141
- xml << "\n"
144
+ param = REXML::Element.new('init-param', element)
145
+ REXML::Element.new('name', param).text = 'host'
146
+ REXML::Element.new('value', param).text = portlet[:host]
147
+
148
+ param = REXML::Element.new('init-param', element)
149
+ REXML::Element.new('name', param).text = 'servlet'
150
+ REXML::Element.new('value', param).text = portlet[:servlet]
151
+
152
+ param = REXML::Element.new('init-param', element)
153
+ REXML::Element.new('name', param).text = 'route'
154
+ portlet_path = portlet[:path].gsub(/&/,"&amp;")
155
+ REXML::Element.new('value', param).text = portlet_path
156
+
157
+ if portlet[:edit_mode] == true
158
+ param = REXML::Element.new('init-param', element)
159
+ REXML::Element.new('name', param).text = 'preferences_route'
160
+
161
+ if portlet[:preferences_route]
162
+ preferences_route = portlet[:preferences_route]
163
+ else
164
+ preferences_route = portlet_path.gsub(':controller', portlet[:defaults][:controller])
165
+ preferences_route = preferences_route.gsub(':action', 'preferences')
166
+ end
167
+ REXML::Element.new('value', param).text = preferences_route
168
+ end
169
+
170
+ return element
171
+ end
172
+
173
+ # <filter-mapping> element.
174
+ def filter_mapping(portlet)
175
+ element = REXML::Element.new('filter-mapping')
176
+
177
+ REXML::Element.new('filter-name', element).text = "#{portlet[:name]}_filter"
178
+ REXML::Element.new('portlet-name', element).text = portlet[:name]
179
+
180
+ return element
181
+ end
182
+
183
+ def debug(config,routes) # :nodoc:
184
+ routes.select{|r| !r[:name].empty?}.each do |route|
185
+ puts '%s: %s' % [route[:name], route[:path]]
186
+ end
142
187
  end
143
188
 
144
189
  end # static methods
@@ -34,19 +34,17 @@ module Caterpillar
34
34
  # The main task.
35
35
  # Reads the configuration file and launches appropriate tasks.
36
36
  def initialize(name = :usage, config = nil, tasks = :define_tasks)
37
- #STDOUT.puts 'Caterpillar v.%s (c) Copyright 2008,2009 Mikael Lammentausta' % VERSION
38
- #STDOUT.puts 'Provided under the terms of the MIT license.'
39
- #STDOUT.puts
40
-
41
37
  @name = name
42
- @config = Util.eval_configuration(config)
38
+
39
+ @config = (name == 'rails' or name == 'version' ) ? Config.new(false) : Util.eval_configuration(config)
43
40
  @logger = @config.logger
41
+
44
42
  @xml_files = []
45
43
 
46
44
  if name == 'rails'
47
45
  @required_gems = %w(rails caterpillar jruby-jars warbler)
48
46
  else
49
- unless @config.rails_root
47
+ if not @config and not %w{generate version}.include?(name)
50
48
  Usage.show()
51
49
  exit 1
52
50
  end
@@ -59,9 +57,9 @@ module Caterpillar
59
57
  private
60
58
 
61
59
  def define_tasks
60
+ define_version_task
62
61
  define_xml_task
63
62
  define_usage_task
64
- define_config_task
65
63
  define_pluginize_task
66
64
  define_environment_task
67
65
  define_portletxml_task
@@ -82,6 +80,7 @@ module Caterpillar
82
80
  define_deploy_xml_task
83
81
  define_deploy_war_task
84
82
  define_rails_task
83
+ define_generate_task
85
84
  end
86
85
 
87
86
  def define_usage_task
@@ -90,24 +89,38 @@ module Caterpillar
90
89
  end
91
90
  end
92
91
 
93
- # TODO: copy and diff config file
94
- def define_config_task
95
- task :config do
96
- STDOUT.puts 'TODO'
92
+ def define_version_task
93
+ task :version do
94
+ version_str = "Caterpillar #{Caterpillar::VERSION} "
95
+ version_str << "Ruby #{RUBY_VERSION} "
96
+ if RUBY_PLATFORM =~ /java/
97
+ version_str << "JRuby #{JRUBY_VERSION}"
98
+ end
99
+ $stdout.puts version_str
97
100
  end
98
101
  end
99
102
 
100
103
  def define_pluginize_task
101
- desc "Unpack Caterpillar as a plugin in your Rails application"
104
+ desc "Unpack Caterpillar to your Rails application"
102
105
  task :pluginize do
103
- if !Dir["vendor/plugins/caterpillar*"].empty?
104
- puts "I found an old nest in vendor/plugins; please trash it so I can make a new one"
105
- puts "(directory vendor/plugins/caterpillar* exists)"
106
+ if !Dir["vendor/plugins/caterpillar*"].empty? && ENV["FORCE"].nil?
107
+ puts "I found an old pupa"
108
+ puts "(directory vendor/plugins/caterpillar* exists);"
109
+ puts "please trash it so I can make a new one,"
110
+ puts "or prepend the command with environment variable FORCE=1."
111
+ exit 1
106
112
  elsif !File.directory?("vendor/plugins")
107
- puts "I can't find a place to build my nest"
113
+ puts "I can't find a place to build my pupa"
108
114
  puts "(directory 'vendor/plugins' is missing)"
115
+ exit 1
109
116
  else
117
+ rm_rf FileList["vendor/plugins/caterpillar*"], :verbose => false
110
118
  ruby "-S", "gem", "unpack", "caterpillar", "--target", "vendor/plugins"
119
+ # rename the versioned name to plain "caterpillar",
120
+ # since Rails has trouble loading some helper files without so
121
+ File.rename(
122
+ "vendor/plugins/caterpillar-#{Caterpillar::VERSION}",
123
+ "vendor/plugins/caterpillar")
111
124
  ruby "./script/generate caterpillar"
112
125
  end
113
126
  end
@@ -124,9 +137,10 @@ module Caterpillar
124
137
  if @config.container.kind_of? Liferay
125
138
  tasks << "#{@name}:liferayportletapp"
126
139
  tasks << "#{@name}:liferaydisplay"
127
- end
128
-
140
+ end
141
+
129
142
  task :makexml => tasks
143
+ puts 'Done!'
130
144
  end
131
145
 
132
146
  # Prints the list of portlets.
@@ -170,17 +184,34 @@ module Caterpillar
170
184
  end
171
185
  end
172
186
 
187
+ def define_generate_task
188
+ @name = :generate
189
+ desc 'Generates stand-alone configuration file'
190
+ task :generate do
191
+ filename = 'portlets-config.rb'
192
+ FileUtils.cp(
193
+ File.expand_path(File.join(__FILE__,
194
+ %w{.. .. .. generators caterpillar templates config portlets.rb})),
195
+ filename
196
+ )
197
+ info("Generated #{filename}")
198
+ end
199
+ end
200
+
173
201
  ### SUB-TASKS
174
202
 
175
203
  # reads Rails environment configuration
176
204
  def define_environment_task
177
- task :default => :test
178
205
  task :environment do
179
- require(File.join(@config.rails_root, 'config', 'environment'))
206
+ begin
207
+ require(File.join(@config.rails_root, 'config', 'environment'))
208
+ rescue
209
+ raise 'Rails environment could not be loaded'
210
+ end
180
211
  if @config.container.is_a?(Caterpillar::Liferay)
181
212
  if @config.container.version.nil? and !defined?(Lportal)
182
- STDERR.puts 'Liferay version is undefined, and lportal gem is not present.'
183
- STDERR.puts 'Please define portlet.container.version in %s.' % @config.class::FILE
213
+ $stderr.puts 'Liferay version is undefined, and lportal gem is not present.'
214
+ $stderr.puts 'Please define portlet.container.version in %s.' % @config.class::FILE
184
215
  raise 'Insufficient configuration'
185
216
  end
186
217
  @config.container.version ||= Lportal::Schema.version
@@ -191,7 +222,7 @@ module Caterpillar
191
222
 
192
223
  # collects Rails' routes and parses the config
193
224
  def define_parse_task
194
- task :parse => :environment do
225
+ task :parse do
195
226
  @config.routes = Util.parse_routes(@config)
196
227
  @portlets = Parser.new(@config).portlets
197
228
  end
@@ -202,9 +233,9 @@ module Caterpillar
202
233
  @name = :xml
203
234
  # set the output filename
204
235
  if @config.container.kind_of? Liferay
205
- file = File.join('tmp','portlet-ext.xml')
236
+ file = 'portlet-ext.xml'
206
237
  else
207
- file = File.join('tmp','portlet.xml')
238
+ file = 'portlet.xml'
208
239
  end
209
240
  @xml_files << file
210
241
  with_namespace_and_config do |name, config|
@@ -212,7 +243,7 @@ module Caterpillar
212
243
  task :portlet do
213
244
  #portal_info
214
245
 
215
- exit 1 unless system('touch %s' % file)
246
+ FileUtils.touch(file)
216
247
  f=File.open(file,'w')
217
248
  f.write Portlet.xml(@portlets)
218
249
  f.close
@@ -224,12 +255,12 @@ module Caterpillar
224
255
  # Writes liferay-portlet-ext.xml
225
256
  def define_liferayportletappxml_task
226
257
  @name = :xml
227
- file = File.join('tmp','liferay-portlet-ext.xml')
258
+ file = 'liferay-portlet-ext.xml'
228
259
  @xml_files << file
229
260
  with_namespace_and_config do |name, config|
230
261
  desc 'Create Liferay portlet XML'
231
262
  task :liferayportletapp do
232
- exit 1 unless system('touch %s' % file)
263
+ FileUtils.touch(file)
233
264
  f=File.open(file,'w')
234
265
  f.write config.container.portletapp_xml(@portlets)
235
266
  f.close
@@ -241,7 +272,7 @@ module Caterpillar
241
272
  # Writes liferay-display.xml
242
273
  def define_liferaydisplayxml_task
243
274
  @name = :xml
244
- file = File.join('tmp','liferay-display.xml')
275
+ file = 'liferay-display.xml'
245
276
  @xml_files << file
246
277
 
247
278
  with_namespace_and_config do |name, config|
@@ -249,7 +280,7 @@ module Caterpillar
249
280
  task :liferaydisplay do
250
281
  raise 'Version 5.1.2 of Liferay is broken!' if config.container.version == '5.1.2'
251
282
 
252
- exit 1 unless system('touch %s' % file)
283
+ FileUtils.touch(file)
253
284
  f=File.open(file,'w')
254
285
  f.write config.container.display_xml(@portlets)
255
286
  f.close
@@ -333,13 +364,15 @@ module Caterpillar
333
364
 
334
365
  # detect the version of the JAR to install
335
366
  portlet_jar = nil
336
- version = (
337
- if container_v and container_v[/^5.1/]
338
- '0.6.0' # FIXME: branch properly
339
- else
340
- '0.10.0'
341
- end
342
- )
367
+ # XXX: since the filter name has changed, the old JAR does not work
368
+ #version = (
369
+ # if container_v and container_v[/^5.1/]
370
+ # '0.6.0' # FIXME: branch properly
371
+ # else
372
+ # '0.10.0'
373
+ # end
374
+ #)
375
+ version = '0.10.1'
343
376
  require 'find'
344
377
  Find.find(source) do |file|
345
378
  if File.basename(file) == "rails-portlet-#{version}.jar"
@@ -573,6 +606,7 @@ module Caterpillar
573
606
  end
574
607
  exit 1 unless conferring_step 'Creating Rails project...' do
575
608
  create_rails_project
609
+ Dir.chdir("#{ARGV[1]}"){system("ruby script/generate html_template >/dev/null")}
576
610
  end
577
611
  exit 1 unless conferring_step 'Updating config/environment.rb...' do
578
612
  update_environment(ARGV[1] + '/config/environment.rb')
@@ -580,10 +614,11 @@ module Caterpillar
580
614
  exit 1 unless conferring_step 'Activating caterpillar...' do
581
615
  # Rake::Task['pluginize'].execute
582
616
  Dir.chdir("#{ARGV[1]}/vendor/plugins"){system 'ruby -S gem unpack caterpillar >/dev/null'}
583
- Dir.chdir("#{ARGV[1]}"){system 'script/generate caterpillar >/dev/null'}
617
+ Dir.chdir("#{ARGV[1]}"){system 'ruby script/generate caterpillar >/dev/null'}
584
618
  end
585
619
  exit 1 unless conferring_step 'Configuring warbler...' do
586
620
  Dir.chdir("#{ARGV[1]}"){system 'ruby -S warble config >/dev/null 2>&1'}
621
+ update_warble(ARGV[1] +'/config/warble.rb' , ARGV[1].split('/')[-1])
587
622
  end
588
623
  end
589
624
  end
@@ -609,7 +644,7 @@ module Caterpillar
609
644
  end
610
645
 
611
646
  _sorted.each_pair do |category,portlets|
612
- STDOUT.puts category
647
+ $stdout.puts category
613
648
  portlets.each do |portlet|
614
649
  # spaces
615
650
  spaces = ''
@@ -619,13 +654,13 @@ module Caterpillar
619
654
 
620
655
  #field = :path
621
656
  #fields = [:name, :id]
622
- STDOUT.puts "\t" + portlet[:title] +spaces+ portlet[:name].inspect + "\t" + portlet[:vars].inspect
657
+ $stdout.puts "\t" + portlet[:title] +spaces+ portlet[:path] # + "\t" + portlet[:vars].inspect
623
658
  end
624
659
  end
625
660
  end
626
661
 
627
662
  def info(msg)
628
- STDOUT.puts ' * ' + msg
663
+ $stdout.puts ' * ' + msg
629
664
  end
630
665
 
631
666
  def portal_info(config=@config)
@@ -635,7 +670,7 @@ module Caterpillar
635
670
  config.container.version,
636
671
  config.container.root
637
672
  ]
638
- @logger ? @logger.info(msg) : STDOUT.puts(msg)
673
+ info(msg)
639
674
  end
640
675
 
641
676
  private
@@ -689,22 +724,30 @@ module Caterpillar
689
724
 
690
725
  def update_environment(file_path)
691
726
  file = File.read(file_path).
692
- sub(/([ ]*#[ ]*config\.gem)/,
693
- " config.gem 'caterpillar', :version => '#{Caterpillar::VERSION}'\n" + '\1')
727
+ sub(/([ ]*#[ ]*config\.gem)/,
728
+ " config.gem 'caterpillar', :version => '>= #{Caterpillar::VERSION}'\n" + '\1')
729
+ File.open(file_path, 'w') {|f| f << file}
730
+ end
731
+
732
+ def update_warble(file_path, project_name)
733
+ file = File.read(file_path).
734
+ sub(/([ ]*#[ ]*config\.war_name = \"mywar\")/,
735
+ " config.war_name = '#{project_name}-portlet'\n")
694
736
  File.open(file_path, 'w') {|f| f << file}
695
737
  end
738
+
696
739
 
697
740
  def conferring_step(message)
698
- STDOUT.print message
699
- STDOUT.flush
741
+ $stdout.print message
742
+ $stdout.flush
700
743
 
701
744
  result = yield
702
745
  if result.class == String or result.class == NilClass
703
- STDOUT.puts "\e[31mFAILED\e[0m"
746
+ $stdout.puts "\e[31mFAILED\e[0m"
704
747
  puts result unless result.nil?
705
748
  return false
706
749
  else
707
- STDOUT.puts "\e[32mOK\e[0m"
750
+ $stdout.puts "\e[32mOK\e[0m"
708
751
  return true
709
752
  end
710
753
  end