Java Code Examples for com.intellij.openapi.vcs.FilePath#getVirtualFile()
The following examples show how to use
com.intellij.openapi.vcs.FilePath#getVirtualFile() .
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: VirtualFileListCellRenderer.java From consulo with Apache License 2.0 | 6 votes |
protected FileStatus getStatus(Object value, FilePath path) { final FileStatus fileStatus; if (value instanceof Change) { fileStatus = ((Change) value).getFileStatus(); } else { final VirtualFile virtualFile = path.getVirtualFile(); if (virtualFile != null) { fileStatus = myFileStatusManager.getStatus(virtualFile); } else { fileStatus = FileStatus.NOT_CHANGED; } } return fileStatus; }
Example 2
Source File: ChangelistConflictTracker.java From consulo with Apache License 2.0 | 6 votes |
private void clearChanges(Collection<Change> changes) { for (Change change : changes) { ContentRevision revision = change.getAfterRevision(); if (revision != null) { FilePath filePath = revision.getFile(); String path = filePath.getPath(); final Conflict wasRemoved = myConflicts.remove(path); final VirtualFile file = filePath.getVirtualFile(); if (wasRemoved != null && file != null) { myEditorNotifications.updateNotifications(file); // we need to update status myFileStatusManager.fileStatusChanged(file); } } } }
Example 3
Source File: IgnoreFiles.java From p4ic4idea with Apache License 2.0 | 6 votes |
private boolean isMatch(@NotNull final FilePath file, @Nullable final VirtualFile ignoreFile) { LOG.debug("Checking ignore status on " + file + " against ignore file " + ignoreFile); if (ignoreFile == null || ignoreFile.isDirectory()) { return false; } VirtualFile vf = file.getVirtualFile(); if (vf == null) { return false; } // TODO look at caching these ignore file results. // It would mean needing to be aware of file reload events, though. try { final IgnoreFileSet patterns = IgnoreFileSet.create(ignoreFile); return patterns.isCoveredByIgnoreFile(vf) && patterns.isIgnored(vf); } catch (IOException e) { // problem reading; assume it's not ignored LOG.info(e); return false; } }
Example 4
Source File: ContentRevisionCache.java From consulo with Apache License 2.0 | 5 votes |
private static String bytesToString(FilePath path, @Nonnull byte[] bytes) { Charset charset = null; if (path.getVirtualFile() != null) { charset = path.getVirtualFile().getCharset(); } if (charset != null) { int bomLength = CharsetToolkit.getBOMLength(bytes, charset); final CharBuffer charBuffer = charset.decode(ByteBuffer.wrap(bytes, bomLength, bytes.length - bomLength)); return charBuffer.toString(); } return CharsetToolkit.bytesToString(bytes, EncodingRegistry.getInstance().getDefaultCharset()); }
Example 5
Source File: ChangesBrowserChangeNode.java From consulo with Apache License 2.0 | 5 votes |
@Override public void render(@Nonnull ChangesBrowserNodeRenderer renderer, boolean selected, boolean expanded, boolean hasFocus) { Change change = getUserObject(); FilePath filePath = ChangesUtil.getFilePath(change); VirtualFile file = filePath.getVirtualFile(); if (myDecorator != null) { myDecorator.preDecorate(change, renderer, renderer.isShowFlatten()); } renderer.appendFileName(file, filePath.getName(), change.getFileStatus().getColor()); String originText = change.getOriginText(myProject); if (originText != null) { renderer.append(spaceAndThinSpace() + originText, SimpleTextAttributes.REGULAR_ATTRIBUTES); } if (renderer.isShowFlatten()) { FilePath parentPath = filePath.getParentPath(); if (parentPath != null) { renderer.append(spaceAndThinSpace() + FileUtil.getLocationRelativeToUserHome(parentPath.getPath()), SimpleTextAttributes.GRAYED_ATTRIBUTES); } appendSwitched(renderer, file); } else if (getFileCount() != 1 || getDirectoryCount() != 0) { appendSwitched(renderer, file); appendCount(renderer); } else { appendSwitched(renderer, file); } renderer.setIcon(getIcon(change, filePath)); if (myDecorator != null) { myDecorator.decorate(change, renderer, renderer.isShowFlatten()); } }
Example 6
Source File: TreeModelBuilder.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private static StaticFilePath staticFrom(@Nonnull FilePath fp) { final String path = fp.getPath(); if (fp.isNonLocal() && (!FileUtil.isAbsolute(path) || VcsUtil.isPathRemote(path))) { return new StaticFilePath(fp.isDirectory(), fp.getIOFile().getPath().replace('\\', '/'), fp.getVirtualFile()); } return new StaticFilePath(fp.isDirectory(), new File(fp.getIOFile().getPath().replace('\\', '/')).getAbsolutePath(), fp.getVirtualFile()); }
Example 7
Source File: MoveChangesToAnotherListAction.java From consulo with Apache License 2.0 | 5 votes |
private static void addAllChangesUnderPath(@Nonnull ChangeListManager changeListManager, @Nonnull FilePath file, @Nonnull List<Change> changes, @Nonnull List<VirtualFile> changedFiles) { for (Change change : changeListManager.getChangesIn(file)) { changes.add(change); FilePath path = ChangesUtil.getAfterPath(change); if (path != null && path.getVirtualFile() != null) { changedFiles.add(path.getVirtualFile()); } } }
Example 8
Source File: VcsHistoryUtil.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private static DiffContent createContent(@Nonnull Project project, @Nonnull byte[] content, @Nonnull VcsFileRevision revision, @Nonnull FilePath filePath) throws IOException { DiffContentFactoryEx contentFactory = DiffContentFactoryEx.getInstanceEx(); if (isCurrent(revision)) { VirtualFile file = filePath.getVirtualFile(); if (file != null) return contentFactory.create(project, file); } if (isEmpty(revision)) { return contentFactory.createEmpty(); } return contentFactory.createFromBytes(project, content, filePath); }
Example 9
Source File: VcsDirtyScopeImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override public boolean isRecursivelyDirty(final VirtualFile vf) { for (THashSet<FilePath> dirsByRoot : myDirtyDirectoriesRecursively.values()) { for (FilePath dir : dirsByRoot) { final VirtualFile dirVf = dir.getVirtualFile(); if (dirVf != null) { if (VfsUtilCore.isAncestor(dirVf, vf, false)) { return true; } } } } return false; }
Example 10
Source File: ChangesUtil.java From consulo with Apache License 2.0 | 5 votes |
@Nullable public static VirtualFile findValidParentAccurately(@Nonnull FilePath filePath) { VirtualFile result = filePath.getVirtualFile(); if (result == null && !ApplicationManager.getApplication().isReadAccessAllowed()) { result = LocalFileSystem.getInstance().refreshAndFindFileByPath(filePath.getPath()); } if (result == null) { result = getValidParentUnderReadAction(filePath); } return result; }
Example 11
Source File: ChangelistBuilderStatusVisitor.java From azure-devops-intellij with MIT License | 5 votes |
public void unversioned(final @NotNull FilePath localPath, final boolean localItemExists, final @NotNull ServerStatus serverStatus) { if (localItemExists) { final VirtualFile filePath = localPath.getVirtualFile(); if (filePath == null) { // for files that were deleted w/o using the VCS changelistBuilder.processLocallyDeletedFile(localPath); } else { changelistBuilder.processUnversionedFile(filePath); } } }
Example 12
Source File: IgnoreFiles.java From p4ic4idea with Apache License 2.0 | 5 votes |
public boolean isFileIgnored(@Nullable final FilePath file) { if (file == null || file.getVirtualFile() == null) { return true; } final VirtualFile ignoreFile = getIgnoreFileForPath(file.getVirtualFile()); return isMatch(file, ignoreFile); }
Example 13
Source File: P4ChangeProvider.java From p4ic4idea with Apache License 2.0 | 5 votes |
private void markIgnored(Set<FilePath> dirtyFiles, ChangelistBuilder builder) { for (FilePath dirtyFile : dirtyFiles) { if (dirtyFile.getVirtualFile() == null || !dirtyFile.getVirtualFile().exists()) { if (LOG.isDebugEnabled()) { LOG.debug("Marking " + dirtyFile + " as locally deleted"); } builder.processLocallyDeletedFile(dirtyFile); } else { if (LOG.isDebugEnabled()) { LOG.debug("Marking " + dirtyFile + " as not versioned"); } // TODO include the IgnoreFileSet // TODO if these files aren't in P4, then they are locally edited but not // marked so by the server. In that case, they are Unversioned. If they // are in Perforce, then they are locally edited. // TODO unversioned files should be susceptible to the P4IGNORE settings. // This is deprecated in >v193, which introduced the new method // that takes a FilePath. Earlier versions don't have that // method. builder.processUnversionedFile(dirtyFile.getVirtualFile()); } } }
Example 14
Source File: P4ChangeProvider.java From p4ic4idea with Apache License 2.0 | 5 votes |
/** * Just the list of files are dirty. If additional files are checked out * on the server, but they aren't marked as dirty, then make a call to mark * them as dirty. * @param config config * @param files cached files * @param builder builds changelists */ private void updateFileCache(ClientConfig config, Set<FilePath> dirty, IdeChangelistMap changes, IdeFileMap files, ChangelistBuilder builder) { List<P4LocalFile> localFiles = new ArrayList<>(dirty.size()); for (FilePath filePath : dirty) { P4LocalFile local = files.forIdeFile(filePath); if (local == null) { if (filePath.getVirtualFile() == null || !filePath.getVirtualFile().exists()) { if (LOG.isDebugEnabled()) { LOG.debug("Marking " + filePath + " as locally deleted"); } builder.processLocallyDeletedFile(filePath); } else if (UserProjectPreferences.getAutoCheckoutModifiedFiles(project)) { if (LOG.isDebugEnabled()) { LOG.debug("Scheduling " + filePath + " for edit and marking it as modified without checkout"); } vcs.getCheckinEnvironment().scheduleUnversionedFilesForAddition( Collections.singletonList(filePath.getVirtualFile())); builder.processModifiedWithoutCheckout(filePath.getVirtualFile()); } else { if (LOG.isDebugEnabled()) { LOG.debug("Marking " + filePath + " as modified without checkout"); } builder.processModifiedWithoutCheckout(filePath.getVirtualFile()); } } else { localFiles.add(local); } } updateLocalFileCache(config, localFiles, changes, builder); }
Example 15
Source File: TodoCheckinHandlerWorker.java From consulo with Apache License 2.0 | 5 votes |
@Nullable private static VirtualFile getFileWithRefresh(@Nonnull FilePath filePath) { VirtualFile file = filePath.getVirtualFile(); if (file == null) { file = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(filePath.getIOFile()); } return file; }
Example 16
Source File: TFSCommittedChangesProvider.java From azure-devops-intellij with MIT License | 5 votes |
@Override @Nullable public RepositoryLocation getLocationFor(final FilePath root) { if (!TFVCUtil.isFileUnderTFVCMapping(project, root)) { return null; } final Workspace workspace = CommandUtils.getPartialWorkspace(project); return new TFSRepositoryLocation(workspace, root.getVirtualFile()); }
Example 17
Source File: ChangeForDiffConvertor.java From consulo with Apache License 2.0 | 4 votes |
public DiffRequestPresentable convert(final Change ch, final boolean forceText) { if (ch.hasOtherLayers() && myRecursive) { return new MultipleDiffRequestPresentable(myProject, ch); } if (ChangesUtil.isTextConflictingChange(ch)) { final AbstractVcs vcs = ChangesUtil.getVcsForChange(ch, myProject); final MergeProvider mergeProvider = vcs.getMergeProvider(); if (mergeProvider == null) return null; final FilePath path = ChangesUtil.getFilePath(ch); VirtualFile vf = path.getVirtualFile(); if (vf == null) { path.hardRefresh(); vf = path.getVirtualFile(); } if (vf == null) return null; return new ConflictedDiffRequestPresentable(myProject, vf, ch); } else { if (forceText) { if (ch.getBeforeRevision() != null && ch.getAfterRevision() != null) { try { if (StringUtil.isEmptyOrSpaces(ch.getBeforeRevision().getContent()) && StringUtil.isEmptyOrSpaces(ch.getAfterRevision().getContent())) { return null; } if (StringUtil.equals(ch.getBeforeRevision().getContent(), ch.getAfterRevision().getContent())) { return null; } } catch (VcsException e) { // } } } final ChangeDiffRequestPresentable presentable = new ChangeDiffRequestPresentable(myProject, ch); if (forceText) { presentable.setIgnoreDirectoryFlag(true); } return presentable; } }
Example 18
Source File: TfsFileUtil.java From azure-devops-intellij with MIT License | 4 votes |
public static boolean localItemExists(FilePath localPath) { VirtualFile file = localPath.getVirtualFile(); return file != null && file.isValid() && file.exists(); }
Example 19
Source File: TfsFileUtil.java From azure-devops-intellij with MIT License | 4 votes |
public static boolean isFileWritable(FilePath localPath) { VirtualFile file = localPath.getVirtualFile(); return file.isWritable() && !file.isDirectory(); }
Example 20
Source File: TFSChangeProvider.java From azure-devops-intellij with MIT License | 4 votes |
public void getChanges(@NotNull final VcsDirtyScope dirtyScope, @NotNull final ChangelistBuilder builder, @NotNull final ProgressIndicator progress, @NotNull final ChangeListManagerGate addGate) { Project project = myVcs.getProject(); if (project.isDisposed()) { return; } progress.setText("Processing changes"); // process only roots, filter out child items since requests are recursive anyway RootsCollection.FilePathRootsCollection roots = new RootsCollection.FilePathRootsCollection(); roots.addAll(dirtyScope.getRecursivelyDirtyDirectories()); final ChangeListManager changeListManager = ChangeListManager.getInstance(project); for (FilePath dirtyFile : dirtyScope.getDirtyFiles()) { // workaround for IDEADEV-31511 and IDEADEV-31721 if (dirtyFile.getVirtualFile() == null || !changeListManager.isIgnoredFile(dirtyFile.getVirtualFile())) { roots.add(dirtyFile); } } if (roots.isEmpty()) { return; } final List<String> pathsToProcess = TFVCUtil.filterValidTFVCPaths(project, roots); if (pathsToProcess.isEmpty()) { return; } List<PendingChange> changes; try { ServerContext serverContext = myVcs.getServerContext(true); changes = TfvcClient.getInstance(project).getStatusForFiles(serverContext, pathsToProcess); } catch (final Throwable t) { logger.error("Failed to get changes from command line. roots=" + StringUtils.join(pathsToProcess, ", "), t); changes = Collections.emptyList(); } // for each change, find out the status of the changes and then add to the list final ChangelistBuilderStatusVisitor changelistBuilderStatusVisitor = new ChangelistBuilderStatusVisitor(project, builder); for (final PendingChange change : changes) { StatusProvider.visitByStatus(changelistBuilderStatusVisitor, change); } }