buildr-gemjar 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.braids +8 -0
- data/.gitignore +5 -0
- data/.rvmrc +1 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.md +98 -0
- data/Rakefile +8 -0
- data/buildr-gemjar.gemspec +42 -0
- data/lib/buildr-gemjar.rb +162 -0
- data/lib/buildr-gemjar/version.rb +3 -0
- data/meta.rakefile +30 -0
- data/spec/buildr-gemjar/version_spec.rb +11 -0
- data/spec/buildr-gemjar_spec.rb +179 -0
- data/spec/repo_builder.rb +59 -0
- data/spec/spec_helper.rb +44 -0
- data/vendor/buildr/.gitignore +17 -0
- data/vendor/buildr/CHANGELOG +1283 -0
- data/vendor/buildr/Gemfile +4 -0
- data/vendor/buildr/LICENSE +176 -0
- data/vendor/buildr/NOTICE +26 -0
- data/vendor/buildr/README.rdoc +134 -0
- data/vendor/buildr/Rakefile +44 -0
- data/vendor/buildr/_buildr +35 -0
- data/vendor/buildr/_jbuildr +35 -0
- data/vendor/buildr/addon/buildr/antlr.rb +65 -0
- data/vendor/buildr/addon/buildr/bnd.rb +147 -0
- data/vendor/buildr/addon/buildr/cobertura.rb +22 -0
- data/vendor/buildr/addon/buildr/drb.rb +281 -0
- data/vendor/buildr/addon/buildr/emma.rb +22 -0
- data/vendor/buildr/addon/buildr/hibernate.rb +149 -0
- data/vendor/buildr/addon/buildr/javacc.rb +85 -0
- data/vendor/buildr/addon/buildr/jaxb_xjc.rb +72 -0
- data/vendor/buildr/addon/buildr/jdepend.rb +60 -0
- data/vendor/buildr/addon/buildr/jetty.rb +248 -0
- data/vendor/buildr/addon/buildr/jibx.rb +86 -0
- data/vendor/buildr/addon/buildr/nailgun.rb +221 -0
- data/vendor/buildr/addon/buildr/openjpa.rb +88 -0
- data/vendor/buildr/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
- data/vendor/buildr/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
- data/vendor/buildr/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
- data/vendor/buildr/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
- data/vendor/buildr/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
- data/vendor/buildr/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
- data/vendor/buildr/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
- data/vendor/buildr/addon/buildr/protobuf.rb +88 -0
- data/vendor/buildr/addon/buildr/xmlbeans.rb +93 -0
- data/vendor/buildr/all-in-one/_buildr +19 -0
- data/vendor/buildr/all-in-one/buildr +368 -0
- data/vendor/buildr/all-in-one/buildr.cmd +1 -0
- data/vendor/buildr/bin/buildr +19 -0
- data/vendor/buildr/buildr.buildfile +58 -0
- data/vendor/buildr/buildr.gemspec +74 -0
- data/vendor/buildr/doc/_config.yml +1 -0
- data/vendor/buildr/doc/_layouts/default.html +90 -0
- data/vendor/buildr/doc/_layouts/preface.html +22 -0
- data/vendor/buildr/doc/artifacts.textile +217 -0
- data/vendor/buildr/doc/building.textile +276 -0
- data/vendor/buildr/doc/contributing.textile +268 -0
- data/vendor/buildr/doc/css/default.css +236 -0
- data/vendor/buildr/doc/css/print.css +101 -0
- data/vendor/buildr/doc/css/syntax.css +23 -0
- data/vendor/buildr/doc/download.textile +138 -0
- data/vendor/buildr/doc/extending.textile +212 -0
- data/vendor/buildr/doc/images/1442160941-frontcover.jpg +0 -0
- data/vendor/buildr/doc/images/asf-logo.gif +0 -0
- data/vendor/buildr/doc/images/asf-logo.png +0 -0
- data/vendor/buildr/doc/images/buildr-hires.png +0 -0
- data/vendor/buildr/doc/images/buildr.png +0 -0
- data/vendor/buildr/doc/images/favicon.png +0 -0
- data/vendor/buildr/doc/images/growl-icon.tiff +0 -0
- data/vendor/buildr/doc/images/note.png +0 -0
- data/vendor/buildr/doc/images/project-structure.png +0 -0
- data/vendor/buildr/doc/images/tip.png +0 -0
- data/vendor/buildr/doc/images/zbuildr.png +0 -0
- data/vendor/buildr/doc/images/zbuildr.tif +0 -0
- data/vendor/buildr/doc/index.textile +69 -0
- data/vendor/buildr/doc/installing.textile +284 -0
- data/vendor/buildr/doc/languages.textile +599 -0
- data/vendor/buildr/doc/mailing_lists.textile +29 -0
- data/vendor/buildr/doc/more_stuff.textile +845 -0
- data/vendor/buildr/doc/packaging.textile +618 -0
- data/vendor/buildr/doc/preface.textile +54 -0
- data/vendor/buildr/doc/projects.textile +276 -0
- data/vendor/buildr/doc/quick_start.textile +210 -0
- data/vendor/buildr/doc/releasing.textile +117 -0
- data/vendor/buildr/doc/scripts/buildr-git.rb +512 -0
- data/vendor/buildr/doc/scripts/gitflow.rb +296 -0
- data/vendor/buildr/doc/scripts/install-jruby.sh +44 -0
- data/vendor/buildr/doc/scripts/install-linux.sh +73 -0
- data/vendor/buildr/doc/scripts/install-osx.sh +52 -0
- data/vendor/buildr/doc/settings_profiles.textile +287 -0
- data/vendor/buildr/doc/testing.textile +247 -0
- data/vendor/buildr/etc/KEYS +189 -0
- data/vendor/buildr/lib/buildr.rb +44 -0
- data/vendor/buildr/lib/buildr/clojure.rb +34 -0
- data/vendor/buildr/lib/buildr/clojure/shell.rb +52 -0
- data/vendor/buildr/lib/buildr/core.rb +34 -0
- data/vendor/buildr/lib/buildr/core/application.rb +700 -0
- data/vendor/buildr/lib/buildr/core/build.rb +516 -0
- data/vendor/buildr/lib/buildr/core/cc.rb +166 -0
- data/vendor/buildr/lib/buildr/core/checks.rb +253 -0
- data/vendor/buildr/lib/buildr/core/common.rb +151 -0
- data/vendor/buildr/lib/buildr/core/compile.rb +622 -0
- data/vendor/buildr/lib/buildr/core/doc.rb +276 -0
- data/vendor/buildr/lib/buildr/core/environment.rb +129 -0
- data/vendor/buildr/lib/buildr/core/filter.rb +404 -0
- data/vendor/buildr/lib/buildr/core/generate.rb +197 -0
- data/vendor/buildr/lib/buildr/core/help.rb +119 -0
- data/vendor/buildr/lib/buildr/core/jrebel.rb +42 -0
- data/vendor/buildr/lib/buildr/core/linux.rb +30 -0
- data/vendor/buildr/lib/buildr/core/osx.rb +46 -0
- data/vendor/buildr/lib/buildr/core/progressbar.rb +161 -0
- data/vendor/buildr/lib/buildr/core/project.rb +975 -0
- data/vendor/buildr/lib/buildr/core/run.rb +43 -0
- data/vendor/buildr/lib/buildr/core/shell.rb +137 -0
- data/vendor/buildr/lib/buildr/core/test.rb +843 -0
- data/vendor/buildr/lib/buildr/core/transports.rb +565 -0
- data/vendor/buildr/lib/buildr/core/util.rb +537 -0
- data/vendor/buildr/lib/buildr/groovy.rb +20 -0
- data/vendor/buildr/lib/buildr/groovy/bdd.rb +106 -0
- data/vendor/buildr/lib/buildr/groovy/compiler.rb +153 -0
- data/vendor/buildr/lib/buildr/groovy/doc.rb +76 -0
- data/vendor/buildr/lib/buildr/groovy/shell.rb +57 -0
- data/vendor/buildr/lib/buildr/ide.rb +19 -0
- data/vendor/buildr/lib/buildr/ide/eclipse.rb +427 -0
- data/vendor/buildr/lib/buildr/ide/eclipse/java.rb +53 -0
- data/vendor/buildr/lib/buildr/ide/eclipse/plugin.rb +71 -0
- data/vendor/buildr/lib/buildr/ide/eclipse/scala.rb +68 -0
- data/vendor/buildr/lib/buildr/ide/idea.rb +576 -0
- data/vendor/buildr/lib/buildr/java.rb +25 -0
- data/vendor/buildr/lib/buildr/java/ant.rb +94 -0
- data/vendor/buildr/lib/buildr/java/bdd.rb +460 -0
- data/vendor/buildr/lib/buildr/java/cobertura.rb +297 -0
- data/vendor/buildr/lib/buildr/java/commands.rb +223 -0
- data/vendor/buildr/lib/buildr/java/compiler.rb +135 -0
- data/vendor/buildr/lib/buildr/java/deprecated.rb +141 -0
- data/vendor/buildr/lib/buildr/java/doc.rb +86 -0
- data/vendor/buildr/lib/buildr/java/ecj.rb +69 -0
- data/vendor/buildr/lib/buildr/java/emma.rb +244 -0
- data/vendor/buildr/lib/buildr/java/external.rb +73 -0
- data/vendor/buildr/lib/buildr/java/jruby.rb +122 -0
- data/vendor/buildr/lib/buildr/java/jtestr_result.rb +295 -0
- data/vendor/buildr/lib/buildr/java/jtestr_runner.rb.erb +116 -0
- data/vendor/buildr/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
- data/vendor/buildr/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +142 -0
- data/vendor/buildr/lib/buildr/java/packaging.rb +734 -0
- data/vendor/buildr/lib/buildr/java/pom.rb +178 -0
- data/vendor/buildr/lib/buildr/java/rjb.rb +154 -0
- data/vendor/buildr/lib/buildr/java/test_result.rb +101 -0
- data/vendor/buildr/lib/buildr/java/tests.rb +362 -0
- data/vendor/buildr/lib/buildr/java/version_requirement.rb +172 -0
- data/vendor/buildr/lib/buildr/packaging.rb +25 -0
- data/vendor/buildr/lib/buildr/packaging/archive.rb +535 -0
- data/vendor/buildr/lib/buildr/packaging/artifact.rb +903 -0
- data/vendor/buildr/lib/buildr/packaging/artifact_namespace.rb +984 -0
- data/vendor/buildr/lib/buildr/packaging/artifact_search.rb +140 -0
- data/vendor/buildr/lib/buildr/packaging/gems.rb +105 -0
- data/vendor/buildr/lib/buildr/packaging/package.rb +249 -0
- data/vendor/buildr/lib/buildr/packaging/tar.rb +189 -0
- data/vendor/buildr/lib/buildr/packaging/version_requirement.rb +192 -0
- data/vendor/buildr/lib/buildr/packaging/zip.rb +178 -0
- data/vendor/buildr/lib/buildr/packaging/ziptask.rb +356 -0
- data/vendor/buildr/lib/buildr/resources/buildr.icns +0 -0
- data/vendor/buildr/lib/buildr/resources/completed.png +0 -0
- data/vendor/buildr/lib/buildr/resources/failed.png +0 -0
- data/vendor/buildr/lib/buildr/resources/icons-license.txt +17 -0
- data/vendor/buildr/lib/buildr/run.rb +195 -0
- data/vendor/buildr/lib/buildr/scala.rb +26 -0
- data/vendor/buildr/lib/buildr/scala/bdd.rb +118 -0
- data/vendor/buildr/lib/buildr/scala/compiler.rb +242 -0
- data/vendor/buildr/lib/buildr/scala/doc.rb +142 -0
- data/vendor/buildr/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.class +0 -0
- data/vendor/buildr/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.java +57 -0
- data/vendor/buildr/lib/buildr/scala/shell.rb +52 -0
- data/vendor/buildr/lib/buildr/scala/tests.rb +171 -0
- data/vendor/buildr/lib/buildr/shell.rb +185 -0
- data/vendor/buildr/lib/buildr/version.rb +18 -0
- data/vendor/buildr/rakelib/all-in-one.rake +113 -0
- data/vendor/buildr/rakelib/checks.rake +57 -0
- data/vendor/buildr/rakelib/doc.rake +137 -0
- data/vendor/buildr/rakelib/metrics.rake +39 -0
- data/vendor/buildr/rakelib/package.rake +73 -0
- data/vendor/buildr/rakelib/release.rake +161 -0
- data/vendor/buildr/rakelib/rspec.rake +101 -0
- data/vendor/buildr/rakelib/setup.rake +66 -0
- data/vendor/buildr/rakelib/stage.rake +220 -0
- data/vendor/buildr/spec/addon/bnd_spec.rb +330 -0
- data/vendor/buildr/spec/addon/drb_spec.rb +328 -0
- data/vendor/buildr/spec/addon/jaxb_xjc_spec.rb +125 -0
- data/vendor/buildr/spec/core/application_spec.rb +631 -0
- data/vendor/buildr/spec/core/build_spec.rb +837 -0
- data/vendor/buildr/spec/core/cc_spec.rb +224 -0
- data/vendor/buildr/spec/core/checks_spec.rb +519 -0
- data/vendor/buildr/spec/core/common_spec.rb +725 -0
- data/vendor/buildr/spec/core/compile_spec.rb +658 -0
- data/vendor/buildr/spec/core/doc_spec.rb +195 -0
- data/vendor/buildr/spec/core/extension_spec.rb +201 -0
- data/vendor/buildr/spec/core/generate_spec.rb +33 -0
- data/vendor/buildr/spec/core/project_spec.rb +772 -0
- data/vendor/buildr/spec/core/run_spec.rb +93 -0
- data/vendor/buildr/spec/core/shell_spec.rb +146 -0
- data/vendor/buildr/spec/core/test_spec.rb +1320 -0
- data/vendor/buildr/spec/core/transport_spec.rb +544 -0
- data/vendor/buildr/spec/core/util_spec.rb +141 -0
- data/vendor/buildr/spec/groovy/bdd_spec.rb +80 -0
- data/vendor/buildr/spec/groovy/compiler_spec.rb +251 -0
- data/vendor/buildr/spec/groovy/doc_spec.rb +65 -0
- data/vendor/buildr/spec/ide/eclipse_spec.rb +739 -0
- data/vendor/buildr/spec/ide/idea_spec.rb +1144 -0
- data/vendor/buildr/spec/java/ant_spec.rb +37 -0
- data/vendor/buildr/spec/java/bdd_spec.rb +374 -0
- data/vendor/buildr/spec/java/cobertura_spec.rb +112 -0
- data/vendor/buildr/spec/java/commands_spec.rb +93 -0
- data/vendor/buildr/spec/java/compiler_spec.rb +252 -0
- data/vendor/buildr/spec/java/doc_spec.rb +56 -0
- data/vendor/buildr/spec/java/ecj_spec.rb +115 -0
- data/vendor/buildr/spec/java/emma_spec.rb +121 -0
- data/vendor/buildr/spec/java/external_spec.rb +56 -0
- data/vendor/buildr/spec/java/java_spec.rb +132 -0
- data/vendor/buildr/spec/java/packaging_spec.rb +1270 -0
- data/vendor/buildr/spec/java/run_spec.rb +78 -0
- data/vendor/buildr/spec/java/test_coverage_helper.rb +257 -0
- data/vendor/buildr/spec/java/tests_spec.rb +497 -0
- data/vendor/buildr/spec/packaging/archive_spec.rb +775 -0
- data/vendor/buildr/spec/packaging/artifact_namespace_spec.rb +743 -0
- data/vendor/buildr/spec/packaging/artifact_spec.rb +1066 -0
- data/vendor/buildr/spec/packaging/packaging_helper.rb +63 -0
- data/vendor/buildr/spec/packaging/packaging_spec.rb +719 -0
- data/vendor/buildr/spec/sandbox.rb +165 -0
- data/vendor/buildr/spec/scala/bdd_spec.rb +124 -0
- data/vendor/buildr/spec/scala/compiler_spec.rb +289 -0
- data/vendor/buildr/spec/scala/doc_spec.rb +88 -0
- data/vendor/buildr/spec/scala/scala.rb +38 -0
- data/vendor/buildr/spec/scala/tests_spec.rb +283 -0
- data/vendor/buildr/spec/spec_helpers.rb +369 -0
- data/vendor/buildr/spec/version_requirement_spec.rb +143 -0
- data/vendor/buildr/spec/xpath_matchers.rb +121 -0
- data/vendor/buildr/tests/BUILDR-320/Buildfile +29 -0
- data/vendor/buildr/tests/JavaSystemProperty/Buildfile +18 -0
- data/vendor/buildr/tests/JavaSystemProperty/src/test/java/FooTest.java +24 -0
- data/vendor/buildr/tests/compile_with_parent/Buildfile +18 -0
- data/vendor/buildr/tests/compile_with_parent/child/src/main/java/Foo.java +23 -0
- data/vendor/buildr/tests/helloWorld/Buildfile +20 -0
- data/vendor/buildr/tests/helloWorld/src/main/java/HelloWorld.java +23 -0
- data/vendor/buildr/tests/integration_testing.rb +56 -0
- data/vendor/buildr/tests/junit3/Buildfile +9 -0
- data/vendor/buildr/tests/junit3/src/main/java/Foo.java +23 -0
- data/vendor/buildr/tests/junit3/src/test/java/FooTest.java +28 -0
- data/vendor/buildr/tests/package_war_as_jar/Buildfile +15 -0
- data/vendor/buildr/tests/package_war_as_jar/src/main/java/Foo.java +19 -0
- metadata +524 -0
@@ -0,0 +1,276 @@
|
|
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
|
+
module Buildr
|
17
|
+
module Doc
|
18
|
+
include Extension
|
19
|
+
|
20
|
+
class << self
|
21
|
+
def select_by_lang(lang)
|
22
|
+
fail 'Unable to define doc task for nil language' if lang.nil?
|
23
|
+
engines.detect { |e| e.language.to_sym == lang.to_sym }
|
24
|
+
end
|
25
|
+
|
26
|
+
alias_method :select, :select_by_lang
|
27
|
+
|
28
|
+
def select_by_name(name)
|
29
|
+
fail 'Unable to define doc task for nil' if name.nil?
|
30
|
+
engines.detect { |e| e.to_sym == name.to_sym }
|
31
|
+
end
|
32
|
+
|
33
|
+
def engines
|
34
|
+
@engines ||= []
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
# Base class for any documentation provider. Defines most
|
40
|
+
# common functionality (things like @into@, @from@ and friends).
|
41
|
+
class Base
|
42
|
+
class << self
|
43
|
+
attr_accessor :language, :source_ext
|
44
|
+
|
45
|
+
def specify(options)
|
46
|
+
@language = options[:language]
|
47
|
+
@source_ext = options[:source_ext]
|
48
|
+
end
|
49
|
+
|
50
|
+
def to_sym
|
51
|
+
@symbol ||= name.split('::').last.downcase.to_sym
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
attr_reader :project
|
56
|
+
|
57
|
+
def initialize(project)
|
58
|
+
@project = project
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
class DocTask < Rake::Task
|
64
|
+
|
65
|
+
# The target directory for the generated documentation files.
|
66
|
+
attr_reader :target
|
67
|
+
|
68
|
+
# Classpath dependencies.
|
69
|
+
attr_accessor :classpath
|
70
|
+
|
71
|
+
# Additional sourcepaths that are not part of the documented files.
|
72
|
+
attr_accessor :sourcepath
|
73
|
+
|
74
|
+
# Returns the documentation tool options.
|
75
|
+
attr_reader :options
|
76
|
+
|
77
|
+
attr_reader :project # :nodoc:
|
78
|
+
|
79
|
+
def initialize(*args) #:nodoc:
|
80
|
+
super
|
81
|
+
@options = {}
|
82
|
+
@classpath = []
|
83
|
+
@sourcepath = []
|
84
|
+
@files = FileList[]
|
85
|
+
enhance do |task|
|
86
|
+
rm_rf target.to_s
|
87
|
+
mkdir_p target.to_s
|
88
|
+
|
89
|
+
engine.generate(source_files, File.expand_path(target.to_s),
|
90
|
+
options.merge(:classpath => classpath, :sourcepath => sourcepath))
|
91
|
+
|
92
|
+
touch target.to_s
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# :call-seq:
|
97
|
+
# into(path) => self
|
98
|
+
#
|
99
|
+
# Sets the target directory and returns self. This will also set the Javadoc task
|
100
|
+
# as a prerequisite to a file task on the target directory.
|
101
|
+
#
|
102
|
+
# For example:
|
103
|
+
# package :zip, :classifier=>'docs', :include=>doc.target
|
104
|
+
def into(path)
|
105
|
+
@target = file(path.to_s).enhance([self]) unless @target && @target.to_s == path.to_s
|
106
|
+
self
|
107
|
+
end
|
108
|
+
|
109
|
+
# :call-seq:
|
110
|
+
# include(*files) => self
|
111
|
+
#
|
112
|
+
# Includes additional source files and directories when generating the documentation
|
113
|
+
# and returns self. When specifying a directory, includes all source files in that directory.
|
114
|
+
def include(*files)
|
115
|
+
@files.include *files.flatten.compact
|
116
|
+
self
|
117
|
+
end
|
118
|
+
|
119
|
+
# :call-seq:
|
120
|
+
# exclude(*files) => self
|
121
|
+
#
|
122
|
+
# Excludes source files and directories from generating the documentation.
|
123
|
+
def exclude(*files)
|
124
|
+
@files.exclude *files
|
125
|
+
self
|
126
|
+
end
|
127
|
+
|
128
|
+
# :call-seq:
|
129
|
+
# with(*artifacts) => self
|
130
|
+
#
|
131
|
+
# Adds files and artifacts as classpath dependencies, and returns self.
|
132
|
+
def with(*specs)
|
133
|
+
@classpath |= Buildr.artifacts(specs.flatten).uniq
|
134
|
+
self
|
135
|
+
end
|
136
|
+
|
137
|
+
# :call-seq:
|
138
|
+
# using(options) => self
|
139
|
+
#
|
140
|
+
# Sets the documentation tool options from a hash and returns self.
|
141
|
+
#
|
142
|
+
# For example:
|
143
|
+
# doc.using :windowtitle=>'My application'
|
144
|
+
# doc.using :vscaladoc
|
145
|
+
def using(*args)
|
146
|
+
args.pop.each { |key, value| @options[key.to_sym] = value } if Hash === args.last
|
147
|
+
|
148
|
+
until args.empty?
|
149
|
+
new_engine = Doc.select_by_name(args.pop)
|
150
|
+
@engine = new_engine.new(project) unless new_engine.nil?
|
151
|
+
end
|
152
|
+
|
153
|
+
self
|
154
|
+
end
|
155
|
+
|
156
|
+
def engine
|
157
|
+
@engine ||= guess_engine
|
158
|
+
end
|
159
|
+
|
160
|
+
# :call-seq:
|
161
|
+
# engine?(clazz) => boolean
|
162
|
+
#
|
163
|
+
# Check if the underlying engine is an instance of the given class
|
164
|
+
def engine?(clazz)
|
165
|
+
begin
|
166
|
+
@engine ||= guess_engine if project.compile.language
|
167
|
+
rescue
|
168
|
+
return false
|
169
|
+
end
|
170
|
+
@engine.is_a?(clazz) if @engine
|
171
|
+
end
|
172
|
+
|
173
|
+
# :call-seq:
|
174
|
+
# from(*sources) => self
|
175
|
+
#
|
176
|
+
# Includes files, directories and projects in the documentation and returns self.
|
177
|
+
#
|
178
|
+
# You can call this method with source files and directories containing source files
|
179
|
+
# to include these files in the documentation, similar to #include. You can also call
|
180
|
+
# this method with projects. When called with a project, it includes all the source files compiled
|
181
|
+
# by that project and classpath dependencies used when compiling.
|
182
|
+
#
|
183
|
+
# For example:
|
184
|
+
# doc.from projects('myapp:foo', 'myapp:bar')
|
185
|
+
def from(*sources)
|
186
|
+
sources.flatten.each do |source|
|
187
|
+
case source
|
188
|
+
when Project
|
189
|
+
self.enhance source.prerequisites
|
190
|
+
self.include source.compile.sources
|
191
|
+
self.with source.compile.dependencies
|
192
|
+
when Rake::Task, String
|
193
|
+
self.include source
|
194
|
+
else
|
195
|
+
fail "Don't know how to generate documentation from #{source || 'nil'}"
|
196
|
+
end
|
197
|
+
end
|
198
|
+
self
|
199
|
+
end
|
200
|
+
|
201
|
+
def prerequisites #:nodoc:
|
202
|
+
super + @files + classpath + sourcepath
|
203
|
+
end
|
204
|
+
|
205
|
+
def source_files #:nodoc:
|
206
|
+
@source_files ||= @files.map(&:to_s).map do |file|
|
207
|
+
Array(engine.class.source_ext).map do |ext|
|
208
|
+
File.directory?(file) ? FileList[File.join(file, "**/*.#{ext}")] : file
|
209
|
+
end
|
210
|
+
end.flatten.reject { |file| @files.exclude?(file) }
|
211
|
+
end
|
212
|
+
|
213
|
+
def needed? #:nodoc:
|
214
|
+
return false if source_files.empty?
|
215
|
+
return true unless File.exist?(target.to_s)
|
216
|
+
source_files.map { |src| File.stat(src.to_s).mtime }.max > File.stat(target.to_s).mtime
|
217
|
+
end
|
218
|
+
|
219
|
+
private
|
220
|
+
|
221
|
+
def guess_engine
|
222
|
+
doc_engine = Doc.select project.compile.language
|
223
|
+
fail 'Unable to guess documentation provider for project.' unless doc_engine
|
224
|
+
doc_engine.new project
|
225
|
+
end
|
226
|
+
|
227
|
+
def associate_with(project)
|
228
|
+
@project ||= project
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
|
233
|
+
first_time do
|
234
|
+
desc 'Create the documentation for this project'
|
235
|
+
Project.local_task :doc
|
236
|
+
end
|
237
|
+
|
238
|
+
before_define(:doc) do |project|
|
239
|
+
DocTask.define_task('doc').tap do |doc|
|
240
|
+
doc.send(:associate_with, project)
|
241
|
+
doc.into project.path_to(:target, :doc)
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
after_define(:doc) do |project|
|
246
|
+
project.doc.from project
|
247
|
+
end
|
248
|
+
|
249
|
+
# :call-seq:
|
250
|
+
# doc(*sources) => JavadocTask
|
251
|
+
#
|
252
|
+
# This method returns the project's documentation task. It also accepts a list of source files,
|
253
|
+
# directories and projects to include when generating the docs.
|
254
|
+
#
|
255
|
+
# By default the doc task uses all the source directories from compile.sources and generates
|
256
|
+
# documentation in the target/doc directory. This method accepts sources and adds them by calling
|
257
|
+
# Buildr::Doc::Base#from.
|
258
|
+
#
|
259
|
+
# For example, if you want to generate documentation for a given project that includes all source files
|
260
|
+
# in two of its sub-projects:
|
261
|
+
# doc projects('myapp:foo', 'myapp:bar').using(:windowtitle=>'Docs for foo and bar')
|
262
|
+
def doc(*sources, &block)
|
263
|
+
task('doc').from(*sources).enhance &block
|
264
|
+
end
|
265
|
+
|
266
|
+
def javadoc(*sources, &block)
|
267
|
+
warn 'The javadoc method is deprecated and will be removed in a future release.'
|
268
|
+
doc(*sources, &block)
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
|
273
|
+
class Project
|
274
|
+
include Doc
|
275
|
+
end
|
276
|
+
end
|
@@ -0,0 +1,129 @@
|
|
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
|
+
|
19
|
+
# Collection of options for controlling Buildr.
|
20
|
+
class Options
|
21
|
+
|
22
|
+
# We use this to present environment variable as arrays.
|
23
|
+
class EnvArray < Array #:nodoc:
|
24
|
+
|
25
|
+
def initialize(name)
|
26
|
+
@name = name.upcase
|
27
|
+
replace((ENV[@name] || ENV[@name.downcase] || '').split(/\s*,\s*/).reject(&:empty?))
|
28
|
+
end
|
29
|
+
|
30
|
+
(Array.instance_methods - Object.instance_methods - Enumerable.instance_methods - ['each']).sort.each do |method|
|
31
|
+
class_eval %{def #{method}(*args, &block) ; result = super ; write_envarray ; result ; end}
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def write_envarray
|
37
|
+
ENV[@name.downcase] = nil
|
38
|
+
ENV[@name] = map(&:to_s).join(',')
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
# Wraps around the proxy environment variables:
|
45
|
+
# * :http -- HTTP_PROXY
|
46
|
+
# * :https -- HTTPS_PROXY
|
47
|
+
# * :exclude -- NO_PROXY
|
48
|
+
class Proxies
|
49
|
+
|
50
|
+
# Returns the HTTP_PROXY URL.
|
51
|
+
def http
|
52
|
+
ENV['HTTP_PROXY'] || ENV['http_proxy']
|
53
|
+
end
|
54
|
+
|
55
|
+
# Sets the HTTP_PROXY URL.
|
56
|
+
def http=(url)
|
57
|
+
ENV['http_proxy'] = nil
|
58
|
+
ENV['HTTP_PROXY'] = url
|
59
|
+
end
|
60
|
+
|
61
|
+
# Returns the HTTPS_PROXY URL.
|
62
|
+
def https
|
63
|
+
ENV['HTTPS_PROXY'] || ENV['https_proxy']
|
64
|
+
end
|
65
|
+
|
66
|
+
# Sets the HTTPS_PROXY URL.
|
67
|
+
def https=(url)
|
68
|
+
ENV['https_proxy'] = nil
|
69
|
+
ENV['HTTPS_PROXY'] = url
|
70
|
+
end
|
71
|
+
|
72
|
+
# Returns list of hosts to exclude from proxying (NO_PROXY).
|
73
|
+
def exclude
|
74
|
+
@exclude ||= EnvArray.new('NO_PROXY')
|
75
|
+
end
|
76
|
+
|
77
|
+
# Sets list of hosts to exclude from proxy (NO_PROXY). Accepts host name, array of names,
|
78
|
+
# or nil to clear the list.
|
79
|
+
def exclude=(url)
|
80
|
+
exclude.clear
|
81
|
+
exclude.concat [url].flatten if url
|
82
|
+
exclude
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
# :call-seq:
|
88
|
+
# proxy => options
|
89
|
+
#
|
90
|
+
# Returns the proxy options. Currently supported options are:
|
91
|
+
# * :http -- HTTP proxy for use when downloading.
|
92
|
+
# * :exclude -- Do not use proxy for these hosts/domains.
|
93
|
+
#
|
94
|
+
# For example:
|
95
|
+
# options.proxy.http = 'http://proxy.acme.com:8080'
|
96
|
+
# You can also set it using the environment variable HTTP_PROXY.
|
97
|
+
#
|
98
|
+
# You can exclude individual hosts from being proxied, or entire domains, for example:
|
99
|
+
# options.proxy.exclude = 'optimus'
|
100
|
+
# options.proxy.exclude = ['optimus', 'prime']
|
101
|
+
# options.proxy.exclude << '*.internal'
|
102
|
+
def proxy
|
103
|
+
@proxy ||= Proxies.new
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
class << self
|
110
|
+
|
111
|
+
# :call-seq:
|
112
|
+
# options => Options
|
113
|
+
#
|
114
|
+
# Returns the Buildr options. See Options.
|
115
|
+
def options
|
116
|
+
@options ||= Options.new
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
# :call-seq:
|
122
|
+
# options => Options
|
123
|
+
#
|
124
|
+
# Returns the Buildr options. See Options.
|
125
|
+
def options
|
126
|
+
Buildr.options
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
@@ -0,0 +1,404 @@
|
|
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 'erb'
|
18
|
+
|
19
|
+
|
20
|
+
module Buildr
|
21
|
+
|
22
|
+
# A filter knows how to copy files from one directory to another, applying mappings to the
|
23
|
+
# contents of these files.
|
24
|
+
#
|
25
|
+
# You can specify the mapping using a Hash, and it will map ${key} fields found in each source
|
26
|
+
# file into the appropriate value in the target file. For example:
|
27
|
+
#
|
28
|
+
# filter.using 'version'=>'1.2', 'build'=>Time.now
|
29
|
+
#
|
30
|
+
# will replace all occurrences of <tt>${version}</tt> with <tt>1.2</tt>, and <tt>${build}</tt>
|
31
|
+
# with the current date/time.
|
32
|
+
#
|
33
|
+
# You can also specify the mapping by passing a proc or a method, that will be called for
|
34
|
+
# each source file, with the file name and content, returning the modified content.
|
35
|
+
#
|
36
|
+
# Without any mapping, the filter simply copies files from the source directory into the target
|
37
|
+
# directory.
|
38
|
+
#
|
39
|
+
# A filter has one target directory, but you can specify any number of source directories,
|
40
|
+
# either when creating the filter or calling #from. Include/exclude patterns are specified
|
41
|
+
# relative to the source directories, so:
|
42
|
+
# filter.include '*.png'
|
43
|
+
# will only include PNG files from any of the source directories.
|
44
|
+
# In the same way, you can use regular expressions, so:
|
45
|
+
# filter.include /picture_.*\.png/
|
46
|
+
# will only include PNG files starting with picture_ from any of the sources directories.
|
47
|
+
#
|
48
|
+
# See Buildr#filter.
|
49
|
+
class Filter
|
50
|
+
|
51
|
+
def initialize #:nodoc:
|
52
|
+
clear
|
53
|
+
end
|
54
|
+
|
55
|
+
# Returns the list of source directories (each being a file task).
|
56
|
+
attr_reader :sources
|
57
|
+
|
58
|
+
# :call-seq:
|
59
|
+
# clear => self
|
60
|
+
#
|
61
|
+
# Clear filter sources and include/exclude patterns
|
62
|
+
def clear
|
63
|
+
@include = []
|
64
|
+
@exclude = []
|
65
|
+
@sources = FileList[]
|
66
|
+
@mapper = Mapper.new
|
67
|
+
self
|
68
|
+
end
|
69
|
+
|
70
|
+
# :call-seq:
|
71
|
+
# from(*sources) => self
|
72
|
+
#
|
73
|
+
# Adds additional directories from which to copy resources.
|
74
|
+
#
|
75
|
+
# For example:
|
76
|
+
# filter.from('src').into('target').using('build'=>Time.now)
|
77
|
+
def from(*sources)
|
78
|
+
@sources |= sources.flatten.map { |dir| file(File.expand_path(dir.to_s)) }
|
79
|
+
self
|
80
|
+
end
|
81
|
+
|
82
|
+
# The target directory as a file task.
|
83
|
+
def target
|
84
|
+
return nil unless @target_dir
|
85
|
+
unless @target
|
86
|
+
@target = file(File.expand_path(@target_dir)) { |task| run if @target == task }
|
87
|
+
@target.enhance @include.select {|f| f.is_a?(Rake::FileTask)}
|
88
|
+
@target.enhance @exclude.select {|f| f.is_a?(Rake::FileTask)}
|
89
|
+
@target.enhance copy_map.values
|
90
|
+
end
|
91
|
+
@target
|
92
|
+
end
|
93
|
+
|
94
|
+
# :call-seq:
|
95
|
+
# into(dir) => self
|
96
|
+
#
|
97
|
+
# Sets the target directory into which files are copied and returns self.
|
98
|
+
#
|
99
|
+
# For example:
|
100
|
+
# filter.from('src').into('target').using('build'=>Time.now)
|
101
|
+
def into(dir)
|
102
|
+
@target_dir = dir.to_s
|
103
|
+
@target = nil
|
104
|
+
self
|
105
|
+
end
|
106
|
+
|
107
|
+
# :call-seq:
|
108
|
+
# include(*files) => self
|
109
|
+
#
|
110
|
+
# Specifies files to include and returns self. See FileList#include.
|
111
|
+
#
|
112
|
+
# By default all files are included. You can use this method to only include specific
|
113
|
+
# files from the source directory.
|
114
|
+
def include(*files)
|
115
|
+
@include += files.flatten
|
116
|
+
self
|
117
|
+
end
|
118
|
+
alias :add :include
|
119
|
+
|
120
|
+
# :call-seq:
|
121
|
+
# exclude(*files) => self
|
122
|
+
#
|
123
|
+
# Specifies files to exclude and returns self. See FileList#exclude.
|
124
|
+
def exclude(*files)
|
125
|
+
@exclude += files.flatten
|
126
|
+
self
|
127
|
+
end
|
128
|
+
|
129
|
+
# The mapping. See #using.
|
130
|
+
def mapping #:nodoc:
|
131
|
+
@mapper.config
|
132
|
+
end
|
133
|
+
|
134
|
+
# The mapper to use. See #using.
|
135
|
+
def mapper #:nodoc:
|
136
|
+
@mapper.mapper_type
|
137
|
+
end
|
138
|
+
|
139
|
+
# :call-seq:
|
140
|
+
# using(mapping) => self
|
141
|
+
# using { |file_name, contents| ... } => self
|
142
|
+
#
|
143
|
+
# Specifies the mapping to use and returns self.
|
144
|
+
#
|
145
|
+
# The most typical mapping uses a Hash, and the default mapping uses the Maven style, so
|
146
|
+
# <code>${key}</code> are mapped to the values. You can change that by passing a different
|
147
|
+
# format as the first argument. Currently supports:
|
148
|
+
# * :ant -- Map <code>@key@</code>.
|
149
|
+
# * :maven -- Map <code>${key}</code> (default).
|
150
|
+
# * :ruby -- Map <code>#{key}</code>.
|
151
|
+
# * :erb -- Map <code><%= key %></code>.
|
152
|
+
# * Regexp -- Maps the matched data (e.g. <code>/=(.*?)=/</code>
|
153
|
+
#
|
154
|
+
# For example:
|
155
|
+
# filter.using 'version'=>'1.2'
|
156
|
+
# Is the same as:
|
157
|
+
# filter.using :maven, 'version'=>'1.2'
|
158
|
+
#
|
159
|
+
# You can also pass a proc or method. It will be called with the file name and content,
|
160
|
+
# to return the mapped content.
|
161
|
+
#
|
162
|
+
# Without any mapping, all files are copied as is.
|
163
|
+
#
|
164
|
+
# To register new mapping type see the Mapper class.
|
165
|
+
def using(*args, &block)
|
166
|
+
@mapper.using(*args, &block)
|
167
|
+
self
|
168
|
+
end
|
169
|
+
|
170
|
+
# :call-seq:
|
171
|
+
# run => boolean
|
172
|
+
#
|
173
|
+
# Runs the filter.
|
174
|
+
def run
|
175
|
+
copy_map = copy_map()
|
176
|
+
|
177
|
+
mkpath target.to_s
|
178
|
+
return false if copy_map.empty?
|
179
|
+
|
180
|
+
copy_map.each do |path, source|
|
181
|
+
dest = File.expand_path(path, target.to_s)
|
182
|
+
if File.directory?(source)
|
183
|
+
mkpath dest
|
184
|
+
else
|
185
|
+
mkpath File.dirname(dest)
|
186
|
+
if @mapper.mapper_type
|
187
|
+
mapped = @mapper.transform(File.open(source, 'rb') { |file| file.read }, path)
|
188
|
+
File.open(dest, 'wb') { |file| file.write mapped }
|
189
|
+
else # no mapping
|
190
|
+
cp source, dest
|
191
|
+
end
|
192
|
+
end
|
193
|
+
File.chmod(File.stat(source).mode | 0200, dest)
|
194
|
+
end
|
195
|
+
touch target.to_s
|
196
|
+
true
|
197
|
+
end
|
198
|
+
|
199
|
+
# Returns the target directory.
|
200
|
+
def to_s
|
201
|
+
target.to_s
|
202
|
+
end
|
203
|
+
|
204
|
+
protected
|
205
|
+
|
206
|
+
# :call-seq:
|
207
|
+
# pattern_match(file, pattern) => boolean
|
208
|
+
#
|
209
|
+
# This method returns true if the file name matches the pattern.
|
210
|
+
# The pattern may be a String, a Regexp or a Proc.
|
211
|
+
#
|
212
|
+
def pattern_match(file, pattern)
|
213
|
+
case
|
214
|
+
when pattern.is_a?(Regexp)
|
215
|
+
return file.match(pattern)
|
216
|
+
when pattern.is_a?(String)
|
217
|
+
return File.fnmatch(pattern, file)
|
218
|
+
when pattern.is_a?(Proc)
|
219
|
+
return pattern.call(file)
|
220
|
+
when pattern.is_a?(Rake::FileTask)
|
221
|
+
return pattern.to_s.match(file)
|
222
|
+
else
|
223
|
+
raise "Cannot interpret pattern #{pattern}"
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
private
|
228
|
+
def copy_map
|
229
|
+
sources.each { |source| raise "Source directory #{source} doesn't exist" unless File.exist?(source.to_s) }
|
230
|
+
raise 'No target directory specified, where am I going to copy the files to?' if target.nil?
|
231
|
+
|
232
|
+
sources.flatten.map(&:to_s).inject({}) do |map, source|
|
233
|
+
files = Util.recursive_with_dot_files(source).
|
234
|
+
map { |file| Util.relative_path(file, source) }.
|
235
|
+
select { |file| @include.empty? || @include.any? { |pattern| pattern_match(file, pattern) } }.
|
236
|
+
reject { |file| @exclude.any? { |pattern| pattern_match(file, pattern) } }
|
237
|
+
files.each do |file|
|
238
|
+
src, dest = File.expand_path(file, source), File.expand_path(file, target.to_s)
|
239
|
+
map[file] = src if !File.exist?(dest) || File.stat(src).mtime >= File.stat(dest).mtime
|
240
|
+
end
|
241
|
+
map
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
# This class implements content replacement logic for Filter.
|
246
|
+
#
|
247
|
+
# To register a new template engine @:foo@, extend this class with a method like:
|
248
|
+
#
|
249
|
+
# def foo_transform(content, path = nil)
|
250
|
+
# # if this method yields a key, the value comes from the mapping hash
|
251
|
+
# content.gsub(/world/) { |str| yield :bar }
|
252
|
+
# end
|
253
|
+
#
|
254
|
+
# Then you can use :foo mapping type on a Filter
|
255
|
+
#
|
256
|
+
# filter.using :foo, :bar => :baz
|
257
|
+
#
|
258
|
+
# Or all by your own, simply
|
259
|
+
#
|
260
|
+
# Mapper.new(:foo, :bar => :baz).transform("Hello world") # => "Hello baz"
|
261
|
+
#
|
262
|
+
# You can handle configuration arguments by providing a @*_config@ method like:
|
263
|
+
#
|
264
|
+
# # The return value of this method is available with the :config accessor.
|
265
|
+
# def moo_config(*args, &block)
|
266
|
+
# raise ArgumentError, "Expected moo block" unless block_given?
|
267
|
+
# { :moos => args, :callback => block }
|
268
|
+
# end
|
269
|
+
#
|
270
|
+
# def moo_transform(content, path = nil)
|
271
|
+
# content.gsub(/moo+/i) do |str|
|
272
|
+
# moos = yield :moos # same than config[:moos]
|
273
|
+
# moo = moos[str.size - 3] || str
|
274
|
+
# config[:callback].call(moo)
|
275
|
+
# end
|
276
|
+
# end
|
277
|
+
#
|
278
|
+
# Usage for the @:moo@ mapper would be something like:
|
279
|
+
#
|
280
|
+
# mapper = Mapper.new(:moo, 'ooone', 'twoo') do |str|
|
281
|
+
# i = nil; str.capitalize.gsub(/\w/) { |s| s.send( (i = !i) ? 'upcase' : 'downcase' ) }
|
282
|
+
# end
|
283
|
+
# mapper.transform('Moo cow, mooo cows singing mooooo') # => 'OoOnE cow, TwOo cows singing MoOoOo'
|
284
|
+
class Mapper
|
285
|
+
|
286
|
+
attr_reader :mapper_type, :config
|
287
|
+
|
288
|
+
def initialize(*args, &block) #:nodoc:
|
289
|
+
using(*args, &block)
|
290
|
+
end
|
291
|
+
|
292
|
+
def using(*args, &block)
|
293
|
+
case args.first
|
294
|
+
when Hash # Maven hash mapping
|
295
|
+
using :maven, *args
|
296
|
+
when Binding # Erb binding
|
297
|
+
using :erb, *args
|
298
|
+
when Symbol # Mapping from a method
|
299
|
+
raise ArgumentError, "Unknown mapping type: #{args.first}" unless respond_to?("#{args.first}_transform", true)
|
300
|
+
configure(*args, &block)
|
301
|
+
when Regexp # Mapping using a regular expression
|
302
|
+
raise ArgumentError, 'Expected regular expression followed by mapping hash' unless args.size == 2 && Hash === args[1]
|
303
|
+
@mapper_type, @config = *args
|
304
|
+
else
|
305
|
+
unless args.empty? && block.nil?
|
306
|
+
raise ArgumentError, 'Expected proc, method or a block' if args.size > 1 || (args.first && block)
|
307
|
+
@mapper_type = :callback
|
308
|
+
config = args.first || block
|
309
|
+
raise ArgumentError, 'Expected proc, method or callable' unless config.respond_to?(:call)
|
310
|
+
@config = config
|
311
|
+
end
|
312
|
+
end
|
313
|
+
self
|
314
|
+
end
|
315
|
+
|
316
|
+
def transform(content, path = nil)
|
317
|
+
type = Regexp === mapper_type ? :regexp : mapper_type
|
318
|
+
raise ArgumentError, "Invalid mapper type: #{type.inspect}" unless respond_to?("#{type}_transform", true)
|
319
|
+
self.__send__("#{type}_transform", content, path) { |key| config[key] || config[key.to_s.to_sym] }
|
320
|
+
end
|
321
|
+
|
322
|
+
private
|
323
|
+
def configure(mapper_type, *args, &block)
|
324
|
+
configurer = method("#{mapper_type}_config") rescue nil
|
325
|
+
if configurer
|
326
|
+
@config = configurer.call(*args, &block)
|
327
|
+
else
|
328
|
+
raise ArgumentError, "Missing hash argument after :#{mapper_type}" unless args.size == 1 && Hash === args[0]
|
329
|
+
@config = {} unless Hash === @config
|
330
|
+
args.first.each_pair { |k, v| @config[k] = v.to_s }
|
331
|
+
end
|
332
|
+
@mapper_type = mapper_type
|
333
|
+
end
|
334
|
+
|
335
|
+
def maven_transform(content, path = nil)
|
336
|
+
content.gsub(/\$\{.*?\}/) { |str| yield(str[2..-2]) || str }
|
337
|
+
end
|
338
|
+
|
339
|
+
def ant_transform(content, path = nil)
|
340
|
+
content.gsub(/@.*?@/) { |str| yield(str[1..-2]) || str }
|
341
|
+
end
|
342
|
+
|
343
|
+
def ruby_transform(content, path = nil)
|
344
|
+
content.gsub(/#\{.*?\}/) { |str| yield(str[2..-2]) || str }
|
345
|
+
end
|
346
|
+
|
347
|
+
def regexp_transform(content, path = nil)
|
348
|
+
content.gsub(mapper_type) { |str| yield(str.scan(mapper_type).join) || str }
|
349
|
+
end
|
350
|
+
|
351
|
+
def callback_transform(content, path = nil)
|
352
|
+
config.call(path, content)
|
353
|
+
end
|
354
|
+
|
355
|
+
def erb_transform(content, path = nil)
|
356
|
+
case config
|
357
|
+
when Binding
|
358
|
+
bnd = config
|
359
|
+
when Hash
|
360
|
+
bnd = OpenStruct.new
|
361
|
+
table = config.inject({}) { |h, e| h[e.first.to_sym] = e.last; h }
|
362
|
+
bnd.instance_variable_set(:@table, table)
|
363
|
+
bnd = bnd.instance_eval { binding }
|
364
|
+
else
|
365
|
+
bnd = config.instance_eval { binding }
|
366
|
+
end
|
367
|
+
require 'erb'
|
368
|
+
ERB.new(content).result(bnd)
|
369
|
+
end
|
370
|
+
|
371
|
+
def erb_config(*args, &block)
|
372
|
+
if block_given?
|
373
|
+
raise ArgumentError, "Expected block or single argument, but both given." unless args.empty?
|
374
|
+
block
|
375
|
+
elsif args.size > 1
|
376
|
+
raise ArgumentError, "Expected block or single argument."
|
377
|
+
else
|
378
|
+
args.first
|
379
|
+
end
|
380
|
+
end
|
381
|
+
|
382
|
+
end # class Mapper
|
383
|
+
|
384
|
+
end
|
385
|
+
|
386
|
+
# :call-seq:
|
387
|
+
# filter(*source) => Filter
|
388
|
+
#
|
389
|
+
# Creates a filter that will copy files from the source directory(ies) into the target directory.
|
390
|
+
# You can extend the filter to modify files by mapping <tt>${key}</tt> into values in each
|
391
|
+
# of the copied files, and by including or excluding specific files.
|
392
|
+
#
|
393
|
+
# A filter is not a task, you must call the Filter#run method to execute it.
|
394
|
+
#
|
395
|
+
# For example, to copy all files from one directory to another:
|
396
|
+
# filter('src/files').into('target/classes').run
|
397
|
+
# To include only the text files, and replace each instance of <tt>${build}</tt> with the current
|
398
|
+
# date/time:
|
399
|
+
# filter('src/files').into('target/classes').include('*.txt').using('build'=>Time.now).run
|
400
|
+
def filter(*sources)
|
401
|
+
Filter.new.from(*sources)
|
402
|
+
end
|
403
|
+
|
404
|
+
end
|