buildr 1.3.5-x86-mswin32

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.
Files changed (186) hide show
  1. data/CHANGELOG +998 -0
  2. data/LICENSE +176 -0
  3. data/NOTICE +26 -0
  4. data/README.rdoc +134 -0
  5. data/Rakefile +45 -0
  6. data/_buildr +29 -0
  7. data/_jbuildr +29 -0
  8. data/addon/buildr/antlr.rb +65 -0
  9. data/addon/buildr/cobertura.rb +22 -0
  10. data/addon/buildr/drb.rb +281 -0
  11. data/addon/buildr/emma.rb +22 -0
  12. data/addon/buildr/hibernate.rb +142 -0
  13. data/addon/buildr/javacc.rb +85 -0
  14. data/addon/buildr/jdepend.rb +60 -0
  15. data/addon/buildr/jetty.rb +248 -0
  16. data/addon/buildr/jibx.rb +86 -0
  17. data/addon/buildr/nailgun.rb +221 -0
  18. data/addon/buildr/openjpa.rb +90 -0
  19. data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  20. data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  21. data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
  22. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  23. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  24. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  25. data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  26. data/addon/buildr/xmlbeans.rb +93 -0
  27. data/bin/buildr +19 -0
  28. data/buildr.buildfile +58 -0
  29. data/buildr.gemspec +65 -0
  30. data/doc/_config.yml +1 -0
  31. data/doc/_layouts/default.html +88 -0
  32. data/doc/_layouts/preface.html +22 -0
  33. data/doc/artifacts.textile +211 -0
  34. data/doc/building.textile +244 -0
  35. data/doc/contributing.textile +252 -0
  36. data/doc/css/default.css +236 -0
  37. data/doc/css/print.css +101 -0
  38. data/doc/css/syntax.css +23 -0
  39. data/doc/download.textile +79 -0
  40. data/doc/extending.textile +186 -0
  41. data/doc/images/1442160941-frontcover.jpg +0 -0
  42. data/doc/images/asf-logo.gif +0 -0
  43. data/doc/images/asf-logo.png +0 -0
  44. data/doc/images/buildr-hires.png +0 -0
  45. data/doc/images/buildr.png +0 -0
  46. data/doc/images/favicon.png +0 -0
  47. data/doc/images/growl-icon.tiff +0 -0
  48. data/doc/images/note.png +0 -0
  49. data/doc/images/project-structure.png +0 -0
  50. data/doc/images/tip.png +0 -0
  51. data/doc/images/zbuildr.png +0 -0
  52. data/doc/images/zbuildr.tif +0 -0
  53. data/doc/index.textile +69 -0
  54. data/doc/installing.textile +266 -0
  55. data/doc/languages.textile +459 -0
  56. data/doc/mailing_lists.textile +25 -0
  57. data/doc/more_stuff.textile +457 -0
  58. data/doc/packaging.textile +430 -0
  59. data/doc/preface.textile +54 -0
  60. data/doc/projects.textile +271 -0
  61. data/doc/quick_start.textile +210 -0
  62. data/doc/scripts/buildr-git.rb +512 -0
  63. data/doc/scripts/gitflow.rb +296 -0
  64. data/doc/scripts/install-jruby.sh +44 -0
  65. data/doc/scripts/install-linux.sh +72 -0
  66. data/doc/scripts/install-osx.sh +52 -0
  67. data/doc/settings_profiles.textile +280 -0
  68. data/doc/testing.textile +222 -0
  69. data/etc/KEYS +151 -0
  70. data/lib/buildr.rb +36 -0
  71. data/lib/buildr/core.rb +35 -0
  72. data/lib/buildr/core/application.rb +656 -0
  73. data/lib/buildr/core/build.rb +452 -0
  74. data/lib/buildr/core/checks.rb +254 -0
  75. data/lib/buildr/core/common.rb +150 -0
  76. data/lib/buildr/core/compile.rb +608 -0
  77. data/lib/buildr/core/environment.rb +129 -0
  78. data/lib/buildr/core/filter.rb +362 -0
  79. data/lib/buildr/core/generate.rb +195 -0
  80. data/lib/buildr/core/help.rb +119 -0
  81. data/lib/buildr/core/osx.rb +46 -0
  82. data/lib/buildr/core/progressbar.rb +156 -0
  83. data/lib/buildr/core/project.rb +866 -0
  84. data/lib/buildr/core/shell.rb +198 -0
  85. data/lib/buildr/core/test.rb +723 -0
  86. data/lib/buildr/core/transports.rb +559 -0
  87. data/lib/buildr/core/util.rb +449 -0
  88. data/lib/buildr/groovy.rb +19 -0
  89. data/lib/buildr/groovy/bdd.rb +106 -0
  90. data/lib/buildr/groovy/compiler.rb +138 -0
  91. data/lib/buildr/groovy/shell.rb +48 -0
  92. data/lib/buildr/ide.rb +19 -0
  93. data/lib/buildr/ide/eclipse.rb +334 -0
  94. data/lib/buildr/ide/eclipse/java.rb +53 -0
  95. data/lib/buildr/ide/eclipse/plugin.rb +68 -0
  96. data/lib/buildr/ide/eclipse/scala.rb +66 -0
  97. data/lib/buildr/ide/idea.ipr.template +300 -0
  98. data/lib/buildr/ide/idea.rb +190 -0
  99. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  100. data/lib/buildr/ide/idea7x.rb +212 -0
  101. data/lib/buildr/java.rb +23 -0
  102. data/lib/buildr/java/ant.rb +94 -0
  103. data/lib/buildr/java/bdd.rb +459 -0
  104. data/lib/buildr/java/cobertura.rb +274 -0
  105. data/lib/buildr/java/commands.rb +213 -0
  106. data/lib/buildr/java/compiler.rb +349 -0
  107. data/lib/buildr/java/deprecated.rb +141 -0
  108. data/lib/buildr/java/emma.rb +244 -0
  109. data/lib/buildr/java/jruby.rb +117 -0
  110. data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
  111. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  112. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +137 -0
  113. data/lib/buildr/java/packaging.rb +716 -0
  114. data/lib/buildr/java/pom.rb +174 -0
  115. data/lib/buildr/java/rjb.rb +155 -0
  116. data/lib/buildr/java/test_result.rb +353 -0
  117. data/lib/buildr/java/tests.rb +333 -0
  118. data/lib/buildr/java/version_requirement.rb +172 -0
  119. data/lib/buildr/packaging.rb +24 -0
  120. data/lib/buildr/packaging/archive.rb +488 -0
  121. data/lib/buildr/packaging/artifact.rb +749 -0
  122. data/lib/buildr/packaging/artifact_namespace.rb +972 -0
  123. data/lib/buildr/packaging/artifact_search.rb +140 -0
  124. data/lib/buildr/packaging/gems.rb +102 -0
  125. data/lib/buildr/packaging/package.rb +238 -0
  126. data/lib/buildr/packaging/tar.rb +186 -0
  127. data/lib/buildr/packaging/version_requirement.rb +172 -0
  128. data/lib/buildr/packaging/zip.rb +73 -0
  129. data/lib/buildr/packaging/ziptask.rb +316 -0
  130. data/lib/buildr/resources/buildr.icns +0 -0
  131. data/lib/buildr/scala.rb +25 -0
  132. data/lib/buildr/scala/bdd.rb +109 -0
  133. data/lib/buildr/scala/compiler.rb +195 -0
  134. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner$.class +0 -0
  135. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.class +0 -0
  136. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.scala +35 -0
  137. data/lib/buildr/scala/shell.rb +55 -0
  138. data/lib/buildr/scala/tests.rb +157 -0
  139. data/lib/buildr/shell.rb +180 -0
  140. data/rakelib/checks.rake +57 -0
  141. data/rakelib/doc.rake +92 -0
  142. data/rakelib/jekylltask.rb +120 -0
  143. data/rakelib/package.rake +73 -0
  144. data/rakelib/release.rake +149 -0
  145. data/rakelib/rspec.rake +73 -0
  146. data/rakelib/setup.rake +54 -0
  147. data/rakelib/stage.rake +213 -0
  148. data/rakelib/stage.rake~ +213 -0
  149. data/spec/addon/drb_spec.rb +328 -0
  150. data/spec/core/application_spec.rb +502 -0
  151. data/spec/core/build_spec.rb +677 -0
  152. data/spec/core/checks_spec.rb +519 -0
  153. data/spec/core/common_spec.rb +670 -0
  154. data/spec/core/compile_spec.rb +583 -0
  155. data/spec/core/extension_spec.rb +93 -0
  156. data/spec/core/generate_spec.rb +33 -0
  157. data/spec/core/project_spec.rb +762 -0
  158. data/spec/core/test_spec.rb +1098 -0
  159. data/spec/core/transport_spec.rb +537 -0
  160. data/spec/core/util_spec.rb +67 -0
  161. data/spec/groovy/bdd_spec.rb +80 -0
  162. data/spec/groovy/compiler_spec.rb +240 -0
  163. data/spec/ide/eclipse_spec.rb +501 -0
  164. data/spec/ide/idea7x_spec.rb +84 -0
  165. data/spec/java/ant_spec.rb +33 -0
  166. data/spec/java/bdd_spec.rb +382 -0
  167. data/spec/java/cobertura_spec.rb +85 -0
  168. data/spec/java/compiler_spec.rb +446 -0
  169. data/spec/java/emma_spec.rb +119 -0
  170. data/spec/java/java_spec.rb +124 -0
  171. data/spec/java/packaging_spec.rb +1134 -0
  172. data/spec/java/test_coverage_helper.rb +257 -0
  173. data/spec/java/tests_spec.rb +493 -0
  174. data/spec/packaging/archive_spec.rb +527 -0
  175. data/spec/packaging/artifact_namespace_spec.rb +654 -0
  176. data/spec/packaging/artifact_spec.rb +795 -0
  177. data/spec/packaging/packaging_helper.rb +63 -0
  178. data/spec/packaging/packaging_spec.rb +684 -0
  179. data/spec/sandbox.rb +142 -0
  180. data/spec/scala/bdd_spec.rb +119 -0
  181. data/spec/scala/compiler_spec.rb +284 -0
  182. data/spec/scala/scala.rb +38 -0
  183. data/spec/scala/tests_spec.rb +261 -0
  184. data/spec/spec_helpers.rb +340 -0
  185. data/spec/version_requirement_spec.rb +129 -0
  186. metadata +383 -0
@@ -0,0 +1,221 @@
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
@@ -0,0 +1,90 @@
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
@@ -0,0 +1,41 @@
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
+ */
@@ -0,0 +1,144 @@
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
+ }