Ejemplo n.º 1
0
  public static String getClassPath() {
    // 类库信息
    String classPath = System.getProperty("java.library.path");
    classPath += System.getProperty("java.class.path");
    //		System.out.println("^^^^^^^^^ java classpath : " + System.getProperty("java.class.path"));
    String basePath = IOUtil.getBasePath();

    if (PropertiesUtil.exist()) {
      basePath = PropertiesUtil.getInstance().readValue(PropertiesUtil.CLASS_PATH);
    }
    //		System.out.println("^^^^^^^^^basePath : " + basePath);

    File file = new File(basePath);
    if (!file.exists()) {
      Log.println("Warn: ClassPath=" + basePath + " does not exist!");
    } else if (file.isDirectory()) {
      classPath += basePath + ";";
      classPath += IOUtil.listJarFiles(basePath, ";");
    } else if (file.getName().toLowerCase().endsWith(".jar")) {
      classPath += basePath + ";";
    } else {
      classPath += IOUtil.read(basePath).replace("\r\n", "").replace("\n", "");
    }

    return classPath;
  }
Ejemplo n.º 2
0
  @Override
  public boolean compile(TestData data) {
    System.out.println("...enter JavaCompiler comple(data)...");

    if (data == null) return false;
    // 读取源码
    String source = data.getStr(JobConst.TARGET_SOURCE);

    //		System.out.println("++++++++++++++++++++++");
    //		System.out.println("souce code : " + source);
    //		if(source.indexOf("();")!=-1){
    //			String s = new String(source);
    //			Pattern pattern = Pattern.compile("=\\s*\\w*\\(\\)\\;");
    //			Matcher matcher = pattern.matcher(s);
    ////			System.out.println(matcher.replaceAll("= 5"));
    //			source = matcher.replaceAll(" = 5;\\/\\/need mocked");
    //		}
    String s = new String(source);
    Pattern pattern = Pattern.compile("valueReturned\\s*=\\s*\\w");
    Matcher matcher = pattern.matcher(s);
    //		System.out.println(matcher.replaceAll(s +"\\/\\/need mocked"));
    source = matcher.replaceAll("valueReturned = 8;\\/\\/need mocked");
    //		System.out.println("++++++++++++++++++++++");
    // 输出源码

    data.copyList(getSrc());
    // 组合输入文件名, 写入临时输出目录
    IOUtil.write(getSrc() + data.getSourceFile().getName(), source);
    setStaticSourceFileName(data.getSourceFile().getName());
    //		System.out.println("========++++++" + data.getSourceFile().getName());
    // 输出信息
    warnFile = getSrc() + WARN;

    String classPath = data.getStr(JobConst.CLASS_PATH);
    if (classPath.isEmpty()) {
      classPath = getClassPath();
    }
    // Debug.println(classPath);

    // 输出make文件
    StringBuilder sb = new StringBuilder();
    ArrayList<String> arr = data.getCompiledList();
    for (int i = 0; i < arr.size(); i++) {
      sb.append(getSrc() + arr.get(i) + JobConst.ENTER);
    }
    Log.println("1111" + getSrc());
    // Debug.println(classPath);
    IOUtil.write(getSrc() + MAKE, sb.toString());

    if (!compile(classPath, getBin(), "@" + getSrc() + MAKE, warnFile)) {
      data.getResult().addReport(IOUtil.read(warnFile));
      // data.put(JobConst.COMPILED_REPORT, IOUtil.read(warnFile));
      return false;
    } else return true;
  }
Ejemplo n.º 3
0
  public String testingImp(int type, String code, String options) {
    Log.println("Receive: type=" + type + " options=" + options);
    long startTime = System.currentTimeMillis();
    ITesting testing;
    switch (type) {
      case 0:
        System.out.println("0000000");
        testing = new CppASTTesting();
        break;
      case 1:
        System.out.println("1111111");
        testing = new CppBPStumpTesting();
        break;
      case 2:
        System.out.println("2222222");
        testing = new CppBPTesting();
        break;
      case 3:
        System.out.println("3333333");
        testing = new CppConditionStumpTesting();
        break;
      case 4:
        System.out.println("4444444");
        testing = new CppConditionTesting();
        break;
      case 5:
        System.out.println("5555555");
        testing = new JavaASTTesting();
        break;
      case 6:
        System.out.println("6666666");
        testing = new JavaBPStumpTesting();
        break;
      case 7:
        System.out.println("7777777");
        testing = new JavaBPTesting();
        break;
      case 8:
        System.out.println("8888888");
        testing = new JavaConditionStumpTesting();
        break;
      case 9:
        System.out.println("9999999");
        testing = new JavaConditionTesting();
        break;
      case 10:
        System.out.println("10101010");
        testing = new CppFunctionTesting();
        break;
      case 11:
        System.out.println("11,11,11");
        testing = new JavaMethodTesting();
        break;
      case 13:
        System.out.println("13131313");
        testing = new JavaGetFlowGraph();
        break;
      default:
        System.out.println("default...");
        testing = new TestingImp();
    }

    String result = testing.testing(code, options);
    System.out.println("-----------------------------");
    System.out.println(result);
    //		System.out.println("result :¡¡" + result);
    long endTime = System.currentTimeMillis() - startTime;
    Log.println("Complete: cost " + endTime + "ms");

    if (type == 2 || type == 4 || type == 7 || type == 9) {
      return addTime(endTime, result);
    } else {
      return result;
    }
  }