Java Code Examples for com.intellij.openapi.vfs.VfsUtilCore#virtualToIoFile()
The following examples show how to use
com.intellij.openapi.vfs.VfsUtilCore#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: ProjectBuildModelImpl.java From ok-gradle with Apache License 2.0 | 6 votes |
@Override @Nullable public GradleSettingsModel getProjectSettingsModel() { VirtualFile virtualFile = null; // If we don't have a root build file, guess the location of the settings file from the project. if (myProjectBuildFile == null) { VirtualFile projectDir = ProjectUtil.guessProjectDir(myBuildModelContext.getProject()); if (projectDir != null) { File ioFile = VfsUtilCore.virtualToIoFile(projectDir); virtualFile = getGradleSettingsFile(ioFile); } } else { virtualFile = myProjectBuildFile.tryToFindSettingsFile(); } if (virtualFile == null) { return null; } GradleSettingsFile settingsFile = myBuildModelContext.getOrCreateSettingsFile(virtualFile); return new GradleSettingsModelImpl(settingsFile); }
Example 2
Source File: ModuleImportProcessor.java From consulo with Apache License 2.0 | 6 votes |
@RequiredUIAccess public static <C extends ModuleImportContext> void showImportChooser(@Nullable Project project, VirtualFile file, @Nonnull AsyncResult<Pair<C, ModuleImportProvider<C>>> result) { boolean isModuleImport = project != null; List<ModuleImportProvider> providers = ModuleImportProviders.getExtensions(isModuleImport); File ioFile = VfsUtilCore.virtualToIoFile(file); List<ModuleImportProvider> avaliableProviders = ContainerUtil.filter(providers, provider -> provider.canImport(ioFile)); if (avaliableProviders.isEmpty()) { Alerts.okError("Cannot import anything from '" + FileUtil.toSystemDependentName(file.getPath()) + "'").showAsync(); result.setRejected(); return; } showImportChooser(project, file, providers, result); }
Example 3
Source File: PathsVerifier.java From consulo with Apache License 2.0 | 6 votes |
public VirtualFile doMove() throws IOException { final VirtualFile oldParent = myCurrent.getParent(); boolean needRename = !Comparing.equal(myCurrent.getName(), myNewName); boolean needMove = !myNewParent.equals(oldParent); if (needRename) { if (needMove) { File oldParentFile = VfsUtilCore.virtualToIoFile(oldParent); File targetAfterRenameFile = new File(oldParentFile, myNewName); if (targetAfterRenameFile.exists() && myCurrent.exists()) { // if there is a conflict during first rename we have to rename to third name, then move, then rename to final target performRenameWithConflicts(oldParentFile); return myCurrent; } } myCurrent.rename(PatchApplier.class, myNewName); } if (needMove) { myCurrent.move(PatchApplier.class, myNewParent); } return myCurrent; }
Example 4
Source File: BinaryFilePatchInProgress.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull @Override public DiffRequestProducer getDiffRequestProducers(final Project project, final PatchReader baseContents) { final ShelvedBinaryFile file = getPatch().getShelvedBinaryFile(); return new DiffRequestProducer() { @Nonnull @Override public DiffRequest process(@Nonnull UserDataHolder context, @Nonnull ProgressIndicator indicator) throws DiffRequestProducerException, ProcessCanceledException { Change change = file.createChange(project); return PatchDiffRequestFactory.createDiffRequest(project, change, getName(), context, indicator); } @Nonnull @Override public String getName() { final File file1 = new File(VfsUtilCore.virtualToIoFile(getBase()), file.AFTER_PATH == null ? file.BEFORE_PATH : file.AFTER_PATH); return FileUtil.toSystemDependentName(file1.getPath()); } }; }
Example 5
Source File: AbstractImportTestsAction.java From consulo with Apache License 2.0 | 6 votes |
@Nullable @Override public RunProfileState getState(@Nonnull Executor executor, @Nonnull ExecutionEnvironment environment) throws ExecutionException { if (!myImported) { myImported = true; return new ImportedTestRunnableState(this, VfsUtilCore.virtualToIoFile(myFile)); } if (myConfiguration != null) { try { return myConfiguration.getState(executor, environment); } catch (Throwable e) { if (myTargetId != null && getTarget() == null) { throw new ExecutionException("The target " + myTargetId + " does not exist"); } LOG.info(e); throw new ExecutionException("Unable to run the configuration: settings are corrupted"); } } throw new ExecutionException("Unable to run the configuration: failed to detect test framework"); }
Example 6
Source File: FileStatusCalculator.java From SVNToolBox with Apache License 2.0 | 6 votes |
@NotNull public FileStatus statusFor(@NotNull SvnVcs svn, @NotNull Project project, @NotNull VirtualFile vFile) { File currentFile = VfsUtilCore.virtualToIoFile(vFile); Url fileUrl = SvnUtil.getUrl(svn, currentFile); if (fileUrl != null) { Info info = svn.getInfo(vFile); if (info != null) { SvnConfiguration svnConfig = SvnConfiguration.getInstance(project); Optional<FileStatus> status; status = statusForCli(project, fileUrl, currentFile); if (status.isPresent()) { return status.get(); } } else { return new FileStatus(fileUrl); } } return FileStatus.EMPTY; }
Example 7
Source File: TFSDiffProvider.java From azure-devops-intellij with MIT License | 6 votes |
@Nullable public VcsRevisionNumber getCurrentRevision(final VirtualFile virtualFile) { try { // need to make a file because the VirtualFile object path is in system-independent format final File localFile = VfsUtilCore.virtualToIoFile(virtualFile); final String filePath = localFile.getPath(); final ServerContext context = TFSVcs.getInstance(project).getServerContext(true); final ItemInfo itemInfo = CommandUtils.getItemInfo(context, filePath); return createRevision(itemInfo, filePath); } catch (Exception e) { logger.warn("Unable to getCurrentRevision", e); AbstractVcsHelper.getInstance(project).showError( new VcsException(LocalizationServiceImpl.getInstance().getExceptionMessage(e), e), TFSVcs.TFVC_NAME); } return VcsRevisionNumber.NULL; }
Example 8
Source File: GradleToolDelegate.java From intellij-quarkus with Eclipse Public License 2.0 | 6 votes |
@Override public void processImport(Module module) { Project project = module.getProject(); File gradleFile = null; for(VirtualFile virtualFile : ModuleRootManager.getInstance(module).getContentRoots()) { File baseDir = VfsUtilCore.virtualToIoFile(virtualFile); File file = new File(baseDir, "build.gradle"); if (file.exists()) { gradleFile = file; break; } } if (gradleFile != null) { ProjectImportProvider gradleProjectImportProvider = getGradleProjectImportProvider(); ProjectImportBuilder gradleProjectImportBuilder = gradleProjectImportProvider.getBuilder(); AddModuleWizard wizard = new AddModuleWizard(project, gradleFile.getPath(), new ProjectImportProvider[]{gradleProjectImportProvider}); if (wizard.getStepCount() == 0 || wizard.showAndGet()) { gradleProjectImportBuilder.commit(project, (ModifiableModuleModel)null, (ModulesProvider)null); } } }
Example 9
Source File: NewBashFileActionTest.java From BashSupport with Apache License 2.0 | 5 votes |
@Test public void testNewFile() throws Exception { ActionManager actionManager = ActionManager.getInstance(); final NewBashFileAction action = (NewBashFileAction) actionManager.getAction("Bash.NewBashScript"); // @see https://devnet.jetbrains.com/message/5539349#5539349 VirtualFile directoryVirtualFile = myFixture.getTempDirFixture().findOrCreateDir(""); final PsiDirectory directory = myFixture.getPsiManager().findDirectory(directoryVirtualFile); Assert.assertEquals(BashStrings.message("newfile.command.name"), action.getCommandName()); Assert.assertEquals(BashStrings.message("newfile.menu.action.text"), action.getActionName(directory, "")); PsiElement result = ApplicationManager.getApplication().runWriteAction(new Computable<PsiElement>() { @Override public PsiElement compute() { try { PsiElement[] elements = action.create("bash_file", directory); return elements.length >= 1 ? elements[0] : null; //the firet element is the BashFile } catch (Exception e) { return null; } } }); assertNotNull("Expected a newly created bash file", result); assertTrue("Expected a newly created bash file", result instanceof BashFile); VirtualFile vFile = ((BashFile) result).getVirtualFile(); File ioFile = VfsUtilCore.virtualToIoFile(vFile); assertTrue("Expected that the new file is executable", ioFile.canExecute()); Assert.assertEquals("Expected default bash file template content", "#!/usr/bin/env bash", result.getText()); }
Example 10
Source File: ModuleDeploymentSourceImpl.java From consulo with Apache License 2.0 | 5 votes |
@javax.annotation.Nullable @Override public File getFile() { VirtualFile contentRoot = getContentRoot(); if (contentRoot == null) { return null; } return VfsUtilCore.virtualToIoFile(contentRoot); }
Example 11
Source File: PackageFileWorker.java From consulo with Apache License 2.0 | 5 votes |
public static void packageFile(@Nonnull VirtualFile file, @Nonnull Project project, final Artifact[] artifacts) throws IOException { LOG.debug("Start packaging file: " + file.getPath()); final Collection<Trinity<Artifact, PackagingElementPath, String>> items = ArtifactUtil.findContainingArtifactsWithOutputPaths(file, project, artifacts); File ioFile = VfsUtilCore.virtualToIoFile(file); for (Trinity<Artifact, PackagingElementPath, String> item : items) { final Artifact artifact = item.getFirst(); final String outputPath = artifact.getOutputPath(); if (!StringUtil.isEmpty(outputPath)) { PackageFileWorker worker = new PackageFileWorker(ioFile, item.getThird()); LOG.debug(" package to " + outputPath); worker.packageFile(outputPath, item.getSecond().getParents()); } } }
Example 12
Source File: BlazeAndroidModuleTemplate.java From intellij with Apache License 2.0 | 5 votes |
public static List<NamedModuleTemplate> getTemplates( AndroidFacet androidFacet, @Nullable VirtualFile targetDirectory) { Module module = androidFacet.getModule(); BlazeAndroidModuleTemplate paths = new BlazeAndroidModuleTemplate(); VirtualFile[] roots = ModuleRootManager.getInstance(module).getContentRoots(); if (roots.length > 0) { paths.moduleRoot = VfsUtilCore.virtualToIoFile(roots[0]); } IdeaSourceProvider sourceProvider = SourceProviderManager.getInstance(androidFacet).getSources(); // If this happens to be a resource package, // the module name (resource package) would be more descriptive than the facet name (Android). // Otherwise, .workspace is still better than (Android). String name = androidFacet.getModule().getName(); if (targetDirectory != null) { String packageName = getPackageName(module.getProject(), targetDirectory); if (packageName != null) { name = packageName; } paths.srcDirectory = VfsUtilCore.virtualToIoFile(targetDirectory); } else { // People usually put the manifest file with their sources. //noinspection OptionalGetWithoutIsPresent paths.srcDirectory = sourceProvider.getManifestDirectoryUrls().stream() .map(it -> new File(VfsUtilCore.urlToPath(it))) .findFirst() .get(); } // We have a res dir if this happens to be a resource module. paths.resDirectories = sourceProvider.getResDirectoryUrls().stream() .map(it -> new File(VfsUtilCore.urlToPath(it))) .collect(Collectors.toList()); return Collections.singletonList(new NamedModuleTemplate(name, paths)); }
Example 13
Source File: DocumentationManager.java From consulo with Apache License 2.0 | 5 votes |
@Nullable private static String generateFileDoc(@Nonnull PsiFile psiFile, boolean withUrl) { VirtualFile file = PsiUtilCore.getVirtualFile(psiFile); File ioFile = file == null || !file.isInLocalFileSystem() ? null : VfsUtilCore.virtualToIoFile(file); BasicFileAttributes attr = null; try { attr = ioFile == null ? null : Files.readAttributes(Paths.get(ioFile.toURI()), BasicFileAttributes.class); } catch (Exception ignored) { } if (attr == null) return null; FileType type = file.getFileType(); String typeName = type == UnknownFileType.INSTANCE ? "Unknown" : type == PlainTextFileType.INSTANCE ? "Text" : type instanceof ArchiveFileType ? "Archive" : type.getId(); String languageName = type.isBinary() ? "" : psiFile.getLanguage().getDisplayName(); return (withUrl ? DocumentationMarkup.DEFINITION_START + file.getPresentableUrl() + DocumentationMarkup.DEFINITION_END + DocumentationMarkup.CONTENT_START : "") + getVcsStatus(psiFile.getProject(), file) + getScope(psiFile.getProject(), file) + "<p><span class='grayed'>Size:</span> " + StringUtil.formatFileSize(attr.size()) + "<p><span class='grayed'>Type:</span> " + typeName + (type.isBinary() || typeName.equals(languageName) ? "" : " (" + languageName + ")") + "<p><span class='grayed'>Modified:</span> " + DateFormatUtil.formatDateTime(attr.lastModifiedTime().toMillis()) + "<p><span class='grayed'>Created:</span> " + DateFormatUtil.formatDateTime(attr.creationTime().toMillis()) + (withUrl ? DocumentationMarkup.CONTENT_END : ""); }
Example 14
Source File: RoboVmModuleBuilder.java From robovm-idea with GNU General Public License v2.0 | 4 votes |
private void applyBuildSystem(final Project project) { if (buildSystem == BuildSystem.Gradle) { File baseDir = VfsUtilCore.virtualToIoFile(project.getBaseDir()); File[] files = baseDir.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return FileUtil.namesEqual("build.gradle", name); } }); if (files != null && files.length != 0) { project.putUserData(ExternalSystemDataKeys.NEWLY_CREATED_PROJECT, Boolean.TRUE); ProjectDataManager projectDataManager = (ProjectDataManager) ServiceManager .getService(ProjectDataManager.class); GradleProjectImportBuilder gradleProjectImportBuilder = new GradleProjectImportBuilder( projectDataManager); gradleProjectImportBuilder.getControl(project).getProjectSettings() .setDistributionType(DistributionType.WRAPPED); GradleProjectImportProvider gradleProjectImportProvider = new GradleProjectImportProvider( gradleProjectImportBuilder); AddModuleWizard wizard = new AddModuleWizard((Project) null, files[0].getPath(), new ProjectImportProvider[] { gradleProjectImportProvider }); if (wizard.getStepCount() <= 0 || wizard.showAndGet()) { ImportModuleAction.createFromWizard(project, wizard); ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { ModifiableModuleModel modifiableModel = ModuleManager.getInstance(project).getModifiableModel(); for (Module module : modifiableModel.getModules()) { try { LanguageLevelModuleExtensionImpl langModel = (LanguageLevelModuleExtensionImpl) LanguageLevelModuleExtensionImpl.getInstance(module).getModifiableModel(true); langModel.setLanguageLevel(LanguageLevel.JDK_1_8); langModel.commit(); } catch(Throwable t) { // could be a non-Java project t.printStackTrace(); } } modifiableModel.commit(); } }); } } } else { FileDocumentManager.getInstance().saveAllDocuments(); MavenProjectsManager.getInstance(project).forceUpdateAllProjectsOrFindAllAvailablePomFiles(); } }
Example 15
Source File: GitCompatUtil.java From GitToolBox with Apache License 2.0 | 4 votes |
private GitRepoInfo(GitRepository repo) { this.repo = repo; rootFile = VfsUtilCore.virtualToIoFile(this.repo.getRoot()); }
Example 16
Source File: IdeaUtils.java From netbeans-mmd-plugin with Apache License 2.0 | 4 votes |
@Nullable public static File vfile2iofile(@Nullable final VirtualFile vfFile) { return vfFile == null ? null : VfsUtilCore.virtualToIoFile(vfFile); }
Example 17
Source File: CopyingCompiler.java From consulo with Apache License 2.0 | 4 votes |
public CopyItem(@Nonnull VirtualFile file, @Nonnull String destinationPath) { myFile = VfsUtilCore.virtualToIoFile(file); myInfo = new DestinationFileInfo(destinationPath, new File(destinationPath).exists()); }
Example 18
Source File: StubOCCompilerSettings.java From intellij with Apache License 2.0 | 4 votes |
@Override public File getCompilerWorkingDir() { return VfsUtilCore.virtualToIoFile(project.getBaseDir()); }