Skip to content

Commit 9cb3b43

Browse files
committed
formatting and removing redundant check
1 parent 9226fc5 commit 9cb3b43

1 file changed

Lines changed: 26 additions & 16 deletions

File tree

.gitlab/TagInitializationErrors.java

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
1-
import org.w3c.dom.Element;
2-
import javax.xml.XMLConstants;
3-
import javax.xml.parsers.DocumentBuilderFactory;
4-
import javax.xml.transform.OutputKeys;
5-
import javax.xml.transform.TransformerFactory;
6-
import javax.xml.transform.dom.DOMSource;
7-
import javax.xml.transform.stream.StreamResult;
81
import java.io.File;
92
import java.nio.file.Files;
103
import java.util.ArrayList;
114
import java.util.LinkedHashMap;
125
import java.util.List;
136
import java.util.Map;
7+
import javax.xml.XMLConstants;
8+
import javax.xml.parsers.DocumentBuilderFactory;
9+
import javax.xml.transform.OutputKeys;
10+
import javax.xml.transform.TransformerFactory;
11+
import javax.xml.transform.dom.DOMSource;
12+
import javax.xml.transform.stream.StreamResult;
13+
import org.w3c.dom.Document;
14+
import org.w3c.dom.Element;
1415

1516
/// Tags synthetic testcases (`initializationError`, `executionError`, `test exception`) with
1617
/// `dd_tags[test.final_status]=skip` so Test Optimization does not treat them as real failures.
1718
/// The script is idempotent — testcases that already carry a `dd_tags[test.final_status]` property
1819
/// are left unchanged.
1920
///
20-
/// **`initializationError`** — Gradle generates these for setup methods. When retried and eventually
21+
/// **`initializationError`** — Gradle generates these for setup methods. When retried and
22+
// eventually
2123
/// successful, multiple testcases appear; only the last one passes. All intermediate attempts are
22-
/// tagged skip. Groups with only one (or zero) `initializationError` entries per classname are left unmodified.
24+
/// tagged skip. Groups with only one (or zero) `initializationError` entries per classname are left
25+
// unmodified.
2326
///
2427
/// **`executionError`** and **`test exception`** — Framework-level synthetic failures that do not
25-
/// represent real test results. Tagged skip unconditionally so Test Optimization treats them as non-failures.
28+
/// represent real test results. Tagged skip unconditionally so Test Optimization treats them as
29+
// non-failures.
2630
///
2731
/// Before (two retries of the same class — first is intermediate, second is the final outcome):
2832
///
@@ -75,18 +79,22 @@ public static void main(String[] args) throws Exception {
7579
}
7680
}
7781
for (var group : byClassname.values()) {
78-
if (group.size() <= 1) continue;
7982
for (int i = 0; i < group.size() - 1; i++) {
80-
if (tagSkip(doc, group.get(i))) modified = true;
83+
if (tagSkip(doc, group.get(i))) {
84+
modified = true;
85+
}
8186
}
8287
}
83-
if (!modified) return;
88+
if (!modified) {
89+
return;
90+
}
8491
var tmpFile = File.createTempFile("TagInitializationErrors", ".xml", xmlFile.getParentFile());
8592
try {
8693
var transformer = TransformerFactory.newInstance().newTransformer();
8794
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
8895
transformer.transform(new DOMSource(doc), new StreamResult(tmpFile));
89-
Files.move(tmpFile.toPath(), xmlFile.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
96+
Files.move(
97+
tmpFile.toPath(), xmlFile.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
9098
} catch (Exception e) {
9199
tmpFile.delete();
92100
throw e;
@@ -97,12 +105,14 @@ static Element firstChildElement(Element parent, String tagName) {
97105
var children = parent.getChildNodes();
98106
for (int i = 0; i < children.getLength(); i++) {
99107
var child = children.item(i);
100-
if (child instanceof Element e && tagName.equals(e.getTagName())) return e;
108+
if (child instanceof Element e && tagName.equals(e.getTagName())) {
109+
return e;
110+
}
101111
}
102112
return null;
103113
}
104114

105-
static boolean tagSkip(org.w3c.dom.Document doc, Element testcase) {
115+
static boolean tagSkip(Document doc, Element testcase) {
106116
var props = firstChildElement(testcase, "properties");
107117
if (props != null) {
108118
var children = props.getChildNodes();

0 commit comments

Comments
 (0)