filament 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/README +7 -0
  2. data/bin/filament +11 -0
  3. data/bin/filament-dbg +3 -0
  4. data/bin/filament-opt +3 -0
  5. data/bin/filament-test +3 -0
  6. data/bin/init +4 -0
  7. data/lib/filament/artifact.rb +49 -0
  8. data/lib/filament/context.rb +46 -0
  9. data/lib/filament/package/svn.rb +123 -0
  10. data/lib/filament/package.rb +326 -0
  11. data/lib/filament/platform.rb +79 -0
  12. data/lib/filament/plugins.rb +32 -0
  13. data/lib/filament/resolver.rb +91 -0
  14. data/lib/filament/target.rb +117 -0
  15. data/lib/filament/util/filelist2.rb +39 -0
  16. data/lib/filament/util/fileutils.rb +51 -0
  17. data/lib/filament/util/lazy_list.rb +74 -0
  18. data/lib/filament/workspace.rb +57 -0
  19. data/lib/filament.rb +199 -0
  20. data/lib/inflector.rb +124 -0
  21. data/lib/svn.rb +78 -0
  22. data/plugins/00util/lib/init.rb +47 -0
  23. data/plugins/01java/lib/filament/java/mixins/java_mixin.rb +19 -0
  24. data/plugins/01java/lib/filament/java/tools/compile.rb +41 -0
  25. data/plugins/01java/lib/filament/java/tools/execute.rb +37 -0
  26. data/plugins/01java/lib/filament/java/tools/jar.rb +59 -0
  27. data/plugins/01java/lib/filament/java/tools.rb +28 -0
  28. data/plugins/01java/lib/init.rb +1 -0
  29. data/plugins/02javame/lib/filament/javame/library.rb +16 -0
  30. data/plugins/02javame/lib/filament/javame/mixins/library_mixin.rb +144 -0
  31. data/plugins/02javame/lib/filament/javame/mixins/suite_mixin.rb +125 -0
  32. data/plugins/02javame/lib/filament/javame/platform.rb +105 -0
  33. data/plugins/02javame/lib/filament/javame/suite.rb +16 -0
  34. data/plugins/02javame/lib/filament/javame/tasks.rb +6 -0
  35. data/plugins/02javame/lib/filament/javame/tools/descriptor.rb +146 -0
  36. data/plugins/02javame/lib/filament/javame/tools/emulator.rb +36 -0
  37. data/plugins/02javame/lib/filament/javame/tools/external/mpp_sdk.rb +39 -0
  38. data/plugins/02javame/lib/filament/javame/tools/external/wtk.rb +60 -0
  39. data/plugins/02javame/lib/filament/javame/tools/preverifier.rb +43 -0
  40. data/plugins/02javame/lib/filament/javame/tools.rb +8 -0
  41. data/plugins/02javame/lib/init.rb +27 -0
  42. data/plugins/05push/lib/bluetooth.rb +66 -0
  43. data/plugins/05push/lib/filament/push/conduits/bluetooth_conduit.rb +25 -0
  44. data/plugins/05push/lib/filament/push/conduits/filter_conduit.rb +20 -0
  45. data/plugins/05push/lib/filament/push/conduits/scp_conduit.rb +35 -0
  46. data/plugins/05push/lib/filament/push.rb +21 -0
  47. data/plugins/05push/lib/init.rb +29 -0
  48. data/tests/build/artifact_name_test.rb +85 -0
  49. data/tests/build/artifact_test.rb +23 -0
  50. data/tests/gen/java/block_test.rb +42 -0
  51. data/tests/gen/java/callable_test.rb +23 -0
  52. data/tests/gen/java/method_test.rb +25 -0
  53. data/tests/gen/java/statement_test.rb +16 -0
  54. data/tests/java/tools_test.rb +8 -0
  55. data/tests/platform_test.rb +25 -0
  56. metadata +135 -0
data/lib/inflector.rb ADDED
@@ -0,0 +1,124 @@
1
+ # The Inflector transforms words from singular to plural, class names to table names, modularized class names to ones without,
2
+ # and class names to foreign keys.
3
+ module Inflector
4
+ extend self
5
+
6
+ def pluralize(word)
7
+ result = word.to_s.dup
8
+
9
+ if uncountable_words.include?(result.downcase)
10
+ result
11
+ else
12
+ plural_rules.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
13
+ result
14
+ end
15
+ end
16
+
17
+ def singularize(word)
18
+ result = word.to_s.dup
19
+
20
+ if uncountable_words.include?(result.downcase)
21
+ result
22
+ else
23
+ singular_rules.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
24
+ result
25
+ end
26
+ end
27
+
28
+ def camelize(lower_case_and_underscored_word)
29
+ lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
30
+ end
31
+
32
+ def underscore(camel_cased_word)
33
+ camel_cased_word.to_s.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z])/,'\1_\2').gsub(/([a-z\d])([A-Z])/,'\1_\2').downcase
34
+ end
35
+
36
+ def humanize(lower_case_and_underscored_word)
37
+ lower_case_and_underscored_word.to_s.gsub(/_/, " ").capitalize
38
+ end
39
+
40
+ def demodulize(class_name_in_module)
41
+ class_name_in_module.to_s.gsub(/^.*::/, '')
42
+ end
43
+
44
+ def tableize(class_name)
45
+ pluralize(underscore(class_name))
46
+ end
47
+
48
+ def classify(table_name)
49
+ camelize(singularize(table_name))
50
+ end
51
+
52
+ def foreign_key(class_name, separate_class_name_and_id_with_underscore = true)
53
+ Inflector.underscore(Inflector.demodulize(class_name)) +
54
+ (separate_class_name_and_id_with_underscore ? "_id" : "id")
55
+ end
56
+
57
+ def constantize(camel_cased_word)
58
+ camel_cased_word.split("::").inject(Object) do |final_type, part|
59
+ final_type = final_type.const_get(part)
60
+ end
61
+ end
62
+
63
+ private
64
+ def uncountable_words #:doc
65
+ %w( equipment information rice money species series fish )
66
+ end
67
+
68
+ def plural_rules #:doc:
69
+ [
70
+ [/^(ox)$/i, '\1\2en'], # ox
71
+ [/([m|l])ouse$/i, '\1ice'], # mouse, louse
72
+ [/(matr|vert)ix|ex$/i, '\1ices'], # matrix, vertex, index
73
+ [/(x|ch|ss|sh)$/i, '\1es'], # search, switch, fix, box, process, address
74
+ [/([^aeiouy]|qu)ies$/i, '\1y'],
75
+ [/([^aeiouy]|qu)y$/i, '\1ies'], # query, ability, agency
76
+ [/(hive)$/i, '\1s'], # archive, hive
77
+ [/(?:([^f])fe|([lr])f)$/i, '\1\2ves'], # half, safe, wife
78
+ [/sis$/i, 'ses'], # basis, diagnosis
79
+ [/([ti])um$/i, '\1a'], # datum, medium
80
+ [/(p)erson$/i, '\1eople'], # person, salesperson
81
+ [/(m)an$/i, '\1en'], # man, woman, spokesman
82
+ [/(c)hild$/i, '\1hildren'], # child
83
+ [/(buffal|tomat)o$/i, '\1\2oes'], # buffalo, tomato
84
+ [/(bu)s$/i, '\1\2ses'], # bus
85
+ [/(alias)/i, '\1es'], # alias
86
+ [/(octop|vir)us$/i, '\1i'], # octopus, virus - virus has no defined plural (according to Latin/dictionary.com), but viri is better than viruses/viruss
87
+ [/(ax|cri|test)is$/i, '\1es'], # axis, crisis
88
+ [/s$/i, 's'], # no change (compatibility)
89
+ [/$/, 's']
90
+ ]
91
+ end
92
+
93
+ def singular_rules #:doc:
94
+ [
95
+ [/(matr)ices$/i, '\1ix'],
96
+ [/(vert)ices$/i, '\1ex'],
97
+ [/^(ox)en/i, '\1'],
98
+ [/(alias)es$/i, '\1'],
99
+ [/([octop|vir])i$/i, '\1us'],
100
+ [/(cris|ax|test)es$/i, '\1is'],
101
+ [/(shoe)s$/i, '\1'],
102
+ [/(o)es$/i, '\1'],
103
+ [/(bus)es$/i, '\1'],
104
+ [/([m|l])ice$/i, '\1ouse'],
105
+ [/(x|ch|ss|sh)es$/i, '\1'],
106
+ [/(m)ovies$/i, '\1\2ovie'],
107
+ [/(s)eries$/i, '\1\2eries'],
108
+ [/([^aeiouy]|qu)ies$/i, '\1y'],
109
+ [/([lr])ves$/i, '\1f'],
110
+ [/(tive)s$/i, '\1'],
111
+ [/(hive)s$/i, '\1'],
112
+ [/([^f])ves$/i, '\1fe'],
113
+ [/(^analy)ses$/i, '\1sis'],
114
+ [/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i, '\1\2sis'],
115
+ [/([ti])a$/i, '\1um'],
116
+ [/(p)eople$/i, '\1\2erson'],
117
+ [/(m)en$/i, '\1an'],
118
+ [/(s)tatus$/i, '\1\2tatus'],
119
+ [/(c)hildren$/i, '\1\2hild'],
120
+ [/(n)ews$/i, '\1\2ews'],
121
+ [/s$/i, '']
122
+ ]
123
+ end
124
+ end
data/lib/svn.rb ADDED
@@ -0,0 +1,78 @@
1
+ require 'yaml'
2
+ require 'rubygems'
3
+ require 'memoize'
4
+
5
+ class SVN
6
+ include Memoize
7
+
8
+ attr_reader :uri
9
+
10
+ def initialize(uri)
11
+ @uri = uri.gsub(/\/$/,'')
12
+
13
+ [:info, 'valid?'.to_sym, :ls].each do |m|
14
+ memoize(m)
15
+ end
16
+ end
17
+
18
+ def valid?
19
+ return system("svn ls #{@uri} &> /dev/null")
20
+ end
21
+
22
+ def tag
23
+ return @uri.match(/(.*)(\/tags)(\/[.^\/]*$)/)[1]
24
+ end
25
+
26
+ def tag?
27
+ return !tag.nil?
28
+ end
29
+
30
+ def branch
31
+ return @uri.match(/(.*)(\/branches)(\/[.^\/]*$)/)[1]
32
+ end
33
+
34
+ def branch?
35
+ return !branch.nil?
36
+ end
37
+
38
+ def trunk?
39
+ return !@uri.match(/(.*)(\/trunk$)/).nil?
40
+ end
41
+
42
+ def info
43
+ info_p = IO.popen("svn info #{@uri}")
44
+ return YAML.load(info_p)
45
+ end
46
+
47
+ def ls
48
+ return IO.popen("svn ls #{@uri}").readlines.collect do |s|
49
+ s.chomp
50
+ end
51
+ end
52
+
53
+ def root
54
+ return info['Repository Root']
55
+ end
56
+
57
+ def revision
58
+ return info['Revision']
59
+ end
60
+
61
+ def name
62
+ return info['Name']
63
+ end
64
+
65
+ def type
66
+ return info['Node Kind'].to_sym
67
+ end
68
+
69
+ def path
70
+ return @uri.split("#{root}/").last
71
+ end
72
+
73
+ def children
74
+ ls.collect do |child|
75
+ SVN.new("#{@uri}/#{child}")
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,47 @@
1
+ class Filament::Util
2
+ package_actions = {
3
+ :list => Proc.new { |packages|
4
+ packages.each do |package|
5
+ package.list
6
+ end
7
+ },
8
+ :update => Proc.new { |packages|
9
+ packages.each do |package|
10
+ package.update
11
+ end
12
+ },
13
+ :status => Proc.new { |packages|
14
+ packages.each do |package|
15
+ package.status
16
+ end
17
+ },
18
+ :commit => Proc.new { |packages|
19
+ packages.each do |package|
20
+ package.commit
21
+ end
22
+ },
23
+ #Display the targets and dependencies, then exit.
24
+ :targets => Proc.new { |packages|
25
+ packages.each do |package|
26
+ puts " #{package.full_name}"
27
+ package.targets.each do |target|
28
+ puts " #{target.uri}"
29
+ end
30
+ end
31
+ }
32
+ }
33
+
34
+ target_actions = {
35
+ :prereqs => Proc.new { |targets|
36
+ targets.each do |target|
37
+ puts " #{target.uri}"
38
+ target.deps.each do |dep|
39
+ puts " #{dep.uri}"
40
+ end
41
+ end
42
+ }
43
+ }
44
+
45
+ Application::PACKAGE_ACTIONS.merge!(package_actions)
46
+ Application::TARGET_ACTIONS.merge!(target_actions)
47
+ end
@@ -0,0 +1,19 @@
1
+ module Filament::Java::Mixins
2
+ module JavaMixin
3
+ def init_java
4
+ end
5
+
6
+ def classpath(target)
7
+ cp = @classpath
8
+ all_deps = TargetList.new
9
+ all_deps << target.flattened_deps
10
+ all_deps << target.weak_deps
11
+ all_deps.each do |d|
12
+ jar = d[:jar]
13
+ # only add the jar if this dependecy has one
14
+ cp << jar unless jar.nil?
15
+ end
16
+ return cp
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,41 @@
1
+ module Filament::Java::Tools
2
+ class Compile
3
+ attr_writer :sources, :output_dir, :source_version, :target_version,
4
+ :classpath, :bootclasspath
5
+
6
+ def initialize(sources=[], output_dir=nil)
7
+ init(sources, output_dir)
8
+ yield self if block_given?
9
+ compile unless @sources.empty? or @output_dir.nil?
10
+ end
11
+
12
+ # loads initial, default values
13
+ def init(sources, output_dir)
14
+ @sources = sources
15
+ @output_dir = output_dir
16
+ @bootclasspath = []
17
+ @classpath = []
18
+ @source_version = nil
19
+ @target_version = nil
20
+ end
21
+
22
+ # executes compile
23
+ def compile
24
+ classpath = join_paths(@classpath)
25
+ bootclasspath = join_paths(@bootclasspath)
26
+ output_dir = fix_paths(@output_dir)
27
+ sources = fix_paths(@sources).join(' ')
28
+ c = "#{JAVAC}"
29
+ c << " -classpath #{classpath}" unless @classpath.empty?
30
+ c << " -bootclasspath #{bootclasspath}" \
31
+ unless @bootclasspath.empty?
32
+ c << " -source #{@source_version}" unless @source_version.nil?
33
+ c << " -target #{@target_version}" unless @target_version.nil?
34
+
35
+ c << " -d #{output_dir}"
36
+ c << " #{sources}"
37
+
38
+ sys c
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,37 @@
1
+ module Filament::Java::Tools
2
+ class Execute
3
+ attr_writer :classpath, :properties, :mainclass, :args
4
+
5
+ def initialize(mainclass=nil)
6
+ init(mainclass)
7
+ yield self if block_given?
8
+ execute unless @mainclass.nil?
9
+ end
10
+
11
+ def init(mainclass)
12
+ @mainclass = mainclass
13
+ @properties = {}
14
+ @classpath = []
15
+ @args = []
16
+ end
17
+
18
+ def execute
19
+ c = "#{JAVA} "
20
+
21
+ classpath = join_paths(@classpath)
22
+ c << "-cp #{classpath} " unless classpath.nil?
23
+
24
+ unless @properties.nil?
25
+ @properties.each do |k,v|
26
+ c << "-D#{k.to_s}=#{v.to_s} "
27
+ end
28
+ end
29
+
30
+ c << @mainclass << " "
31
+
32
+ c << @args.to_a.join
33
+
34
+ sys c
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,59 @@
1
+ module Filament::Java::Tools
2
+ class Jar
3
+ attr_writer :jar_file, :base_dir, :manifest, :index, :update
4
+ attr_accessor :package_files
5
+
6
+ def initialize(jar_file=nil, base_dir=nil)
7
+ @jar_file = jar_file
8
+ @base_dir = base_dir
9
+ @package_files = []
10
+ @manifest = nil
11
+ @index = false
12
+ @update = false
13
+
14
+ yield self if block_given?
15
+
16
+ raise "jar_file cannot be nil." if @jar_file.nil?
17
+
18
+ jar
19
+ end
20
+
21
+ def jar
22
+ c = "#{JAR} "
23
+ c << 'v' if $verbose
24
+ c << 'f'
25
+ if @update
26
+ c << 'u'
27
+ else
28
+ c << 'c'
29
+ end
30
+ c << 'm' unless @manifest.nil?
31
+ c << " #{fix_paths(@jar_file)}"
32
+ c << " #{fix_paths(@manifest)}" unless @manifest.nil? or @manifest.empty?
33
+ c << " -C #{fix_paths(@base_dir)} ." unless @base_dir.nil?
34
+ c << " #{fix_paths(@package_files)}" unless @package_files.empty?
35
+
36
+ sys c
37
+
38
+ if @index
39
+ c = "#{JAR} i #{fix_paths(@jar_file)}"
40
+ sys c
41
+ end
42
+ end
43
+
44
+ def self.extract(jar_file, output_dir)
45
+ cd output_dir do |dir|
46
+ if windows?
47
+ # using jar is too slow
48
+ c = "#{JAR} xf #{fix_paths(jar_file)}"
49
+ sys c
50
+ else
51
+ c = 'unzip '
52
+ c << '-q ' unless $verbose
53
+ c << "-o #{fix_paths(jar_file)}"
54
+ sys c
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,28 @@
1
+ require 'filament/platform'
2
+
3
+ module Filament
4
+ module Java
5
+ module Tools
6
+ def self.bin(path=nil)
7
+ java_home_env = ENV['JAVA_HOME']
8
+ unless java_home_env.nil?
9
+ java_bin = "#{java_home_env}/bin"
10
+ return java_bin if path.nil?
11
+ return Filament::Platform.to_exec_path("#{java_bin}/#{path}")
12
+ else
13
+ # assume it's in the path
14
+ return path
15
+ end
16
+ end
17
+
18
+ JAVAC = Tools.bin('javac')
19
+ JAVA = Tools.bin('java')
20
+ JAR = Tools.bin('jar')
21
+ end
22
+ end
23
+ end
24
+
25
+ require 'filament/java/tools/jar'
26
+ require 'filament/java/tools/execute'
27
+ require 'filament/java/tools/compile'
28
+
@@ -0,0 +1 @@
1
+ require 'filament/java/tools'
@@ -0,0 +1,16 @@
1
+ require 'filament/javame/mixins/library_mixin'
2
+
3
+ module Filament::JavaME
4
+ class Library < Filament::Artifact
5
+ include JavaME::Mixins::LibraryMixin
6
+
7
+ def init
8
+ init_library
9
+ end
10
+
11
+ def build_artifact
12
+ define_library(self)
13
+ invoke_tasks
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,144 @@
1
+ require 'filament/java/mixins/java_mixin'
2
+
3
+ module Filament::JavaME::Mixins
4
+ module LibraryMixin
5
+ include Java::Mixins::JavaMixin
6
+
7
+ attr_writer :package_deps
8
+ attr_reader :srcs, :resources, :manifest, :platform, :cldc_version
9
+
10
+ def jar_path
11
+ return "#{output_dir}/#{@name}.jar"
12
+ end
13
+
14
+ def init_library
15
+ init_java
16
+ @srcs = FileList2.new
17
+ @resources = FileList2.new
18
+ @manifest = nil
19
+ @package_deps = false
20
+ @platform = JavaME::Tools.tags_for($target_platform)
21
+ @cldc_version = JavaME::Tools.cldc_version_for($target_platform)
22
+ @bootclasspath = JavaME::Tools.classpath_for($target_platform)
23
+ @classpath = []
24
+
25
+ @append_entries = {}
26
+ @custom_entries = {}
27
+
28
+ @jad_config = Proc.new do |d|
29
+ d.append_entries(@append_entries)
30
+ d.custom_entries(@custom_entries)
31
+ end
32
+ end
33
+
34
+ def custom_entries(h)
35
+ h.keys.each do |key|
36
+ @custom_entries[key] = h[key]
37
+ end
38
+ end
39
+
40
+ def append_entries(h)
41
+ h.keys.each do |key|
42
+ @append_entries[key] ||= []
43
+
44
+ entry = h[key]
45
+
46
+ if entry.is_a?(Array)
47
+ @append_entries[key] += entry
48
+ else
49
+ @append_entries[key] << entry
50
+ end
51
+ end
52
+ end
53
+
54
+ def define_library(target)
55
+ compiled_dir = directory(:compiled)
56
+ preverified_dir = directory(:preverified)
57
+ package_dir = directory(:package)
58
+
59
+ cp = classpath(target)
60
+ # prune empty entries from src
61
+ @srcs.compact!
62
+
63
+ if @package_deps
64
+ target.flattened_deps.each do |dep|
65
+ j = dep[:jar]
66
+ unless j.nil?
67
+ @resources.include(j)
68
+ end
69
+ end
70
+ end
71
+
72
+ jar_deps = @srcs + @resources + directories + cp + @bootclasspath
73
+
74
+ desc = target.package.descriptor
75
+ if File.exist?(desc)
76
+ jar_deps << desc
77
+ end
78
+
79
+ unless @manifest.nil?
80
+ jar_deps += @manifest
81
+ end
82
+
83
+ jar_task = file(jar_path => jar_deps) do |t|
84
+ package_files = FileList.new
85
+ unless @srcs.empty?
86
+ # compile to the unverified directory
87
+ Java::Tools::Compile.new(@srcs, compiled_dir) do |c|
88
+ c.source_version = 1.2
89
+ c.target_version = 1.1
90
+ c.classpath = cp
91
+ c.bootclasspath = @bootclasspath
92
+ end
93
+
94
+ # preverify to the preverified directory
95
+ JavaME::Tools.preverify(compiled_dir, preverified_dir) do |j|
96
+ j.cldc_version = @cldc_version
97
+ j.classpath = cp + @bootclasspath
98
+ end
99
+
100
+ # package up verified classes
101
+ package_files.add("#{preverified_dir}/*")
102
+ end
103
+
104
+ # package up resources
105
+ package_files.add(*@resources) unless @resources.empty?
106
+ package_files.each do |f|
107
+ p = Pathname.new(f)
108
+
109
+ if p.extname == ".jar"
110
+ Java::Tools::Jar.extract(f, package_dir)
111
+ else
112
+ cp_r_if(f, package_dir) { |p| !(p =~ /\.svn$/) }
113
+ end
114
+ end
115
+
116
+ # remove svn files we may have copied
117
+ exclude_files = FileList.new
118
+ exclude_files.clear_exclude
119
+ exclude_files.add("#{package_dir}/META-INF")
120
+ exclude_files.add("#{package_dir}/**/.svn")
121
+
122
+ exclude_files.each do |file|
123
+ rm_rf(file)
124
+ end
125
+
126
+ Java::Tools::Jar.new(jar_path, FileList.new(package_dir)) do |jar|
127
+ jar.manifest = @manifest
128
+ end
129
+ end
130
+
131
+ target.output :tag => [:default, :jar],
132
+ :output => jar_path,
133
+ :deployable => true
134
+
135
+ target.output :tag => :jad_config,
136
+ :output => @jad_config,
137
+ :deployable => false
138
+
139
+ @tasks << jar_task
140
+
141
+ return jar_task
142
+ end
143
+ end
144
+ end