ScriptRunner.java

上一篇 /

下一篇  2012-03-19 15:05:42

/ 个人分类:android

package com.android.monkeyrunner;

import org.python.core.Py;

import org.python.core.PyObject;

import org.python.util.PythonInterpreter;

import org.python.util.InteractiveConsole;

import java.io.File;

import java.io.IOException;

import java.io.FileInputStream;

import java.lang.RuntimeException;

import java.util.Properties;

/***

* Runs Jython based scripts.

*/

public class ScriptRunner {

/*** The "this" scope object for scripts. */

private final Object scope;

private final String variable;

/*** Private constructor. */

private ScriptRunner(Object scope, String variable) {

this.scope = scope;

this.variable = variable;

}

/*** Creates a new instance for the given scope object. */

public static ScriptRunner newInstance(Object scope, String variable) {

return new ScriptRunner(scope, variable);

}

/***

* Runs the specified Jython script. First runs the initialization script. to

* preload the appropriate client library version.

*/

public static void run(String scriptfilename) {

try {

initPython();

PythonInterpreter python = new PythonInterpreter();

python.execfile(scriptfilename);

} catch(Exception e) {

e.printStackTrace();

}

}

/*** Initialize the python interpreter. */

private static void initPython() {

Properties props = new Properties();

// Default is 'message' which displays sys-package-mgr bloat

// Choose one of error,warning,message,comment,debug

props.setProperty("python.verbose", "error");

props.setProperty("python.path", System.getProperty("java.class.path"));

PythonInterpreter.initialize(System.getProperties(), props, new String[] {""});

}

/***

* Create and run a console using a new python interpreter for the test

* associated with this instance.

*/

public void console() throws IOException {

initPython();

InteractiveConsole python = new InteractiveConsole();

initInterpreter(python, scope, variable);

python.interact();

}

/***

* Start an interactive python interpreter using the specified set of local

* variables. Use this to interrupt a running test script. with a prompt:

*

* @param locals

*/

public static void console(PyObject locals) {

initPython();

InteractiveConsole python = new InteractiveConsole(locals);

python.interact();

}

/***

* Initialize a python interpreter.

*

* @param python

* @param scope

* @throws IOException

*/

public static void initInterpreter(PythonInterpreter python, Object scope, String variable)

throws IOException {

// Store the current test case as the this variable

python.set(variable, scope);

}

}

TAG:

我来说两句

显示全部

内容

昵称

验证

提交评论

java scriptrunner_ScriptRunner.java相关推荐

  1. java unlimited_具有无限参数的Java方法(Java method with unlimited arguments)

    具有无限参数的Java方法(Java method with unlimited arguments) Spring框架使用方法,您可以根据需要传递尽可能多的参数. 我想写一个函数,也可以采取无限量的 ...

  2. 介绍java -cp java -jar的区别

    java -cp 和 -classpath 一样,是指定类运行所依赖其他类的路径,通常是类库,jar包之类,需要全路径到jar包,window上分号";" java -cp &am ...

  3. 【Java】Java连接Mysql数据库的demo示例

    [Java]Java连接Mysql数据库的demo示例 1.安装mysql数据库 2.下载java-mysql-connector.jar包 3.完成java配置 4.写java代码运行测试 1.安装 ...

  4. java抓取网页标题内容_[Java教程]java 网页页面抓取标题和正文

    [Java教程]java 网页页面抓取标题和正文 0 2014-07-10 09:01:30 import java.io.BufferedReader;import java.io.IOExcept ...

  5. Java基础-Java中的堆内存和离堆内存机制

    Java基础-Java中的堆内存和离堆内存机制 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 转载于:https://www.cnblogs.com/yinzhengjie/p/9 ...

  6. Java 异常java.lang.IllegalArgumentException: Illegal group reference

    Java 异常java.lang.IllegalArgumentException: Illegal group reference 参考文章: (1)Java 异常java.lang.Illegal ...

  7. Java基础-JAVA中常见的数据结构介绍

    Java基础-JAVA中常见的数据结构介绍 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.什么是数据结构 答:数据结构是指数据存储的组织方式.大致上分为线性表.栈(Stack) ...

  8. 4.6 W 字总结!Java 11—Java 17特性详解

    作者 | 民工哥技术之路 来源 | https://mp.weixin.qq.com/s/SVleHYFQeePNT7q67UoL4Q Java 11 特性详解 基于嵌套的访问控制 与 Java 语言 ...

  9. 做了6年的Java,java视频教程传智播客

    JAVA基础 JAVA异常分类及处理 异常分类 异常的处理方式 Throw和throws的区别 JAVA反射 动态语言 反射机制概念 (运行状态中知道类所有的属性和方法) Java反射API 反射使用 ...

最新文章

  1. 4566: [Haoi2016]找相同字符 SAM
  2. 优化一个小时不出结果的SQL
  3. 【错误记录】Flutter 插件不兼容 ( requires Flutter SDK version >=1.22.0 <2.0.0, url_launcher >=5.7.7 <6.0.0- )
  4. 学习 OpenStack 的方法论 - 每天5分钟玩转 OpenStack(150)
  5. linux系统12,Linux操作系统12则经典应用技巧
  6. leetcode面试题 17.08. 马戏团人塔(二分法)
  7. Ubuntu下安装setuptools
  8. 缓存(之一) 使用Apache Httpd实现http缓存
  9. log4j配置详解(非常详细)
  10. GPS信号的中的GPGGA的数据
  11. python删除word表格中的某一行_python-docx添加和删除表格行、列
  12. 骁龙200/400/600/800芯片型号对应及规格介绍
  13. xml大于等于转移_Mybatis.xml文件中大于小于等于
  14. 人机对战初体验—四子棋游戏
  15. 初识计算机网络||概述
  16. html倒计时动画,js+css3倒计时动画特效
  17. edge 黑色 护眼 深色模式
  18. 什么是cache?为什么需要cache?cache存在的合理性
  19. c语言实例--十进制转化为二进制
  20. 生成订单核销二维码,扫码完成核销

热门文章

  1. 华为如何打造智能终端的有趣灵魂?(下)
  2. 递归三:变态蛙跳台阶
  3. Puppet 实验三 安装和配置
  4. Oracle 跨resetlogs的恢复
  5. Ceph:RBD在线扩容容量
  6. 解决chrome 很卡的问题
  7. SharePoint 2010 change home page或者default page
  8. erlang/thrift快速安装
  9. Centos下机器学习算法Mahout库的安装和示例
  10. (转载)jsp与servlet之间页面跳转及参数传递实例