Permalink
Browse files

Merge branch 'jruby-1_7'

Conflicts:
	.travis.yml
	build.xml
	core/src/main/java/org/jruby/ext/etc/RubyEtc.java
	lib/ruby/1.9/rdoc/markdown.rb
	maven/jruby-jars/src/it/helloworld/pom.xml
	pom.xml
	test/jruby.1.9.index
	test/jruby/test_pathname_dup.rb
	test/test_command_line_switches.rb
  • Loading branch information...
2 parents 0267396 + af32441 commit b183dfe7c6824f5e44fc4213a9c836c7eb7f2e40 @mkristian mkristian committed Jul 24, 2014
Showing with 393 additions and 67 deletions.
  1. +1 −1 .travis.yml
  2. +5 −1 core/src/main/java/org/jruby/RubyFile.java
  3. +1 −1 core/src/main/java/org/jruby/ext/etc/RubyEtc.java
  4. +43 −25 core/src/main/java/org/jruby/runtime/load/LibrarySearcher.java
  5. +2 −2 core/src/main/java/org/jruby/util/JarDirectoryResource.java
  6. +2 −2 core/src/main/java/org/jruby/util/JarFileResource.java
  7. +28 −22 core/src/main/java/org/jruby/util/JarResource.java
  8. +34 −0 core/src/test/java/org/jruby/util/JarResourceTest.java
  9. 0 core/src/test/resources/f o.rb
  10. 0 core/src/test/resources/foo.rb
  11. BIN core/src/test/resources/foobar.jar
  12. BIN core/src/test/resources/space bar/foobar.jar
  13. +3 −0 maven/jruby-complete/src/it/hello world/pom.xml
  14. +3 −0 maven/jruby-complete/src/it/helloworld/pom.xml
  15. +22 −0 maven/jruby-jars/pom.xml
  16. +1 −1 maven/jruby/src/it/many_jars_with_embedded_gems/app/pom.rb
  17. +1 −1 maven/jruby/src/it/many_jars_with_embedded_gems/app/pom.xml
  18. +3 −0 maven/jruby/src/it/many_jars_with_embedded_gems/invoker.properties
  19. +6 −0 maven/jruby/src/it/many_jars_with_embedded_gems/zip_gem/Gemfile
  20. +2 −7 maven/jruby/src/it/many_jars_with_embedded_gems/zip_gem/pom.rb
  21. +10 −1 maven/jruby/src/it/many_jars_with_embedded_gems/zip_gem/pom.xml
  22. +3 −0 maven/jruby/src/it/osgi_all_inclusive/Gemfile
  23. +53 −0 maven/jruby/src/it/osgi_all_inclusive/pom.rb
  24. +9 −0 maven/jruby/src/it/osgi_all_inclusive/src/main/ruby/hello.rb
  25. +122 −0 ...n/jruby/src/it/osgi_all_inclusive/src/test/java/org/jruby/embed/osgi/test/JRubyOsgiEmbedTest.java
  26. +11 −0 spec/java_integration/utilities/load_from_jar_spec.rb
  27. +1 −1 spec/regression/GH-1800_krypt_ffi_regression_spec.rb
  28. +3 −2 test/jruby/test_system_error.rb
  29. +24 −0 test/test_pathname.rb
View
@@ -50,7 +50,7 @@ before_install:
# the install stores the artifact in the localrepo for
# the second maven run with $TARGET
-script: env; mvn install $TARGET -Dinvoker.skip=false | grep -v Down; [ ${PIPESTATUS[0]} == 0 ]
+script: env; mvn install $TARGET -Dinvoker.skip=false | egrep -v 'Download|\\[exec\\] [[:digit:]]+/[[:digit:]]+|^[[:space:]]*\\[exec\\][[:space:]]*$' ; [ ${PIPESTATUS[0]} == 0 ]
install: /bin/true
notifications:
irc:
@@ -753,7 +753,11 @@ public static IRubyObject realpath(ThreadContext context, IRubyObject recv, IRub
if (!RubyFileTest.exist_p(recv, file).isTrue()) {
throw context.runtime.newErrnoENOENTError(file.toString());
}
- return file;
+ try {
+ return context.runtime.newString(new File(file.toString()).getCanonicalPath());
+ } catch (IOException ioex) {
+ throw context.runtime.newErrnoENOENTError(file.toString());
+ }
}
/**
@@ -398,7 +398,7 @@ public static IRubyObject getgrent(IRubyObject recv) {
@JRubyMethod(module = true)
public static IRubyObject systmpdir(ThreadContext context, IRubyObject recv) {
Ruby runtime = context.getRuntime();
- ByteList tmp = ByteList.create(System.getProperty("java.io.tmpdir"));
+ ByteList tmp = ByteList.create(System.getProperty("java.io.tmpdir")); // default for all platforms except Windows
if (Platform.IS_WINDOWS) {
String commonAppData = System.getenv("CSIDL_COMMON_APPDATA");
if (commonAppData != null) tmp = ByteList.create(commonAppData);
@@ -1,20 +1,19 @@
package org.jruby.runtime.load;
import org.jruby.Ruby;
-import org.jruby.RubyArray;
import org.jruby.RubyHash;
import org.jruby.RubyString;
import org.jruby.ast.executable.Script;
-import org.jruby.exceptions.RaiseException;
import org.jruby.runtime.builtin.IRubyObject;
-import org.jruby.runtime.load.DebugLog;
import org.jruby.runtime.load.LoadService.SuffixType;
import org.jruby.util.FileResource;
import org.jruby.util.JRubyFile;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import java.util.Map;
@@ -28,24 +27,29 @@ public Ruby18(LoadService loadService) {
protected String resolveLoadName(FileResource unused, String ruby18Path) {
return ruby18Path;
}
+
+ @Override
+ protected String resolveScriptName(FileResource unused, String ruby18Path) {
+ return ruby18Path;
+ }
}
static class FoundLibrary implements Library {
private final Library delegate;
- private final String scriptName;
+ private final String loadName;
- public FoundLibrary(Library delegate, String scriptName) {
+ public FoundLibrary(Library delegate, String loadName) {
this.delegate = delegate;
- this.scriptName = scriptName;
+ this.loadName = loadName;
}
@Override
public void load(Ruby runtime, boolean wrap) throws IOException {
delegate.load(runtime, wrap);
}
- public String getScriptName() {
- return scriptName;
+ public String getLoadName() {
+ return loadName;
}
}
@@ -64,7 +68,7 @@ public FoundLibrary findBySearchState(LoadService.SearchState state) {
FoundLibrary lib = findLibrary(state.searchFile, state.suffixType);
if (lib != null) {
state.library = lib;
- state.loadName = lib.getScriptName();
+ state.loadName = lib.getLoadName();
}
return lib;
}
@@ -129,20 +133,9 @@ private FoundLibrary findResourceLibrary(String baseName, String suffix) {
return findFileResource(path, suffix);
}
- // If path is absolute, try loading it directly
- if (new File(baseName).isAbsolute()) {
- return findFileResource(baseName, suffix);
- }
-
- // A hack because apparently test_load tests expect to be able to load file:foo.jar even if
- // '.' is not in $LOAD_PATH. *sigh*
- // This probably shouldn't survive into real release.
- if (baseName.startsWith("file:")) {
- String name = baseName.substring(5);
- FoundLibrary found = findFileResource(name, suffix);
- if (found != null) {
- return found;
- }
+ // If path is considered absolute, bypass loadPath iteration and load as-is
+ if (isAbsolute(baseName)) {
+ return findFileResource(baseName, suffix);
}
for (IRubyObject loadPathEntry : loadService.loadPath.toJavaArray()) {
@@ -168,20 +161,42 @@ private FoundLibrary findFileResourceWithLoadPath(String searchName, String suff
FileResource resource = JRubyFile.createResource(runtime, pathWithSuffix);
if (resource.exists()) {
DebugLog.Resource.logFound(pathWithSuffix);
- String scriptName = resolveLoadName(resource, pathWithSuffix);
+ String scriptName = resolveScriptName(resource, pathWithSuffix);
+ String loadName = resolveLoadName(resource, searchName + suffix);
return new FoundLibrary(
new ResourceLibrary(searchName, scriptName, resource),
- scriptName);
+ loadName);
}
return null;
}
+ private static boolean isAbsolute(String path) {
+ // jar: prefix doesn't mean anything anymore, but we might still encounter it
+ if (path.startsWith("jar:")) {
+ path = path.substring(4);
+ }
+
+ if (path.startsWith("file:")) {
+ // We treat any paths with a file schema as absolute, because apparently some tests
+ // explicitely depend on such behavior (test/test_load.rb). On other hand, maybe it's
+ // not too bad, since otherwise joining LOAD_PATH logic would be more complicated if
+ // it'd have to worry about schema.
+ return true;
+ }
+
+ return new File(path).isAbsolute();
+ }
+
protected String resolveLoadName(FileResource resource, String ruby18path) {
return resource.absolutePath();
}
+ protected String resolveScriptName(FileResource resource, String ruby18Path) {
+ return resource.absolutePath();
+ }
+
static class ResourceLibrary implements Library {
private final String searchName;
private final String scriptName;
@@ -232,6 +247,9 @@ private void loadClass(Ruby runtime, boolean wrap) {
private void loadJar(Ruby runtime, boolean wrap) {
try {
URL url = new File(location).toURI().toURL();
+ if ( location.contains( "!") ) {
+ url = new URL( "jar:" + url );
+ }
runtime.getJRubyClassLoader().addURL(url);
} catch (MalformedURLException badUrl) {
runtime.newIOErrorFromException(badUrl);
@@ -19,8 +19,8 @@
private final String path;
private final String[] contents;
- JarDirectoryResource(String jarPath, String path, String[] contents) {
- super(jarPath);
+ JarDirectoryResource(String jarPath, boolean rootSlashPrefix, String path, String[] contents) {
+ super(jarPath, rootSlashPrefix);
this.path = path;
this.contents = contents;
}
@@ -23,8 +23,8 @@
private final JarEntry entry;
private final InputStream entryStream;
- JarFileResource(String jarPath, JarEntry entry, InputStream entryStream) {
- super(jarPath);
+ JarFileResource(String jarPath, boolean rootSlashPrefix, JarEntry entry, InputStream entryStream) {
+ super(jarPath, rootSlashPrefix);
this.entry = entry;
this.entryStream = entryStream;
}
@@ -2,15 +2,13 @@
import jnr.posix.FileStat;
import jnr.posix.POSIX;
-import org.jruby.util.io.ChannelDescriptor;
-import org.jruby.util.io.ModeFlags;
-import java.io.IOException;
import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.util.jar.JarEntry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
abstract class JarResource implements FileResource {
private static Pattern PREFIX_MATCH = Pattern.compile("^(?:jar:)?(?:file:)?(.*)$");
@@ -26,23 +24,31 @@ public static JarResource create(String pathname) {
return null;
}
- String jarPath = sanitized.substring(0, bang);
- String entryPath = sanitized.substring(bang + 1);
- if (!entryPath.startsWith("/")) {
- entryPath = "/" + entryPath;
+ String jarPath;
+ String entryPath;
+ try
+ {
+ // since pathname is actually an uri we need to decode any url decoded characters like %20
+ // which happens when directory names contain spaces
+ jarPath = URLDecoder.decode(sanitized.substring(0, bang), "UTF-8");
+ entryPath = URLDecoder.decode(sanitized.substring(bang + 1), "UTF-8");
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ throw new RuntimeException( "hmm - system does not know UTF-8 string encoding :(" );
}
// TODO: Do we really need to support both test.jar!foo/bar.rb and test.jar!/foo/bar.rb cases?
- JarResource resource = createJarResource(jarPath, entryPath);
+ JarResource resource = createJarResource(jarPath, entryPath, false);
- if (resource == null) {
- resource = createJarResource(jarPath, entryPath.substring(1));
+ if (resource == null && entryPath.startsWith("/")) {
+ resource = createJarResource(jarPath, entryPath.substring(1), true);
}
-
+
return resource;
}
- private static JarResource createJarResource(String jarPath, String path) {
+ private static JarResource createJarResource(String jarPath, String entryPath, boolean rootSlashPrefix) {
JarCache.JarIndex index = jarCache.getIndex(jarPath);
if (index == null) {
@@ -52,31 +58,31 @@ private static JarResource createJarResource(String jarPath, String path) {
// Try it as directory first, because jars tend to have foo/ entries
// and it's not really possible disambiguate between files and directories.
- String[] entries = index.getDirEntries(path);
+ String[] entries = index.getDirEntries(entryPath);
if (entries != null) {
- return new JarDirectoryResource(jarPath, path, entries);
+ return new JarDirectoryResource(jarPath, rootSlashPrefix, entryPath, entries);
}
- JarEntry jarEntry = index.getJarEntry(path);
+ JarEntry jarEntry = index.getJarEntry(entryPath);
if (jarEntry != null) {
InputStream jarEntryStream = index.getInputStream(jarEntry);
- return new JarFileResource(path, jarEntry, jarEntryStream);
+ return new JarFileResource(jarPath, rootSlashPrefix, jarEntry, jarEntryStream);
}
return null;
}
- private final String jarPath;
+ private final String jarPrefix;
private final JarFileStat fileStat;
- protected JarResource(String jarPath) {
- this.jarPath = jarPath;
+ protected JarResource(String jarPath, boolean rootSlashPrefix) {
+ this.jarPrefix = rootSlashPrefix ? jarPath + "!/" : jarPath + "!";
this.fileStat = new JarFileStat(this);
}
@Override
public String absolutePath() {
- return jarPath + "!" + entryName();
+ return jarPrefix + entryName();
}
@Override
@@ -0,0 +1,34 @@
+package org.jruby.util;
+
+import junit.framework.TestCase;
+
+public class JarResourceTest extends TestCase {
+
+ public void testCreateJarResource(){
+ String jar = Thread.currentThread().getContextClassLoader().getResource( "foobar.jar" ).toExternalForm();
+ JarResource resource = JarResource.create( jar + "!/foo.rb" );
+ assertNotNull( resource );
+ resource = JarResource.create( jar + "!/f o.rb" );
+ assertNotNull( resource );
+ resource = JarResource.create( jar + "!/f%20o.rb" );
+ assertNotNull( resource );
+ resource = JarResource.create( jar + "!/doesnotexist.rb" );
+ assertNull( resource );
+ resource = JarResource.create( jar.replace( ".jar", ".zip" ) + "!/foo.rb" );
+ assertNull( resource );
+ }
+
+ public void testCreateJarResourceWithSpaceCharInPath(){
+ String jar = Thread.currentThread().getContextClassLoader().getResource( "space bar/foobar.jar" ).toExternalForm();
+ JarResource resource = JarResource.create( jar + "!/foo.rb" );
+ assertNotNull( resource );
+ resource = JarResource.create( jar + "!/f o.rb" );
+ assertNotNull( resource );
+ resource = JarResource.create( jar + "!/f%20o.rb" );
+ assertNotNull( resource );
+ resource = JarResource.create( jar + "!/doesnotexist.rb" );
+ assertNull( resource );
+ resource = JarResource.create( jar.replace( ".jar", ".zip" ) + "!/foo.rb" );
+ assertNull( resource );
+ }
+}
No changes.
No changes.
Binary file not shown.
Binary file not shown.
@@ -36,6 +36,9 @@
<configuration>
<executable>java</executable>
<arguments>
+<!--
+ <argument>-Djruby.debug.loadService=true</argument>
+-->
<argument>-jar</argument>
<argument>jruby-complete-@project.version@.jar</argument>
<argument>-e</argument>
@@ -22,6 +22,9 @@
<configuration>
<executable>java</executable>
<arguments>
+<!--
+ <argument>-Djruby.debug.loadService=true</argument>
+-->
<argument>-classpath</argument>
<!-- automatically creates the classpath using all project dependencies,
also adding the project build directory -->
View
@@ -58,6 +58,28 @@ freezing to) a specific jruby-complete jar version.</description>
<directory>${basedir}/pkg</directory>
<finalName>jruby-jars-9000.dev</finalName>
<plugins>
+ <plugin>
+ <artifactId>maven-invoker-plugin</artifactId>
+ <configuration>
+ <projectsDirectory>src/it</projectsDirectory>
+ <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
+ <preBuildHookScript>setup.bsh</preBuildHookScript>
+ <postBuildHookScript>verify.bsh</postBuildHookScript>
+ </configuration>
+ <executions>
+ <execution>
+ <id>integration-test</id>
+ <goals>
+ <goal>install</goal>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <settingsFile>${basedir}/src/it/settings.xml</settingsFile>
+ <localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
<plugin>
<groupId>de.saumya.mojo</groupId>
<artifactId>gem-maven-plugin</artifactId>
@@ -1,6 +1,6 @@
# two jars with embedded gems
jar 'de.saumya.mojo:maven-tools', '0.34.2'
-jar 'rubygems:zip', '2.0.2'
+jar 'org.rubygems:zip', '2.0.2'
# jruby scripting container
pom 'org.jruby:jruby', '@project.version@'
Oops, something went wrong.

0 comments on commit b183dfe

Please sign in to comment.