-
-
Notifications
You must be signed in to change notification settings - Fork 925
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
have an ExtendedFileResource which keeps the URL of reource to load j…
…ar files
Showing
10 changed files
with
146 additions
and
77 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
core/src/main/java/org/jruby/runtime/load/ExtendedFileResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.jruby.runtime.load; | ||
|
||
import java.net.URL; | ||
|
||
import org.jruby.util.FileResource; | ||
|
||
public interface ExtendedFileResource extends FileResource { | ||
URL getURL(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
core/src/main/java/org/jruby/util/FileResourceFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.jruby.util; | ||
|
||
import org.jruby.Ruby; | ||
import org.jruby.runtime.ThreadContext; | ||
import org.jruby.runtime.load.ExtendedFileResource; | ||
|
||
public class FileResourceFactory { | ||
public static ExtendedFileResource createResource(ThreadContext context, String pathname) { | ||
return createResource(context.runtime, pathname); | ||
} | ||
|
||
public static ExtendedFileResource createResource(Ruby runtime, String pathname) { | ||
return createResource(runtime.getCurrentDirectory(), pathname); | ||
} | ||
|
||
public static ExtendedFileResource createResource(String cwd, String pathname) { | ||
ExtendedFileResource emptyResource = EmptyFileResource.create(pathname); | ||
if (emptyResource != null) { | ||
return emptyResource; | ||
} | ||
|
||
ExtendedFileResource jarResource = JarResource.create(pathname); | ||
if (jarResource != null) { | ||
return jarResource; | ||
} | ||
|
||
// HACK turn the pathname into something meaningful in case of being an URI | ||
ExtendedFileResource cpResource = ClasspathResource.create(pathname.replace(cwd == null ? "" : cwd, "" )); | ||
if (cpResource != null) { | ||
return cpResource; | ||
} | ||
|
||
// HACK this codes get triggers by LoadService via findOnClasspath, so remove the prefix to get the uri | ||
ExtendedFileResource urlResource = URLResource.create(pathname.replace("classpath:/", "")); | ||
if (urlResource != null) { | ||
return urlResource; | ||
} | ||
|
||
if (pathname.startsWith("file:")) { | ||
pathname = pathname.substring(5); | ||
} | ||
|
||
// If any other special resource types fail, count it as a filesystem backed resource. | ||
return new RegularFileResource(JRubyFile.create(cwd, pathname)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters