Remove Compiler::resolveSibling
Now that we no longer support the GWT build, we can use the Java
native method for this.
@@ -87,9 +87,9 @@ import java.io.OutputStream;
import java.io.PrintStream;
import java.io.Serializable;
import java.nio.file.Files;
+import java.nio.file.Paths;
import java.util.AbstractSet;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -2896,7 +2896,11 @@ public class Compiler extends AbstractCompiler implements ErrorHandler, SourceFi
&& resultOriginalPath.equals(resolvedSourceMap.sourceMapPath)) {
relativePath = resolvedSourceMap.relativePath;
} else {
- relativePath = resolveSibling(sourceMapOriginalPath, resultOriginalPath);
+ relativePath =
+ Paths.get(sourceMapOriginalPath)
+ .resolveSibling(resultOriginalPath)
+ .normalize()
+ .toString();
SourceFile source = getSourceFileByName(relativePath);
if (source == null && !isNullOrEmpty(resultOriginalPath)) {
source =
@@ -3669,39 +3673,6 @@ public class Compiler extends AbstractCompiler implements ErrorHandler, SourceFi
this.moduleMap = moduleMap;
}
- /**
- * Simplistic implementation of the java.nio.file.Path resolveSibling method that works with GWT.
- *
- * @param fromPath - must be a file (not directory)
- * @param toPath - must be a file (not directory)
- */
- private static String resolveSibling(String fromPath, String toPath) {
- // If the destination is an absolute path, nothing to do.
- if (toPath.startsWith("/")) {
- return toPath;
- }
-
- List<String> fromPathParts = new ArrayList<>(Arrays.asList(fromPath.split("/")));
- List<String> toPathParts = new ArrayList<>(Arrays.asList(toPath.split("/")));
- if (!fromPathParts.isEmpty()) {
- fromPathParts.remove(fromPathParts.size() - 1);
- }
-
- while (!fromPathParts.isEmpty() && !toPathParts.isEmpty()) {
- if (toPathParts.get(0).equals(".")) {
- toPathParts.remove(0);
- } else if (toPathParts.get(0).equals("..")) {
- toPathParts.remove(0);
- fromPathParts.remove(fromPathParts.size() - 1);
- } else {
- break;
- }
- }
-
- fromPathParts.addAll(toPathParts);
- return String.join("/", fromPathParts);
- }
-
public void resetAndIntitializeSourceMap() {
if (sourceMap == null) {
return;
