Beispiel #1
0
  private Test genTestSuite(String className, String filename, String bundlePath)
      throws IOException {

    // remove any "non-word" characters, i.e., leave only letters
    // that should ensure the python class name is syntatically valid
    className = className.replaceAll("\\W", "");

    TestSuite ret = new TestSuite(className);
    PythonInterpreter interp = new PythonInterpreter();
    String testCode =
        "# coding=utf-8\n"
            + "from __future__ import with_statement\n"
            + "import junit\n"
            + "from junit.framework.Assert import *\n"
            + "from sikuli.Sikuli import *\n"
            + "class "
            + className
            + " (junit.framework.TestCase):\n"
            + "\tdef __init__(self, name):\n"
            + "\t\tjunit.framework.TestCase.__init__(self,name)\n"
            + "\t\tself.theTestFunction = getattr(self,name)\n"
            + "\t\tsetBundlePath('"
            + bundlePath
            + "')\n"
            + "\tdef runTest(self):\n"
            + "\t\tself.theTestFunction()\n";

    BufferedReader in = new BufferedReader(new FileReader(filename));
    String line;
    // int lineNo = 0;
    // Pattern patDef = Pattern.compile("def\\s+(\\w+)\\s*\\(");
    while ((line = in.readLine()) != null) {
      // lineNo++;
      testCode += "\t" + line + "\n";
      /*
      Matcher matcher = patDef.matcher(line);
      if(matcher.find()){
         String func = matcher.group(1);
         Debug.log("Parsed " + lineNo + ": " + func);
         _lineNoOfTest.put( func, lineNo );
      }
      */
    }
    interp.exec(testCode);
    PyList tests =
        (PyList)
            interp.eval(
                "[" + className + "(f) for f in dir(" + className + ") if f.startswith(\"test\")]");
    while (tests.size() > 0) {
      PyObject t = tests.pop();
      Test t2 = (Test) (t).__tojava__(TestCase.class);
      ret.addTest(t2);
    }

    return ret;
  }
Beispiel #2
0
  public void open(File file) {
    try {
      BufferedReader in = new BufferedReader(new FileReader(file));
      game = "";

      for (String s = in.readLine(); s != null; s = in.readLine()) {
        game += s + "\n";
      }
      game.trim();
      in.close();
    } catch (IOException e) {
      System.out.println("File I/O error!");
    }
  }
 private void readLST(String file) {
   BufferedReader input;
   try {
     input = new BufferedReader(new FileReader(new File(file)));
     try {
       String line;
       while ((line = input.readLine()) != null)
         if (!line.isEmpty()) readDAT(ysDir + "/" + line.substring(0, line.indexOf(" ")));
     } finally {
       input.close();
     }
   } catch (IOException ex) {
     System.out.println(ex);
   }
 }
  protected String consume(BufferedReader br) throws Exception {
    StringBuilder ret = new StringBuilder();

    int ch;
    while ((ch = br.read()) != -1) ret.appendCodePoint(ch);

    return ret.toString();
  }
 private void readDAT(String file) {
   BufferedReader input;
   try {
     input = new BufferedReader(new FileReader(new File(file)));
     try {
       String line;
       while ((line = input.readLine()) != null) {
         int index = line.indexOf("IDENTIFY ");
         int index2 = line.indexOf("IDENTIFY ".toLowerCase());
         if (index != -1) localDB.add(line.substring(index + 10, line.length() - 1));
         else if (index2 != -1) localDB.add(line.substring(index2 + 10, line.length() - 1));
       }
     } finally {
       input.close();
     }
   } catch (IOException ex) {
     System.out.println(ex);
   }
 }
Beispiel #6
0
 private String physReadTextFile(File file) {
   // physically read text file
   try {
     BufferedReader input = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
     StringBuffer tmp = new StringBuffer();
     while (input.ready()) {
       tmp.append(input.readLine());
       tmp.append("\n");
     }
     return tmp.toString();
   } catch (FileNotFoundException e) {
     // not sure how this can happen
     showErrorDialog("Unable to load \"" + file.getName() + "\" (file not found)");
   } catch (IOException e) {
     // This happens if e.g. file already exists and
     // we do not have write permissions
     showErrorDialog("Unable to load \"" + file.getName() + "\" (I/O error)");
   }
   return new String("");
 }
 public void setSolution(File file) throws FileNotFoundException, IOException {
   FileInputStream fstream = new FileInputStream(file);
   // Get the object of DataInputStream
   DataInputStream in = new DataInputStream(fstream);
   BufferedReader br = new BufferedReader(new InputStreamReader(in));
   String strLine;
   strLine = br.readLine();
   sol_rows = Integer.valueOf(strLine);
   strLine = br.readLine();
   sol_columns = Integer.valueOf(strLine);
   sol_data = new char[sol_rows][sol_columns];
   // Read File Line By Line
   for (int i = 0; i < sol_rows; i++) {
     strLine = br.readLine();
     for (int j = 0; j < 2 * sol_columns; j += 2) {
       sol_data[i][(j / 2)] = strLine.charAt(j);
     }
   }
   br.close();
 }
    protected void loadAirspacesFromPath(String path, Collection<Airspace> airspaces) {
      File file = ExampleUtil.saveResourceToTempFile(path, ".zip");
      if (file == null) return;

      try {
        ZipFile zipFile = new ZipFile(file);

        ZipEntry entry = null;
        for (Enumeration<? extends ZipEntry> e = zipFile.entries();
            e.hasMoreElements();
            entry = e.nextElement()) {
          if (entry == null) continue;

          String name = WWIO.getFilename(entry.getName());

          if (!(name.startsWith("gov.nasa.worldwind.render.airspaces") && name.endsWith(".xml")))
            continue;

          String[] tokens = name.split("-");

          try {
            Class c = Class.forName(tokens[0]);
            Airspace airspace = (Airspace) c.newInstance();
            BufferedReader input =
                new BufferedReader(new InputStreamReader(zipFile.getInputStream(entry)));
            String s = input.readLine();
            airspace.restoreState(s);
            airspaces.add(airspace);

            if (tokens.length >= 2) {
              airspace.setValue(AVKey.DISPLAY_NAME, tokens[1]);
            }
          } catch (Exception ex) {
            ex.printStackTrace();
          }
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
Beispiel #9
0
  // this constructor takes as an arg the list of file names that are gonna be displayed
  ShowFiles(ArrayList<String> myFiles) {

    // if it is an empty file list, do nothing
    if (myFiles.size() == 0) return;

    // remember the list of files
    myFileList = myFiles;

    // this is the current file to display
    myFName = myFiles.remove(0);

    try {

      // open up the file to display
      FileReader myFile = new FileReader(myFName);
      BufferedReader myReader = new BufferedReader(myFile);
      String myString;

      // and build up the string to display
      stringToCheck = "";
      while ((myString = myReader.readLine()) != null) {
        stringToCheck += (myString + "\n");
      }

      // close the reader when done
      myReader.close();
    } catch (Exception e) {
      throw new RuntimeException("Problem opening/reading file");
    }

    // start up the window and wait until it is done
    (new Thread(this)).start();
    waitUntilDone();

    // and recursively display the rest of the files
    ShowFiles temp = new ShowFiles(myFiles);
    myFiles.add(0, myFName);
  }
  public java.util.List<String> readTextFromJar(String s) {
    InputStream is = null;
    BufferedReader br = null;
    String line;
    ArrayList<String> list = new ArrayList<String>();

    try {
      is = getClass().getResourceAsStream(s);
      br = new BufferedReader(new InputStreamReader(is));
      while (null != (line = br.readLine())) {
        list.add(line);
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      try {
        if (br != null) br.close();
        if (is != null) is.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    return list;
  }
  public void setGoal(File file) throws FileNotFoundException, IOException {
    FileInputStream fstream = new FileInputStream(file);
    // Get the object of DataInputStream
    DataInputStream in = new DataInputStream(fstream);
    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String strLine;
    // Read File Line By Line
    strLine = br.readLine();
    input_count = Integer.valueOf(br.readLine());
    results = new String[input_count];
    tapes = new String[input_count];

    for (int i = 0; i < input_count; i++) {
      results[i] = br.readLine();
      tapes[i] = br.readLine();
    }
    jLabel1.setText(strLine);
    jLabel1.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.BLACK));
    br.close();
  }
Beispiel #12
0
  public boolean loadSourceFile(File file) {
    boolean result = false;

    selectedPath = file.getParent();

    BufferedReader sourceFile = null;

    String directoryPath = file.getParent();
    String sourceName = file.getName();

    int idx = sourceName.lastIndexOf(".");
    fileExt = idx == -1 ? "" : sourceName.substring(idx + 1);
    baseName = idx == -1 ? sourceName.substring(0) : sourceName.substring(0, idx);
    String basePath = directoryPath + File.separator + baseName;

    DataOptions.directoryPath = directoryPath;

    sourcePath = file.getPath();

    AssemblerOptions.sourcePath = sourcePath;
    AssemblerOptions.listingPath = basePath + ".lst";
    AssemblerOptions.objectPath = basePath + ".cd";

    String var = System.getenv("ROPE_MACROS_DIR");
    if (var != null && !var.isEmpty()) {
      File dir = new File(var);
      if (dir.exists() && dir.isDirectory()) {
        AssemblerOptions.macroPath = var;
      } else {
        AssemblerOptions.macroPath = directoryPath;
      }
    } else {
      AssemblerOptions.macroPath = directoryPath;
    }

    DataOptions.inputPath = AssemblerOptions.objectPath;
    DataOptions.outputPath = basePath + ".out";
    DataOptions.readerPath = null;
    DataOptions.punchPath = basePath + ".pch";
    DataOptions.tape1Path = basePath + ".mt1";
    DataOptions.tape2Path = basePath + ".mt2";
    DataOptions.tape3Path = basePath + ".mt3";
    DataOptions.tape4Path = basePath + ".mt4";
    DataOptions.tape5Path = basePath + ".mt5";
    DataOptions.tape6Path = basePath + ".mt6";

    this.setTitle("EDIT: " + sourceName);
    fileText.setText(sourcePath);

    if (dialog == null) {
      dialog = new AssemblerDialog(mainFrame, "Assembler options");

      Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
      Dimension dialogSize = dialog.getSize();
      dialog.setLocation(
          (screenSize.width - dialogSize.width) / 2, (screenSize.height - dialogSize.height) / 2);
    }

    dialog.initialize();

    AssemblerOptions.command = dialog.buildCommand();

    sourceArea.setText(null);

    try {
      sourceFile = new BufferedReader(new FileReader(file));
      String line;

      while ((line = sourceFile.readLine()) != null) {
        sourceArea.append(line + "\n");
      }

      sourceArea.setCaretPosition(0);
      optionsButton.setEnabled(true);
      assembleButton.setEnabled(true);
      saveButton.setEnabled(true);

      setSourceChanged(false);
      undoMgr.discardAllEdits();

      result = true;
    } catch (IOException ex) {
      ex.printStackTrace();
    } finally {
      try {
        if (sourceFile != null) {
          sourceFile.close();
        }
      } catch (IOException ignore) {
      }
    }

    return result;
  }
Beispiel #13
0
  public GameFile() {
    game = "";

    // load character names and descriptions
    characters = "";
    File characterFile = new File("/home/cory/Programming/treasure_hunt/data/characters.data");
    try {
      BufferedReader in = new BufferedReader(new FileReader(characterFile));
      for (String s = in.readLine(); s != null; s = in.readLine()) {
        characters += s + "\n";
      }
      characters.trim();
      in.close();
    } catch (IOException e) {
      System.out.println("File I/O error! Couldn't load character data file.");
      System.exit(1);
    }

    // load weapon names and descriptions
    weapons = "";
    File weaponFile = new File("/home/cory/Programming/treasure_hunt/data/weapons.data");
    try {
      BufferedReader in = new BufferedReader(new FileReader(weaponFile));
      for (String s = in.readLine(); s != null; s = in.readLine()) {
        weapons += s + "\n";
      }
      weapons.trim();
      in.close();
    } catch (IOException e) {
      System.out.println("File I/O error! Couldn't load weapon data file.");
      System.exit(1);
    }

    // load treasure names and desciptions
    treasures = "";
    File treasureFile = new File("/home/cory/Programming/treasure_hunt/data/treasures.data");
    try {
      BufferedReader in = new BufferedReader(new FileReader(treasureFile));
      for (String s = in.readLine(); s != null; s = in.readLine()) {
        treasures += s + "\n";
      }
      treasures.trim();
      in.close();
    } catch (IOException e) {
      System.out.println("File I/O error! Couldn't load treasure data file.");
      System.exit(1);
    }
  }
 private void ys_cfg(File file) throws FileNotFoundException, IOException, URISyntaxException {
   BufferedReader input;
   String line;
   input = new BufferedReader(new FileReader(file));
   try {
     while ((line = input.readLine()) != null) {
       if (line.length() > 17) {
         if (line.substring(0, 17).equals("YSDIR           =")) {
           ysDir = line.substring(17);
           try {
             file = new File(ysDir + "/config/network.cfg");
             input = new BufferedReader(new FileReader(file));
             try {
               while ((line = input.readLine()) != null) {
                 line = line.trim();
                 if (line.substring(0, 10).equals("PORTNUMBER")) {
                   portBox.setText(line.substring(11));
                 }
               }
             } finally {
               input.close();
             }
             try {
               URL url = new URL("http://www.yspilots.com/shadowhunters/rssList.php");
               BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
               String s;
               while ((s = in.readLine()) != null) {
                 if (s.indexOf("http://www.yspilots.com/shadowhunters/get_info.php?ip=") != -1)
                   ipBox.addItem(
                       s.substring(
                           s.indexOf("http://www.yspilots.com/shadowhunters/get_info.php?ip=")
                               + 54,
                           s.indexOf("&amp;port=")));
               }
               in.close();
             } catch (IOException ex) {
               JOptionPane.showMessageDialog(
                   this,
                   "Impossible to get the online server list!",
                   "addonsearch",
                   JOptionPane.ERROR_MESSAGE);
               file = new File(ysDir + "/config/serverhistory.txt");
               input = new BufferedReader(new FileReader(file));
               try {
                 while ((line = input.readLine()) != null) {
                   if (line.length() > 0) {
                     ipBox.addItem(line.trim());
                   }
                 }
               } finally {
                 input.close();
               }
             }
           } catch (IOException ex) {
             JOptionPane.showMessageDialog(
                 this,
                 "Impossible to find the file " + file.getName() + " or to read it!\n" + ex,
                 "addonsearch",
                 JOptionPane.ERROR_MESSAGE);
           }
         } else if (line.substring(0, 17).equals("YSVERSION       =")) {
           versionBox.setText(line.substring(17));
         }
       }
     }
   } finally {
     input.close();
   }
 }
Beispiel #15
0
  // Run selected test cases.
  private void runTests() {

    for (int i = 0; i < tests.size(); i++) {
      // If box for test is checked, run it.
      if (tests.get(i).isSelected()) {

        // Get the URLs of all of the required files.
        String folderURL = tests.get(i).getText();
        String testURL = folderURL.concat(folderURL.substring(folderURL.lastIndexOf('/')));
        String efgFile = testURL + ".EFG";
        String guiFile = testURL + ".GUI";
        String tstFile = testURL + ".TST";
        String prgFile = testURL + ".PRG";

        // attempt to read in file with program's parameters
        try {
          FileInputStream fstream = new FileInputStream(prgFile);
          DataInputStream in = new DataInputStream(fstream);
          BufferedReader br = new BufferedReader(new InputStreamReader(in));
          HashMap<String, String> prgParams = new HashMap<String, String>();
          String strLine;
          while ((strLine = br.readLine()) != null) {
            // add found parameters into prgParams as <key, value>
            String[] matches = strLine.split("=");
            prgParams.put(matches[0], matches[1]);
          }

          if (prgParams.containsKey("path") && prgParams.containsKey("main")) {
            programPath = prgParams.get("path");
            mainClass = prgParams.get("main");
          }

          in.close();
        } catch (Exception e) {
          System.err.println(e.getMessage());
        }

        System.out.println("We hit Run");

        // Run the replayer using the three test files.
        System.out.println(
            "../../../dist/guitar/jfc-replayer.sh -cp "
                + programPath
                + " -c "
                + mainClass
                + " -g "
                + guiFile
                + " -e "
                + efgFile
                + " -t "
                + tstFile);
        try {
          Runtime rt = Runtime.getRuntime();
          Process proc =
              rt.exec(
                  "../../../dist/guitar/jfc-replayer.sh -cp "
                      + programPath
                      + " -c "
                      + mainClass
                      + " -g "
                      + guiFile
                      + " -e "
                      + efgFile
                      + " -t "
                      + tstFile);

          // InputStream ips = proc.getInputStream();
          BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
          String inputLine;
          while ((inputLine = in.readLine()) != null) System.out.println(inputLine);
          in.close();

        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
  }