caterpillar 1.2.5 → 1.3.1

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,2009,2010 Mikael Lammentausta
6
4
  #
@@ -39,17 +37,22 @@ module Caterpillar
39
37
  #STDOUT.puts 'Caterpillar v.%s (c) Copyright 2008,2009 Mikael Lammentausta' % VERSION
40
38
  #STDOUT.puts 'Provided under the terms of the MIT license.'
41
39
  #STDOUT.puts
40
+
42
41
  @name = name
43
42
  @config = Util.eval_configuration(config)
44
43
  @logger = @config.logger
45
- unless @config.rails_root
46
- Usage.show()
47
- exit 1
44
+ @xml_files = []
45
+
46
+ if name == 'rails'
47
+ @required_gems = %w(rails caterpillar jruby-jars warbler)
48
+ else
49
+ unless @config.rails_root
50
+ Usage.show()
51
+ exit 1
52
+ end
48
53
  end
49
54
 
50
55
  yield self if block_given?
51
- @xml_files = []
52
-
53
56
  send tasks
54
57
  end
55
58
 
@@ -78,6 +81,7 @@ module Caterpillar
78
81
  define_deploy_task
79
82
  define_deploy_xml_task
80
83
  define_deploy_war_task
84
+ define_rails_task
81
85
  end
82
86
 
83
87
  def define_usage_task
@@ -103,9 +107,7 @@ module Caterpillar
103
107
  puts "I can't find a place to build my nest"
104
108
  puts "(directory 'vendor/plugins' is missing)"
105
109
  else
106
- Dir.chdir("vendor/plugins") do
107
- ruby "-S", "gem", "unpack", "caterpillar"
108
- end
110
+ ruby "-S", "gem", "unpack", "caterpillar", "--target", "vendor/plugins"
109
111
  ruby "./script/generate caterpillar"
110
112
  end
111
113
  end
@@ -124,10 +126,7 @@ module Caterpillar
124
126
  tasks << "#{@name}:liferaydisplay"
125
127
  end
126
128
 
127
- # print produced portlets
128
- #tasks << :portlets
129
-
130
- task :xml => tasks
129
+ task :makexml => tasks
131
130
  end
132
131
 
133
132
  # Prints the list of portlets.
@@ -217,7 +216,7 @@ module Caterpillar
217
216
  f=File.open(file,'w')
218
217
  f.write Portlet.xml(@portlets)
219
218
  f.close
220
- info '-> %s' % file
219
+ #info '-> %s' % file
221
220
  end
222
221
  end
223
222
  end
@@ -234,7 +233,7 @@ module Caterpillar
234
233
  f=File.open(file,'w')
235
234
  f.write config.container.portletapp_xml(@portlets)
236
235
  f.close
237
- info '-> %s' % file
236
+ #info '-> %s' % file
238
237
  end
239
238
  end
240
239
  end
@@ -254,7 +253,7 @@ module Caterpillar
254
253
  f=File.open(file,'w')
255
254
  f.write config.container.display_xml(@portlets)
256
255
  f.close
257
- info '-> %s' % file
256
+ #info '-> %s' % file
258
257
  end
259
258
  end
260
259
  end
@@ -338,7 +337,7 @@ module Caterpillar
338
337
  if container_v and container_v[/^5.1/]
339
338
  '0.6.0' # FIXME: branch properly
340
339
  else
341
- '0.9.2'
340
+ '0.10.0'
342
341
  end
343
342
  )
344
343
  require 'find'
@@ -368,7 +367,7 @@ module Caterpillar
368
367
  # check for previous installs..
369
368
  Find.find(target) do |file|
370
369
  if File.basename(file) =~ /rails-portlet/
371
- old_version = file[/(\d.\d.\d).jar/,1]
370
+ old_version = file[/(\d.\d*.\d).jar/,1]
372
371
  # check if there's an update available
373
372
  if version.gsub(/\./,'').to_i > old_version.gsub(/\./,'').to_i
374
373
  info 'Rails-portlet version %s is found, but an update is available' % old_version
@@ -410,10 +409,9 @@ module Caterpillar
410
409
  require 'find'
411
410
  Find.find(target) do |file|
412
411
  if File.basename(file) =~ /rails-portlet/
413
- version = file[/(\d.\d.\d).jar/,1]
414
- info 'Uninstalling Rails-portlet version %s from %s' % [version, target]
415
- exit 1 unless system('rm -f %s' % file)
416
- exit 0
412
+ version = file[/(\d.\d*.\d).jar/,1]
413
+ info 'Uninstalling Rails-portlet JAR version %s from %s' % [version, target]
414
+ exit File.delete(file)
417
415
  end
418
416
  end
419
417
 
@@ -426,7 +424,7 @@ module Caterpillar
426
424
  def define_jar_version_task
427
425
  @name = :jar
428
426
  with_namespace_and_config do |name, config|
429
- desc 'Checks the installed Rails-portlet version'
427
+ desc 'Checks the installed Rails-portlet JAR version'
430
428
  task :version do
431
429
  raise 'Only Liferay is supported' unless deployment_requirements_met?
432
430
  require 'find'
@@ -434,13 +432,13 @@ module Caterpillar
434
432
 
435
433
  Find.find(target) do |file|
436
434
  if File.basename(file) =~ /rails-portlet/
437
- version = file[/(\d.\d.\d).jar/,1]
438
- info 'Rails-portlet version %s found in %s' % [version, target]
435
+ version = file[/(\d.\d*.\d).jar/,1]
436
+ info 'Rails-portlet version %s found: %s' % [version, file]
439
437
  exit 0
440
438
  end
441
439
  end
442
440
 
443
- info 'Rails-portlet was not found in %s' % target
441
+ info 'Rails-portlet JAR was not found in %s' % target
444
442
  exit 1
445
443
  end
446
444
  end
@@ -490,15 +488,15 @@ module Caterpillar
490
488
  # only update the DB if the lportal gem is loaded
491
489
  tasks << 'db:update' if defined?(Lportal)
492
490
 
493
- [:xml, :warble, 'deploy:xml', 'deploy:war'].each { |task| tasks << task }
491
+ ['deploy:xml', 'warble', 'deploy:war'].each { |task| tasks << task }
494
492
  task :deploy => tasks
495
493
  end
496
494
 
497
495
  def define_deploy_xml_task
498
496
  @name = :deploy
499
497
  with_namespace_and_config do |name, config|
500
- desc 'Deploys the XML files'
501
- task :xml do
498
+ desc 'Builds and deploys the XML files'
499
+ task :xml => 'makexml' do
502
500
  unless deployment_requirements_met?
503
501
  info 'Deployment is only supported on Liferay on Tomcat. Patches are welcome.'
504
502
  info 'Copy these XML files into the portlet container\'s WEB-INF.'
@@ -507,15 +505,16 @@ module Caterpillar
507
505
  end
508
506
 
509
507
  target = @config.container.WEB_INF
510
- info 'deploying XML files to %s' % target
508
+ info 'deploying XML files'
511
509
 
512
510
  @xml_files.each do |file|
513
- exit 1 unless system('cp %s %s' % [file,target])
514
- info ' %s' % [file]
511
+ FileUtils.cp(file,target)
512
+ info "-> " + File.join(target, File.basename(file))
515
513
  end
516
514
  end
517
515
  end
518
516
  end
517
+
519
518
  def define_deploy_war_task
520
519
  @name = :deploy
521
520
  with_namespace_and_config do |name, config|
@@ -554,9 +553,6 @@ module Caterpillar
554
553
  end
555
554
  end
556
555
 
557
-
558
-
559
-
560
556
  def with_namespace_and_config
561
557
  name, config = @name, @config
562
558
  namespace name do
@@ -564,6 +560,34 @@ module Caterpillar
564
560
  end
565
561
  end
566
562
 
563
+ def define_rails_task
564
+ task :rails do
565
+ exit 1 unless conferring_step 'Checking for required gems...' do
566
+ check_required_gems
567
+ end
568
+ exit 1 unless conferring_step 'Checking for JRuby binary...' do
569
+ check_jruby
570
+ end
571
+ exit 1 unless conferring_step 'Checking for required gems in JRuby...' do
572
+ check_jruby_required_gems
573
+ end
574
+ exit 1 unless conferring_step 'Creating Rails project...' do
575
+ create_rails_project
576
+ end
577
+ exit 1 unless conferring_step 'Updating config/environment.rb...' do
578
+ update_environment(ARGV[1] + '/config/environment.rb')
579
+ end
580
+ exit 1 unless conferring_step 'Activating caterpillar...' do
581
+ # Rake::Task['pluginize'].execute
582
+ 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'}
584
+ end
585
+ exit 1 unless conferring_step 'Configuring warbler...' do
586
+ Dir.chdir("#{ARGV[1]}"){system 'ruby -S warble config >/dev/null 2>&1'}
587
+ end
588
+ end
589
+ end
590
+
567
591
  protected
568
592
 
569
593
  def deployment_requirements_met?
@@ -614,7 +638,76 @@ module Caterpillar
614
638
  @logger ? @logger.info(msg) : STDOUT.puts(msg)
615
639
  end
616
640
 
641
+ private
617
642
 
643
+ def check_required_gems
644
+ gems = @required_gems
645
+ available_gems = []
646
+
647
+ gems.each {|gem| available_gems << gem if Gem::available? gem}
648
+ gems_not_found = (gems - available_gems)
649
+
650
+ if gems_not_found.empty?
651
+ return true
652
+ else
653
+ return "These required gems were not found: #{gems_not_found.join(' ')}\n" +
654
+ "Please install them with: ruby -S gem install #{gems_not_found.join(' ')}"
655
+ end
656
+ end
657
+
658
+ def check_jruby
659
+ has_jruby = system 'jruby --copyright >/dev/null 2>&1'
660
+
661
+ if has_jruby
662
+ return true
663
+ else
664
+ return "jruby binary was not found in your path\n" +
665
+ "Please visit: http://jruby.org/"
666
+ end
667
+ end
618
668
 
669
+ def check_jruby_required_gems
670
+ jruby_gems = `jruby -S gem list`
671
+ available_gems = []
672
+
673
+ @required_gems.each {|gem| available_gems << gem if jruby_gems.match(gem)}
674
+ gems_not_found = (@required_gems - available_gems)
675
+
676
+ if gems_not_found.empty?
677
+ return true
678
+ else
679
+ return "These required gems were not found: #{gems_not_found.join(' ')}\n" +
680
+ "Please install them with: jruby -S gem install #{gems_not_found.join(' ')}"
681
+ end
682
+ end
683
+
684
+ def create_rails_project
685
+ return 'specify rails project name' if ARGV[1].nil?
686
+ return "#{ARGV[1]} folder name already exists" if FileTest.exists? ARGV[1]
687
+ return system "ruby -S rails #{ARGV[1]} >/dev/null"
688
+ end
689
+
690
+ def update_environment(file_path)
691
+ file = File.read(file_path).
692
+ sub(/([ ]*#[ ]*config\.gem)/,
693
+ " config.gem 'caterpillar', :version => '#{Caterpillar::VERSION}'\n" + '\1')
694
+ File.open(file_path, 'w') {|f| f << file}
695
+ end
696
+
697
+ def conferring_step(message)
698
+ STDOUT.print message
699
+ STDOUT.flush
700
+
701
+ result = yield
702
+ if result.class == String or result.class == NilClass
703
+ STDOUT.puts "\e[31mFAILED\e[0m"
704
+ puts result unless result.nil?
705
+ return false
706
+ else
707
+ STDOUT.puts "\e[32mOK\e[0m"
708
+ return true
709
+ end
710
+ end
711
+
619
712
  end
620
713
  end
Binary file
@@ -8,65 +8,71 @@
8
8
 
9
9
  require 'rubygems'
10
10
 
11
- # Rails gem chooser
11
+ # Rails gem chooser.
12
12
  #
13
- # Requires the proper Rails version by the +RAILS_ROOT/config/environment.rb+ file.
13
+ # Selects RAILS_GEM_VERSION from ENV, or from RAILS_ROOT/config/environment.rb.
14
+ # Returns nil otherwise.
14
15
  class RailsGemChooser
15
16
  class << self
16
17
 
17
18
  def version(config_file=nil)
18
- unless config_file
19
- config_file = File.join(
20
- File.expand_path(RAILS_ROOT),
21
- 'config',
22
- 'environment.rb'
23
- )
19
+ # detect from ENV
20
+ if ENV['RAILS_GEM_VERSION']
21
+ return ENV['RAILS_GEM_VERSION']
22
+ elsif not config_file
23
+ # load Rails config file
24
+ if RAILS_ROOT
25
+ config_file = File.join(
26
+ File.expand_path(RAILS_ROOT),
27
+ 'config',
28
+ 'environment.rb'
29
+ )
30
+ else
31
+ STDERR.puts 'Could not detect Rails version'
32
+ return nil
33
+ end
24
34
  end
25
35
  # don't attempt to load Rails if building a Rubygem..!
26
36
  if $0[/gem$/] or !File.exist?(config_file)
27
- rails_gem_version = nil
37
+ return nil
28
38
  else
29
- # Attempt to guess proper Rails version by reading Rails' config file
39
+ # read from Rails config file
30
40
  f=File.open(config_file)
31
41
  config = f.read
32
- rails_gem_version = config[/RAILS_GEM_VERSION.*(\d\.\d\.\d)/,1]
33
42
  f.close
34
- #STDOUT.puts 'Detected Rails version %s from the config file %s' % [rails_gem_version,config_file]
43
+ rails_gem_version = config[/^RAILS_GEM_VERSION.*(\d\.\d\.\d)/,1]
44
+ STDOUT.puts 'Detected Rails version %s from the config file %s' % [rails_gem_version,config_file]
45
+ return rails_gem_version
35
46
  end
36
- return rails_gem_version
37
47
  end
38
48
 
39
49
  # Load a specific GEM
40
50
  def __load_gem(name,version)
51
+ #p 'require gem %s v%s' % [name,version]
41
52
  version ? gem(name, '= '+version) : gem(name)
42
53
  require name
43
54
  end
44
55
 
45
56
  # Either define +rails_gem_version+ or +config_file+
46
- # Without any parameters, the config_file is detected from RAILS_ROOT.
47
57
  def __load(rails_gem_version=nil,config_file=nil)
48
58
  raise 'oops' if config_file and rails_gem_version
49
59
 
50
- rails_gem_version ||= version(config_file)
60
+ rails_gem_version ||= version(config_file) # also detects ENV['RAILS_GEM_VERSION']
51
61
 
52
62
  #STDOUT.puts 'Loading Rails version %s' % rails_gem_version
53
- #DEPRECATION WARNING: require "activesupport" is deprecated and will be removed in Rails 3. Use require "active_support" instead..
54
- #DEPRECATION WARNING: require "actionpack" is deprecated and will be removed in Rails 3. Use require "action_pack" instead..
55
- #DEPRECATION WARNING: require "activerecord" is deprecated and will be removed in Rails 3. Use require "active_record" instead..
56
- #if rails_gem_version[/^2/]
57
- rails_gems = %w{ activesupport actionpack activerecord }
58
- #else
59
- # .. except that this does not work..
60
- # rails_gems = %w{ active_support action_pack active_record }
61
- #end
62
63
 
63
- # gem build fails when activesupport is loaded here
64
- # - except with Rails 2.3.5 where this needs to be added.
65
- if $0[/gem$/]
66
- # rails_gems -= ['activesupport']
67
- end
68
- rails_gems.each do |rg|
69
- __load_gem(rg,rails_gem_version)
64
+ # XXX: silly hack because gem loading seems to have a problem..
65
+ # >> gem('active_support', '=2.3.5')
66
+ # Gem::LoadError: Could not find RubyGem active_support (= 2.3.5)
67
+ # >> require 'activesupport'
68
+ # DEPRECATION WARNING: require "activesupport" is deprecated and will be removed in Rails 3. Use require "active_support" instead..
69
+ require 'active_support'
70
+ rails_gems = %w{ actionpack activerecord }
71
+
72
+ ActiveSupport::Deprecation.silence do
73
+ rails_gems.each do |rg|
74
+ __load_gem(rg,rails_gem_version)
75
+ end
70
76
  end
71
77
  require 'action_controller'
72
78
 
@@ -98,6 +98,14 @@ class Caterpillar::JunitController < Caterpillar::ApplicationController
98
98
  render :text => ""
99
99
  end
100
100
 
101
+ def download_image
102
+ send_file(File.expand_path('vendor/plugins/caterpillar/portlet_test_bench/resources/jake_sully.jpg'), :filename => "jake_sully.jpg")
103
+ end
104
+
105
+ def preferences
106
+ render :text => "Preferences view"
107
+ end
108
+
101
109
  # Sets a session value so the single SESSION_KEY cookie is set.
102
110
  # The output XML prints the session ID and the JUnit test compares this
103
111
  # to the value from another request, and with the same cookie they should match.
@@ -109,6 +117,7 @@ class Caterpillar::JunitController < Caterpillar::ApplicationController
109
117
  def redirect
110
118
  redirect_to :action => :redirect_target
111
119
  end
120
+
112
121
  def redirect_target
113
122
  render :text => request.request_uri
114
123
  end
@@ -119,6 +128,7 @@ class Caterpillar::JunitController < Caterpillar::ApplicationController
119
128
  cookies[:the_time] = Time.now.to_s
120
129
  redirect_to :action => "show_cookies"
121
130
  end
131
+
122
132
  def show_cookies
123
133
  logger.debug 'Cookies: %s' % cookies.inspect
124
134
  render :text => cookies.to_xml
@@ -10,7 +10,7 @@ background: white;
10
10
  font-size: 11px;
11
11
  line-height: 15px;
12
12
  }
13
- #mainTitle {
13
+ #testBenchContainer h1 {
14
14
  border-bottom: 1px solid #B9B9B9;
15
15
  color: #990000;
16
16
  font-size: 18px;
@@ -18,7 +18,7 @@ background: white;
18
18
  margin-bottom: 20px;
19
19
  padding: 0 0 0 15px;
20
20
  }
21
- h1 {
21
+ #testBenchContainer h2 {
22
22
  border: 1px solid #B9B9B9;
23
23
  color: #990000;
24
24
  font-size: 14px;
@@ -33,14 +33,13 @@ h1 {
33
33
 
34
34
  <div id="testBenchContainer">
35
35
 
36
- <div id="mainTitle">
37
- Rails-portlet test bench
38
- </div>
36
+ <h1>Rails-portlet test bench</h1>
37
+
39
38
  <p style="font-size: 14px;">
40
39
  These are isolated test cases of the Rails-portlet, for manual testing in the browser. The <%= link_to_exit_portlet 'source code', 'http://rails-portlet.rubyforge.org/svn/trunk/caterpillar/portlet_test_bench/' -%> can be used as a reference for using the same features in other Rails apps.
41
40
  </p>
42
41
 
43
- <h1>HTTP</h1>
42
+ <h2>HTTP</h2>
44
43
  <div class="testContainer">
45
44
 
46
45
  <%= link_to 'URL parameter passing',
@@ -61,7 +60,7 @@ These are isolated test cases of the Rails-portlet, for manual testing in the br
61
60
  </div>
62
61
 
63
62
 
64
- <h1>JavaScripts</h1>
63
+ <h2>JavaScripts</h2>
65
64
  <div class="testContainer">
66
65
 
67
66
  <%= link_to 'Simple JavaScript',
@@ -85,7 +84,7 @@ These are isolated test cases of the Rails-portlet, for manual testing in the br
85
84
  </div>
86
85
 
87
86
 
88
- <h1>CSS</h1>
87
+ <h2>CSS</h2>
89
88
  <div class="testContainer">
90
89
 
91
90
  <%= link_to 'Simple CSS',
@@ -97,7 +96,7 @@ These are isolated test cases of the Rails-portlet, for manual testing in the br
97
96
  </div>
98
97
 
99
98
 
100
- <h1>Misc</h1>
99
+ <h2>Misc</h2>
101
100
  <div class="testContainer">
102
101
 
103
102
  <%= link_to 'Image resources',
@@ -122,7 +121,7 @@ These are isolated test cases of the Rails-portlet, for manual testing in the br
122
121
  </div>
123
122
 
124
123
 
125
- <h1>JUnit</h1>
124
+ <h2>JUnit</h2>
126
125
 
127
126
  The JUnit tests are used for automatic testing and they output XML.
128
127