Add all jython directories found in class path to jython interpreter's path (#751)

This commit is contained in:
Mars Lan 2017-09-15 16:02:20 -07:00 committed by GitHub
parent 3a16b6e280
commit c7d4130fab

View File

@ -14,7 +14,9 @@
package metadata.etl;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;
import java.util.Properties;
import org.python.core.PyDictionary;
import org.python.core.PyString;
@ -50,14 +52,25 @@ public abstract class EtlJob extends BaseJob {
}
private void addJythonToPath(PySystemState pySystemState) {
URL url = classLoader.getResource("jython");
if (url != null) {
File file = new File(url.getFile());
String path = file.getPath();
if (path.startsWith("file:")) {
path = path.substring(5);
Enumeration<URL> urls;
try {
urls = classLoader.getResources("jython/");
} catch (IOException e) {
logger.info("Failed to get resource: {}", e.getMessage());
return;
}
while (urls.hasMoreElements()) {
URL url = urls.nextElement();
logger.debug("jython url: {}", url.getPath());
if (url != null) {
File file = new File(url.getFile());
String path = file.getPath();
if (path.startsWith("file:")) {
path = path.substring(5);
}
pySystemState.path.append(new PyString(path.replace("!", "")));
}
pySystemState.path.append(new PyString(path.replace("!", "")));
}
}