filament 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/filament.rb CHANGED
@@ -20,6 +20,22 @@ require 'filament/artifact'
20
20
  require 'filament/util/filelist2'
21
21
  require 'filament/util/fileutils'
22
22
 
23
+ class Module
24
+ def attr_accessor2(*symbols)
25
+ # attr_writer(*symbols)
26
+ symbols.each do |sym|
27
+ attr_sym = "@#{sym.to_s}".to_sym
28
+ define_method(sym) do |*val|
29
+ if val.empty?
30
+ return instance_variable_get(attr_sym)
31
+ else
32
+ return instance_variable_set(attr_sym, val.first)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+
23
39
  module Filament
24
40
  def log(msg)
25
41
  puts msg if $verbose
@@ -17,6 +17,10 @@ module Filament
17
17
  end
18
18
 
19
19
  class Package
20
+ def target(name, klass, &block)
21
+ klass.new(name, &block)
22
+ end
23
+
20
24
  attr_reader :parent, :name, :realpath, :workspace, :package_resolver, :target_resolver, :build_context
21
25
  alias :pathname :realpath
22
26
 
@@ -183,7 +187,9 @@ module Filament
183
187
  def subpackages(include_disabled = false)
184
188
  return [] unless parent?
185
189
 
186
- children = @realpath.children.reject { |child| !child.directory? }
190
+ children = @realpath.children.reject do |child|
191
+ not child.directory? or child.basename.to_s =~ /^\./
192
+ end
187
193
 
188
194
  children.collect! do |child|
189
195
  subpackage(child.basename.to_s)
@@ -268,7 +274,7 @@ module Filament
268
274
  end
269
275
 
270
276
  def descriptor
271
- return "#{@realpath}/rakefile.rb"
277
+ return "#{@realpath}/package.rb"
272
278
  end
273
279
 
274
280
  def << (target)
@@ -286,7 +292,7 @@ module Filament
286
292
  raise "package descriptor for #{@realpath} does not exist '#{pn}'"
287
293
  end
288
294
 
289
- @execution_context.wrap(pn.read, pn.realpath)
295
+ @execution_context.execute { instance_eval(pn.read, pn.realpath) }
290
296
  end
291
297
 
292
298
  def target_dir(subdir=nil)
@@ -296,8 +302,8 @@ module Filament
296
302
  pn += "#{subdir}/#{$build_dir_prefix}"
297
303
  end
298
304
 
299
- mkdir_p(pn) unless pn.exist?
300
- return pn.realpath
305
+ # mkdir_p(pn) unless pn.exist?
306
+ return pn.to_s
301
307
  end
302
308
 
303
309
  def working_dir
@@ -104,11 +104,10 @@ module Filament
104
104
  return if done?
105
105
  @invoked = true
106
106
 
107
- puts ">>> BUILDING #{uri} (#{package.pathname}, #{self})"
108
-
109
107
  @package.execute do
110
108
  @weak_deps.each {|t| t.invoke}
111
109
  @deps.each {|t| t.invoke}
110
+ puts ">>> BUILDING #{uri} (#{@package.pathname}, #{self})"
112
111
  instance_eval(&@block)
113
112
  end
114
113
  end
@@ -25,4 +25,4 @@ end
25
25
  require 'filament/java/tools/jar'
26
26
  require 'filament/java/tools/execute'
27
27
  require 'filament/java/tools/compile'
28
-
28
+ require 'filament/java/tools/proguard'
@@ -27,8 +27,7 @@ module Filament::Java::Tools
27
27
  sources = fix_paths(@sources).join(' ')
28
28
  c = "#{JAVAC}"
29
29
  c << " -classpath #{classpath}" unless @classpath.empty?
30
- c << " -bootclasspath #{bootclasspath}" \
31
- unless @bootclasspath.empty?
30
+ c << " -bootclasspath #{bootclasspath}" unless @bootclasspath.empty?
32
31
  c << " -source #{@source_version}" unless @source_version.nil?
33
32
  c << " -target #{@target_version}" unless @target_version.nil?
34
33
 
@@ -1,25 +1,23 @@
1
1
  module Filament::Java::Tools
2
2
  class Execute
3
- attr_writer :classpath, :properties, :mainclass, :args
3
+ attr_writer :classpath, :properties, :mainclass, :args, :jar
4
4
 
5
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
6
  @mainclass = mainclass
7
+ @jar = nil
13
8
  @properties = {}
14
9
  @classpath = []
15
10
  @args = []
11
+
12
+ yield self if block_given?
13
+ execute unless @mainclass.nil? and @jar.nil?
16
14
  end
17
15
 
18
16
  def execute
19
17
  c = "#{JAVA} "
20
18
 
21
19
  classpath = join_paths(@classpath)
22
- c << "-cp #{classpath} " unless classpath.nil?
20
+ c << "-cp #{classpath} " unless @classpath.nil? or @classpath.empty?
23
21
 
24
22
  unless @properties.nil?
25
23
  @properties.each do |k,v|
@@ -27,11 +25,13 @@ module Filament::Java::Tools
27
25
  end
28
26
  end
29
27
 
30
- c << @mainclass << " "
28
+ c << "-jar #{@jar} " unless @jar.nil?
29
+
30
+ c << @mainclass << " " unless @mainclass.nil?
31
31
 
32
- c << @args.to_a.join
32
+ c << @args.to_a.join(' ')
33
33
 
34
- sys c
34
+ sys c
35
35
  end
36
36
  end
37
37
  end
@@ -0,0 +1,41 @@
1
+ require 'tempfile'
2
+
3
+ module Filament::Java::Tools
4
+ class << self
5
+ def proguard(injars=nil, outjars=nil, &block)
6
+ Proguard.new(injars, outjars, &block)
7
+ end
8
+ end
9
+
10
+ class Proguard
11
+ def initialize(injars=nil, outjars=nil)
12
+ @options = []
13
+
14
+ self.injars(injars) unless injars.nil?
15
+ self.outjars(outjars) unless outjars.nil?
16
+
17
+ yield self if block_given?
18
+
19
+ p self
20
+ obfuscate
21
+ end
22
+
23
+ def obfuscate
24
+ tmp = Tempfile.open('options.pro')
25
+ @options.each do |option|
26
+ tmp.puts(option)
27
+ end
28
+ tmp.close
29
+
30
+ Execute.new do |e|
31
+ e.jar = ENV['PROGUARD_HOME'] + '/lib/proguard.jar'
32
+ e.args = "@#{tmp.path}"
33
+ end
34
+ end
35
+
36
+ def method_missing(msg, *args)
37
+ option = msg.to_s.gsub(/=/, '')
38
+ @options << "-#{option} #{args}"
39
+ end
40
+ end
41
+ end
@@ -4,19 +4,18 @@ module Filament::JavaME::Mixins
4
4
  module LibraryMixin
5
5
  include Java::Mixins::JavaMixin
6
6
 
7
+ attr_accessor2 :obfuscate
8
+
7
9
  attr_writer :package_deps
8
10
  attr_reader :srcs, :resources, :manifest, :platform, :cldc_version
9
11
 
10
- def jar_path
11
- return "#{output_dir}/#{@name}.jar"
12
- end
13
-
14
12
  def init_library
15
13
  init_java
16
14
  @srcs = FileList2.new
17
15
  @resources = FileList2.new
18
16
  @manifest = nil
19
17
  @package_deps = false
18
+ @obfuscate = false
20
19
  @platform = JavaME::Tools.tags_for($target_platform)
21
20
  @cldc_version = JavaME::Tools.cldc_version_for($target_platform)
22
21
  @bootclasspath = JavaME::Tools.classpath_for($target_platform)
@@ -51,10 +50,17 @@ module Filament::JavaME::Mixins
51
50
  end
52
51
  end
53
52
 
53
+ def jar_path
54
+ return "#{output_dir}/#{@name}.jar"
55
+ end
56
+
54
57
  def define_library(target)
55
58
  compiled_dir = directory(:compiled)
59
+ obfuscated_dir = directory(:obfuscated)
56
60
  preverified_dir = directory(:preverified)
57
61
  package_dir = directory(:package)
62
+ proguard_dir = directory(:proguard)
63
+ proguard_preverified_dir = directory(:proguard_preverified)
58
64
 
59
65
  cp = classpath(target)
60
66
  # prune empty entries from src
@@ -92,7 +98,7 @@ module Filament::JavaME::Mixins
92
98
  end
93
99
 
94
100
  # preverify to the preverified directory
95
- JavaME::Tools.preverify(compiled_dir, preverified_dir) do |j|
101
+ JavaME::Tools::preverify(compiled_dir, preverified_dir) do |j|
96
102
  j.cldc_version = @cldc_version
97
103
  j.classpath = cp + @bootclasspath
98
104
  end
@@ -106,7 +112,7 @@ module Filament::JavaME::Mixins
106
112
  package_files.each do |f|
107
113
  p = Pathname.new(f)
108
114
 
109
- if p.extname == ".jar"
115
+ if p.extname == '.jar'
110
116
  Java::Tools::Jar.extract(f, package_dir)
111
117
  else
112
118
  cp_r_if(f, package_dir) { |p| !(p =~ /\.svn$/) }
@@ -117,14 +123,45 @@ module Filament::JavaME::Mixins
117
123
  exclude_files = FileList.new
118
124
  exclude_files.clear_exclude
119
125
  exclude_files.add("#{package_dir}/META-INF")
120
- exclude_files.add("#{package_dir}/**/.svn")
121
126
 
122
127
  exclude_files.each do |file|
123
128
  rm_rf(file)
124
129
  end
125
130
 
126
- Java::Tools::Jar.new(jar_path, FileList.new(package_dir)) do |jar|
127
- jar.manifest = @manifest
131
+ # obfuscate, if necessary
132
+ if @obfuscate
133
+ Java::Tools::proguard(package_dir, proguard_dir) do |o|
134
+ (@classpath + @bootclasspath).each do |libraryjar|
135
+ o.libraryjars libraryjar
136
+ end
137
+
138
+ target.flattened_deps.each do |dep|
139
+ b = dep[:proguard]
140
+ b.call(o) unless b.nil?
141
+ end
142
+
143
+ o.defaultpackage "''"
144
+ o.dontusemixedcaseclassnames
145
+ o.allowaccessmodification
146
+ o.keep 'public class * extends javax.microedition.midlet.MIDlet'
147
+ end
148
+
149
+ FileList.new("#{proguard_dir}/*").each do |f|
150
+ cp_r_if(f, proguard_preverified_dir) { |p| !(p =~ /\.class$/) }
151
+ end
152
+
153
+ JavaME::Tools::preverify(proguard_dir, proguard_preverified_dir) do |j|
154
+ j.cldc_version = @cldc_version
155
+ j.classpath = cp + @bootclasspath
156
+ end
157
+
158
+ Java::Tools::Jar.new(jar_path, FileList.new(proguard_preverified_dir)) do |jar|
159
+ jar.manifest = @manifest
160
+ end
161
+ else
162
+ Java::Tools::Jar.new(jar_path, FileList.new(package_dir)) do |jar|
163
+ jar.manifest = @manifest
164
+ end
128
165
  end
129
166
  end
130
167
 
@@ -1,22 +1,5 @@
1
1
  require 'filament/javame/mixins/library_mixin'
2
2
 
3
- class Module
4
- def attr_accessor2(*symbols)
5
- # attr_writer(*symbols)
6
- symbols.each do |sym|
7
- attr_sym = "@#{sym.to_s}".to_sym
8
- define_method(sym) do |*val|
9
- if val.empty?
10
- return instance_variable_get(attr_sym)
11
- else
12
- return instance_variable_set(attr_sym, val.first)
13
- end
14
- end
15
- end
16
- end
17
- end
18
-
19
-
20
3
  module Filament::JavaME::Mixins
21
4
  module SuiteMixin
22
5
  include JavaME::Mixins::LibraryMixin
@@ -40,6 +23,7 @@ module Filament::JavaME::Mixins
40
23
  init_library
41
24
  @descriptor_config = Proc.new {}
42
25
  @package_deps = true
26
+ @obfuscate = true # TODO should be based on $build_type
43
27
  @defaultmidlet_class = nil
44
28
  @midlets = []
45
29
 
@@ -63,10 +47,15 @@ module Filament::JavaME::Mixins
63
47
  def define_jad(target)
64
48
  # create a list for imported jad configs
65
49
  configs = []
50
+
51
+ # start with this target
52
+ config = target[:jad_config]
53
+ configs << config unless config.nil?
54
+
66
55
  target.flattened_deps.each do |dep|
67
56
  # ask each dep for its contribution
68
- config = dep[:jad_config]
69
- configs << config unless config.nil?
57
+ config = dep[:jad_config]
58
+ configs << config unless config.nil?
70
59
  end
71
60
 
72
61
  full_config = Proc.new do |d|
@@ -6,6 +6,7 @@ module Filament::JavaME
6
6
 
7
7
  def init
8
8
  init_suite
9
+ @obfuscate = true # TODO should be based on $build_type
9
10
  end
10
11
 
11
12
  def build_artifact
@@ -3,20 +3,9 @@ require 'filament/javame/tools/emulator'
3
3
 
4
4
  module Filament::JavaME::Tools
5
5
  module MppSdk
6
- def self.home
7
- mpp_home_env = ENV['MPP_SDK_HOME']
8
-
9
- return mpp_home_env unless mpp_home_env.nil?
10
-
11
- base_dir = "#{$workspace.realpath}/vendor/applications/mpp-sdk"
12
- version = Pathname.new("#{base_dir}/VERSION").read.chomp
13
-
14
- return "#{base_dir}/#{version}"
15
- end
16
-
17
6
  class MppSdkEmulator < Emulator
18
7
  def run
19
- cd MppSdk::home do |d|
8
+ cd ENV['MPP_SDK_HOME'] do |d|
20
9
  c = "java -jar player.jar #{@jad_path}"
21
10
  sys c
22
11
  end
@@ -27,7 +16,7 @@ module Filament::JavaME::Tools
27
16
  def preverify
28
17
  raise "MppSdkPreverifier only works on darwin" unless darwin?
29
18
 
30
- c = "#{MppSdk::home}/osx/preverify/preverify"
19
+ c = ENV['MPP_SDK_HOME'] + "/osx/preverify/preverify"
31
20
  c << " -classpath #{join_paths(@classpath)}" unless @classpath.empty?
32
21
  c << " -d #{fix_paths(@output_dir)}"
33
22
  c << " -cldc1.0" if @cldc_version == 1.0
@@ -4,19 +4,8 @@ require 'filament/javame/tools/preverifier'
4
4
 
5
5
  module Filament::JavaME::Tools
6
6
  module Wtk
7
- def self.home
8
- wtk_home_env = ENV['WTK_HOME']
9
-
10
- return wtk_home_env unless wtk_home_env.nil?
11
-
12
- wtk_base = "#{$workspace.realpath}/vendor/applications/wtk"
13
-
14
- return "#{wtk_base}/windows/2.3" if windows?
15
- return "#{wtk_base}/linux/2.2"
16
- end
17
-
18
7
  def self.bin(path=nil)
19
- wtk_bin = home + '/bin'
8
+ wtk_bin = ENV['WTK_HOME'] + '/bin'
20
9
  return wtk_bin if path.nil?
21
10
  return to_exec_path("#{wtk_bin}/#{path}")
22
11
  end
@@ -57,4 +46,4 @@ module Filament::JavaME::Tools
57
46
  end
58
47
  end
59
48
  end
60
- end
49
+ end
@@ -38,6 +38,5 @@ module Filament::JavaME::Tools
38
38
 
39
39
  preverify unless @classes.nil? or @output_dir.nil?
40
40
  end
41
-
42
41
  end
43
42
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: filament
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.0
7
- date: 2006-03-14 00:00:00 -05:00
6
+ version: 0.1.1
7
+ date: 2006-03-16 00:00:00 -05:00
8
8
  summary: A flexible dependency-based build platform based on Rake
9
9
  require_paths:
10
10
  - lib
@@ -81,6 +81,7 @@ files:
81
81
  - plugins/01java/lib/filament/java/tools/compile.rb
82
82
  - plugins/01java/lib/filament/java/tools/execute.rb
83
83
  - plugins/01java/lib/filament/java/tools/jar.rb
84
+ - plugins/01java/lib/filament/java/tools/proguard.rb
84
85
  - plugins/02javame/lib
85
86
  - plugins/02javame/lib/filament
86
87
  - plugins/02javame/lib/init.rb