trinidad_hotdeploy_extension 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 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.
data/README ADDED
@@ -0,0 +1,31 @@
1
+ Trinidad hotdeploy extension
2
+ ======
3
+
4
+ # DESCRIPTION
5
+
6
+ Extension to allow Trinidad to redeploy an application each time a file, for instance tmp/restart.txt, is modified without restarting Tomcat.
7
+
8
+ [WARNING] This extension only works with Trinidad 0.9.0 or avobe.
9
+
10
+ # INSTALL
11
+
12
+ $ jruby -S gem install trinidad_hotdeploy_extensions
13
+
14
+ # CONFIGURE
15
+
16
+ To configure it, you need to add it into the extensions section of a web application, it also allows to configure the name of the file to monitor and the period that it waits to check the file.
17
+
18
+ ---
19
+ web_apps:
20
+ default:
21
+ extensions:
22
+ hotdeploy:
23
+ monitor: tmp/restart.txt # this parameter is optional, the default value is tmp/restart.txt
24
+ delay: 30000 # in milliseconds, this parameter is optional, the default value is 1 second
25
+
26
+
27
+ You can find further information on how to write your own extension in the wiki: http://wiki.github.com/calavera/trinidad/extensions
28
+
29
+ # Copyright
30
+
31
+ Copyright (c) 2010 David Calavera. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,149 @@
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
+ task :default => :spec
47
+
48
+ require 'spec/rake/spectask'
49
+ Spec::Rake::SpecTask.new(:spec) do |spec|
50
+ spec.libs << 'lib' << 'spec'
51
+ spec.spec_opts = ['--options', 'spec/spec.opts']
52
+ spec.spec_files = FileList['spec/**/*_spec.rb']
53
+ end
54
+
55
+
56
+ desc "Generate RCov test coverage and open in your browser"
57
+ task :coverage do
58
+ require 'rcov'
59
+ sh "rm -fr coverage"
60
+ sh "rcov test/test_*.rb"
61
+ sh "open coverage/index.html"
62
+ end
63
+
64
+ require 'rake/rdoctask'
65
+ Rake::RDocTask.new do |rdoc|
66
+ rdoc.rdoc_dir = 'rdoc'
67
+ rdoc.title = "#{name} #{version}"
68
+ rdoc.rdoc_files.include('README*')
69
+ rdoc.rdoc_files.include('lib/**/*.rb')
70
+ end
71
+
72
+ desc "Open an irb session preloaded with this library"
73
+ task :console do
74
+ sh "irb -rubygems -r ./lib/#{name}.rb"
75
+ end
76
+
77
+ #############################################################################
78
+ #
79
+ # Custom tasks (add your own tasks here)
80
+ #
81
+ #############################################################################
82
+
83
+
84
+
85
+ #############################################################################
86
+ #
87
+ # Packaging tasks
88
+ #
89
+ #############################################################################
90
+
91
+ task :release => :build do
92
+ unless `git branch` =~ /^\* master$/
93
+ puts "You must be on the master branch to release!"
94
+ exit!
95
+ end
96
+ sh "git commit --allow-empty -a -m 'Release #{version}'"
97
+ sh "git tag v#{version}"
98
+ sh "git push origin master"
99
+ sh "git push v#{version}"
100
+ sh "gem push pkg/#{name}-#{version}.gem"
101
+ end
102
+
103
+ task :build => ['ant:build', 'gemspec'] do
104
+ sh "mkdir -p pkg"
105
+ sh "gem build #{gemspec_file}"
106
+ sh "mv #{gem_file} pkg"
107
+ end
108
+
109
+ task :gemspec => :validate do
110
+ # read spec file and split out manifest section
111
+ spec = File.read(gemspec_file)
112
+ head, manifest, tail = spec.split(" # = MANIFEST =\n")
113
+
114
+ # replace name version and date
115
+ replace_header(head, :name)
116
+ replace_header(head, :version)
117
+ replace_header(head, :date)
118
+ #comment this out if your rubyforge_project has a different name
119
+ replace_header(head, :rubyforge_project)
120
+
121
+ # determine file list from git ls-files
122
+ files = `git ls-files`.
123
+ split("\n").
124
+ sort.
125
+ reject { |file| file =~ /^\./ }.
126
+ reject { |file| file =~ /^(rdoc|pkg|src|trinidad-libs|racklib)/ }.
127
+ map { |file| " #{file}" }.
128
+ join("\n")
129
+
130
+ files << "\n trinidad-libs/trinidad-hotdeploy-extension.jar"
131
+
132
+ # piece file back together and write
133
+ manifest = " s.files = %w[\n#{files}\n ]\n"
134
+ spec = [head, manifest, tail].join(" # = MANIFEST =\n")
135
+ File.open(gemspec_file, 'w') { |io| io.write(spec) }
136
+ puts "Updated #{gemspec_file}"
137
+ end
138
+
139
+ task :validate do
140
+ libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
141
+ unless libfiles.empty?
142
+ puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
143
+ exit!
144
+ end
145
+ unless Dir['VERSION*'].empty?
146
+ puts "A `VERSION` file at root level violates Gem best practices."
147
+ exit!
148
+ end
149
+ end
@@ -0,0 +1,19 @@
1
+ module Trinidad
2
+ module Extensions
3
+ require File.expand_path('../../trinidad-libs/trinidad-hotdeploy-extension.jar', __FILE__)
4
+
5
+ class HotdeployWebAppExtension < WebAppExtension
6
+ VERSION = '0.1.0'
7
+
8
+ def configure(tomcat, app_context)
9
+ @options[:monitor] ||= File.join(app_context.doc_base, 'tmp/restart.txt')
10
+ monitor = File.expand_path(@options[:monitor])
11
+ delay = @options[:delay] || 1000
12
+
13
+ listener = org.jruby.trinidad.HotDeployLifecycleListener.new(app_context, monitor, delay)
14
+ app_context.addLifecycleListener(listener)
15
+ listener
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,38 @@
1
+ require 'ant'
2
+ require 'fileutils'
3
+ include FileUtils
4
+
5
+ TARGET_DIR = 'target'
6
+ LIBS_DIR = 'trinidad-libs'
7
+ JAR_NAME = 'trinidad-hotdeploy-extension.jar'
8
+
9
+ namespace :ant do
10
+ desc 'Clean the java target directory'
11
+ task :clean do
12
+ rm_f TARGET_DIR
13
+ rm_f "#{LIBS_DIR}/#{JAR_NAME}"
14
+ end
15
+
16
+ desc 'Compile the java classes'
17
+ task :compile => :clean do
18
+ opts = {
19
+ :fork => 'true',
20
+ :failonerror => 'true',
21
+ :srcdir => 'src/main/java',
22
+ :destdir => TARGET_DIR,
23
+ :classpath => Dir.glob('trinidad-libs/*.jar').join(':')
24
+ }
25
+
26
+ mkdir_p TARGET_DIR
27
+ ant.javac(opts)
28
+ end
29
+
30
+ desc 'Create the jar file'
31
+ task :build => :compile do
32
+ opts = {
33
+ :destfile => "#{LIBS_DIR}/#{JAR_NAME}",
34
+ :basedir => TARGET_DIR
35
+ }
36
+ ant.jar(opts)
37
+ end
38
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format specdoc
@@ -0,0 +1,25 @@
1
+ require 'rubygems'
2
+ begin
3
+ require 'spec'
4
+ rescue LoadError
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ require 'trinidad'
10
+ begin
11
+ require 'trinidad/jars'
12
+ rescue LoadError
13
+ gem 'trinidad_jars'
14
+ require 'trinidad/jars'
15
+ end
16
+
17
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
18
+
19
+ require 'java'
20
+ require 'trinidad_hotdeploy_extension'
21
+ require 'mocha'
22
+
23
+ Spec::Runner.configure do |config|
24
+ config.mock_with :mocha
25
+ end
@@ -0,0 +1,46 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'optparse'
3
+
4
+ describe Trinidad::Extensions::HotdeployWebAppExtension do
5
+ subject { Trinidad::Extensions::HotdeployWebAppExtension.new({}) }
6
+
7
+ before(:each) do
8
+ @tomcat = Trinidad::Tomcat::Tomcat.new
9
+ @context = Trinidad::Tomcat::StandardContext.new
10
+ @context.doc_base = Dir.pwd
11
+ end
12
+
13
+ it "uses tmp/restart.txt as monitor by default" do
14
+ listener = subject.configure(@tomcat, @context)
15
+ listener.monitor.should =~ /tmp\/restart.txt$/
16
+ end
17
+
18
+ it "can use a custom monitor file" do
19
+ ext = Trinidad::Extensions::HotdeployWebAppExtension.new({
20
+ :monitor => 'tmp/redeploy.txt'
21
+ })
22
+ listener = ext.configure(@tomcat, @context)
23
+ listener.monitor.should =~ /tmp\/redeploy.txt$/
24
+ end
25
+
26
+ it "uses the base directory when the custom path is relative" do
27
+ ext = Trinidad::Extensions::HotdeployWebAppExtension.new({
28
+ :monitor => 'tmp/redeploy.txt'
29
+ })
30
+ listener = ext.configure(@tomcat, @context)
31
+ listener.monitor.should =~ /^#{File.expand_path('../../', __FILE__)}/
32
+ end
33
+
34
+ it "checks the file each second by default" do
35
+ listener = subject.configure(@tomcat, @context)
36
+ listener.delay.should == 1000
37
+ end
38
+
39
+ it "can use a custom delay" do
40
+ ext = Trinidad::Extensions::HotdeployWebAppExtension.new({
41
+ :delay => 30000
42
+ })
43
+ listener = ext.configure(@tomcat, @context)
44
+ listener.delay.should == 30000
45
+ end
46
+ 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_hotdeploy_extension'
16
+ s.version = '0.1.0'
17
+ s.date = '2010-04-28'
18
+ s.rubyforge_project = 'trinidad_hotdeploy_extension'
19
+
20
+ ## Make sure your summary is short. The description may be as long
21
+ ## as you like.
22
+ s.summary = "Hot deployer for Trinidad"
23
+ s.description = "Perform hot deploys on Trinidad ala Passenger"
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_hotdeploy_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 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_jars')
44
+
45
+ ## List your development dependencies here. Development dependencies are
46
+ ## those that are only needed during development
47
+ s.add_development_dependency('rspec')
48
+ s.add_development_dependency('mocha')
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
+ LICENSE
56
+ README
57
+ Rakefile
58
+ lib/trinidad_hotdeploy_extension.rb
59
+ rakelib/build.rake
60
+ spec/spec.opts
61
+ spec/spec_helper.rb
62
+ spec/trinidad_hotdeploy_extension_spec.rb
63
+ trinidad_hotdeploy_extension.gemspec
64
+ trinidad-libs/trinidad-hotdeploy-extension.jar
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 =~ /^test\/test_.*\.rb/ }
71
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trinidad_hotdeploy_extension
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - David Calavera
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-28 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: trinidad_jars
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: rspec
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
41
+ version: "0"
42
+ type: :development
43
+ version_requirements: *id002
44
+ - !ruby/object:Gem::Dependency
45
+ name: mocha
46
+ prerelease: false
47
+ requirement: &id003 !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ segments:
52
+ - 0
53
+ version: "0"
54
+ type: :development
55
+ version_requirements: *id003
56
+ description: Perform hot deploys on Trinidad ala Passenger
57
+ email: calavera@apache.org
58
+ executables: []
59
+
60
+ extensions: []
61
+
62
+ extra_rdoc_files:
63
+ - README
64
+ - LICENSE
65
+ files:
66
+ - LICENSE
67
+ - README
68
+ - Rakefile
69
+ - lib/trinidad_hotdeploy_extension.rb
70
+ - rakelib/build.rake
71
+ - spec/spec.opts
72
+ - spec/spec_helper.rb
73
+ - spec/trinidad_hotdeploy_extension_spec.rb
74
+ - trinidad_hotdeploy_extension.gemspec
75
+ - trinidad-libs/trinidad-hotdeploy-extension.jar
76
+ has_rdoc: true
77
+ homepage: http://github.com/calavera/trinidad_hotdeploy_extension
78
+ licenses: []
79
+
80
+ post_install_message:
81
+ rdoc_options:
82
+ - --charset=UTF-8
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ segments:
97
+ - 0
98
+ version: "0"
99
+ requirements: []
100
+
101
+ rubyforge_project: trinidad_hotdeploy_extension
102
+ rubygems_version: 1.3.6
103
+ signing_key:
104
+ specification_version: 2
105
+ summary: Hot deployer for Trinidad
106
+ test_files: []
107
+