mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -49,7 +49,6 @@ import java.io.InputStream;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
@@ -102,15 +101,8 @@ public class BrowserUtil {
|
||||
browse(VfsUtil.toUri(file));
|
||||
}
|
||||
|
||||
public static boolean browse(@NotNull File file) {
|
||||
try {
|
||||
browse(new URI(StandardFileSystems.FILE_PROTOCOL, "", file.getAbsolutePath(), null));
|
||||
return true;
|
||||
}
|
||||
catch (URISyntaxException e) {
|
||||
LOG.debug(e);
|
||||
return false;
|
||||
}
|
||||
public static void browse(@NotNull File file) {
|
||||
browse(VfsUtil.toUri(file));
|
||||
}
|
||||
|
||||
public static void browse(@NotNull URL url) {
|
||||
@@ -158,10 +150,8 @@ public class BrowserUtil {
|
||||
}
|
||||
}
|
||||
|
||||
if (browse(file)) {
|
||||
return;
|
||||
}
|
||||
uri = null;
|
||||
browse(file);
|
||||
return;
|
||||
}
|
||||
|
||||
if (uri == null) {
|
||||
|
||||
@@ -498,7 +498,7 @@ public class VfsUtil extends VfsUtilCore {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return correct URI, must be used only for external communication
|
||||
* @return correct URL, must be used only for external communication
|
||||
*/
|
||||
@NotNull
|
||||
public static URI toUri(@NotNull VirtualFile file) {
|
||||
@@ -517,6 +517,23 @@ public class VfsUtil extends VfsUtilCore {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return correct URL, must be used only for external communication
|
||||
*/
|
||||
@NotNull
|
||||
public static URI toUri(@NotNull File file) {
|
||||
String path = file.toURI().getPath();
|
||||
try {
|
||||
if (SystemInfo.isWindows && path.charAt(0) != '/') {
|
||||
path = '/' + path;
|
||||
}
|
||||
return new URI(StandardFileSystems.FILE_PROTOCOL, "", path, null, null);
|
||||
}
|
||||
catch (URISyntaxException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* uri - may be incorrect (escaping or missed "/" before disk name under windows), may be not fully encoded,
|
||||
* may contains query and fragment
|
||||
|
||||
@@ -297,6 +297,9 @@ public class VfsUtilTest extends PlatformLangTestCase {
|
||||
}
|
||||
|
||||
public void testToUri() {
|
||||
assertEquals("file:///asd", VfsUtil.toUri(new File("/asd")).toASCIIString());
|
||||
assertEquals("file:///asd%20/sd", VfsUtil.toUri(new File("/asd /sd")).toASCIIString());
|
||||
|
||||
URI uri = VfsUtil.toUri("file:///asd");
|
||||
assertNotNull(uri);
|
||||
assertEquals("file", uri.getScheme());
|
||||
|
||||
Reference in New Issue
Block a user