asproject 0.1.21
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.txt +0 -0
- data/History.txt +0 -0
- data/MIT-LICENSE.txt +20 -0
- data/Manifest.txt +16 -0
- data/README.txt +3 -0
- data/TODO.txt +10 -0
- data/bin/asclass +16 -0
- data/bin/asproject +16 -0
- data/lib/asclass.rb +254 -0
- data/lib/asclass_arguments.rb +147 -0
- data/lib/asproject.rb +248 -0
- data/lib/asproject/version.rb +9 -0
- data/lib/asproject_arguments.rb +175 -0
- data/lib/asproject_base.rb +43 -0
- data/lib/asproject_utils.rb +57 -0
- data/lib/eclipse_project.rb +32 -0
- data/lib/path_finder.rb +286 -0
- data/lib/platform.rb +107 -0
- data/lib/project.rb +82 -0
- data/lib/template_resolver.rb +144 -0
- data/lib/test_suite_generator.rb +128 -0
- data/rakefile.rb +85 -0
- data/setup.rb +1585 -0
- data/templates/asclass/as2/Class.as +11 -0
- data/templates/asclass/as2/Component.as +8 -0
- data/templates/asclass/as2/Interface.as +3 -0
- data/templates/asclass/as2/TestCase.as +30 -0
- data/templates/asclass/as2/TestSuite.as +15 -0
- data/templates/asclass/as3/Class.as +9 -0
- data/templates/asclass/as3/Component.as +9 -0
- data/templates/asclass/as3/Component.mxml +1 -0
- data/templates/asclass/as3/Interface.as +6 -0
- data/templates/asclass/as3/TestCase.as +30 -0
- data/templates/asclass/as3/TestSuite.as +18 -0
- data/templates/asproject/as2/project/rakefile.rb +18 -0
- data/templates/asproject/as2/project/src/AsProject.as +13 -0
- data/templates/asproject/as2/project/test/AsProjectRunner.as +12 -0
- data/templates/asproject/as3/project/rakefile.rb +18 -0
- data/templates/asproject/as3/project/src/AsProject.as +9 -0
- data/templates/asproject/as3/project/src/AsProjectRunner.as +11 -0
- data/templates/asproject/asunit2/project/lib/asunit/AsUnitUi.swf +0 -0
- data/templates/asproject/asunit2/project/lib/asunit/Sys.as +70 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/LocalOutputPanel.as +182 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/LocalOutputPanelTest.as +84 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/LocalOutputPanelTextArea.as +111 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/LocalOutputPanelTextAreaTest.as +26 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/LocalOutputPanelTitleBar.as +81 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/ResizeHandle.as +35 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/ScrollArrow.as +34 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/ScrollHandle.as +43 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/ScrollListener.as +10 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/TextScroller.as +169 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/shapes/Rectangle.as +29 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/shapes/Triangle.as +27 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/AsUnit.as +19 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/Assert.as +408 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/Assertion.as +27 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/Reflection.as +68 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/Test.as +3 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/TestCase.as +191 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/TestCaseXml.as +31 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/TestFailure.as +15 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/TestResult.as +15 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/TestRunner.as +41 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/TestSetup.as +19 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/TestSuite.as +22 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/ui/Main.as +325 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/ui/RemoteVersion.as +24 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/ui/SuccessMeter.as +32 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/Comparable.as +7 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/EventListener.as +29 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/EventSource.as +89 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalConnClient.as +42 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalConnGateway.as +47 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalConnServer.as +61 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalMessageBroker.as +58 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/Observable.as +11 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/TextFile.as +30 -0
- data/templates/asproject/asunit25/project/lib/asunit/AsUnitTestRunner.as +13 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/errors/AssertionFailedError.as +7 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/errors/AssertionPassedError.as +7 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/errors/ClassNotFoundError.as +7 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/errors/IllegalOperationError.as +7 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/errors/InstanceNotFoundError.as +7 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/errors/InvocationTargetError.as +7 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/errors/UnimplementedFeatureError.as +7 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/Assert.as +376 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/AssertMock.as +15 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/AssertTest.as +59 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/ITestListener.as +13 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/Test.as +11 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/TestCase.as +277 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/TestCaseMock.as +23 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/TestCaseTest.as +29 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/TestCaseXml.as +38 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/TestFailure.as +47 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/TestResult.as +168 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/TestSuite.as +102 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/runner/BaseTestRunner.as +101 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/runner/IResultPrinter.as +8 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/textui/ResultPrinter.as +254 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/textui/SuccessBar.as +41 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/textui/TestRunner.as +17 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/util/ArrayIterator.as +24 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/util/ArrayIteratorTest.as +52 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/util/Iterator.as +5 -0
- data/templates/asproject/asunit3/project/lib/asunit/AsUnitTestRunner.as +10 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/errors/AbstractMemberCalledError.as +10 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/errors/AssertionFailedError.as +10 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/errors/ClassNotFoundError.as +10 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/errors/InstanceNotFoundError.as +10 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/errors/UnimplementedFeatureError.as +10 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/Assert.as +271 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/AsynchronousTestCase.as +52 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/AsynchronousTestCaseExample.as +71 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/Test.as +15 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/TestCase.as +351 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/TestCaseExample.as +73 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/TestFailure.as +47 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/TestListener.as +22 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/TestResult.as +158 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/TestSuite.as +115 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/runner/BaseTestRunner.as +15 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/runner/TestSuiteLoader.as +9 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/runner/Version.as +11 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/textui/FlexRunner.as +19 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/textui/FlexTestRunner.as +55 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/textui/ResultPrinter.as +245 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/textui/TestRunner.as +121 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/util/ArrayIterator.as +26 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/util/Iterator.as +9 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/util/Properties.as +30 -0
- data/templates/asproject/asunit3/project/lib/asunit/mx/managers/LayoutManager.as +945 -0
- data/templates/asproject/config/project/config/asclass_config.rb +58 -0
- data/templates/asproject/fb2as/project/.actionScriptProperties +21 -0
- data/templates/asproject/fb2as/project/.project +29 -0
- data/templates/asproject/fdt/project/.as2_classpath +6 -0
- data/templates/asproject/fdt/project/.project +19 -0
- data/templates/ide/mate/Create Class.tmCommand +37 -0
- data/templates/ide/mate/Rebuild Test Suites.tmCommand +33 -0
- data/templates/ide/mate/Run Rake Task.tmCommand +127 -0
- metadata +266 -0
@@ -0,0 +1,57 @@
|
|
1
|
+
|
2
|
+
module AsProject
|
3
|
+
|
4
|
+
##########################
|
5
|
+
# Custom Errors
|
6
|
+
class ProjectError < StandardError; end
|
7
|
+
class UsageError < ProjectError; end
|
8
|
+
end
|
9
|
+
|
10
|
+
RAND_CHARS = ['A','B','C','D','E','F','a','b','c','d','e','f']
|
11
|
+
|
12
|
+
def Dir::unique_tmpdir(application='RubyApplication')
|
13
|
+
rand_max = RAND_CHARS.size
|
14
|
+
uniqueish_name = ''
|
15
|
+
24.times{ uniqueish_name << RAND_CHARS[rand(rand_max)] }
|
16
|
+
|
17
|
+
tmp = Dir.tmpdir
|
18
|
+
app_tmp = File.join(tmp, application)
|
19
|
+
if(!File.exists?(app_tmp))
|
20
|
+
Dir.mkdir(app_tmp)
|
21
|
+
end
|
22
|
+
|
23
|
+
tmp = File.expand_path(File.join(app_tmp, uniqueish_name))
|
24
|
+
if(File.exists?(tmp) && is_retry)
|
25
|
+
raise ProjectError.new('Dir.unique_tmpdir attempted to create a new dir over an existing dir')
|
26
|
+
# else if(File.exists?(tmp))
|
27
|
+
# Try again once before failing, uniqueish names aren't too unique...
|
28
|
+
# Dir.unique_tmpdir(application, true)
|
29
|
+
end
|
30
|
+
Dir.mkdir(tmp)
|
31
|
+
return tmp
|
32
|
+
end
|
33
|
+
|
34
|
+
def Dir::tmpdir
|
35
|
+
tmp = nil
|
36
|
+
for dir in [ENV['TMPDIR'], ENV['TMP'], ENV['TEMP'],
|
37
|
+
ENV['USERPROFILE'], '/tmp']
|
38
|
+
if dir and File.directory?(dir) and File.writable?(dir)
|
39
|
+
tmp = dir
|
40
|
+
break
|
41
|
+
end
|
42
|
+
end
|
43
|
+
if(tmp.nil?)
|
44
|
+
raise ProjectError.new('AsProject was unable to find a valid temporary directory on this computer.')
|
45
|
+
end
|
46
|
+
# Has to actually CD to the dir, because
|
47
|
+
# on os x, tmp == /tmp until you're in it,
|
48
|
+
# then it's /private/tmp?!
|
49
|
+
# TestCases are relying on this value to
|
50
|
+
# Be identical when you retrieve it and
|
51
|
+
# when you are 'in' it...
|
52
|
+
start = Dir.pwd
|
53
|
+
Dir.chdir(tmp)
|
54
|
+
tmp = Dir.pwd
|
55
|
+
Dir.chdir(start)
|
56
|
+
return tmp
|
57
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
require 'rexml/document'
|
3
|
+
|
4
|
+
module AsProject
|
5
|
+
class EclipseProject < Project
|
6
|
+
|
7
|
+
def initialize(dir=nil)
|
8
|
+
super(dir)
|
9
|
+
@project_name = ''
|
10
|
+
@file_path = nil
|
11
|
+
if(!dir.nil?)
|
12
|
+
self.file_path = File.join(dir, '.project')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def file_path=(path)
|
17
|
+
@file_path = path
|
18
|
+
file = File.open(path, 'r')
|
19
|
+
parse(file.read)
|
20
|
+
file.close
|
21
|
+
end
|
22
|
+
|
23
|
+
def parse(str)
|
24
|
+
xml = REXML::Document.new(str)
|
25
|
+
@project_name = REXML::XPath.first(xml, '//projectDescription/name').text
|
26
|
+
end
|
27
|
+
|
28
|
+
def file_path
|
29
|
+
return @file_path
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/path_finder.rb
ADDED
@@ -0,0 +1,286 @@
|
|
1
|
+
|
2
|
+
module AsProject
|
3
|
+
class PathFinder < TemplateResolver
|
4
|
+
attr_accessor :execution_dir
|
5
|
+
|
6
|
+
def initialize(execution_dir)
|
7
|
+
super()
|
8
|
+
@execution_dir = execution_dir
|
9
|
+
@current_project = nil
|
10
|
+
@user = create_user
|
11
|
+
end
|
12
|
+
|
13
|
+
def gem_asproject_home
|
14
|
+
parent = File.dirname(File.dirname(__FILE__))
|
15
|
+
return File.expand_path(parent)
|
16
|
+
end
|
17
|
+
|
18
|
+
def user_library
|
19
|
+
return @user.library
|
20
|
+
end
|
21
|
+
|
22
|
+
def user_home
|
23
|
+
return @user.home
|
24
|
+
end
|
25
|
+
|
26
|
+
def user_asproject_home
|
27
|
+
return @user.asproject_home
|
28
|
+
end
|
29
|
+
|
30
|
+
def current_project=(dir)
|
31
|
+
@current_project = dir
|
32
|
+
end
|
33
|
+
|
34
|
+
# Don't store the 'inspected' current_project
|
35
|
+
# Only store it if the value was set from
|
36
|
+
# outside
|
37
|
+
def current_project
|
38
|
+
if(@current_project.nil?)
|
39
|
+
return find_project(@execution_dir)
|
40
|
+
else
|
41
|
+
return @current_project
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def get_children(dir)
|
46
|
+
list = []
|
47
|
+
if(dir.nil?)
|
48
|
+
return list
|
49
|
+
end
|
50
|
+
Dir.open(dir).each do |child|
|
51
|
+
if(!AsProject.ignore_file? child)
|
52
|
+
list << child
|
53
|
+
end
|
54
|
+
end
|
55
|
+
return list
|
56
|
+
end
|
57
|
+
|
58
|
+
# Collect and return all available templates from:
|
59
|
+
# (PROJECT_PATH)/config/templates/(TYPE)/
|
60
|
+
# (USER_HOME)/(ASPROJECT_HOME)/templates/
|
61
|
+
# (ASPROJECT_GEM_HOME)/templates
|
62
|
+
def get_available_templates(type)
|
63
|
+
project_templates = get_children(get_project_template(type, ''))
|
64
|
+
user_templates = get_children(get_user_template(type, ''))
|
65
|
+
gem_templates = get_children(get_gem_template(type, ''))
|
66
|
+
result = []
|
67
|
+
project_templates.each do |template|
|
68
|
+
result << template
|
69
|
+
end
|
70
|
+
user_templates.each do |template|
|
71
|
+
if(!result.index(template))
|
72
|
+
result << template
|
73
|
+
end
|
74
|
+
end
|
75
|
+
gem_templates.each do |template|
|
76
|
+
if(!result.index(template))
|
77
|
+
result << template
|
78
|
+
end
|
79
|
+
end
|
80
|
+
return result
|
81
|
+
end
|
82
|
+
|
83
|
+
# @type: 'class' or 'project'
|
84
|
+
# @name: 'as3', 'mxml', 'fb2', or user-created folder name
|
85
|
+
# Represents folders inside of the appropriate template type dir
|
86
|
+
def get_template(type, name)
|
87
|
+
template = get_project_template(type, name)
|
88
|
+
if(template.nil?)
|
89
|
+
template = get_user_template(type, name)
|
90
|
+
end
|
91
|
+
if(template.nil?)
|
92
|
+
template = get_gem_template(type, name)
|
93
|
+
end
|
94
|
+
return template
|
95
|
+
end
|
96
|
+
|
97
|
+
def get_project_template(type, name)
|
98
|
+
begin
|
99
|
+
if(@execution_dir.nil?)
|
100
|
+
dir = Dir.pwd
|
101
|
+
else
|
102
|
+
dir = @execution_dir
|
103
|
+
end
|
104
|
+
project = find_project(dir)
|
105
|
+
template = File.join(project, 'config', 'templates', type, name)
|
106
|
+
if(File.exists? template)
|
107
|
+
return template
|
108
|
+
else
|
109
|
+
return nil
|
110
|
+
end
|
111
|
+
rescue
|
112
|
+
return nil
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def get_user_template(type, name)
|
117
|
+
template = File.expand_path(File.join(user_asproject_home, 'templates', type, name))
|
118
|
+
if(File.exists? template)
|
119
|
+
return template
|
120
|
+
else
|
121
|
+
return nil
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def get_gem_template(type, name)
|
126
|
+
template = File.expand_path(File.join(gem_asproject_home, 'templates', type, name))
|
127
|
+
if(File.exists? template)
|
128
|
+
return template
|
129
|
+
end
|
130
|
+
raise ProjectError.new('Requested template not found at ' + template)
|
131
|
+
end
|
132
|
+
|
133
|
+
private
|
134
|
+
def find_project(dir)
|
135
|
+
if(is_project? dir)
|
136
|
+
return dir
|
137
|
+
elsif(File.dirname(dir) == dir)
|
138
|
+
raise ProjectError.new('AsProject::PathFinder reached the root of the file system without finding a valid project.')
|
139
|
+
else
|
140
|
+
find_project(File.dirname(dir))
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
# Why wouldn't RDT let me spread this if statement
|
145
|
+
# Over multiple lines?
|
146
|
+
private
|
147
|
+
def is_project?(dir)
|
148
|
+
return (has_config_yaml?(dir) || has_eclipse_project?(dir) || has_src_eclipse_project?(dir) || has_src_and_test?(dir))
|
149
|
+
end
|
150
|
+
|
151
|
+
def has_config_yaml?(dir)
|
152
|
+
return File.exists?(File.join(dir, 'config', 'asproject.yaml'))
|
153
|
+
end
|
154
|
+
|
155
|
+
def has_eclipse_project?(dir)
|
156
|
+
return File.exists?(File.join(dir, '.project'))
|
157
|
+
end
|
158
|
+
|
159
|
+
def has_src_eclipse_project?(dir)
|
160
|
+
return File.exists?(File.join(dir, 'src', '.project'))
|
161
|
+
end
|
162
|
+
|
163
|
+
def has_src_and_test?(dir)
|
164
|
+
return File.directory?(File.join(dir, 'src')) && File.directory?(File.join(dir, 'test'))
|
165
|
+
end
|
166
|
+
|
167
|
+
private
|
168
|
+
def create_user
|
169
|
+
os = Platform::OS
|
170
|
+
impl = Platform::IMPL
|
171
|
+
if(os == :win32 || os == :unix && impl == :cygwin)
|
172
|
+
@user = WinUser.new
|
173
|
+
elsif(os == :unix && impl == :macosx)
|
174
|
+
@user = OSXUser.new
|
175
|
+
else
|
176
|
+
@user = User.new
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
#############################
|
182
|
+
# User class
|
183
|
+
class User
|
184
|
+
|
185
|
+
def initialize
|
186
|
+
@default_asproject = '.asproject'
|
187
|
+
end
|
188
|
+
|
189
|
+
def asproject_home
|
190
|
+
return get_or_create(File.join(home, @default_asproject))
|
191
|
+
end
|
192
|
+
|
193
|
+
def library
|
194
|
+
return home
|
195
|
+
end
|
196
|
+
|
197
|
+
def home
|
198
|
+
["HOME", "USERPROFILE"].each do |homekey|
|
199
|
+
return ENV[homekey] if ENV[homekey]
|
200
|
+
end
|
201
|
+
|
202
|
+
if ENV["HOMEDRIVE"] && ENV["HOMEPATH"]
|
203
|
+
return "#{ENV["HOMEDRIVE"]}:#{ENV["HOMEPATH"]}"
|
204
|
+
end
|
205
|
+
|
206
|
+
begin
|
207
|
+
File.expand_path("~")
|
208
|
+
rescue StandardError => ex
|
209
|
+
if File::ALT_SEPARATOR
|
210
|
+
"C:/"
|
211
|
+
else
|
212
|
+
"/"
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
def file_exists?(file)
|
218
|
+
return File.exists?(file)
|
219
|
+
end
|
220
|
+
|
221
|
+
def get_or_create dir
|
222
|
+
if(!file_exists? dir)
|
223
|
+
Dir.mkdir dir
|
224
|
+
end
|
225
|
+
return dir
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
class WinUser < User
|
230
|
+
@@LOCAL_SETTINGS = "Local\ Settings"
|
231
|
+
@@APPLICATION_DATA = "Application\ Data"
|
232
|
+
|
233
|
+
def initialize
|
234
|
+
super
|
235
|
+
@win_asproject = 'AsProject'
|
236
|
+
end
|
237
|
+
|
238
|
+
def library
|
239
|
+
usr = home
|
240
|
+
# For some reason, my homepath returns inside 'My Documents'...
|
241
|
+
if(usr.index "My Documents")
|
242
|
+
usr = File.dirname(usr)
|
243
|
+
end
|
244
|
+
application_data = File.join(usr, @@LOCAL_SETTINGS, @@APPLICATION_DATA)
|
245
|
+
if(File.exists?(application_data))
|
246
|
+
return application_data
|
247
|
+
else
|
248
|
+
return super
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
def asproject_home
|
253
|
+
if(library == home)
|
254
|
+
return super
|
255
|
+
end
|
256
|
+
ap_home = File.join(library, @win_asproject);
|
257
|
+
return get_or_create(ap_home)
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
class OSXUser < User
|
262
|
+
@@LIBRARY = 'Library'
|
263
|
+
|
264
|
+
def initialize
|
265
|
+
super
|
266
|
+
@osx_asproject = 'AsProject'
|
267
|
+
end
|
268
|
+
|
269
|
+
def library
|
270
|
+
lib = File.join(home, @@LIBRARY)
|
271
|
+
if(File.exists?(lib))
|
272
|
+
return lib
|
273
|
+
else
|
274
|
+
return super
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
def asproject_home
|
279
|
+
if(library == home)
|
280
|
+
return super
|
281
|
+
end
|
282
|
+
ap_home = File.join(library, @osx_asproject)
|
283
|
+
get_or_create(ap_home)
|
284
|
+
end
|
285
|
+
end
|
286
|
+
end
|
data/lib/platform.rb
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
#
|
2
|
+
# platform.rb: naive platform detection for Ruby
|
3
|
+
# author: Matt Mower <self@mattmower.com>
|
4
|
+
#
|
5
|
+
|
6
|
+
# == Platform
|
7
|
+
#
|
8
|
+
# Platform is a simple module which parses the Ruby constant
|
9
|
+
# RUBY_PLATFORM and works out the OS, it's implementation,
|
10
|
+
# and the architecture it's running on.
|
11
|
+
#
|
12
|
+
# The motivation for writing this was coming across a case where
|
13
|
+
#
|
14
|
+
# +if RUBY_PLATFORM =~ /win/+
|
15
|
+
#
|
16
|
+
# didn't behave as expected (i.e. on powerpc-darwin-8.1.0)
|
17
|
+
#
|
18
|
+
# It is hoped that providing a library for parsing the platform
|
19
|
+
# means that we can cover all the cases and have something which
|
20
|
+
# works reliably 99% of the time.
|
21
|
+
#
|
22
|
+
# Please report any anomalies or new combinations to the author(s).
|
23
|
+
#
|
24
|
+
# == Use
|
25
|
+
#
|
26
|
+
# require "platform"
|
27
|
+
#
|
28
|
+
# defines
|
29
|
+
#
|
30
|
+
# Platform::OS (:unix,:win32,:vms,:os2)
|
31
|
+
# Platform::impl (:macosx,:linux,:mswin)
|
32
|
+
# Platform::arch (:powerpc,:x86,:alpha)
|
33
|
+
#
|
34
|
+
# if an unknown configuration is encountered any (or all) of
|
35
|
+
# these constant may have the value :unknown.
|
36
|
+
#
|
37
|
+
# To display the combination for your setup run
|
38
|
+
#
|
39
|
+
# ruby platform.rb
|
40
|
+
#
|
41
|
+
module Platform
|
42
|
+
os = nil
|
43
|
+
impl = nil
|
44
|
+
arch = nil
|
45
|
+
|
46
|
+
if RUBY_PLATFORM =~ /darwin/i
|
47
|
+
os = :unix
|
48
|
+
impl = :macosx
|
49
|
+
elsif RUBY_PLATFORM =~ /linux/i
|
50
|
+
os = :unix
|
51
|
+
impl = :linux
|
52
|
+
elsif RUBY_PLATFORM =~ /freebsd/i
|
53
|
+
os = :unix
|
54
|
+
impl = :freebsd
|
55
|
+
elsif RUBY_PLATFORM =~ /netbsd/i
|
56
|
+
os = :unix
|
57
|
+
impl = :netbsd
|
58
|
+
elsif RUBY_PLATFORM =~ /mswin/i
|
59
|
+
os = :win32
|
60
|
+
impl = :mswin
|
61
|
+
elsif RUBY_PLATFORM =~ /cygwin/i
|
62
|
+
os = :unix
|
63
|
+
impl = :cygwin
|
64
|
+
elsif RUBY_PLATFORM =~ /mingw/i
|
65
|
+
os = :win32
|
66
|
+
impl = :mingw
|
67
|
+
elsif RUBY_PLATFORM =~ /bccwin/i
|
68
|
+
os = :win32
|
69
|
+
impl = :bccwin
|
70
|
+
elsif RUBY_PLATFORM =~ /wince/i
|
71
|
+
os = :win32
|
72
|
+
impl = :wince
|
73
|
+
elsif RUBY_PLATFORM =~ /vms/i
|
74
|
+
os = :vms
|
75
|
+
impl = :vms
|
76
|
+
elsif RUBY_PLATFORM =~ /os2/i
|
77
|
+
os = :os2
|
78
|
+
impl = :os2 # maybe there is some better choice here?
|
79
|
+
else
|
80
|
+
os = :unknown
|
81
|
+
impl = :unknown
|
82
|
+
end
|
83
|
+
|
84
|
+
# whither AIX, SOLARIS, and the other unixen?
|
85
|
+
|
86
|
+
if RUBY_PLATFORM =~ /(i\d86)/i
|
87
|
+
arch = :x86
|
88
|
+
elsif RUBY_PLATFORM =~ /ia64/i
|
89
|
+
arch = :ia64
|
90
|
+
elsif RUBY_PLATFORM =~ /powerpc/i
|
91
|
+
arch = :powerpc
|
92
|
+
elsif RUBY_PLATFORM =~ /alpha/i
|
93
|
+
arch = :alpha
|
94
|
+
else
|
95
|
+
arch = :unknown
|
96
|
+
end
|
97
|
+
|
98
|
+
OS = os
|
99
|
+
IMPL = impl
|
100
|
+
ARCH = arch
|
101
|
+
# What about AMD, Turion, Motorola, etc..?
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
if __FILE__ == $0
|
106
|
+
puts "Platform OS=#{Platform::OS}, impl=#{Platform::IMPL}, arch=#{Platform::ARCH}"
|
107
|
+
end
|