C0 code coverage information
Generated on Wed Oct 07 08:34:02 -0700 2009 with rcov 0.8.2.1
Code reported as executed by Ruby looks like this...
and this: this line is also marked as covered.
Lines considered as run by rcov, but not reported by Ruby, look like this,
and this: these lines were inferred by rcov (using simple heuristics).
Finally, here's a line marked as not executed.
1 # Licensed to the Apache Software Foundation (ASF) under one or more
2 # contributor license agreements. See the NOTICE file distributed with this
3 # work for additional information regarding copyright ownership. The ASF
4 # licenses this file to you under the Apache License, Version 2.0 (the
5 # "License"); you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations under
14 # the License.
15
16
17 require 'rjb'
18
19
20 # Equivalent to Java system properties. For example:
21 # ENV_JAVA['java.version']
22 # ENV_JAVA['java.class.version']
23 ENV_JAVA = {}
24
25
26 # Buildr runs along side a JVM, using either RJB or JRuby. The Java module allows
27 # you to access Java classes and create Java objects.
28 #
29 # Java classes are accessed as static methods on the Java module, for example:
30 # str = Java.java.lang.String.new('hai!')
31 # str.toUpperCase
32 # => 'HAI!'
33 # Java.java.lang.String.isInstance(str)
34 # => true
35 # Java.com.sun.tools.javac.Main.compile(args)
36 #
37 # The classpath attribute allows Buildr to add JARs and directories to the classpath,
38 # for example, we use it to load Ant and various Ant tasks, code generators, test
39 # frameworks, and so forth.
40 #
41 # When using an artifact specification, Buildr will automatically download and
42 # install the artifact before adding it to the classpath.
43 #
44 # For example, Ant is loaded as follows:
45 # Java.classpath << 'org.apache.ant:ant:jar:1.7.0'
46 #
47 # Artifacts can only be downloaded after the Buildfile has loaded, giving it
48 # a chance to specify which remote repositories to use, so adding to classpath
49 # does not by itself load any libraries. You must call Java.load before accessing
50 # any Java classes to give Buildr a chance to load the libraries specified in the
51 # classpath.
52 #
53 # When building an extension, make sure to follow these rules:
54 # 1. Add to the classpath when the extension is loaded (i.e. in module or class
55 # definition), so the first call to Java.load anywhere in the code will include
56 # the libraries you specify.
57 # 2. Call Java.load once before accessing any Java classes, allowing Buildr to
58 # set up the classpath.
59 # 3. Only call Java.load when invoked, otherwise you may end up loading the JVM
60 # with a partial classpath, or before all remote repositories are listed.
61 # 4. Check on a clean build with empty local repository.
62 module Java
63
64 module Package #:nodoc:
65
66 def method_missing(sym, *args, &block)
67 raise ArgumentError, 'No arguments expected' unless args.empty?
68 name = "#{@name}.#{sym}"
69 return ::Rjb.import(name) if sym.to_s =~ /^[[:upper:]]/
70 ::Java.send :__package__, name
71 end
72
73 end
74
75 # On OS X we know where the default JDK is. We can try to guess for other OS.
76 # We set JAVA_HOME early so we can use it without calling Java.load first.
77 ENV['JAVA_HOME'] ||= '/System/Library/Frameworks/JavaVM.framework/Home' if Config::CONFIG['host_os'] =~ /darwin/i
78
79 class << self
80
81 # Returns the classpath, an array listing directories, JAR files and
82 # artifacts. Use when loading the extension to add any additional
83 # libraries used by that extension.
84 #
85 # For example, Ant is loaded as follows:
86 # Java.classpath << 'org.apache.ant:ant:jar:1.7.0'
87 def classpath
88 @classpath ||= []
89 end
90
91 # Most platforms requires tools.jar to be on the classpath, tools.jar contains the
92 # Java compiler (OS X and AIX are two exceptions we know about, may be more).
93 # Guess where tools.jar is from JAVA_HOME, which hopefully points to the JDK,
94 # but maybe the JRE. Return nil if not found.
95 def tools_jar #:nodoc:
96 @tools_jar ||= begin
97 home = ENV['JAVA_HOME'] or fail 'Are we forgetting something? JAVA_HOME not set.'
98 ['lib/tools.jar', '../lib/tools.jar'].map { |path| File.expand_path(path, home) }.
99 find { |path| File.exist?(path) }
100 end
101 end
102
103 # Loads the JVM and all the libraries listed on the classpath. Call this
104 # method before accessing any Java class, but only call it from methods
105 # used in the build, giving the Buildfile a chance to load all extensions
106 # that append to the classpath and specify which remote repositories to use.
107 def load
108 return self if @loaded
109 classpath << tools_jar if tools_jar
110
111 classpath.map! { |path| Proc === path ? path.call : path }
112 cp = Buildr.artifacts(classpath).map(&:to_s).each { |path| file(path).invoke }
113 java_opts = (ENV['JAVA_OPTS'] || ENV['JAVA_OPTIONS']).to_s.split
114 ::Rjb.load cp.join(File::PATH_SEPARATOR), java_opts
115
116 props = ::Rjb.import('java.lang.System').getProperties
117 enum = props.propertyNames
118 while enum.hasMoreElements
119 name = enum.nextElement.toString
120 ENV_JAVA[name] = props.getProperty(name)
121 end
122 @loaded = true
123 self
124 end
125
126 def method_missing(sym, *args, &block) #:nodoc:
127 raise ArgumentError, 'No arguments expected' unless args.empty?
128 name = sym.to_s
129 return ::Rjb.import(name) if name =~ /^[[:upper:]]/
130 __package__ name
131 end
132
133 private
134
135 def __package__(name) #:nodoc:
136 const = name.split('.').map { |part| part.gsub(/^./) { |char| char.upcase } }.join
137 return const_get(const) if constants.include?(const) || constants.include?(const.to_sym)
138 package = Module.new
139 package.extend Package
140 package.instance_variable_set :@name, name
141 const_set(const, package)
142 end
143
144 end
145
146 end
147
148
149 class Array
150 # Converts a Ruby array into a typed Java array, argument specifies the element type.
151 # This is necessary for JRuby and causes no harm on RJB.
152 def to_java(cls)
153 map { |item| cls.new(item) }
154 end
155 end
Generated using the rcov code coverage analysis tool for Ruby
version 0.8.2.1.