Java Code Examples for com.intellij.openapi.vfs.VfsUtil#virtualToIoFile()

The following examples show how to use com.intellij.openapi.vfs.VfsUtil#virtualToIoFile() . 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: BlazeTypeScriptConfig.java    From intellij with Apache License 2.0 6 votes vote down vote up
private ImmutableList<VirtualFile> resolveFilesList() {
  VirtualFile base = baseUrlFile.getValue();
  if (base == null) {
    return ImmutableList.of();
  }
  File baseFile = VfsUtil.virtualToIoFile(base);
  FileOperationProvider fOps = FileOperationProvider.getInstance();
  return filesStrings.stream()
      .map(f -> new File(baseFile, f))
      .map(
          f -> {
            try {
              return fOps.isSymbolicLink(f) ? fOps.readSymbolicLink(f) : f;
            } catch (IOException e) {
              logger.warn(e);
              return f;
            }
          })
      .map(f -> VfsUtils.resolveVirtualFile(f, /* refreshIfNeeded= */ false))
      .filter(Objects::nonNull)
      .collect(ImmutableList.toImmutableList());
}
 
Example 2
Source File: ContainerFile.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Nullable
public File getFile(Project project) {
    if (!FileUtil.isAbsolute(this.path)) {
        VirtualFile virtualFile = VfsUtil.findRelativeFile(this.path, ProjectUtil.getProjectDir(project));
        if(virtualFile == null) {
            return null;
        }

        return VfsUtil.virtualToIoFile(virtualFile);
    }

    File file = new File(this.path);
    if(!file.exists()) {
       return null;
    }

    return file;
}
 
Example 3
Source File: ImportProjectOpenProcessor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public Image getIcon(@Nonnull VirtualFile file) {
  File ioFile = VfsUtil.virtualToIoFile(file);
  for (ModuleImportProvider provider : myProviders) {
    if (provider.canImport(ioFile)) {
      return provider.getIcon();
    }
  }
  return null;
}
 
Example 4
Source File: CommitPanel.java    From commit-template-idea-plugin with Apache License 2.0 5 votes vote down vote up
CommitPanel(Project project) {
    for (ChangeType type : ChangeType.values()) {
        changeType.addItem(type);
    }
    File workingDirectory = VfsUtil.virtualToIoFile(project.getBaseDir());
    Command.Result result = new Command(workingDirectory, "git log --all --format=%s | grep -Eo '^[a-z]+(\\(.*\\)):.*$' | sed 's/^.*(\\(.*\\)):.*$/\\1/' | sort -n | uniq").execute();
    if (result.isSuccess()) {
        result.getOutput().forEach(changeScope::addItem);
    }
}
 
Example 5
Source File: ResultCallbackBuckHandler.java    From buck with Apache License 2.0 5 votes vote down vote up
/** @deprecated Use {@link ResultCallbackBuckHandler(Project, BuckCommand, Consumer<String>)}. */
@Deprecated
public ResultCallbackBuckHandler(
    final Project project,
    final VirtualFile root,
    final BuckCommand command,
    final Consumer<String> futureCallback) {
  super(project, VfsUtil.virtualToIoFile(root), command, true);
  this.futureCallback = futureCallback;
  this.stdout = new StringBuilder();
}
 
Example 6
Source File: BuckQueryCommandHandler.java    From buck with Apache License 2.0 5 votes vote down vote up
/** @deprecated Use {@link BuckQueryCommandHandler(Project, BuckCommand, Function)}. */
@Deprecated
public BuckQueryCommandHandler(
    final Project project,
    final VirtualFile root,
    final BuckCommand command,
    Function<List<String>, Void> actionsToExecute) {
  super(project, VfsUtil.virtualToIoFile(root), command, true);
  this.actionsToExecute = actionsToExecute;
}
 
Example 7
Source File: BuckBuildCommandHandler.java    From buck with Apache License 2.0 5 votes vote down vote up
/** @deprecated Use {@link BuckBuildCommandHandler(Project, BuckCommand, boolean)} */
@Deprecated
public BuckBuildCommandHandler(
    final Project project,
    final VirtualFile root,
    final BuckCommand command,
    final boolean doStartNotify) {
  super(project, VfsUtil.virtualToIoFile(root), command, doStartNotify);
}
 
Example 8
Source File: LocalProfilerFactory.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
/**
 * find csv on settings or container configuration
 */
@Nullable
private File findCsvProfilerFile(@NotNull Project project) {
    String profilerCsvPath = Settings.getInstance(project).profilerCsvPath;
    if (StringUtils.isBlank(profilerCsvPath)) {
        return getCsvIndex(project);
    }

    VirtualFile relativeFile = VfsUtil.findRelativeFile(ProjectUtil.getProjectDir(project), profilerCsvPath.replace("\\", "/").split("/"));
    if (relativeFile != null) {
        return VfsUtil.virtualToIoFile(relativeFile);
    }

    return null;
}
 
Example 9
Source File: ShopwareInstallerProjectGenerator.java    From idea-php-shopware-plugin with MIT License 5 votes vote down vote up
@Override
public void generateProject(@NotNull final Project project, final @NotNull VirtualFile baseDir, final @NotNull ShopwareInstallerSettings settings, @NotNull Module module) {

    String downloadPath = settings.getVersion().getUrl();
    String toDir = baseDir.getPath();

    VirtualFile zipFile = PhpConfigurationUtil.downloadFile(project, null, toDir, downloadPath, "shopware.zip");

    if (zipFile == null) {
        showErrorNotification(project, "Cannot download Shopware.zip file");
        return;
    }

    // Convert files
    File zip = VfsUtil.virtualToIoFile(zipFile);
    File base = VfsUtil.virtualToIoFile(baseDir);

    Task.Backgroundable task = new Task.Backgroundable(project, "Extracting", true) {
        @Override
        public void run(@NotNull ProgressIndicator progressIndicator) {

            try {
                // unzip file
                ZipUtil.extract(zip, base, null);

                // Delete TMP File
                FileUtil.delete(zip);

                // Activate Plugin
                IdeHelper.enablePluginAndConfigure(project);
            } catch (IOException e) {
                showErrorNotification(project, "There is a error occurred");
            }
        }
    };

    ProgressManager.getInstance().run(task);
}
 
Example 10
Source File: NewBashFileAction.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
@NotNull
protected PsiElement[] create(String newName, PsiDirectory directory) throws Exception {
    PsiFile file = BashTemplatesFactory.createFromTemplate(directory, computeFilename(newName), BashTemplatesFactory.DEFAULT_TEMPLATE_FILENAME);

    File ioFile = VfsUtil.virtualToIoFile(file.getVirtualFile());
    if (ioFile.exists()) {
        ioFile.setExecutable(true, true);
    }

    PsiElement child = file.getLastChild();
    return child != null ? new PsiElement[]{file, child} : new PsiElement[]{file};
}
 
Example 11
Source File: MindMapDocumentEditor.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
public boolean findPrev(@Nonnull final Pattern pattern, @Nonnull final FindTextScopeProvider provider) {
  Topic startTopic = null;
  if (this.mindMapPanel.hasSelectedTopics()) {
    final Topic[] selected = this.mindMapPanel.getSelectedTopics();
    startTopic = selected[0];
  }

  final VirtualFile baseFolder = findRootFolderForEditedFile();
  final File projectBaseFolder = baseFolder == null ? null : VfsUtil.virtualToIoFile(baseFolder);

  final Set<ExtraType> extras = new HashSet<ExtraType>();
  if (provider.toSearchIn(FindTextScopeProvider.SearchTextScope.IN_TOPIC_NOTES)) {
    extras.add(ExtraType.NOTE);
  }
  if (provider.toSearchIn(FindTextScopeProvider.SearchTextScope.IN_TOPIC_FILES)) {
    extras.add(ExtraType.FILE);
  }
  if (provider.toSearchIn(FindTextScopeProvider.SearchTextScope.IN_TOPIC_URI)) {
    extras.add(ExtraType.LINK);
  }
  final boolean inTopicText = provider.toSearchIn(FindTextScopeProvider.SearchTextScope.IN_TOPIC_TEXT);

  Topic found = this.mindMapPanel.getModel().findPrev(projectBaseFolder, startTopic, pattern, inTopicText, extras);
  if (found == null && startTopic != null) {
    found = this.mindMapPanel.getModel().findPrev(projectBaseFolder, null, pattern, inTopicText, extras);
  }

  if (found != null) {
    this.mindMapPanel.removeAllSelection();
    this.mindMapPanel.focusTo(found);
  }

  return found != null;
}
 
Example 12
Source File: MindMapDocumentEditor.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
public boolean findNext(@Nonnull final Pattern pattern, @Nonnull final FindTextScopeProvider provider) {
  Topic startTopic = null;
  if (this.mindMapPanel.hasSelectedTopics()) {
    final Topic[] selected = this.mindMapPanel.getSelectedTopics();
    startTopic = selected[selected.length - 1];
  }

  final VirtualFile baseFolder = findRootFolderForEditedFile();
  final File projectBaseFolder = baseFolder == null ? null : VfsUtil.virtualToIoFile(baseFolder);

  final Set<ExtraType> extras = EnumSet.noneOf(ExtraType.class);
  if (provider.toSearchIn(FindTextScopeProvider.SearchTextScope.IN_TOPIC_NOTES)) {
    extras.add(ExtraType.NOTE);
  }
  if (provider.toSearchIn(FindTextScopeProvider.SearchTextScope.IN_TOPIC_FILES)) {
    extras.add(ExtraType.FILE);
  }
  if (provider.toSearchIn(FindTextScopeProvider.SearchTextScope.IN_TOPIC_URI)) {
    extras.add(ExtraType.LINK);
  }
  final boolean inTopicText = provider.toSearchIn(FindTextScopeProvider.SearchTextScope.IN_TOPIC_TEXT);

  Topic found = this.mindMapPanel.getModel().findNext(projectBaseFolder, startTopic, pattern, inTopicText, extras);
  if (found == null && startTopic != null) {
    found = this.mindMapPanel.getModel().findNext(projectBaseFolder, null, pattern, inTopicText, extras);
  }

  if (found != null) {
    this.mindMapPanel.removeAllSelection();
    this.mindMapPanel.focusTo(found);
  }

  return found != null;
}
 
Example 13
Source File: BuckKillCommandHandler.java    From Buck-IntelliJ-Plugin with Apache License 2.0 4 votes vote down vote up
public BuckKillCommandHandler(
    final Project project,
    final VirtualFile root,
    final BuckCommand command) {
  super(project, VfsUtil.virtualToIoFile(root), command);
}
 
Example 14
Source File: BuckBuildCommandHandler.java    From Buck-IntelliJ-Plugin with Apache License 2.0 4 votes vote down vote up
public BuckBuildCommandHandler(
    final Project project,
    final VirtualFile root,
    final BuckCommand command) {
  super(project, VfsUtil.virtualToIoFile(root), command);
}
 
Example 15
Source File: BuckBuildCommandHandler.java    From buck with Apache License 2.0 4 votes vote down vote up
/** @deprecated Use {@link BuckBuildCommandHandler(Project, BuckCommand)} */
@Deprecated
public BuckBuildCommandHandler(
    final Project project, final VirtualFile root, final BuckCommand command) {
  super(project, VfsUtil.virtualToIoFile(root), command, true);
}
 
Example 16
Source File: MindMapPanelControllerImpl.java    From netbeans-mmd-plugin with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public File getProjectFolder() {
  final VirtualFile vfile = this.getEditor().findRootFolderForEditedFile();
  return vfile == null ? null : VfsUtil.virtualToIoFile(vfile);
}
 
Example 17
Source File: MindMapPanelControllerImpl.java    From netbeans-mmd-plugin with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public File getMindMapFile() {
  return VfsUtil.virtualToIoFile(this.editor.getFile());
}
 
Example 18
Source File: BuckKillCommandHandler.java    From buck with Apache License 2.0 4 votes vote down vote up
/** @deprecated Use {@link BuckKillCommandHandler(Project, BuckCommand)}. */
@Deprecated
public BuckKillCommandHandler(
    final Project project, final VirtualFile root, final BuckCommand command) {
  super(project, VfsUtil.virtualToIoFile(root), command, true);
}
 
Example 19
Source File: ArchivesBuilder.java    From consulo with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private <T> void buildArchive(final ArchivePackageInfo archive) throws IOException {
  if (archive.getPackedFiles().isEmpty() && archive.getPackedArchives().isEmpty()) {
    myContext.addMessage(CompilerMessageCategory.WARNING, "Archive '" + archive.getPresentableDestination() + "' has no files so it won't be created", null,
                         -1, -1);
    return;
  }

  myContext.getProgressIndicator().setText(CompilerBundle.message("packaging.compiler.message.building.0", archive.getPresentableDestination()));
  File tempFile = File.createTempFile("artifactCompiler", "tmp");

  myBuiltArchives.put(archive, tempFile);

  FileUtil.createParentDirs(tempFile);

  ArchivePackageWriter<T> packageWriter = (ArchivePackageWriter<T>)archive.getPackageWriter();

  T archiveFile;

  if (packageWriter instanceof ArchivePackageWriterEx) {
    archiveFile = ((ArchivePackageWriterEx<T>)packageWriter).createArchiveObject(tempFile, archive);
  }
  else {
    archiveFile = packageWriter.createArchiveObject(tempFile);
  }

  try {
    final THashSet<String> writtenPaths = new THashSet<>();
    for (Pair<String, VirtualFile> pair : archive.getPackedFiles()) {
      final VirtualFile sourceFile = pair.getSecond();
      if (sourceFile.isInLocalFileSystem()) {
        File file = VfsUtil.virtualToIoFile(sourceFile);
        addFileToArchive(archiveFile, packageWriter, file, pair.getFirst(), writtenPaths);
      }
      else {
        extractFileAndAddToArchive(archiveFile, packageWriter, sourceFile, pair.getFirst(), writtenPaths);
      }
    }

    for (Pair<String, ArchivePackageInfo> nestedArchive : archive.getPackedArchives()) {
      File nestedArchiveFile = myBuiltArchives.get(nestedArchive.getSecond());
      if (nestedArchiveFile != null) {
        addFileToArchive(archiveFile, packageWriter, nestedArchiveFile, nestedArchive.getFirst(), writtenPaths);
      }
      else {
        LOGGER.debug("nested archive file " + nestedArchive.getFirst() + " for " + archive.getPresentableDestination() + " not found");
      }
    }
  }
  catch (Exception e) {
    e.printStackTrace();
  }
  finally {
    packageWriter.close(archiveFile);
  }
}
 
Example 20
Source File: GoBinaryContextProvider.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Nullable
private static TargetInfo getTargetLabel(PsiFile psiFile) {
  Project project = psiFile.getProject();
  BlazeProjectData projectData =
      BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
  if (projectData == null) {
    return null;
  }
  VirtualFile virtualFile = psiFile.getVirtualFile();
  if (virtualFile == null) {
    return null;
  }
  File file = VfsUtil.virtualToIoFile(virtualFile);
  Collection<TargetKey> rulesForFile =
      SourceToTargetMap.getInstance(project).getRulesForSourceFile(file);

  TargetMap targetMap = projectData.getTargetMap();
  List<TargetKey> libraryKeys = new ArrayList<>();
  for (TargetKey key : rulesForFile) {
    TargetIdeInfo target = targetMap.get(key);
    if (target == null || target.getKind().getLanguageClass() != LanguageClass.GO) {
      continue;
    }
    switch (target.getKind().getRuleType()) {
      case BINARY:
        return target.toTargetInfo();
      case LIBRARY:
        libraryKeys.add(target.getKey());
        break;
      case TEST:
      case UNKNOWN:
        // ignore these
    }
  }
  ImmutableMultimap<TargetKey, TargetKey> rdeps = ReverseDependencyMap.get(project);
  return libraryKeys.stream()
      .map(rdeps::get)
      .flatMap(Collection::stream)
      .map(targetMap::get)
      .filter(Objects::nonNull)
      .filter(t -> t.getKind().getLanguageClass() == LanguageClass.GO)
      .filter(t -> t.getKind().getRuleType() == RuleType.BINARY)
      .map(TargetIdeInfo::toTargetInfo)
      .findFirst()
      .orElse(null);
}