Java Code Examples for com.intellij.openapi.vcs.FilePath#getPath()

The following examples show how to use com.intellij.openapi.vcs.FilePath#getPath() . 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: AnnotateRevisionAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
protected VirtualFile getFile(@Nonnull AnActionEvent e) {
  VcsFileRevision revision = getFileRevision(e);
  if (revision == null) return null;

  final FileType currentFileType = myAnnotation.getFile().getFileType();
  FilePath filePath = (revision instanceof VcsFileRevisionEx ? ((VcsFileRevisionEx)revision).getPath() : VcsUtil.getFilePath(myAnnotation.getFile()));
  return new VcsVirtualFile(filePath.getPath(), revision, VcsFileSystem.getInstance()) {
    @Nonnull
    @Override
    public FileType getFileType() {
      FileType type = super.getFileType();
      if (!type.isBinary()) return type;
      if (!currentFileType.isBinary()) return currentFileType;
      return PlainTextFileType.INSTANCE;
    }
  };
}
 
Example 2
Source File: ChangelistConflictTracker.java    From consulo with Apache License 2.0 6 votes vote down vote up
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: TFSContentRevision.java    From azure-devops-intellij with MIT License 5 votes vote down vote up
public static TFSContentRevision create(final Project project,
                                        final @NotNull FilePath localPath,
                                        final int changeset,
                                        final String modificationDate) {
    return new TFSContentRevision(project) {

        public int getChangeset() {
            return changeset;
        }

        @NotNull
        public FilePath getFile() {
            return localPath;
        }

        protected String getFilePath() {
            return localPath.getPath();
        }

        public String getModificationDate() {
            return modificationDate;
        }

        @NotNull
        public VcsRevisionNumber getRevisionNumber() {
            return new TfsRevisionNumber(changeset, localPath.getName(), modificationDate);
        }
    };
}
 
Example 4
Source File: ResolveConflictHelper.java    From azure-devops-intellij with MIT License 5 votes vote down vote up
/**
 * Process a content conflict specifically
 *
 * @param context
 * @param model
 * @param contentTriplet
 * @param localPath
 * @throws VcsException
 */
@VisibleForTesting
protected void processContentConflict(final ServerContext context, final ResolveConflictsModel model,
                                      final ContentTriplet contentTriplet, final FilePath localPath,
                                      final NameMergerResolution nameMergerResolution) throws VcsException {
    boolean resolved = true;
    if (contentTriplet != null) {
        final File localFile = new File(localPath.getPath());
        ArgumentHelper.checkIfFile(localFile);
        VirtualFile vFile = VcsUtil.getVirtualFileWithRefresh(localFile);
        if (vFile != null) {
            try {
                TfsFileUtil.setReadOnly(vFile, false);
                // opens dialog for merge
                resolved = ConflictsEnvironment.getContentMerger()
                        .mergeContent(contentTriplet, project, vFile, null);
            } catch (IOException e) {
                throw new VcsException(e);
            }
        } else {
            throw new VcsException(TfPluginBundle.message(TfPluginBundle.KEY_TFVC_CONFLICT_MERGE_LOAD_FAILED, localPath.getPresentableUrl()));
        }
    }

    if (resolved) {
        resolveConflictWithProgress(localPath.getPath(), ResolveConflictsCommand.AutoResolveType.KeepYours, context, model, true, nameMergerResolution);
    } else {
        logger.warn("Conflict merge was aborted by user");
    }
}
 
Example 5
Source File: TreeModelBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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 6
Source File: ChangesBrowserFilePathNode.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static String getRelativePath(@javax.annotation.Nullable FilePath parent, @Nonnull FilePath child) {
  boolean isLocal = !child.isNonLocal();
  boolean caseSensitive = isLocal && SystemInfoRt.isFileSystemCaseSensitive;
  String result = parent != null ? FileUtil.getRelativePath(parent.getPath(), child.getPath(), '/', caseSensitive) : null;

  result = result == null ? child.getPath() : result;

  return isLocal ? FileUtil.toSystemDependentName(result) : result;
}
 
Example 7
Source File: TFVCUtil.java    From azure-devops-intellij with MIT License 4 votes vote down vote up
/**
 * Determines whether the file is in the TFVC service directory ($tf or .tf).
 */
public static boolean isInServiceDirectory(FilePath filePath) {
    String path = filePath.getPath();
    return StringUtils.containsIgnoreCase(path, "$tf")
            || StringUtils.containsIgnoreCase(path, ".tf");
}
 
Example 8
Source File: IdeaTextPatchBuilder.java    From consulo with Apache License 2.0 4 votes vote down vote up
@javax.annotation.Nullable
private static AirContentRevision convertRevisionToAir(final ContentRevision cr, final Long ts) {
  if (cr == null) return null;
  final FilePath fp = cr.getFile();
  final StaticPathDescription description = new StaticPathDescription(fp.isDirectory(),
                                                                      ts == null ? fp.getIOFile().lastModified() : ts, fp.getPath());
  if (cr instanceof BinaryContentRevision) {
    return new AirContentRevision() {
      @Override
      public boolean isBinary() {
        return true;
      }
      @Override
      public String getContentAsString() {
        throw new IllegalStateException();
      }
      @Override
      public byte[] getContentAsBytes() throws VcsException {
        return ((BinaryContentRevision) cr).getBinaryContent();
      }
      @Override
      public String getRevisionNumber() {
        return ts != null ? null : cr.getRevisionNumber().asString();
      }
      @Override
      @Nonnull
      public PathDescription getPath() {
        return description;
      }

      @Override
      public Charset getCharset() {
        return null;
      }
    };
  } else {
    return new AirContentRevision() {
      @Override
      public boolean isBinary() {
        return false;
      }
      @Override
      public String getContentAsString() throws VcsException {
        return cr.getContent();
      }
      @Override
      public byte[] getContentAsBytes() throws VcsException {
        throw new IllegalStateException();
      }
      @Override
      public String getRevisionNumber() {
        return ts != null ? null : cr.getRevisionNumber().asString();
      }
      @Override
      @Nonnull
      public PathDescription getPath() {
        return description;
      }

      @Override
      public Charset getCharset() {
        return fp.getCharset();
      }
    };
  }
}