ittayd-buildr 1.3.4 → 1.3.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (169) hide show
  1. data/CHANGELOG +62 -9
  2. data/NOTICE +1 -1
  3. data/README.rdoc +9 -21
  4. data/Rakefile +20 -39
  5. data/_buildr +1 -0
  6. data/{spec/java/ant.rb → _jbuildr} +11 -15
  7. metadata +30 -210
  8. data/DISCLAIMER +0 -7
  9. data/addon/buildr/antlr.rb +0 -65
  10. data/addon/buildr/cobertura.rb +0 -22
  11. data/addon/buildr/drb.rb +0 -281
  12. data/addon/buildr/emma.rb +0 -22
  13. data/addon/buildr/hibernate.rb +0 -142
  14. data/addon/buildr/javacc.rb +0 -85
  15. data/addon/buildr/jdepend.rb +0 -60
  16. data/addon/buildr/jetty.rb +0 -248
  17. data/addon/buildr/jibx.rb +0 -86
  18. data/addon/buildr/nailgun.rb +0 -221
  19. data/addon/buildr/openjpa.rb +0 -90
  20. data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  21. data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  22. data/addon/buildr/org/apache/buildr/BuildrNail.java +0 -41
  23. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  24. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  25. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  26. data/addon/buildr/org/apache/buildr/JettyWrapper.java +0 -144
  27. data/addon/buildr/path.rb +0 -136
  28. data/addon/buildr/xmlbeans.rb +0 -93
  29. data/buildr.buildfile +0 -53
  30. data/buildr.gemspec +0 -58
  31. data/doc/css/default.css +0 -228
  32. data/doc/css/print.css +0 -100
  33. data/doc/css/syntax.css +0 -52
  34. data/doc/images/apache-incubator-logo.png +0 -0
  35. data/doc/images/buildr-hires.png +0 -0
  36. data/doc/images/buildr.png +0 -0
  37. data/doc/images/favicon.png +0 -0
  38. data/doc/images/growl-icon.tiff +0 -0
  39. data/doc/images/note.png +0 -0
  40. data/doc/images/project-structure.png +0 -0
  41. data/doc/images/tip.png +0 -0
  42. data/doc/images/zbuildr.tif +0 -0
  43. data/doc/pages/artifacts.textile +0 -207
  44. data/doc/pages/building.textile +0 -240
  45. data/doc/pages/contributing.textile +0 -208
  46. data/doc/pages/download.textile +0 -62
  47. data/doc/pages/extending.textile +0 -175
  48. data/doc/pages/getting_started.textile +0 -273
  49. data/doc/pages/index.textile +0 -42
  50. data/doc/pages/languages.textile +0 -407
  51. data/doc/pages/mailing_lists.textile +0 -17
  52. data/doc/pages/more_stuff.textile +0 -314
  53. data/doc/pages/packaging.textile +0 -427
  54. data/doc/pages/projects.textile +0 -274
  55. data/doc/pages/recipes.textile +0 -103
  56. data/doc/pages/settings_profiles.textile +0 -274
  57. data/doc/pages/testing.textile +0 -212
  58. data/doc/pages/troubleshooting.textile +0 -103
  59. data/doc/pages/whats_new.textile +0 -323
  60. data/doc/print.haml +0 -51
  61. data/doc/print.toc.yaml +0 -29
  62. data/doc/scripts/buildr-git.rb +0 -412
  63. data/doc/scripts/install-jruby.sh +0 -44
  64. data/doc/scripts/install-linux.sh +0 -64
  65. data/doc/scripts/install-osx.sh +0 -52
  66. data/doc/site.haml +0 -56
  67. data/doc/site.toc.yaml +0 -47
  68. data/etc/KEYS +0 -151
  69. data/etc/git-svn-authors +0 -16
  70. data/lib/buildr.rb +0 -33
  71. data/lib/buildr/core.rb +0 -29
  72. data/lib/buildr/core/application.rb +0 -665
  73. data/lib/buildr/core/build.rb +0 -311
  74. data/lib/buildr/core/checks.rb +0 -254
  75. data/lib/buildr/core/common.rb +0 -150
  76. data/lib/buildr/core/compile.rb +0 -590
  77. data/lib/buildr/core/environment.rb +0 -117
  78. data/lib/buildr/core/filter.rb +0 -366
  79. data/lib/buildr/core/generate.rb +0 -195
  80. data/lib/buildr/core/help.rb +0 -119
  81. data/lib/buildr/core/osx.rb +0 -49
  82. data/lib/buildr/core/progressbar.rb +0 -156
  83. data/lib/buildr/core/project.rb +0 -923
  84. data/lib/buildr/core/test.rb +0 -715
  85. data/lib/buildr/core/transports.rb +0 -560
  86. data/lib/buildr/core/util.rb +0 -294
  87. data/lib/buildr/groovy.rb +0 -18
  88. data/lib/buildr/groovy/bdd.rb +0 -106
  89. data/lib/buildr/groovy/compiler.rb +0 -138
  90. data/lib/buildr/ide.rb +0 -19
  91. data/lib/buildr/ide/eclipse.rb +0 -222
  92. data/lib/buildr/ide/idea.ipr.template +0 -300
  93. data/lib/buildr/ide/idea.rb +0 -190
  94. data/lib/buildr/ide/idea7x.ipr.template +0 -290
  95. data/lib/buildr/ide/idea7x.rb +0 -212
  96. data/lib/buildr/java.rb +0 -23
  97. data/lib/buildr/java/ant.rb +0 -92
  98. data/lib/buildr/java/bdd.rb +0 -451
  99. data/lib/buildr/java/cobertura.rb +0 -236
  100. data/lib/buildr/java/commands.rb +0 -211
  101. data/lib/buildr/java/compiler.rb +0 -348
  102. data/lib/buildr/java/deprecated.rb +0 -141
  103. data/lib/buildr/java/emma.rb +0 -238
  104. data/lib/buildr/java/jruby.rb +0 -117
  105. data/lib/buildr/java/jtestr_runner.rb.erb +0 -116
  106. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  107. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +0 -119
  108. data/lib/buildr/java/packaging.rb +0 -717
  109. data/lib/buildr/java/pom.rb +0 -174
  110. data/lib/buildr/java/rjb.rb +0 -155
  111. data/lib/buildr/java/test_result.rb +0 -307
  112. data/lib/buildr/java/tests.rb +0 -329
  113. data/lib/buildr/java/version_requirement.rb +0 -172
  114. data/lib/buildr/packaging.rb +0 -24
  115. data/lib/buildr/packaging/archive.rb +0 -488
  116. data/lib/buildr/packaging/artifact.rb +0 -759
  117. data/lib/buildr/packaging/artifact_namespace.rb +0 -972
  118. data/lib/buildr/packaging/artifact_search.rb +0 -140
  119. data/lib/buildr/packaging/gems.rb +0 -102
  120. data/lib/buildr/packaging/package.rb +0 -233
  121. data/lib/buildr/packaging/tar.rb +0 -186
  122. data/lib/buildr/packaging/version_requirement.rb +0 -172
  123. data/lib/buildr/packaging/zip.rb +0 -64
  124. data/lib/buildr/packaging/ziptask.rb +0 -313
  125. data/lib/buildr/resources/buildr.icns +0 -0
  126. data/lib/buildr/scala.rb +0 -19
  127. data/lib/buildr/scala/compiler.rb +0 -109
  128. data/lib/buildr/scala/tests.rb +0 -203
  129. data/rakelib/apache.rake +0 -191
  130. data/rakelib/changelog.rake +0 -57
  131. data/rakelib/doc.rake +0 -103
  132. data/rakelib/package.rake +0 -76
  133. data/rakelib/release.rake +0 -65
  134. data/rakelib/rspec.rake +0 -83
  135. data/rakelib/rubyforge.rake +0 -56
  136. data/rakelib/scm.rake +0 -49
  137. data/rakelib/setup.rake +0 -81
  138. data/rakelib/stage.rake +0 -48
  139. data/spec/addon/drb_spec.rb +0 -328
  140. data/spec/core/application_spec.rb +0 -419
  141. data/spec/core/build_spec.rb +0 -423
  142. data/spec/core/checks_spec.rb +0 -519
  143. data/spec/core/common_spec.rb +0 -670
  144. data/spec/core/compile_spec.rb +0 -582
  145. data/spec/core/generate_spec.rb +0 -33
  146. data/spec/core/project_spec.rb +0 -776
  147. data/spec/core/test_spec.rb +0 -1098
  148. data/spec/core/transport_spec.rb +0 -500
  149. data/spec/groovy/bdd_spec.rb +0 -80
  150. data/spec/groovy/compiler_spec.rb +0 -239
  151. data/spec/ide/eclipse_spec.rb +0 -311
  152. data/spec/java/bdd_spec.rb +0 -358
  153. data/spec/java/cobertura_spec.rb +0 -77
  154. data/spec/java/compiler_spec.rb +0 -446
  155. data/spec/java/emma_spec.rb +0 -120
  156. data/spec/java/java_spec.rb +0 -96
  157. data/spec/java/packaging_spec.rb +0 -1120
  158. data/spec/java/test_coverage_spec.rb +0 -255
  159. data/spec/java/tests_spec.rb +0 -471
  160. data/spec/packaging/archive_spec.rb +0 -503
  161. data/spec/packaging/artifact_namespace_spec.rb +0 -646
  162. data/spec/packaging/artifact_spec.rb +0 -795
  163. data/spec/packaging/packaging_helper.rb +0 -63
  164. data/spec/packaging/packaging_spec.rb +0 -589
  165. data/spec/sandbox.rb +0 -139
  166. data/spec/scala/compiler_spec.rb +0 -228
  167. data/spec/scala/tests_spec.rb +0 -215
  168. data/spec/spec_helpers.rb +0 -327
  169. data/spec/version_requirement_spec.rb +0 -123
@@ -1,221 +0,0 @@
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
-
17
- require 'jruby'
18
- require 'rbconfig'
19
- require 'tmpdir'
20
- require 'buildr/drb'
21
-
22
-
23
- module Buildr
24
-
25
- # This addon is provided for fast interaction with a DRb BuildrServer (buildr/drb).
26
- #
27
- # This module delegates task invocation to the BuildrServer, it only implements
28
- # nailgun required logic (server/client).
29
- #
30
- # Usage:
31
- #
32
- # buildr -r buildr/nailgun nailgun:start
33
- #
34
- # Once the server has been started you can invoke tasks using the nailgun client
35
- # installed on $JRUBY_HOME/tool/nailgun. It's recommended to add this path to
36
- # your PATH environment variable, so that the ng command is available at any dir.
37
- #
38
- # ng build # invoke the build task
39
- #
40
- module Nailgun
41
- extend self
42
-
43
- VERSION = '0.7.1'
44
- NAME = "nailgun-#{VERSION}"
45
- URL = "http://downloads.sourceforge.net/nailgun/#{NAME}.zip"
46
- ARTIFACT_SPEC = "com.martiansoftware:nailgun:jar:#{VERSION}"
47
- PORT = DRbApplication::PORT + 2
48
- ADDON_BIN = File.dirname(__FILE__)
49
-
50
- # Returns the path to JRUBY_HOME.
51
- def jruby_home
52
- ENV['JRUBY_HOME'] || Config::CONFIG['prefix']
53
- end
54
-
55
- # Returns the path to NAILGUN_HOME.
56
- def nailgun_home
57
- ENV['NAILGUN_HOME'] || File.expand_path('tool/nailgun', jruby_home)
58
- end
59
-
60
- def tmp_path(*paths)
61
- File.join(Dir.tmpdir, 'nailgun', *paths)
62
- end
63
-
64
- module Util
65
- extend self
66
-
67
- def add_to_sysloader(path)
68
- sysloader = java.lang.ClassLoader.getSystemClassLoader
69
- add_url_method = java.lang.Class.forName('java.net.URLClassLoader').
70
- getDeclaredMethod('addURL', [java.net.URL.java_class].to_java(java.lang.Class))
71
- add_url_method.setAccessible(true)
72
- add_url_method.invoke(sysloader, [java.io.File.new(path).toURI.toURL].to_java(java.net.URL))
73
- end
74
-
75
- # invoke a java constructor
76
- def ctor(on_class, *args)
77
- parameters = []
78
- classes = []
79
- args.each do |obj|
80
- case obj
81
- when nil
82
- classes.push(nil)
83
- parameters.push(nil)
84
- when Hash
85
- vclass = obj.keys.first
86
- value = obj[vclass]
87
- classes.push(vclass.java_class)
88
- parameters.push(value)
89
- else
90
- parameters.push obj
91
- classes.push obj.class.java_class
92
- end
93
- end
94
- on_class = [on_class.java_class].to_java(java.lang.Class)[0]
95
- ctor = on_class.getDeclaredConstructor(classes.to_java(java.lang.Class))
96
- ctor.setAccessible(true)
97
- ctor.newInstance(parameters.to_java(java.lang.Object))
98
- end
99
-
100
- end # Util
101
-
102
- module Client
103
-
104
- def main(nail)
105
- nail.out.println "Connected to #{nail.getNGServer}"
106
-
107
- runtime = JRuby.runtime
108
-
109
- stdout = Util.ctor(org.jruby.RubyIO, runtime, java.io.OutputStream => nail.out)
110
- stderr = Util.ctor(org.jruby.RubyIO, runtime, java.io.OutputStream => nail.err)
111
- stdin = Util.ctor(org.jruby.RubyIO, runtime, java.io.InputStream => nail.in)
112
-
113
- dir = nail.getWorkingDirectory
114
- argv = [nail.command] + nail.args
115
-
116
- DRbApplication.remote_run :dir => dir, :argv => argv,
117
- :in => stdin, :out => stdout, :err => stderr
118
- rescue => e
119
- nail.err.println e unless SystemExit === e
120
- nail.exit 1
121
- end
122
-
123
- end # Client
124
-
125
- module Server
126
- def initialize(host, port)
127
- @host = host || "*"
128
- @port = port
129
- super(host, port)
130
- end
131
-
132
- def start
133
- self.allow_nails_by_class_name = false
134
-
135
- NGClient::Main.nail = NGClient.new
136
- self.default_nail_class = NGClient::Main
137
-
138
- @thread = java.lang.Thread.new(self)
139
- @thread.setName(to_s)
140
- @thread.start
141
-
142
- sleep 1 while getPort == 0
143
- info "#{self} Started."
144
- end
145
-
146
- def stop
147
- @thread.kill
148
- end
149
-
150
- def to_s
151
- version = "Buildr #{Buildr::VERSION} #{RUBY_PLATFORM[/java/] && '(JRuby '+JRUBY_VERSION+')'}"
152
- self.class.name+'('+[version, @host, @port].join(', ')+')'
153
- end
154
- end # Server
155
-
156
- namespace(:nailgun) do
157
-
158
- dist_zip = Buildr.download(tmp_path(NAME + '.zip') => URL)
159
- dist_dir = Buildr.unzip(tmp_path(NAME) => dist_zip)
160
-
161
- nailgun_jar = file(tmp_path(NAME, NAME, NAME + '.jar'))
162
- nailgun_jar.enhance [dist_dir] unless File.exist?(nailgun_jar.to_s)
163
-
164
- attr_reader :artifact
165
- @artifact = Buildr.artifact(ARTIFACT_SPEC).from(nailgun_jar)
166
-
167
- compiled_bin = file(tmp_path(NAME, NAME, 'ng' + Config::CONFIG['EXEEXT']) => dist_dir.target) do |task|
168
- unless task.to_s.pathmap('%x') == '.exe'
169
- Dir.chdir(task.to_s.pathmap('%d')) do
170
- info "Compiling #{task.to_s}"
171
- system('make', task.to_s.pathmap('%f')) or
172
- fail "Nailgun binary compilation failed."
173
- end
174
- end
175
- end
176
-
177
- attr_reader :installed_bin
178
- @installed_bin = file(File.expand_path(compiled_bin.to_s.pathmap('%f'), nailgun_home) => compiled_bin) do |task|
179
- mkpath task.to_s.pathmap('%d'), :verbose => false
180
- cp compiled_bin.to_s, task.to_s, :verbose => false
181
- end
182
-
183
- task('drb-notice') do
184
- info ''
185
- info 'Running in JRuby, a nailgun server will be started so that'
186
- info 'you can use your nailgun client to invoke buildr tasks: '
187
- info ''
188
- info ' '+Nailgun.installed_bin.to_s
189
- info ''
190
- end
191
-
192
- task('drb' => ['drb-notice', 'start'])
193
-
194
- desc 'Start the nailgun server'
195
- task('start' => [installed_bin, 'setup']) do |task|
196
- server = NGServer.new(nil, PORT)
197
- server.start
198
- end
199
-
200
- task('setup' => artifact) do
201
- module Util
202
- include Buildr::Util
203
- end
204
-
205
- Util.add_to_sysloader artifact.to_s
206
- Util.add_to_sysloader ADDON_BIN
207
-
208
- class NGClient
209
- include org.apache.buildr.BuildrNail
210
- include Client
211
- end
212
-
213
- class NGServer < com.martiansoftware.nailgun.NGServer
214
- include Server
215
- end
216
- end
217
-
218
- end # ng_tasks
219
-
220
- end # module Nailgun
221
- end
@@ -1,90 +0,0 @@
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
-
17
- require 'buildr/java'
18
-
19
-
20
- module Buildr
21
-
22
- # Provides OpenJPA bytecode enhancement and Mapping tool task. Require explicitly using <code>require "buildr/openjpa"</code>.
23
- module OpenJPA
24
-
25
- VERSION = "1.0.1"
26
-
27
- REQUIRES = [ "org.apache.openjpa:openjpa:jar:#{VERSION}",
28
- "commons-collections:commons-collections:jar:3.1",
29
- "commons-dbcp:commons-dbcp:jar:1.2.1",
30
- "commons-lang:commons-lang:jar:2.1",
31
- "commons-pool:commons-pool:jar:1.2",
32
- "javax.persistence:persistence-api:jar:1.0",
33
- "org.apache.geronimo.specs:geronimo-j2ee-connector_1.5_spec:jar:1.0",
34
- "org.apache.geronimo.specs:geronimo-jta_1.0.1B_spec:jar:1.0",
35
- "net.sourceforge.serp:serp:jar:1.11.0" ]
36
-
37
- Java.classpath << REQUIRES
38
-
39
- class << self
40
-
41
- def enhance(options)
42
- rake_check_options options, :classpath, :properties, :output
43
- artifacts = Buildr.artifacts(options[:classpath]).each { |a| a.invoke }.map(&:to_s) + [options[:output].to_s]
44
- properties = file(options[:properties]).tap { |task| task.invoke }.to_s
45
-
46
- Buildr.ant "openjpa" do |ant|
47
- ant.taskdef :name=>"enhancer", :classname=>"org.apache.openjpa.ant.PCEnhancerTask",
48
- :classpath=>requires.join(File::PATH_SEPARATOR)
49
- ant.enhancer :directory=>options[:output].to_s do
50
- ant.config :propertiesFile=>properties
51
- ant.classpath :path=>artifacts.join(File::PATH_SEPARATOR)
52
- end
53
- end
54
- end
55
-
56
- def mapping_tool(options)
57
- rake_check_options options, :classpath, :properties, :sql, :action
58
- artifacts = Buildr.artifacts(options[:classpath]).each{ |a| a.invoke }.map(&:to_s)
59
- properties = file(options[:properties].to_s).tap { |task| task.invoke }.to_s
60
-
61
- Buildr.ant("openjpa") do |ant|
62
- ant.taskdef :name=>"mapping", :classname=>"org.apache.openjpa.jdbc.ant.MappingToolTask",
63
- :classpath=>requires.join(File::PATH_SEPARATOR)
64
- ant.mapping :schemaAction=>options[:action], :sqlFile=>options[:sql].to_s, :ignoreErrors=>"true" do
65
- ant.config :propertiesFile=>properties
66
- ant.classpath :path=>artifacts.join(File::PATH_SEPARATOR)
67
- end
68
- end
69
- end
70
-
71
- private
72
-
73
- def requires()
74
- @requires ||= Buildr.artifacts(REQUIRES).each { |artifact| artifact.invoke }.map(&:to_s)
75
- end
76
-
77
- end
78
-
79
- def open_jpa_enhance(options = nil)
80
- jpa_options = { :output=>compile.target, :classpath=>compile.dependencies,
81
- :properties=>path_to(:source, :main, :resources, 'META-INF/persistence.xml') }
82
- OpenJPA.enhance jpa_options.merge(options || {})
83
- end
84
-
85
- end
86
-
87
- class Project
88
- include OpenJPA
89
- end
90
- end
@@ -1,41 +0,0 @@
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
14
- * under the License.
15
- */
16
-
17
-
18
- package org.apache.buildr;
19
-
20
- import com.martiansoftware.nailgun.NGContext;
21
-
22
- public interface BuildrNail {
23
-
24
- public void main(NGContext ctx);
25
-
26
- public static class Main {
27
- private static BuildrNail nail;
28
- public static void setNail(BuildrNail _nail) { nail = _nail; }
29
- public static void nailMain(NGContext ctx) {
30
- nail.main(ctx);
31
- }
32
- }
33
-
34
- }
35
-
36
- /*
37
- * Local Variables:
38
- * indent-tabs-mode: nil
39
- * c-basic-offset: 2
40
- * End:
41
- */
@@ -1,144 +0,0 @@
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
14
- * under the License.
15
- */
16
-
17
-
18
- package org.apache.buildr;
19
-
20
- import org.mortbay.jetty.Server;
21
- import org.mortbay.jetty.Request;
22
- import org.mortbay.jetty.Handler;
23
- import org.mortbay.jetty.handler.AbstractHandler;
24
- import org.mortbay.jetty.handler.ContextHandler;
25
- import org.mortbay.jetty.handler.ContextHandlerCollection;
26
- import org.mortbay.jetty.webapp.WebAppContext;
27
- import org.mortbay.jetty.webapp.WebAppClassLoader;
28
-
29
- import javax.servlet.http.HttpServletRequest;
30
- import javax.servlet.http.HttpServletResponse;
31
- import javax.servlet.ServletException;
32
- import java.io.IOException;
33
- import java.util.HashMap;
34
-
35
- /**
36
- * @author Matthieu Riou <mriou at apache dot org>
37
- */
38
- public class JettyWrapper {
39
-
40
- private Server _server;
41
- private ContextHandlerCollection _handlerColl;
42
-
43
- public JettyWrapper(int port) throws Exception {
44
- _server = new Server(port);
45
- // Adding the buildr handler to control our server lifecycle
46
- ContextHandler context = new ContextHandler();
47
- context.setContextPath("/buildr");
48
- Handler handler = new BuildrHandler();
49
- context.setHandler(handler);
50
-
51
- _handlerColl = new ContextHandlerCollection();
52
- _handlerColl.setHandlers(new Handler[] {context});
53
-
54
- _server.addHandler(_handlerColl);
55
- _server.start();
56
- }
57
-
58
- /*
59
- public void join() {
60
- try {
61
- _server.join();
62
- } catch (Exception e) {
63
- e.printStackTrace();
64
- }
65
- }
66
- */
67
-
68
- private class BuildrHandler extends AbstractHandler {
69
-
70
- private HashMap _apps = new HashMap();
71
-
72
- public void handle(String string, HttpServletRequest request,
73
- HttpServletResponse response, int i) throws IOException, ServletException {
74
- response.setContentType("text/html");
75
- if (request.getPathInfo().equals("/")) {
76
- response.getWriter().println("Alive");
77
- ((Request)request).setHandled(true);
78
- return;
79
- } else if (request.getPathInfo().equals("/deploy")) {
80
- try {
81
- String webapp = request.getParameter("webapp");
82
- String path = request.getParameter("path");
83
- System.out.println("Deploying " + webapp + " in " + path);
84
- WebAppContext context;
85
-
86
- context = (WebAppContext) _apps.get(path);
87
- if (context != null) {
88
- context.stop();
89
- _handlerColl.removeHandler(context);
90
- _apps.remove(path);
91
- }
92
-
93
- context = new WebAppContext(webapp, path);
94
- context.setConfigurationClasses(new String[] {
95
- "org.mortbay.jetty.webapp.WebInfConfiguration",
96
- "org.mortbay.jetty.webapp.WebXmlConfiguration"});
97
- context.setClassLoader(new WebAppClassLoader(context));
98
-
99
- _handlerColl.addHandler(context);
100
- context.start();
101
- _apps.put(path, context);
102
- response.getWriter().println("Deployed");
103
- response.getWriter().println(context.getTempDirectory());
104
- ((Request)request).setHandled(true);
105
- } catch (Throwable e) {
106
- e.printStackTrace();
107
- response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
108
- ((Request)request).setHandled(true);
109
- return;
110
- }
111
- } else if (request.getPathInfo().equals("/undeploy")) {
112
- try {
113
- String path = request.getParameter("path");
114
- WebAppContext context = (WebAppContext) _apps.get(path);
115
- if (context != null) {
116
- System.out.println("Undeploying app at " + path);
117
- context.stop();
118
- _handlerColl.removeHandler(context);
119
- _apps.remove(path);
120
- }
121
- response.getWriter().println("Undeployed");
122
- ((Request)request).setHandled(true);
123
- } catch (Throwable e) {
124
- e.printStackTrace();
125
- response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
126
- ((Request)request).setHandled(true);
127
- return;
128
- }
129
- } else if (request.getPathInfo().equals("/stop")) {
130
- try {
131
- _server.stop();
132
- _server.destroy();
133
- // Brute force
134
- System.exit(0);
135
- } catch (Exception e) {
136
- e.printStackTrace();
137
- }
138
- }
139
- response.getWriter().println("OK " + request.getPathInfo());
140
- ((Request)request).setHandled(true);
141
- }
142
-
143
- }
144
- }