Java Code Examples for com.intellij.openapi.vfs.VirtualFile#refresh()
The following examples show how to use
com.intellij.openapi.vfs.VirtualFile#refresh() .
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: JscsFixAction.java From jscs-plugin with MIT License | 6 votes |
public void actionPerformed(AnActionEvent e) { final Project project = e.getProject(); if (project == null) return; final VirtualFile file = (VirtualFile) e.getDataContext().getData(DataConstants.VIRTUAL_FILE); JscsProjectComponent component = project.getComponent(JscsProjectComponent.class); // JscsConfigFileListener.start(collectedInfo.project); // actualFile = ActualFile2.getOrCreateActualFile(JSCS_TEMP_FILE_KEY, file, collectedInfo.fileContent); // if (actualFile == null || actualFile.getActualFile() == null) { // return null; // } // File cwd = new File(project.getBasePath()); // if (actualFile instanceof ActualFile2.TempActualFile) { // cwd = ((ActualFile2.TempActualFile) actualFile).getTempFile().file.getParentFile(); // } // String relativeFile = actualFile.getActualFile().getName(); // File cwd = actualFile.getActualFile().getParentFile(); // String relativeFile = FileUtils.makeRelative(cwd, actualFile.getActualFile()); String rc = JscsExternalAnnotator.getRC(project, component.jscsRcFile); LintResult result = JscsRunner.fix(project.getBasePath(), file.getPath(), component.nodeInterpreter, component.jscsExecutable, rc, component.preset, component.settings.esnext, component.settings.esprima); file.refresh(true, false); }
Example 2
Source File: ReadOnlyAttributeUtil.java From consulo with Apache License 2.0 | 6 votes |
/** * Sets specified read-only status for the spcified <code>file</code>. * This method can be performed only for files which are in local file system. * * @param file file which read-only attribute to be changed. * @param readOnlyStatus new read-only status. * @throws java.lang.IllegalArgumentException * if passed <code>file</code> doesn't * belong to the local file system. * @throws IOException if some <code>IOException</code> occurred. */ public static void setReadOnlyAttribute(VirtualFile file, boolean readOnlyStatus) throws IOException { if (file.getFileSystem().isReadOnly()) { throw new IllegalArgumentException("Wrong file system: " + file.getFileSystem()); } if (file.isWritable() == !readOnlyStatus) { return; } if (file instanceof NewVirtualFile) { ((NewVirtualFile)file).setWritable(!readOnlyStatus); } else { String path = file.getPresentableUrl(); setReadOnlyAttribute(path, readOnlyStatus); file.refresh(false, false); } }
Example 3
Source File: NewStoryboardAction.java From robovm-idea with GNU General Public License v2.0 | 6 votes |
public void actionPerformed(AnActionEvent e) { if(module == null) { return; } VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(e.getDataContext()); final NewStoryboardDialog dialog = new NewStoryboardDialog(e.getProject(), new File(file.getCanonicalPath())); dialog.show(); if(dialog.getExitCode() == DialogWrapper.OK_EXIT_CODE) { IBIntegratorProxy proxy = IBIntegratorManager.getInstance().getProxy(module); if(proxy == null) { RoboVmPlugin.logError(e.getProject(), "Couldn't get interface builder integrator for module %s", module.getName()); } else { File resourceDir = new File(file.getCanonicalPath()); proxy.newIOSStoryboard(dialog.getStoryboardName(), resourceDir); VirtualFile vsfFile = VfsUtil.findFileByIoFile(resourceDir, true); vsfFile.refresh(false, true); } } }
Example 4
Source File: PersistentFSTest.java From consulo with Apache License 2.0 | 6 votes |
public void testDeleteSubstRoots() throws IOException, InterruptedException { if (!SystemInfo.isWindows) return; File tempDirectory = FileUtil.createTempDirectory(getTestName(false), null); File substRoot = IoTestUtil.createSubst(tempDirectory.getPath()); VirtualFile subst = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(substRoot); assertNotNull(subst); try { final File[] children = substRoot.listFiles(); assertNotNull(children); } finally { IoTestUtil.deleteSubst(substRoot.getPath()); } subst.refresh(false, true); PersistentFS fs = PersistentFS.getInstance(); VirtualFile[] roots = fs.getRoots(LocalFileSystem.getInstance()); for (VirtualFile root : roots) { String rootPath = root.getPath(); String prefix = StringUtil.commonPrefix(rootPath, substRoot.getPath()); assertEmpty(prefix); } }
Example 5
Source File: BuckDeps.java From buck with Apache License 2.0 | 6 votes |
/** * In the given {@code buckFile}, modify the given {@code target} to include {@code dependency} in * its deps. * * @param buckFile Home for the given {@code target}. * @param target The fully qualified target to be modified. * @param dependency The fully qualified dependency required by the target. */ static boolean modifyTargetToAddDependency( VirtualFile buckFile, String target, String dependency) { try { File file = new File(buckFile.getPath()); String oldContents = FileUtil.loadFile(file); String newContents = tryToAddDepsToTarget(oldContents, dependency, target); if (oldContents.equals(newContents)) { return false; } LOG.info("Updating " + file.getPath()); FileUtil.writeToFile(file, newContents); buckFile.refresh(false, false); return true; } catch (IOException e) { LOG.error( "Failed to update " + buckFile.getPath() + " target " + target + " to include " + dependency, e); return false; } }
Example 6
Source File: OutputFileUtil.java From consulo with Apache License 2.0 | 5 votes |
@Override public Result applyFilter(String line, int entireLength) { if (line.startsWith(CONSOLE_OUTPUT_FILE_MESSAGE)) { final String filePath = StringUtil.trimEnd(line.substring(CONSOLE_OUTPUT_FILE_MESSAGE.length()), "\n"); return new Result(entireLength - filePath.length() - 1, entireLength, new HyperlinkInfo() { @Override public void navigate(final Project project) { final VirtualFile file = ApplicationManager.getApplication().runWriteAction(new Computable<VirtualFile>() { @Nullable @Override public VirtualFile compute() { return LocalFileSystem.getInstance().refreshAndFindFileByPath(FileUtil.toSystemIndependentName(filePath)); } }); if (file != null) { file.refresh(false, false); ApplicationManager.getApplication().runReadAction(new Runnable() { @Override public void run() { FileEditorManager.getInstance(project).openTextEditor(new OpenFileDescriptor(project, file), true); } }); } } }); } return null; }
Example 7
Source File: NewProjectAction.java From consulo with Apache License 2.0 | 5 votes |
@RequiredUIAccess private static void generateProjectAsync(Project project, @Nonnull NewProjectPanel panel) { // leave current step panel.finish(); NewModuleWizardContext context = panel.getWizardContext(); final File location = new File(context.getPath()); final int childCount = location.exists() ? location.list().length : 0; if (!location.exists() && !location.mkdirs()) { Messages.showErrorDialog(project, "Cannot create directory '" + location + "'", "Create Project"); return; } final VirtualFile baseDir = WriteAction.compute(() -> LocalFileSystem.getInstance().refreshAndFindFileByIoFile(location)); baseDir.refresh(false, true); if (childCount > 0) { int rc = Messages.showYesNoDialog(project, "The directory '" + location + "' is not empty. Continue?", "Create New Project", Messages.getQuestionIcon()); if (rc == Messages.NO) { return; } } RecentProjectsManager.getInstance().setLastProjectCreationLocation(location.getParent()); UIAccess uiAccess = UIAccess.current(); ProjectManager.getInstance().openProjectAsync(baseDir, uiAccess).doWhenDone((openedProject) -> { uiAccess.give(() -> NewOrImportModuleUtil.doCreate(panel, openedProject, baseDir)); }); }
Example 8
Source File: BuckGotoProviderTest.java From buck with Apache License 2.0 | 5 votes |
private VirtualFile makeFile(VirtualFile root, String relativePath, String... lines) throws IOException { File targetFile = Paths.get(root.getPath()).resolve(relativePath).toFile(); targetFile.getParentFile().mkdirs(); try (BufferedWriter writer = new BufferedWriter(new FileWriter(targetFile))) { for (String line : lines) { writer.write(line); writer.newLine(); } } root.refresh(false, true); return root.findFileByRelativePath(relativePath); }
Example 9
Source File: L2GitUtil.java From azure-devops-intellij with MIT License | 5 votes |
/** * Clones a repo and returns the Project that it belongs to * * @param project * @param baseDirectory * @param myGit * @param gitRepoUrl * @param teamProject * @return */ public static Project cloneRepo(final Project project, final File baseDirectory, final Git myGit, final String gitRepoUrl, final String teamProject) { final CustomCheckoutListener customListener = new CustomCheckoutListener(project); final VirtualFile virtualBaseDirectory = LocalFileSystem.getInstance().findFileByIoFile(baseDirectory); ProgressManager.getInstance().runProcess(new Runnable() { @Override public void run() { git4idea.checkout.GitCheckoutProvider.clone(project, myGit, customListener, virtualBaseDirectory, gitRepoUrl, teamProject, baseDirectory.getPath()); } }, new ProgressIndicatorBase()); DvcsUtil.addMappingIfSubRoot(project, FileUtil.join(baseDirectory.getPath(), teamProject), GitVcs.NAME); virtualBaseDirectory.refresh(true, true, new Runnable() { public void run() { if (project.isOpen() && !project.isDisposed() && !project.isDefault()) { final VcsDirtyScopeManager mgr = VcsDirtyScopeManager.getInstance(project); mgr.fileDirty(virtualBaseDirectory); } } }); return customListener.getNewProject(); }
Example 10
Source File: FlutterSdk.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Runs flutter create and waits for it to finish. * <p> * Shows output in a console unless the module parameter is null. * <p> * Notifies process listener if one is specified. * <p> * Returns the PubRoot if successful. */ @Nullable public PubRoot createFiles(@NotNull VirtualFile baseDir, @Nullable Module module, @Nullable ProcessListener listener, @Nullable FlutterCreateAdditionalSettings additionalSettings) { final Process process; if (module == null) { process = flutterCreate(baseDir, additionalSettings).start(null, listener); } else { process = flutterCreate(baseDir, additionalSettings).startInModuleConsole(module, null, listener); } if (process == null) { return null; } try { if (process.waitFor() != 0) { return null; } } catch (InterruptedException e) { FlutterUtils.warn(LOG, e); return null; } if (EdtInvocationManager.getInstance().isEventDispatchThread()) { VfsUtil.markDirtyAndRefresh(false, true, true, baseDir); // Need this for AS. } else { baseDir.refresh(false, true); // The current thread must NOT be in a read action. } return PubRoot.forDirectory(baseDir); }
Example 11
Source File: FlutterModuleBuilder.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Nullable private static VirtualFile findAndroidModuleFile(@NotNull VirtualFile baseDir, String flutterModuleName) { baseDir.refresh(false, false); for (String name : asList(flutterModuleName + "_android.iml", "android.iml")) { final VirtualFile candidate = baseDir.findChild(name); if (candidate != null && candidate.exists()) { return candidate; } } return null; }
Example 12
Source File: PubRoot.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Returns the PubRoot for a directory, provided it contains a pubspec.yaml file. * <p> * Refreshes the directory and the lib directory (if present). Returns null if not found. */ @Nullable public static PubRoot forDirectoryWithRefresh(@NotNull VirtualFile dir) { // Ensure file existence and timestamps are up to date. dir.refresh(false, false); return forDirectory(dir); }
Example 13
Source File: BaseProjectTreeBuilder.java From consulo with Apache License 2.0 | 5 votes |
@Override protected final void expandNodeChildren(@Nonnull final DefaultMutableTreeNode node) { final NodeDescriptor userObject = (NodeDescriptor)node.getUserObject(); if (userObject == null) return; Object element = userObject.getElement(); VirtualFile virtualFile = getFileToRefresh(element); super.expandNodeChildren(node); if (virtualFile != null) { virtualFile.refresh(true, false); } }
Example 14
Source File: SymlinkTestCase.java From consulo with Apache License 2.0 | 5 votes |
protected void refresh(boolean recursive) { final VirtualFile tempDir = myFileSystem.findFileByIoFile(myTempDir); assertNotNull(myTempDir.getPath(), tempDir); tempDir.getChildren(); tempDir.refresh(false, true); if (recursive) { VfsUtilCore.visitChildrenRecursively(tempDir, new VirtualFileVisitor() { }); } }
Example 15
Source File: FileDocumentManagerImplTest.java From consulo with Apache License 2.0 | 5 votes |
public void testExternalReplaceWithTheSameText() throws Exception { final VirtualFile file = createFile(); long modificationStamp = file.getModificationStamp(); DocumentEx document = (DocumentEx)myDocumentManager.getDocument(file); FileUtil.writeToFile(new File(file.getPath()), "xxx"); file.refresh(false, false); assertNotNull(file.toString(), document); assertNotSame(file.getModificationStamp(), modificationStamp); assertEquals(file.getModificationStamp(), document.getModificationStamp()); }
Example 16
Source File: VirtualFileUtil.java From NutzCodeInsight with Apache License 2.0 | 5 votes |
/** * 刷新目录 * * @param path */ public static void refreshPath(Path path) { VirtualFile value = VirtualFileManager.getInstance().findFileByUrl(path.toUri().toString()); if (value != null) { value.refresh(true, true); } }
Example 17
Source File: BuckGotoProviderTest.java From buck with Apache License 2.0 | 4 votes |
private VirtualFile makeDirectory(VirtualFile root, String relativePath) { Paths.get(root.getPath()).resolve(relativePath).toFile().mkdirs(); root.refresh(false, true); return root.findFileByRelativePath(relativePath); }
Example 18
Source File: ArtifactCompilerTestCase.java From consulo with Apache License 2.0 | 4 votes |
public static void assertOutput(Artifact artifact, TestFileSystemBuilder item) { final VirtualFile outputFile = getOutputDir(artifact); outputFile.refresh(false, true); item.build().assertDirectoryEqual(VfsUtil.virtualToIoFile(outputFile)); }
Example 19
Source File: RoboVmModuleBuilder.java From robovm-idea with GNU General Public License v2.0 | 4 votes |
@Override public void setupRootModel(final ModifiableRootModel modifiableRootModel) throws ConfigurationException { // set the Java SDK myJdk = RoboVmPlugin.getSdk(); if (myJdk == null || !robovmDir.isEmpty()) { myJdk = RoboVmSdkType.findBestJdk(); } // set a project jdk if none is set ProjectRootManager manager = ProjectRootManager.getInstance(modifiableRootModel.getProject()); if (manager.getProjectSdk() == null) { manager.setProjectSdk(RoboVmSdkType.findBestJdk()); } if (buildSystem != BuildSystem.None) { // apply the template final Project project = modifiableRootModel.getProject(); StartupManager.getInstance(project).runWhenProjectIsInitialized(new DumbAwareRunnable() { public void run() { DumbService.getInstance(project).smartInvokeLater(new Runnable() { public void run() { ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { RoboVmModuleBuilder.this.applyTemplate(project); } }); } }); } }); // apply the build system StartupManager.getInstance(project).registerPostStartupActivity(new DumbAwareRunnable() { public void run() { DumbService.getInstance(project).smartInvokeLater(new Runnable() { public void run() { RoboVmModuleBuilder.this.applyBuildSystem(project); } }); } }); } else { Sdk jdk = RoboVmSdkType.findBestJdk(); LanguageLevel langLevel = ((JavaSdk) jdk.getSdkType()).getVersion(jdk).getMaxLanguageLevel(); modifiableRootModel.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(langLevel); super.setupRootModel(modifiableRootModel); final VirtualFile contentRoot = LocalFileSystem.getInstance() .findFileByIoFile(new File(modifiableRootModel.getProject().getBasePath())); applyTemplate(modifiableRootModel.getProject()); contentRoot.refresh(false, true); for (ContentEntry entry : modifiableRootModel.getContentEntries()) { for (SourceFolder srcFolder : entry.getSourceFolders()) { entry.removeSourceFolder(srcFolder); } if (robovmDir.isEmpty()) { entry.addSourceFolder(contentRoot.findFileByRelativePath("/src/main/java"), false); } new File(entry.getFile().getCanonicalPath()).delete(); } } }
Example 20
Source File: SOAPKitScaffoldingAction.java From mule-intellij-plugins with Apache License 2.0 | 4 votes |
@Override public void actionPerformed(AnActionEvent anActionEvent) { final VirtualFile selectedWsdlFile = CommonDataKeys.VIRTUAL_FILE.getData(anActionEvent.getDataContext()); final Project project = anActionEvent.getProject(); PsiFile psiFile = anActionEvent.getData(CommonDataKeys.PSI_FILE); final VirtualFile moduleContentRoot = ProjectRootManager.getInstance(project).getFileIndex().getContentRootForFile(selectedWsdlFile); final VirtualFile appsRoot = moduleContentRoot.findFileByRelativePath(MuleConfigUtils.CONFIG_RELATIVE_PATH); String appPath = appsRoot.getPath(); String wsdlPath = selectedWsdlFile.getPath(); logger.debug("*** WSDL PATH IS " + wsdlPath); logger.debug("*** APP PATH IS " + appPath); Definition wsdlDefinition = WsdlUtils.parseWSDL(wsdlPath); List<String> configFiles = MuleDeployProperties.getConfigFileNames(appPath); final SoapKitDialog form = new SoapKitDialog(wsdlDefinition, configFiles); form.show(); boolean isOk = form.getExitCode() == DialogWrapper.OK_EXIT_CODE; if (!isOk) return; final String service = form.getService().getSelectedItem().toString(); final String port = form.getPort().getSelectedItem().toString(); String muleXml = form.getConfigFile().getSelectedItem().toString(); logger.debug("*** SERVICE " + service); logger.debug("*** PORT " + port); logger.debug("*** muleXml " + muleXml); logger.debug("*** wsdlPath " + wsdlPath); if (SoapKitDialog.NEW_FILE.equals(muleXml)) { File muleXmlFile = null; int i = 0; do { muleXml = selectedWsdlFile.getNameWithoutExtension() + (i > 0 ? "-" + i : "") + ".xml"; muleXmlFile = new File(appPath, muleXml); i++; } while (muleXmlFile.exists()); } final String muleXmlConfigFileName = muleXml; try { new WriteCommandAction.Simple(project, psiFile) { @Override protected void run() throws Throwable { VirtualFile vMuleXmlFile = appsRoot.findOrCreateChildData(this, muleXmlConfigFileName); Element resultElement = SCAFFOLDER.scaffold(wsdlPath, wsdlPath, service, port, ""); writeMuleXmlFile(resultElement, vMuleXmlFile); } }.execute(); } catch (Exception e) { Notification notification = MuleUIUtils.MULE_NOTIFICATION_GROUP.createNotification("Unable to generate flows from WSDL File", "Error Message : " + e, NotificationType.ERROR, null); Notifications.Bus.notify(notification, project); } moduleContentRoot.refresh(false, true); }