Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update quick-xml to 0.25 #880

Merged
merged 1 commit into from Sep 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -49,7 +49,7 @@ lazy_static = "1.4"
log = "0.4"
md-5 = "0.10"
num_cpus = "1.13"
quick-xml = "0.23"
quick-xml = "0.25"
rayon = "1.5"
regex = "1.5"
rustc-hash = "1.1"
Expand Down
82 changes: 41 additions & 41 deletions src/cobertura.rs
Expand Up @@ -342,16 +342,16 @@ pub fn output_cobertura(

let mut writer = Writer::new_with_indent(Cursor::new(vec![]), b' ', 4);
writer
.write_event(Event::Decl(BytesDecl::new(b"1.0", None, None)))
.write_event(Event::Decl(BytesDecl::new("1.0", None, None)))
.unwrap();
writer
.write_event(Event::DocType(BytesText::from_escaped_str(
.write_event(Event::DocType(BytesText::from_escaped(
" coverage SYSTEM 'http://cobertura.sourceforge.net/xml/coverage-04.dtd'",
)))
.unwrap();

let cov_tag = b"coverage";
let mut cov = BytesStart::borrowed(cov_tag, cov_tag.len());
let cov_tag = "coverage";
let mut cov = BytesStart::from_content(cov_tag, cov_tag.len());
let stats = coverage.get_stats();
cov.push_attribute(("lines-covered", stats.lines_covered.to_string().as_ref()));
cov.push_attribute(("lines-valid", stats.lines_valid.to_string().as_ref()));
Expand All @@ -374,45 +374,45 @@ pub fn output_cobertura(
writer.write_event(Event::Start(cov)).unwrap();

// export header
let sources_tag = b"sources";
let source_tag = b"source";
let sources_tag = "sources";
let source_tag = "source";
writer
.write_event(Event::Start(BytesStart::borrowed(
.write_event(Event::Start(BytesStart::from_content(
sources_tag,
sources_tag.len(),
)))
.unwrap();
for path in &coverage.sources {
writer
.write_event(Event::Start(BytesStart::borrowed(
.write_event(Event::Start(BytesStart::from_content(
source_tag,
source_tag.len(),
)))
.unwrap();
writer
.write_event(Event::Text(BytesText::from_plain_str(path)))
.write_event(Event::Text(BytesText::new(path)))
.unwrap();
writer
.write_event(Event::End(BytesEnd::borrowed(source_tag)))
.write_event(Event::End(BytesEnd::new(source_tag)))
.unwrap();
}
writer
.write_event(Event::End(BytesEnd::borrowed(sources_tag)))
.write_event(Event::End(BytesEnd::new(sources_tag)))
.unwrap();

// export packages
let packages_tag = b"packages";
let pack_tag = b"package";
let packages_tag = "packages";
let pack_tag = "package";

writer
.write_event(Event::Start(BytesStart::borrowed(
.write_event(Event::Start(BytesStart::from_content(
packages_tag,
packages_tag.len(),
)))
.unwrap();
// Export the package
for package in &coverage.packages {
let mut pack = BytesStart::borrowed(pack_tag, pack_tag.len());
let mut pack = BytesStart::from_content(pack_tag, pack_tag.len());
pack.push_attribute(("name", package.name.as_ref()));
let stats = package.get_stats();
pack.push_attribute(("line-rate", stats.line_rate().to_string().as_ref()));
Expand All @@ -422,20 +422,20 @@ pub fn output_cobertura(
writer.write_event(Event::Start(pack)).unwrap();

// export_classes
let classes_tag = b"classes";
let class_tag = b"class";
let methods_tag = b"methods";
let method_tag = b"method";
let classes_tag = "classes";
let class_tag = "class";
let methods_tag = "methods";
let method_tag = "method";

writer
.write_event(Event::Start(BytesStart::borrowed(
.write_event(Event::Start(BytesStart::from_content(
classes_tag,
classes_tag.len(),
)))
.unwrap();

for class in &package.classes {
let mut c = BytesStart::borrowed(class_tag, class_tag.len());
let mut c = BytesStart::from_content(class_tag, class_tag.len());
c.push_attribute(("name", class.name.as_ref()));
c.push_attribute(("filename", class.file_name.as_ref()));
let stats = class.get_stats();
Expand All @@ -445,14 +445,14 @@ pub fn output_cobertura(

writer.write_event(Event::Start(c)).unwrap();
writer
.write_event(Event::Start(BytesStart::borrowed(
.write_event(Event::Start(BytesStart::from_content(
methods_tag,
methods_tag.len(),
)))
.unwrap();

for method in &class.methods {
let mut m = BytesStart::borrowed(method_tag, method_tag.len());
let mut m = BytesStart::from_content(method_tag, method_tag.len());
m.push_attribute(("name", method.name.as_ref()));
m.push_attribute(("signature", method.signature.as_ref()));
let stats = method.get_stats();
Expand All @@ -463,31 +463,31 @@ pub fn output_cobertura(

write_lines(&mut writer, &method.lines);
writer
.write_event(Event::End(BytesEnd::borrowed(method_tag)))
.write_event(Event::End(BytesEnd::new(method_tag)))
.unwrap();
}
writer
.write_event(Event::End(BytesEnd::borrowed(methods_tag)))
.write_event(Event::End(BytesEnd::new(methods_tag)))
.unwrap();
write_lines(&mut writer, &class.lines);
}
writer
.write_event(Event::End(BytesEnd::borrowed(class_tag)))
.write_event(Event::End(BytesEnd::new(class_tag)))
.unwrap();
writer
.write_event(Event::End(BytesEnd::borrowed(classes_tag)))
.write_event(Event::End(BytesEnd::new(classes_tag)))
.unwrap();
writer
.write_event(Event::End(BytesEnd::borrowed(pack_tag)))
.write_event(Event::End(BytesEnd::new(pack_tag)))
.unwrap();
}

writer
.write_event(Event::End(BytesEnd::borrowed(packages_tag)))
.write_event(Event::End(BytesEnd::new(packages_tag)))
.unwrap();

writer
.write_event(Event::End(BytesEnd::borrowed(cov_tag)))
.write_event(Event::End(BytesEnd::new(cov_tag)))
.unwrap();

let result = writer.into_inner().into_inner();
Expand All @@ -496,17 +496,17 @@ pub fn output_cobertura(
}

fn write_lines(writer: &mut Writer<Cursor<Vec<u8>>>, lines: &[Line]) {
let lines_tag = b"lines";
let line_tag = b"line";
let lines_tag = "lines";
let line_tag = "line";

writer
.write_event(Event::Start(BytesStart::borrowed(
.write_event(Event::Start(BytesStart::from_content(
lines_tag,
lines_tag.len(),
)))
.unwrap();
for line in lines {
let mut l = BytesStart::borrowed(line_tag, line_tag.len());
let mut l = BytesStart::from_content(line_tag, line_tag.len());
match line {
Line::Plain {
ref number,
Expand All @@ -526,33 +526,33 @@ fn write_lines(writer: &mut Writer<Cursor<Vec<u8>>>, lines: &[Line]) {
l.push_attribute(("branch", "true"));
writer.write_event(Event::Start(l)).unwrap();

let conditions_tag = b"conditions";
let condition_tag = b"condition";
let conditions_tag = "conditions";
let condition_tag = "condition";

writer
.write_event(Event::Start(BytesStart::borrowed(
.write_event(Event::Start(BytesStart::from_content(
conditions_tag,
conditions_tag.len(),
)))
.unwrap();
for condition in conditions {
let mut c = BytesStart::borrowed(condition_tag, condition_tag.len());
let mut c = BytesStart::from_content(condition_tag, condition_tag.len());
c.push_attribute(("number", condition.number.to_string().as_ref()));
c.push_attribute(("type", condition.cond_type.to_string().as_ref()));
c.push_attribute(("coverage", condition.coverage.to_string().as_ref()));
writer.write_event(Event::Empty(c)).unwrap();
}
writer
.write_event(Event::End(BytesEnd::borrowed(conditions_tag)))
.write_event(Event::End(BytesEnd::new(conditions_tag)))
.unwrap();
}
}
writer
.write_event(Event::End(BytesEnd::borrowed(line_tag)))
.write_event(Event::End(BytesEnd::new(line_tag)))
.unwrap();
}
writer
.write_event(Event::End(BytesEnd::borrowed(lines_tag)))
.write_event(Event::End(BytesEnd::new(lines_tag)))
.unwrap();
}

Expand Down
43 changes: 22 additions & 21 deletions src/parser.rs
Expand Up @@ -11,6 +11,7 @@ use std::str;

use log::error;

use quick_xml::encoding::Decoder;
use quick_xml::events::attributes::AttrError;
use quick_xml::events::{BytesStart, Event};
use quick_xml::Reader;
Expand Down Expand Up @@ -558,8 +559,8 @@ fn get_xml_attribute<R: BufRead>(
) -> Result<String, ParserError> {
for a in event.attributes() {
let a = a?;
if a.key == name.as_bytes() {
return Ok(a.unescape_and_decode_value(reader)?);
if a.key.into_inner() == name.as_bytes() {
return Ok(a.decode_and_unescape_value(reader)?.into_owned());
}
}
Err(ParserError::InvalidRecord(format!(
Expand All @@ -576,16 +577,16 @@ fn parse_jacoco_report_sourcefile<T: BufRead>(
let mut branches: BTreeMap<u32, Vec<bool>> = BTreeMap::new();

loop {
match parser.read_event(buf) {
Ok(Event::Start(ref e)) if e.local_name() == b"line" => {
match parser.read_event_into(buf) {
Ok(Event::Start(ref e)) if e.local_name().into_inner() == b"line" => {
let (mut ci, mut cb, mut mb, mut nr) = (None, None, None, None);
for a in e.attributes() {
let a = a?;
match a.key {
b"ci" => ci = Some(parser.decode(&a.value)?.parse::<u64>()?),
b"cb" => cb = Some(parser.decode(&a.value)?.parse::<u64>()?),
b"mb" => mb = Some(parser.decode(&a.value)?.parse::<u64>()?),
b"nr" => nr = Some(parser.decode(&a.value)?.parse::<u32>()?),
match a.key.into_inner() {
b"ci" => ci = Some(Decoder {}.decode(&a.value)?.parse::<u64>()?),
b"cb" => cb = Some(Decoder {}.decode(&a.value)?.parse::<u64>()?),
b"mb" => mb = Some(Decoder {}.decode(&a.value)?.parse::<u64>()?),
b"nr" => nr = Some(Decoder {}.decode(&a.value)?.parse::<u32>()?),
_ => (),
}
}
Expand Down Expand Up @@ -614,7 +615,7 @@ fn parse_jacoco_report_sourcefile<T: BufRead>(
lines.insert(nr, hit);
}
}
Ok(Event::End(ref e)) if e.local_name() == b"sourcefile" => {
Ok(Event::End(ref e)) if e.local_name().into_inner() == b"sourcefile" => {
break;
}
Err(e) => return Err(ParserError::Parse(e.to_string())),
Expand All @@ -634,13 +635,13 @@ fn parse_jacoco_report_method<T: BufRead>(
let mut executed = false;

loop {
match parser.read_event(buf) {
Ok(Event::Start(ref e)) if e.local_name() == b"counter" => {
match parser.read_event_into(buf) {
Ok(Event::Start(ref e)) if e.local_name().into_inner() == b"counter" => {
if get_xml_attribute(parser, e, "type")? == "METHOD" {
executed = get_xml_attribute(parser, e, "covered")?.parse::<u32>()? > 0;
}
}
Ok(Event::End(ref e)) if e.local_name() == b"method" => break,
Ok(Event::End(ref e)) if e.local_name().into_inner() == b"method" => break,
Err(e) => return Err(ParserError::Parse(e.to_string())),
_ => {}
}
Expand All @@ -658,16 +659,16 @@ fn parse_jacoco_report_class<T: BufRead>(
let mut functions: FunctionMap = FxHashMap::default();

loop {
match parser.read_event(buf) {
Ok(Event::Start(ref e)) if e.local_name() == b"method" => {
match parser.read_event_into(buf) {
Ok(Event::Start(ref e)) if e.local_name().into_inner() == b"method" => {
let name = get_xml_attribute(parser, e, "name")?;
let full_name = format!("{}#{}", class_name, name);

let start_line = get_xml_attribute(parser, e, "line")?.parse::<u32>()?;
let function = parse_jacoco_report_method(parser, buf, start_line)?;
functions.insert(full_name, function);
}
Ok(Event::End(ref e)) if e.local_name() == b"class" => break,
Ok(Event::End(ref e)) if e.local_name().into_inner() == b"class" => break,
Err(e) => return Err(ParserError::Parse(e.to_string())),
_ => {}
}
Expand All @@ -685,9 +686,9 @@ fn parse_jacoco_report_package<T: BufRead>(
let mut results_map: FxHashMap<String, CovResult> = FxHashMap::default();

loop {
match parser.read_event(buf) {
match parser.read_event_into(buf) {
Ok(Event::Start(ref e)) => {
match e.local_name() {
match e.local_name().into_inner() {
b"class" => {
// Fully qualified class name: "org/example/Person$Age"
let fq_class = get_xml_attribute(parser, e, "name")?;
Expand Down Expand Up @@ -742,7 +743,7 @@ fn parse_jacoco_report_package<T: BufRead>(
&_ => {}
}
}
Ok(Event::End(ref e)) if e.local_name() == b"package" => break,
Ok(Event::End(ref e)) if e.local_name().into_inner() == b"package" => break,
Err(e) => return Err(ParserError::Parse(e.to_string())),
_ => {}
}
Expand Down Expand Up @@ -783,8 +784,8 @@ pub fn parse_jacoco_xml_report<T: Read>(
let mut buf = Vec::new();

loop {
match parser.read_event(&mut buf) {
Ok(Event::Start(ref e)) if e.local_name() == b"package" => {
match parser.read_event_into(&mut buf) {
Ok(Event::Start(ref e)) if e.local_name().into_inner() == b"package" => {
let package = get_xml_attribute(&parser, e, "name")?;
let mut package_results =
parse_jacoco_report_package(&mut parser, &mut buf, &package)?;
Expand Down