Module: Java
- Defined in:
- lib/buildr/java/rjb.rb,
lib/buildr/java/jruby.rb,
lib/buildr/java/commands.rb,
lib/buildr/java/deprecated.rb
Overview
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Defined Under Namespace
Modules: Commands, Package Classes: Options
Constant Summary collapse
- JRUBY_MIN_VERSION =
This version is the minimal version Buildr will support. Any older version of JRuby will raise an exception.
'1.5.1'
Class Method Summary collapse
-
.apt(*args) ⇒ Object
Deprecated: Use Java::Commands.apt instead.
-
.classpath ⇒ Object
Returns the classpath, an array listing directories, JAR files and artifacts.
-
.home ⇒ Object
Deprecated: Use ENV instead.
-
.java(*args, &block) ⇒ Object
Deprecated: Use Java::Commands.java instead.
-
.javac(*args) ⇒ Object
Deprecated: Use Java::Commands.javac instead.
-
.javadoc(*args) ⇒ Object
Deprecated: Use Java::Commands.javadoc instead.
-
.load ⇒ Object
Loads the JVM and all the libraries listed on the classpath.
-
.loaded? ⇒ Boolean
Returns true if the JVM is loaded with all the libraries loaded on the classpath.
-
.method_missing(sym, *args, &block) ⇒ Object
:nodoc:.
-
.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).
-
.version ⇒ Object
Deprecated: Use ENV_JAVA instead.
Class Method Details
.apt(*args) ⇒ Object
Deprecated: Use Java::Commands.apt instead.
28 29 30 31 |
# File 'lib/buildr/java/deprecated.rb', line 28 def apt(*args) Buildr.application.deprecated 'Use Java::Commands.apt instead.' Commands.apt(*args) end |
.classpath ⇒ Object
Returns the classpath, an array listing directories, JAR files and artifacts. Use when loading the extension to add any additional libraries used by that extension.
For example, Ant is loaded as follows:
Java.classpath << 'org.apache.ant:ant:jar:1.7.0'
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/buildr/java/rjb.rb', line 88 def classpath @classpath ||= begin classpath = [] class << classpath def new_add(*args) warn 'Java is already loaded' if Java.loaded? send(:old_add, *args) end alias_method :old_add, :<< alias_method :<<, :new_add end classpath end end |
.home ⇒ Object
Deprecated: Use ENV instead
53 54 55 56 |
# File 'lib/buildr/java/deprecated.rb', line 53 def home Buildr.application.deprecated 'Use ENV[\'JAVA_HOME\'] instead.' ENV['JAVA_HOME'] end |
.java(*args, &block) ⇒ Object
Deprecated: Use Java::Commands.java instead.
21 22 23 24 25 |
# File 'lib/buildr/java/deprecated.rb', line 21 def java(*args, &block) return send(:method_missing, :java) if args.empty? Buildr.application.deprecated 'Use Java::Commands.java instead.' Commands.java(*args, &block) end |
.javac(*args) ⇒ Object
Deprecated: Use Java::Commands.javac instead.
34 35 36 37 |
# File 'lib/buildr/java/deprecated.rb', line 34 def javac(*args) Buildr.application.deprecated 'Use Java::Commands.javac instead.' Commands.javac(*args) end |
.javadoc(*args) ⇒ Object
Deprecated: Use Java::Commands.javadoc instead.
40 41 42 43 |
# File 'lib/buildr/java/deprecated.rb', line 40 def javadoc(*args) Buildr.application.deprecated 'Use Java::Commands.javadoc instead.' Commands.javadoc(*args) end |
.load ⇒ Object
Loads the JVM and all the libraries listed on the classpath. Call this method before accessing any Java class, but only call it from methods used in the build, giving the Buildfile a chance to load all extensions that append to the classpath and specify which remote repositories to use.
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/buildr/java/rjb.rb', line 126 def load return self if @loaded classpath << tools_jar if tools_jar classpath.map! { |path| Proc === path ? path.call : path } cp = Buildr.artifacts(classpath).map(&:to_s).each { |path| file(path).invoke } java_opts = (ENV['JAVA_OPTS'] || ENV['JAVA_OPTIONS']).to_s.split # Prepend the JDK bin directory to the path under windows as RJB can have issues if it picks # up jvm dependencies from other products installed on the system if Buildr::Util.win_os? ENV["PATH"] = "#{ENV['JAVA_HOME']}#{File::SEPARATOR}bin#{File::PATH_SEPARATOR}#{ENV["PATH"]}" end ::Rjb.load cp.join(File::PATH_SEPARATOR), java_opts props = ::Rjb.import('java.lang.System').getProperties enum = props.propertyNames while enum.hasMoreElements name = enum.nextElement.toString ENV_JAVA[name] = props.getProperty(name) end @loaded = true self end |
.loaded? ⇒ Boolean
Returns true if the JVM is loaded with all the libraries loaded on the classpath.
106 107 108 |
# File 'lib/buildr/java/rjb.rb', line 106 def loaded? @loaded end |
.method_missing(sym, *args, &block) ⇒ Object
:nodoc:
151 152 153 154 155 156 157 |
# File 'lib/buildr/java/rjb.rb', line 151 def method_missing(sym, *args, &block) #:nodoc: raise ArgumentError, 'No arguments expected' unless args.empty? Java.load # need to load RJB's classpath now! name = sym.to_s return ::Rjb.import(name) if name =~ /^[[:upper:]]/ __package__ name 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.
114 115 116 117 118 119 120 |
# File 'lib/buildr/java/rjb.rb', line 114 def tools_jar #:nodoc: @tools_jar ||= begin home = ENV['JAVA_HOME'] or fail 'Are we forgetting something? JAVA_HOME not set.' ['lib/tools.jar', '../lib/tools.jar'].map { |path| File.(path, home) }. find { |path| File.exist?(path) } end end |