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,158 +0,0 @@
|
|
1
|
-
=begin
|
2
|
-
Copyright (c) 2007 Pattern Park
|
3
|
-
|
4
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
-
a copy of this software and associated documentation files (the
|
6
|
-
"Software"), to deal in the Software without restriction, including
|
7
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
-
permit persons to whom the Software is furnished to do so, subject to
|
10
|
-
the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be
|
13
|
-
included in all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
-
=end
|
23
|
-
|
24
|
-
require 'zip/zipfilesystem'
|
25
|
-
|
26
|
-
# TODO: Make this task more like a rake FileTask
|
27
|
-
# The output should be the task name and the input
|
28
|
-
# files should be added as prerequisites
|
29
|
-
|
30
|
-
module Sprout
|
31
|
-
class ZipError < StandardError #:nodoc:
|
32
|
-
end
|
33
|
-
|
34
|
-
# The ZipTask should accept any directory as input and either
|
35
|
-
# an expected zip file name or directory where one will be created
|
36
|
-
# for output.
|
37
|
-
# The resulting zip file will only be generated if a file in the
|
38
|
-
# input directory has a newer timestamp than the existing zip file
|
39
|
-
class ZipTask < Rake::FileTask
|
40
|
-
|
41
|
-
# Array of file names that should not be added to the zip archive.
|
42
|
-
# The default value of this property is:
|
43
|
-
# @excludes = ['.', '..', '.svn', '.cvs', '.DS_Store', '.git', 'CVS', 'Thumbs.db']
|
44
|
-
attr_writer :excludes
|
45
|
-
# The file or folder that should be archived.
|
46
|
-
#
|
47
|
-
# If input is a directory, all of it's contents
|
48
|
-
# will be recursively added to the archive (excluding any files that match +excludes+ of course).
|
49
|
-
#
|
50
|
-
# If input is a file, a new archive will be created with a similar file name and only that file
|
51
|
-
# will be added to the archive.
|
52
|
-
attr_writer :input
|
53
|
-
# Zip archive file to create. Usually, the name of the zip task will be used for this property,
|
54
|
-
# but in cases where you want a particular task name and a different output file, you can set
|
55
|
-
# this parameter.
|
56
|
-
attr_writer :output
|
57
|
-
|
58
|
-
def self.define_task(*args, &block) # :nodoc:
|
59
|
-
t = super
|
60
|
-
yield t if block_given?
|
61
|
-
t.define
|
62
|
-
end
|
63
|
-
|
64
|
-
def define # :nodoc:
|
65
|
-
@input = define_input(input)
|
66
|
-
@output = define_output(output || name)
|
67
|
-
end
|
68
|
-
|
69
|
-
def output
|
70
|
-
@output ||= nil
|
71
|
-
end
|
72
|
-
|
73
|
-
def input
|
74
|
-
@input ||= nil
|
75
|
-
end
|
76
|
-
|
77
|
-
def execute(*args) # :nodoc:
|
78
|
-
create_archive
|
79
|
-
end
|
80
|
-
|
81
|
-
def excludes
|
82
|
-
@excludes ||= ['.', '..', '.svn', '.cvs', '.DS_Store', '.git', 'CVS', 'Thumbs.db']
|
83
|
-
end
|
84
|
-
|
85
|
-
private
|
86
|
-
|
87
|
-
def create_archive(force=false) # :nodoc:
|
88
|
-
return unless (force || name == output)
|
89
|
-
|
90
|
-
start = Dir.pwd
|
91
|
-
begin
|
92
|
-
full_output = File.expand_path(output)
|
93
|
-
full_input = File.expand_path(input)
|
94
|
-
Dir.chdir(File.dirname(full_input))
|
95
|
-
masked_input = full_input.gsub("#{Dir.pwd}/", '')
|
96
|
-
|
97
|
-
# Create the containing folder for output
|
98
|
-
if(!File.directory?(File.dirname(full_output)))
|
99
|
-
FileUtils.mkdir_p(File.dirname(full_output))
|
100
|
-
end
|
101
|
-
|
102
|
-
ZipUtil.pack(masked_input, full_output, excludes)
|
103
|
-
|
104
|
-
ensure
|
105
|
-
Dir.chdir(start)
|
106
|
-
end
|
107
|
-
|
108
|
-
end
|
109
|
-
|
110
|
-
def define_input(input)
|
111
|
-
file input do |t|
|
112
|
-
raise ZipError.new("ZipTask '#{name}' could not find valid input at: #{input}") unless (File.exists?(input))
|
113
|
-
end
|
114
|
-
|
115
|
-
input_files = FileList["#{input}/**/**/*"]
|
116
|
-
input_files.each do |f|
|
117
|
-
prerequisites << f
|
118
|
-
end
|
119
|
-
prerequisites << input
|
120
|
-
return input
|
121
|
-
end
|
122
|
-
|
123
|
-
def define_output(out)
|
124
|
-
|
125
|
-
# If the provided parent dir doesn't
|
126
|
-
# exist, create it
|
127
|
-
if(!File.exists?(File.dirname(out)))
|
128
|
-
FileUtils.mkdir_p(File.dirname(out))
|
129
|
-
end
|
130
|
-
|
131
|
-
# If the provided output is just a directory
|
132
|
-
# and it's parent doesn't yet exist, create the
|
133
|
-
# provided output directory before appending
|
134
|
-
# the real zip file name
|
135
|
-
if(!File.basename(out).index('.'))
|
136
|
-
FileUtils.mkdir_p(out)
|
137
|
-
end
|
138
|
-
|
139
|
-
# If out is just a directory, append input's basename
|
140
|
-
# to create the zip file
|
141
|
-
if(File.directory?(out))
|
142
|
-
out = File.join(out, File.basename(input) + '.zip')
|
143
|
-
end
|
144
|
-
|
145
|
-
if(out != name)
|
146
|
-
file out do
|
147
|
-
create_archive(true)
|
148
|
-
end
|
149
|
-
prerequisites << out
|
150
|
-
end
|
151
|
-
return out
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
def zip(*args, &block)
|
157
|
-
Sprout::ZipTask.define_task(args, &block)
|
158
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
|
2
|
-
module Sprout
|
3
|
-
|
4
|
-
class ToolTaskModel < Rake::FileTask
|
5
|
-
include DynamicAccessors
|
6
|
-
|
7
|
-
def self.define_task(args, &block)
|
8
|
-
t = super
|
9
|
-
yield t if block_given?
|
10
|
-
end
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
def tool_task_model(*args, &block)
|
18
|
-
Sprout::ToolTaskModel.define_task(args, &block)
|
19
|
-
end
|
data/lib/sprout/user.rb
DELETED
@@ -1,415 +0,0 @@
|
|
1
|
-
require 'platform'
|
2
|
-
require 'sprout/log'
|
3
|
-
require 'sprout/process_runner'
|
4
|
-
|
5
|
-
module Sprout
|
6
|
-
|
7
|
-
class ExecutionError < StandardError # :nodoc:
|
8
|
-
end
|
9
|
-
|
10
|
-
# The User class provides a single and consistent interface to User based paths
|
11
|
-
# and features so that Sprout implementation code doesn't need to be concerned
|
12
|
-
# with which Operating system it is running on.
|
13
|
-
#
|
14
|
-
class User
|
15
|
-
@@user = nil
|
16
|
-
|
17
|
-
# Retrieve a user instance that represents the currently logged in user on this system.
|
18
|
-
def User.new(os=nil, impl=nil)
|
19
|
-
if(os.nil? && impl.nil? && @@user)
|
20
|
-
return @@user
|
21
|
-
end
|
22
|
-
if(os.nil?)
|
23
|
-
os = Platform::OS
|
24
|
-
end
|
25
|
-
if(impl.nil?)
|
26
|
-
impl = Platform::IMPL
|
27
|
-
end
|
28
|
-
if(os == :win32 && impl == :vista)
|
29
|
-
@@user = VistaUser.new
|
30
|
-
elsif(os == :win32 && impl == :cygwin)
|
31
|
-
@@user = CygwinUser.new
|
32
|
-
elsif(os == :win32)
|
33
|
-
@@user = WinUser.new
|
34
|
-
elsif(os == :unix && impl == :macosx)
|
35
|
-
@@user = OSXUser.new
|
36
|
-
# elsif(os == :unix && impl == :linux)
|
37
|
-
# @@user = UnixUser.new
|
38
|
-
else
|
39
|
-
@@user = UnixUser.new
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def User.user=(user) # :nodoc:
|
44
|
-
@@user = user
|
45
|
-
end
|
46
|
-
|
47
|
-
def User.home=(path) # :nodoc:
|
48
|
-
User.new().home = path
|
49
|
-
end
|
50
|
-
|
51
|
-
def User.is_a?(type)
|
52
|
-
User.new().is_a?(type)
|
53
|
-
end
|
54
|
-
|
55
|
-
# Pass an executable or binary file name and find out if that file exists in the system
|
56
|
-
# path or not
|
57
|
-
def User.in_path?(executable)
|
58
|
-
User.new().in_path?(executable)
|
59
|
-
end
|
60
|
-
|
61
|
-
# Retrieve the full path to an executable that exists in the user path
|
62
|
-
def User.get_exe_path(executable)
|
63
|
-
return User.new().get_exe_path(executable)
|
64
|
-
end
|
65
|
-
|
66
|
-
# Return the home path for the currently logged in user. If the user name is lbayes, this should be:
|
67
|
-
#
|
68
|
-
# Windows XP:: C:\Documents And Settings\lbayes
|
69
|
-
# Cygwin:: /cygdrive/c/Documents And Settings/lbayes
|
70
|
-
# OS X:: /Users/lbayes
|
71
|
-
# Linux:: ~/
|
72
|
-
def User.home
|
73
|
-
User.new().home
|
74
|
-
end
|
75
|
-
|
76
|
-
# Returns the home path for a named application based on the currently logged in user and operating system.
|
77
|
-
# If the user name is lbayes and the application name is Sprouts, this path will be:
|
78
|
-
#
|
79
|
-
# Windows XP:: C:\Documents And Settings\lbayes\Local Settings\Application Data\Sprouts
|
80
|
-
# Cygwin:: /cygdrive/c/Documents And Settings/Local Settings/Application Data/Sprouts
|
81
|
-
# OS X:: /Users/lbayes/Library/Sprouts
|
82
|
-
# Linux:: ~/.sprouts
|
83
|
-
def User.application_home(name)
|
84
|
-
return User.new().application_home(name)
|
85
|
-
end
|
86
|
-
|
87
|
-
# Returns the library path on the current system. This is the general path where all applications should
|
88
|
-
# store configuration or session data.
|
89
|
-
#
|
90
|
-
# Windows XP:: C:\Documents And Settings\lbayes\Local Settings\Application Data
|
91
|
-
# Cygwin:: /cygdrive/c/Documents And Settings/lbayes/Local Settings/Application Data
|
92
|
-
# OS X:: /Users/lbayes/Library
|
93
|
-
# Linux:: ~/
|
94
|
-
def User.library
|
95
|
-
return User.new().library
|
96
|
-
end
|
97
|
-
|
98
|
-
# Execute a named tool sprout. The full sprout name should be provided to the tool parameter, and
|
99
|
-
# a string of shell parameters that will be sent to the tool itself.
|
100
|
-
def User.execute(tool, options='')
|
101
|
-
return User.new().execute(tool, options)
|
102
|
-
end
|
103
|
-
|
104
|
-
def User.execute_silent(tool, options='')
|
105
|
-
return User.new().execute_silent(tool, options)
|
106
|
-
end
|
107
|
-
|
108
|
-
# Execute a named tool sprout as a new thread and return that thread
|
109
|
-
def User.execute_thread(tool, options='')
|
110
|
-
if(Log.debug)
|
111
|
-
return ThreadMock.new
|
112
|
-
else
|
113
|
-
return User.new().execute_thread(tool, options)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
# Clean a path string in such a way that works for each platform. For example, Windows doesn't like
|
118
|
-
# it when we backslash to escape spaces in a path because that is the character they use as a delimiter.
|
119
|
-
# And OS X doesn't really like it when we wrap paths in quotes.
|
120
|
-
def User.clean_path(path)
|
121
|
-
return User.new().clean_path(path)
|
122
|
-
end
|
123
|
-
|
124
|
-
end
|
125
|
-
|
126
|
-
#############################
|
127
|
-
# UnixUser class
|
128
|
-
class UnixUser # :nodoc:
|
129
|
-
|
130
|
-
def initialize
|
131
|
-
setup_user
|
132
|
-
@home = nil
|
133
|
-
end
|
134
|
-
|
135
|
-
def setup_user
|
136
|
-
end
|
137
|
-
|
138
|
-
def home=(path)
|
139
|
-
@home = path
|
140
|
-
end
|
141
|
-
|
142
|
-
def home
|
143
|
-
if(@home)
|
144
|
-
return @home
|
145
|
-
end
|
146
|
-
|
147
|
-
# Original implementation:
|
148
|
-
#["HOME", "USERPROFILE"].each do |homekey|
|
149
|
-
# Change submitted by Michael Fleet (disinovate)
|
150
|
-
# Does this work for everyone on Windows?
|
151
|
-
["USERPROFILE", "HOME"].each do |homekey|
|
152
|
-
return @home = ENV[homekey] if ENV[homekey]
|
153
|
-
end
|
154
|
-
|
155
|
-
if ENV["HOMEDRIVE"] && ENV["HOMEPATH"]
|
156
|
-
return @home = "#{ENV["HOMEDRIVE"]}:#{ENV["HOMEPATH"]}"
|
157
|
-
end
|
158
|
-
|
159
|
-
begin
|
160
|
-
return @home = File.expand_path("~")
|
161
|
-
rescue StandardError => e
|
162
|
-
if File::ALT_SEPARATOR
|
163
|
-
return @home = "C:\\"
|
164
|
-
else
|
165
|
-
return @home = "/"
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
def get_exe_path(executable)
|
171
|
-
paths = get_paths
|
172
|
-
file = nil
|
173
|
-
paths.each do |path|
|
174
|
-
file = File.join(path, executable)
|
175
|
-
if(File.exists?(file))
|
176
|
-
return file
|
177
|
-
end
|
178
|
-
end
|
179
|
-
return nil
|
180
|
-
end
|
181
|
-
|
182
|
-
def in_path?(executable)
|
183
|
-
return !get_exe_path(executable).nil?
|
184
|
-
end
|
185
|
-
|
186
|
-
def get_paths
|
187
|
-
return ENV['PATH'].split(':')
|
188
|
-
end
|
189
|
-
|
190
|
-
def library
|
191
|
-
return home
|
192
|
-
end
|
193
|
-
|
194
|
-
def platform
|
195
|
-
if(Platform::OS == :win32)
|
196
|
-
return :win32
|
197
|
-
elsif(Platform::IMPL == :macosx)
|
198
|
-
return :macosx
|
199
|
-
else
|
200
|
-
return Platform::IMPL
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
def get_process_runner(command)
|
205
|
-
return ProcessRunner.new(command)
|
206
|
-
end
|
207
|
-
|
208
|
-
# Creates a new process, executes the command
|
209
|
-
# and returns the result and throws if the process
|
210
|
-
# writes to stderr
|
211
|
-
def execute(tool, options='')
|
212
|
-
Log.puts(">> Execute: #{File.basename(tool)} #{options}")
|
213
|
-
tool = clean_path(tool)
|
214
|
-
runner = get_process_runner("#{tool} #{options}")
|
215
|
-
|
216
|
-
error = runner.read_err
|
217
|
-
result = runner.read
|
218
|
-
|
219
|
-
if(result.size > 0)
|
220
|
-
Log.puts result
|
221
|
-
end
|
222
|
-
|
223
|
-
if(error.size > 0)
|
224
|
-
raise ExecutionError.new("[ERROR] #{error}")
|
225
|
-
end
|
226
|
-
|
227
|
-
result || error
|
228
|
-
end
|
229
|
-
|
230
|
-
# Creates and returns the process without
|
231
|
-
# attempting to read or write to the stream.
|
232
|
-
# This is useful for interacting with
|
233
|
-
# long-lived CLI processes like FCSH or FDB.
|
234
|
-
def execute_silent(tool, options='')
|
235
|
-
tool = clean_path(tool)
|
236
|
-
return get_process_runner("#{tool} #{options}")
|
237
|
-
end
|
238
|
-
|
239
|
-
def execute_thread(tool, options='')
|
240
|
-
return Thread.new do
|
241
|
-
execute(tool, options)
|
242
|
-
end
|
243
|
-
end
|
244
|
-
|
245
|
-
# Repair Windows Line endings
|
246
|
-
# found in non-windows executables
|
247
|
-
# (Flex SDK is regularly published
|
248
|
-
# with broken CRLFs)
|
249
|
-
def repair_executable(path)
|
250
|
-
return unless should_repair_executable(path)
|
251
|
-
|
252
|
-
content = File.read(path)
|
253
|
-
if(content.match(/\r\n/))
|
254
|
-
content.gsub!(/\r\n/, "\n")
|
255
|
-
File.open(path, 'w+') do |f|
|
256
|
-
f.write content
|
257
|
-
end
|
258
|
-
end
|
259
|
-
end
|
260
|
-
|
261
|
-
def should_repair_executable(path)
|
262
|
-
return (File.exists?(path) && !File.directory?(path) && File.read(path).match(/^\#\!/))
|
263
|
-
end
|
264
|
-
|
265
|
-
def clean_path(path)
|
266
|
-
repair_executable path
|
267
|
-
|
268
|
-
if(path.index(' '))
|
269
|
-
# Changed 2/26/2008 in attempt to support
|
270
|
-
# ToolTask.PathsParam s that have spaces in the values
|
271
|
-
return path.split(' ').join('\ ')
|
272
|
-
# return %{'#{path}'}
|
273
|
-
end
|
274
|
-
return path
|
275
|
-
end
|
276
|
-
|
277
|
-
def application_home(name)
|
278
|
-
return File.join(library, format_application_name(name.to_s));
|
279
|
-
end
|
280
|
-
|
281
|
-
def format_application_name(name)
|
282
|
-
if(name.index('.') != 0)
|
283
|
-
name = '.' + name
|
284
|
-
end
|
285
|
-
return name.split(" ").join("_").downcase
|
286
|
-
end
|
287
|
-
end
|
288
|
-
|
289
|
-
class OSXUser < UnixUser # :nodoc:
|
290
|
-
@@LIBRARY = 'Library'
|
291
|
-
|
292
|
-
def library
|
293
|
-
lib = File.join(home, @@LIBRARY)
|
294
|
-
if(File.exists?(lib))
|
295
|
-
return lib
|
296
|
-
else
|
297
|
-
return super
|
298
|
-
end
|
299
|
-
end
|
300
|
-
|
301
|
-
def format_application_name(name)
|
302
|
-
return name.capitalize
|
303
|
-
end
|
304
|
-
end
|
305
|
-
|
306
|
-
class WinUser < UnixUser # :nodoc:
|
307
|
-
@@LOCAL_SETTINGS = "Local\ Settings"
|
308
|
-
@@APPLICATION_DATA = "Application\ Data"
|
309
|
-
|
310
|
-
def initialize
|
311
|
-
super
|
312
|
-
@home = nil
|
313
|
-
end
|
314
|
-
|
315
|
-
def setup_user
|
316
|
-
end
|
317
|
-
|
318
|
-
def home
|
319
|
-
usr = super
|
320
|
-
if(usr.index "My Documents")
|
321
|
-
usr = File.dirname(usr)
|
322
|
-
end
|
323
|
-
return usr
|
324
|
-
end
|
325
|
-
|
326
|
-
def get_paths
|
327
|
-
return ENV['PATH'].split(';')
|
328
|
-
end
|
329
|
-
|
330
|
-
def library
|
331
|
-
# For some reason, my homepath returns inside 'My Documents'...
|
332
|
-
application_data = File.join(home, @@LOCAL_SETTINGS, @@APPLICATION_DATA)
|
333
|
-
if(File.exists?(application_data))
|
334
|
-
return application_data
|
335
|
-
else
|
336
|
-
return super
|
337
|
-
end
|
338
|
-
end
|
339
|
-
|
340
|
-
# Override from UnixUser and
|
341
|
-
# block behavior.
|
342
|
-
# I know this is smelly... Fixes?
|
343
|
-
def should_repair_executable(path)
|
344
|
-
false
|
345
|
-
end
|
346
|
-
|
347
|
-
def clean_path(path)
|
348
|
-
path = path.split('/').join("\\")
|
349
|
-
if(path.index(' '))
|
350
|
-
return %{"#{path}"}
|
351
|
-
end
|
352
|
-
return path
|
353
|
-
end
|
354
|
-
|
355
|
-
def format_application_name(name)
|
356
|
-
return name.capitalize
|
357
|
-
end
|
358
|
-
end
|
359
|
-
|
360
|
-
class CygwinUser < WinUser # :nodoc:
|
361
|
-
|
362
|
-
def initialize
|
363
|
-
super
|
364
|
-
@home = nil
|
365
|
-
@win_home = nil
|
366
|
-
@win_home_cyg_path = nil
|
367
|
-
end
|
368
|
-
|
369
|
-
def setup_user
|
370
|
-
end
|
371
|
-
|
372
|
-
def clean_path(path)
|
373
|
-
if(path.index(' '))
|
374
|
-
return %{'#{path}'}
|
375
|
-
end
|
376
|
-
return path
|
377
|
-
end
|
378
|
-
|
379
|
-
def win_home
|
380
|
-
if(@win_home.nil?)
|
381
|
-
@win_home = ENV['HOMEDRIVE'] + ENV['HOMEPATH']
|
382
|
-
end
|
383
|
-
return @win_home
|
384
|
-
end
|
385
|
-
|
386
|
-
def home
|
387
|
-
if(@home.nil?)
|
388
|
-
path = win_home.split('\\').join("/")
|
389
|
-
path = path.split(":").join("")
|
390
|
-
parts = path.split("/")
|
391
|
-
path = parts.shift().downcase + "/" + parts.join("/")
|
392
|
-
@home = "/cygdrive/" + path
|
393
|
-
end
|
394
|
-
return @home
|
395
|
-
end
|
396
|
-
|
397
|
-
end
|
398
|
-
|
399
|
-
class VistaUser < WinUser # :nodoc:
|
400
|
-
def home
|
401
|
-
profile = ENV['USERPROFILE']
|
402
|
-
if(profile)
|
403
|
-
return profile
|
404
|
-
end
|
405
|
-
return super
|
406
|
-
end
|
407
|
-
end
|
408
|
-
|
409
|
-
class ThreadMock # :nodoc:
|
410
|
-
def alive?
|
411
|
-
return false
|
412
|
-
end
|
413
|
-
end
|
414
|
-
end
|
415
|
-
|