iconara-java_tools 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,12 +1,11 @@
1
- h1. Java Tools
1
+ = Java Tools
2
2
 
3
3
  Ruby wrappers for javac and jar that don't just exec.
4
4
 
5
- Ant is a nice tool for writing Java build scripts, but Rake is nicer. The only thing missing from Rake is a way to run javac and jar, and although it's easy to run these with exec you have to wait for the JVM to start for each invocation. In combination with JRuby this gem lets you run @javac@ and @jar@ in your Rake scripts without exec'ing, by using the programmatic interface to Javac and Java's ZIP file creation capabilities.
5
+ Ant is a nice tool for writing Java build scripts, but Rake is nicer. The only thing missing from Rake is a way to run javac and jar, and although it's easy to run these with exec you have to wait for the JVM to start for each invocation. In combination with JRuby this gem lets you run +javac+ and +jar+ in your Rake scripts without exec'ing, by using the programmatic interface to Javac and Java's ZIP file creation capabilities.
6
6
 
7
- h2. Example
7
+ == Example
8
8
 
9
- <pre><code>
10
9
  require 'java_tools'
11
10
 
12
11
 
@@ -17,35 +16,32 @@ h2. Example
17
16
  task :dist => :compile do
18
17
  jar 'dist/my-awsome-app.jar', FileList['build/**/*.class'], :base_dir => 'build'
19
18
  end
20
- </code></pre>
21
19
 
22
- There are more examples in the @examples@ directory.
20
+ There are more examples in the +examples+ directory.
23
21
 
24
- h2. Command style
22
+ == Command style
25
23
 
26
24
  Many Rake add-ons look like this:
27
25
 
28
- <pre><code>
29
26
  Spec::Rake::SpecTask.new(:spec) do |spec|
30
27
  spec.spec_opts << '--options' << 'spec/spec.opts'
31
28
  # ...
32
29
  end
33
- </code></pre>
34
30
 
35
- I think it ruins the DSL illusion, and I prefer to write tasks that contain commands, more like how @cp@, @rm@ and @sh@ work in Rake.
31
+ I think it ruins the DSL illusion, and I prefer to write tasks that contain commands, more like how +cp+, +rm+ and +sh+ work in Rake.
36
32
 
37
- h2. Nailgun
33
+ == Nailgun
38
34
 
39
35
  Don't forget that since JRuby 1.3 you can minimize the startup by using the built-in Nailgun support. Run
40
36
 
41
- @jruby --ng-server &@
37
+ jruby --ng-server &
42
38
 
43
39
  to start a Nailgun server and then run Rake with this command
44
40
 
45
- @jruby --ng -S rake@
41
+ jruby --ng -S rake
46
42
 
47
- you'll notice that the startup time decreases significantly the second time you run it. To avoid having to write all that every time you want to build create an alias, I call mine @jrk@.
43
+ you'll notice that the startup time decreases significantly the second time you run it. To avoid having to write all that every time you want to build create an alias, I call mine +jrk+.
48
44
 
49
- h2. Upcomming
45
+ == Upcomming
50
46
 
51
- Even though the whole rationale behind Java Tools is to avoid exec it wouldn't be much effort to support non-JRuby runtimes since at least the @javac@ command needs to build the command string anyway.
47
+ Even though the whole rationale behind Java Tools is to avoid exec it wouldn't be much effort to support non-JRuby runtimes since at least the +javac+ command needs to build the command string anyway.
@@ -2,18 +2,18 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{java_tools}
5
- s.version = "0.1.1"
5
+ s.version = "0.1.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Theo Hultberg"]
9
- s.date = %q{2009-08-05}
9
+ s.date = %q{2009-08-06}
10
10
  s.description = %q{Ant is a nice tool for writing Java build scripts, but Rake is nicer. The only thing missing from Rake is a way to run javac and jar, and although it's easy to run these as shell scripts you have to wait for the JVM to start. In combination with JRuby this gem lets you run javac and jar in your Rake scripts without exec'ing.}
11
11
  s.email = %q{theo@iconara.net}
12
12
  s.extra_rdoc_files = [
13
- "README.textile"
13
+ "README.rdoc"
14
14
  ]
15
15
  s.files = [
16
- "README.textile",
16
+ "README.rdoc",
17
17
  "Rakefile",
18
18
  "VERSION",
19
19
  "examples/compile/Rakefile",
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
31
31
  "spec/spec.opts",
32
32
  "spec/spec_helper.rb",
33
33
  "tasks/gem.rake",
34
+ "tasks/rdoc.rake",
34
35
  "tasks/spec.rake"
35
36
  ]
36
37
  s.homepage = %q{http://github.com/iconara/java_tools}
@@ -5,9 +5,9 @@ require File.expand_path(File.dirname(__FILE__)) + '/java_tools/javac'
5
5
  require File.expand_path(File.dirname(__FILE__)) + '/java_tools/jar'
6
6
 
7
7
 
8
- module JavaTools
8
+ module JavaTools # :nodoc:
9
9
 
10
- def self.version
10
+ def self.version # :nodoc:
11
11
  version_file = File.join(File.dirname(__FILE__), '..', 'VERSION')
12
12
 
13
13
  File.open(version_file) do |f|
@@ -15,7 +15,7 @@ module JavaTools
15
15
  end
16
16
  end
17
17
 
18
- def self.configure_command( command, options )
18
+ def self.configure_command( command, options ) # :nodoc:
19
19
  options.each do |option, value|
20
20
  setter_name = "#{option}="
21
21
 
@@ -29,6 +29,31 @@ module JavaTools
29
29
 
30
30
  end
31
31
 
32
+ # Javac can be run in either command or yield mode: command mode
33
+ # looks roughly like this:
34
+ #
35
+ # javac [file1, file2], :destination => 'build'
36
+ #
37
+ # and yield mode like this:
38
+ #
39
+ # javac(file1, file2) do |conf|
40
+ # conf.destination = 'build'
41
+ # end
42
+ #
43
+ # In command mode you pass a hash with the configuration directives
44
+ # (listed below) and in yield mode an object is passed to the block,
45
+ # and the configuration directives should be set on that.
46
+ #
47
+ # The possible configuration directives are:
48
+ # * source_path
49
+ # * destination
50
+ # * class_path
51
+ # * deprecation_warnings
52
+ # * warnings
53
+ # * encoding
54
+ # * verbose
55
+ #
56
+ # The directives are the same as the properties of JavaTools::Javac.
32
57
  def javac( source_files, options = nil )
33
58
  obj = JavaTools::Javac.new(*source_files)
34
59
 
@@ -41,6 +66,27 @@ def javac( source_files, options = nil )
41
66
  obj.execute
42
67
  end
43
68
 
69
+ # Jar can be run in either command or yield mode: command mode
70
+ # looks roughly like this:
71
+ #
72
+ # jar 'output.jar', [file1, file2], :base_dir => 'build'
73
+ #
74
+ # and yield mode like this:
75
+ #
76
+ # jar('output.jar', [file1, file2]) do |conf|
77
+ # conf.base_dir = 'build'
78
+ # end
79
+ #
80
+ # In command mode you pass a hash with the configuration directives
81
+ # (listed below) and in yield mode an object is passed to the block,
82
+ # and the configuration directives should be set on that.
83
+ #
84
+ # The possible configuration directives are:
85
+ # * base_dir
86
+ # * compression
87
+ # * verbose
88
+ #
89
+ # The directives are the same as the properties of JavaTools::Javac.
44
90
  def jar( output, files = nil, options = nil )
45
91
  base_dir = nil
46
92
 
@@ -10,16 +10,26 @@ module JavaTools
10
10
 
11
11
  class Jar
12
12
 
13
- attr_accessor :base_dir, # string
14
- :compression, # number (0-9)
15
- :verbose # boolean
16
-
13
+ # The path to the directory which should be considered the root of the archive.
14
+ #
15
+ # If you set +base_dir+ to "build" and add the file "build/Main.class", that file
16
+ # will be put in the archive as "Main.class".
17
+ attr_accessor :base_dir
18
+
19
+ # The ZIP compression rate from 0 (no compression) to 9 (maximal compression)
20
+ attr_accessor :compression
21
+
22
+ # Whether or not to print the equivalent command string to the output (see #execute)
23
+ attr_accessor :verbose
24
+
25
+ # The path to the JAR file that will be generated
17
26
  attr_reader :output
18
-
27
+
28
+
19
29
  def initialize( output, files = nil, base_dir = nil )
20
30
  @output = output
21
31
  @base_dir = base_dir
22
- @entries = { } # archive_path => JarEntry
32
+ @entries = { } # archive_path => IO
23
33
  @verbose = false
24
34
  @compression = 1
25
35
 
@@ -28,6 +38,16 @@ module JavaTools
28
38
  add_files(files) unless files.nil? || files.empty?
29
39
  end
30
40
 
41
+ # Sets the attributes that will end up in the JAR manifest.
42
+ #
43
+ # Attribute names are treated case insensitively, so setting
44
+ # both Main-Class and main-class will result in only one being used.
45
+ #
46
+ # Will raise an error on malformed attribute names (must start with a
47
+ # letter or digit and contain only letter, digits, dashes and underscores).
48
+ #
49
+ # The manifest you set will be merged with a set of default attributes (but
50
+ # yours will override).
31
51
  def manifest=( manifest_hash )
32
52
  @manifest = default_manifest
33
53
 
@@ -40,12 +60,14 @@ module JavaTools
40
60
  end
41
61
  end
42
62
 
43
- def remove_manifest_attribute( name )
63
+ # Removes a manifest attribute, the comparison is case insensitive.
64
+ def remove_manifest_attribute( name ) # :nodoc:
44
65
  @manifest.delete_if do |key, value|
45
66
  key.downcase == name.downcase
46
67
  end
47
68
  end
48
69
 
70
+ # Convenience method for setting the Main-Class manifest attribute
49
71
  def main_class=( class_name )
50
72
  if class_name
51
73
  @manifest['Main-Class'] = class_name
@@ -54,23 +76,25 @@ module JavaTools
54
76
  end
55
77
  end
56
78
 
57
- def default_manifest
79
+ def default_manifest # :nodoc:
58
80
  {
59
81
  'Built-By' => "JavaTools v#{JavaTools::version}",
60
82
  'Manifest-Version' => '1.0'
61
83
  }
62
84
  end
63
85
 
64
- def manifest_string
86
+ def manifest_string # :nodoc:
65
87
  @manifest.keys.inject("") do |str, key|
66
88
  str + "#{key}: #{@manifest[key]}\n"
67
89
  end
68
90
  end
69
91
 
70
- def commit_manifest
92
+ def commit_manifest # :nodoc:
71
93
  add_blob(manifest_string, 'META-INF/MANIFEST.MF')
72
94
  end
73
95
 
96
+ # Adds the file at +file_path+ to the archive and put it at +archive_path+
97
+ # (the same as +file_path+ by default) inside the archive.
74
98
  def add_file( file_path, archive_path = nil )
75
99
  archive_path = find_archive_path(file_path, @base_dir) unless archive_path
76
100
 
@@ -83,24 +107,30 @@ module JavaTools
83
107
  @entries[archive_path || file_path] = File.new(file_path)
84
108
  end
85
109
 
110
+ # Adds a list of files to the archive, at paths relative to +base_dir+
111
+ # (defaults to #base_dir) inside the archive.
86
112
  def add_files( files, base_dir = nil )
87
113
  files.each do |file|
88
114
  add_file(file, find_archive_path(file, base_dir || @base_dir))
89
115
  end
90
116
  end
91
117
 
118
+ # Adds a string to the archive at +archive_path+.
92
119
  def add_blob( str, archive_path )
93
120
  @entries[archive_path] = StringIO.new(str)
94
121
  end
95
122
 
96
- def remove_entry( archive_path )
123
+ def remove_entry( archive_path ) # :nodoc:
97
124
  @entries.delete(archive_path)
98
125
  end
99
126
 
100
- def entries
127
+ def entries # :nodoc:
101
128
  @entries.keys
102
129
  end
103
130
 
131
+ # Creates the archive. If #verbose is true the equivalent command string
132
+ # for the +jar+ command will be printed to the stream passed as +io+ (or
133
+ # +$stdout+ by default)
104
134
  def execute( io = $stderr )
105
135
  raise "Output not set" unless @output
106
136
 
@@ -112,7 +142,7 @@ module JavaTools
112
142
  create_zipfile
113
143
  end
114
144
 
115
- def create_zipfile
145
+ def create_zipfile # :nodoc:
116
146
  buffer_size = 65536
117
147
 
118
148
  zipstream = ZipOutputStream.new(FileOutputStream.new(@output))
@@ -130,7 +160,7 @@ module JavaTools
130
160
  zipstream.close
131
161
  end
132
162
 
133
- def find_archive_path( path, base_dir )
163
+ def find_archive_path( path, base_dir ) # :nodoc:
134
164
  if base_dir
135
165
  prefix = base_dir + (base_dir =~ /\/$/ ? '' : '/')
136
166
 
@@ -10,14 +10,30 @@ module JavaTools
10
10
 
11
11
  class Javac
12
12
 
13
- attr_accessor :source_files, # array
14
- :source_path, # array
15
- :destination, # string
16
- :class_path, # array
17
- :deprecation_warnings, # boolean
18
- :warnings, # boolean
19
- :encoding, # string
20
- :verbose # boolean
13
+ # The files to compile.
14
+ attr_accessor :source_files
15
+
16
+ # Additional directories where source files can be found.
17
+ attr_accessor :source_path
18
+
19
+ # The directory where the generated class files should be written, defaults to "build"
20
+ attr_accessor :destination
21
+
22
+ # The compilation class path
23
+ attr_accessor :class_path
24
+
25
+ # Show deprecation warnings, true by default
26
+ attr_accessor :deprecation_warnings
27
+
28
+ # Generate warnings, true by default
29
+ attr_accessor :warnings
30
+
31
+ # The encoding of the source files
32
+ attr_accessor :encoding
33
+
34
+ # Whether or not to print the equivalent command string to the output (see #execute)
35
+ attr_accessor :verbose
36
+
21
37
 
22
38
  def initialize( *source_files )
23
39
  @source_files = source_files || [ ]
@@ -31,7 +47,7 @@ module JavaTools
31
47
  @verbose = false
32
48
  end
33
49
 
34
- def command_args
50
+ def command_args # :nodoc:
35
51
  args = [ ]
36
52
  args << '-sourcepath' << @source_path.join(':') unless @source_path.empty?
37
53
  args << '-d' << @destination unless (@destination.nil? || @destination =~ /^\s*$/)
@@ -42,7 +58,7 @@ module JavaTools
42
58
  args + @source_files
43
59
  end
44
60
 
45
- def command_string
61
+ def command_string # :nodoc:
46
62
  args = [ ]
47
63
  args << '-sourcepath' << @source_path.join(':') unless @source_path.empty?
48
64
  args << '-d' << @destination unless (@destination.nil? || @destination =~ /^\s*$/)
@@ -54,6 +70,9 @@ module JavaTools
54
70
  "javac #{args.join(' ')} …"
55
71
  end
56
72
 
73
+ # Run javac. If #verbose is true the equivalent command string for
74
+ # the +javac+ command will be printed to the stream passed as +io+ (or
75
+ # +$stdout+ by default)
57
76
  def execute( io = $stderr )
58
77
  output_writer = StringWriter.new
59
78
 
@@ -0,0 +1,10 @@
1
+ require 'rake/rdoctask'
2
+
3
+
4
+ Rake::RDocTask.new do |rd|
5
+ rd.rdoc_dir = 'docs'
6
+ rd.title = 'Java Tools'
7
+ rd.main = 'README.rdoc'
8
+
9
+ rd.rdoc_files.include('README.rdoc', 'lib/**/*.rb')
10
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iconara-java_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Theo Hultberg
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-05 00:00:00 -07:00
12
+ date: 2009-08-06 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -20,9 +20,9 @@ executables: []
20
20
  extensions: []
21
21
 
22
22
  extra_rdoc_files:
23
- - README.textile
23
+ - README.rdoc
24
24
  files:
25
- - README.textile
25
+ - README.rdoc
26
26
  - Rakefile
27
27
  - VERSION
28
28
  - examples/compile/Rakefile
@@ -40,6 +40,7 @@ files:
40
40
  - spec/spec.opts
41
41
  - spec/spec_helper.rb
42
42
  - tasks/gem.rake
43
+ - tasks/rdoc.rake
43
44
  - tasks/spec.rake
44
45
  has_rdoc: false
45
46
  homepage: http://github.com/iconara/java_tools