Revamp how classpath loading works

This commit is contained in:
Ben Gruver
2016-04-23 09:18:22 -07:00
parent 8a5a6e3fc5
commit e474301e60
7 changed files with 352 additions and 212 deletions

View File

@ -28,9 +28,12 @@
package org.jf.util;
import com.google.common.collect.Lists;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class PathUtil {
private PathUtil() {
@ -55,8 +58,8 @@ public class PathUtil {
}
static String getRelativeFileInternal(File canonicalBaseFile, File canonicalFileToRelativize) {
ArrayList<String> basePath = getPathComponents(canonicalBaseFile);
ArrayList<String> pathToRelativize = getPathComponents(canonicalFileToRelativize);
List<String> basePath = getPathComponents(canonicalBaseFile);
List<String> pathToRelativize = getPathComponents(canonicalFileToRelativize);
//if the roots aren't the same (i.e. different drives on a windows machine), we can't construct a relative
//path from one to the other, so just return the canonical file
@ -105,21 +108,21 @@ public class PathUtil {
return sb.toString();
}
private static ArrayList<String> getPathComponents(File file) {
public static List<String> getPathComponents(File file) {
ArrayList<String> path = new ArrayList<String>();
while (file != null) {
File parentFile = file.getParentFile();
if (parentFile == null) {
path.add(0, file.getPath());
path.add(file.getPath());
} else {
path.add(0, file.getName());
path.add(file.getName());
}
file = parentFile;
}
return path;
return Lists.reverse(path);
}
}