diff --git a/.circleci/collect_results.sh b/.circleci/collect_results.sh index dc6a0eb7682..f94944f40c4 100755 --- a/.circleci/collect_results.sh +++ b/.circleci/collect_results.sh @@ -19,6 +19,16 @@ if [[ ${#TEST_RESULT_DIRS[@]} -eq 0 ]]; then exit 0 fi +# Read sourceFile.xml into map +declare -A SOURCE_FILE_MAP +SOURCE_FILE_XML="test-results/sourceFiles.xml" +while IFS= read -r line +do + KEY=$(echo "$line" | cut -d ":" -f 1) + VALUE=$(echo "$line" | cut -d ":" -f 2) + SOURCE_FILE_MAP["$KEY"]="$VALUE" +done < "$SOURCE_FILE_XML" + echo "Saving test results:" while IFS= read -r -d '' RESULT_XML_FILE do @@ -30,6 +40,13 @@ do sed -i '/ sourceFiles = new HashMap(); + + @Override + public void postProcessTestInstance(Object testInstance, ExtensionContext context) + throws IOException { + getTestData(context); + } + + public static Map getSourceFiles() { + return sourceFiles; + } + + private static void getTestData(ExtensionContext context) throws IOException { + // get test classname and source file + String testClassName = context.getTestClass().get().getName(); + String testClassPath = testClassName.replace(".", "/") + ".java"; + String root = Paths.get("").toAbsolutePath().toString(); + String absolutePath = root + "/src/test/java/" + testClassPath; + String subPath = + absolutePath.substring(absolutePath.indexOf("dd-trace-java") + "dd-trace-java".length()); + + // print to sourceFiles.xml only if source file has not already been added + if (!sourceFiles.containsKey(testClassName)) { + File sourceFile = new File(root + "/build/test-results/sourceFiles.xml"); + if (!sourceFile.exists()) { + sourceFile.createNewFile(); + } + BufferedWriter writer = new BufferedWriter(new FileWriter(sourceFile, true)); + writer.write(testClassName + ":" + subPath); + writer.newLine(); + writer.close(); + } + sourceFiles.put(testClassName, subPath); + } +} diff --git a/gradle/java.gradle b/gradle/java.gradle index ff93b9dcf4a..59ac3b3697b 100644 --- a/gradle/java.gradle +++ b/gradle/java.gradle @@ -2,3 +2,20 @@ apply plugin: 'datadog.dependency-locking' apply from: "$rootDir/gradle/java_deps.gradle" apply from: "$rootDir/gradle/java_no_deps.gradle" + +tasks.named("test") { + finalizedBy("myCustomTask") +} + +tasks.named("forkedTest") { + finalizedBy("myCustomTask") +} + +tasks.register('myCustomTask') { + group = "Custom Tasks" // Optional, for better organization + description = "This is a custom task that prints a message" + + doLast { + println("Running my custom task!") + } +} diff --git a/gradle/java_no_deps.gradle b/gradle/java_no_deps.gradle index fe6f3c85f3d..f741f9ad11a 100644 --- a/gradle/java_no_deps.gradle +++ b/gradle/java_no_deps.gradle @@ -19,6 +19,7 @@ ext.testcontainersLimit = gradle.sharedServices.registerIfAbsent("testcontainers if (tasks.matching({it.name == 'forkedTest'}).empty) { tasks.register('forkedTest', Test).configure { useJUnitPlatform() + jvmArgs("-Djunit.jupiter.extensions.autodetection.enabled=true") } }