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