class Buildr::TestFramework::Java
Public Class Methods
dependencies()
click to toggle source
Calls superclass method
Buildr::TestFramework::Base::dependencies
# File lib/buildr/java/tests.rb, line 27 def dependencies unless @dependencies super # Add buildr utility classes (e.g. JavaTestFilter) @dependencies |= [ File.join(File.dirname(__FILE__)) ] end @dependencies end
Private Instance Methods
filter_classes(dependencies, criteria)
click to toggle source
Return a list of classnames that match the given criteria. The criteria parameter is a hash that must contain at least one of:
-
:class_names – List of patterns to match against class name
-
:interfaces – List of java interfaces or java classes
-
:class_annotations – List of annotations on class level
-
:method_annotations – List of annotations on method level
-
:fields – List of java field names
# File lib/buildr/java/tests.rb, line 54 def filter_classes(dependencies, criteria = {}) return [] unless task.compile.target target = task.compile.target.to_s candidates = Dir["#{target}/**/*.class"]. map { |file| Util.relative_path(file, target).ext('').gsub(File::SEPARATOR, '.') }. reject { |name| name =~ /\$./ } result = [] if criteria[:class_names] result.concat candidates.select { |name| criteria[:class_names].flatten.any? { |pat| pat === name } } end begin Java.load filter = Java.org.apache.buildr.JavaTestFilter.new(dependencies.to_java(Java.java.lang.String)) if criteria[:interfaces] filter.add_interfaces(criteria[:interfaces].to_java(Java.java.lang.String)) end if criteria[:class_annotations] filter.add_class_annotations(criteria[:class_annotations].to_java(Java.java.lang.String)) end if criteria[:method_annotations] filter.add_method_annotations(criteria[:method_annotations].to_java(Java.java.lang.String)) end if criteria[:fields] filter.add_fields(criteria[:fields].to_java(Java.java.lang.String)) end result.concat filter.filter(candidates.to_java(Java.java.lang.String)).map(&:to_s) rescue =>ex info "#{ex.class}: #{ex.message}" raise end end