com.intellij.openapi.vcs.changes.ContentRevision Java Examples

The following examples show how to use com.intellij.openapi.vcs.changes.ContentRevision. 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: ModuleVcsPathPresenter.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public String getPresentableRelativePath(@Nonnull final ContentRevision fromRevision, @Nonnull final ContentRevision toRevision) {
  // need to use parent path because the old file is already not there
  FilePath fromPath = fromRevision.getFile();
  FilePath toPath = toRevision.getFile();

  if ((fromPath.getParentPath() == null) || (toPath.getParentPath() == null)) {
    return null;
  }

  final VirtualFile oldFile = fromPath.getParentPath().getVirtualFile();
  final VirtualFile newFile = toPath.getParentPath().getVirtualFile();
  if (oldFile != null && newFile != null) {
    Module oldModule = ModuleUtilCore.findModuleForFile(oldFile, myProject);
    Module newModule = ModuleUtilCore.findModuleForFile(newFile, myProject);
    if (oldModule != newModule) {
      return getPresentableRelativePathFor(oldFile);
    }
  }
  final RelativePathCalculator calculator =
          new RelativePathCalculator(toPath.getIOFile().getAbsolutePath(), fromPath.getIOFile().getAbsolutePath());
  calculator.execute();
  final String result = calculator.getResult();
  return (result == null) ? null : result.replace("/", File.separator);
}
 
Example #2
Source File: TFSRollbackEnvironmentTest.java    From azure-devops-intellij with MIT License 6 votes vote down vote up
private void setupRollbackChanges() {
    Change change1 = mock(Change.class);
    Change change2 = mock(Change.class);
    Change change3 = mock(Change.class);
    changes = ImmutableList.of(change1, change2, change3);
    ContentRevision contentRevision1 = mock(ContentRevision.class);
    ContentRevision contentRevision2 = mock(ContentRevision.class);
    ContentRevision contentRevision3 = mock(ContentRevision.class);

    when(change1.getType()).thenReturn(Change.Type.DELETED);
    when(change2.getType()).thenReturn(Change.Type.MODIFICATION);
    when(change3.getType()).thenReturn(Change.Type.NEW);

    when(contentRevision1.getFile()).thenReturn(filePath1);
    when(contentRevision2.getFile()).thenReturn(filePath2);
    when(contentRevision3.getFile()).thenReturn(filePath3);

    when(change1.getBeforeRevision()).thenReturn(contentRevision1);
    when(change2.getAfterRevision()).thenReturn(contentRevision2);
    when(change3.getAfterRevision()).thenReturn(contentRevision3);
}
 
Example #3
Source File: ReviewDiffRequest.java    From review-board-idea-plugin with Apache License 2.0 6 votes vote down vote up
@NotNull
@Override
public DiffContent[] getContents() {
    try {
        ContentRevision beforeRevision = selectedChange.getBeforeRevision();
        ContentRevision afterRevision = selectedChange.getAfterRevision();
        FileType srcFileType = FileTypeRegistry.getInstance()
                .getFileTypeByFileName(beforeRevision.getFile().getName());
        FileType dstFileType = FileTypeRegistry.getInstance()
                .getFileTypeByFileName(afterRevision.getFile().getName());

        return new DiffContent[]{
                new SimpleContent(defaultString(beforeRevision.getContent()), srcFileType),
                new SimpleContent(defaultString(afterRevision.getContent()), dstFileType)
        };
    } catch (Exception e1) {
        throw new RuntimeException(e1);
    }
}
 
Example #4
Source File: CommittedChangesTreeBrowser.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void addOrReplaceChange(final List<Change> changes, final Change c) {
  final ContentRevision beforeRev = c.getBeforeRevision();
  // todo!!! further improvements needed
  if (beforeRev != null) {
    final String beforeName = beforeRev.getFile().getName();
    final String beforeAbsolutePath = beforeRev.getFile().getIOFile().getAbsolutePath();
    for (Change oldChange : changes) {
      ContentRevision rev = oldChange.getAfterRevision();
      // first compare name, which is many times faster - to remove 99% not matching
      if (rev != null && (rev.getFile().getName().equals(beforeName)) && rev.getFile().getIOFile().getAbsolutePath().equals(beforeAbsolutePath)) {
        changes.remove(oldChange);
        if (oldChange.getBeforeRevision() != null || c.getAfterRevision() != null) {
          changes.add(new Change(oldChange.getBeforeRevision(), c.getAfterRevision()));
        }
        return;
      }
    }
  }
  changes.add(c);
}
 
Example #5
Source File: VcsLogStructureFilterImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public boolean matches(@Nonnull VcsCommitMetadata details) {
  if ((details instanceof VcsFullCommitDetails)) {
    for (Change change : ((VcsFullCommitDetails)details).getChanges()) {
      ContentRevision before = change.getBeforeRevision();
      if (before != null && matches(before.getFile().getPath())) {
        return true;
      }
      ContentRevision after = change.getAfterRevision();
      if (after != null && matches(after.getFile().getPath())) {
        return true;
      }
    }
    return false;
  }
  else {
    return false;
  }
}
 
Example #6
Source File: CommentsDiffTool.java    From Crucible4IDEA with MIT License 6 votes vote down vote up
private static void addGutter(@NotNull Editor editor2,
                              @NotNull final Review review,
                              @NotNull FilePath filePath,
                              @Nullable final ContentRevision revision) {
  if (revision == null) return;

  for (Comment comment : review.getComments()) {
    final String id = comment.getReviewItemId();
    final String path = review.getPathById(id);
    if (path != null && filePath.getPath().endsWith(path) &&
        (review.isInPatch(comment) || revision.getRevisionNumber().asString().equals(comment.getRevision()))) {

      int line = Integer.parseInt(comment.getLine()) - 1;
      final RangeHighlighter highlighter = editor2.getMarkupModel().addLineHighlighter(line, HighlighterLayer.ERROR + 1, null);
      final ReviewGutterIconRenderer gutterIconRenderer = new ReviewGutterIconRenderer(review, filePath, comment);
      highlighter.setGutterIconRenderer(gutterIconRenderer);
    }
  }
}
 
Example #7
Source File: Difference.java    From consulo with Apache License 2.0 6 votes vote down vote up
private ContentRevision createContentRevision(final Entry e, final IdeaGateway gw) {
  if (e == null) return null;

  return new ContentRevision() {
    @Nullable
    public String getContent() throws VcsException {
      if (e.isDirectory()) return null;
      return e.getContent().getString(e, gw);
    }

    @Nonnull
    public FilePath getFile() {
      return new FilePathImpl(new File(e.getPath()), e.isDirectory());
    }

    @Nonnull
    public VcsRevisionNumber getRevisionNumber() {
      return VcsRevisionNumber.NULL;
    }
  };
}
 
Example #8
Source File: ApplyBinaryShelvedFilePatch.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected Result applyChange(Project project, final VirtualFile fileToPatch, FilePath pathBeforeRename, Getter<CharSequence> baseContents)
        throws IOException {
  try {
    ContentRevision contentRevision = myPatch.getShelvedBinaryFile().createChange(project).getAfterRevision();
    if (contentRevision != null) {
      assert (contentRevision instanceof ShelvedBinaryContentRevision);
      byte[] binaryContent = ((ShelvedBinaryContentRevision)contentRevision).getBinaryContent();
      //it may be new empty binary file
      fileToPatch.setBinaryContent(binaryContent != null ? binaryContent : ArrayUtil.EMPTY_BYTE_ARRAY);
    }
  }
  catch (VcsException e) {
    LOG.error("Couldn't apply shelved binary patch", e);
    return new Result(ApplyPatchStatus.FAILURE) {

      @Override
      public ApplyPatchForBaseRevisionTexts getMergeData() {
        return null;
      }
    };
  }
  return SUCCESS;
}
 
Example #9
Source File: VcsAwareFormatChangedTextUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@javax.annotation.Nullable
private static String getRevisionedContentFrom(@Nonnull Change change) {
  ContentRevision revision = change.getBeforeRevision();
  if (revision == null) {
    return null;
  }

  try {
    return revision.getContent();
  }
  catch (VcsException e) {
    LOG.error("Can't get content for: " + change.getVirtualFile(), e);
    return null;
  }
}
 
Example #10
Source File: PlatformVcsPathPresenter.java    From consulo with Apache License 2.0 5 votes vote down vote up
public String getPresentableRelativePath(final ContentRevision fromRevision, final ContentRevision toRevision) {
  FilePath fromPath = fromRevision.getFile();
  FilePath toPath = toRevision.getFile();

  final RelativePathCalculator calculator =
    new RelativePathCalculator(toPath.getIOFile().getAbsolutePath(), fromPath.getIOFile().getAbsolutePath());
  calculator.execute();
  final String result = calculator.getResult();
  return (result == null) ? null : result.replace("/", File.separator);
}
 
Example #11
Source File: VcsUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * @param change "Change" description.
 * @return Return true if the "Change" object is created for "Rename" operation:
 *         in this case name of files for "before" and "after" revisions must not
 *         coniside.
 */
public static boolean isRenameChange(Change change) {
  boolean isRenamed = false;
  ContentRevision before = change.getBeforeRevision();
  ContentRevision after = change.getAfterRevision();
  if (before != null && after != null) {
    String prevFile = getCanonicalLocalPath(before.getFile().getPath());
    String newFile = getCanonicalLocalPath(after.getFile().getPath());
    isRenamed = !prevFile.equals(newFile);
  }
  return isRenamed;
}
 
Example #12
Source File: AbstractFilePatchInProgress.java    From consulo with Apache License 2.0 5 votes vote down vote up
public PatchChange(ContentRevision beforeRevision, ContentRevision afterRevision, AbstractFilePatchInProgress patchInProgress) {
  super(beforeRevision, afterRevision,
        patchInProgress.isBaseExists() || FilePatchStatus.ADDED.equals(patchInProgress.getStatus())
        ? null
        : FileStatus.MERGED_WITH_CONFLICTS);
  myPatchInProgress = patchInProgress;
}
 
Example #13
Source File: BinaryFilePatchInProgress.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public ContentRevision getNewContentRevision() {
  if (FilePatchStatus.DELETED.equals(myStatus)) return null;

  if (myNewContentRevision != null) return myNewContentRevision;
  if (myPatch.getAfterFileName() != null) {
    final FilePath newFilePath = FilePatchStatus.ADDED.equals(myStatus) ? VcsUtil.getFilePath(myIoCurrentBase, false)
                                                                        : detectNewFilePathForMovedOrModified();
    myNewContentRevision = new ShelvedBinaryContentRevision(newFilePath, myPatch.getShelvedBinaryFile().SHELVED_PATH);
  }
  return myNewContentRevision;
}
 
Example #14
Source File: OpenRepositoryVersionAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean hasValidChanges(final Change[] changes) {
  for(Change c: changes) {
    final ContentRevision contentRevision = c.getAfterRevision();
    if (contentRevision != null && !contentRevision.getFile().isDirectory()) {
      return true;
    }
  }
  return false;
}
 
Example #15
Source File: ContentRevisionVirtualFile.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static ContentRevisionVirtualFile create(@Nonnull ContentRevision contentRevision) {
  synchronized(ourMap) {
    ContentRevisionVirtualFile revisionVirtualFile = ourMap.get(contentRevision);
    if (revisionVirtualFile == null) {
      revisionVirtualFile = new ContentRevisionVirtualFile(contentRevision);
      ourMap.put(contentRevision, revisionVirtualFile);
    }
    return revisionVirtualFile;
  }
}
 
Example #16
Source File: SelectFilesToAddTextsToPatchPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static Set<Change> getBig(List<Change> changes) {
  final Set<Change> exclude = new HashSet<>();
  for (Change change : changes) {
    // try to estimate size via VF: we assume that base content hasn't been changed much
    VirtualFile virtualFile = getVfFromChange(change);
    if (virtualFile != null) {
      if (isBig(virtualFile)) {
        exclude.add(change);
      }
      continue;
    }
    // otherwise, to avoid regression we have to process context length
    ContentRevision beforeRevision = change.getBeforeRevision();
    if (beforeRevision != null) {
      try {
        String content = beforeRevision.getContent();
        if (content == null) {
          final FilePath file = beforeRevision.getFile();
          LOG.info("null content for " + (file.getPath()) + ", is dir: " + (file.isDirectory()));
          continue;
        }
        if (content.length() > VcsConfiguration.ourMaximumFileForBaseRevisionSize) {
          exclude.add(change);
        }
      }
      catch (VcsException e) {
        LOG.info(e);
      }
    }
  }
  return exclude;
}
 
Example #17
Source File: SubmitModel.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
private List<OptionalClientServerConfig> getConfigsForChanges(Collection<Change> changes) {
    ProjectConfigRegistry registry = ProjectConfigRegistry.getInstance(project);
    if (registry == null) {
        return Collections.emptyList();
    }
    List<FilePath> files = new ArrayList<>(changes.size() * 2);
    for (Change change : changes) {
        ContentRevision before = change.getBeforeRevision();
        if (before != null) {
            files.add(before.getFile());
        }
        ContentRevision after = change.getAfterRevision();
        if (after != null) {
            files.add(after.getFile());
        }
    }
    // We only need the unique servers; multiples of the same server will result
    // in excessive job queries.  Instead, we'll find one of the clients associated
    // with each server.
    Map<P4ServerName, OptionalClientServerConfig> configs = new HashMap<>();
    for (FilePath file : files) {
        ClientConfigRoot config = registry.getClientFor(file);
        if (config != null && !configs.containsKey(config.getServerConfig().getServerName())) {
            configs.put(
                    config.getServerConfig().getServerName(),
                    new OptionalClientServerConfig(config.getClientConfig()));
        }
    }
    return new ArrayList<>(configs.values());
}
 
Example #18
Source File: P4ChangelistListener.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
private Collection<FilePath> getAffectedFiles(ClientConfigRoot clientConfigRoot, Collection<Change> changes) {
    Set<FilePath> ret = new HashSet<>();
    for (Change change : changes) {
        for (ContentRevision cr : Arrays.asList(change.getBeforeRevision(), change.getAfterRevision())) {
            if (cr != null) {
                FilePath file = cr.getFile();
                if (!ret.contains(file) && FileTreeUtil.isSameOrUnder(clientConfigRoot.getClientRootDir(), file)) {
                    ret.add(cr.getFile());
                }
            }
        }
    }
    return ret;
}
 
Example #19
Source File: TFSCheckinEnvironmentTest.java    From azure-devops-intellij with MIT License 5 votes vote down vote up
private void setupCommit() {
    Change change1 = mock(Change.class);
    Change change2 = mock(Change.class);
    Change change3 = mock(Change.class);
    ContentRevision contentRevision1 = mock(ContentRevision.class);
    ContentRevision contentRevision2 = mock(ContentRevision.class);
    ContentRevision contentRevision3 = mock(ContentRevision.class);
    changes = ImmutableList.of(change1, change2, change3);

    FilePath filePath1 = mock(FilePath.class);
    when(filePath1.getPath()).thenReturn("/path/to/file1");
    when(contentRevision1.getFile()).thenReturn(filePath1);

    FilePath filePath2 = mock(FilePath.class);
    when(filePath2.getPath()).thenReturn("/path/to/file2");
    when(contentRevision2.getFile()).thenReturn(filePath2);

    FilePath filePath3 = mock(FilePath.class);
    when(filePath3.getPath()).thenReturn("/path/to/file3");
    when(contentRevision3.getFile()).thenReturn(filePath3);

    when(change1.getBeforeRevision()).thenReturn(contentRevision1);
    when(change2.getBeforeRevision()).thenReturn(null);
    when(change3.getBeforeRevision()).thenReturn(null);
    when(change1.getAfterRevision()).thenReturn(null);
    when(change2.getAfterRevision()).thenReturn(contentRevision2);
    when(change3.getAfterRevision()).thenReturn(contentRevision3);
}
 
Example #20
Source File: TFSDiffProvider.java    From azure-devops-intellij with MIT License 5 votes vote down vote up
@Nullable
public ContentRevision createFileContent(final VcsRevisionNumber vcsRevisionNumber, final VirtualFile virtualFile) {
    if (VcsRevisionNumber.NULL.equals(vcsRevisionNumber)) {
        return null;
    } else {
        final FilePath path = TfsFileUtil.getFilePath(virtualFile);
        try {
            return TFSContentRevision.create(project, path, getChangeset(vcsRevisionNumber), getModificationDate(vcsRevisionNumber));
        } catch (Exception e) {
            logger.warn("Unable to create file content", e);
            AbstractVcsHelper.getInstance(project).showError(new VcsException(e), TFSVcs.TFVC_NAME);
            return null;
        }
    }
}
 
Example #21
Source File: TFSRollbackEnvironment.java    From azure-devops-intellij with MIT License 5 votes vote down vote up
public void rollbackChanges(final List<Change> changes,
                            final List<VcsException> vcsExceptions,
                            @NotNull final RollbackProgressListener listener) {
    logger.info("rollbackChanges started");
    final List<FilePath> localPaths = new ArrayList<FilePath>();

    listener.determinate();
    for (final Change change : changes) {
        final ContentRevision revision = change.getType() == Change.Type.DELETED ? change.getBeforeRevision() : change.getAfterRevision();
        localPaths.add(revision.getFile());
    }

    undoPendingChanges(localPaths, vcsExceptions, listener);
    logger.info("rollbackChanges ended");
}
 
Example #22
Source File: ChangelistBuilderStatusVisitor.java    From azure-devops-intellij with MIT License 5 votes vote down vote up
public void renamed(final @NotNull FilePath localPath, final boolean localItemExists, final @NotNull ServerStatus serverStatus) {
    if (localItemExists) {
        final ContentRevision before = getPreviousRenamedRevision(localPath, serverStatus.localVer);
        final ContentRevision after = CurrentContentRevision.create(localPath);
        changelistBuilder.processChange(new Change(before, after), TFSVcs.getKey());
    } else {
        changelistBuilder.processLocallyDeletedFile(localPath);
    }
}
 
Example #23
Source File: ChangelistBuilderStatusVisitor.java    From azure-devops-intellij with MIT License 5 votes vote down vote up
public void renamedCheckedOut(final @NotNull FilePath localPath, final boolean localItemExists, final @NotNull ServerStatus serverStatus) {
    if (localItemExists) {
        final ContentRevision before = getPreviousRenamedRevision(localPath, serverStatus.localVer);
        final ContentRevision after = CurrentContentRevision.create(localPath);
        changelistBuilder.processChange(new Change(before, after), TFSVcs.getKey());
    } else {
        changelistBuilder.processLocallyDeletedFile(localPath);
    }
}
 
Example #24
Source File: VcsDiffUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static List<Change> createChangesWithCurrentContentForFile(@Nonnull FilePath filePath,
                                                                  @Nullable ContentRevision beforeContentRevision) {
  return Collections.singletonList(new Change(beforeContentRevision, CurrentContentRevision.create(filePath)));
}
 
Example #25
Source File: ChangesTreeList.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static boolean seemsToBeMoved(Change change, VirtualFile toSelect) {
  ContentRevision afterRevision = change.getAfterRevision();
  if (afterRevision == null) return false;
  FilePath file = afterRevision.getFile();
  return FileUtil.pathsEqual(file.getPath(), toSelect.getPath());
}
 
Example #26
Source File: SelectFilesToAddTextsToPatchPanel.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
private static VirtualFile getVfFromChange(@Nonnull Change change) {
  ContentRevision after = change.getAfterRevision();
  return after != null ? after.getFile().getVirtualFile() : null;
}
 
Example #27
Source File: TFSCheckinEnvironment.java    From azure-devops-intellij with MIT License 4 votes vote down vote up
@Nullable
public List<VcsException> commit(final List<Change> changes,
                                 final String preparedComment,
                                 @NotNull NullableFunction<Object, Object> parametersHolder, Set<String> feedback) {
    final List<VcsException> errors = new ArrayList<VcsException>();

    // set progress bar status
    final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
    TFSProgressUtil.setProgressText(progressIndicator, TfPluginBundle.message(TfPluginBundle.KEY_TFVC_CHECKIN_STATUS));

    // find files that are to be checked in
    final List<String> files = new ArrayList<String>();
    for (final Change change : changes) {
        String path = null;
        final ContentRevision beforeRevision = change.getBeforeRevision();
        final ContentRevision afterRevision = change.getAfterRevision();
        if (afterRevision != null) {
            path = afterRevision.getFile().getPath();
        } else if (beforeRevision != null) {
            path = beforeRevision.getFile().getPath();
        }
        if (path != null) {
            files.add(path);
        }
    }

    try {
        final ServerContext context = myVcs.getServerContext(true);
        final List<Integer> workItemIds = VcsHelper.getWorkItemIdsFromMessage(preparedComment);
        final String changesetNumber = CommandUtils.checkinFiles(context, files, preparedComment, workItemIds);

        // notify user of success
        final String changesetLink = String.format(UrlHelper.SHORT_HTTP_LINK_FORMATTER, UrlHelper.getTfvcChangesetURI(context.getUri().toString(), changesetNumber),
                TfPluginBundle.message(TfPluginBundle.KEY_TFVC_CHECKIN_LINK_TEXT, changesetNumber));
        VcsNotifier.getInstance(myVcs.getProject()).notifyImportantInfo(TfPluginBundle.message(TfPluginBundle.KEY_TFVC_CHECKIN_SUCCESSFUL_TITLE),
                TfPluginBundle.message(TfPluginBundle.KEY_TFVC_CHECKIN_SUCCESSFUL_MSG, changesetLink), new NotificationListener() {
                    @Override
                    public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent hyperlinkEvent) {
                        BrowserUtil.browse(hyperlinkEvent.getURL());
                    }
                });
    } catch (Exception e) {
        // no notification needs to be done by us for errors, IntelliJ handles that
        logger.warn("Error during checkin", e);
        if (e instanceof TeamServicesException) {
            // get localized message in the case of TeamServicesException otherwise the key will print out instead of the error
            errors.add(new VcsException(LocalizationServiceImpl.getInstance().getExceptionMessage(e)));
        } else {
            errors.add(new VcsException(e));
        }
    }

    return errors;
}
 
Example #28
Source File: BaseAnalysisActionDialog.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public AnalysisScope getScope(@Nonnull AnalysisUIOptions uiOptions, @Nonnull AnalysisScope defaultScope, @Nonnull Project project, Module module) {
  AnalysisScope scope;
  if (isProjectScopeSelected()) {
    scope = new AnalysisScope(project);
    uiOptions.SCOPE_TYPE = AnalysisScope.PROJECT;
  }
  else {
    final SearchScope customScope = getCustomScope();
    if (customScope != null) {
      scope = new AnalysisScope(customScope, project);
      uiOptions.SCOPE_TYPE = AnalysisScope.CUSTOM;
      uiOptions.CUSTOM_SCOPE_NAME = customScope.getDisplayName();
    }
    else if (isModuleScopeSelected()) {
      scope = new AnalysisScope(module);
      uiOptions.SCOPE_TYPE = AnalysisScope.MODULE;
    }
    else if (isUncommitedFilesSelected()) {
      final ChangeListManager changeListManager = ChangeListManager.getInstance(project);
      List<VirtualFile> files;
      if (myChangeLists.getSelectedItem() == ALL) {
        files = changeListManager.getAffectedFiles();
      }
      else {
        files = new ArrayList<VirtualFile>();
        for (ChangeList list : changeListManager.getChangeListsCopy()) {
          if (!Comparing.strEqual(list.getName(), (String)myChangeLists.getSelectedItem())) continue;
          final Collection<Change> changes = list.getChanges();
          for (Change change : changes) {
            final ContentRevision afterRevision = change.getAfterRevision();
            if (afterRevision != null) {
              final VirtualFile vFile = afterRevision.getFile().getVirtualFile();
              if (vFile != null) {
                files.add(vFile);
              }
            }
          }
        }
      }
      scope = new AnalysisScope(project, new HashSet<VirtualFile>(files));
      uiOptions.SCOPE_TYPE = AnalysisScope.UNCOMMITTED_FILES;
    }
    else {
      scope = defaultScope;
      uiOptions.SCOPE_TYPE = defaultScope.getScopeType();//just not project scope
    }
  }
  uiOptions.ANALYZE_TEST_SOURCES = isInspectTestSources();
  scope.setIncludeTestSource(isInspectTestSources());
  scope.setScope(getCustomScope());

  FindSettings.getInstance().setDefaultScopeName(scope.getDisplayName());
  return scope;
}
 
Example #29
Source File: VcsUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static boolean isChangeForFolder(Change change) {
  ContentRevision revB = change.getBeforeRevision();
  ContentRevision revA = change.getAfterRevision();
  return (revA != null && revA.getFile().isDirectory()) || (revB != null && revB.getFile().isDirectory());
}
 
Example #30
Source File: VcsAnnotationCachedProxy.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * @param currentRevision - just a hint for optimization
 */
private FileAnnotation annotate(VirtualFile file, final VcsRevisionNumber revisionNumber, final boolean currentRevision,
                                final ThrowableComputable<FileAnnotation, VcsException> delegate) throws VcsException {
  final AnnotationProvider annotationProvider = myAnnotationProvider;

  final FilePath filePath = VcsUtil.getFilePath(file);

  final VcsCacheableAnnotationProvider cacheableAnnotationProvider = (VcsCacheableAnnotationProvider)annotationProvider;

  VcsAnnotation vcsAnnotation = null;
  if (revisionNumber != null) {
    Object cachedData = myCache.get(filePath, myVcs.getKeyInstanceMethod(), revisionNumber);
    vcsAnnotation = ObjectUtils.tryCast(cachedData, VcsAnnotation.class);
  }

  if (vcsAnnotation != null) {
    final VcsHistoryProvider historyProvider = myVcs.getVcsHistoryProvider();
    final VcsAbstractHistorySession history = getHistory(revisionNumber, filePath, historyProvider, vcsAnnotation.getFirstRevision());
    if (history == null) return null;
    // question is whether we need "not moved" path here?
    final ContentRevision fileContent = myVcs.getDiffProvider().createFileContent(revisionNumber, file);
    final FileAnnotation restored = cacheableAnnotationProvider.
            restore(vcsAnnotation, history, fileContent.getContent(), currentRevision,
                    revisionNumber);
    if (restored != null) {
      return restored;
    }
  }

  final FileAnnotation fileAnnotation = delegate.compute();
  vcsAnnotation = cacheableAnnotationProvider.createCacheable(fileAnnotation);
  if (vcsAnnotation == null) return fileAnnotation;

  if (revisionNumber != null) {
    myCache.put(filePath, myVcs.getKeyInstanceMethod(), revisionNumber, vcsAnnotation);
  }

  if (myVcs.getVcsHistoryProvider() instanceof VcsCacheableHistorySessionFactory) {
    loadHistoryInBackgroundToCache(revisionNumber, filePath, vcsAnnotation);
  }
  return fileAnnotation;
}