trinidad_diagnostics_extension 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'trinidad'
4
+ gem 'jruby-lint', '>=0.3.0'
5
+
6
+ group :test do
7
+ gem 'rspec'
8
+ end
@@ -0,0 +1,34 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ bouncy-castle-java (1.5.0146.1)
5
+ diff-lcs (1.1.2)
6
+ jruby-lint (0.3.0)
7
+ jruby-openssl
8
+ nokogiri (= 1.5.0.beta.4)
9
+ term-ansicolor
10
+ jruby-openssl (0.7.4)
11
+ bouncy-castle-java
12
+ jruby-rack (1.0.9)
13
+ nokogiri (1.5.0.beta.4-java)
14
+ rspec (2.5.0)
15
+ rspec-core (~> 2.5.0)
16
+ rspec-expectations (~> 2.5.0)
17
+ rspec-mocks (~> 2.5.0)
18
+ rspec-core (2.5.2)
19
+ rspec-expectations (2.5.0)
20
+ diff-lcs (~> 1.1.2)
21
+ rspec-mocks (2.5.0)
22
+ term-ansicolor (1.0.5)
23
+ trinidad (1.2.1)
24
+ jruby-rack (>= 1.0.9)
25
+ trinidad_jars (>= 1.0.1)
26
+ trinidad_jars (1.0.1)
27
+
28
+ PLATFORMS
29
+ java
30
+
31
+ DEPENDENCIES
32
+ jruby-lint (>= 0.3.0)
33
+ rspec
34
+ trinidad
@@ -0,0 +1,5 @@
1
+ == 0.1.0 (2011-07-05)
2
+
3
+ * Initial release
4
+ * Create diagnostics.html
5
+ * Allow debug mode
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 David Calavera
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.
@@ -0,0 +1,33 @@
1
+ # Trinidad diagnostics extension
2
+
3
+ Trinidad diagnostics let's you know the level of compatibility between
4
+ your application and JRuby.
5
+
6
+ It uses [JRuby lint](http://github.com/jruby/jruby-lint)
7
+ under the hood to inspect your code before Trinidad starts up your
8
+ application. Once your code is audited jruby-lint generates an html report
9
+ that's located under your public directory, so you can access to it from a
10
+ browser. I.e if the application path is `/` the report is located under
11
+ `/diagnostics.html`.
12
+
13
+ ## Installation
14
+
15
+ Install the gem trinidad_diagnostics_extension or add it to your Gemfile.
16
+
17
+ ## Configuration
18
+
19
+ Add the extension to the Trinidad's configuration file:
20
+
21
+ ---
22
+ extensions:
23
+ diagnostics:
24
+
25
+ Or load it from the command line:
26
+
27
+ $ trinidad --load diagnostics
28
+
29
+ ### Further configuration
30
+
31
+ There is a debug mode that prints the results by the console log to. Add the
32
+ option `debug: true` under the extension configuration or use the option
33
+ `--diagnostics-debug` from the command line.
@@ -0,0 +1,131 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'date'
4
+
5
+ #############################################################################
6
+ #
7
+ # Helper functions
8
+ #
9
+ #############################################################################
10
+
11
+ def name
12
+ @name ||= Dir['*.gemspec'].first.split('.').first
13
+ end
14
+
15
+ def version
16
+ line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
17
+ line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
18
+ end
19
+
20
+ def date
21
+ Date.today.to_s
22
+ end
23
+
24
+ def rubyforge_project
25
+ name
26
+ end
27
+
28
+ def gemspec_file
29
+ "#{name}.gemspec"
30
+ end
31
+
32
+ def gem_file
33
+ "#{name}-#{version}.gem"
34
+ end
35
+
36
+ def replace_header(head, header_name)
37
+ head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
38
+ end
39
+
40
+ #############################################################################
41
+ #
42
+ # Standard tasks
43
+ #
44
+ #############################################################################
45
+
46
+ desc "Open an irb session preloaded with this library"
47
+ task :console do
48
+ sh "irb -rubygems -r ./lib/#{name}.rb"
49
+ end
50
+
51
+ #############################################################################
52
+ #
53
+ # Custom tasks (add your own tasks here)
54
+ #
55
+ #############################################################################
56
+
57
+ task :default => :spec
58
+
59
+ require 'rspec/core/rake_task'
60
+
61
+ RSpec::Core::RakeTask.new(:spec) do |spec|
62
+ spec.rspec_opts = ['--colour', "--format documentation"]
63
+ end
64
+
65
+ #############################################################################
66
+ #
67
+ # Packaging tasks
68
+ #
69
+ #############################################################################
70
+
71
+ task :release => :build do
72
+ unless `git branch` =~ /^\* master$/
73
+ puts "You must be on the master branch to release!"
74
+ exit!
75
+ end
76
+ sh "git commit --allow-empty -a -m 'Release #{version}'"
77
+ sh "git tag v#{version}"
78
+ sh "git push origin master"
79
+ sh "git push --tags"
80
+ sh "gem push pkg/#{name}-#{version}.gem"
81
+ end
82
+
83
+ task :build => :gemspec do
84
+ sh "mkdir -p pkg"
85
+ sh "gem build #{gemspec_file}"
86
+ sh "mv #{gem_file} pkg"
87
+ end
88
+
89
+ task :install => :build do
90
+ sh "gem install pkg/#{name}-#{version}.gem"
91
+ end
92
+
93
+ task :gemspec => :validate do
94
+ # read spec file and split out manifest section
95
+ spec = File.read(gemspec_file)
96
+ head, manifest, tail = spec.split(" # = MANIFEST =\n")
97
+
98
+ # replace name version and date
99
+ replace_header(head, :name)
100
+ replace_header(head, :version)
101
+ replace_header(head, :date)
102
+ #comment this out if your rubyforge_project has a different name
103
+ replace_header(head, :rubyforge_project)
104
+
105
+ # determine file list from git ls-files
106
+ files = `git ls-files`.
107
+ split("\n").
108
+ sort.
109
+ reject { |file| file =~ /^\./ }.
110
+ reject { |file| file =~ /^(rdoc|pkg|src|trinidad-libs|rakelib)/ }.
111
+ map { |file| " #{file}" }.
112
+ join("\n")
113
+
114
+ # piece file back together and write
115
+ manifest = " s.files = %w[\n#{files}\n ]\n"
116
+ spec = [head, manifest, tail].join(" # = MANIFEST =\n")
117
+ File.open(gemspec_file, 'w') { |io| io.write(spec) }
118
+ puts "Updated #{gemspec_file}"
119
+ end
120
+
121
+ task :validate do
122
+ libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
123
+ unless libfiles.empty?
124
+ puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
125
+ exit!
126
+ end
127
+ unless Dir['VERSION*'].empty?
128
+ puts "A `VERSION` file at root level violates Gem best practices."
129
+ exit!
130
+ end
131
+ end
@@ -0,0 +1,63 @@
1
+ module Trinidad
2
+ module Extensions
3
+ gem 'jruby-lint'
4
+ require 'jruby/lint'
5
+
6
+ class DiagnosticsWebAppExtension < WebAppExtension
7
+ VERSION = '0.1.0'
8
+
9
+ def configure(tomcat, app_context)
10
+ app_context.add_lifecycle_listener DiagnosticsListener.new(@options[:debug])
11
+ end
12
+ end
13
+
14
+ class DiagnosticsOptionsExtension < OptionsExtension
15
+ def configure(parser, default_options)
16
+ default_options[:extensions] ||= {}
17
+ default_options[:extensions][:diagnostics] = {}
18
+
19
+ parser.on('--dd', '--diagnostics-debug', 'Append diagnostics to the console log') do
20
+ default_options[:extensions][:diagnostics] ||= {}
21
+ default_options[:extensions][:diagnostics][:debug] = true
22
+ end
23
+ end
24
+ end
25
+
26
+ class DiagnosticsListener
27
+ require 'ostruct'
28
+ include Trinidad::Tomcat::LifecycleListener
29
+
30
+ def initialize(debug)
31
+ @debug = debug || false
32
+ end
33
+
34
+ def lifecycleEvent(event)
35
+ if event.type == Trinidad::Tomcat::Lifecycle::BEFORE_START_EVENT
36
+ puts '-- Trinidad diagnostics on' if @debug
37
+ app_context = event.lifecycle
38
+
39
+ options = lint_options(app_context)
40
+
41
+ run_diagnostics(options)
42
+ puts '-- Trinidad diagnostics off' if @debug
43
+ end
44
+ end
45
+
46
+ def run_diagnostics(options)
47
+ JRuby::Lint::Project.new(options).run
48
+ end
49
+
50
+ def lint_options(app_context)
51
+ OpenStruct.new(
52
+ :html => report_output(app_context),
53
+ :chdir => app_context.doc_base,
54
+ :text => @debug)
55
+ end
56
+
57
+ def report_output(app_context)
58
+ public_root = app_context.find_parameter('public.root') || 'public'
59
+ File.join(public_root, 'diagnostics.html')
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,6 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+
3
+ require 'java'
4
+ require 'rspec'
5
+ require 'trinidad'
6
+ require 'trinidad_diagnostics_extension'
@@ -0,0 +1,73 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Trinidad::Extensions::DiagnosticsWebAppExtension' do
4
+ it "add the diagnostics listener to the application context" do
5
+ context = Trinidad::Tomcat::StandardContext.new
6
+ extension = Trinidad::Extensions::DiagnosticsWebAppExtension.new {}
7
+ extension.configure(nil, context)
8
+
9
+ context.find_lifecycle_listeners.should have(1).listener
10
+ end
11
+ end
12
+
13
+ describe 'Trinidad::Extensions::DiagnosticsListener' do
14
+ subject { Trinidad::Extensions::DiagnosticsListener }
15
+ let(:context) { Trinidad::Tomcat::StandardContext.new }
16
+
17
+ it 'keeps the report file under the public root' do
18
+ listener = subject.new(false)
19
+ context.add_parameter('public.root', 'foo')
20
+
21
+ file_path = listener.report_output(context)
22
+ file_path.should == 'foo/diagnostics.html'
23
+ end
24
+
25
+ it "uses `public' as default path to keep the report" do
26
+ listener = subject.new(false)
27
+
28
+ file_path = listener.report_output(context)
29
+ file_path.should == 'public/diagnostics.html'
30
+ end
31
+
32
+ it "uses the context doc base as root directory to inspect" do
33
+ listener = subject.new(false)
34
+ context.doc_base = Dir.pwd
35
+
36
+ options = listener.lint_options(context)
37
+ options.chdir.should == Dir.pwd
38
+ end
39
+
40
+ it "appends a text reporter when the debug option is enabled" do
41
+ listener = subject.new(true)
42
+
43
+ options = listener.lint_options(context)
44
+ options.text.should == true
45
+ end
46
+
47
+ it "uses the report output as html report file path" do
48
+ listener = subject.new(true)
49
+
50
+ options = listener.lint_options(context)
51
+ options.html.should == listener.report_output(context)
52
+ end
53
+
54
+ it "runs the diagnostics before the application starts" do
55
+ listener = subject.new(false)
56
+ event = mock
57
+ event.should_receive(:type).and_return Trinidad::Tomcat::Lifecycle::BEFORE_START_EVENT
58
+ event.should_receive(:lifecycle).and_return context
59
+ listener.should_receive(:run_diagnostics)
60
+
61
+ listener.lifecycleEvent event
62
+ end
63
+
64
+ it "does not run the diagnostics on any other event" do
65
+ listener = subject.new(false)
66
+ event = mock
67
+ event.should_receive(:type).and_return Trinidad::Tomcat::Lifecycle::AFTER_START_EVENT
68
+ event.should_not_receive(:lifecycle)
69
+ listener.should_not_receive(:run_diagnostics)
70
+
71
+ listener.lifecycleEvent event
72
+ end
73
+ end
@@ -0,0 +1,71 @@
1
+ ## This is the rakegem gemspec template. Make sure you read and understand
2
+ ## all of the comments. Some sections require modification, and others can
3
+ ## be deleted if you don't need them. Once you understand the contents of
4
+ ## this file, feel free to delete any comments that begin with two hash marks.
5
+ ## You can find comprehensive Gem::Specification documentation, at
6
+ ## http://docs.rubygems.org/read/chapter/20
7
+ Gem::Specification.new do |s|
8
+ s.specification_version = 2 if s.respond_to? :specification_version=
9
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
10
+ s.rubygems_version = '1.3.5'
11
+
12
+ ## Leave these as is they will be modified for you by the rake gemspec task.
13
+ ## If your rubyforge_project name is different, then edit it and comment out
14
+ ## the sub! line in the Rakefile
15
+ s.name = 'trinidad_diagnostics_extension'
16
+ s.version = '0.1.0'
17
+ s.date = '2011-07-05'
18
+ s.rubyforge_project = 'trinidad_diagnostics_extension'
19
+
20
+ ## Make sure your summary is short. The description may be as long
21
+ ## as you like.
22
+ s.summary = "JRuby diagnostics for Trinidad"
23
+ s.description = "Plugin that uses JRuby-lint to run diagnostics for the application before Trinidad starts it up"
24
+
25
+ ## List the primary authors. If there are a bunch of authors, it's probably
26
+ ## better to set the email to an email list or something. If you don't have
27
+ ## a custom homepage, consider using your GitHub URL or the like.
28
+ s.authors = ["David Calavera"]
29
+ s.email = 'calavera@apache.org'
30
+ s.homepage = 'http://github.com/calavera/trinidad_diagnostics_extension'
31
+
32
+ ## This gets added to the $LOAD_PATH so that 'lib/NAME.rb' can be required as
33
+ ## require 'NAME.rb' or'/lib/NAME/file.rb' can be as require 'NAME/file.rb'
34
+ s.require_paths = %w[lib]
35
+
36
+ ## Specify any RDoc options here. You'll want to add your README and
37
+ ## LICENSE files to the extra_rdoc_files list.
38
+ s.rdoc_options = ["--charset=UTF-8"]
39
+ s.extra_rdoc_files = %w[README.md LICENSE]
40
+
41
+ ## List your runtime dependencies here. Runtime dependencies are those
42
+ ## that are needed for an end user to actually USE your code.
43
+ s.add_dependency('trinidad')
44
+ s.add_dependency('jruby-lint', '>=0.3.0')
45
+
46
+ ## List your development dependencies here. Development dependencies are
47
+ ## those that are only needed during development
48
+ s.add_development_dependency('rspec')
49
+
50
+ ## Leave this section as-is. It will be automatically generated from the
51
+ ## contents of your Git repository via the gemspec task. DO NOT REMOVE
52
+ ## THE MANIFEST COMMENTS, they are used as delimiters by the task.
53
+ # = MANIFEST =
54
+ s.files = %w[
55
+ Gemfile
56
+ Gemfile.lock
57
+ History.txt
58
+ LICENSE
59
+ README.md
60
+ Rakefile
61
+ lib/trinidad_diagnostics_extension.rb
62
+ spec/spec_helper.rb
63
+ spec/trinidad_diagnostics_extension_spec.rb
64
+ trinidad_diagnostics_extension.gemspec
65
+ ]
66
+ # = MANIFEST =
67
+
68
+ ## Test files will be grabbed from the file list. Make sure the path glob
69
+ ## matches what you actually use.
70
+ s.test_files = s.files.select { |path| path =~ /^spec\/.*\_spec.rb/ }
71
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trinidad_diagnostics_extension
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - David Calavera
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-07-05 00:00:00 +02:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: trinidad
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: jruby-lint
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: 0.3.0
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: rspec
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ type: :development
48
+ version_requirements: *id003
49
+ description: Plugin that uses JRuby-lint to run diagnostics for the application before Trinidad starts it up
50
+ email: calavera@apache.org
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ extra_rdoc_files:
56
+ - README.md
57
+ - LICENSE
58
+ files:
59
+ - Gemfile
60
+ - Gemfile.lock
61
+ - History.txt
62
+ - LICENSE
63
+ - README.md
64
+ - Rakefile
65
+ - lib/trinidad_diagnostics_extension.rb
66
+ - spec/spec_helper.rb
67
+ - spec/trinidad_diagnostics_extension_spec.rb
68
+ - trinidad_diagnostics_extension.gemspec
69
+ has_rdoc: true
70
+ homepage: http://github.com/calavera/trinidad_diagnostics_extension
71
+ licenses: []
72
+
73
+ post_install_message:
74
+ rdoc_options:
75
+ - --charset=UTF-8
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: "0"
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: "0"
90
+ requirements: []
91
+
92
+ rubyforge_project: trinidad_diagnostics_extension
93
+ rubygems_version: 1.5.1
94
+ signing_key:
95
+ specification_version: 2
96
+ summary: JRuby diagnostics for Trinidad
97
+ test_files:
98
+ - spec/trinidad_diagnostics_extension_spec.rb