buildr-tomcat 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/COPYING.LESSER ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ buildr-tomcat
2
+ =============
3
+
4
+ buildr-tomcat provides a plugin for Buildr that allows you to run a war-packaged project in an embedded Tomcat.
5
+
6
+ It is largely based on the Jetty plugin, but is somewhat simplified.
7
+
8
+ Installation:
9
+
10
+ git clone https://github.com/technophobia/buildr-tomcat.git
11
+ cd buildr-tomcat
12
+ ./build.sh
13
+
14
+ Example:
15
+
16
+ require 'tomcat'
17
+
18
+ define "my-webapp" do
19
+ compile.with # some dependencies here
20
+ package(:war)
21
+
22
+ task('tomcat') do |task|
23
+ name = 'my-webapp'
24
+ Buildr::Tomcat::explode(self)
25
+ Buildr::Tomcat.new(name, "http://localhost:8084/#{name}", "#{name}/target/#{name}-#{VERSION_NUMBER}").run
26
+
27
+ trap 'SIGINT' do
28
+ puts "Stopping Tomcat"
29
+ tomcat.stop
30
+ end
31
+ Thread.stop
32
+ end
33
+ end
34
+
data/Rakefile ADDED
@@ -0,0 +1,47 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with this
3
+ # work for additional information regarding copyright ownership. The ASF
4
+ # licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+ # To work-around a bug with gemcutter: http://stackoverflow.com/questions/4932881/gemcutter-rake-build-now-throws-undefined-method-write-for-syckemitter
17
+ require 'psych' if RUBY_VERSION >= '1.9.2' && !RUBY_PLATFORM[/java/]
18
+
19
+ # We need JAVA_HOME for most things (setup, spec, etc).
20
+ unless ENV['JAVA_HOME']
21
+ if RUBY_PLATFORM[/java/]
22
+ ENV['JAVA_HOME'] = Java.java.lang.System.getProperty('java.home')
23
+ elsif RUBY_PLATFORM[/darwin/]
24
+ ENV['JAVA_HOME'] = '/System/Library/Frameworks/JavaVM.framework/Home'
25
+ else
26
+ fail "Please set JAVA_HOME first (set JAVA_HOME=... or env JAVA_HOME=... rake ...)"
27
+ end
28
+ end
29
+
30
+
31
+ # Load the Gem specification for the current platform (Ruby or JRuby).
32
+ def spec(platform = RUBY_PLATFORM[/java/] || 'ruby')
33
+ @specs ||= ['ruby', 'java', 'x86-mswin32'].inject({}) { |hash, spec_platform|
34
+ $platform = spec_platform
35
+ hash.update(spec_platform=>Gem::Specification.load('buildr-tomcat.gemspec'))
36
+ }
37
+ @specs[platform]
38
+ end
39
+
40
+ # Tell us if we need sudo for various commands.
41
+ def sudo_needed?
42
+ RbConfig::CONFIG['host_os'] !~ /windows|cygwin|bccwin|cygwin|djgpp|mingw|mswin|wince/i && !ENV['GEM_HOME']
43
+ end
44
+
45
+
46
+ desc 'Clean up all temporary directories used for running tests, creating documentation, packaging, etc.'
47
+ task :clobber
data/lib/tomcat.rb ADDED
@@ -0,0 +1,202 @@
1
+ require 'thread'
2
+
3
+ module Buildr
4
+
5
+ class Tomcat
6
+
7
+ # Which version of Tomcat we're using by default (change with options.tomcat.version).
8
+ VERSION = "6.1.3"
9
+ SLF4J_VERSION = "1.4.3"
10
+
11
+ TOMCAT_VERSION = '7.0.21'
12
+ TOMCAT = [ "org.apache.tomcat.embed:tomcat-embed-jasper:jar:#{TOMCAT_VERSION}", "org.apache.tomcat:tomcat-catalina:jar:#{TOMCAT_VERSION}", "org.apache.tomcat:tomcat-jasper:jar:#{TOMCAT_VERSION}", "org.apache.tomcat:tomcat-servlet-api:jar:#{TOMCAT_VERSION}", "org.apache.tomcat.embed:tomcat-embed-core:jar:#{TOMCAT_VERSION}", "org.apache.tomcat.embed:tomcat-embed-logging-log4j:jar:#{TOMCAT_VERSION}" ]
13
+ TOMCAT << 'buildr-tomcat:buildr-tomcat:jar:1.0.0'
14
+
15
+ Java.classpath << File.dirname(__FILE__)
16
+ Java.classpath << TOMCAT
17
+
18
+
19
+
20
+ # Default URL fort (change with options.tomcat.url).
21
+ URL = "http://localhost:8080"
22
+
23
+ class << self
24
+
25
+ # :call-seq:
26
+ # instance() => Tomcat
27
+ #
28
+ # Returns an instance of Tomcat.
29
+ def instance()
30
+ @instance ||= Tomcat.new("", URL)
31
+ end
32
+
33
+ #
34
+ # Explode a war-file into the target directory.
35
+ #
36
+ #
37
+ def explode(project)
38
+ name = project.name.split(':').last
39
+ dirname = "#{name}/target/#{name}-#{VERSION_NUMBER}"
40
+
41
+ if !File.exists? dirname
42
+ system("unzip -q #{name}/target/#{name}-#{VERSION_NUMBER}.war -d #{dirname}")
43
+ end
44
+ end
45
+ end
46
+
47
+ def initialize(name, url, webAppLocation) #:nodoc:
48
+ @webAppLocation = webAppLocation
49
+ @url = url
50
+ namespace name do
51
+ @setup = task("setup")
52
+ @teardown = task("teardown")
53
+ @use = task("use") { fire }
54
+ end
55
+ end
56
+
57
+ # The URL for the Tomcat server. Leave as is if you want to use the default server
58
+ # (http://localhost:8080).
59
+ attr_accessor :url
60
+
61
+ # :call-seq:
62
+ # start(pipe?)
63
+ #
64
+ # Starts Tomcat. This method does not return, it keeps the thread running until
65
+ # Tomcat is stopped. If you want to run Tomcat parallel with other tasks in the build,
66
+ # invoke the #use task instead.
67
+ def start(sync = nil)
68
+ begin
69
+ puts "classpath #{Java.classpath.inspect}"
70
+ port = URI.parse(url).port
71
+ puts "***** Starting Tomcat at http://localhost:#{port}"
72
+ Java.load
73
+ tomcat = Java.com.technophobia.buildr.tomcat.TomcatWrapper.new(port, URI.parse(url).path, @webAppLocation)
74
+
75
+ puts "***** Tomcat has started up *****"
76
+ sync << "Started" if sync
77
+ sleep # Forever
78
+ rescue Interrupt # Stopped from console
79
+ puts "Interrupted"
80
+ rescue Exception=>error
81
+ puts "#{error.class}: #{error.message}"
82
+ end
83
+ exit! # No at_exit
84
+ end
85
+
86
+ def run()
87
+ puts "***** RUNNING IN THE BACKGROUND *****"
88
+ use.invoke
89
+ end
90
+
91
+ # :call-seq:
92
+ # stop()
93
+ #
94
+ # Stops Tomcat. Stops a server running in a separate process.
95
+ def stop()
96
+ puts "***** STOPPING TOMCAT *****"
97
+ uri = URI.parse(url)
98
+ begin
99
+ Net::HTTP.start(uri.host, uri.port) do |http|
100
+ http.request_post "/buildr/stop", ""
101
+ end
102
+ rescue Errno::ECONNREFUSED
103
+ # Expected if Tomcat server not running.
104
+ rescue EOFError
105
+ # We get EOFError because Tomcat is brutally killed.
106
+ end
107
+ puts "***** Told tomcat server to stop"
108
+ end
109
+
110
+
111
+ # :call-seq:
112
+ # running?() => boolean
113
+ #
114
+ # Returns true if it finds a running Tomcat server that supports the Buildr
115
+ # requests for deploying, stopping, etc.
116
+ def running?()
117
+ puts "Checking if already running..."
118
+ uri = URI.parse(url)
119
+ begin
120
+ Net::HTTP.start(uri.host, uri.port) do |http|
121
+ response = http.request_get("/buildr/")
122
+ response.is_a?(Net::HTTPSuccess) && response.body =~ /Alive/
123
+ end
124
+ rescue Errno::ECONNREFUSED, Errno::EBADF
125
+ false
126
+ end
127
+ end
128
+
129
+
130
+ # :call-seq:
131
+ # setup(*prereqs) => task
132
+ # setup(*prereqs) { |task| .. } => task
133
+ #
134
+ # This task executes when Tomcat is first used in the build. You can use it to
135
+ # deploy artifacts into Tomcat.
136
+ def setup(*prereqs, &block)
137
+ @setup.enhance prereqs, &block
138
+ end
139
+
140
+ # :call-seq:
141
+ # teardown(*prereqs) => task
142
+ # teardown(*prereqs) { |task| .. } => task
143
+ #
144
+ # This task executes when the build is done. You can use it to undeploy artifacts
145
+ # previously deployed into Tomcat.
146
+ def teardown(*prereqs, &block)
147
+ @teardown.enhance prereqs, &block
148
+ end
149
+
150
+ # :call-seq:
151
+ # use(*prereqs) => task
152
+ # use(*prereqs) { |task| .. } => task
153
+ #
154
+ # If you intend to use Tomcat, invoke this task. It will start a new instance of
155
+ # Tomcat and close it when the build is done. However, if you already have a server
156
+ # running in the background (e.g. tomcat:start), it will use that server and will
157
+ # not close it down.
158
+ def use(*prereqs, &block)
159
+ @use.enhance prereqs, &block
160
+ end
161
+
162
+
163
+
164
+ protected
165
+
166
+ # If you want to start Tomcat inside the build, call this method instead of #start.
167
+ # It will spawn a separate process that will run Tomcat, and will stop Tomcat when
168
+ # the build ends. However, if you already started Tomcat from the console (with
169
+ # take tomcat:start), it will use the existing instance without shutting it down.
170
+ def fire()
171
+ puts "***** Firing up Tomcat *****"
172
+ unless running?
173
+ sync = Queue.new
174
+ Thread.new { start sync }
175
+ # Wait for Tomcat to Fire up before doing anything else.
176
+ sync.pop == "Started" or fail "Tomcat not started"
177
+ puts "***** Tomcat fired up *****"
178
+ at_exit { stop }
179
+ end
180
+ @setup.invoke
181
+ at_exit { @teardown.invoke }
182
+ end
183
+ end
184
+
185
+
186
+ namespace "tomcat" do
187
+ desc "Start an instance of Tomcat running in the background"
188
+ task("start") { Tomcat.instance.start }
189
+ desc "Stop an instance of Tomcat running in the background"
190
+ task("stop") { Tomcat.instance.stop }
191
+ end
192
+
193
+ # :call-seq:
194
+ # tomcat() => Tomcat
195
+ #
196
+ # Returns a Tomcat object. You can use this to discover the Tomcat#use task,
197
+ # configure the Tomcat#setup and Tomcat#teardown tasks, deploy and undeploy to Tomcat.
198
+ def tomcat()
199
+ @tomcat ||= Tomcat.instance
200
+ end
201
+
202
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: buildr-tomcat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Rory Gibson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-26 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ! " Provides the ability to run a war-packaged artifact using an embedded
15
+ Tomcat. \n"
16
+ email: rgibson@technophobia.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - README.md
22
+ - Rakefile
23
+ - COPYING.LESSER
24
+ - lib/tomcat.rb
25
+ - lib/com/technophobia/buildr/tomcat/TomcatWrapper$2.class
26
+ - lib/com/technophobia/buildr/tomcat/TomcatWrapper.class
27
+ - lib/com/technophobia/buildr/tomcat/TomcatWrapper$1.class
28
+ homepage: http://github.com/technophobia/buildr-tomcat
29
+ licenses: []
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubyforge_project:
48
+ rubygems_version: 1.8.24
49
+ signing_key:
50
+ specification_version: 3
51
+ summary: Tomcat plugin for Buildr
52
+ test_files: []