public void close(boolean store_output) throws IllegalArgumentException, IllegalStateException, IOException { if (closed) return; closed = true; started_pw.close(); all_csv_pw.close(); writeTestSuiteEnd(); writeTally(); main_serial.endTag(null, "testsuites"); main_serial.endDocument(); main_serial.flush(); out.close(); // @see PhpUnitReader#readTally { FileWriter fw = new FileWriter(new File(dir.getAbsolutePath() + "/tally.xml")); main_serial.setOutput(fw); writeTally(); // write again - this file is smaller and faster to read main_serial.flush(); fw.close(); } // // do this after finishing phpunit.xml since that's more important than alphabetizing text file // lists for (StatusListEntry e : status_list_map.values()) e.close(); if (!store_output) output_by_name = null; } // end public void close
public void generateXmlListOfForms(PrintWriter output, CallingContext cc) throws IOException, ODKDatastoreException { Document d = new Document(); d.setStandalone(true); d.setEncoding(HtmlConsts.UTF8_ENCODE); Element e = d.createElement(XML_TAG_NAMESPACE, XFormsTableConsts.XFORMS_TAG); e.setPrefix(null, XML_TAG_NAMESPACE); d.addChild(0, Node.ELEMENT, e); int idx = 0; e.addChild(idx++, Node.IGNORABLE_WHITESPACE, BasicConsts.NEW_LINE); // build XML table of form information for (IForm form : forms) { if (!form.getDownloadEnabled()) continue; idx = generateFormXmlEntry(d, e, idx, form, cc); } KXmlSerializer serializer = new KXmlSerializer(); serializer.setOutput(output); // setting the response content type emits the xml header. // just write the body here... d.writeChildren(serializer); serializer.flush(); }
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(); } }
public PhpUnitResultWriter( File dir, PhpBuildInfo build_info, AHost host, ScenarioSetSetup scenario_set_setup, PhpUnitSourceTestPack test_pack) throws FileNotFoundException, IOException { this.build_info = build_info; this.host = host; this.scenario_set_setup = scenario_set_setup; this.test_pack_name_and_version = test_pack.getNameAndVersionString().intern(); this.dir = dir; dir.mkdirs(); all_csv_pw = new PrintWriter(new FileWriter(new File(dir, "ALL.csv"))); started_pw = new PrintWriter(new FileWriter(new File(dir, "STARTED.txt"))); output_by_name = new HashMap<String, String>(800); // include scenario-set in file name to make it easier to view a bunch of them in Notepad++ or // other MDIs File file = new File( dir + "/" + StringUtil.max( "phpunit_" + test_pack.getName() + "_" + scenario_set_setup.getNameWithVersionInfo(), 40) + ".xml"); // XXX write host, scenario_set and build to file (do in #writeTally or #close) main_serial = new KXmlSerializer(); extra_serial = new KXmlSerializer(); main_serial.setOutput(out = new BufferedOutputStream(new FileOutputStream(file)), "utf-8"); // setup serializer to indent XML (pretty print) so its easy for people to read main_serial.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); extra_serial.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); status_list_map = new HashMap<EPhpUnitTestStatus, StatusListEntry>(); for (EPhpUnitTestStatus status : EPhpUnitTestStatus.values()) { status_list_map.put(status, new StatusListEntry(status)); } }
@Override protected void serializeAttributes(final KXmlSerializer serializer) throws NullParameterAdditionalInfoException, IOException { final AdditionalInfoTableField aitf = (AdditionalInfoTableField) m_ParameterAdditionalInfo; if (aitf != null) { serializer.text("\n"); serializer.text("\t\t\t"); serializer.startTag(null, ATTRIBUTE); serializer.attribute(null, NAME, PARENT); serializer.attribute(null, VALUE, aitf.getParentParameterName()); serializer.endTag(null, ATTRIBUTE); serializer.text("\n"); serializer.text("\t\t\t"); serializer.startTag(null, ATTRIBUTE); serializer.attribute(null, NAME, MANDATORY); serializer.attribute(null, VALUE, Boolean.valueOf(aitf.getIsMandatory()).toString()); serializer.endTag(null, ATTRIBUTE); } else { throw new NullParameterAdditionalInfoException(); } }
private static void writeSubmissionManifest( EncryptedFormInformation formInfo, File submissionXml, List<File> mediaFiles) throws EncryptionException { Document d = new Document(); d.setStandalone(true); d.setEncoding(UTF_8); Element e = d.createElement(XML_ENCRYPTED_TAG_NAMESPACE, DATA); e.setPrefix(null, XML_ENCRYPTED_TAG_NAMESPACE); e.setAttribute(null, ID, formInfo.formId); if (formInfo.formVersion != null) { e.setAttribute(null, VERSION, formInfo.formVersion); } e.setAttribute(null, ENCRYPTED, "yes"); d.addChild(0, Node.ELEMENT, e); int idx = 0; Element c; c = d.createElement(XML_ENCRYPTED_TAG_NAMESPACE, BASE64_ENCRYPTED_KEY); c.addChild(0, Node.TEXT, formInfo.base64RsaEncryptedSymmetricKey); e.addChild(idx++, Node.ELEMENT, c); c = d.createElement(XML_OPENROSA_NAMESPACE, META); c.setPrefix("orx", XML_OPENROSA_NAMESPACE); { Element instanceTag = d.createElement(XML_OPENROSA_NAMESPACE, INSTANCE_ID); instanceTag.addChild(0, Node.TEXT, formInfo.instanceMetadata.instanceId); c.addChild(0, Node.ELEMENT, instanceTag); } e.addChild(idx++, Node.ELEMENT, c); e.addChild(idx++, Node.IGNORABLE_WHITESPACE, NEW_LINE); if (mediaFiles != null) { for (File file : mediaFiles) { c = d.createElement(XML_ENCRYPTED_TAG_NAMESPACE, MEDIA); Element fileTag = d.createElement(XML_ENCRYPTED_TAG_NAMESPACE, FILE); fileTag.addChild(0, Node.TEXT, file.getName() + ".enc"); c.addChild(0, Node.ELEMENT, fileTag); e.addChild(idx++, Node.ELEMENT, c); e.addChild(idx++, Node.IGNORABLE_WHITESPACE, NEW_LINE); } } c = d.createElement(XML_ENCRYPTED_TAG_NAMESPACE, ENCRYPTED_XML_FILE); c.addChild(0, Node.TEXT, submissionXml.getName() + ".enc"); e.addChild(idx++, Node.ELEMENT, c); c = d.createElement(XML_ENCRYPTED_TAG_NAMESPACE, BASE64_ENCRYPTED_ELEMENT_SIGNATURE); c.addChild(0, Node.TEXT, formInfo.getBase64EncryptedElementSignature()); e.addChild(idx++, Node.ELEMENT, c); FileOutputStream fout = null; OutputStreamWriter writer = null; try { fout = new FileOutputStream(submissionXml); writer = new OutputStreamWriter(fout, UTF_8); KXmlSerializer serializer = new KXmlSerializer(); serializer.setOutput(writer); // setting the response content type emits the xml header. // just write the body here... d.writeChildren(serializer); serializer.flush(); writer.flush(); fout.getChannel().force(true); writer.close(); } catch (Exception ex) { ex.printStackTrace(); String msg = "Error writing submission.xml for encrypted submission: " + submissionXml.getParentFile().getName(); Log.e(t, msg); throw new EncryptionException(msg, ex); } finally { IOUtils.closeQuietly(writer); IOUtils.closeQuietly(fout); } }
/** * 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) { } }
private void writeTally() throws IllegalArgumentException, IllegalStateException, IOException { main_serial.startTag("pftt", "tally"); main_serial.attribute(null, "test_pack_name_and_version", test_pack_name_and_version); main_serial.attribute(null, "os_name", host.getOSNameLong()); main_serial.attribute(null, "test_count", Integer.toString(test_count)); main_serial.attribute(null, "percent_total", Integer.toString(getTestCount())); main_serial.attribute(null, "pass", Integer.toString(count(EPhpUnitTestStatus.PASS))); main_serial.attribute(null, "pass_percent", Float.toString(passRate())); main_serial.attribute(null, "timeout", Integer.toString(count(EPhpUnitTestStatus.TIMEOUT))); main_serial.attribute(null, "failure", Integer.toString(count(EPhpUnitTestStatus.FAILURE))); main_serial.attribute( null, "failure_percent", Float.toString( 100.0f * (((float) count(EPhpUnitTestStatus.FAILURE)) / ((float) getTestCount())))); main_serial.attribute(null, "error", Integer.toString(count(EPhpUnitTestStatus.ERROR))); main_serial.attribute( null, "error_percent", Float.toString( 100.0f * (((float) count(EPhpUnitTestStatus.ERROR)) / ((float) getTestCount())))); main_serial.attribute(null, "crash", Integer.toString(count(EPhpUnitTestStatus.CRASH))); main_serial.attribute( null, "crash_percent", Float.toString( 100.0f * (((float) count(EPhpUnitTestStatus.CRASH)) / ((float) getTestCount())))); main_serial.attribute(null, "skip", Integer.toString(count(EPhpUnitTestStatus.SKIP))); main_serial.attribute(null, "xskip", Integer.toString(count(EPhpUnitTestStatus.XSKIP))); main_serial.attribute(null, "warning", Integer.toString(count(EPhpUnitTestStatus.WARNING))); main_serial.attribute(null, "notice", Integer.toString(count(EPhpUnitTestStatus.NOTICE))); main_serial.attribute( null, "deprecated", Integer.toString(count(EPhpUnitTestStatus.DEPRECATED))); main_serial.attribute( null, "not_implemented", Integer.toString(count(EPhpUnitTestStatus.NOT_IMPLEMENTED))); main_serial.attribute( null, "unsupported", Integer.toString(count(EPhpUnitTestStatus.UNSUPPORTED))); main_serial.attribute( null, "test_exception", Integer.toString(count(EPhpUnitTestStatus.TEST_EXCEPTION))); main_serial.attribute(null, "bork", Integer.toString(count(EPhpUnitTestStatus.BORK))); if (ini != null) { main_serial.startTag("pftt", "ini"); main_serial.text(ini.toString()); main_serial.endTag("pftt", "ini"); } main_serial.endTag("pftt", "tally"); } // end private void writeTally
private void writeTestSuiteEnd() throws IllegalArgumentException, IllegalStateException, IOException { main_serial.endTag(null, "testsuite"); }
private void writeTestSuiteStart(String test_suite_name) throws IllegalArgumentException, IllegalStateException, IOException { main_serial.startTag(null, "testsuite"); if (StringUtil.isNotEmpty(test_suite_name)) main_serial.attribute(null, "name", test_suite_name); }
// @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