com.intellij.openapi.vcs.actions.VcsContextFactory Java Examples

The following examples show how to use com.intellij.openapi.vcs.actions.VcsContextFactory. 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: IdeaLightweightExtension.java    From p4ic4idea with Apache License 2.0 6 votes vote down vote up
private void initializeApplication(Application application) {
    DefaultPicoContainer pico = new DefaultPicoContainer();
    when(application.getPicoContainer()).thenReturn(pico);

    MessageBus bus = new SingleThreadedMessageBus(null);
    when(application.getMessageBus()).thenReturn(bus);

    // Service setup.  See ServiceManager
    pico.registerComponent(service(PasswordSafe.class, new MockPasswordSafe()));
    pico.registerComponent(service(VcsContextFactory.class, new MockVcsContextFactory()));

    VirtualFileManager vfm = mock(VirtualFileManager.class);
    when(application.getComponent(VirtualFileManager.class)).thenReturn(vfm);

    AccessToken readToken = mock(AccessToken.class);
    when(application.acquireReadActionLock()).thenReturn(readToken);

    ApplicationInfo appInfo = mock(ApplicationInfo.class);
    when(appInfo.getApiVersion()).thenReturn("IC-182.1.1");
    registerApplicationService(ApplicationInfo.class, appInfo);
}
 
Example #2
Source File: ContentAnnotationCacheImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void register(final VirtualFile vf, final VcsKey vcsKey, final VcsRevisionNumber number, final FileAnnotation fa) {
  final HistoryCacheWithRevisionKey key = new HistoryCacheWithRevisionKey(VcsContextFactory.SERVICE.getInstance().createFilePathOn(vf), vcsKey, number);
  synchronized (myLock) {
    if (myCache.get(key) != null) return;
  }
  final long absoluteLimit = System.currentTimeMillis() - VcsContentAnnotationSettings.ourAbsoluteLimit;
  final TreeMap<Integer, Long> map = new TreeMap<Integer, Long>();
  final int lineCount = fa.getLineCount();
  for (int i = 0; i < lineCount; i++) {
    Date lineDate = fa.getLineDate(i);
    if (lineDate == null) return;
    if (lineDate.getTime() >= absoluteLimit) map.put(i, lineDate.getTime());
  }
  synchronized (myLock) {
    myCache.put(key, map);
  }
}
 
Example #3
Source File: VcsVFSListener.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void addFileToDelete(VirtualFile file) {
  if (file.isDirectory() && file instanceof NewVirtualFile && !isDirectoryVersioningSupported()) {
    for (VirtualFile child : ((NewVirtualFile)file).getCachedChildren()) {
      addFileToDelete(child);
    }
  }
  else {
    final VcsDeleteType type = needConfirmDeletion(file);
    final FilePath filePath = VcsContextFactory.SERVICE.getInstance().createFilePathOn(new File(file.getPath()), file.isDirectory());
    if (type == VcsDeleteType.CONFIRM) {
      myDeletedFiles.add(filePath);
    }
    else if (type == VcsDeleteType.SILENT) {
      myDeletedWithoutConfirmFiles.add(filePath);
    }
  }
}
 
Example #4
Source File: TFSCommittedChangesProvider.java    From azure-devops-intellij with MIT License 5 votes vote down vote up
@Override
public Pair<TFSChangeList, FilePath> getOneList(final VirtualFile file, final VcsRevisionNumber number) throws VcsException {
    final ChangeBrowserSettings settings = createDefaultSettings();
    settings.USE_CHANGE_AFTER_FILTER = true;
    settings.USE_CHANGE_BEFORE_FILTER = true;
    settings.CHANGE_BEFORE = settings.CHANGE_AFTER = String.valueOf(((TfsRevisionNumber) number).getValue());
    final FilePath filePath = VcsContextFactory.SERVICE.getInstance().createFilePathOn(file);
    final List<TFSChangeList> list = getCommittedChanges(settings, getLocationFor(filePath), 1);
    if (list.size() == 1) {
        return Pair.create(list.get(0), filePath);
    }
    return null;
}
 
Example #5
Source File: BrowseChangesAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean isActionEnabled(final AnActionEvent e) {
  Project project = e.getData(CommonDataKeys.PROJECT);
  if (project == null) return false;
  VirtualFile vFile = e.getData(PlatformDataKeys.VIRTUAL_FILE);
  if (vFile == null) return false;
  AbstractVcs vcs = ProjectLevelVcsManager.getInstance(project).getVcsFor(vFile);
  if (vcs == null || vcs.getCommittedChangesProvider() == null || !vcs.allowsRemoteCalls(vFile)) {
    return false;
  }
  FilePath filePath = VcsContextFactory.SERVICE.getInstance().createFilePathOn(vFile);
  return AbstractVcs.fileInVcsByFileStatus(project, filePath);
}
 
Example #6
Source File: VcsUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static FilePath getFilePath(@Nonnull VirtualFile file) {
  return VcsContextFactory.SERVICE.getInstance().createFilePathOn(file);
}
 
Example #7
Source File: FakeRevision.java    From consulo with Apache License 2.0 4 votes vote down vote up
public FakeRevision(String path) throws ChangeListManagerSerialization.OutdatedFakeRevisionException {
  final FilePath file = VcsContextFactory.SERVICE.getInstance().createFilePathOn(new File(path));
  if (file == null) throw new ChangeListManagerSerialization.OutdatedFakeRevisionException();
  myFile = file;
}
 
Example #8
Source File: VcsUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static FilePath getFilePath(@Nonnull VirtualFile parent, @Nonnull String fileName, boolean isDirectory) {
  return VcsContextFactory.SERVICE.getInstance().createFilePath(parent, fileName, isDirectory);
}
 
Example #9
Source File: VcsUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static FilePath getFilePath(@Nonnull VirtualFile parent, @Nonnull String name) {
  return VcsContextFactory.SERVICE.getInstance().createFilePathOn(parent, name);
}
 
Example #10
Source File: VcsUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static FilePath getFilePathForDeletedFile(@Nonnull String path, boolean isDirectory) {
  return VcsContextFactory.SERVICE.getInstance().createFilePathOnDeleted(new File(path), isDirectory);
}
 
Example #11
Source File: VcsUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static FilePath getFilePath(@Nonnull File file, boolean isDirectory) {
  return VcsContextFactory.SERVICE.getInstance().createFilePathOn(file, isDirectory);
}
 
Example #12
Source File: VcsUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static FilePath getFilePathOnNonLocal(String path, boolean isDirectory) {
  return VcsContextFactory.SERVICE.getInstance().createFilePathOnNonLocal(path, isDirectory);
}
 
Example #13
Source File: VcsUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static FilePath getFilePath(@Nonnull String path, boolean isDirectory) {
  return VcsContextFactory.SERVICE.getInstance().createFilePath(path, isDirectory);
}
 
Example #14
Source File: VcsUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static FilePath getFilePath(@Nonnull File file) {
  return VcsContextFactory.SERVICE.getInstance().createFilePathOn(file);
}
 
Example #15
Source File: SingleItemAction.java    From azure-devops-intellij with MIT License 4 votes vote down vote up
public void actionPerformed(final AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    final VirtualFile file = VcsUtil.getOneVirtualFile(e);

    if (project == null || file == null) {
        // This shouldn't happen, but just in case
        logger.warn("project or file is null in actionPerformed");
        return;
    }

    // checked by isEnabled()
    final FilePath localPath = VcsContextFactory.SERVICE.getInstance().createFilePathOn(file);

    final String actionTitle = StringUtil.trimEnd(e.getPresentation().getText(), "...");
    try {
        final SingleItemActionContext actionContext = new SingleItemActionContext(project, localPath);
        final List<VcsException> errors = new ArrayList<VcsException>();
        ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
            public void run() {
                try {
                    ProgressManager.getInstance().getProgressIndicator().setIndeterminate(true);
                    final ServerContext context = TFSVcs.getInstance(project).getServerContext(true);
                    final ItemInfo item = CommandUtils.getItemInfo(context, localPath.getPath());
                    actionContext.setItem(item);
                    actionContext.setServerContext(context);
                } catch (final Throwable t) {
                    errors.add(TFSVcs.convertToVcsException(t));
                }
            }
        }, getProgressMessage(), false, project);

        if (!errors.isEmpty()) {
            AbstractVcsHelper.getInstance(project).showErrors(errors, TFSVcs.TFVC_NAME);
            return;
        }

        execute(actionContext);
    } catch (TfsException ex) {
        Messages.showErrorDialog(project, ex.getMessage(), actionTitle);
    }
}
 
Example #16
Source File: VcsUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static void markFileAsDirty(final Project project, final String path) {
  final FilePath filePath = VcsContextFactory.SERVICE.getInstance().createFilePathOn(new File(path));
  markFileAsDirty( project, filePath );
}
 
Example #17
Source File: LocalChangeList.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static LocalChangeList createEmptyChangeList(Project project, @Nonnull String name) {
  return VcsContextFactory.SERVICE.getInstance().createLocalChangeList(project, name);
}
 
Example #18
Source File: TfsFileUtil.java    From azure-devops-intellij with MIT License 4 votes vote down vote up
public static FilePath getFilePath(@NotNull final VirtualFile f) {
    return VcsContextFactory.SERVICE.getInstance().createFilePathOn(f);
}
 
Example #19
Source File: MultipleItemAction.java    From azure-devops-intellij with MIT License 4 votes vote down vote up
@Override
public void actionPerformed(final AnActionEvent anActionEvent) {
    logger.info("Starting multiple item action");

    final MultipleItemActionContext context = new MultipleItemActionContext();
    context.project = anActionEvent.getData(CommonDataKeys.PROJECT);
    final VirtualFile[] files = VcsUtil.getVirtualFiles(anActionEvent);

    logger.info("Finding the list of selected files and getting itemInfos for each one");
    runWithProgress(context, new Runnable() {
        public void run() {
            ProgressManager.getInstance().getProgressIndicator().setIndeterminate(true);
            context.serverContext = TFSVcs.getInstance(context.project).getServerContext(true);

            // Get the local paths
            final List<String> localPaths = new ArrayList<String>(files.length);
            for (final VirtualFile file : files) {
                final FilePath localPath = VcsContextFactory.SERVICE.getInstance().createFilePathOn(file);
                localPaths.add(localPath.getPath());
            }

            // Get the item infos
            loadItemInfoCollection(context, localPaths);

            // Set the default path and additional parameters
            if (context.itemInfos.size() > 0) {
                logger.info("Setting the defaultLocalPath and workingFolder");
                context.defaultLocalPath = context.itemInfos.get(0).getLocalItem();
                context.isFolder = Path.directoryExists(context.defaultLocalPath);
                context.workingFolder = context.isFolder ?
                        context.defaultLocalPath :
                        Path.getDirectoryName(context.defaultLocalPath);
            }
        }
    }, TfPluginBundle.message(TfPluginBundle.KEY_ACTIONS_TFVC_LABEL_PROGRESS_GATHERING_INFORMATION));

    if (context.hasErrors()) {
        logger.info("Errors found; showing them and exiting");
        showErrors(context);
        return;
    }

    if (!context.hasItems()) {
        // Somehow we got here without items selected or we couldn't find the info for them.
        // This shouldn't happen, but just in case we won't continue
        logger.warn("We ended up without any items in the list and no errors occurred. We need to understand how this happened.");
        return;
    }

    // Now that we have all the item infos, we can execute the body of this action
    logger.info("Calling the subclasses execute method to do the actual work.");
    execute(context);

    if (context.cancelled) {
        return;
    }

    if (context.hasErrors()) {
        logger.info("Errors found; showing them and exiting");
        showErrors(context);
    }
}