Java Code Examples for com.intellij.openapi.util.io.FileUtil#createIfDoesntExist()
The following examples show how to use
com.intellij.openapi.util.io.FileUtil#createIfDoesntExist() .
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: Utils.java From KodeBeagle with Apache License 2.0 | 6 votes |
@NotNull public String createFileWithContents(final String displayFileName, final String contents, final String baseDir, final String digest) throws IOException { final String fileParentPath = String.format("%s%c%s", baseDir, File.separatorChar, digest); final File parentDir = new File(fileParentPath); FileUtil.createDirectory(parentDir); parentDir.deleteOnExit(); final String fullFilePath = String.format("%s%c%s", parentDir.getAbsolutePath(), File.separatorChar, displayFileName); final File file = new File(fullFilePath); if (!file.exists()) { FileUtil.createIfDoesntExist(file); forceWrite(contents, file); file.deleteOnExit(); } return fullFilePath; }
Example 2
Source File: TranslatingCompilerFilesMonitorImpl.java From consulo with Apache License 2.0 | 6 votes |
@Override public void suspendProject(Project project) { final int projectId = getProjectId(project); synchronized (myDataLock) { if (!mySuspendedProjects.add(projectId)) { return; } FileUtil.createIfDoesntExist(CompilerPaths.getRebuildMarkerFile(project)); // cleanup internal structures to free memory mySourcesToRecompile.remove(projectId); myOutputsToDelete.remove(projectId); myGeneratedDataPaths.remove(project); TranslationCompilerProjectMonitor.getInstance(project).removeCompileOutputInfoFile(); } }
Example 3
Source File: CompileDriver.java From consulo with Apache License 2.0 | 6 votes |
private void writeStatus(CompileStatus status, CompileContext context) { final File statusFile = new File(myCachesDirectoryPath, VERSION_FILE_NAME); final File lockFile = getLockFile(); try { FileUtil.createIfDoesntExist(statusFile); DataOutputStream out = new DataOutputStream(new FileOutputStream(statusFile)); try { out.writeInt(status.CACHE_FORMAT_VERSION); out.writeLong(status.VFS_CREATION_STAMP); } finally { out.close(); } if (status.COMPILATION_IN_PROGRESS) { FileUtil.createIfDoesntExist(lockFile); } else { deleteFile(lockFile); } } catch (IOException e) { context.addMessage(CompilerMessageCategory.ERROR, CompilerBundle.message("compiler.error.exception", e.getMessage()), null, -1, -1); } }
Example 4
Source File: LocalFileStorage.java From consulo with Apache License 2.0 | 6 votes |
public File createLocalFile(@Nonnull String url) throws IOException { int ast = url.indexOf('?'); if (ast != -1) { url = url.substring(0, ast); } int last = url.lastIndexOf('/'); String baseName; if (last == url.length() - 1) { baseName = url.substring(url.lastIndexOf('/', last-1) + 1, last); } else { baseName = url.substring(last + 1); } int index = baseName.lastIndexOf('.'); String prefix = index == -1 ? baseName : baseName.substring(0, index); String suffix = index == -1 ? "" : baseName.substring(index+1); prefix = PathUtil.suggestFileName(prefix); suffix = PathUtil.suggestFileName(suffix); File file = FileUtil.findSequentNonexistentFile(myStorageIODirectory, prefix, suffix); FileUtil.createIfDoesntExist(file); return file; }
Example 5
Source File: PlatformTestCase.java From consulo with Apache License 2.0 | 5 votes |
protected static Module doCreateRealModuleIn(final String moduleName, final Project project) { final VirtualFile baseDir = project.getBaseDir(); assertNotNull(baseDir); final File moduleFile = new File(baseDir.getPath().replace('/', File.separatorChar), moduleName); FileUtil.createIfDoesntExist(moduleFile); myFilesToDelete.add(moduleFile); return WriteAction.compute(() -> { final VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(moduleFile); Module module = ModuleManager.getInstance(project).newModule(moduleName, virtualFile.getPath()); module.getModuleDir(); return module; }); }
Example 6
Source File: VcsLogCachesInvalidator.java From consulo with Apache License 2.0 | 5 votes |
public synchronized boolean isValid() { if (PersistentUtil.getCorruptionMarkerFile().exists()) { boolean deleted = FileUtil.deleteWithRenaming(PersistentUtil.LOG_CACHE); if (!deleted) { // if could not delete caches, ensure that corruption marker is still there FileUtil.createIfDoesntExist(PersistentUtil.getCorruptionMarkerFile()); } else { LOG.debug("Deleted VCS Log caches at " + PersistentUtil.LOG_CACHE); } return deleted; } return true; }
Example 7
Source File: VcsLogCachesInvalidator.java From consulo with Apache License 2.0 | 5 votes |
@Override public void invalidateCaches() { if (PersistentUtil.LOG_CACHE.exists()) { String[] children = PersistentUtil.LOG_CACHE.list(); if (!ArrayUtil.isEmpty(children)) { FileUtil.createIfDoesntExist(PersistentUtil.getCorruptionMarkerFile()); } } }
Example 8
Source File: FSRecords.java From consulo with Apache License 2.0 | 5 votes |
private static void invalidateIndex(@Nonnull String reason) { LOG.info("Marking VFS as corrupted: " + reason); final File indexRoot = ContainerPathManager.get().getIndexRoot(); if (indexRoot.exists()) { final String[] children = indexRoot.list(); if (children != null && children.length > 0) { // create index corruption marker only if index directory exists and is non-empty // It is incorrect to consider non-existing indices "corrupted" FileUtil.createIfDoesntExist(new File(ContainerPathManager.get().getIndexRoot(), "corruption.marker")); } } }
Example 9
Source File: UpdateBreakpointsAfterRenameTest.java From consulo with Apache License 2.0 | 5 votes |
private VirtualFile createFile(String path) { final File ioFile = new File(myTempFiles.createTempDir(), FileUtil.toSystemDependentName(path)); FileUtil.createIfDoesntExist(ioFile); final VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(ioFile); assertNotNull(virtualFile); return virtualFile; }
Example 10
Source File: PackageFileWorker.java From consulo with Apache License 2.0 | 4 votes |
private static JBZipFile getOrCreateZipFile(File archiveFile) throws IOException { FileUtil.createIfDoesntExist(archiveFile); return new JBZipFile(archiveFile); }
Example 11
Source File: AbstractStorage.java From consulo with Apache License 2.0 | 4 votes |
private void tryInit(String storageFilePath, PagePool pool, int retryCount) throws IOException { convertFromOldExtensions(storageFilePath); final File recordsFile = new File(storageFilePath + INDEX_EXTENSION); final File dataFile = new File(storageFilePath + DATA_EXTENSION); if (recordsFile.exists() != dataFile.exists()) { deleteFiles(storageFilePath); } FileUtil.createIfDoesntExist(recordsFile); FileUtil.createIfDoesntExist(dataFile); AbstractRecordsTable recordsTable = null; DataTable dataTable; try { recordsTable = createRecordsTable(pool, recordsFile); dataTable = new DataTable(dataFile, pool); } catch (IOException e) { LOG.info(e.getMessage()); if (recordsTable != null) { recordsTable.dispose(); } boolean deleted = deleteFiles(storageFilePath); if (!deleted) { throw new IOException("Can't delete caches at: " + storageFilePath); } if (retryCount >= 5) { throw new IOException("Can't create storage at: " + storageFilePath); } tryInit(storageFilePath, pool, retryCount+1); return; } myRecordsTable = recordsTable; myDataTable = dataTable; myPool = pool; if (myDataTable.isCompactNecessary()) { compact(storageFilePath); } }