Beispiel #1
0
  public static void save(final ArrayList elements, final String sFilename) {

    try {
      final File file = new File(sFilename);
      if (!file.exists()) {
        final String dir = file.getParent();
        new File(dir).mkdir();
        file.createNewFile();
      }
      final Writer writer = new FileWriter(file);
      final KXmlSerializer serializer = new KXmlSerializer();
      serializer.setOutput(writer);
      serializer.startDocument(encoding, new Boolean(true));
      serializer.text("\n\t");
      serializer.startTag(null, HELP);
      for (int i = 0; i < elements.size(); i++) {
        final HelpElement element = (HelpElement) elements.get(i);
        element.serialize(serializer);
      }
      serializer.text("\n\t");
      serializer.endTag(null, HELP);
      serializer.text("\n");
      serializer.startDocument(encoding, new Boolean(true));
      writer.close();
    } catch (final IOException e) {
      e.printStackTrace();
    }
  }
  /**
   * Si existe la version de paleta 1.0, la actualizara a la 1.1 y renombrará la antigua version.
   *
   * @param palettesBasePath
   * @param colorTable
   */
  public static void save_to_1_1(String palettesBasePath, ColorTable colorTable) {
    try {
      // Generar nuevo fichero
      KXmlSerializer parserOutput = new KXmlSerializer();
      FileOutputStream out =
          new FileOutputStream(palettesBasePath + File.separator + colorTable.getName() + ".xml");
      OutputStreamWriter writer = new OutputStreamWriter(out, "UTF8");
      parserOutput.setOutput(writer);
      parserOutput.startDocument("UTF-8", null);
      parserOutput.startTag(null, "ColorTable");
      parserOutput.attribute(null, "name", colorTable.getName());
      parserOutput.attribute(null, "version", "1.1");
      parserOutput.text("\n");

      ArrayList items = colorTable.getColorItems();
      for (int i = 0; i < items.size(); i++) {
        ColorItem colorItem = (ColorItem) items.get(i);
        parserOutput.startTag(null, "Color");
        parserOutput.attribute(null, "value", String.valueOf(colorItem.getValue()));
        if (colorItem.getNameClass() != null)
          parserOutput.attribute(null, "name", String.valueOf(colorItem.getNameClass()));
        else parserOutput.attribute(null, "name", "");
        Color color = colorItem.getColor();
        parserOutput.attribute(
            null,
            "rgb",
            String.valueOf(color.getRed() + "," + color.getGreen() + "," + color.getBlue()));
        parserOutput.attribute(null, "interpolated", String.valueOf(colorItem.getInterpolated()));
        parserOutput.endTag(null, "Color");
        parserOutput.text("\n");
      }

      for (int i = 0; i < items.size(); i++) {
        ColorItem colorItem = (ColorItem) items.get(i);
        parserOutput.startTag(null, "Alpha");
        parserOutput.attribute(null, "value", String.valueOf(colorItem.getValue()));
        parserOutput.attribute(null, "alpha", String.valueOf(colorItem.getColor().getAlpha()));
        parserOutput.attribute(null, "interpolated", String.valueOf(colorItem.getInterpolated()));
        parserOutput.endTag(null, "Alpha");
        parserOutput.text("\n");
      }

      parserOutput.endTag(null, "ColorTable");
      parserOutput.text("\n");
      parserOutput.endDocument();
      // Cerrar nuevo fichero
      writer.close();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  /**
   * Crea los ficheros que forman la paleta de color de la version 1.1 a traves de un XML que se le
   * pasa por parametro
   *
   * @param palettesPath
   */
  private static void createVersionFromXML(String palettesBasePath, String xml) {
    new File(palettesBasePath).mkdir();
    KXmlParser parser = new KXmlParser();
    StringReader reader = new StringReader(xml);
    try {
      parser.setInput(reader);
      int tag = parser.nextTag();

      parser.require(KXmlParser.START_TAG, null, "palettes");
      tag = parser.nextTag();
      parser.require(KXmlParser.START_TAG, null, "palette_list");
      parser.skipSubTree();
      parser.require(KXmlParser.END_TAG, null, "palette_list");
      tag = parser.nextTag();

      while (tag == KXmlParser.START_TAG) {
        parser.require(KXmlParser.START_TAG, null, "palette");
        if (parser.getAttributeCount() == 2) {
          // Generar nuevo fichero
          KXmlSerializer parserOutput = new KXmlSerializer();
          FileOutputStream fileOutputStream =
              new FileOutputStream(
                  palettesBasePath + File.separator + parser.getAttributeValue(0) + ".xml");

          parserOutput.setOutput(fileOutputStream, null);
          parserOutput.startDocument("UTF-8", null);
          parserOutput.startTag(null, "ColorTable");
          parserOutput.attribute(null, "name", parser.getAttributeValue(0));
          parserOutput.attribute(null, "version", "1.1");

          tag = parser.nextTag();
          parser.require(KXmlParser.START_TAG, null, "table");
          tag = parser.nextTag();

          parserOutput.text("\n");
          ArrayList items = new ArrayList();
          while (tag == KXmlParser.START_TAG) {
            parser.require(KXmlParser.START_TAG, null, "entry");
            if (parser.getAttributeCount() == 3) {
              String rgb =
                  parser
                      .getAttributeValue(1)
                      .substring(
                          parser.getAttributeValue(1).indexOf(",") + 1,
                          parser.getAttributeValue(1).length());

              int a =
                  Integer.valueOf(
                          parser
                              .getAttributeValue(1)
                              .substring(0, parser.getAttributeValue(1).indexOf(",")))
                      .intValue();
              int r = Integer.valueOf(rgb.substring(0, rgb.indexOf(","))).intValue();
              int g =
                  Integer.valueOf(rgb.substring(rgb.indexOf(",") + 1, rgb.lastIndexOf(",")))
                      .intValue();
              int b =
                  Integer.valueOf(rgb.substring(rgb.lastIndexOf(",") + 1, rgb.length())).intValue();

              ColorItem colorItem = new ColorItem();
              colorItem.setColor(new Color(r, g, b, a));
              colorItem.setInterpolated(50);
              colorItem.setNameClass(parser.getAttributeValue(0));
              colorItem.setValue(Double.parseDouble(parser.getAttributeValue(2)));
              items.add(colorItem);
            }
            tag = parser.nextTag();
            parser.require(KXmlParser.END_TAG, null, "entry");
            tag = parser.nextTag();
          }
          parser.require(KXmlParser.END_TAG, null, "table");
          tag = parser.nextTag();

          ColorTable colorTable = new ColorTable();
          colorTable.createPaletteFromColorItems(items, true);
          items = colorTable.getColorItems();
          for (int i = 0; i < items.size(); i++) {
            ColorItem colorItem = (ColorItem) items.get(i);
            parserOutput.startTag(null, "Color");
            parserOutput.attribute(null, "value", String.valueOf(colorItem.getValue()));
            parserOutput.attribute(null, "name", String.valueOf(colorItem.getNameClass()));
            Color color = colorItem.getColor();
            parserOutput.attribute(
                null,
                "rgb",
                String.valueOf(color.getRed() + "," + color.getGreen() + "," + color.getBlue()));
            parserOutput.attribute(
                null, "interpolated", String.valueOf(colorItem.getInterpolated()));
            parserOutput.endTag(null, "Color");
            parserOutput.text("\n");
          }

          for (int i = 0; i < items.size(); i++) {
            ColorItem colorItem = (ColorItem) items.get(i);
            parserOutput.startTag(null, "Alpha");
            parserOutput.attribute(null, "value", String.valueOf(colorItem.getValue()));
            parserOutput.attribute(null, "alpha", String.valueOf(colorItem.getColor().getAlpha()));
            parserOutput.attribute(
                null, "interpolated", String.valueOf(colorItem.getInterpolated()));
            parserOutput.endTag(null, "Alpha");
            parserOutput.text("\n");
          }

          parserOutput.endTag(null, "ColorTable");
          parserOutput.text("\n");
          parserOutput.endDocument();
          // Cerrar nuevo fichero
          fileOutputStream.close();
        }
        parser.require(KXmlParser.END_TAG, null, "palette");
        tag = parser.nextTag();
      }
      parser.require(KXmlParser.END_TAG, null, "palettes");
    } catch (XmlPullParserException xmlEx) {
      System.out.println(
          "El fichero de paletas predeterminadas no tiene la estructura correcta:\n	"
              + xmlEx.getMessage());
    } catch (IOException e) {
    }
  }
Beispiel #4
0
  // @see PHPUnit/Util/Log/JUnit.php#startTestSuite
  public void writeResult(boolean store_output, PhpUnitTestResult result)
      throws IllegalArgumentException, IllegalStateException, IOException {
    if (closed)
      throw new IllegalStateException("can not write to closed PhpUnitResultWriter. it is closed.");

    if (result.ini != null && (this.ini == null || !this.ini.equals(result.ini)))
      this.ini = result.ini;
    test_count++;

    final String test_name = result.getName();
    status_list_map.get(result.status).write(test_name, result);

    if ((store_output
            || (result.status == EPhpUnitTestStatus.FAILURE
                || result.status == EPhpUnitTestStatus.ERROR
                || result.status == EPhpUnitTestStatus.CRASH))
        && StringUtil.isNotEmpty(result.output)) {
      // store crash output too: for exit code and status
      output_by_name.put(test_name, result.output);
    }

    // write file header
    String test_suite_name =
        result.test_case.getPhpUnitDist() != null
                && result.test_case.getPhpUnitDist().getPath() != null
            ? result.test_case.getPhpUnitDist().getPath().getPath()
            : null;
    if (is_first_result) {
      main_serial.startDocument("utf-8", null);
      main_serial.setPrefix("pftt", "pftt");
      main_serial.startTag(null, "testsuites");
      writeTestSuiteStart(test_suite_name);

      is_first_result = false;
    } else if (test_suite_name != null
        && last_test_suite_name != null
        && !test_suite_name.equals(last_test_suite_name)) {
      writeTestSuiteEnd();
      writeTestSuiteStart(test_suite_name);
    }
    last_test_suite_name = test_suite_name;
    //

    // write result itself
    result.serial(main_serial);

    //
    if ((result.code_coverage != null || result.extra != null)
        && PhpUnitTestResult.shouldStoreAllInfo(result.status)) {
      // store this data in a separate file
      File f =
          new File(
              dir,
              result
                      .getName()
                      .replace("::", "_")
                      .replace("(", "_")
                      .replace(")", "")
                      .replace(".php", "")
                  + ".xml");
      f.getParentFile().mkdirs(); // ensure directory exists
      FileWriter fw = new FileWriter(f);
      extra_serial.setOutput(fw);
      extra_serial.startDocument("utf-8", Boolean.TRUE);
      extra_serial.startTag("pftt", "phpUnitTestResult");
      if (result.extra != null) result.extra.serial(extra_serial);
      if (result.code_coverage != null) result.code_coverage.serial(extra_serial);
      extra_serial.endTag("pftt", "phpUnitTestResult");
      extra_serial.endDocument();
      extra_serial.flush();
      fw.close();
    }
    //

    // store name, status and run-time in CSV format
    all_csv_pw.print("'");
    all_csv_pw.print(test_name);
    all_csv_pw.print("','");
    all_csv_pw.print(result.status);
    all_csv_pw.print("',");
    all_csv_pw.print(result.run_time_micros);
    all_csv_pw.println();
  } // end public void writeResult