{"action":"created","comment":{"url":"https://api.github.com/repos/eclipse/scanning/pulls/comments/104926352","pull_request_review_id":25782038,"id":104926352,"diff_hunk":"@@ -0,0 +1,240 @@\n+package org.eclipse.scanning.jython;\n+\n+import java.io.File;\n+import java.io.IOException;\n+import java.util.Iterator;\n+import java.util.Properties;\n+\n+import org.eclipse.core.runtime.FileLocator;\n+import org.eclipse.core.runtime.Platform;\n+import org.eclipse.scanning.points.ScanPointGeneratorFactory;\n+import org.osgi.framework.Bundle;\n+import org.osgi.framework.wiring.BundleWiring;\n+import org.python.core.Py;\n+import org.python.core.PyString;\n+import org.python.core.PySystemState;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+/**\n+ * \n+ * An interpreter manager which is designed to create an interpreter\n+ * which either is sympathic and working with the GDA configuration or\n+ * creates an empty and working interpreter.\n+ * \n+ * @author Matthew Gerring\n+ *\n+ */\n+class JythonInterpreterManager {\n+\n+\tprivate static final Logger logger = LoggerFactory.getLogger(JythonInterpreterManager.class);\n+\t\n+\t\n+\tprivate static volatile PySystemState configuredState;\n+\n+\t/**\n+\t * Call to ensure that an interpreter is set up and configured and\n+\t * able to load the relevant bundles.\n+\t */\n+\tpublic static synchronized void setupSystemState(String... bundleNames) {\n+\t\t\n+\t\tClassLoader loader=null;\n+\t\tif (configuredState==null) { // Relies on setupSystemState() being called early in the server startup.\n+\t\t\tloader = createJythonClassLoader(PySystemState.class.getClassLoader());\n+\t \t\tinitializePythonPath(loader); \n+\t\t}\n+\t\t\n+    \tPySystemState state = Py.getSystemState();\n+    \tif (state==configuredState) return;\n+    \t\n+    \tif (loader==null) {\n+    \t\t// Then someone else has changed the PySystemState\n+    \t\t// They will not have added our \n+\t\t\tloader = createJythonClassLoader(state.getClassLoader());   // Don't clobber their working.\t\t\n+    \t}\n+\t   \tstate.setClassLoader(loader);\n+    \t\n+     \tsetJythonPaths(state);       // Tries to ensure that enough of jython is on the path\n+     \tsetSpgGeneratorPaths(state, bundleNames); // Adds the scripts directory from points\n+\t   \tPy.setSystemState(state);\n+ \n+\t   \tconfiguredState = state;\n+\t}\n+\n+\tprivate static void setSpgGeneratorPaths(PySystemState state, String... bundleNames) {\n+\t\t\n+        File location = getBundleLocation(\"org.eclipse.scanning.points\");\n+        state.path.add(new PyString(location.getAbsolutePath() + \"/scripts/\"));\n+        \n+        if (bundleNames!=null) {\n+        \tfor (String bundle : bundleNames) {\n+                location = getBundleLocation(bundle);\n+                state.path.add(new PyString(location.getAbsolutePath() + \"/scripts/\"));\n+\t\t\t}\n+        }\n+\t}\n+\n+\n+\tprivate static void initializePythonPath(ClassLoader loader) {\n+\t\ttry {\n+\t    \tString jythonBundleName = System.getProperty(\"org.eclipse.scanning.jython.osgi.bundle.name\", \"uk.ac.diamond.jython\");\n+\t        File loc = getBundleLocation(jythonBundleName); // TODO Name the jython OSGi bundle without Diamond in it!\n+\t        if (loc ==null) return;\n+\t        File jythonDir = find(loc, \"jython\");\n+\t        if (jythonDir ==null) return;\n+\t        \n+\t        Properties props = new Properties();\n+\t    \tprops.setProperty(\"python.home\", jythonDir.getAbsolutePath());\n+\t    \tprops.setProperty(\"python.console.encoding\", \"UTF-8\"); // Used to prevent: console: Failed to install '': java.nio.charset.UnsupportedCharsetException: cp0.\n+\t    \tprops.setProperty(\"python.options.showJavaExceptions\", \"true\");\n+\t    \tprops.setProperty(\"python.verbose\", \"warning\");\n+\n+\t    \tProperties preprops = System.getProperties();\n+\t    \t\n+\t    \tPySystemState.initialize(preprops, props, new String[]{}, loader);\n+\t    \n+\t    } catch (Throwable ne) {","path":"org.eclipse.scanning.points/src/org/eclipse/scanning/jython/JythonInterpreterManager.java","position":96,"original_position":96,"commit_id":"2b9d47036530cfa556d49dd3f227f72b096c25c2","original_commit_id":"2b9d47036530cfa556d49dd3f227f72b096c25c2","user":{"login":"gerring","id":1318764,"avatar_url":"https://avatars2.githubusercontent.com/u/1318764?v=3","gravatar_id":"","url":"https://api.github.com/users/gerring","html_url":"https://github.com/gerring","followers_url":"https://api.github.com/users/gerring/followers","following_url":"https://api.github.com/users/gerring/following{/other_user}","gists_url":"https://api.github.com/users/gerring/gists{/gist_id}","starred_url":"https://api.github.com/users/gerring/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gerring/subscriptions","organizations_url":"https://api.github.com/users/gerring/orgs","repos_url":"https://api.github.com/users/gerring/repos","events_url":"https://api.github.com/users/gerring/events{/privacy}","received_events_url":"https://api.github.com/users/gerring/received_events","type":"User","site_admin":false},"body":"![MAJOR](https://raw.githubusercontent.com/SonarCommunity/sonar-github/master/images/severity-major.png 'Severity: MAJOR') Catch Exception instead of Throwable. [![rule](https://raw.githubusercontent.com/SonarCommunity/sonar-github/master/images/rule.png)](https://sonarqube.com/coding_rules#rule_key=squid%3AS1181)\n","created_at":"2017-03-08T14:23:23Z","updated_at":"2017-03-08T14:23:23Z","html_url":"https://github.com/eclipse/scanning/pull/23#discussion_r104926352","pull_request_url":"https://api.github.com/repos/eclipse/scanning/pulls/23","_links":{"self":{"href":"https://api.github.com/repos/eclipse/scanning/pulls/comments/104926352"},"html":{"href":"https://github.com/eclipse/scanning/pull/23#discussion_r104926352"},"pull_request":{"href":"https://api.github.com/repos/eclipse/scanning/pulls/23"}}},"pull_request":{"url":"https://api.github.com/repos/eclipse/scanning/pulls/23","id":109703011,"html_url":"https://github.com/eclipse/scanning/pull/23","diff_url":"https://github.com/eclipse/scanning/pull/23.diff","patch_url":"https://github.com/eclipse/scanning/pull/23.patch","issue_url":"https://api.github.com/repos/eclipse/scanning/issues/23","number":23,"state":"open","locked":false,"title":"Jython refactor","user":{"login":"gerring","id":1318764,"avatar_url":"https://avatars2.githubusercontent.com/u/1318764?v=3","gravatar_id":"","url":"https://api.github.com/users/gerring","html_url":"https://github.com/gerring","followers_url":"https://api.github.com/users/gerring/followers","following_url":"https://api.github.com/users/gerring/following{/other_user}","gists_url":"https://api.github.com/users/gerring/gists{/gist_id}","starred_url":"https://api.github.com/users/gerring/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gerring/subscriptions","organizations_url":"https://api.github.com/users/gerring/orgs","repos_url":"https://api.github.com/users/gerring/repos","events_url":"https://api.github.com/users/gerring/events{/privacy}","received_events_url":"https://api.github.com/users/gerring/received_events","type":"User","site_admin":false},"body":"Make the JythonObjectFactory callable from any class. This is useful for creating Jython Device processing for instance.","created_at":"2017-03-08T14:13:38Z","updated_at":"2017-03-08T14:23:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"00ea451d1cfc4d260a7725c92d11bf200620ba17","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/eclipse/scanning/pulls/23/commits","review_comments_url":"https://api.github.com/repos/eclipse/scanning/pulls/23/comments","review_comment_url":"https://api.github.com/repos/eclipse/scanning/pulls/comments{/number}","comments_url":"https://api.github.com/repos/eclipse/scanning/issues/23/comments","statuses_url":"https://api.github.com/repos/eclipse/scanning/statuses/2b9d47036530cfa556d49dd3f227f72b096c25c2","head":{"label":"eclipse:jython_refactor","ref":"jython_refactor","sha":"2b9d47036530cfa556d49dd3f227f72b096c25c2","user":{"login":"eclipse","id":56974,"avatar_url":"https://avatars2.githubusercontent.com/u/56974?v=3","gravatar_id":"","url":"https://api.github.com/users/eclipse","html_url":"https://github.com/eclipse","followers_url":"https://api.github.com/users/eclipse/followers","following_url":"https://api.github.com/users/eclipse/following{/other_user}","gists_url":"https://api.github.com/users/eclipse/gists{/gist_id}","starred_url":"https://api.github.com/users/eclipse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eclipse/subscriptions","organizations_url":"https://api.github.com/users/eclipse/orgs","repos_url":"https://api.github.com/users/eclipse/repos","events_url":"https://api.github.com/users/eclipse/events{/privacy}","received_events_url":"https://api.github.com/users/eclipse/received_events","type":"Organization","site_admin":false},"repo":{"id":83696502,"name":"scanning","full_name":"eclipse/scanning","owner":{"login":"eclipse","id":56974,"avatar_url":"https://avatars2.githubusercontent.com/u/56974?v=3","gravatar_id":"","url":"https://api.github.com/users/eclipse","html_url":"https://github.com/eclipse","followers_url":"https://api.github.com/users/eclipse/followers","following_url":"https://api.github.com/users/eclipse/following{/other_user}","gists_url":"https://api.github.com/users/eclipse/gists{/gist_id}","starred_url":"https://api.github.com/users/eclipse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eclipse/subscriptions","organizations_url":"https://api.github.com/users/eclipse/orgs","repos_url":"https://api.github.com/users/eclipse/repos","events_url":"https://api.github.com/users/eclipse/events{/privacy}","received_events_url":"https://api.github.com/users/eclipse/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/eclipse/scanning","description":"Scanning is an open source project for moving scientific instruments and writing NeXus (http://www.nexusformat.org/) compliant files. It is designed to be control system neutral, EPICS, TANGO etc. may be used. See https://projects.eclipse.org/proposals/scanning and https://github.com/eclipse/scanning/blob/master/GETTINGSTARTED.pdf","fork":false,"url":"https://api.github.com/repos/eclipse/scanning","forks_url":"https://api.github.com/repos/eclipse/scanning/forks","keys_url":"https://api.github.com/repos/eclipse/scanning/keys{/key_id}","collaborators_url":"https://api.github.com/repos/eclipse/scanning/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/eclipse/scanning/teams","hooks_url":"https://api.github.com/repos/eclipse/scanning/hooks","issue_events_url":"https://api.github.com/repos/eclipse/scanning/issues/events{/number}","events_url":"https://api.github.com/repos/eclipse/scanning/events","assignees_url":"https://api.github.com/repos/eclipse/scanning/assignees{/user}","branches_url":"https://api.github.com/repos/eclipse/scanning/branches{/branch}","tags_url":"https://api.github.com/repos/eclipse/scanning/tags","blobs_url":"https://api.github.com/repos/eclipse/scanning/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/eclipse/scanning/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/eclipse/scanning/git/refs{/sha}","trees_url":"https://api.github.com/repos/eclipse/scanning/git/trees{/sha}","statuses_url":"https://api.github.com/repos/eclipse/scanning/statuses/{sha}","languages_url":"https://api.github.com/repos/eclipse/scanning/languages","stargazers_url":"https://api.github.com/repos/eclipse/scanning/stargazers","contributors_url":"https://api.github.com/repos/eclipse/scanning/contributors","subscribers_url":"https://api.github.com/repos/eclipse/scanning/subscribers","subscription_url":"https://api.github.com/repos/eclipse/scanning/subscription","commits_url":"https://api.github.com/repos/eclipse/scanning/commits{/sha}","git_commits_url":"https://api.github.com/repos/eclipse/scanning/git/commits{/sha}","comments_url":"https://api.github.com/repos/eclipse/scanning/comments{/number}","issue_comment_url":"https://api.github.com/repos/eclipse/scanning/issues/comments{/number}","contents_url":"https://api.github.com/repos/eclipse/scanning/contents/{+path}","compare_url":"https://api.github.com/repos/eclipse/scanning/compare/{base}...{head}","merges_url":"https://api.github.com/repos/eclipse/scanning/merges","archive_url":"https://api.github.com/repos/eclipse/scanning/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/eclipse/scanning/downloads","issues_url":"https://api.github.com/repos/eclipse/scanning/issues{/number}","pulls_url":"https://api.github.com/repos/eclipse/scanning/pulls{/number}","milestones_url":"https://api.github.com/repos/eclipse/scanning/milestones{/number}","notifications_url":"https://api.github.com/repos/eclipse/scanning/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/eclipse/scanning/labels{/name}","releases_url":"https://api.github.com/repos/eclipse/scanning/releases{/id}","deployments_url":"https://api.github.com/repos/eclipse/scanning/deployments","created_at":"2017-03-02T15:58:52Z","updated_at":"2017-03-06T10:34:25Z","pushed_at":"2017-03-08T14:16:16Z","git_url":"git://github.com/eclipse/scanning.git","ssh_url":"git@github.com:eclipse/scanning.git","clone_url":"https://github.com/eclipse/scanning.git","svn_url":"https://github.com/eclipse/scanning","homepage":"","size":7968,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":2,"forks":3,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"eclipse:master","ref":"master","sha":"8a255bc7d8d28d0a039177b51dbd9e78a5bb9d27","user":{"login":"eclipse","id":56974,"avatar_url":"https://avatars2.githubusercontent.com/u/56974?v=3","gravatar_id":"","url":"https://api.github.com/users/eclipse","html_url":"https://github.com/eclipse","followers_url":"https://api.github.com/users/eclipse/followers","following_url":"https://api.github.com/users/eclipse/following{/other_user}","gists_url":"https://api.github.com/users/eclipse/gists{/gist_id}","starred_url":"https://api.github.com/users/eclipse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eclipse/subscriptions","organizations_url":"https://api.github.com/users/eclipse/orgs","repos_url":"https://api.github.com/users/eclipse/repos","events_url":"https://api.github.com/users/eclipse/events{/privacy}","received_events_url":"https://api.github.com/users/eclipse/received_events","type":"Organization","site_admin":false},"repo":{"id":83696502,"name":"scanning","full_name":"eclipse/scanning","owner":{"login":"eclipse","id":56974,"avatar_url":"https://avatars2.githubusercontent.com/u/56974?v=3","gravatar_id":"","url":"https://api.github.com/users/eclipse","html_url":"https://github.com/eclipse","followers_url":"https://api.github.com/users/eclipse/followers","following_url":"https://api.github.com/users/eclipse/following{/other_user}","gists_url":"https://api.github.com/users/eclipse/gists{/gist_id}","starred_url":"https://api.github.com/users/eclipse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eclipse/subscriptions","organizations_url":"https://api.github.com/users/eclipse/orgs","repos_url":"https://api.github.com/users/eclipse/repos","events_url":"https://api.github.com/users/eclipse/events{/privacy}","received_events_url":"https://api.github.com/users/eclipse/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/eclipse/scanning","description":"Scanning is an open source project for moving scientific instruments and writing NeXus (http://www.nexusformat.org/) compliant files. It is designed to be control system neutral, EPICS, TANGO etc. may be used. See https://projects.eclipse.org/proposals/scanning and https://github.com/eclipse/scanning/blob/master/GETTINGSTARTED.pdf","fork":false,"url":"https://api.github.com/repos/eclipse/scanning","forks_url":"https://api.github.com/repos/eclipse/scanning/forks","keys_url":"https://api.github.com/repos/eclipse/scanning/keys{/key_id}","collaborators_url":"https://api.github.com/repos/eclipse/scanning/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/eclipse/scanning/teams","hooks_url":"https://api.github.com/repos/eclipse/scanning/hooks","issue_events_url":"https://api.github.com/repos/eclipse/scanning/issues/events{/number}","events_url":"https://api.github.com/repos/eclipse/scanning/events","assignees_url":"https://api.github.com/repos/eclipse/scanning/assignees{/user}","branches_url":"https://api.github.com/repos/eclipse/scanning/branches{/branch}","tags_url":"https://api.github.com/repos/eclipse/scanning/tags","blobs_url":"https://api.github.com/repos/eclipse/scanning/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/eclipse/scanning/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/eclipse/scanning/git/refs{/sha}","trees_url":"https://api.github.com/repos/eclipse/scanning/git/trees{/sha}","statuses_url":"https://api.github.com/repos/eclipse/scanning/statuses/{sha}","languages_url":"https://api.github.com/repos/eclipse/scanning/languages","stargazers_url":"https://api.github.com/repos/eclipse/scanning/stargazers","contributors_url":"https://api.github.com/repos/eclipse/scanning/contributors","subscribers_url":"https://api.github.com/repos/eclipse/scanning/subscribers","subscription_url":"https://api.github.com/repos/eclipse/scanning/subscription","commits_url":"https://api.github.com/repos/eclipse/scanning/commits{/sha}","git_commits_url":"https://api.github.com/repos/eclipse/scanning/git/commits{/sha}","comments_url":"https://api.github.com/repos/eclipse/scanning/comments{/number}","issue_comment_url":"https://api.github.com/repos/eclipse/scanning/issues/comments{/number}","contents_url":"https://api.github.com/repos/eclipse/scanning/contents/{+path}","compare_url":"https://api.github.com/repos/eclipse/scanning/compare/{base}...{head}","merges_url":"https://api.github.com/repos/eclipse/scanning/merges","archive_url":"https://api.github.com/repos/eclipse/scanning/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/eclipse/scanning/downloads","issues_url":"https://api.github.com/repos/eclipse/scanning/issues{/number}","pulls_url":"https://api.github.com/repos/eclipse/scanning/pulls{/number}","milestones_url":"https://api.github.com/repos/eclipse/scanning/milestones{/number}","notifications_url":"https://api.github.com/repos/eclipse/scanning/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/eclipse/scanning/labels{/name}","releases_url":"https://api.github.com/repos/eclipse/scanning/releases{/id}","deployments_url":"https://api.github.com/repos/eclipse/scanning/deployments","created_at":"2017-03-02T15:58:52Z","updated_at":"2017-03-06T10:34:25Z","pushed_at":"2017-03-08T14:16:16Z","git_url":"git://github.com/eclipse/scanning.git","ssh_url":"git@github.com:eclipse/scanning.git","clone_url":"https://github.com/eclipse/scanning.git","svn_url":"https://github.com/eclipse/scanning","homepage":"","size":7968,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":2,"forks":3,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/eclipse/scanning/pulls/23"},"html":{"href":"https://github.com/eclipse/scanning/pull/23"},"issue":{"href":"https://api.github.com/repos/eclipse/scanning/issues/23"},"comments":{"href":"https://api.github.com/repos/eclipse/scanning/issues/23/comments"},"review_comments":{"href":"https://api.github.com/repos/eclipse/scanning/pulls/23/comments"},"review_comment":{"href":"https://api.github.com/repos/eclipse/scanning/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/eclipse/scanning/pulls/23/commits"},"statuses":{"href":"https://api.github.com/repos/eclipse/scanning/statuses/2b9d47036530cfa556d49dd3f227f72b096c25c2"}}}}
{"actor":{"display_login":"gerring"}}