buildr 1.3.5-x86-mswin32

Sign up to get free protection for your applications and to get access to all the features.
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,180 @@
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
+ module Buildr
18
+ module ShellProviders
19
+ class << self
20
+ def add(p)
21
+ @providers ||= {}
22
+
23
+ if p.lang == :none
24
+ @providers[:none] ||= []
25
+ @providers[:none] << p
26
+ else
27
+ @providers[p.lang] = p
28
+ end
29
+ end
30
+ alias :<< :add
31
+
32
+ def providers
33
+ @providers ||= {}
34
+ end
35
+
36
+ def each
37
+ providers.each do |lang, p|
38
+ if lang == :none
39
+ p.each do |x|
40
+ yield x
41
+ end
42
+ else
43
+ yield p
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ module Shell
51
+ class Base
52
+ attr_reader :project
53
+
54
+ class << self
55
+ def lang
56
+ :none
57
+ end
58
+
59
+ def to_sym
60
+ @symbol ||= name.split('::').last.downcase.to_sym
61
+ end
62
+ end
63
+
64
+ def initialize(project)
65
+ @project = project
66
+ end
67
+
68
+ def build?
69
+ true
70
+ end
71
+
72
+ def launch
73
+ fail 'Not implemented'
74
+ end
75
+ end
76
+
77
+ module JavaRebel
78
+ def rebel_home
79
+ unless @rebel_home
80
+ @rebel_home = ENV['REBEL_HOME'] or ENV['JAVA_REBEL'] or ENV['JAVAREBEL'] or ENV['JAVAREBEL_HOME']
81
+
82
+ if @rebel_home and File.directory? @rebel_home
83
+ @rebel_home += File::SEPARATOR + 'javarebel.jar'
84
+ end
85
+ end
86
+
87
+ if @rebel_home and File.exists? @rebel_home
88
+ @rebel_home
89
+ else
90
+ nil
91
+ end
92
+ end
93
+
94
+ def rebel_args
95
+ if rebel_home
96
+ [
97
+ '-noverify',
98
+ "-javaagent:#{rebel_home}"
99
+ ]
100
+ else
101
+ []
102
+ end
103
+ end
104
+
105
+ def rebel_props(project)
106
+ {}
107
+ end
108
+ end
109
+ end
110
+
111
+ module ShellExtension
112
+ include Extension
113
+
114
+ first_time do
115
+ Project.local_task 'shell'
116
+
117
+ ShellProviders.each { |p| Project.local_task "shell:#{p.to_sym}" } # TODO not working
118
+ end
119
+
120
+ before_define do |project|
121
+ ShellProviders.each do |p|
122
+ name = p.to_sym
123
+
124
+ trace "Defining task #{project.name}:shell:#{name}"
125
+
126
+ p_inst = p.new project
127
+ deps = if p_inst.build? then [:compile] else [] end
128
+
129
+ project.task "shell:#{name}" => deps do
130
+ trace "Launching #{name} shell"
131
+ p_inst.launch
132
+ end
133
+ end
134
+ end
135
+
136
+ after_define do |project|
137
+ default_shell = project.shell.using
138
+
139
+ if default_shell
140
+ dep = "shell:#{default_shell.to_sym}"
141
+
142
+ trace "Defining task shell based on #{dep}"
143
+ project.task :shell => dep
144
+ else
145
+ project.task :shell do
146
+ fail "No shell provider defined for language '#{project.compile.language}'"
147
+ end
148
+ end
149
+ end
150
+
151
+ class ShellConfig
152
+ def initialize(project)
153
+ @project = project
154
+ end
155
+
156
+ def using(*args)
157
+ if args.size > 0
158
+ @using ||= args.first
159
+ else
160
+ @using ||= find_shell_task
161
+ end
162
+ end
163
+
164
+ private
165
+ def find_shell_task
166
+ lang = @project.compile.language
167
+ ShellProviders.providers[lang]
168
+ end
169
+ end
170
+
171
+ # TODO temporary hack
172
+ def shell
173
+ @shell ||= ShellConfig.new self
174
+ end
175
+ end
176
+
177
+ class Project
178
+ include ShellExtension
179
+ end
180
+ end
@@ -0,0 +1,57 @@
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
+ desc "Check that source files contain the Apache license"
18
+ task :license=>FileList["**/*.{rb,rake,java,gemspec,buildfile}", 'Rakefile'] do |task|
19
+ puts "Checking that files contain the Apache license ... "
20
+ required = task.prerequisites.select { |fn| File.file?(fn) }
21
+ missing = required.reject { |fn|
22
+ comments = File.read(fn).scan(/(\/\*(.*?)\*\/)|^#\s+(.*?)$|^-#\s+(.*?)$|<!--(.*?)-->/m).
23
+ map { |match| match.compact }.flatten.join("\n")
24
+ comments =~ /Licensed to the Apache Software Foundation/ && comments =~ /http:\/\/www.apache.org\/licenses\/LICENSE-2.0/
25
+ }
26
+ fail "#{missing.join(', ')} missing Apache License, please add it before making a release!" unless missing.empty?
27
+ puts "[x] Source files contain the Apache license"
28
+ end
29
+
30
+
31
+ desc "Look for new dependencies, check transitive dependencies"
32
+ task :dependency do
33
+ puts "Checking that all dependencies are up to date ..."
34
+ # Find if anything has a more recent dependency. These are not errors, just reports.
35
+ spec.dependencies.each do |dep|
36
+ current = Gem::SourceInfoCache.search(dep).last
37
+ latest = Gem::SourceInfoCache.search(Gem::Dependency.new(dep.name, '>0')).last
38
+ puts "A new version of #{dep.name} is available, #{latest.version} replaces #{current.version}" if (current && latest && latest.version > current.version)
39
+ end
40
+
41
+ # Returns orderd list of transitive dependencies for the given dependency.
42
+ transitive = lambda { |depend|
43
+ dep_spec = Gem::SourceIndex.from_installed_gems.search(depend).last
44
+ fail "No specification for dependency #{depend}" unless dep_spec
45
+ dep_spec.runtime_dependencies.map { |trans| transitive[trans].push(trans) }.flatten.uniq }
46
+ # For each dependency, make sure *all* its transitive dependencies are listed
47
+ # as a Buildr dependency, and order is preserved.
48
+ spec.dependencies.each_with_index do |dep, index|
49
+ puts "checking #{dep.name}"
50
+ transitive[dep].each do |trans|
51
+ matching = spec.dependencies.find { |existing| trans =~ existing }
52
+ fail "#{trans} required by #{dep} and missing from spec" unless matching
53
+ fail "#{trans} must come before #{dep} in dependency list" unless spec.dependencies.index(matching) < index
54
+ end
55
+ end
56
+ puts "[X] Checked all dependencies are up to date and transitive dependencies are correctly ordered"
57
+ end
data/rakelib/doc.rake ADDED
@@ -0,0 +1,92 @@
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
+ task 'doc:setup'
18
+ begin # For the Web site, we use the SDoc RDoc generator/theme (http://github.com/voloko/sdoc/)
19
+ require 'sdoc'
20
+ rescue LoadError
21
+ puts "Buildr uses the SDoc RDoc generator/theme. You can install it by running rake doc:setup"
22
+ task('doc:setup') { install_gem 'voloko-sdoc', :source=>'http://gems.github.com' }
23
+ end
24
+
25
+
26
+ require 'rake/rdoctask'
27
+
28
+ desc "Generate RDoc documentation in rdoc/"
29
+ Rake::RDocTask.new :rdoc do |rdoc|
30
+ rdoc.rdoc_dir = 'rdoc'
31
+ rdoc.title = spec.name
32
+ rdoc.options = spec.rdoc_options.clone
33
+ rdoc.rdoc_files.include('lib/**/*.rb')
34
+ rdoc.rdoc_files.include spec.extra_rdoc_files
35
+ end
36
+
37
+
38
+ begin
39
+ require 'rakelib/jekylltask'
40
+
41
+ desc "Generate Buildr documentation in _site/"
42
+ JekyllTask.new :jekyll do |task|
43
+ task.source = 'doc'
44
+ task.target = '_site'
45
+ end
46
+
47
+ rescue LoadError
48
+ puts "Buildr uses the mojombo-jekyll to generate the Web site. You can install it by running rake doc:setup"
49
+ task 'doc:setup' do
50
+ install_gem 'mojombo-jekyll', :source=>'http://gems.github.com', :version=>'0.5.4'
51
+ if `pygmentize -V`.empty?
52
+ args = %w{easy_install Pygments}
53
+ args.unshift 'sudo' unless Config::CONFIG['host_os'] =~ /windows/
54
+ sh *args
55
+ end
56
+ end
57
+ end
58
+
59
+
60
+ desc "Generate Buildr documentation as buildr.pdf"
61
+ file 'buildr.pdf'=>'_site' do |task|
62
+ pages = File.read('_site/preface.html').scan(/<li><a href=['"]([^'"]+)/).flatten.map { |f| "_site/#{f}" }
63
+ sh 'prince', '--input=html', '--no-network', '--log=prince_errors.log', "--output=#{task.name}", '_site/preface.html', *pages
64
+ end
65
+
66
+ desc "Build a copy of the Web site in the ./_site"
67
+ task :site=>['_site', :rdoc, '_reports/specs.html', '_reports/coverage', 'buildr.pdf'] do
68
+ cp_r 'rdoc', '_site'
69
+ fail 'No RDocs in site directory' unless File.exist?('_site/rdoc/files/lib/buildr_rb.html')
70
+ cp '_reports/specs.html', '_site'
71
+ cp_r '_reports/coverage', '_site'
72
+ fail 'No coverage report in site directory' unless File.exist?('_site/coverage/index.html')
73
+ cp 'CHANGELOG', '_site'
74
+ cp 'buildr.pdf', '_site'
75
+ fail 'No PDF in site directory' unless File.exist?('_site/buildr.pdf')
76
+ puts 'OK'
77
+ end
78
+
79
+ # Publish prerequisites to Web site.
80
+ task 'publish'=>:site do
81
+ target = "people.apache.org:/www/#{spec.name}.apache.org/"
82
+ puts "Uploading new site to #{target} ..."
83
+ sh 'rsync', '--progress', '--recursive', '--delete', '_site/', target
84
+ sh 'ssh', 'people.apache.org', 'chmod', '-R', 'g+w', "/www/#{spec.name}.apache.org/*"
85
+ puts "Done"
86
+ end
87
+
88
+ task :clobber do
89
+ rm_rf '_site'
90
+ rm_f 'buildr.pdf'
91
+ rm_f 'prince_errors.log'
92
+ end
@@ -0,0 +1,120 @@
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
+ gem 'mojombo-jekyll', '~> 0.5.2' # skip past some buggy versions
18
+ require 'rake/tasklib'
19
+ require 'jekyll'
20
+
21
+
22
+ class JekyllTask < Rake::TaskLib
23
+ def initialize(name=:jekyll) # :yield: self
24
+ @name = name
25
+ @source = name
26
+ @target = name
27
+ yield self if block_given?
28
+ task name, :auto, :needs=>[@source] do |task, args|
29
+ generate args.auto
30
+ end
31
+ if @source != @target
32
+ file @target=>FileList["#{@source}/**/*"] do
33
+ generate
34
+ end
35
+ task 'clobber' do
36
+ rm_rf @target
37
+ end
38
+ end
39
+ end
40
+
41
+ attr_accessor :source
42
+ attr_accessor :target
43
+
44
+ def generate(auto = false)
45
+ options = { 'source'=>source, 'destination'=>target }
46
+ options = Jekyll.configuration(options)
47
+ site = Jekyll::Site.new(options)
48
+
49
+ if auto
50
+ require 'directory_watcher'
51
+ puts "Auto generating: just edit a page and save, watch the console to see when we're done regenerating pages"
52
+ dw = DirectoryWatcher.new(source)
53
+ dw.interval = 1
54
+ dw.glob = Dir.chdir(source) do
55
+ dirs = Dir['*'].select { |x| File.directory?(x) }
56
+ dirs -= [target]
57
+ dirs = dirs.map { |x| "#{x}/**/*" }
58
+ dirs += ['*']
59
+ end
60
+ dw.start
61
+ dw.add_observer do |*args|
62
+ t = Time.now.strftime("%Y-%m-%d %H:%M:%S")
63
+ puts "[#{t}] regeneration: #{args.size} files changed"
64
+ site.process
65
+ puts "Done"
66
+ end
67
+ loop { sleep 1 }
68
+ else
69
+ puts "Generating documentation in #{target}"
70
+ site.process
71
+ touch target
72
+ end
73
+ end
74
+ end
75
+
76
+
77
+ module TocFilter
78
+ def toc(input)
79
+ input.scan(/<(h2)(?:>|\s+(.*?)>)([^<]*)<\/\1\s*>/mi).inject(%{<ol class="toc">}) { |toc, entry|
80
+ id = entry[1][/^id=(['"])(.*)\1$/, 2]
81
+ title = entry[2].gsub(/<(\w*).*?>(.*?)<\/\1\s*>/m, '\2').strip
82
+ toc << %{<li><a href="##{id}">#{title}</a></li>}
83
+ } << "</ol>"
84
+ end
85
+ end
86
+ Liquid::Template.register_filter(TocFilter)
87
+
88
+
89
+
90
+ # Under Ruby 1.9 [a,b,c].to_s doesn't join the array first. (Jekyll 0.5.2 requires this)
91
+ module Jekyll
92
+ class HighlightBlock < Liquid::Block
93
+ def render(context)
94
+ if context.registers[:site].pygments
95
+ render_pygments(context, super.join)
96
+ else
97
+ render_codehighlighter(context, super.join)
98
+ end
99
+ end
100
+ end
101
+ end
102
+
103
+ # Ruby 1.9 has sane closure scoping which manages to mess Liquid filters. (Liquid 2.0.0 requires this)
104
+ module Liquid
105
+ class Variable
106
+ def render(context)
107
+ return '' if @name.nil?
108
+ @filters.inject(context[@name]) do |output, filter|
109
+ filterargs = filter[1].to_a.collect do |a|
110
+ context[a]
111
+ end
112
+ begin
113
+ context.invoke(filter[0], output, *filterargs)
114
+ rescue FilterNotFound
115
+ raise FilterNotFound, "Error - filter '#{filter[0]}' in '#{@markup.strip}' could not be found."
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end