Skip to content
Browse files

Fix and test for JRUBY-1229, allow loading jars with no manifest with…

…out load error

git-svn-id: http://svn.codehaus.org/jruby/trunk/jruby@4665 961051c9-f516-0410-bf72-c9f7e237a7b7
  • Loading branch information...
1 parent 2f3e5ee commit 8ed5ac0c3d5415067cd166b7273cb69e8e75f4f7 @headius headius committed Oct 22, 2007
Showing with 20 additions and 14 deletions.
  1. +15 −13 src/org/jruby/runtime/load/JarredScript.java
  2. BIN test/jar_with_no_manifest.jar
  3. +5 −1 test/testLoad.rb
View
28 src/org/jruby/runtime/load/JarredScript.java
@@ -70,19 +70,21 @@ public void load(Ruby runtime) {
JarInputStream in = new JarInputStream(new BufferedInputStream(jarFile.openStream()));
Manifest mf = in.getManifest();
- String rubyInit = mf.getMainAttributes().getValue("Ruby-Init");
- if (rubyInit != null) {
- JarEntry entry = in.getNextJarEntry();
- while (entry != null && !entry.getName().equals(rubyInit)) {
- entry = in.getNextJarEntry();
- }
- if (entry != null) {
- IRubyObject old = runtime.getGlobalVariables().isDefined("$JAR_URL") ? runtime.getGlobalVariables().get("$JAR_URL") : runtime.getNil();
- try {
- runtime.getGlobalVariables().set("$JAR_URL", runtime.newString("jar:" + jarFile + "!/"));
- runtime.loadFile("init", new InputStreamReader(in));
- } finally {
- runtime.getGlobalVariables().set("$JAR_URL", old);
+ if (mf != null) {
+ String rubyInit = mf.getMainAttributes().getValue("Ruby-Init");
+ if (rubyInit != null) {
+ JarEntry entry = in.getNextJarEntry();
+ while (entry != null && !entry.getName().equals(rubyInit)) {
+ entry = in.getNextJarEntry();
+ }
+ if (entry != null) {
+ IRubyObject old = runtime.getGlobalVariables().isDefined("$JAR_URL") ? runtime.getGlobalVariables().get("$JAR_URL") : runtime.getNil();
+ try {
+ runtime.getGlobalVariables().set("$JAR_URL", runtime.newString("jar:" + jarFile + "!/"));
+ runtime.loadFile("init", new InputStreamReader(in));
+ } finally {
+ runtime.getGlobalVariables().set("$JAR_URL", old);
+ }
}
}
}
View
BIN test/jar_with_no_manifest.jar
Binary file not shown.
View
6 test/testLoad.rb
@@ -11,6 +11,11 @@
# Load jar file RubyInitTest.java
require File::dirname(file) + "/RubyInitTest"
test_ok($ruby_init)
+
+ # JRUBY-1229, allow loading jar files without manifest
+ test_no_exception {
+ require "test/jar_with_no_manifest.jar"
+ }
end
# Yes, the following line is supposed to appear twice
@@ -24,4 +29,3 @@
test_ok require('test/foo.bar')
test_ok $loaded_foo_bar
-

0 comments on commit 8ed5ac0

Please sign in to comment.
Something went wrong with that request. Please try again.