Skip to content

Commit d36a8a5

Browse files
authored
Add support for windows-style path (backslashes) (#11073)
# What Does This Do Source filename used in probe definition can have path using backslashes (Windows-style) we normalize those paths before building the definition matcher # Motivation # Additional Notes # Contributor Checklist - Format the title according to [the contribution guidelines](https://github.com/DataDog/dd-trace-java/blob/master/CONTRIBUTING.md#title-format) - Assign the `type:` and (`comp:` or `inst:`) labels in addition to [any other useful labels](https://github.com/DataDog/dd-trace-java/blob/master/CONTRIBUTING.md#labels) - Avoid using `close`, `fix`, or [any linking keywords](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword) when referencing an issue Use `solves` instead, and assign the PR [milestone](https://github.com/DataDog/dd-trace-java/milestones) to the issue - Update the [CODEOWNERS](https://github.com/DataDog/dd-trace-java/blob/master/.github/CODEOWNERS) file on source file addition, migration, or deletion - Update [public documentation](https://docs.datadoghq.com/tracing/trace_collection/library_config/java/) with any new configuration flags or behaviors Jira ticket: [DEBUG-5109] ***Note:*** **Once your PR is ready to merge, add it to the merge queue by commenting `/merge`.** `/merge -c` cancels the queue request. `/merge -f --reason "reason"` skips all merge queue checks; please use this judiciously, as some checks do not run at the PR-level. For more information, see [this doc](https://datadoghq.atlassian.net/wiki/spaces/DEVX/pages/3121612126/MergeQueue). <!-- # Opening vs Drafting a PR: When opening a pull request, please open it as a draft to not auto assign reviewers before you feel the pull request is in a reviewable state. # Linking a JIRA ticket: Please link your JIRA ticket by adding its identifier between brackets (ex [PROJ-IDENT]) in the PR description, not the title. This requirement only applies to Datadog employees. --> [DEBUG-5109]: https://datadoghq.atlassian.net/browse/DEBUG-5109?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
1 parent 20cb71f commit d36a8a5

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/agent/TransformerDefinitionMatcher.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ private void populateDefinitionFileNamesMap(Collection<ProbeDefinition> definiti
5959
if (fileName == null) {
6060
continue;
6161
}
62+
fileName = normalizeWindowsToUnixPath(fileName);
6263
Map<String, List<ProbeDefinition>> targetMap =
6364
fileName.indexOf('/') != -1
6465
? definitionsByQualifiedFileNames
@@ -67,6 +68,10 @@ private void populateDefinitionFileNamesMap(Collection<ProbeDefinition> definiti
6768
}
6869
}
6970

71+
private static String normalizeWindowsToUnixPath(String fileName) {
72+
return fileName.replace('\\', '/');
73+
}
74+
7075
private Trie buildDefinitionFileNamesTrie(
7176
Map<String, List<ProbeDefinition>> definitionsByFileNames) {
7277
Trie resultTrie = new Trie();

dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/agent/TransformerDefinitionMatcherTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,26 @@ public void sourceFileAbsoluteFileName() {
7474
assertEquals(PROBE_ID1, probeDefinitions.get(0).getProbeId());
7575
}
7676

77+
@Test
78+
public void sourceFileWindowsStyleFileName() {
79+
LogProbe probe = createProbe(PROBE_ID1, "src\\main\\java\\java\\lang\\String.java", 23);
80+
TransformerDefinitionMatcher matcher = createMatcher(probe);
81+
List<ProbeDefinition> probeDefinitions = match(matcher, String.class);
82+
assertEquals(1, probeDefinitions.size());
83+
assertEquals(PROBE_ID1, probeDefinitions.get(0).getProbeId());
84+
}
85+
86+
@Test
87+
public void sourceFileWindowsStyleAbsoluteFileName() {
88+
LogProbe probe =
89+
createProbe(
90+
PROBE_ID1, "C:\\Users\\user\\project\\src\\main\\java\\java\\lang\\String.java", 23);
91+
TransformerDefinitionMatcher matcher = createMatcher(probe);
92+
List<ProbeDefinition> probeDefinitions = match(matcher, String.class);
93+
assertEquals(1, probeDefinitions.size());
94+
assertEquals(PROBE_ID1, probeDefinitions.get(0).getProbeId());
95+
}
96+
7797
@Test
7898
public void sourceFileSimpleFileName() {
7999
LogProbe probe = createProbe(PROBE_ID1, "String.java", 23);

0 commit comments

Comments
 (0)