Java Code Examples for com.intellij.openapi.vfs.LocalFileSystem#refreshAndFindFileByPath()

The following examples show how to use com.intellij.openapi.vfs.LocalFileSystem#refreshAndFindFileByPath() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OpenExternalConfigAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private static VirtualFile getExternalConfig(@Nonnull DataContext context) {
  ProjectSystemId externalSystemId = context.getData(ExternalSystemDataKeys.EXTERNAL_SYSTEM_ID);
  if (externalSystemId == null) {
    return null;
  }

  ExternalProjectPojo projectPojo = context.getData(ExternalSystemDataKeys.SELECTED_PROJECT);
  if (projectPojo == null) {
    return null;
  }

  String path = projectPojo.getPath();
  LocalFileSystem fileSystem = LocalFileSystem.getInstance();
  VirtualFile externalSystemConfigPath = fileSystem.refreshAndFindFileByPath(path);
  if (externalSystemConfigPath == null) {
    return null;
  }

  VirtualFile toOpen = externalSystemConfigPath;
  for (ExternalSystemConfigLocator locator : ExternalSystemConfigLocator.EP_NAME.getExtensionList()) {
    if (externalSystemId.equals(locator.getTargetExternalSystemId())) {
      toOpen = locator.adjust(toOpen);
      if (toOpen == null) {
        return null;
      }
    }
  }
  return toOpen.isDirectory() ? null : toOpen;
}
 
Example 2
Source File: ProjectFromSourcesBuilderImplModified.java    From tmc-intellij with MIT License 4 votes vote down vote up
private static void setupRootModel(
        ProjectDescriptor projectDescriptor,
        final ModuleDescriptor descriptor,
        final ModifiableRootModel rootModel,
        final Map<LibraryDescriptor, Library> projectLibs) {
    final CompilerModuleExtension compilerModuleExtension =
            rootModel.getModuleExtension(CompilerModuleExtension.class);
    compilerModuleExtension.setExcludeOutput(true);
    rootModel.inheritSdk();

    //Module root model seems to store .iml files root dependencies. (src, test, lib)
    logger.info("Starting setupRootModel in ProjectFromSourcesBuilderImplModified");
    final Set<File> contentRoots = descriptor.getContentRoots();
    for (File contentRoot : contentRoots) {
        final LocalFileSystem lfs = LocalFileSystem.getInstance();
        VirtualFile moduleContentRoot =
                lfs.refreshAndFindFileByPath(
                        FileUtil.toSystemIndependentName(contentRoot.getPath()));
        if (moduleContentRoot != null) {
            final ContentEntry contentEntry = rootModel.addContentEntry(moduleContentRoot);
            final Collection<DetectedSourceRoot> sourceRoots =
                    descriptor.getSourceRoots(contentRoot);
            for (DetectedSourceRoot srcRoot : sourceRoots) {
                final String srcpath =
                        FileUtil.toSystemIndependentName(srcRoot.getDirectory().getPath());
                final VirtualFile sourceRoot = lfs.refreshAndFindFileByPath(srcpath);
                if (sourceRoot != null) {
                    contentEntry.addSourceFolder(
                            sourceRoot,
                            shouldBeTestRoot(srcRoot.getDirectory()),
                            getPackagePrefix(srcRoot));
                }
            }
        }
    }
    logger.info("Inherits compiler output path from project");
    compilerModuleExtension.inheritCompilerOutputPath(true);

    logger.info("Starting to create module level libraries");
    final LibraryTable moduleLibraryTable = rootModel.getModuleLibraryTable();
    for (LibraryDescriptor libDescriptor :
            ModuleInsight.getLibraryDependencies(
                    descriptor, projectDescriptor.getLibraries())) {
        final Library projectLib = projectLibs.get(libDescriptor);
        if (projectLib != null) {
            rootModel.addLibraryEntry(projectLib);
        } else {
            // add as module library
            final Collection<File> jars = libDescriptor.getJars();
            for (File file : jars) {
                Library library = moduleLibraryTable.createLibrary();
                Library.ModifiableModel modifiableModel = library.getModifiableModel();
                modifiableModel.addRoot(
                        VfsUtil.getUrlForLibraryRoot(file), OrderRootType.CLASSES);
                modifiableModel.commit();
            }
        }
    }
    logger.info("Ending setupRootModel in ProjectFromSourcesBuilderImplModified");
}
 
Example 3
Source File: MacFileSaverDialog.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static VirtualFile fileToVirtualFile(File file) {
  final LocalFileSystem localFileSystem = LocalFileSystem.getInstance();
  final String vfsPath = FileUtil.toSystemIndependentName(file.getAbsolutePath());
  return localFileSystem.refreshAndFindFileByPath(vfsPath);
}
 
Example 4
Source File: MacPathChooserDialog.java    From consulo with Apache License 2.0 4 votes vote down vote up
private VirtualFile fileToVirtualFile(File file) {
  final LocalFileSystem localFileSystem = LocalFileSystem.getInstance();
  final String vfsPath = FileUtil.toSystemIndependentName(file.getAbsolutePath());
  return localFileSystem.refreshAndFindFileByPath(vfsPath);
}
 
Example 5
Source File: WinPathChooserDialog.java    From consulo with Apache License 2.0 4 votes vote down vote up
private VirtualFile fileToVirtualFile(File file) {
  final LocalFileSystem localFileSystem = LocalFileSystem.getInstance();
  final String vfsPath = FileUtil.toSystemIndependentName(file.getAbsolutePath());
  return localFileSystem.refreshAndFindFileByPath(vfsPath);
}