Module: Buildr::Util
Overview
:nodoc:
Instance Method Summary collapse
-
#recursive_with_dot_files(*dirs) ⇒ Object
Generally speaking, it’s not a good idea to operate on dot files (files starting with dot).
-
#relative_path(to, from = '.') ⇒ Object
Return the path to the first argument, starting from the path provided by the second argument.
-
#tools_jar ⇒ Object
Most platforms requires tools.jar to be on the classpath, tools.jar contains the Java compiler (OS X and AIX are two exceptions we know about, may be more).
Instance Method Details
#recursive_with_dot_files(*dirs) ⇒ Object
Generally speaking, it’s not a good idea to operate on dot files (files starting with dot). These are considered invisible files (.svn, .hg, .irbrc, etc). Dir.glob/FileList ignore them on purpose. There are few cases where we do have to work with them (filter, zip), a better solution is welcome, maybe being more explicit with include. For now, this will do.
45 46 47 |
# File 'lib/buildr/core/util.rb', line 45 def recursive_with_dot_files(*dirs) FileList[dirs.map { |dir| File.join(dir, '/**/{*,.*}') }].reject { |file| File.basename(file) =~ /^[.]{1,2}$/ } end |
#relative_path(to, from = '.') ⇒ Object
Return the path to the first argument, starting from the path provided by the second argument.
For example:
relative_path('foo/bar', 'foo')
=> 'bar'
relative_path('foo/bar', 'baz')
=> '../foo/bar'
relative_path('foo/bar')
=> 'foo/bar'
relative_path('/foo/bar', 'baz')
=> '/foo/bar'
33 34 35 36 37 38 39 |
# File 'lib/buildr/core/util.rb', line 33 def relative_path(to, from = '.') to = Pathname.new(to).cleanpath return to.to_s if from.nil? to_path = Pathname.new(File.(to.to_s, "/")) from_path = Pathname.new(File.(from.to_s, "/")) to_path.relative_path_from(from_path).to_s end |
#tools_jar ⇒ Object
Most platforms requires tools.jar to be on the classpath, tools.jar contains the Java compiler (OS X and AIX are two exceptions we know about, may be more). Guess where tools.jar is from JAVA_HOME, which hopefully points to the JDK, but maybe the JRE. Return nil if not found.
53 54 55 56 57 58 59 |
# File 'lib/buildr/core/util.rb', line 53 def tools_jar #:nodoc: @tools_jar ||= begin home = ENV['JAVA_HOME'] or fail 'Are we forgetting something? JAVA_HOME not set.' %w[lib/tools.jar ../lib/tools.jar].map { |path| File.(path, home) }. find { |path| File.exist?(path) } end end |