Java Code Examples for com.intellij.openapi.util.io.FileUtil#createTempDirectory()
The following examples show how to use
com.intellij.openapi.util.io.FileUtil#createTempDirectory() .
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: InsightUpdateQueue.java From reasonml-idea-plugin with MIT License | 6 votes |
public InsightUpdateQueue(@NotNull Project project, @NotNull VirtualFile sourceFile) { super("hints", 200, true, null); setRestartTimerOnAdd(true); m_contentRoot = BsPlatform.findContentRootForFile(project, sourceFile).orElse(null); m_libRoot = m_contentRoot == null ? null : m_contentRoot.findFileByRelativePath("lib/bs"); m_sourceFile = sourceFile; try { m_tempDirectory = FileUtil.createTempDirectory("BS_" + project.getName().replaceAll(" ", "_"), null); } catch (IOException e) { throw new RuntimeException(e); // TODO handle exception } initConfig(project); }
Example 2
Source File: VersionControlPathTests.java From azure-devops-intellij with MIT License | 6 votes |
@Test public void localPathFromTfsRepresentationShouldConvertPathCase() throws IOException { File tempDirectory = FileUtil.createTempDirectory("azure-devops", ".tmp"); try { File tempFile = tempDirectory.toPath().resolve("CASE_SENSITIVE.tmp").toFile(); Assert.assertTrue(tempFile.createNewFile()); String tfsRepresentation = tempFile.getAbsolutePath(); // On non-Windows systems, TFS uses a "fake drive" prefix: if (!SystemInfo.isWindows) tfsRepresentation = "U:" + tfsRepresentation; String localPath = VersionControlPath.localPathFromTfsRepresentation(tfsRepresentation); Assert.assertEquals(tempFile.getAbsolutePath(), localPath); if (!SystemInfo.isFileSystemCaseSensitive) { tfsRepresentation = tfsRepresentation.toLowerCase(); localPath = VersionControlPath.localPathFromTfsRepresentation(tfsRepresentation); Assert.assertEquals(tempFile.getAbsolutePath(), localPath); } } finally { FileUtil.delete(tempDirectory); } }
Example 3
Source File: VfsAwareMapIndexStorage.java From consulo with Apache License 2.0 | 6 votes |
private static File getSessionDir() { File sessionDirectory = mySessionDirectory; if (sessionDirectory == null) { synchronized (VfsAwareMapIndexStorage.class) { sessionDirectory = mySessionDirectory; if (sessionDirectory == null) { try { mySessionDirectory = sessionDirectory = FileUtil.createTempDirectory(new File(ContainerPathManager.get().getTempPath()), Long.toString(System.currentTimeMillis()), "", true); } catch (IOException ex) { throw new RuntimeException("Can not create temp directory", ex); } } } } return sessionDirectory; }
Example 4
Source File: InstalledPluginsManagerMain.java From consulo with Apache License 2.0 | 6 votes |
@Nullable public static PluginDescriptor loadDescriptionFromJar(final File file) throws IOException { PluginDescriptor descriptor = null; if (file.getName().endsWith(".zip")) { final File outputDir = FileUtil.createTempDirectory("plugin", ""); try { ZipUtil.extract(file, outputDir, null); final File[] files = outputDir.listFiles(); if (files != null && files.length == 1) { descriptor = PluginsLoader.loadPluginDescriptor(files[0]); } } finally { FileUtil.delete(outputDir); } } return descriptor; }
Example 5
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 6
Source File: TestFileSystemItem.java From consulo with Apache License 2.0 | 6 votes |
private void assertFileEqual(File file, String relativePath) { try { Assert.assertEquals("in " + relativePath, myName, file.getName()); if (myArchive) { final File dirForExtracted = FileUtil.createTempDirectory("extracted_archive", null,false); ZipUtil.extract(file, dirForExtracted, null); assertDirectoryEqual(dirForExtracted, relativePath); FileUtil.delete(dirForExtracted); } else if (myDirectory) { Assert.assertTrue(relativePath + file.getName() + " is not a directory", file.isDirectory()); assertDirectoryEqual(file, relativePath); } else if (myContent != null) { final String content = FileUtil.loadFile(file); Assert.assertEquals("content mismatch for " + relativePath, myContent, content); } } catch (IOException e) { throw new RuntimeException(e); } }
Example 7
Source File: UsageNodeTreeBuilderTest.java From consulo with Apache License 2.0 | 6 votes |
public void testFilesWithTheSameNameButDifferentPathsEndUpInDifferentGroups() throws IOException { File ioDir = FileUtil.createTempDirectory("t", null, false); VirtualFile dir = null; try { dir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(ioDir); PsiFile f1 = getPsiManager().findFile(VfsTestUtil.createFile(dir, "/x/X.java", "class X{}")); PsiFile f2 = getPsiManager().findFile(VfsTestUtil.createFile(dir, "/y/X.java", "class X{}")); PsiElement class1 = ArrayUtil.getLastElement(f1.getChildren()); PsiElement class2 = ArrayUtil.getLastElement(f2.getChildren()); FileGroupingRule fileGroupingRule = new FileGroupingRule(getProject()); UsageGroup group1 = fileGroupingRule.getParentGroupFor(new UsageInfo2UsageAdapter(new UsageInfo(class1)), UsageTarget.EMPTY_ARRAY); UsageGroup group2 = fileGroupingRule.getParentGroupFor(new UsageInfo2UsageAdapter(new UsageInfo(class2)), UsageTarget.EMPTY_ARRAY); int compareTo = group1.compareTo(group2); assertTrue(String.valueOf(compareTo), compareTo < 0); } finally { if (dir != null) { VfsTestUtil.deleteFile(dir); } FileUtil.delete(ioDir); } }
Example 8
Source File: GetPathPerformanceTest.java From consulo with Apache License 2.0 | 6 votes |
public void testGetPath() throws IOException, InterruptedException { final File dir = FileUtil.createTempDirectory("GetPath",""); dir.deleteOnExit(); String path = dir.getPath() + StringUtil.repeat("/xxx", 50) + "/fff.txt"; File ioFile = new File(path); boolean b = ioFile.getParentFile().mkdirs(); assertTrue(b); boolean c = ioFile.createNewFile(); assertTrue(c); final VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByPath(ioFile.getPath().replace(File.separatorChar, '/')); assertNotNull(file); PlatformTestUtil.startPerformanceTest("VF.getPath() performance failed", 4000, new ThrowableRunnable() { @Override public void run() { for (int i = 0; i < 1000000; ++i) { file.getPath(); } } }).cpuBound().assertTiming(); }
Example 9
Source File: LocalFileSystemTest.java From consulo with Apache License 2.0 | 6 votes |
public void testBadFileName() throws Exception { if (!SystemInfo.isUnix) { System.err.println(getName() + " skipped: " + SystemInfo.OS_NAME); return; } final File dir = FileUtil.createTempDirectory("test.", ".dir"); final File file = FileUtil.createTempFile(dir, "test\\", "\\txt", true); final VirtualFile vDir = myFS.refreshAndFindFileByIoFile(dir); assertNotNull(vDir); assertEquals(0, vDir.getChildren().length); ((VirtualFileSystemEntry)vDir).markDirtyRecursively(); vDir.refresh(false, true); final VirtualFile vFile = myFS.refreshAndFindFileByIoFile(file); assertNull(vFile); }
Example 10
Source File: SwaggerUiCreator.java From intellij-swagger with MIT License | 5 votes |
@NotNull private File copySwaggerUiToTempDir() throws IOException, URISyntaxException { final File tempSwaggerUiDir = FileUtil.createTempDirectory(SWAGGER_UI_FOLDER_NAME, "", true); copyFromJar(Paths.get(tempSwaggerUiDir.toURI())); return tempSwaggerUiDir; }
Example 11
Source File: GeneralCommandLineTest.java From consulo with Apache License 2.0 | 5 votes |
@Test public void unicodeClassPath() throws Exception { assumeTrue(SystemInfo.isUnix); File dir = FileUtil.createTempDirectory("path with spaces 'and quotes' и юникодом ", ".tmp"); try { GeneralCommandLine commandLine = makeJavaCommand(ParamPassingTest.class, dir); String output = execAndGetOutput(commandLine, null); assertEquals("=====\n=====\n", StringUtil.convertLineSeparators(output)); } finally { FileUtil.delete(dir); } }
Example 12
Source File: ProjectStoreImplIdeaDirTest.java From consulo with Apache License 2.0 | 5 votes |
@Override protected File getTempProjectDir() throws IOException { final File projectDir = FileUtil.createTempDirectory(getTestName(true), "project"); File ideaDir = new File(projectDir, Project.DIRECTORY_STORE_FOLDER); assertTrue(ideaDir.mkdir() || ideaDir.isDirectory()); File iprFile = new File(ideaDir, "misc.xml"); FileUtil.writeToFile(iprFile, getIprFileContent()); myFilesToDelete.add(projectDir); return projectDir; }
Example 13
Source File: LocalFileSystemTest.java From consulo with Apache License 2.0 | 5 votes |
public void testHardLinks() throws Exception { if (!SystemInfo.isWindows && !SystemInfo.isUnix) { System.err.println(getName() + " skipped: " + SystemInfo.OS_NAME); return; } final boolean safeWrite = GeneralSettings.getInstance().isUseSafeWrite(); final File dir = FileUtil.createTempDirectory("hardlinks.", ".dir", false); final SafeWriteRequestor requestor = new SafeWriteRequestor() { }; try { GeneralSettings.getInstance().setUseSafeWrite(false); final File targetFile = new File(dir, "targetFile"); assertTrue(targetFile.createNewFile()); final File hardLinkFile = IoTestUtil.createHardLink(targetFile.getAbsolutePath(), "hardLinkFile"); final VirtualFile file = myFS.refreshAndFindFileByIoFile(targetFile); assertNotNull(file); file.setBinaryContent("hello".getBytes(CharsetToolkit.UTF8_CHARSET), 0, 0, requestor); assertTrue(file.getLength() > 0); final VirtualFile check = myFS.refreshAndFindFileByIoFile(hardLinkFile); assertNotNull(check); assertEquals(file.getLength(), check.getLength()); assertEquals("hello", VfsUtilCore.loadText(check)); } finally { GeneralSettings.getInstance().setUseSafeWrite(safeWrite); FileUtil.delete(dir); } }
Example 14
Source File: TempDirTestFixtureImpl.java From consulo with Apache License 2.0 | 5 votes |
protected File createTempDirectory() { try { if (myTempDir == null) { File th = getTempHome(); myTempDir = th != null ? FileUtil.createTempDirectory(th, "unitTest", null,false) : FileUtil.createTempDirectory("unitTest", null,false); myFilesToDelete.add(myTempDir); } return myTempDir; } catch (IOException e) { throw new RuntimeException("Cannot create temp dir", e); } }
Example 15
Source File: TempFiles.java From consulo with Apache License 2.0 | 5 votes |
private File createTempDir(@Nonnull String prefix) { try { File dir = FileUtil.createTempDirectory(prefix, "test",false); tempFileCreated(dir); getVFileByFile(dir); return dir; } catch (IOException e) { throw new RuntimeException(e); } }
Example 16
Source File: MockApplicationTestCase.java From consulo with Apache License 2.0 | 5 votes |
public File getTempDir() throws IOException { if (myTempDir == null) { myTempDir = FileUtil.createTempDirectory(getName(), getClass().getName(), false); } return myTempDir; }
Example 17
Source File: GaugeWebBrowserPreview.java From Intellij-Plugin with Apache License 2.0 | 4 votes |
private static File createOrGetTempDirectory(String projectName) throws IOException { if (tempDirectory == null) tempDirectory = FileUtil.createTempDirectory(projectName, null, true); return tempDirectory; }
Example 18
Source File: VueModuleBuilder.java From vue-for-idea with BSD 3-Clause "New" or "Revised" License | 4 votes |
protected static File createTemp() throws IOException { return FileUtil.createTempDirectory("intellij-vue-generator", null, false); }
Example 19
Source File: LockSupportTest.java From consulo with Apache License 2.0 | 4 votes |
@Before public void setUp() throws IOException { myTempDir = FileUtil.createTempDirectory("LockSupportTest.", ".tmp", false); }