private Repository toRepository(Object value) throws IOException {
if (value instanceof Wrapper) {
value = ((Wrapper) value).unwrap();
}
Repository repo = null;
if (value instanceof Repository) {
repo = (Repository) value;
// repositories in module search path must be configured as root repository
repo.setRoot();
cache.put(repo.getPath(), new SoftReference<Repository>(repo));
} else if (value != null && value != Undefined.instance) {
String str = ScriptRuntime.toString(value);
SoftReference<Repository> ref = cache.get(str);
repo = ref == null ? null : ref.get();
if (repo == null) {
File file = new File(str);
if (file.isFile() && StringUtils.isZipOrJarFile(str)) {
repo = new ZipRepository(str);
} else {
repo = new FileRepository(str);
}
cache.put(repo.getPath(), new SoftReference<Repository>(repo));
}
} else {
throw Context.reportRuntimeError("Invalid module path item: " + value);
}
return repo;