def library_import(self, name, attributes): # equals org.python.core.ClasspathPyImporter.PYCLASSPATH_PREFIX if 'Jython' in platform.python_implementation(): import org.python.core.imp as jimp if attributes['source']: if '__pyclasspath__' in attributes['source']: res = attributes['source'].split( '__pyclasspath__')[1].replace(os.sep, '') attributes['source'] = str( jimp.getSyspathJavaLoader().getResources( res).nextElement()) else: try: source_uri = jimp.getSyspathJavaLoader().getResources( name + '.class').nextElement() attributes['source'] = str(source_uri) except: pass source_uri_txt = attributes['source'] if source_uri_txt and 'file:/' in source_uri_txt: from java.io import File as File from java.net import URL as URL filePath = re.split('.*(?=file[:])', source_uri_txt) if len(filePath) > 1: path = re.split('[!][/]', filePath[1])[0] f = File(URL(path).getFile()) source_uri_txt = f.getAbsolutePath() attributes['source'] = source_uri_txt self._send_to_server(AgentEventMessage.LIBRARY_IMPORT, name, attributes)
def library_import(self, name, attributes): # equals org.python.core.ClasspathPyImporter.PYCLASSPATH_PREFIX import platform if 'Jython' in platform.python_implementation(): import org.python.core.imp as jimp if attributes['source']: if '__pyclasspath__' in attributes['source']: res = attributes['source'].split('__pyclasspath__')[1].replace(os.sep, '') attributes['source'] = str(jimp.getSyspathJavaLoader().getResources(res).nextElement()) else: try: source_uri = jimp.getSyspathJavaLoader().getResources(name + '.class').nextElement() attributes['source'] = str(source_uri) except: pass source_uri_txt = attributes['source'] if source_uri_txt and 'file:/' in source_uri_txt: import re from java.io import File as File from java.net import URL as URL filePath = re.split('.*(?=file[:])', source_uri_txt) if len(filePath) > 1: path = re.split('[!][/]', filePath[1])[0] f = File(URL(path).getFile()) source_uri_txt = f.getAbsolutePath() attributes['source'] = source_uri_txt self._send_socket("library_import", name, attributes)
def _find_jar_source_path(self, source, name): try: import org.python.core.imp as jimp if not source: res = name + ".class" return jimp.getSyspathJavaLoader().getResource(res).getPath() elif '__pyclasspath__' in source: res = source[source.index('__pyclasspath__') + 16:] return jimp.getSyspathJavaLoader().getResource(res).getPath() except: pass return source
def resource(name): result = {} try: r = ResourceBundle.getBundle("properties/" + name, Locale.getDefault(), imp.getSyspathJavaLoader()) for key in r.getKeys(): result[key] = r.getString(key) except MissingResourceException, e: pass
def _find_jar_source_path(module_name): import org.python.core.imp as jimp from types import ModuleType module = jimp.load(module_name) if isinstance(module, ModuleType): source = module.__file__ if '__pyclasspath__' in source: res = source[source.index('__pyclasspath__') + 16:] return jimp.getSyspathJavaLoader().getResource(res).getPath() return source else: return module.getResource('/' + module_name.replace('.', '/') + ".class").getPath()
def makeLoader(self): return jxxload_help.PathVFSJavaLoader(self.vfs, imp.getSyspathJavaLoader())
# # Copyright 2019 XEBIALABS # # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # from java.lang import Thread from org.python.core.imp import getSyspathJavaLoader from com.xebialabs.overtherepy.jython import PatchedSyspathJavaLoader Thread.currentThread().contextClassLoader = PatchedSyspathJavaLoader( getSyspathJavaLoader()) # Setup the environment import os import sys import site import urllib2 class LocalEZSetup(object): def __init__(self, base_dir): self._base_dir = base_dir site_dir = os.path.join(base_dir, 'site-packages') self._site_dir = site_dir if not os.path.exists(site_dir): os.mkdir(site_dir) site.addsitedir(site_dir)
# of the License. # # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; # without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along with this # program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth # Floor, Boston, MA 02110-1301 USA # from java.lang import Thread from org.python.core.imp import getSyspathJavaLoader from com.xebialabs.overtherepy.jython import PatchedSyspathJavaLoader Thread.currentThread().contextClassLoader = PatchedSyspathJavaLoader(getSyspathJavaLoader()) # Setup the environment import os import sys import site import urllib2 class LocalEZSetup(object): def __init__(self, base_dir): self._base_dir = base_dir site_dir = os.path.join(base_dir, 'site-packages') self._site_dir = site_dir if not os.path.exists(site_dir): os.mkdir(site_dir) site.addsitedir(site_dir)