|
25 | 25 | package com.oracle.truffle.tools.profiler.impl;
|
26 | 26 |
|
27 | 27 | import java.io.File;
|
| 28 | +import java.net.URL; |
28 | 29 | import java.nio.file.Path;
|
29 |
| -import java.nio.file.Paths; |
30 | 30 | import java.util.ArrayList;
|
31 | 31 | import java.util.List;
|
32 | 32 | import java.util.Objects;
|
@@ -106,17 +106,27 @@ static String getShortDescription(SourceSection sourceSection) {
|
106 | 106 | return UNKNOWN;
|
107 | 107 | }
|
108 | 108 | StringBuilder b = new StringBuilder();
|
109 |
| - if (sourceSection.getSource().getPath() == null) { |
110 |
| - b.append(sourceSection.getSource().getName()); |
111 |
| - } else { |
112 |
| - Path pathAbsolute = Paths.get(sourceSection.getSource().getPath()); |
113 |
| - Path pathBase = new File("").getAbsoluteFile().toPath(); |
| 109 | + Source source = sourceSection.getSource(); |
| 110 | + URL url = source.getURL(); |
| 111 | + if (url != null && !"file".equals(url.getProtocol())) { |
| 112 | + b.append(url.toExternalForm()); |
| 113 | + } else if (source.getPath() != null) { |
114 | 114 | try {
|
| 115 | + /* |
| 116 | + * On Windows, getPath for a local file URL returns a path in the format |
| 117 | + * `/C:/Documents/`, which is not a valid file system path on Windows. Attempting to |
| 118 | + * parse this path using Path#of results in a failure. However, java.io.File |
| 119 | + * correctly handles this format by removing the invalid leading `/` character. |
| 120 | + */ |
| 121 | + Path pathAbsolute = new File(source.getPath()).toPath(); |
| 122 | + Path pathBase = new File("").getAbsoluteFile().toPath(); |
115 | 123 | Path pathRelative = pathBase.relativize(pathAbsolute);
|
116 | 124 | b.append(pathRelative.toFile());
|
117 | 125 | } catch (IllegalArgumentException e) {
|
118 |
| - b.append(sourceSection.getSource().getName()); |
| 126 | + b.append(source.getName()); |
119 | 127 | }
|
| 128 | + } else { |
| 129 | + b.append(source.getName()); |
120 | 130 | }
|
121 | 131 |
|
122 | 132 | b.append("~").append(formatIndices(sourceSection, true));
|
|
0 commit comments