Repository: buildr Updated Branches: refs/heads/master f0ccc5fa3 -> 7a0e75e36
BUILDR-523 Issue a warning when Java.classpath is modified after Java.load has happened Project: http://git-wip-us.apache.org/repos/asf/buildr/repo Commit: http://git-wip-us.apache.org/repos/asf/buildr/commit/7a0e75e3 Tree: http://git-wip-us.apache.org/repos/asf/buildr/tree/7a0e75e3 Diff: http://git-wip-us.apache.org/repos/asf/buildr/diff/7a0e75e3 Branch: refs/heads/master Commit: 7a0e75e362e4e7680632b360868bebd9518fc665 Parents: f0ccc5f Author: Antoine Toulme <[email protected]> Authored: Sat Aug 13 16:38:50 2016 -0700 Committer: Antoine Toulme <[email protected]> Committed: Sat Aug 13 16:38:50 2016 -0700 ---------------------------------------------------------------------- CHANGELOG | 1 + lib/buildr/java/jruby.rb | 20 +++++++++++++++++++- lib/buildr/java/rjb.rb | 24 +++++++++++++++++++++--- spec/java/java_spec.rb | 6 ++++++ 4 files changed, 47 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/buildr/blob/7a0e75e3/CHANGELOG ---------------------------------------------------------------------- diff --git a/CHANGELOG b/CHANGELOG index f8eed47..03e5ee5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -13,6 +13,7 @@ * Added: Travis badge to README.rdoc * Added: Added Rubygems badges to README.rdoc * Added: BUILDR-577 Allow remote repo to be added with http basic auth support. Submitted by Michael Guymon. +* Added: BUILDR-523 Issue a warning when Java.classpath is modified after Java.load has happened * Fixed: BUILDR-207 remove 'Skipping tests' messages * Added: BUILDR-703 release: allow THIS_VERSION to be defined in another file * Fixed: BUILDR-674 Artifacts with bundle extension cannot be downloaded by Buildr http://git-wip-us.apache.org/repos/asf/buildr/blob/7a0e75e3/lib/buildr/java/jruby.rb ---------------------------------------------------------------------- diff --git a/lib/buildr/java/jruby.rb b/lib/buildr/java/jruby.rb index 6ca35f9..a36b03a 100644 --- a/lib/buildr/java/jruby.rb +++ b/lib/buildr/java/jruby.rb @@ -72,7 +72,25 @@ module Java # For example, Ant is loaded as follows: # Java.classpath << 'org.apache.ant:ant:jar:1.7.0' def classpath - @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 + + # Returns true if the JVM is loaded with all the libraries loaded on the classpath. + def loaded? + @loaded end # Most platforms requires tools.jar to be on the classpath, tools.jar contains the http://git-wip-us.apache.org/repos/asf/buildr/blob/7a0e75e3/lib/buildr/java/rjb.rb ---------------------------------------------------------------------- diff --git a/lib/buildr/java/rjb.rb b/lib/buildr/java/rjb.rb index ba12f7a..26b02dc 100644 --- a/lib/buildr/java/rjb.rb +++ b/lib/buildr/java/rjb.rb @@ -65,7 +65,7 @@ ENV_JAVA = {} # with a partial classpath, or before all remote repositories are listed. # 4. Check on a clean build with empty local repository. module Java - + module Package #:nodoc: def method_missing(sym, *args, &block) @@ -78,7 +78,7 @@ module Java end class << self - + # 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. @@ -86,7 +86,25 @@ module Java # For example, Ant is loaded as follows: # Java.classpath << 'org.apache.ant:ant:jar:1.7.0' def classpath - @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 + + # Returns true if the JVM is loaded with all the libraries loaded on the classpath. + def loaded? + @loaded end # Most platforms requires tools.jar to be on the classpath, tools.jar contains the http://git-wip-us.apache.org/repos/asf/buildr/blob/7a0e75e3/spec/java/java_spec.rb ---------------------------------------------------------------------- diff --git a/spec/java/java_spec.rb b/spec/java/java_spec.rb index 110b79e..a6c2226 100644 --- a/spec/java/java_spec.rb +++ b/spec/java/java_spec.rb @@ -51,6 +51,12 @@ else end end +describe 'Java.classpath' do + it 'should issue a warning if the classpath is modified after Java is loaded' do + lambda { Java.classpath << 'foo:bar:1.0' }.should show_warning(/Java is already loaded/) + end +end + describe 'Java.tools_jar' do before do
