mszczytowski-spring-fu 0.1.1
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.
- data/CHANGELOG +0 -0
- data/LICENSE +20 -0
- data/Manifest +7 -0
- data/README +85 -0
- data/lib/maciej_szczytowski/spring_fu.rb +144 -0
- data/lib/spring-fu.rb +3 -0
- data/spring-fu.gemspec +23 -0
- data/test/maciej_szczytowski/spring_fu_test.rb +6 -0
- metadata +69 -0
data/CHANGELOG
ADDED
|
File without changes
|
data/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2008 Maciej Szczytowski
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest
ADDED
data/README
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
SpringFu
|
|
2
|
+
========
|
|
3
|
+
|
|
4
|
+
This extension ...
|
|
5
|
+
|
|
6
|
+
Installation
|
|
7
|
+
============
|
|
8
|
+
|
|
9
|
+
1. Install JRuby - see wiki.jruby.org for details.
|
|
10
|
+
|
|
11
|
+
2. Install Rails and Warbler:
|
|
12
|
+
|
|
13
|
+
jruby -S gem install rails warbler
|
|
14
|
+
|
|
15
|
+
3. Create Rails application:
|
|
16
|
+
|
|
17
|
+
jruby -S rails spring-on-rails
|
|
18
|
+
|
|
19
|
+
cd spring-on-rails
|
|
20
|
+
|
|
21
|
+
4. Create Warbler configuration file:
|
|
22
|
+
|
|
23
|
+
jruby -S warble config
|
|
24
|
+
|
|
25
|
+
5. Copy Spring and CommonsLogging jars into lib directory:
|
|
26
|
+
|
|
27
|
+
cp %PATH_TO_JARS_REPOSITORY%/spring.jar lib
|
|
28
|
+
cp %PATH_TO_REPOSITORY%/commons-logging.jar lib
|
|
29
|
+
|
|
30
|
+
6. Create Spring context and fill it with Your Spring configuration:
|
|
31
|
+
|
|
32
|
+
mkdir config/spring/
|
|
33
|
+
vim config/spring/applicationContext.xml
|
|
34
|
+
|
|
35
|
+
7. Copy web.xml template from Warbler into config directory:
|
|
36
|
+
|
|
37
|
+
cp %PATH_TO_GEMS_REPOSITORY%/warbler-%VERSION%/web.xml.erb config
|
|
38
|
+
|
|
39
|
+
vim config/web.xml.erb
|
|
40
|
+
|
|
41
|
+
8. Add Spring listener into web.xml.erb file:
|
|
42
|
+
|
|
43
|
+
<context-param>
|
|
44
|
+
<param-name>contextConfigLocation</param-name>
|
|
45
|
+
<param-value>/WEB-INF/config/spring/applicationContext.xml</param-value>
|
|
46
|
+
</context-param>
|
|
47
|
+
|
|
48
|
+
<listener>
|
|
49
|
+
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
|
|
50
|
+
</listener>
|
|
51
|
+
|
|
52
|
+
9. Add gem dependency in your Rails config:
|
|
53
|
+
|
|
54
|
+
config.gem 'mszczytowski-spring-fu', :lib => 'spring-fu', :source => 'http://gems.github.com'
|
|
55
|
+
|
|
56
|
+
10. Add gem dependency in Warbler config:
|
|
57
|
+
|
|
58
|
+
config.gems << "spring-fu"
|
|
59
|
+
|
|
60
|
+
10. Install gems:
|
|
61
|
+
|
|
62
|
+
jruby -S rake gems:install
|
|
63
|
+
|
|
64
|
+
11. Create war file:
|
|
65
|
+
|
|
66
|
+
jruby -S rake war
|
|
67
|
+
|
|
68
|
+
12. Deploy on Tomcat and have fun.
|
|
69
|
+
|
|
70
|
+
Usage
|
|
71
|
+
=====
|
|
72
|
+
|
|
73
|
+
class YourController < ApplicationController
|
|
74
|
+
|
|
75
|
+
spring_bean :useful_bean
|
|
76
|
+
spring_bean :another_bean, :as => "new_name"
|
|
77
|
+
|
|
78
|
+
def your_method
|
|
79
|
+
useful_bean.do_sth_cool_in_spring_bean
|
|
80
|
+
new_name.add(2, 2)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
Copyright (c) 2008 Maciej Szczytowski, released under the MIT license
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
module MaciejSzczytowski
|
|
2
|
+
module SpringFu
|
|
3
|
+
|
|
4
|
+
ERROR_NOT_JRUBY = "calling java methods is allowed only in JRuby environment"
|
|
5
|
+
|
|
6
|
+
ERROR_SERVLET_CONTEXT_NOT_FOUND = "servlet context cannot be found"
|
|
7
|
+
|
|
8
|
+
ERROR_SPRING_CONTEXT_NOT_FOUND = "spring context cannot be found"
|
|
9
|
+
|
|
10
|
+
ERROR_SPRING_CLASS_NOT_IMPORTED = "class org.springframework.web.context.support.WebApplicationContextUtils is not found"
|
|
11
|
+
|
|
12
|
+
ERROR_BEAN_NOT_FOUND = "bean %s cannot be found in spring context"
|
|
13
|
+
|
|
14
|
+
def self.included(base)
|
|
15
|
+
if jruby? and servlet_context_exists? and spring_imported? and spring_context_exists?
|
|
16
|
+
base.send(:extend, ClassMethods)
|
|
17
|
+
else
|
|
18
|
+
base.send(:extend, MockClassMethods)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Example:
|
|
23
|
+
#
|
|
24
|
+
# class YourController < ApplicationController
|
|
25
|
+
# spring_bean :useful_bean
|
|
26
|
+
# spring_bean :another_bean, :as => "new_name"
|
|
27
|
+
#
|
|
28
|
+
# def your_method
|
|
29
|
+
# useful_bean.do_sth_cool_in_spring_bean
|
|
30
|
+
# new_name.add(2, 2)
|
|
31
|
+
# end
|
|
32
|
+
# end
|
|
33
|
+
#
|
|
34
|
+
module ClassMethods
|
|
35
|
+
|
|
36
|
+
def spring_bean(name, options = {})
|
|
37
|
+
# use bean name as accessor, unless other is provided
|
|
38
|
+
options[:as] ||= name
|
|
39
|
+
|
|
40
|
+
# nil is default value, unless other is provided
|
|
41
|
+
options[:default] ||= nil
|
|
42
|
+
options[:allow_nil] ||= false
|
|
43
|
+
|
|
44
|
+
bean_name = nil
|
|
45
|
+
|
|
46
|
+
if bean_exists_in_spring_context?(name)
|
|
47
|
+
bean_name = name
|
|
48
|
+
elsif bean_exists_in_spring_context?(name.to_s.camelize(:lower).to_sym)
|
|
49
|
+
bean_name = name.to_s.camelize(:lower).to_sym
|
|
50
|
+
elsif bean_exists_in_spring_context?(name.to_s.camelize.to_sym)
|
|
51
|
+
bean_name = name.to_s.camelize.to_sym
|
|
52
|
+
elsif bean_exists_in_spring_context?(name.to_s.underscore.to_sym)
|
|
53
|
+
bean_name = name.to_s.underscore.to_sym
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
if bean_name
|
|
57
|
+
define_method(name) do
|
|
58
|
+
self.class.send(:get_bean_from_spring_context, bean_name)
|
|
59
|
+
end
|
|
60
|
+
elsif options[:default] or options[:allow_nil]
|
|
61
|
+
# there is no bean with given name, return default value
|
|
62
|
+
# when default is not nil, allow_nil options is not significant
|
|
63
|
+
define_method(name) do
|
|
64
|
+
options[:default]
|
|
65
|
+
end
|
|
66
|
+
else
|
|
67
|
+
# there is no bean with given name, raise an error
|
|
68
|
+
raise MaciejSzczytowski::SpringFu::ERROR_BEAN_NOT_FOUND % name.to_s
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
private
|
|
73
|
+
|
|
74
|
+
def get_bean_from_spring_context(bean_name)
|
|
75
|
+
get_spring_context.get_bean(bean_name.to_s)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def get_spring_context
|
|
79
|
+
WebApplicationContextUtils.get_web_application_context($servlet_context)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def bean_exists_in_spring_context?(bean_name)
|
|
83
|
+
get_spring_context.contains_bean(bean_name.to_s)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
module MockClassMethods
|
|
89
|
+
|
|
90
|
+
def spring_bean(name, options = {})
|
|
91
|
+
define_method(name) do
|
|
92
|
+
MaciejSzczytowski::SpringFu::MOCK_BEAN
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
private
|
|
99
|
+
|
|
100
|
+
def self.jruby?
|
|
101
|
+
unless defined? JRUBY_VERSION
|
|
102
|
+
define_mock_bean_for_error MaciejSzczytowski::SpringFu::ERROR_NOT_JRUBY
|
|
103
|
+
else
|
|
104
|
+
true
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def self.servlet_context_exists?
|
|
109
|
+
unless $servlet_context
|
|
110
|
+
define_mock_bean_for_error MaciejSzczytowski::SpringFu::ERROR_SERVLET_CONTEXT_NOT_FOUND
|
|
111
|
+
else
|
|
112
|
+
true
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def self.spring_context_exists?
|
|
117
|
+
unless WebApplicationContextUtils.get_web_application_context($servlet_context)
|
|
118
|
+
define_mock_bean_for_error MaciejSzczytowski::SpringFu::ERROR_SPRING_CONTEXT_NOT_FOUND
|
|
119
|
+
else
|
|
120
|
+
true
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def self.spring_imported?
|
|
125
|
+
#import org.springframework.web.context.support.WebApplicationContextUtils
|
|
126
|
+
#rescue NameError
|
|
127
|
+
#define_mock_bean_for_error MaciejSzczytowski::SpringFu::ERROR_SPRING_CLASS_NOT_IMPORTED
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def self.define_mock_bean_for_error(error_message)
|
|
131
|
+
mock_bean = nil
|
|
132
|
+
def mock_bean.method_missing(meth,*args)
|
|
133
|
+
raise MaciejSzczytowski::SpringFu::ERROR_MESSAGE
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
const_set(:ERROR_MESSAGE, error_message)
|
|
137
|
+
const_set(:MOCK_BEAN, mock_bean)
|
|
138
|
+
|
|
139
|
+
false
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
end
|
data/lib/spring-fu.rb
ADDED
data/spring-fu.gemspec
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Gem::Specification.new do |s|
|
|
2
|
+
s.name = %q{spring-fu}
|
|
3
|
+
s.version = "0.1.1"
|
|
4
|
+
|
|
5
|
+
s.specification_version = 2 if s.respond_to? :specification_version=
|
|
6
|
+
|
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
8
|
+
|
|
9
|
+
s.authors = ["Maciej Szczytowski"]
|
|
10
|
+
s.date = %q{2008-07-30}
|
|
11
|
+
s.description = %q{SpringFramework support for JRuby on Rails application.}
|
|
12
|
+
s.email = %q{mszczytowski (at) gmail (dot) com}
|
|
13
|
+
s.extra_rdoc_files = ["README", "CHANGELOG", "LICENSE"]
|
|
14
|
+
s.files = ["spring-fu.gemspec", "lib/spring-fu.rb", "lib/maciej_szczytowski/spring_fu.rb", "Manifest", "README", "CHANGELOG", "LICENSE", "test/maciej_szczytowski/spring_fu_test.rb"]
|
|
15
|
+
s.has_rdoc = true
|
|
16
|
+
s.homepage = %q{http://github.com/mszczytowski/spring-fu}
|
|
17
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "spring-fu", "--main", "README", "CHANGELOG", "LICENSE"]
|
|
18
|
+
s.require_paths = ["lib"]
|
|
19
|
+
s.rubyforge_project = %q{spring-fu}
|
|
20
|
+
s.rubygems_version = %q{1.2.0}
|
|
21
|
+
s.summary = %q{SpringFramework support for JRuby on Rails application.}
|
|
22
|
+
s.test_files = ["test/maciej_szczytowski/spring_fu_test.rb"]
|
|
23
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: mszczytowski-spring-fu
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Maciej Szczytowski
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2008-07-30 00:00:00 -07:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies: []
|
|
15
|
+
|
|
16
|
+
description: SpringFramework support for JRuby on Rails application.
|
|
17
|
+
email: mszczytowski (at) gmail (dot) com
|
|
18
|
+
executables: []
|
|
19
|
+
|
|
20
|
+
extensions: []
|
|
21
|
+
|
|
22
|
+
extra_rdoc_files:
|
|
23
|
+
- README
|
|
24
|
+
- CHANGELOG
|
|
25
|
+
- LICENSE
|
|
26
|
+
files:
|
|
27
|
+
- spring-fu.gemspec
|
|
28
|
+
- lib/spring-fu.rb
|
|
29
|
+
- lib/maciej_szczytowski/spring_fu.rb
|
|
30
|
+
- Manifest
|
|
31
|
+
- README
|
|
32
|
+
- CHANGELOG
|
|
33
|
+
- LICENSE
|
|
34
|
+
- test/maciej_szczytowski/spring_fu_test.rb
|
|
35
|
+
has_rdoc: true
|
|
36
|
+
homepage: http://github.com/mszczytowski/spring-fu
|
|
37
|
+
post_install_message:
|
|
38
|
+
rdoc_options:
|
|
39
|
+
- --line-numbers
|
|
40
|
+
- --inline-source
|
|
41
|
+
- --title
|
|
42
|
+
- spring-fu
|
|
43
|
+
- --main
|
|
44
|
+
- README
|
|
45
|
+
- CHANGELOG
|
|
46
|
+
- LICENSE
|
|
47
|
+
require_paths:
|
|
48
|
+
- lib
|
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: "0"
|
|
54
|
+
version:
|
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
|
+
requirements:
|
|
57
|
+
- - ">="
|
|
58
|
+
- !ruby/object:Gem::Version
|
|
59
|
+
version: "0"
|
|
60
|
+
version:
|
|
61
|
+
requirements: []
|
|
62
|
+
|
|
63
|
+
rubyforge_project: spring-fu
|
|
64
|
+
rubygems_version: 1.2.0
|
|
65
|
+
signing_key:
|
|
66
|
+
specification_version: 2
|
|
67
|
+
summary: SpringFramework support for JRuby on Rails application.
|
|
68
|
+
test_files:
|
|
69
|
+
- test/maciej_szczytowski/spring_fu_test.rb
|