Skip to content

Commit 349bb5b

Browse files
committed
Print sourceFiles to XML
1 parent 7d2f32c commit 349bb5b

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed
Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package datadog.context;
22

3+
import java.io.BufferedWriter;
4+
import java.io.FileWriter;
5+
import java.io.IOException;
36
import java.nio.file.Paths;
47
import java.util.HashMap;
58
import java.util.Map;
@@ -10,22 +13,29 @@ public class GatherSourceFileInfoExtension implements TestInstancePostProcessor
1013
private static Map<String, String> sourceFiles = new HashMap<String, String>();
1114

1215
@Override
13-
public void postProcessTestInstance(Object testInstance, ExtensionContext context) {
16+
public void postProcessTestInstance(Object testInstance, ExtensionContext context)
17+
throws IOException {
1418
getTestData(context);
1519
}
1620

1721
public static Map<String, String> getSourceFiles() {
1822
return sourceFiles;
1923
}
2024

21-
private static void getTestData(ExtensionContext context) {
25+
private static void getTestData(ExtensionContext context) throws IOException {
2226
// get test classname and source file
2327
String testClassName = context.getTestClass().get().getName();
2428
String testClassPath = testClassName.replace(".", "/") + ".java";
25-
String absolutePath = Paths.get("").toAbsolutePath() + "/src/test/java/" + testClassPath;
29+
String root = Paths.get("").toAbsolutePath().toString();
30+
String absolutePath = root + "/src/test/java/" + testClassPath;
2631
String subPath =
2732
absolutePath.substring(absolutePath.indexOf("dd-trace-java") + "dd-trace-java".length());
2833
// add info to sourceFiles map
2934
sourceFiles.put(testClassName, subPath);
35+
// print to sourceFiles.xml
36+
BufferedWriter writer =
37+
new BufferedWriter(new FileWriter(root + "/build/test-results/test/sourceFiles.xml"));
38+
writer.write(sourceFiles.toString());
39+
writer.close();
3040
}
3141
}

0 commit comments

Comments
 (0)