sprout 0.7.246 → 1.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sprout might be problematic. Click here for more details.
- data/CHANGELOG.md +10 -0
- data/Gemfile +28 -0
- data/MIT-LICENSE +3 -2
- data/POSTINSTALL.rdoc +28 -0
- data/README.textile +152 -0
- data/bin/sprout +1 -131
- data/bin/sprout-generator +10 -0
- data/bin/sprout-library +11 -0
- data/bin/sprout-tool +10 -0
- data/lib/sprout.rb +4 -500
- data/lib/sprout/archive_unpacker.rb +122 -206
- data/lib/sprout/base.rb +90 -0
- data/lib/sprout/concern.rb +30 -0
- data/lib/sprout/dir.rb +23 -0
- data/lib/sprout/errors.rb +94 -0
- data/lib/sprout/executable.rb +496 -0
- data/lib/sprout/executable/boolean.rb +35 -0
- data/lib/sprout/executable/collection_param.rb +53 -0
- data/lib/sprout/executable/file_param.rb +53 -0
- data/lib/sprout/executable/files.rb +26 -0
- data/lib/sprout/executable/number.rb +10 -0
- data/lib/sprout/executable/param.rb +222 -0
- data/lib/sprout/executable/parameter_factory.rb +28 -0
- data/lib/sprout/executable/path.rb +21 -0
- data/lib/sprout/executable/paths.rb +21 -0
- data/lib/sprout/executable/string_param.rb +15 -0
- data/lib/sprout/executable/strings.rb +11 -0
- data/lib/sprout/executable/url.rb +10 -0
- data/lib/sprout/executable/urls.rb +10 -0
- data/lib/sprout/file_target.rb +76 -0
- data/lib/sprout/generator/base.rb +233 -0
- data/lib/sprout/generator/command.rb +67 -0
- data/lib/sprout/generator/directory_manifest.rb +49 -0
- data/lib/sprout/generator/file_manifest.rb +55 -0
- data/lib/sprout/generator/manifest.rb +13 -0
- data/lib/sprout/generator/template_manifest.rb +13 -0
- data/lib/sprout/generators/generator/generator_generator.rb +48 -0
- data/lib/sprout/generators/generator/templates/generator_class.rb +17 -0
- data/lib/sprout/generators/generator/templates/generator_executable +9 -0
- data/lib/sprout/generators/generator/templates/generator_template +1 -0
- data/lib/sprout/generators/generator/templates/generator_test.rb +37 -0
- data/lib/sprout/generators/generator/templates/generator_test_helper.rb +16 -0
- data/lib/sprout/generators/library/library_generator.rb +20 -0
- data/lib/sprout/generators/library/templates/library.gemspec +19 -0
- data/lib/sprout/generators/library/templates/library.rb +15 -0
- data/lib/sprout/generators/ruby/ruby_generator.rb +59 -0
- data/lib/sprout/generators/ruby/templates/ruby_base.rb +10 -0
- data/lib/sprout/generators/ruby/templates/ruby_executable +6 -0
- data/lib/sprout/generators/ruby/templates/ruby_gemfile +4 -0
- data/lib/sprout/generators/ruby/templates/ruby_input.rb +7 -0
- data/lib/sprout/generators/tool/templates/Gemfile +4 -0
- data/lib/sprout/generators/tool/templates/tool.gemspec +22 -0
- data/lib/sprout/generators/tool/templates/tool.rb +38 -0
- data/lib/sprout/generators/tool/tool_generator.rb +36 -0
- data/lib/sprout/library.rb +111 -0
- data/lib/sprout/log.rb +1 -0
- data/lib/sprout/platform.rb +71 -0
- data/lib/sprout/process_runner.rb +80 -40
- data/lib/sprout/progress_bar.rb +341 -0
- data/lib/sprout/rdoc_parser.rb +91 -0
- data/lib/sprout/remote_file_loader.rb +72 -50
- data/lib/sprout/remote_file_target.rb +44 -152
- data/lib/sprout/ruby_feature.rb +167 -0
- data/lib/sprout/specification.rb +197 -0
- data/lib/sprout/string.rb +19 -0
- data/lib/sprout/system.rb +35 -0
- data/lib/sprout/system/base_system.rb +225 -0
- data/lib/sprout/system/java_system.rb +9 -0
- data/lib/sprout/system/osx_system.rb +26 -0
- data/lib/sprout/system/unix_system.rb +72 -0
- data/lib/sprout/system/vista_system.rb +16 -0
- data/lib/sprout/system/win_nix_system.rb +41 -0
- data/lib/sprout/system/win_system.rb +76 -0
- data/lib/sprout/test/sprout_test_case.rb +211 -0
- data/lib/sprout/version.rb +9 -4
- data/rakefile.rb +85 -144
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/sprout.gemspec +26 -0
- data/test/fixtures/archive_unpacker/copyable/some_file.exe +0 -0
- data/test/fixtures/archive_unpacker/copyable/some_file.rb +0 -0
- data/test/fixtures/archive_unpacker/copyable/some_file.swc +0 -0
- data/test/fixtures/archive_unpacker/tgz/some folder.tgz +0 -0
- data/test/fixtures/archive_unpacker/tgz/some_file.tgz +0 -0
- data/test/fixtures/archive_unpacker/zip/some folder.zip +0 -0
- data/test/fixtures/archive_unpacker/zip/some_file.zip +0 -0
- data/test/fixtures/examples/app_generator.rb +127 -0
- data/test/fixtures/examples/echo_inputs.rb +151 -0
- data/test/fixtures/executable/echochamber_gem/bin/echochamber +3 -0
- data/test/fixtures/executable/echochamber_gem/echo_chamber.rb +10 -0
- data/test/fixtures/executable/flex3sdk_gem/flex3sdk.rb +11 -0
- data/test/fixtures/executable/flex3sdk_gem/mxmlc +3 -0
- data/test/fixtures/executable/flex3sdk_gem/mxmlc.bat +3 -0
- data/test/fixtures/executable/mxmlc.rb +805 -0
- data/test/fixtures/executable/params/input.as +0 -0
- data/test/fixtures/executable/params/input2.as +0 -0
- data/test/fixtures/executable/params/input3.as +0 -0
- data/test/fixtures/executable/params/mxmlc +5 -0
- data/test/fixtures/executable/path with spaces/input.as b/data/test/fixtures/executable/path with → spaces/input.as +0 -0
- data/test/fixtures/executable/path with spaces/input2.as b/data/test/fixtures/executable/path with → spaces/input2.as +0 -0
- data/test/fixtures/executable/path with spaces/input3.as b/data/test/fixtures/executable/path with → spaces/input3.as +0 -0
- data/test/fixtures/executable/paths/folder1/file1 +0 -0
- data/test/fixtures/executable/paths/folder1/file2 +0 -0
- data/test/fixtures/executable/paths/folder1/file3 +0 -0
- data/test/fixtures/executable/paths/folder2/file4 +0 -0
- data/test/fixtures/executable/paths/folder2/file5 +0 -0
- data/test/fixtures/executable/paths/folder3/file6 +0 -0
- data/test/fixtures/executable/src/Main.as +0 -0
- data/test/fixtures/executable/windows_line_endings +47 -0
- data/test/fixtures/generators/song_generator.rb +11 -0
- data/test/fixtures/generators/song_subclass/least_favorite.rb +10 -0
- data/test/fixtures/generators/song_subclass/templates/Song.txt +3 -0
- data/test/fixtures/generators/temp_generator.rb +24 -0
- data/test/fixtures/generators/templates/Main.as +9 -0
- data/test/fixtures/generators/templates/OtherFileTemplate +1 -0
- data/test/fixtures/generators/templates/SomeFile +1 -0
- data/test/fixtures/generators/templates/SomeSubclassFile +2 -0
- data/test/fixtures/generators/templates/Song.txt +3 -0
- data/test/fixtures/generators/templates/destroy +0 -0
- data/test/fixtures/generators/templates/generate +0 -0
- data/test/fixtures/library/archive/Archive.swc +0 -0
- data/test/fixtures/library/sources/lib/a/A.as +0 -0
- data/test/fixtures/library/sources/lib/b/B.as +0 -0
- data/test/fixtures/library/sources/src/Source.as +0 -0
- data/test/fixtures/process_runner/chmod_script.sh +3 -0
- data/test/fixtures/process_runner/dir with spaces/chmod_script.sh +3 -0
- data/test/fixtures/process_runner/failure +5 -0
- data/test/fixtures/process_runner/success +4 -0
- data/test/fixtures/remote_file_loader/md5/echochamber-test.zip +0 -0
- data/test/fixtures/remote_file_loader/md5/file_with_known_md5 +0 -0
- data/test/fixtures/remote_file_target/bin/echochamber +3 -0
- data/test/fixtures/remote_file_target/bin/echochamber.bat +3 -0
- data/test/fixtures/remote_file_target/echochamber-test.zip +0 -0
- data/test/fixtures/specification/asunit4.rb +25 -0
- data/test/fixtures/specification/ext/AsUnit-4.1.pre.swc +0 -0
- data/test/fixtures/specification/flashplayer.rb +30 -0
- data/test/fixtures/specification/flex4sdk.rb +72 -0
- data/test/fixtures/specification/flexunit4.sproutspec +17 -0
- data/test/fixtures/specification/lib/as3reflection/Reflection.as +0 -0
- data/test/fixtures/specification/src/AsUnit.as +0 -0
- data/test/fixtures/user/mxmlc_crlf +3 -0
- data/test/unit/archive_unpacker_test.rb +108 -0
- data/test/unit/boolean_param_test.rb +38 -0
- data/test/unit/executable_option_parser_test.rb +142 -0
- data/test/unit/executable_param_test.rb +76 -0
- data/test/unit/executable_test.rb +237 -0
- data/test/unit/fake_executable_task.rb +22 -0
- data/test/unit/fake_other_executable.rb +20 -0
- data/test/unit/fake_process_runner.rb +29 -0
- data/test/unit/file_param_test.rb +61 -0
- data/test/unit/file_target_test.rb +42 -0
- data/test/unit/files_param_test.rb +72 -0
- data/test/unit/generator_generator_test.rb +85 -0
- data/test/unit/generator_test.rb +333 -0
- data/test/unit/library_generator_test.rb +41 -0
- data/test/unit/library_test.rb +88 -0
- data/test/unit/osx_system_test.rb +20 -0
- data/test/unit/path_param_test.rb +43 -0
- data/test/unit/paths_param_test.rb +53 -0
- data/test/unit/platform_test.rb +76 -0
- data/test/unit/process_runner_test.rb +104 -0
- data/test/unit/rdoc_parser_test.rb +15 -0
- data/test/unit/remote_file_loader_test.rb +34 -0
- data/test/unit/remote_file_target_test.rb +105 -0
- data/test/unit/ruby_feature_test.rb +108 -0
- data/test/unit/ruby_generator_test.rb +70 -0
- data/test/unit/specification_test.rb +73 -0
- data/test/unit/sprout_test.rb +170 -0
- data/test/unit/sprout_test_helper.rb +18 -0
- data/test/unit/string_param_test.rb +19 -0
- data/test/unit/string_test.rb +20 -0
- data/test/unit/strings_param_test.rb +27 -0
- data/test/unit/test_helper.rb +1 -0
- data/test/unit/tool_generator_test.rb +43 -0
- data/test/unit/unix_system_test.rb +52 -0
- data/test/unit/user_test.rb +147 -0
- data/test/unit/vista_system_test.rb +40 -0
- data/test/unit/win_nix_system_test.rb +26 -0
- data/test/unit/win_system_test.rb +61 -0
- metadata +318 -113
- data/doc/Bundle +0 -14
- data/doc/Generator +0 -35
- data/doc/Library +0 -63
- data/doc/Task +0 -21
- data/doc/Tool +0 -20
- data/lib/platform.rb +0 -113
- data/lib/progress_bar.rb +0 -354
- data/lib/sprout/builder.rb +0 -51
- data/lib/sprout/bundle_resolver.rb +0 -349
- data/lib/sprout/commands/generate.rb +0 -9
- data/lib/sprout/dynamic_accessors.rb +0 -40
- data/lib/sprout/general_tasks.rb +0 -6
- data/lib/sprout/generator.rb +0 -7
- data/lib/sprout/generator/base_mixins.rb +0 -186
- data/lib/sprout/generator/named_base.rb +0 -227
- data/lib/sprout/project_model.rb +0 -278
- data/lib/sprout/simple_resolver.rb +0 -88
- data/lib/sprout/tasks/erb_resolver.rb +0 -118
- data/lib/sprout/tasks/gem_wrap_task.rb +0 -214
- data/lib/sprout/tasks/git_task.rb +0 -134
- data/lib/sprout/tasks/library_task.rb +0 -118
- data/lib/sprout/tasks/sftp_task.rb +0 -248
- data/lib/sprout/tasks/ssh_task.rb +0 -153
- data/lib/sprout/tasks/tool_task.rb +0 -836
- data/lib/sprout/tasks/zip_task.rb +0 -158
- data/lib/sprout/tool_task_model.rb +0 -19
- data/lib/sprout/user.rb +0 -415
- data/lib/sprout/version_file.rb +0 -89
- data/lib/sprout/zip_util.rb +0 -61
- data/samples/gem_wrap/rakefile.rb +0 -17
@@ -1,836 +0,0 @@
|
|
1
|
-
|
2
|
-
module Sprout
|
3
|
-
|
4
|
-
class ToolTaskError < StandardError #:nodoc:
|
5
|
-
end
|
6
|
-
|
7
|
-
# The ToolTask provides some base functionality for any Command Line Interface (CLI) tool.
|
8
|
-
# It also provides support for GUI tools that you would like to expose from the
|
9
|
-
# Command Line (Like the Flash Player for example).
|
10
|
-
#
|
11
|
-
# ToolTask extends Rake::FileTask, and should be thought of in the same way.
|
12
|
-
# Martin Fowler did a much better job of describing Rake and specifically FileTasks than
|
13
|
-
# I can in his (now classic) Rake article[http://martinfowler.com/articles/rake.html#FileTasks] from 2005.
|
14
|
-
#
|
15
|
-
# What this means is that most tool task instances should be named for the file that they will create.
|
16
|
-
# For example, an Sprout::MXMLCTask instance should be named for the SWF that it will generate.
|
17
|
-
#
|
18
|
-
# mxmlc 'bin/SomeProject.swf' => :corelib do |t|
|
19
|
-
# t.input = 'src/SomeProject.as'
|
20
|
-
# t.default_size = '800 600'
|
21
|
-
# t.namespace = "my_namespace://path\ " + File.expand_path("~/Desktop/SomeProject/build/main.xml")
|
22
|
-
# end
|
23
|
-
#
|
24
|
-
# If you don't put a "\ " for the space in the "t.namespace" directive, you'll get this:
|
25
|
-
# rake aborted!
|
26
|
-
# [ERROR] command line: Error: default arguments may not be interspersed with other options
|
27
|
-
#
|
28
|
-
# In general, a tool task will only be executed if it's output file (name) does not exist or
|
29
|
-
# if the output file is older than any file identified as a prerequisite.
|
30
|
-
#
|
31
|
-
# Many of the compiler tasks take advantage of this feature by opting out of unnecessary compilation.
|
32
|
-
#
|
33
|
-
# Subclasses can add and configure command line parameters by calling the protected add_param method
|
34
|
-
# that is implemented on this class.
|
35
|
-
#
|
36
|
-
class ToolTask < Rake::FileTask
|
37
|
-
@@preprocessed_tasks = Hash.new
|
38
|
-
|
39
|
-
def self.add_preprocessed_task(name)
|
40
|
-
@@preprocessed_tasks[name] = true
|
41
|
-
end
|
42
|
-
|
43
|
-
def self.has_preprocessed_task?(name)
|
44
|
-
!@@preprocessed_tasks[name].nil?
|
45
|
-
end
|
46
|
-
|
47
|
-
def self.clear_preprocessed_tasks
|
48
|
-
@@preprocessed_tasks.clear
|
49
|
-
end
|
50
|
-
|
51
|
-
def initialize(name, app) # :nodoc:
|
52
|
-
super
|
53
|
-
@preprocessed_path = nil
|
54
|
-
@prepended_args = nil
|
55
|
-
@appended_args = nil
|
56
|
-
@default_gem_name = nil
|
57
|
-
@default_gem_path = nil
|
58
|
-
initialize_task
|
59
|
-
end
|
60
|
-
|
61
|
-
def self.define_task(args, &block)
|
62
|
-
t = super
|
63
|
-
if(t.is_a?(ToolTask))
|
64
|
-
t.find_and_resolve_model
|
65
|
-
yield t if block_given?
|
66
|
-
t.define
|
67
|
-
t.prepare
|
68
|
-
end
|
69
|
-
return t
|
70
|
-
end
|
71
|
-
|
72
|
-
# Full name of the sprout tool gem that this tool task will use. For example, the MXMLCTask
|
73
|
-
# uses the sprout-flex3sdk-tool at the time of this writing, but will at some point
|
74
|
-
# change to use the sprout-flex3sdk-tool. You can combine this value with gem_version
|
75
|
-
# in order to specify exactly which gem your tool task is executing.
|
76
|
-
def gem_name
|
77
|
-
return @gem_name ||= @default_gem_name
|
78
|
-
end
|
79
|
-
|
80
|
-
def gem_name=(name)
|
81
|
-
@gem_name = name
|
82
|
-
end
|
83
|
-
|
84
|
-
# The exact gem version that you would like the ToolTask to execute. By default this value
|
85
|
-
# should be nil and will download the latest version of the gem that is available unless
|
86
|
-
# there is a version already installed on your system.
|
87
|
-
#
|
88
|
-
# This attribute could be an easy
|
89
|
-
# way to update your local gem to the latest version without leaving your build file,
|
90
|
-
# but it's primary purpose is to allow you to specify very specific versions of the tools
|
91
|
-
# that your project depends on. This way your team can rest assured that they are all
|
92
|
-
# working with the same tools.
|
93
|
-
def gem_version
|
94
|
-
return @gem_version ||= nil
|
95
|
-
end
|
96
|
-
|
97
|
-
def gem_version=(version)
|
98
|
-
@gem_version = version
|
99
|
-
end
|
100
|
-
|
101
|
-
# The path inside the installed gem where an executable can be found. For the MXMLCTask, this
|
102
|
-
# value is 'bin/mxmlc'.
|
103
|
-
def gem_path
|
104
|
-
return @gem_path ||= @default_gem_path
|
105
|
-
end
|
106
|
-
|
107
|
-
def each_param
|
108
|
-
params.each do |param|
|
109
|
-
yield param if block_given?
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
# Create a string that can be turned into a file
|
114
|
-
# that rdoc can parse to describe the customized
|
115
|
-
# or generated task using param name, type and
|
116
|
-
# description
|
117
|
-
def to_rdoc
|
118
|
-
result = ''
|
119
|
-
parts = self.class.to_s.split('::')
|
120
|
-
class_name = parts.pop
|
121
|
-
module_count = 0
|
122
|
-
while(module_name = parts.shift)
|
123
|
-
result << "module #{module_name}\n"
|
124
|
-
module_count += 1
|
125
|
-
end
|
126
|
-
|
127
|
-
result << "class #{class_name} < ToolTask\n"
|
128
|
-
|
129
|
-
params.each do |param|
|
130
|
-
result << param.to_rdoc
|
131
|
-
end
|
132
|
-
|
133
|
-
while((module_count -= 1) >= 0)
|
134
|
-
result << "end\nend\n"
|
135
|
-
end
|
136
|
-
|
137
|
-
return result
|
138
|
-
end
|
139
|
-
|
140
|
-
# Arguments to be prepended in front of the command line output
|
141
|
-
def prepended_args=(args)
|
142
|
-
@prepended_args = args
|
143
|
-
end
|
144
|
-
|
145
|
-
# Returns arguments that were prepended in front of the command line output
|
146
|
-
def prepended_args
|
147
|
-
@prepended_args
|
148
|
-
end
|
149
|
-
|
150
|
-
# Arguments to appended at the end of the command line output
|
151
|
-
def appended_args=(args)
|
152
|
-
@appended_args = args
|
153
|
-
end
|
154
|
-
|
155
|
-
# Returns arguments that were appended at the end of the command line output
|
156
|
-
def appended_args
|
157
|
-
@appended_args
|
158
|
-
end
|
159
|
-
|
160
|
-
# Command line arguments to execute preprocessor.
|
161
|
-
# The preprocessor execution should accept text via STDIN and return its processed content via STDOUT.
|
162
|
-
#
|
163
|
-
# In the following example, the +MXMLCTask+ has been configured to use the C preprocessor (cpp) and
|
164
|
-
# place the processed output into a +_preprocessed+ folder, instead of the hidden default folder at
|
165
|
-
# .preprocessed.
|
166
|
-
#
|
167
|
-
# One side effect of the cpp tool is that it adds 2 carriage returns to the top of any processed files,
|
168
|
-
# so we have simply piped its output to the tail command which then strips those carriage returns from
|
169
|
-
# all files - which retains accurate line numbers for any compiler error messages.
|
170
|
-
#
|
171
|
-
# mxmlc 'bin/SomeProject.swf' => :corelib do |t|
|
172
|
-
# t.input = 'src/SomeProject.as'
|
173
|
-
# t.default_size = '800 600'
|
174
|
-
# t.preprocessor = 'cpp -D__DEBUG=true -P - - | tail -c +3'
|
175
|
-
# t.preprocessed_path = '_preprocessed'
|
176
|
-
# end
|
177
|
-
#
|
178
|
-
# Any source files found in this example project can now take advantage of any tools, macros or syntax
|
179
|
-
# available to CPP. For example, the +__DEBUG+ variable is now defined and can be accessed in ActionScript
|
180
|
-
# source code as follows:
|
181
|
-
#
|
182
|
-
# public static const DEBUG:Boolean = __DEBUG;
|
183
|
-
#
|
184
|
-
# Any commandline tool identified on this attribute will be provided the content of each file on STDIN and
|
185
|
-
# whatever it returns to STDOUT will be written into the +preprocessed_path+. This means that we can
|
186
|
-
# take advantage of the entire posix tool chain by piping inputs and outputs from one tool to another.
|
187
|
-
# Whatever the last tool returns will be handed off to the concrete compiler.
|
188
|
-
def preprocessor=(preprocessor)
|
189
|
-
@preprocessor = preprocessor
|
190
|
-
end
|
191
|
-
|
192
|
-
def preprocessor
|
193
|
-
@preprocessor
|
194
|
-
end
|
195
|
-
|
196
|
-
# Path where preprocessed files are stored. Defaults to '.preprocessed'
|
197
|
-
def preprocessed_path=(preprocessed_path)
|
198
|
-
@preprocessed_path = preprocessed_path
|
199
|
-
end
|
200
|
-
|
201
|
-
def preprocessed_path
|
202
|
-
@preprocessed_path ||= '.preprocessed'
|
203
|
-
end
|
204
|
-
|
205
|
-
def display_preprocess_message # :nodoc:
|
206
|
-
if(!preprocessor.nil?)
|
207
|
-
puts ">> Preprocessed text files in: #{File.join(Dir.pwd, preprocessed_path)} with #{preprocessor}"
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
def execute(*args)
|
212
|
-
display_preprocess_message
|
213
|
-
exe = Sprout.get_executable(gem_name, gem_path, gem_version)
|
214
|
-
User.execute(exe, to_shell)
|
215
|
-
end
|
216
|
-
|
217
|
-
# Create a string that represents this configured tool for shell execution
|
218
|
-
def to_shell
|
219
|
-
return @to_shell_proc.call(self) if(!@to_shell_proc.nil?)
|
220
|
-
|
221
|
-
result = []
|
222
|
-
result << @prepended_args unless @prepended_args.nil?
|
223
|
-
params.each do |param|
|
224
|
-
if(param.visible?)
|
225
|
-
result << param.to_shell
|
226
|
-
end
|
227
|
-
end
|
228
|
-
result << @appended_args unless @appended_args.nil?
|
229
|
-
return result.join(' ')
|
230
|
-
end
|
231
|
-
|
232
|
-
# An Array of all parameters that have been added to this Tool.
|
233
|
-
def params
|
234
|
-
@params ||= []
|
235
|
-
end
|
236
|
-
|
237
|
-
# Called after initialize and define, usually subclasses should
|
238
|
-
# only override define.
|
239
|
-
def prepare
|
240
|
-
# Get each added param to inject prerequisites as necessary
|
241
|
-
params.each do |param|
|
242
|
-
param.prepare
|
243
|
-
end
|
244
|
-
prepare_prerequisites
|
245
|
-
end
|
246
|
-
|
247
|
-
def prepare_prerequisites
|
248
|
-
# Ensure there are no duplicates in the prerequisite collection
|
249
|
-
@prerequisites = prerequisites.uniq
|
250
|
-
end
|
251
|
-
|
252
|
-
def define
|
253
|
-
resolve_libraries(prerequisites)
|
254
|
-
end
|
255
|
-
|
256
|
-
# Look for a ToolTaskModel in the list
|
257
|
-
# of prerequisites. If found, apply
|
258
|
-
# any applicable params to self...
|
259
|
-
def find_and_resolve_model
|
260
|
-
prerequisites.each do |prereq|
|
261
|
-
instance = Rake::application[prereq]
|
262
|
-
if(instance.is_a?(ToolTaskModel))
|
263
|
-
resolve_model(instance)
|
264
|
-
end
|
265
|
-
end
|
266
|
-
end
|
267
|
-
|
268
|
-
# The default file expression to append to each PathParam
|
269
|
-
# in order to build file change prerequisites.
|
270
|
-
#
|
271
|
-
# Defaults to '/**/**/*'
|
272
|
-
#
|
273
|
-
def default_file_expression
|
274
|
-
@default_file_expression ||= '/**/**/*'
|
275
|
-
end
|
276
|
-
|
277
|
-
protected
|
278
|
-
|
279
|
-
def initialize_task
|
280
|
-
end
|
281
|
-
|
282
|
-
def validate
|
283
|
-
params.each do |param|
|
284
|
-
param.validate
|
285
|
-
end
|
286
|
-
end
|
287
|
-
|
288
|
-
# +add_param+ is the workhorse of the ToolTask.
|
289
|
-
# This method is used to add new shell parameters to the task.
|
290
|
-
# +name+ is a symbol or string that represents the parameter that you would like to add
|
291
|
-
# such as :debug or :source_path.
|
292
|
-
# +type+ is usually sent as a Ruby symbol and can be one of the following:
|
293
|
-
#
|
294
|
-
# [:string] Any string value
|
295
|
-
# [:boolean] true or false
|
296
|
-
# [:number] Any number
|
297
|
-
# [:file] Path to a file
|
298
|
-
# [:url] Basic URL
|
299
|
-
# [:path] Path to a directory
|
300
|
-
# [:files] Collection of files
|
301
|
-
# [:paths] Collection of directories
|
302
|
-
# [:strings] Collection of arbitrary strings
|
303
|
-
# [:urls] Collection of URLs
|
304
|
-
#
|
305
|
-
# Be sure to check out the Sprout::TaskParam class to learn more about
|
306
|
-
# block editing the parameters.
|
307
|
-
#
|
308
|
-
# Once parameters have been added using the +add_param+ method, clients
|
309
|
-
# can set and get those parameters from the newly created task.
|
310
|
-
#
|
311
|
-
def add_param(name, type, &block) # :yields: Sprout::TaskParam
|
312
|
-
name = name.to_s
|
313
|
-
|
314
|
-
# First ensure the named accessor doesn't yet exist...
|
315
|
-
# BUT, namespace is a reserved word, so override that
|
316
|
-
if(!name == "namespace" and param_hash[name])
|
317
|
-
raise ToolTaskError.new("TaskBase.add_param called with existing parameter name: #{name}")
|
318
|
-
end
|
319
|
-
|
320
|
-
param = create_param(type)
|
321
|
-
param.init do |p|
|
322
|
-
p.belongs_to = self
|
323
|
-
p.name = name
|
324
|
-
p.type = type
|
325
|
-
yield p if block_given?
|
326
|
-
end
|
327
|
-
|
328
|
-
param_hash[name] = param
|
329
|
-
params << param
|
330
|
-
end
|
331
|
-
|
332
|
-
# Alias an existing parameter with another name. For example, the
|
333
|
-
# existing parameter :source_path might be given an alias '-sp' as follows:
|
334
|
-
#
|
335
|
-
# add_param_alias(:sp, :source_path)
|
336
|
-
#
|
337
|
-
# Alias parameters cannot be configured differently from the parameter
|
338
|
-
# that they alias
|
339
|
-
#
|
340
|
-
def add_param_alias(name, other_param)
|
341
|
-
if(param_hash.has_key? other_param.to_s)
|
342
|
-
param_hash[name.to_s] = param_hash[other_param.to_s]
|
343
|
-
else
|
344
|
-
raise ToolTaskError.new("TaskBase.add_param_alias called with")
|
345
|
-
end
|
346
|
-
end
|
347
|
-
|
348
|
-
def create_param(type)
|
349
|
-
return eval("#{type.to_s.capitalize}Param.new")
|
350
|
-
end
|
351
|
-
|
352
|
-
def param_hash
|
353
|
-
@param_hash ||= {}
|
354
|
-
end
|
355
|
-
|
356
|
-
def respond_to?(name)
|
357
|
-
result = super
|
358
|
-
if(!result)
|
359
|
-
result = param_hash.has_key? name.to_s
|
360
|
-
end
|
361
|
-
return result
|
362
|
-
end
|
363
|
-
|
364
|
-
def clean_name(name)
|
365
|
-
name.gsub(/=$/, '')
|
366
|
-
end
|
367
|
-
|
368
|
-
def method_missing(name, *args)
|
369
|
-
name = name.to_s
|
370
|
-
cleaned = clean_name(name)
|
371
|
-
if(!respond_to?(cleaned))
|
372
|
-
raise NoMethodError.new("undefined method '#{name}' for #{self.class}", name)
|
373
|
-
end
|
374
|
-
param = param_hash[cleaned]
|
375
|
-
|
376
|
-
matched = name =~ /=$/
|
377
|
-
if(matched)
|
378
|
-
param.value = args.shift
|
379
|
-
elsif(param)
|
380
|
-
param.value
|
381
|
-
else
|
382
|
-
raise ToolTaskError.new("method_missing called with undefined parameter [#{name}]")
|
383
|
-
end
|
384
|
-
end
|
385
|
-
|
386
|
-
# Iterate over all prerequisites looking for any
|
387
|
-
# that are a LibraryTask.
|
388
|
-
# Concrete ToolTask implementations should
|
389
|
-
# override resolve_library in order to add
|
390
|
-
# the library sources or binaries appropriately.
|
391
|
-
def resolve_libraries(prerequisites)
|
392
|
-
prerequisites.each do |prereq|
|
393
|
-
instance = Rake::application[prereq]
|
394
|
-
if(instance.is_a?(LibraryTask))
|
395
|
-
resolve_library(instance)
|
396
|
-
end
|
397
|
-
end
|
398
|
-
end
|
399
|
-
|
400
|
-
# Concrete ToolTasks should override this method
|
401
|
-
# and add any dependent libraries appropriately
|
402
|
-
def resolve_library(library_task)
|
403
|
-
end
|
404
|
-
|
405
|
-
def resolve_model(model)
|
406
|
-
model.each_attribute do |key, value|
|
407
|
-
if(respond_to? key)
|
408
|
-
self.send("#{key}=", value)
|
409
|
-
end
|
410
|
-
end
|
411
|
-
end
|
412
|
-
|
413
|
-
# If the provided path contains spaces, wrap it in quotes so that
|
414
|
-
# shell tools won't choke on the spaces
|
415
|
-
def clean_path(path)
|
416
|
-
if(path.index(' '))
|
417
|
-
path = %{"#{path}"}
|
418
|
-
end
|
419
|
-
return path
|
420
|
-
end
|
421
|
-
|
422
|
-
end
|
423
|
-
|
424
|
-
#######################################################
|
425
|
-
# Parameter Implementations
|
426
|
-
|
427
|
-
# The base class for all ToolTask parameters. This class is extended by a variety
|
428
|
-
# of concrete implementations.
|
429
|
-
#
|
430
|
-
# At the time of this writing, only the :boolean TaskParam modifies the interface by
|
431
|
-
# adding the +show_on_false+ attribute.
|
432
|
-
#
|
433
|
-
# Some other helpful features are as follows:
|
434
|
-
#
|
435
|
-
# :file, :files, :path and :paths will all add any items that have been added to
|
436
|
-
# their values as file task prerequisites. This is especially helpful when writing
|
437
|
-
# rake tasks for Command Line Interface (CLI) compilers.
|
438
|
-
#
|
439
|
-
class TaskParam
|
440
|
-
attr_accessor :belongs_to
|
441
|
-
attr_accessor :description
|
442
|
-
attr_accessor :hidden_name
|
443
|
-
attr_accessor :hidden_value
|
444
|
-
attr_accessor :name
|
445
|
-
attr_accessor :preprocessable
|
446
|
-
attr_accessor :required
|
447
|
-
attr_accessor :type
|
448
|
-
attr_accessor :validator
|
449
|
-
attr_accessor :visible
|
450
|
-
|
451
|
-
attr_writer :prefix
|
452
|
-
attr_writer :value
|
453
|
-
attr_writer :delimiter
|
454
|
-
attr_writer :shell_name
|
455
|
-
attr_writer :to_shell_proc
|
456
|
-
|
457
|
-
# Set the file_expression (blob) to append to each path
|
458
|
-
# in order to build the prerequisites FileList.
|
459
|
-
#
|
460
|
-
# Defaults to parent ToolTask.default_file_expression
|
461
|
-
attr_writer :file_expression
|
462
|
-
|
463
|
-
def init
|
464
|
-
yield self if block_given?
|
465
|
-
end
|
466
|
-
|
467
|
-
# By default, ToolParams only appear in the shell
|
468
|
-
# output when they are not nil
|
469
|
-
def visible?
|
470
|
-
@visible ||= value
|
471
|
-
end
|
472
|
-
|
473
|
-
def required?
|
474
|
-
(required == true)
|
475
|
-
end
|
476
|
-
|
477
|
-
def validate
|
478
|
-
if(required? && !visible?)
|
479
|
-
raise ToolTaskError.new("#{name} is required and must not be nil")
|
480
|
-
end
|
481
|
-
end
|
482
|
-
|
483
|
-
def prepare
|
484
|
-
prepare_prerequisites
|
485
|
-
end
|
486
|
-
|
487
|
-
def prepare_prerequisites
|
488
|
-
end
|
489
|
-
|
490
|
-
# Should the param name be hidden from the shell?
|
491
|
-
# Used for params like 'input' on mxmlc
|
492
|
-
def hidden_name?
|
493
|
-
@hidden_name ||= false
|
494
|
-
end
|
495
|
-
|
496
|
-
# Should the param value be hidden from the shell?
|
497
|
-
# Usually used for Boolean toggles like '-debug'
|
498
|
-
def hidden_value?
|
499
|
-
@hidden_value ||= false
|
500
|
-
end
|
501
|
-
|
502
|
-
# Leading character for each parameter
|
503
|
-
# Can sometimes be an empty string,
|
504
|
-
# other times it's a double dash '--'
|
505
|
-
# but usually it's just a single dash '-'
|
506
|
-
def prefix
|
507
|
-
@prefix ||= '-'
|
508
|
-
end
|
509
|
-
|
510
|
-
def value
|
511
|
-
@value
|
512
|
-
end
|
513
|
-
|
514
|
-
def shell_value
|
515
|
-
value.to_s
|
516
|
-
end
|
517
|
-
|
518
|
-
def file_expression # :nodoc:
|
519
|
-
@file_expression ||= belongs_to.default_file_expression
|
520
|
-
end
|
521
|
-
|
522
|
-
# ToolParams join their name/value pair with an
|
523
|
-
# equals sign by default, this can be modified
|
524
|
-
# To a space or whatever you wish
|
525
|
-
def delimiter
|
526
|
-
@delimiter ||= '='
|
527
|
-
end
|
528
|
-
|
529
|
-
# Return the name with a single leading dash
|
530
|
-
# and underscores replaced with dashes
|
531
|
-
def shell_name
|
532
|
-
@shell_name ||= prefix + name.split('_').join('-')
|
533
|
-
end
|
534
|
-
|
535
|
-
def to_shell
|
536
|
-
if(!@to_shell_proc.nil?)
|
537
|
-
return @to_shell_proc.call(self)
|
538
|
-
elsif(hidden_name?)
|
539
|
-
return shell_value
|
540
|
-
elsif(hidden_value?)
|
541
|
-
return shell_name
|
542
|
-
else
|
543
|
-
return "#{shell_name}#{delimiter}#{shell_value}"
|
544
|
-
end
|
545
|
-
end
|
546
|
-
|
547
|
-
# Create a string that can be turned into a file
|
548
|
-
# that rdoc can parse to describe the customized
|
549
|
-
# or generated task using param name, type and
|
550
|
-
# description
|
551
|
-
def to_rdoc
|
552
|
-
result = ''
|
553
|
-
parts = description.split("\n") unless description.nil?
|
554
|
-
result << "# #{parts.join("\n# ")}\n" unless description.nil?
|
555
|
-
result << "def #{name}=(#{type})\n @#{name} = #{type}\nend\n\n"
|
556
|
-
return result
|
557
|
-
end
|
558
|
-
|
559
|
-
protected
|
560
|
-
|
561
|
-
def should_preprocess?
|
562
|
-
return preprocessable && !belongs_to.preprocessor.nil?
|
563
|
-
end
|
564
|
-
|
565
|
-
def prepare_preprocessor_paths(paths)
|
566
|
-
processed = []
|
567
|
-
paths.each do |path|
|
568
|
-
processed << prepare_preprocessor_path(path)
|
569
|
-
end
|
570
|
-
return processed
|
571
|
-
end
|
572
|
-
|
573
|
-
def prepare_preprocessor_files(files)
|
574
|
-
processed = []
|
575
|
-
files.each do |file|
|
576
|
-
processed << prepare_preprocessor_file(file)
|
577
|
-
end
|
578
|
-
return processed
|
579
|
-
end
|
580
|
-
|
581
|
-
def cleaned_preprocessed_path(path)
|
582
|
-
File.join(belongs_to.preprocessed_path, path.gsub('../', 'backslash/'))
|
583
|
-
end
|
584
|
-
|
585
|
-
def prepare_preprocessor_path(path)
|
586
|
-
processed_path = cleaned_preprocessed_path(path)
|
587
|
-
FileUtils.mkdir_p(processed_path)
|
588
|
-
files = FileList[path + file_expression]
|
589
|
-
files.each do |input_file|
|
590
|
-
prepare_preprocessor_file(input_file)
|
591
|
-
end
|
592
|
-
|
593
|
-
return processed_path
|
594
|
-
end
|
595
|
-
|
596
|
-
def prepare_preprocessor_file(input_file)
|
597
|
-
output_file = cleaned_preprocessed_path(input_file)
|
598
|
-
setup_preprocessing_file_tasks(input_file, output_file)
|
599
|
-
return output_file
|
600
|
-
end
|
601
|
-
|
602
|
-
def text_file?(file_name)
|
603
|
-
[/\.as$/, /\.txt$/, /\.mxml$/, /\.xml$/, /\.js$/, /\.html$/, /\.htm$/].select do |regex|
|
604
|
-
if (file_name.match(regex))
|
605
|
-
return true
|
606
|
-
end
|
607
|
-
end.size > 0
|
608
|
-
end
|
609
|
-
|
610
|
-
def setup_preprocessing_file_tasks(input_file, output_file)
|
611
|
-
return if(File.directory?(input_file))
|
612
|
-
CLEAN.add(belongs_to.preprocessed_path) if(!CLEAN.index(belongs_to.preprocessed_path))
|
613
|
-
|
614
|
-
# Only create the preprocessed action if one does not
|
615
|
-
# already exist. There were many being created before...
|
616
|
-
|
617
|
-
file input_file
|
618
|
-
file output_file => input_file do
|
619
|
-
# Couldn't return, b/c Rake complained...
|
620
|
-
if(!ToolTask::has_preprocessed_task?(output_file))
|
621
|
-
dir = File.dirname(output_file)
|
622
|
-
if(!File.exists?(dir))
|
623
|
-
FileUtils.mkdir_p(dir)
|
624
|
-
end
|
625
|
-
|
626
|
-
content = nil
|
627
|
-
# Open the input file and read its content:
|
628
|
-
File.open(input_file, 'r') do |readable|
|
629
|
-
content = readable.read
|
630
|
-
end
|
631
|
-
|
632
|
-
# Preprocess the content if it's a known text file type:
|
633
|
-
if(text_file?(input_file))
|
634
|
-
content = preprocess_content(content, belongs_to.preprocessor, input_file)
|
635
|
-
end
|
636
|
-
|
637
|
-
# Write the content to the output file:
|
638
|
-
File.open(output_file, 'w+') do |writable|
|
639
|
-
writable.write(content)
|
640
|
-
end
|
641
|
-
|
642
|
-
ToolTask::add_preprocessed_task(output_file)
|
643
|
-
end
|
644
|
-
end
|
645
|
-
|
646
|
-
belongs_to.prerequisites << output_file
|
647
|
-
end
|
648
|
-
|
649
|
-
def preprocess_content(content, statement, file_name)
|
650
|
-
process = ProcessRunner.new(statement)
|
651
|
-
process.puts(content)
|
652
|
-
process.close_write
|
653
|
-
result = process.read
|
654
|
-
error = process.read_err
|
655
|
-
if(error.size > 0)
|
656
|
-
belongs_to.display_preprocess_message
|
657
|
-
FileUtils.rm_rf(belongs_to.preprocessed_path)
|
658
|
-
raise ExecutionError.new("[ERROR] Preprocessor failed on file #{file_name} #{error}")
|
659
|
-
end
|
660
|
-
process.kill
|
661
|
-
Log.puts ">> Preprocessed and created: #{belongs_to.preprocessed_path}/#{file_name}"
|
662
|
-
return result
|
663
|
-
end
|
664
|
-
|
665
|
-
end
|
666
|
-
|
667
|
-
# Concrete param object for :string values
|
668
|
-
class StringParam < TaskParam # :nodoc:
|
669
|
-
|
670
|
-
def shell_value
|
671
|
-
value.gsub(/ /, "\ ")
|
672
|
-
end
|
673
|
-
end
|
674
|
-
|
675
|
-
# Concrete param object for :symbol values
|
676
|
-
# like class names
|
677
|
-
class SymbolParam < TaskParam # :nodoc:
|
678
|
-
end
|
679
|
-
|
680
|
-
# Concrete param object for :url values
|
681
|
-
class UrlParam < TaskParam # :nodoc:
|
682
|
-
end
|
683
|
-
|
684
|
-
# Concrete param object for :number values
|
685
|
-
class NumberParam < TaskParam # :nodoc:
|
686
|
-
end
|
687
|
-
|
688
|
-
# Concrete param object for :file values
|
689
|
-
class FileParam < TaskParam # :nodoc:
|
690
|
-
|
691
|
-
def prepare_prerequisites
|
692
|
-
if(value && value != belongs_to.name.to_s)
|
693
|
-
if(should_preprocess?)
|
694
|
-
@value = prepare_preprocessor_file(value)
|
695
|
-
else
|
696
|
-
file value
|
697
|
-
belongs_to.prerequisites << value
|
698
|
-
end
|
699
|
-
end
|
700
|
-
end
|
701
|
-
end
|
702
|
-
|
703
|
-
# Concrete param object for :path values
|
704
|
-
class PathParam < TaskParam # :nodoc:
|
705
|
-
|
706
|
-
def prepare_prerequisites
|
707
|
-
if(value && value != belongs_to.name.to_s)
|
708
|
-
if should_preprocess?
|
709
|
-
@value = prepare_preprocessor_path(value)
|
710
|
-
else
|
711
|
-
file value
|
712
|
-
belongs_to.prerequisites << value
|
713
|
-
end
|
714
|
-
end
|
715
|
-
end
|
716
|
-
end
|
717
|
-
|
718
|
-
# Concrete param object for :boolean values
|
719
|
-
class BooleanParam < TaskParam # :nodoc:
|
720
|
-
attr_writer :show_on_false
|
721
|
-
|
722
|
-
def visible?
|
723
|
-
@visible ||= value
|
724
|
-
if(show_on_false)
|
725
|
-
return true unless value
|
726
|
-
else
|
727
|
-
return @visible
|
728
|
-
end
|
729
|
-
end
|
730
|
-
|
731
|
-
def show_on_false
|
732
|
-
@show_on_false ||= false
|
733
|
-
end
|
734
|
-
|
735
|
-
def value
|
736
|
-
@value ||= false
|
737
|
-
end
|
738
|
-
|
739
|
-
end
|
740
|
-
|
741
|
-
# Concrete param object for collections of strings
|
742
|
-
class StringsParam < TaskParam # :nodoc:
|
743
|
-
|
744
|
-
def value=(val)
|
745
|
-
if(val.is_a?(String))
|
746
|
-
message = "The #{name} property is an Array, not a String. It looks like you may have used the assignment operator (=) where the append operator (<<) was expected."
|
747
|
-
raise ToolTaskError.new(message)
|
748
|
-
end
|
749
|
-
@value = val
|
750
|
-
end
|
751
|
-
|
752
|
-
# Files lists are initialized to an empty array by default
|
753
|
-
def value
|
754
|
-
@value ||= []
|
755
|
-
end
|
756
|
-
|
757
|
-
# By default, the FilesParams will not appear in the shell
|
758
|
-
# output if there are zero items in the collection
|
759
|
-
def visible?
|
760
|
-
@visible ||= (value && value.size > 0)
|
761
|
-
end
|
762
|
-
|
763
|
-
# Default delimiter is +=
|
764
|
-
# This is what will appear between each name/value pair as in:
|
765
|
-
# "source_path+=src source_path+=test source_path+=lib"
|
766
|
-
def delimiter
|
767
|
-
@delimiter ||= "+="
|
768
|
-
end
|
769
|
-
|
770
|
-
# Returns a shell formatted string of the collection
|
771
|
-
def to_shell
|
772
|
-
return @to_shell_proc.call(self) if(!@to_shell_proc.nil?)
|
773
|
-
|
774
|
-
result = []
|
775
|
-
value.each do |str|
|
776
|
-
result << "#{shell_name}#{delimiter}#{str}"
|
777
|
-
end
|
778
|
-
return result.join(' ')
|
779
|
-
end
|
780
|
-
end
|
781
|
-
|
782
|
-
# Concrete param object for collections of symbols (like class names)
|
783
|
-
class SymbolsParam < StringsParam # :nodoc:
|
784
|
-
end
|
785
|
-
|
786
|
-
# Concrete param object for collections of files
|
787
|
-
class FilesParam < StringsParam # :nodoc:
|
788
|
-
|
789
|
-
def prepare
|
790
|
-
super
|
791
|
-
usr = User.new
|
792
|
-
path = nil
|
793
|
-
value.each_index do |index|
|
794
|
-
path = value[index]
|
795
|
-
value[index] = usr.clean_path path
|
796
|
-
end
|
797
|
-
end
|
798
|
-
|
799
|
-
def prepare_prerequisites
|
800
|
-
if should_preprocess?
|
801
|
-
@value = prepare_preprocessor_files(value)
|
802
|
-
else
|
803
|
-
value.each do |f|
|
804
|
-
file f
|
805
|
-
belongs_to.prerequisites << f
|
806
|
-
end
|
807
|
-
end
|
808
|
-
end
|
809
|
-
|
810
|
-
end
|
811
|
-
|
812
|
-
# Concrete param object for collections of paths
|
813
|
-
class PathsParam < FilesParam # :nodoc:
|
814
|
-
|
815
|
-
def prepare_prerequisites
|
816
|
-
if should_preprocess?
|
817
|
-
@value = prepare_preprocessor_paths(value)
|
818
|
-
else
|
819
|
-
value.each do |path|
|
820
|
-
files = FileList[path + file_expression]
|
821
|
-
files.each do |f|
|
822
|
-
file f
|
823
|
-
belongs_to.prerequisites << f
|
824
|
-
end
|
825
|
-
end
|
826
|
-
end
|
827
|
-
end
|
828
|
-
|
829
|
-
|
830
|
-
end
|
831
|
-
|
832
|
-
# Concrete param object for collections of files
|
833
|
-
class UrlsParam < StringsParam # :nodoc:
|
834
|
-
end
|
835
|
-
|
836
|
-
end
|