Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 7df3e56395cf^
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2d3914ae663b
Choose a head ref

Commits on May 28, 2015

  1. Copy the full SHA
    a6db2cd View commit details
  2. Copy the full SHA
    207c3c2 View commit details

Commits on May 29, 2015

  1. Copy the full SHA
    fa690dc View commit details
  2. Copy the full SHA
    46c7d68 View commit details
  3. avoid (local) context ref over-head + refactor to context.nil esp. in…

    … anon-class methods
    
    ... where ctx is a local while runtime.getNil() comes from parent scope
    also added a packEnumValues helper with context being passed instead of runtime
    kares committed May 29, 2015
    Copy the full SHA
    20e3382 View commit details
  4. Copy the full SHA
    d8aa8af View commit details
  5. Copy the full SHA
    cd30b12 View commit details
  6. Copy the full SHA
    7de07f9 View commit details
  7. Copy the full SHA
    56e8746 View commit details
  8. Copy the full SHA
    1ea53a6 View commit details
  9. Copy the full SHA
    2c9825d View commit details
  10. keep mkdir consistent when using uri-like paths

    * there was a problem with file:////path/to/dir where the extra slashes
      did confuse the logic
    * all pathes starting with uri: can not create any directories
    
    fixes #2972
    
    Sponsored by Lookout Inc.
    mkristian committed May 29, 2015
    Copy the full SHA
    0137667 View commit details

Commits on May 30, 2015

  1. ensure relative_require on root of uri:classloader:/

    this fixes a regression of 0137667
    
    Sponsored by Lookout Inc.
    mkristian committed May 30, 2015
    Copy the full SHA
    562a240 View commit details
  2. Copy the full SHA
    92a1923 View commit details
  3. Copy the full SHA
    b32767d View commit details
  4. Copy the full SHA
    23b872e View commit details
  5. Copy the full SHA
    e12ad7e View commit details
  6. Copy the full SHA
    1a94da8 View commit details

Commits on Jun 2, 2015

  1. use new JRuby.create to load script from command line script source

    delegate script source argument to the new load service FileResource
    factory and allow all uri like paths which the regular JRuby code
    uses as well.
    
    fixes #2948
    
    Sponsored by Lookout Inc.
    mkristian committed Jun 2, 2015
    3
    Copy the full SHA
    4da7547 View commit details
  2. Copy the full SHA
    d7fc016 View commit details
  3. Add support for http.nonProxyHosts and rework ENV_JAVA support.

    Fixes #2983.
    
    Note that Ruby 1.9 has no support for environment-driven proxy
    settings, so this change is only available in 2.0 mode on JRuby
    1.7.
    headius committed Jun 2, 2015
    Copy the full SHA
    35cf0da View commit details

Commits on Jun 3, 2015

  1. set ENV['RUBY'] when jruby.home is not regular directory

    JRuby comes with rake as part of its ruby stdlib. rake has a feature
    to spawn a new ruby process and execute things. this is used by unit
    tests and rspec. this spawn needs to determin the ruby executable. when
    jruby runs from the jruby-complete.jar then ENV['RUBY'] will tell rake to
    use which does actual execute and spawn a new
    `java -cp jruby-complete.jar org.jruby.Main` process.
    
    added an integration test in maven/jruby-complete/src/it which executes
    `java -jar jruby-complete.jar -S rake test:mri`
    
    there are still short comings with ArgumentProcessor and some -J-xyz switches
    
    Sponsored by Lookout Inc.
    mkristian committed Jun 3, 2015
    5
    Copy the full SHA
    5c45c39 View commit details
  2. Copy the full SHA
    1e43071 View commit details
  3. if current directory is inside the classloader a spawn jruby process …

    …should do the same
    
    first the code need to launch a new jruby process, when the current
    directory is inside the classloader then the spawned jruby process
    needs to have the same current directory
    
    Sponsored by Lookout Inc.
    mkristian committed Jun 3, 2015
    Copy the full SHA
    3a4235a View commit details

Commits on Jun 4, 2015

  1. Copy the full SHA
    98cab87 View commit details
  2. Copy the full SHA
    f8a17c1 View commit details
  3. Copy the full SHA
    a11eb7a View commit details
  4. Copy the full SHA
    0ab74b7 View commit details
  5. Copy the full SHA
    8c2b5f5 View commit details
  6. Copy the full SHA
    fb4d26b View commit details
  7. Copy the full SHA
    46ae07b View commit details
  8. Copy the full SHA
    7daf537 View commit details
  9. handle big decimal ** float value calculation (with Java double math)…

    … ...
    
    since we're now not raising users should get ~ the value they expect (closing #1967)
    kares committed Jun 4, 2015
    Copy the full SHA
    5c5b5cb View commit details
  10. minor BigDecimal code cleanup

    kares committed Jun 4, 2015
    Copy the full SHA
    fdf5201 View commit details
  11. Copy the full SHA
    2b990bc View commit details
  12. Copy the full SHA
    4ac1c5d View commit details
  13. Copy the full SHA
    e492b3a View commit details
  14. basic BigDecimal sub-class test ... all working the same as MRI 1.8/1.9

    ... no need to address #365 as the allocate+initialize sequence seems MRI-like
    kares committed Jun 4, 2015
    Copy the full SHA
    967ca40 View commit details

Commits on Jun 5, 2015

  1. Merge branch 'jruby-1_7'

    * jruby-1_7: (38 commits)
      basic BigDecimal sub-class test ... all working the same as MRI 1.8/1.9
      avoid deprecated newInstance + one less pattern to match on BigDecimal.new
      [bigdecimal] keep the simplified newInstance backport 1.8 compatible
      [bigdecimal] backport simplified newInstance impl from master
      minor BigDecimal code cleanup
      handle big decimal ** float value calculation (with Java double math) ... since we're now not raising users should get ~ the value they expect (closing #1967)
      static-ize and simplify private helpers
      BigDecimal should not raise error on pow/** with float arg (under 1.9 #1967)
      some more (internal) RubyBigDecimal dry-ing / tidy-ing
      do coercion on * and / (same as MRI has been doing since 1.8) ... fixes #2538
      handle BigDecimal cmp failure compatibly with MRI (fixes #2539)
      pass around context in BigDecimal impl + simplify cmp method's code
      move JI java.mat.BigDecimal test out of Ruby's BigDecimal tests
      [travis-ci] test-extended on jdk8
      if current directory is inside the classloader a spawn jruby process should do the same
      use the new bin stubs from new rubygems
      set ENV['RUBY'] when jruby.home is not regular directory
      Add support for http.nonProxyHosts and rework ENV_JAVA support.
      pik the right class in URLResourceTest
      use new JRuby.create to load script from command line script source
      ...
    
    Conflicts:
    	.travis.yml
    	core/src/main/java/org/jruby/RubyDir.java
    	core/src/main/java/org/jruby/RubyEnumerable.java
    	core/src/main/java/org/jruby/RubyEnumerator.java
    	core/src/main/java/org/jruby/RubyHash.java
    	core/src/main/java/org/jruby/RubyInstanceConfig.java
    	core/src/main/java/org/jruby/RubyModule.java
    	core/src/main/java/org/jruby/ext/bigdecimal/RubyBigDecimal.java
    	core/src/main/java/org/jruby/util/ClasspathResource.java
    	core/src/main/java/org/jruby/util/URLResource.java
    	core/src/test/java/org/jruby/util/URLResourceTest.java
    	lib/ruby/2.0/net/http.rb
    	lib/ruby/2.0/uri/generic.rb
    	maven/jruby/src/it/runnable/spec/one_spec.rb
    	test/test_backquote.rb
    	test/test_big_decimal.rb
    	test/test_dir.rb
    	test/test_file.rb
    	test/test_higher_javasupport.rb
    	test/test_load.rb
    kares committed Jun 5, 2015
    Copy the full SHA
    7df3e56 View commit details
  2. 1
    Copy the full SHA
    2d3914a View commit details
Showing with 1,457 additions and 912 deletions.
  1. +1 −1 bin/rake
  2. +1 −1 bin/rdoc
  3. +1 −1 bin/ri
  4. +266 −265 core/src/main/java/org/jruby/RubyEnumerable.java
  5. +62 −61 core/src/main/java/org/jruby/RubyEnumerator.java
  6. +41 −41 core/src/main/java/org/jruby/RubyHash.java
  7. +9 −2 core/src/main/java/org/jruby/RubyInstanceConfig.java
  8. +4 −4 core/src/main/java/org/jruby/RubyModule.java
  9. +380 −314 core/src/main/java/org/jruby/ext/bigdecimal/RubyBigDecimal.java
  10. +30 −29 core/src/main/java/org/jruby/internal/runtime/methods/JavaMethod.java
  11. +6 −4 core/src/main/java/org/jruby/javasupport/Java.java
  12. +1 −4 core/src/main/java/org/jruby/javasupport/JavaUtil.java
  13. +10 −2 core/src/main/java/org/jruby/util/ShellLauncher.java
  14. +23 −5 core/src/main/java/org/jruby/util/URLResource.java
  15. +15 −15 core/src/test/java/org/jruby/util/URLResourceTest.java
  16. +16 −16 lib/ruby/stdlib/uri/generic.rb
  17. +35 −0 maven/jruby-complete/src/it/extended/Mavenfile
  18. +86 −0 maven/jruby-complete/src/it/extended/pom.xml
  19. +150 −4 maven/jruby/src/it/integrity/pom.xml
  20. BIN maven/jruby/src/it/integrity/src/main/resources/hello.jar
  21. +1 −0 maven/jruby/src/it/integrity/src/main/resources/hello.rb
  22. +23 −0 maven/jruby/src/it/integrity/verify.bsh
  23. +5 −3 maven/jruby/src/it/runnable/Mavenfile
  24. +3 −1 maven/jruby/src/it/runnable/Rakefile
  25. +17 −2 maven/jruby/src/it/runnable/pom.xml
  26. +5 −1 maven/jruby/src/it/runnable/spec/one_spec.rb
  27. +0 −40 maven/jruby/src/it/runnable/src/main/java/Main.java
  28. +7 −4 maven/jruby/src/it/runnable/verify.bsh
  29. 0 test/jruby/relative.rb
  30. +1 −0 test/jruby/require_relative.rb
  31. +7 −1 test/jruby/test_backquote.rb
  32. +152 −40 test/jruby/test_big_decimal.rb
  33. +15 −13 test/jruby/test_dir.rb
  34. +26 −26 test/jruby/test_file.rb
  35. +35 −0 test/jruby/test_hash.rb
  36. +8 −0 test/jruby/test_higher_javasupport.rb
  37. +14 −10 test/jruby/test_load.rb
  38. +1 −2 test/{ → jruby}/test_load_gem_extensions.rb
2 changes: 1 addition & 1 deletion bin/rake
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ version = ">= 0"
if ARGV.first
str = ARGV.first
str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
if str =~ /\A_(.*)_\z/
if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then
version = $1
ARGV.shift
end
2 changes: 1 addition & 1 deletion bin/rdoc
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ version = ">= 0"
if ARGV.first
str = ARGV.first
str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
if str =~ /\A_(.*)_\z/
if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then
version = $1
ARGV.shift
end
2 changes: 1 addition & 1 deletion bin/ri
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ version = ">= 0"
if ARGV.first
str = ARGV.first
str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
if str =~ /\A_(.*)_\z/
if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then
version = $1
ARGV.shift
end
531 changes: 266 additions & 265 deletions core/src/main/java/org/jruby/RubyEnumerable.java

Large diffs are not rendered by default.

123 changes: 62 additions & 61 deletions core/src/main/java/org/jruby/RubyEnumerator.java
Original file line number Diff line number Diff line change
@@ -62,18 +62,18 @@ public class RubyEnumerator extends RubyObject {

/** args to each method */
private IRubyObject[] methodArgs;

/** A value or proc to provide the size of the Enumerator contents*/
private IRubyObject size;

/** Function object for lazily computing size (used for internally created enumerators) */
private SizeFn sizeFn;

private IRubyObject feedValue;

public static void defineEnumerator(Ruby runtime) {
RubyModule enm = runtime.getClassFromPath("Enumerable");

final RubyClass enmr;
enmr = runtime.defineClass("Enumerator", runtime.getObject(), ENUMERATOR_ALLOCATOR);

@@ -303,17 +303,17 @@ public IRubyObject each(ThreadContext context, Block block) {

return object.callMethod(context, method, methodArgs, block);
}

@JRubyMethod(rest = true)
public IRubyObject each(ThreadContext context, IRubyObject[] args, Block block) {
if (args.length == 0) {
return each(context, block);
}

IRubyObject[] newArgs = new IRubyObject[methodArgs.length + args.length];
System.arraycopy(methodArgs, 0, newArgs, 0, methodArgs.length);
System.arraycopy(args, 0, newArgs, methodArgs.length, args.length);

return new RubyEnumerator(context.runtime, getType(), object, context.runtime.newSymbol("each"), newArgs);
}

@@ -415,7 +415,7 @@ public IRubyObject size(ThreadContext context) {
if (size.respondsTo("call")) {
return size.callMethod(context, "call");
}

return size;
}

@@ -434,13 +434,14 @@ public IRubyObject size(IRubyObject[] args) {

private IRubyObject with_index_common(ThreadContext context, final Block block, final String rubyMethodName, IRubyObject arg) {
final Ruby runtime = context.runtime;
int index = arg.isNil() ? 0 : RubyNumeric.num2int(arg);
if (!block.isGiven()) {
return arg.isNil() ? enumeratorizeWithSize(context, this, rubyMethodName, enumSizeFn(context)) :
enumeratorizeWithSize(context, this, rubyMethodName, new IRubyObject[]{runtime.newFixnum(index)}, enumSizeFn(context));
final int index = arg.isNil() ? 0 : RubyNumeric.num2int(arg);
if ( ! block.isGiven() ) {
return arg.isNil() ?
enumeratorizeWithSize(context, this, rubyMethodName, enumSizeFn(context)) :
enumeratorizeWithSize(context, this, rubyMethodName, new IRubyObject[]{runtime.newFixnum(index)}, enumSizeFn(context));
}

return RubyEnumerable.callEach(runtime, context, this, new RubyEnumerable.EachWithIndex(context, block, index));
return RubyEnumerable.callEach(runtime, context, this, new RubyEnumerable.EachWithIndex(block, index));
}

@JRubyMethod
@@ -461,32 +462,32 @@ public IRubyObject with_index19(ThreadContext context, final Block block) {
public IRubyObject with_index19(ThreadContext context, IRubyObject arg, final Block block) {
return with_index_common(context, block, "with_index", arg);
}

private volatile Nexter nexter = null;

@JRubyMethod
public synchronized IRubyObject next(ThreadContext context) {
ensureNexter(context);
if (!feedValue.isNil()) feedValue = context.nil;
return nexter.next();
}

@JRubyMethod
public synchronized IRubyObject rewind(ThreadContext context) {
if (object.respondsTo("rewind")) object.callMethod(context, "rewind");

if (nexter != null) {
nexter.shutdown();
nexter = null;
}

return this;
}

@JRubyMethod
public synchronized IRubyObject peek(ThreadContext context) {
ensureNexter(context);

return nexter.peek();
}

@@ -528,7 +529,7 @@ private void ensureNexter(ThreadContext context) {
}
}
}

@Override
protected void finalize() throws Throwable {
try {
@@ -550,11 +551,11 @@ protected void finalize() throws Throwable {
public interface SizeFn {
IRubyObject size(IRubyObject[] args);
}

private static abstract class Nexter {
/** the runtime associated with all objects */
protected final Ruby runtime;

/** target for each operation */
protected final IRubyObject object;

@@ -565,7 +566,7 @@ private static abstract class Nexter {
protected final IRubyObject[] methodArgs;

private IRubyObject feedValue;

public Nexter(Ruby runtime, IRubyObject object, String method, IRubyObject[] methodArgs) {
this.object = object;
this.method = method;
@@ -582,16 +583,16 @@ public IRubyObject getFeedValue() {
}

public abstract IRubyObject next();

public abstract void shutdown();

public abstract IRubyObject peek();
}

private static class ArrayNexter extends Nexter {
private final RubyArray array;
private int index = 0;

public ArrayNexter(Ruby runtime, IRubyObject object, String method, IRubyObject[] methodArgs) {
super(runtime, object, method, methodArgs);
array = (RubyArray)object;
@@ -613,10 +614,10 @@ public void shutdown() {
@Override
public IRubyObject peek() {
checkIndex();

return get();
}

protected IRubyObject get() {
return array.eltOk(index);
}
@@ -625,22 +626,22 @@ private void checkIndex() throws RaiseException {
if (index >= array.size()) throw runtime.newLightweightStopIterationError("stop iteration");
}
}

private static class ThreadedNexter extends Nexter implements Runnable {
private static final boolean DEBUG = false;

/** sync queue to wait for values */
private SynchronousQueue<IRubyObject> out = new SynchronousQueue<IRubyObject>();

/** thread that's executing this Nexter */
private volatile Thread thread;

/** whether we're done iterating */
private IRubyObject doneObject;

/** future to cancel job if it has not started */
private Future future;

/** death mark */
protected volatile boolean die = false;

@@ -649,7 +650,7 @@ private static class ThreadedNexter extends Nexter implements Runnable {

/** Exception used for unrolling the iteration on terminate */
private static class TerminateEnumeration extends RuntimeException implements Unrescuable {}

public ThreadedNexter(Ruby runtime, IRubyObject object, String method, IRubyObject[] methodArgs) {
super(runtime, object, method, methodArgs);
setFeedValue(runtime.getNil());
@@ -660,106 +661,106 @@ public synchronized IRubyObject next() {
if (doneObject != null) {
return returnValue(doneObject);
}

ensureStarted();

return returnValue(take());
}

@Override
public synchronized void shutdown() {
// cancel future in case we have not been started
future.cancel(true);

// mark for death
die = true;

Thread myThread = thread;
if (myThread != null) {
if (DEBUG) System.out.println("clearing for shutdown");

// we interrupt twice, to break out of iteration and
// (potentially) break out of final exchange
myThread.interrupt();
myThread.interrupt();

// release references
thread = null;
doneObject = null;
}
}

@Override
public synchronized IRubyObject peek() {
if (doneObject != null) {
return returnValue(doneObject);
}

ensureStarted();

if (lastValue != null) {
return lastValue;
}

peekTake();

return returnValue(lastValue);
}

private void ensureStarted() {
if (thread == null) future = runtime.getFiberExecutor().submit(this);
}

private IRubyObject peekTake() {
try {
return lastValue = out.take();
} catch (InterruptedException ie) {
throw runtime.newThreadError("interrupted during iteration");
}
}

private IRubyObject take() {
try {
if (lastValue != null) {
return lastValue;
}

return out.take();
} catch (InterruptedException ie) {
throw runtime.newThreadError("interrupted during iteration");
} finally {
lastValue = null;
}
}

private IRubyObject returnValue(IRubyObject value) {
// if it's the NEVER object, raise StopIteration
if (value == NEVER) {
doneObject = value;
throw runtime.newLightweightStopIterationError("stop iteration");
}

// if it's an exception, raise it
if (value instanceof RubyException) {
doneObject = value;
throw new RaiseException((RubyException)value);
}

// otherwise, just return it
return value;
}

@Override
public void run() {
if (die) return;

thread = Thread.currentThread();
ThreadContext context = runtime.getCurrentContext();

if (DEBUG) System.out.println(Thread.currentThread().getName() + ": starting up nexter thread");

IRubyObject finalObject = NEVER;

try {
IRubyObject oldExc = runtime.getGlobalVariables().get("$!"); // Save $!
final TerminateEnumeration terminateEnumeration = new TerminateEnumeration();
@@ -770,7 +771,7 @@ public IRubyObject call(ThreadContext context, IRubyObject[] args, Block block)
try {
if (DEBUG) System.out.println(Thread.currentThread().getName() + ": exchanging: " + Arrays.toString(args));
if (die) throw terminateEnumeration;
out.put(RubyEnumerable.packEnumValues(runtime, args));
out.put(RubyEnumerable.packEnumValues(context, args));
if (die) throw terminateEnumeration;
} catch (InterruptedException ie) {
if (DEBUG) System.out.println(Thread.currentThread().getName() + ": interrupted");
82 changes: 41 additions & 41 deletions core/src/main/java/org/jruby/RubyHash.java
Original file line number Diff line number Diff line change
@@ -123,7 +123,7 @@ public static RubyClass createHashClass(Ruby runtime) {

hashc.setClassIndex(ClassIndex.HASH);
hashc.setReifiedClass(RubyHash.class);

hashc.kindOf = new RubyModule.JavaClassKindOf(RubyHash.class);

hashc.includeModule(runtime.getEnumerable());
@@ -399,7 +399,7 @@ public Object setValue(Object value) {
public boolean equals(Object other){
if(!(other instanceof RubyHashEntry)) return false;
RubyHashEntry otherEntry = (RubyHashEntry)other;

return (key == otherEntry.key || key.eql(otherEntry.key)) &&
(value == otherEntry.value || value.equals(otherEntry.value));
}
@@ -431,11 +431,11 @@ private static int MRIBucketIndex(final int h, final int length) {
private final synchronized void resize(int newCapacity) {
final RubyHashEntry[] oldTable = table;
final RubyHashEntry[] newTable = new RubyHashEntry[newCapacity];

for (int j = 0; j < oldTable.length; j++) {
RubyHashEntry entry = oldTable[j];
oldTable[j] = null;

while (entry != null) {
RubyHashEntry next = entry.next;
int i = bucketIndex(entry.hash, newCapacity);
@@ -444,7 +444,7 @@ private final synchronized void resize(int newCapacity) {
entry = next;
}
}

table = newTable;
}

@@ -458,11 +458,11 @@ private final void JavaSoftCheckResize() {
resizeAndAdjustThreshold(table);
}
}

private boolean overThreshold() {
return size > threshold;
}

private void resizeAndAdjustThreshold(RubyHashEntry[] oldTable) {
int newCapacity = oldTable.length << 1;
resize(newCapacity);
@@ -757,11 +757,11 @@ private void checkDefaultProcArity(IRubyObject proc) {
public IRubyObject set_default_proc(IRubyObject proc) {
return set_default_proc20(proc);
}

@JRubyMethod(name = "default_proc=")
public IRubyObject set_default_proc20(IRubyObject proc) {
modify();

if (proc.isNil()) {
ifNone = proc;
return proc;
@@ -800,14 +800,14 @@ public void visit(IRubyObject key, IRubyObject value) {
if (!firstEntry[0]) str.cat((byte)',').cat((byte)' ');

str.cat(inspect(context, key)).cat((byte)'=').cat((byte)'>').cat(inspect(context, value));

firstEntry[0] = false;
}
});
str.cat((byte)'}');
return str;
}

private IRubyObject inspectHash19(final ThreadContext context) {
final RubyString str = RubyString.newStringLight(context.runtime, DEFAULT_INSPECT_STR_SIZE, USASCIIEncoding.INSTANCE);
str.cat((byte)'{');
@@ -820,13 +820,13 @@ public void visit(IRubyObject key, IRubyObject value) {
if (!firstEntry[0]) str.cat((byte)',').cat((byte)' ');

str.cat19(inspect(context, key)).cat((byte)'=').cat((byte)'>').cat19(inspect(context, value));

firstEntry[0] = false;
}
});
str.cat((byte)'}');
return str;
}
}

/** rb_hash_inspect
*
@@ -945,7 +945,7 @@ public RubyHash rehash() {
public RubyHash to_hash() {
return this;
}

@JRubyMethod
public RubyHash to_h(ThreadContext context) {
return getType() == getRuntime().getHash() ? this : newHash(getRuntime()).replace(context, this);
@@ -963,7 +963,7 @@ public final void fastASet(IRubyObject key, IRubyObject value) {
public final void fastASetSmall(IRubyObject key, IRubyObject value) {
internalPutSmall(key, value);
}

public final void fastASetCheckString(Ruby runtime, IRubyObject key, IRubyObject value) {
if (key instanceof RubyString && !isComparedByIdentity()) {
op_asetForString(runtime, (RubyString) key, value);
@@ -1073,12 +1073,12 @@ public void visit(IRubyObject key, IRubyObject value) {
} catch (Mismatch e) {
return runtime.getFalse();
}

return runtime.getTrue();
}

/** rb_hash_equal
*
*
*/
@JRubyMethod(name = "==")
@Override
@@ -1087,7 +1087,7 @@ public IRubyObject op_equal(final ThreadContext context, IRubyObject other) {
}

/** rb_hash_eql
*
*
*/
@JRubyMethod(name = "eql?")
public IRubyObject op_eql19(final ThreadContext context, IRubyObject other) {
@@ -1104,9 +1104,9 @@ public IRubyObject op_aref(ThreadContext context, IRubyObject key) {
}

/** rb_hash_hash
*
*
*/
// FIXME:
// FIXME:
@Override
public RubyFixnum hash() {
final Ruby runtime = getRuntime();
@@ -1128,7 +1128,7 @@ public void visit(IRubyObject key, IRubyObject value) {
}

/** rb_hash_hash
*
*
*/
@JRubyMethod(name = "hash")
public RubyFixnum hash19() {
@@ -1161,30 +1161,30 @@ public void visit(IRubyObject key, IRubyObject value) {
*/
public IRubyObject fetch(ThreadContext context, IRubyObject[] args, Block block) {
Arity.checkArgumentCount(context.runtime, args.length, 1, 2);

switch(args.length) {
case 1: return fetch(context, args[0], block);
case 2: return fetch(context, args[0], args[1], block);
}

return null;
}

@JRubyMethod
public IRubyObject fetch(ThreadContext context, IRubyObject key, Block block) {
Ruby runtime = context.runtime;

IRubyObject value = internalGet(key);

if (value == null) {
if (block.isGiven()) return block.yield(context, key);

throw runtime.newKeyError("key not found: " + key);
}

return value;
}

@JRubyMethod
public IRubyObject fetch(ThreadContext context, IRubyObject key, IRubyObject _default, Block block) {
Ruby runtime = context.runtime;
@@ -1195,13 +1195,13 @@ public IRubyObject fetch(ThreadContext context, IRubyObject key, IRubyObject _de
}

IRubyObject value = internalGet(key);

if (value == null) {
if (blockGiven) return block.yield(context, key);

return _default;
}

return value;
}

@@ -1263,7 +1263,7 @@ public RubyBoolean has_value_p(ThreadContext context, IRubyObject expected) {
}

private volatile int iteratorCount;

private static final AtomicIntegerFieldUpdater<RubyHash> ITERATOR_UPDATER;
static {
AtomicIntegerFieldUpdater<RubyHash> iterUp = null;
@@ -1321,7 +1321,7 @@ public void visit(IRubyObject key, IRubyObject value) {
});
} else {
final Ruby runtime = context.runtime;

iteratorVisitAll(new Visitor() {
@Override
public void visit(IRubyObject key, IRubyObject value) {
@@ -1360,7 +1360,7 @@ public void visit(IRubyObject key, IRubyObject value) {
}
});

return this;
return this;
}

/** rb_hash_each_value
@@ -1413,11 +1413,11 @@ public IRubyObject keep_if(final ThreadContext context, final Block block) {
if (block.isGiven()) {
keep_ifCommon(context, block);
return this;
}
}

return enumeratorizeWithSize(context, this, "keep_if", enumSizeFn());
}

public boolean keep_ifCommon(final ThreadContext context, final Block block) {
testFrozen("Hash");
final boolean[] modified = {false};
@@ -1559,7 +1559,7 @@ public IRubyObject delete(ThreadContext context, IRubyObject key, Block block) {
if (entry != NO_ENTRY) return entry.value;

if (block.isGiven()) return block.yield(context, key);
return getRuntime().getNil();
return context.nil;
}

/** rb_hash_select
@@ -1585,7 +1585,7 @@ public void visit(IRubyObject key, IRubyObject value) {
}
});

return result;
return result;
}

/** rb_hash_delete_if
@@ -1686,7 +1686,7 @@ public RubyHash merge_bang(final ThreadContext context, final IRubyObject other,
public RubyHash merge_bang19(final ThreadContext context, final IRubyObject other, final Block block) {
modify();
final RubyHash otherHash = other.convertToHash();

if (otherHash.empty_p().isTrue()) return this;

final Ruby runtime = getRuntime();
@@ -1750,7 +1750,7 @@ public void visit(IRubyObject key, IRubyObject value) {

private RubyHash replaceCommon19(final ThreadContext context, IRubyObject other, Visitor visitor) {
modify();

final RubyHash otherHash = other.convertToHash();

if (this == otherHash) return this;
@@ -2358,13 +2358,13 @@ public boolean equals(Object o) {
ConvertingEntry other = (ConvertingEntry)o;
return entry.equals(other.entry);
}

@Override
public int hashCode() {
return entry.hashCode();
}
}

@Deprecated
public IRubyObject op_aset19(ThreadContext context, IRubyObject key, IRubyObject value) {
modify();
11 changes: 9 additions & 2 deletions core/src/main/java/org/jruby/RubyInstanceConfig.java
Original file line number Diff line number Diff line change
@@ -52,6 +52,7 @@
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
@@ -113,10 +114,10 @@ public RubyInstanceConfig() {

threadDumpSignal = Options.THREAD_DUMP_SIGNAL.load();

environment = new HashMap<String,String>();
try {
environment = System.getenv();
environment.putAll(System.getenv());
} catch (SecurityException se) {
environment = new HashMap<String,String>();
}
}

@@ -698,6 +699,12 @@ public void setEnvironment(Map newEnvironment) {
}

public Map getEnvironment() {
if (!new File(getJRubyHome()).exists() && !environment.containsKey("RUBY")) {
// the assumption that if JRubyHome is not a regular file that java.class.path
// is the one which launched jruby is probably wrong. but is sufficient for
// java -jar jruby-complete.jar
environment.put("RUBY", "java -cp " + System.getProperty("java.class.path") + " org.jruby.Main");
}
return environment;
}

8 changes: 4 additions & 4 deletions core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
@@ -2134,7 +2134,7 @@ public IRubyObject initialize(ThreadContext context, Block block) {
module_exec(context, new IRubyObject[] {this}, block);
}

return getRuntime().getNil();
return context.nil;
}

public void addReadWriteAttribute(ThreadContext context, String name) {
@@ -2186,7 +2186,7 @@ public IRubyObject attr_reader(ThreadContext context, IRubyObject[] args) {
addAccessor(context, args[i].asJavaString().intern(), visibility, true, false);
}

return context.runtime.getNil();
return context.nil;
}

/** rb_mod_attr_writer
@@ -2201,7 +2201,7 @@ public IRubyObject attr_writer(ThreadContext context, IRubyObject[] args) {
addAccessor(context, args[i].asJavaString().intern(), visibility, false, true);
}

return context.runtime.getNil();
return context.nil;
}


@@ -2226,7 +2226,7 @@ public IRubyObject attr_accessor(ThreadContext context, IRubyObject[] args) {
addAccessor(context, args[i].asJavaString().intern(), visibility, true, true);
}

return context.runtime.getNil();
return context.nil;
}

/**
694 changes: 380 additions & 314 deletions core/src/main/java/org/jruby/ext/bigdecimal/RubyBigDecimal.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
@@ -77,33 +77,33 @@ public abstract class JavaMethod extends DynamicMethod implements Cloneable, Met
{null, null, null, JavaMethodThreeOrNBlock.class},
};


public JavaMethod(RubyModule implementationClass, Visibility visibility) {
this(implementationClass, visibility, CallConfiguration.FrameFullScopeNone);
}

public JavaMethod(RubyModule implementationClass, Visibility visibility, CallConfiguration callConfig) {
super(implementationClass, visibility, callConfig);
}

public JavaMethod(RubyModule implementationClass, Visibility visibility, CallConfiguration callConfig, String name) {
super(implementationClass, visibility, callConfig, name);
}

protected JavaMethod() {}

public void init(RubyModule implementationClass, Arity arity, Visibility visibility, StaticScope staticScope, CallConfiguration callConfig) {
this.staticScope = staticScope;
this.arity = arity;
super.init(implementationClass, visibility, callConfig);
}

public DynamicMethod dup() {
try {
JavaMethod msm = (JavaMethod)clone();
return msm;
} catch (CloneNotSupportedException cnse) {
return null;
return (JavaMethod) super.clone();
}
catch (CloneNotSupportedException ex) {
throw new AssertionError(ex);
}
}

@@ -186,7 +186,7 @@ protected final void callTraceCompiled(ThreadContext context, boolean enabled, S
protected final void returnTraceCompiled(ThreadContext context, boolean enabled, String name) {
if (enabled) context.trace(RubyEvent.RETURN, name, getImplementationClass());
}

public void setArity(Arity arity) {
this.arity = arity;
}
@@ -195,23 +195,23 @@ public void setArity(Arity arity) {
public Arity getArity() {
return arity;
}

public void setJavaName(String javaName) {
this.javaName = javaName;
}

public String getJavaName() {
return javaName;
}

public void setSingleton(boolean isSingleton) {
this.isSingleton = isSingleton;
}

public boolean isSingleton() {
return isSingleton;
}

@Override
public boolean isNative() {
return true;
@@ -220,12 +220,12 @@ public boolean isNative() {
public StaticScope getStaticScope() {
return staticScope;
}

public void setParameterDesc(String parameterDesc) {
this.parameterDesc = parameterDesc;
this.parameterList = null;
}

public void setParameterList(String[] parameterList) {
this.parameterDesc = null;
this.parameterList = parameterList;
@@ -239,7 +239,7 @@ public String[] getParameterList() {
parameterList = new String[0];
}
}

return parameterList;
}

@@ -259,8 +259,7 @@ public void setCallerRequirement(CallConfiguration callerRequirement) {

protected static IRubyObject raiseArgumentError(JavaMethod method, ThreadContext context, String name, int given, int min, int max) {
Arity.raiseArgumentError(context.runtime, name, given, min, max);
// never reached
return context.runtime.getNil();
throw new AssertionError("expected to throw ArgumentError"); // never reached
}

protected static void checkArgumentCount(JavaMethod method, ThreadContext context, String name, IRubyObject[] args, int num) {
@@ -590,12 +589,14 @@ public JavaMethodOneOrTwoOrThreeBlock(RubyModule implementationClass, Visibility

public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
switch (args.length) {
case 0:
throw context.runtime.newArgumentError(0, 1);
case 1: return call(context, self, clazz, name, args[0], block);
case 2: return call(context, self, clazz, name, args[0], args[1], block);
case 3: return call(context, self, clazz, name, args[0], args[1], args[2], block);
default: return raiseArgumentError(this, context, name, args.length, 3, 3);
case 1:
return call(context, self, clazz, name, args[0], block);
case 2:
return call(context, self, clazz, name, args[0], args[1], block);
case 3:
return call(context, self, clazz, name, args[0], args[1], args[2], block);
default:
return raiseArgumentError(this, context, name, args.length, 1, 3);
}
}
}
@@ -722,7 +723,7 @@ public JavaMethodZeroOrOneOrN(RubyModule implementationClass, Visibility visibil
public JavaMethodZeroOrOneOrN(RubyModule implementationClass, Visibility visibility, CallConfiguration callConfig) {
super(implementationClass, visibility, callConfig);
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, Block block) {
return call(context, self, clazz, name, arg0);
@@ -778,7 +779,7 @@ public JavaMethodOneOrN(RubyModule implementationClass, Visibility visibility, C
public JavaMethodOneOrN(RubyModule implementationClass, Visibility visibility, CallConfiguration callConfig, String name) {
super(implementationClass, visibility, callConfig, name);
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, Block block) {
return call(context, self, clazz, name, arg0);
10 changes: 6 additions & 4 deletions core/src/main/java/org/jruby/javasupport/Java.java
Original file line number Diff line number Diff line change
@@ -1149,10 +1149,12 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz
}
final RubyProc proc = (RubyProc) self;
final IRubyObject[] newArgs;
if ( args.length == 1 ) newArgs = IRubyObject.NULL_ARRAY;
else {
newArgs = new IRubyObject[ args.length - 1 ];
System.arraycopy(args, 1, newArgs, 0, newArgs.length);
switch( args.length ) {
case 1 : newArgs = IRubyObject.NULL_ARRAY; break;
case 2 : newArgs = new IRubyObject[] { args[0] }; break;
case 3 : newArgs = new IRubyObject[] { args[0], args[1] }; break;
default : newArgs = new IRubyObject[ args.length - 1 ];
System.arraycopy(args, 1, newArgs, 0, newArgs.length);
}
return proc.call(context, newArgs);
}
5 changes: 1 addition & 4 deletions core/src/main/java/org/jruby/javasupport/JavaUtil.java
Original file line number Diff line number Diff line change
@@ -216,10 +216,7 @@ public static IRubyObject convertJavaArrayElementToRuby(Ruby runtime, JavaConver
}

public static Class<?> primitiveToWrapper(final Class<?> type) {
if (type.isPrimitive()) {
return CodegenUtils.getBoxType(type);
}
return type;
return type.isPrimitive() ? CodegenUtils.getBoxType(type) : type;
}

@SuppressWarnings("unchecked")
12 changes: 10 additions & 2 deletions core/src/main/java/org/jruby/util/ShellLauncher.java
Original file line number Diff line number Diff line change
@@ -1432,8 +1432,16 @@ public static Process run(Ruby runtime, IRubyObject[] rawArgs, boolean doExecuta
log(runtime, "Launching directly (no shell)");
cfg.verifyExecutableForDirect();
}

aProcess = buildProcess(runtime, cfg.getExecArgs(), getCurrentEnv(runtime), pwd);
String[] args = cfg.execArgs;
// only if we inside a jar and spawning org.jruby.Main we
// change to the current directory inside the jar
if (runtime.getCurrentDirectory().startsWith("uri:classloader:") &&
args[args.length - 1].contains("org.jruby.Main")) {
pwd = new File(System.getProperty("user.dir"));
args[args.length - 1] = args[args.length - 1].replace("org.jruby.Main",
"org.jruby.Main -C " + runtime.getCurrentDirectory());
}
aProcess = buildProcess(runtime, args, getCurrentEnv(runtime), pwd);
}
} catch (SecurityException se) {
throw runtime.newSecurityError(se.getLocalizedMessage());
28 changes: 23 additions & 5 deletions core/src/main/java/org/jruby/util/URLResource.java
Original file line number Diff line number Diff line change
@@ -150,12 +150,16 @@ public Channel openChannel( ModeFlags flags, int perm ) throws ResourceException
}

public static FileResource create(ClassLoader cl, String pathname, boolean isFile) {
// fall back on thread context classloader
if (cl == null ) {
cl = Thread.currentThread().getContextClassLoader();
}
try
{
pathname = new URI(pathname.replaceFirst("^/*", "/")).normalize().getPath().replaceAll("^/([.][.]/)*", "");
} catch (URISyntaxException e) {
{
pathname = new URI(pathname.replaceFirst("^/*", "/")).normalize().getPath().replaceAll("^/([.][.]/)*", "");
} catch (URISyntaxException e) {
pathname = pathname.replaceAll("^[.]?/*", "");
}
}
URL url = cl.getResource(pathname);
String[] files = isFile ? null : listClassLoaderFiles(cl, pathname);
return new URLResource(URI_CLASSLOADER + "/" + pathname,
@@ -164,10 +168,24 @@ public static FileResource create(ClassLoader cl, String pathname, boolean isFil
files);
}

public static FileResource create(ClassLoader cl, String pathname) {
return create(cl, pathname, true);
}

public static FileResource createClassloaderURI(Ruby runtime, String pathname, boolean isFile) {
return create(runtime.getJRubyClassLoader(), pathname, isFile);
// retrieve the classloader from the runtime if available otherwise mimic how the runtime got its classloader and
// take this
ClassLoader cl = runtime != null ? runtime.getJRubyClassLoader() : URLResource.class.getClassLoader();
return create(cl, pathname, isFile);
}

// public static FileResource createClassloaderURI(Ruby runtime, String pathname) {
// // retrieve the classloader from the runtime if available otherwise mimic how the runtime got its classloader and
// // take this
// ClassLoader cl = runtime != null ? runtime.getJRubyClassLoader() : URLResource.class.getClassLoader();
// return create(cl, pathname);
// }

public static FileResource create(Ruby runtime, String pathname, boolean isFile)
{
if (!pathname.startsWith(URI)) {
30 changes: 15 additions & 15 deletions core/src/test/java/org/jruby/util/URLResourceTest.java
Original file line number Diff line number Diff line change
@@ -7,22 +7,22 @@
import junit.framework.TestCase;

public class URLResourceTest extends TestCase {
public void testDirectory(){

public void testDirectory(){
String uri = Thread.currentThread().getContextClassLoader().getResource( "somedir" ).toExternalForm();
FileResource resource = URLResource.create(Ruby.getGlobalRuntime(), "uri:" + uri, false);
FileResource resource = URLResource.create((Ruby) null, "uri:" + uri, false);

assertNotNull(resource );
assertFalse(resource.isFile());
assertTrue(resource.isDirectory());
assertTrue(resource.exists());
assertEquals(Arrays.asList(resource.list()),
assertEquals(Arrays.asList(resource.list()),
Arrays.asList(new String[] {".", "dir_without_listing", "dir_with_listing"}));
}

public void testNoneDirectory(){
String uri = Thread.currentThread().getContextClassLoader().getResource( "somedir/dir_without_listing" ).toExternalForm();
FileResource resource = URLResource.create(Ruby.getGlobalRuntime(), "uri:" + uri, false);
FileResource resource = URLResource.create((Ruby) null, "uri:" + uri, false);

assertNotNull(resource );
// you can open streams on file-system directories
@@ -34,20 +34,20 @@ public void testNoneDirectory(){

public void testFile(){
String uri = Thread.currentThread().getContextClassLoader().getResource( "somedir/.jrubydir" ).toExternalForm();
FileResource resource = URLResource.create(Ruby.getGlobalRuntime(), "uri:" + uri, false);
FileResource resource = URLResource.create((Ruby) null, "uri:" + uri, false);

assertNotNull(resource );
// you can open streams on file-system directories
assertTrue(resource.isFile());
assertTrue(resource.exists());
assertFalse(resource.isDirectory());
assertNull(resource.list());
}

public void testNonExistingFile(){
String uri = Thread.currentThread().getContextClassLoader().getResource( "somedir" ).toExternalForm();
FileResource resource = URLResource.create(Ruby.getGlobalRuntime(), "uri:" + uri + "/not_there", false);
FileResource resource = URLResource.create((Ruby) null, "uri:" + uri + "/not_there", false);

assertNotNull(resource );
assertFalse(resource.isFile());
assertFalse(resource.exists());
@@ -57,7 +57,7 @@ public void testNonExistingFile(){

public void testDirectoryClassloader()
{
FileResource resource = URLResource.create(Ruby.getGlobalRuntime(),
FileResource resource = URLResource.create((Ruby) null,
"uri:classloader:/somedir", false);

assertNotNull( resource );
@@ -71,7 +71,7 @@ public void testDirectoryClassloader()

public void testNoneDirectoryClassloader()
{
FileResource resource = URLResource.create(Ruby.getGlobalRuntime(),
FileResource resource = URLResource.create((Ruby) null,
"uri:classloader:/somedir/dir_without_listing", false);

assertNotNull( resource );
@@ -84,7 +84,7 @@ public void testNoneDirectoryClassloader()

public void testFileClassloader()
{
FileResource resource = URLResource.create(Ruby.getGlobalRuntime(),
FileResource resource = URLResource.create((Ruby) null,
"uri:classloader:/somedir/.jrubydir", false );

assertNotNull( resource );
@@ -97,7 +97,7 @@ public void testFileClassloader()

public void testNonExistingFileClassloader()
{
FileResource resource = URLResource.create(Ruby.getGlobalRuntime(),
FileResource resource = URLResource.create((Ruby) null,
"uri:classloader:/somedir/not_there", false );

assertNotNull( resource );
32 changes: 16 additions & 16 deletions lib/ruby/stdlib/uri/generic.rb
Original file line number Diff line number Diff line change
@@ -1550,24 +1550,24 @@ def find_proxy
end

def http_proxy_from_env
proxy_uri = ENV['http_proxy']
proxy_host = ENV_JAVA['http.proxyHost']

if proxy_uri.nil? && (proxy_uri = ENV['HTTP_PROXY'])
warn 'The environment variable HTTP_PROXY is discouraged. Use http_proxy.'
if proxy_host
begin
proxy_port = (ENV_JAVA['http.proxyPort'] || 80).to_i
if proxy_port > 0
proxy_uri = "http://#{proxy_host}:#{proxy_port}"
else
warn "invalid http.proxyPort property: #{ENV_JAVA['http.proxyPort']}"
end
end
end

if proxy_uri.nil? || proxy_uri.empty?
proxy_host = ENV_JAVA['http.proxyHost']
proxy_uri = ENV['http_proxy']

if proxy_host
begin
proxy_port = (ENV_JAVA['http.proxyPort'] || 80).to_i
if proxy_port > 0
proxy_uri = "http://#{proxy_host}:#{proxy_port}"
else
warn "invalid http.proxyPort property: #{ENV_JAVA['http.proxyPort']}"
end
end
if proxy_uri.nil? && (proxy_uri = ENV['HTTP_PROXY'])
warn 'The environment variable HTTP_PROXY is discouraged. Use http_proxy.'
end
end

@@ -1577,11 +1577,11 @@ def http_proxy_from_env

DEFAULT_JVM_NON_PROXY_HOSTS = "local|*.local|169.254/16|*.169.254/16|127.0.0.1|localhost|*.localhost"
def no_proxy_from_env
name = "no_proxy"
no_proxy = ENV[name] || ENV[name.upcase]
no_proxy = ENV_JAVA['http.nonProxyHosts']

if no_proxy.nil? || no_proxy.empty?
no_proxy = ENV_JAVA['http.nonProxyHosts']
name = "no_proxy"
no_proxy = ENV[name] || ENV[name.upcase]
end

no_proxy
35 changes: 35 additions & 0 deletions maven/jruby-complete/src/it/extended/Mavenfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#-*- mode: ruby -*-

properties( 'polyglot.dump.pom' => 'pom.xml',
'jruby.version' => '@project.version@',
'jruby.version' => '1.7.21-SNAPSHOT',
'jruby.plugins.version' => '1.0.8',
'jruby.home' => '${basedir}/../../../../..' )

phase :package do
plugin :dependency do
execute_goal( :copy,
:artifactItems => [ {
:groupId => 'org.jruby',
:artifactId => 'jruby-complete',
:version => '${jruby.version}'
} ] )
end

plugin( 'org.codehaus.mojo:exec-maven-plugin:1.2',
:executable => 'java',
:environmentVariables => {
'GEM_PATH' => '${jruby.home}/lib/ruby/gems/shared',
'GEM_HOME' => '${jruby.home}/lib/ruby/gems/shared'
},
:basedir => '${jruby.home}' ) do

execute_goal( :exec, :id => 'rake -T',
:arguments => [ '-jar', '${project.build.directory}/dependency/jruby-complete-${jruby.version}.jar', '-S', 'rake', '-T' ] )

execute_goal( :exec, :id => 'rake test:mri',
:arguments => [ '-jar', '${project.build.directory}/dependency/jruby-complete-${jruby.version}.jar', '-S', 'rake', 'test:mri' ] )

end
end

86 changes: 86 additions & 0 deletions maven/jruby-complete/src/it/extended/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>no_group_id_given</groupId>
<artifactId>extended</artifactId>
<version>0.0.0</version>
<name>extended</name>
<properties>
<jruby.home>${basedir}/../../../../..</jruby.home>
<jruby.version>1.7.21-SNAPSHOT</jruby.version>
<jruby.plugins.version>1.0.8</jruby.plugins.version>
<polyglot.dump.pom>pom.xml</polyglot.dump.pom>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.jruby</groupId>
<artifactId>jruby-complete</artifactId>
<version>${jruby.version}</version>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>rake -T</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<arguments>
<argument>-jar</argument>
<argument>${project.build.directory}/dependency/jruby-complete-${jruby.version}.jar</argument>
<argument>-S</argument>
<argument>rake</argument>
<argument>-T</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>rake test:mri</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<arguments>
<argument>-jar</argument>
<argument>${project.build.directory}/dependency/jruby-complete-${jruby.version}.jar</argument>
<argument>-S</argument>
<argument>rake</argument>
<argument>test:mri</argument>
</arguments>
</configuration>
</execution>
</executions>
<configuration>
<executable>java</executable>
<environmentVariables>
<GEM_PATH>${jruby.home}/lib/ruby/gems/shared</GEM_PATH>
<GEM_HOME>${jruby.home}/lib/ruby/gems/shared</GEM_HOME>
</environmentVariables>
<basedir>${jruby.home}</basedir>
</configuration>
</plugin>
</plugins>
</build>
</project>
154 changes: 150 additions & 4 deletions maven/jruby/src/it/integrity/pom.xml
Original file line number Diff line number Diff line change
@@ -157,8 +157,154 @@
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<execution>
<id>jruby classpath:hello.rb</id>
<phase>test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath/>
<argument>org.jruby.Main</argument>
<argument>classpath:hello.rb</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>jruby classpath:/hello.rb</id>
<phase>test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath/>
<argument>org.jruby.Main</argument>
<argument>classpath:/hello.rb</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>jruby uri:classloader:/hello.rb</id>
<phase>test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath/>
<argument>org.jruby.Main</argument>
<argument>uri:classloader:/hello.rb</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>jruby uri:classloader://hello.rb</id>
<phase>test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath/>
<argument>org.jruby.Main</argument>
<argument>uri:classloader://hello.rb</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>jruby -C uri:classloader:// hello.rb</id>
<phase>test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath/>
<argument>org.jruby.Main</argument>
<argument>-C</argument>
<argument>uri:classloader://</argument>
<argument>hello.rb</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>jruby jar:file://hello.jar!/helo.rb</id>
<phase>test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath/>
<argument>org.jruby.Main</argument>
<argument>jar:file://${project.build.outputDirectory}/hello.jar!/helo.rb</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>jruby file://hello.jar!/helo.rb</id>
<phase>test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath/>
<argument>org.jruby.Main</argument>
<argument>file://${project.build.outputDirectory}/hello.jar!/helo.rb</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>jruby file://hello.rb</id>
<phase>test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath/>
<argument>org.jruby.Main</argument>
<argument>file://${project.build.outputDirectory}/hello.rb</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>jruby hello.rb</id>
<phase>test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath/>
<argument>org.jruby.Main</argument>
<argument>${project.build.outputDirectory}/hello.rb</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Binary file not shown.
1 change: 1 addition & 0 deletions maven/jruby/src/it/integrity/src/main/resources/hello.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
puts "hello #{__FILE__}"
23 changes: 23 additions & 0 deletions maven/jruby/src/it/integrity/verify.bsh
Original file line number Diff line number Diff line change
@@ -43,3 +43,26 @@ if ( !log.contains( expected ) )
{
throw new RuntimeException( "log file does not contain '" + expected + "'" );
}

// we are already OK if those scripts execute and there a duplicates which do
// get checked here
expected = "hello classpath:hello.rb";
if ( !log.contains( expected ) ) throw new RuntimeException( "log file does not contain '" + expected + "'" );

expected = "hello classpath:/hello.rb";
if ( !log.contains( expected ) ) throw new RuntimeException( "log file does not contain '" + expected + "'" );

expected = "hello uri:classloader:/hello.rb";
if ( !log.contains( expected ) ) throw new RuntimeException( "log file does not contain '" + expected + "'" );

expected = "hello uri:classloader://hello.rb";
if ( !log.contains( expected ) ) throw new RuntimeException( "log file does not contain '" + expected + "'" );

expected = "hello hello.rb";
if ( !log.contains( expected ) ) throw new RuntimeException( "log file does not contain '" + expected + "'" );

expected = "maven/jruby/target/it/integrity/target/classes/hello.jar!/helo.rb";
if ( !log.contains( expected ) ) throw new RuntimeException( "log file does not contain '" + expected + "'" );

expected = "maven/jruby/target/it/integrity/target/classes/hello.rb";
if ( !log.contains( expected ) ) throw new RuntimeException( "log file does not contain '" + expected + "'" );
8 changes: 5 additions & 3 deletions maven/jruby/src/it/runnable/Mavenfile
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ gem 'bundler', '1.7.7'

pom 'org.jruby:jruby', '${jruby.version}'

jar 'de.saumya.mojo:jruby-mains', '0.1.0'
jar 'de.saumya.mojo:jruby-mains', '0.2.0'

build do
directory 'pkg'
@@ -63,7 +63,6 @@ phase :package do
plugin( 'org.codehaus.mojo:exec-maven-plugin:1.2',
:executable => 'java',
:environmentVariables => {
'PATH' => '${basedir}',
'HOME' => '${basedir}',
'GEM_PATH' => '${basedir}',
'GEM_HOME' => '${basedir}'
@@ -72,9 +71,12 @@ phase :package do
execute_goal( :exec, :id => 'rake -T',
:arguments => [ '-jar', 'runnable.jar', '-S', 'rake', '-T' ] )

execute_goal( :exec, :id => 'rake spec',
:arguments => [ '-jar', 'runnable.jar', '-S', 'rake', 'spec' ] )

execute_goal( :exec, :id => 'rspec',
:arguments => [ '-jar', 'runnable.jar', '-S', 'rspec' ] )

end
end

4 changes: 3 additions & 1 deletion maven/jruby/src/it/runnable/Rakefile
Original file line number Diff line number Diff line change
@@ -12,4 +12,6 @@ require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)

task :default => :spec
task :default => :spec

puts "#{__FILE__} #{ARGV.inspect}"
19 changes: 17 additions & 2 deletions maven/jruby/src/it/runnable/pom.xml
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@
<dependency>
<groupId>de.saumya.mojo</groupId>
<artifactId>jruby-mains</artifactId>
<version>0.1.0</version>
<version>0.2.0</version>
</dependency>
</dependencies>
<repositories>
@@ -216,11 +216,26 @@
</arguments>
</configuration>
</execution>
<execution>
<id>rake spec</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<arguments>
<argument>-jar</argument>
<argument>runnable.jar</argument>
<argument>-S</argument>
<argument>rake</argument>
<argument>spec</argument>
</arguments>
</configuration>
</execution>
</executions>
<configuration>
<executable>java</executable>
<environmentVariables>
<PATH>${basedir}</PATH>
<HOME>${basedir}</HOME>
<GEM_PATH>${basedir}</GEM_PATH>
<GEM_HOME>${basedir}</GEM_HOME>
6 changes: 5 additions & 1 deletion maven/jruby/src/it/runnable/spec/one_spec.rb
Original file line number Diff line number Diff line change
@@ -2,11 +2,15 @@

describe "something" do
it "does something" do
__FILE__.should == 'uri:classloader:/spec/one_spec.rb'
$CLASSPATH.size.should == 6
Jars.home.should == 'uri:classloader://'
Dir.pwd.should == 'uri:classloader://'
$LOAD_PATH.each do |lp|
lp.should =~ /^uri:classloader:|runnable.jar!\//
# bundler or someone else messes up the $LOAD_PATH
unless ["uri", "classloader", "//gems/bundler-1.7.7/lib"].member?( lp )
lp.should =~ /^uri:classloader:|runnable.jar!\//
end
end
end
end
40 changes: 0 additions & 40 deletions maven/jruby/src/it/runnable/src/main/java/Main.java

This file was deleted.

11 changes: 7 additions & 4 deletions maven/jruby/src/it/runnable/verify.bsh
Original file line number Diff line number Diff line change
@@ -4,7 +4,10 @@ import org.codehaus.plexus.util.FileUtils;

String log = FileUtils.fileRead( new File( basedir, "build.log" ) );
String expected = "Run RSpec code examples";
if ( !log.contains( expected ) )
{
throw new RuntimeException( "log file does not contain '" + expected + "'" );
}
if ( !log.contains( expected ) ) throw new RuntimeException( "log file does not contain '" + expected + "'" );

expected = "uri:classloader:/Rakefile []";
if ( !log.contains( expected ) ) throw new RuntimeException( "log file does not contain '" + expected + "'" );

expected = "uri:classloader:/Rakefile [\"spec\"]";
if ( !log.contains( expected ) ) throw new RuntimeException( "log file does not contain '" + expected + "'" );
Empty file added test/jruby/relative.rb
Empty file.
1 change: 1 addition & 0 deletions test/jruby/require_relative.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative 'relative'
8 changes: 7 additions & 1 deletion test/jruby/test_backquote.rb
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@ def test_empty_backquotes
assert_raise(Errno::ENOENT) {``}
assert_raise(Errno::ENOENT) {` `}
assert_raise(Errno::ENOENT) {`\n`}
# pend "#{__method__}: `\\n` does not raise Errno::ENOENT as expected"
else # we just check that empty backquotes won't blow up JRuby
`` rescue nil
` ` rescue nil
@@ -49,10 +50,15 @@ def test_backquotes_with_redirects_pass_through_shell

assert_equal "arguments: one two\n", `./arguments one two 2> /dev/null`
assert_equal "", `./arguments three four > /dev/null`
ruby = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
# ruby = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
assert_equal "arguments: five six\n", jruby(%{-e 'puts "arguments: five six"' 2> /dev/null})
end
ensure
File.delete("arguments") rescue nil
end

private

def pend(msg); warn msg end unless method_defined? :pend

end
192 changes: 152 additions & 40 deletions test/jruby/test_big_decimal.rb
Original file line number Diff line number Diff line change
@@ -15,12 +15,12 @@ def test_no_singleton_methods_on_bigdecimal
assert_raise(TypeError) { class << num ; def amethod ; end ; end }
assert_raise(TypeError) { def num.amethod ; end }
end

def test_can_instantiate_big_decimal
assert_nothing_raised {BigDecimal.new("4")}
assert_nothing_raised {BigDecimal.new("3.14159")}
end

def test_can_implicitly_instantiate_big_decimal
# JRUBY-153 issues
assert_nothing_raised {BigDecimal("4")}
@@ -32,21 +32,61 @@ def test_alphabetic_args_return_zero
'Big Decimal objects instanitiated with a value that starts
with a letter should have a value of 0.0' )
end

class X
def to_str; "3.14159" end
end

def test_can_accept_arbitrary_objects_as_arguments
# as log as the object has a #to_str method...
x = X.new
assert_nothing_raised { BigDecimal.new(x) }
assert_nothing_raised { BigDecimal(x) }
end


def test_cmp
begin
BigDecimal.new('10') < "foo"
rescue ArgumentError => e
assert_equal 'comparison of BigDecimal with String failed', e.message
else
fail 'expected cmp to fail'
end

begin
BigDecimal.new('10') >= nil
rescue ArgumentError => e
assert_equal 'comparison of BigDecimal with nil failed', e.message
else
fail 'expected cmp to fail'
end
end

class MyNum
def *(other)
33
end

def /(other)
99
end

def coerce(other)
[MyNum.new, self]
end
end

def test_coerce_div_mul
require 'bigdecimal/util'

assert_equal 33, BigDecimal.new('10') * MyNum.new
assert_equal 99, 10.0 / MyNum.new
assert_equal 99, 10.0.to_d / MyNum.new
end

require "bigdecimal/newton"
include Newton

class Function
def initialize()
@zero = BigDecimal::new("0.0")
@@ -69,7 +109,7 @@ def values(x) # <= defines functions solved
f
end
end

def test_newton_extension
f = BigDecimal::limit(100)
f = Function.new
@@ -79,10 +119,10 @@ def test_newton_extension
BigDecimal('0.1000000000262923315461642086010446338567975310185638386446002778855192224707966221794469725479649528E1')]
assert_equal expected, x
end

require "bigdecimal/math.rb"
include BigMath

def test_math_extension
expected = BigDecimal('0.31415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066453462141417033006060218E1')
# this test fails under C Ruby
@@ -93,7 +133,7 @@ def test_math_extension
one = BigDecimal("1")
two = BigDecimal("2")
three = BigDecimal("3")

assert_equal one * 1, one
assert_equal one / 1, one
assert_equal one + 1, two
@@ -103,25 +143,25 @@ def test_math_extension
assert_equal one, three % two
assert_equal BigDecimal("0.2"), BigDecimal("2.2") % two
assert_equal BigDecimal("0.003"), BigDecimal("15.993") % BigDecimal("15.99")

assert_equal 1*one, one
assert_equal 1/one, one
assert_equal 1+one, BigDecimal("2")
assert_equal 1-one, BigDecimal("0")

assert_equal one * 1.0, 1.0
assert_equal one / 1.0, 1.0
assert_equal one + 1.0, 2.0
assert_equal one - 1.0, 0.0

assert_equal 1.0*one, 1.0
assert_equal 1.0/one, 1.0
assert_equal 1.0+one, 2.0
assert_equal 1.0-one, 0.0

assert_equal("1.0", BigDecimal.new('1.0').to_s('F'))
assert_equal("0.0", BigDecimal.new('0.0').to_s)

assert_equal(BigDecimal("2"), BigDecimal("1.5").round)
assert_equal(BigDecimal("15"), BigDecimal("15").round)
assert_equal(BigDecimal("20"), BigDecimal("15").round(-1))
@@ -130,7 +170,7 @@ def test_math_extension
assert_equal(BigDecimal("10"), BigDecimal("15").round(-1, BigDecimal::ROUND_HALF_DOWN))
assert_equal(BigDecimal("20"), BigDecimal("25").round(-1, BigDecimal::ROUND_HALF_EVEN))
assert_equal(BigDecimal("15.99"), BigDecimal("15.993").round(2))

assert_equal(BigDecimal("1"), BigDecimal("1.8").round(0, BigDecimal::ROUND_DOWN))
assert_equal(BigDecimal("2"), BigDecimal("1.2").round(0, BigDecimal::ROUND_UP))
assert_equal(BigDecimal("-1"), BigDecimal("-1.5").round(0, BigDecimal::ROUND_CEILING))
@@ -140,63 +180,92 @@ def test_math_extension
assert_equal(BigDecimal("2"), BigDecimal("1.5").round(0, BigDecimal::ROUND_HALF_EVEN))
assert_equal(BigDecimal("2"), BigDecimal("2.5").round(0, BigDecimal::ROUND_HALF_EVEN))
end

def test_big_decimal_power
require 'bigdecimal/math'

n = BigDecimal("10")
assert_equal(n.power(0), BigDecimal("1"))
assert_equal(n.power(1), n)
assert_equal(n.power(2), BigDecimal("100"))
assert_equal(n.power(-1), BigDecimal("0.1"))
assert_raises(TypeError) { n.power(1.1) }

n.power(1.1)

begin
n.power('1.1')
rescue TypeError => e
assert_equal 'wrong argument type String (expected scalar Numeric)', e.message
else
fail 'expected to raise TypeError'
end

assert_equal BigDecimal('0.1E2'), n.power(1.0)

res = n.power(1.1)
#assert_equal BigDecimal('0.125892541E2'), res
# NOTE: we're not handling precision the same as MRI with pow
assert_equal '0.125892541', res.to_s[0..10]
assert_equal 'E2', res.to_s[-2..-1]

res = 2 ** BigDecimal(1.2, 2)
#assert_equal BigDecimal('0.229739671E1'), res
# NOTE: we're not handling precision the same as MRI with pow
assert_equal '0.22973967', res.to_s[0..9]
assert_equal 'E1', res.to_s[-2..-1]

res = BigDecimal(1.2, 2) ** 2.0
assert_equal BigDecimal('0.144E1'), res

end

def test_big_decimal_mode
# Accept valid arguments to #mode
assert BigDecimal.mode(BigDecimal::EXCEPTION_OVERFLOW)
assert BigDecimal.mode(BigDecimal::EXCEPTION_OVERFLOW,true)
assert BigDecimal.mode(BigDecimal::EXCEPTION_OVERFLOW,false)

# Reject invalid arguments to #mode
assert_raises(TypeError) { BigDecimal.mode(true) } # first argument must be a Fixnum
assert_raises(ArgumentError) { BigDecimal.mode(BigDecimal::EXCEPTION_OVERFLOW, 1) } # second argument must be [true|false]
assert_raises(TypeError) { BigDecimal.mode(512) } # first argument must be == 256, or return non-zero when AND-ed with 255

# exception mode defaults to 0
assert_equal 0, BigDecimal.mode(1) # value of first argument doesn't matter when retrieving the current exception mode, as long as it's a Fixnum <= 255

# set and clear a single exception mode
assert_equal BigDecimal::EXCEPTION_INFINITY, BigDecimal.mode(BigDecimal::EXCEPTION_INFINITY, true)
assert_equal 0, BigDecimal.mode(BigDecimal::EXCEPTION_INFINITY, false)
assert_equal BigDecimal::EXCEPTION_NaN, BigDecimal.mode(BigDecimal::EXCEPTION_NaN, true)
assert_equal 0, BigDecimal.mode(BigDecimal::EXCEPTION_NaN, false)

# set a composition of exception modes separately, make sure the final result is the composited value
BigDecimal.mode(BigDecimal::EXCEPTION_INFINITY, true)
BigDecimal.mode(BigDecimal::EXCEPTION_NaN, true)
assert_equal BigDecimal::EXCEPTION_INFINITY | BigDecimal::EXCEPTION_NaN, BigDecimal.mode(1)

# reset the exception mode to 0 for the following tests
BigDecimal.mode(BigDecimal::EXCEPTION_INFINITY, false)
BigDecimal.mode(BigDecimal::EXCEPTION_NaN, false)

# set a composition of exception modes with one call and retrieve it using the retrieval idiom
# note: this is to check compatibility with MRI, which currently sets only the last mode
# it checks for
BigDecimal.mode(BigDecimal::EXCEPTION_INFINITY | BigDecimal::EXCEPTION_NaN, true)
assert_equal BigDecimal::EXCEPTION_NaN, BigDecimal.mode(1)

# rounding mode defaults to BigDecimal::ROUND_HALF_UP
assert_equal BigDecimal::ROUND_HALF_UP, BigDecimal.mode(BigDecimal::ROUND_MODE)

# make sure each setting complete replaces any previous setting
[BigDecimal::ROUND_UP, BigDecimal::ROUND_DOWN, BigDecimal::ROUND_CEILING, BigDecimal::ROUND_FLOOR,
BigDecimal::ROUND_HALF_UP, BigDecimal::ROUND_HALF_DOWN, BigDecimal::ROUND_HALF_EVEN].each do |mode|
assert_equal mode, BigDecimal.mode(BigDecimal::ROUND_MODE, mode)
end

# reset rounding mode to 0 for following tests
BigDecimal.mode(BigDecimal::ROUND_MODE, BigDecimal::ROUND_HALF_UP)

assert_raises(TypeError) { BigDecimal.mode(BigDecimal::ROUND_MODE, true) } # second argument must be a Fixnum
assert_raises(ArgumentError) { BigDecimal.mode(BigDecimal::ROUND_MODE, 8) } # any Fixnum >= 8 should trigger this error, as the valid rounding modes are currently [0..6]
end
@@ -207,7 +276,7 @@ def test_marshaling
bd_serialized = Marshal.dump(bd)
assert_equal f, Marshal.restore(bd_serialized).to_f
end

#JRUBY-2272
def test_marshal_regression
assert_equal BigDecimal('0.0'), Marshal.load(Marshal.dump(BigDecimal.new('0.0')))
@@ -223,31 +292,74 @@ def test_large_bigdecimal_to_f
assert neg_inf < 0
assert BigDecimal.new("5E-69999999").to_f < Float::EPSILON
end

#JRUBY-3818
def test_decimal_format
require 'java'
format = java.text.DecimalFormat.new("#,##0.00")
locale_separator = java.text.DecimalFormatSymbols.new().getDecimalSeparator()
value = java.math.BigDecimal.new("10")
assert_equal "10" + locale_separator.chr + "00", format.format(value)

def test_infinity
assert_equal true, BigDecimal.new("0.0000000001").finite?

#if RUBY_VERSION > '1.9'
# assert_raises(FloatDomainError) { BigDecimal("Infinity") }
# assert_raises(FloatDomainError) { BigDecimal("+Infinity") }
# assert_raises(FloatDomainError) { BigDecimal("-Infinity") }
#else
assert_equal 1, BigDecimal("Infinity").infinite?
assert_equal false, BigDecimal("-Infinity").finite?
assert_equal false, BigDecimal("+Infinity").finite?
#end

assert_raises(TypeError) { BigDecimal(:"+Infinity") }

assert_equal BigDecimal('0'), BigDecimal("infinity")
assert_equal BigDecimal('0'), BigDecimal("+Infinit")
end

#JRUBY-5190
def test_large_precisions
def test_large_precisions
a = BigDecimal("1").div(BigDecimal("3"), 307)
b = BigDecimal("1").div(BigDecimal("3"), 308)
assert_equal a.to_f, b.to_f
end

# GH-644, GH-648
def test_div_by_float_precision_gh644
a = BigDecimal.new(11023)/2.2046
a = BigDecimal.new(11023) / 2.2046
assert_equal 5_000, a.to_f
end

def test_div_by_float_precision_gh648
b = BigDecimal.new(1.05, 10)/1.48
b = BigDecimal.new(1.05, 10) / 1.48
assert (b.to_f - 0.7094594594594595) < Float::EPSILON
end

def test_GH_2650
assert_equal(BigDecimal.new("10.91231", 1).to_f, 10.91231)
assert_equal(BigDecimal.new("10.9", 2).to_f, 10.9)
end

class BigDeci < BigDecimal

# MRI does not invoke initialize on 1.8./1.9
def initialize(arg); raise super(arg.to_s) end

def abs; -super end
def infinite?; false end

end

def test_subclass
a = BigDeci.new 1.to_s
assert_equal -1, a.abs
assert_equal false, a.infinite?

a = BigDeci.new '-100'
assert_equal -5, a.div(20)
assert_equal -100, a.abs

assert a.inspect.index('#<BigDecimal:')
assert_equal '-0.1E3', a.to_s

assert_equal BigDeci, a.class
assert a.is_a?(BigDeci)
assert a.kind_of?(BigDeci)
end

end
28 changes: 15 additions & 13 deletions test/jruby/test_dir.rb
Original file line number Diff line number Diff line change
@@ -135,22 +135,21 @@ def test_chdir_and_pwd
pwd.gsub! '\\', '/'
assert_equal("testDir_4", pwd.split("/")[-1].strip)
end

# FIXME: does not pass in 2.0 mode
# pwd = `java -cp "#{java_test_classes}" org.jruby.util.Pwd`
# pwd.gsub! '\\', '/'
# assert_equal("testDir_4", pwd.split("/")[-1].strip)
pend 'FIXME: been commented out on 9K (works on 1.7) - please review'
pwd = `java -cp "#{java_test_classes}" org.jruby.util.Pwd`
pwd.gsub! '\\', '/'
assert_equal("testDir_4", pwd.split("/")[-1].strip)
end
# FIXME: does not pass in 2.0 mode
# Dir.chdir("testDir_4")
# pwd = `java -cp "#{java_test_classes}" org.jruby.util.Pwd`
# pwd.gsub! '\\', '/'
# assert_equal("testDir_4", pwd.split("/")[-1].strip)
Dir.chdir("testDir_4")
pend 'FIXME: been commented out on 9K (works on 1.7) - please review'
pwd = `java -cp "#{java_test_classes}" org.jruby.util.Pwd`
pwd.gsub! '\\', '/'
assert_equal("testDir_4", pwd.split("/")[-1].strip)
end

def test_glob_inside_jar_file
# the respective files get found via the classloader
jar_file = jar_file_with_spaces.sub(/.*!/, 'uri:classloader:')
pend 'FIXME: needs more work after merge - (@mkristian) please review'
jar_file = jar_file_with_spaces

["#{jar_file}/abc", "#{jar_file}/inside_jar.rb", "#{jar_file}/second_jar.rb"].each do |f|
assert $__glob_value.include?(f), "#{f} not found in #{$__glob_value.inspect}"
@@ -168,6 +167,7 @@ def test_glob_with_magic_inside_jar_file
aref = Dir["#{jar_file}/[a-z]*_jar.rb"]
glob = Dir.glob("#{jar_file}/[a-z]*_jar.rb")

pend 'FIXME: regression after merge - (@mkristian) please review'
[aref, glob].each do |collect|
["#{jar_file}/inside_jar.rb", "#{jar_file}/second_jar.rb"].each do |f|
assert collect.include?(f)
@@ -208,7 +208,9 @@ def jar_file_with_spaces
require 'test/jruby/dir with spaces/test_jar.jar'
require 'inside_jar'

"file:" + File.join(File.dirname(__FILE__), "dir with spaces", "test_jar.jar") + "!"
first = File.expand_path(File.join(File.dirname(__FILE__), '..'))

"file:" + File.join(first, "test", "dir with spaces", "test_jar.jar") + "!"
end

# JRUBY-4177
52 changes: 26 additions & 26 deletions test/jruby/test_file.rb
Original file line number Diff line number Diff line change
@@ -118,12 +118,12 @@ def test_windows_dirname
end

def test_windows_network_path

assert_equal("\\\\network\\share", File.dirname("\\\\network\\share\\file.bat"))
assert_equal("\\\\network\\share", File.dirname("\\\\network\\share"))
assert_equal("\\\\localhost\\c$", File.dirname("\\\\localhost\\c$\\boot.bat"))
assert_equal("\\\\localhost\\c$", File.dirname("\\\\localhost\\c$"))

end

def test_expand_path_windows
@@ -267,7 +267,8 @@ def test_expand_path_looks_like_url
end

def test_mkdir_with_non_file_uri_raises_error
assert_raises(Errno::ENOTDIR) { FileUtils.mkdir_p("classpath:/META-INF/jruby.home/foo") }
assert_raises(Errno::ENOTDIR) { FileUtils.mkdir_p("classpath:/META-INF/jruby.home") }
assert !File.directory?("classpath:/META-INF/jruby.home")
end

def test_mkdir_with_file_uri_works_as_expected
@@ -493,10 +494,10 @@ def test_file_query # - file?
end

def test_readable_query # - readable?
assert(File.readable?(__FILE__))
assert(File.readable?(File.dirname(__FILE__)))
assert(File.readable?('test/jruby/test_file.rb'))
assert(File.readable?('test'))
assert(! File.readable?('test_not'))
result = jruby("-e 'print File.readable?(\"test_not\");print File.readable?(\"#{File.dirname(__FILE__)}\");print File.readable?(\"#{__FILE__}\")'", 'jruby.native.enabled' => 'false' )
result = jruby("-e 'print File.readable?(\"test_not\");print File.readable?(\"test\");print File.readable?(\"test/jruby/test_file.rb\")'", 'jruby.native.enabled' => 'false' )
assert(result == 'falsetruetrue')
end

@@ -514,7 +515,7 @@ def test_readable_query # - readable?
result = jruby("-e 'print File.#{method}(\"#{exec_file}\");print File.#{method}(\"test_not\");print File.#{method}(\"test\");print File.#{method}(\"test/test_file.rb\")'", 'jruby.native.enabled' => 'false' )
assert(result == 'truefalsetruefalse')
end
end
end

def test_file_exist_query
assert(File.exist?('test'))
@@ -546,7 +547,7 @@ def test_require_from_jar_url_with_spaces_in_load_path
assert require('foo')
assert $LOADED_FEATURES.pop =~ /foo\.rb$/
end

with_load_path("file:" + File.expand_path("test/jruby/dir with spaces/test_jar.jar") + "!") do
assert require('abc/foo')
assert $LOADED_FEATURES.pop =~ /foo\.rb$/
@@ -660,22 +661,21 @@ def test_file_stat_uri_prefixes
end

# JRUBY-2524
# GH #2048 Stat of an empty resource does not generate proper Exception
# def test_file_time_uri_prefixes
# assert_raise(Errno::ENOENT) do
# File.atime("file:")
# end
# assert_raise(Errno::ENOENT) do
# File.atime("file:!")
# end

# assert_raise(Errno::ENOENT) do
# File.ctime("file:")
# end
# assert_raise(Errno::ENOENT) do
# File.ctime("file:!")
# end
# end
def test_file_time_uri_prefixes
assert_raise(Errno::ENOENT) do
File.atime("file:")
end
assert_raise(Errno::ENOENT) do
File.atime("file:!")
end

assert_raise(Errno::ENOENT) do
File.ctime("file:")
end
assert_raise(Errno::ENOENT) do
File.ctime("file:!")
end
end

def test_file_open_utime
filename = "__test__file"
@@ -1110,7 +1110,7 @@ def test_open_file_in_jar
File.open('file:test/jruby/dir with spaces/test_jar.jar!/abc/foo.rb'){}
File.open('jar:file:test/jruby/dir with spaces/test_jar.jar!/abc/foo.rb'){}
end

# JRUBY-3634: File.read or File.open with a url to a file resource fails with StringIndexOutOfBounds exception
def test_file_url
path = File.expand_path(__FILE__)
@@ -1197,5 +1197,5 @@ def test_file_path_is_tainted
# jruby/jruby#2331
def test_classpath_realpath
assert_equal("classpath:/java/lang/String.class", File.realpath("classpath:/java/lang/String.class"))
end if RUBY_VERSION >= '1.9'
end
end
35 changes: 35 additions & 0 deletions test/jruby/test_hash.rb
Original file line number Diff line number Diff line change
@@ -56,4 +56,39 @@ def test_lookup_with_equal_and_same_hash_should_not_work
hash = {equal1 => 'bar'}
assert_nil(hash[equal2])
end

def test_yield_arguments
hash = { :a => 1, :b => 2, :c => 3 }

passed = []; ret = hash.select { |pair| passed << pair; passed.size < 3 }
assert_equal [:a, :b, :c], passed
assert_equal( { :a => 1, :b => 2 }, ret )
passed = []; ret = hash.select { |k,v| passed << k; passed << v }
assert_equal [:a, 1, :b, 2, :c, 3], passed
assert_equal hash, ret

passed = []; ret = hash.reject { |pair| passed << pair; passed.size < 2 }
assert_equal [:a, :b, :c], passed
assert_equal( { :b => 2, :c => 3 }, ret )
passed = []; ret = hash.reject { |k,v| passed << k; passed << v }
assert_equal [:a, 1, :b, 2, :c, 3], passed
assert_equal( {}, ret )

passed = []; ret = hash.take_while { |pair| passed << pair; true }
assert_equal [[:a, 1], [:b, 2], [:c, 3]], passed
assert_equal [[:a, 1], [:b, 2], [:c, 3]], ret

passed = []; ret = hash.take_while { |k,v| passed << k; passed << v; passed.size < 3 }
assert_equal [:a, 1, :b, 2], passed
assert_equal [[:a, 1]], ret

passed = []; ret = hash.collect { |pair| passed << pair }
assert_equal [[:a, 1], [:b, 2], [:c, 3]], passed

passed = []; ret = hash.collect { |k,v| passed << k; passed << v; passed.size < 3 }
assert_equal [:a, 1, :b, 2, :c, 3], passed
assert_equal [true, false, false], ret

end

end
8 changes: 8 additions & 0 deletions test/jruby/test_higher_javasupport.rb
Original file line number Diff line number Diff line change
@@ -712,6 +712,14 @@ def test_big_decimal_interaction
assert_equal(BigDecimal, BigDecimal.new("1.23").add(BigDecimal.new("2.34")).class)
end

#JRUBY-3818
def test_decimal_format
format = java.text.DecimalFormat.new("#,##0.00")
locale_separator = java.text.DecimalFormatSymbols.new().getDecimalSeparator()
value = java.math.BigDecimal.new("10")
assert_equal "10" + locale_separator.chr + "00", format.format(value)
end

def test_direct_package_access
a = java.util.ArrayList.new
assert_equal(0, a.size)
24 changes: 14 additions & 10 deletions test/jruby/test_load.rb
Original file line number Diff line number Diff line change
@@ -46,13 +46,12 @@ def test_require
assert $loaded_foo_bar
end

def test_require_without_current_dir_in_load_path
omit( 'old load service will find those files. regular tests switch ruby CWD and work. this test keeps java CWD and ruby CWD the same' )
$LOAD_PATH.delete '.'
assert_raises(LoadError) { require('test/jruby/dummy') }
assert require('./test/jruby/dummy')
ensure
$LOAD_PATH << '.'
# GH-2972
def test_require_relative_via_uri_classloader_protocol
$CLASSPATH << './test/jruby'
assert_nothing_raised do
require 'uri:classloader:/require_relative.rb'
end
end

# JRUBY-3231
@@ -192,6 +191,11 @@ def test_require_with_non_existent_jar_3
$:.shift
end

def test_load_rb_if_jar_doesnt_exist
pend 'someone (@mkristian?) please fix me'
require 'test/jruby/fake.jar' # test/fake.jar does not exist, but test/fake.jar.rb does.
end

def test_overriding_require_shouldnt_cause_problems
eval(<<DEPS, binding, "deps")
class ::Object
@@ -267,9 +271,9 @@ def test_loading_jar_with_leading_underscore
def test_jar_with_plus_in_name
assert_in_sub_runtime %{
require 'test/jruby/jar_with+.jar'
Dir["#{File.dirname( __FILE__ )}/jar_with+.jar!/*"].size == 2
}
end
Dir["#{File.dirname( __FILE__ )}/jar_with+.jar!/*"].size == 2
}
end

# JRUBY-5045
def test_cwd_plus_dotdot_jar_loading
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require 'test/unit'
require 'test/test_helper'
require 'rbconfig'
require 'test/jruby/test_helper'
require 'jruby/path_helper'

class TestLoad < Test::Unit::TestCase