use of com.intellij.openapi.vfs.VirtualFileSystem in project kotlin by JetBrains.
the class LibrarySourcesConfig method checkLibFilesAndReportErrors.
private boolean checkLibFilesAndReportErrors(@NotNull JsConfig.Reporter report, @Nullable Function1<VirtualFile, Unit> action) {
List<String> libraries = getLibraries();
if (libraries.isEmpty()) {
return false;
}
VirtualFileSystem fileSystem = VirtualFileManager.getInstance().getFileSystem(StandardFileSystems.FILE_PROTOCOL);
VirtualFileSystem jarFileSystem = VirtualFileManager.getInstance().getFileSystem(StandardFileSystems.JAR_PROTOCOL);
Set<String> modules = new HashSet<String>();
for (String path : libraries) {
VirtualFile file;
File filePath = new File(path);
if (!filePath.exists()) {
report.error("Path '" + path + "' does not exist");
return true;
}
if (path.endsWith(".jar") || path.endsWith(".zip")) {
file = jarFileSystem.findFileByPath(path + URLUtil.JAR_SEPARATOR);
} else {
file = fileSystem.findFileByPath(path);
}
if (file == null) {
report.error("File '" + path + "' does not exist or could not be read");
return true;
}
List<KotlinJavascriptMetadata> metadataList = KotlinJavascriptMetadataUtils.loadMetadata(filePath);
if (metadataList.isEmpty()) {
report.warning("'" + path + "' is not a valid Kotlin Javascript library");
continue;
}
for (KotlinJavascriptMetadata metadata : metadataList) {
if (!metadata.getVersion().isCompatible()) {
report.error("File '" + path + "' was compiled with an incompatible version of Kotlin. " + "The binary version of its metadata is " + metadata.getVersion() + ", expected version is " + JsMetadataVersion.INSTANCE);
return true;
}
if (!modules.add(metadata.getModuleName())) {
report.warning("Module \"" + metadata.getModuleName() + "\" is defined in more, than one file");
}
}
if (action != null) {
action.invoke(file);
}
}
return false;
}
use of com.intellij.openapi.vfs.VirtualFileSystem in project kotlin by JetBrains.
the class BasicTest method createJetFileList.
private static List<KtFile> createJetFileList(@NotNull Project project, @NotNull List<String> list, @Nullable String root) {
List<KtFile> libFiles = Lists.newArrayList();
PsiManager psiManager = PsiManager.getInstance(project);
VirtualFileSystem fileSystem = VirtualFileManager.getInstance().getFileSystem(StandardFileSystems.FILE_PROTOCOL);
VirtualFile rootFile = root == null ? null : fileSystem.findFileByPath(root);
for (String libFileName : list) {
VirtualFile virtualFile = rootFile == null ? fileSystem.findFileByPath(libFileName) : rootFile.findFileByRelativePath(libFileName);
//TODO logging?
assert virtualFile != null : "virtual file is missing, most likely the file doesn't exist: " + libFileName;
PsiFile psiFile = psiManager.findFile(virtualFile);
libFiles.add((KtFile) psiFile);
}
return libFiles;
}
use of com.intellij.openapi.vfs.VirtualFileSystem in project intellij-elixir by KronicDeth.
the class ParsingTestCase method setProjectSdkFromSdkHome.
private void setProjectSdkFromSdkHome(@NotNull String sdkHome) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
MessageBus messageBus = messageBus();
registerProjectFileIndex(messageBus);
ProjectRootManager projectRootManager = registerProjectRootManager();
assertTrue(pathIsValidSdkHome(sdkHome));
registerExtensionPoint(OrderRootType.EP_NAME, OrderRootType.class);
registerExtension(OrderRootType.EP_NAME, new JavadocOrderRootType());
getApplication().addComponent(VirtualFileManager.class, new VirtualFileManagerImpl(new VirtualFileSystem[] { new MockLocalFileSystem() }, messageBus));
ProjectJdkTable projectJdkTable = new ProjectJdkTableImpl();
registerApplicationService(ProjectJdkTable.class, projectJdkTable);
registerExtensionPoint(com.intellij.openapi.projectRoots.SdkType.EP_NAME, com.intellij.openapi.projectRoots.SdkType.class);
registerExtension(com.intellij.openapi.projectRoots.SdkType.EP_NAME, new ElixirSdkType());
Sdk sdk = ElixirSdkType.createMockSdk(sdkHome, elixirSdkRelease());
projectJdkTable.addJdk(sdk);
ExtensionsArea area = Extensions.getArea(myProject);
registerExtensionPoint(area, ProjectExtension.EP_NAME, ProjectExtension.class);
registerExtensionPoint(FilePropertyPusher.EP_NAME, FilePropertyPusher.class);
myProject.addComponent(PushedFilePropertiesUpdater.class, new PushedFilePropertiesUpdaterImpl(myProject));
projectRootManager.setProjectSdk(sdk);
}
use of com.intellij.openapi.vfs.VirtualFileSystem in project intellij-plugins by JetBrains.
the class FlexDocumentationProvider method findUrlForVirtualFile.
@NotNull
private static List<String> findUrlForVirtualFile(final Project project, final VirtualFile virtualFile, final String relPath) {
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
Module module = fileIndex.getModuleForFile(virtualFile);
if (module == null) {
final VirtualFileSystem fs = virtualFile.getFileSystem();
if (fs instanceof JarFileSystem) {
final VirtualFile jar = ((JarFileSystem) fs).getVirtualFileForJar(virtualFile);
if (jar != null) {
module = fileIndex.getModuleForFile(jar);
}
}
}
if (module != null) {
String[] javadocPaths = JavaModuleExternalPaths.getInstance(module).getJavadocUrls();
List<String> httpRoots = PlatformDocumentationUtil.getHttpRoots(correctHttpRoots(javadocPaths), relPath);
if (httpRoots != null)
return httpRoots;
}
final List<OrderEntry> orderEntries = fileIndex.getOrderEntriesForFile(virtualFile);
for (OrderEntry orderEntry : orderEntries) {
final String[] files = JavadocOrderRootType.getUrls(orderEntry);
final List<String> httpRoot = PlatformDocumentationUtil.getHttpRoots(correctHttpRoots(files), relPath);
if (httpRoot != null)
return httpRoot;
}
return Collections.emptyList();
}
use of com.intellij.openapi.vfs.VirtualFileSystem in project intellij-community by JetBrains.
the class JavaDocumentationProvider method findUrlForVirtualFile.
@Nullable
public static List<String> findUrlForVirtualFile(@NotNull Project project, @NotNull VirtualFile virtualFile, @NotNull String relPath) {
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
Module module = fileIndex.getModuleForFile(virtualFile);
if (module == null) {
final VirtualFileSystem fs = virtualFile.getFileSystem();
if (fs instanceof JarFileSystem) {
final VirtualFile jar = ((JarFileSystem) fs).getVirtualFileForJar(virtualFile);
if (jar != null) {
module = fileIndex.getModuleForFile(jar);
}
}
}
if (module != null) {
String[] javadocPaths = JavaModuleExternalPaths.getInstance(module).getJavadocUrls();
final List<String> httpRoots = PlatformDocumentationUtil.getHttpRoots(javadocPaths, relPath);
// if found nothing and the file is from library classes, fall back to order entries
if (httpRoots != null || !fileIndex.isInLibraryClasses(virtualFile)) {
return httpRoots;
}
}
for (OrderEntry orderEntry : fileIndex.getOrderEntriesForFile(virtualFile)) {
for (VirtualFile root : orderEntry.getFiles(JavadocOrderRootType.getInstance())) {
if (root.getFileSystem() == JarFileSystem.getInstance()) {
VirtualFile file = root.findFileByRelativePath(relPath);
List<Url> urls = file == null ? null : BuiltInWebBrowserUrlProviderKt.getBuiltInServerUrls(file, project, null);
if (!ContainerUtil.isEmpty(urls)) {
List<String> result = new SmartList<>();
for (Url url : urls) {
result.add(url.toExternalForm());
}
return result;
}
}
}
List<String> httpRoot = PlatformDocumentationUtil.getHttpRoots(JavadocOrderRootType.getUrls(orderEntry), relPath);
if (httpRoot != null) {
return httpRoot;
}
}
return null;
}
Aggregations