Search in sources :

Example 1 with CvsEnvironment

use of com.intellij.cvsSupport2.connections.CvsEnvironment in project intellij-community by JetBrains.

the class CvsHistoryProvider method createRevisions.

private List<VcsFileRevision> createRevisions(final CvsEnvironment connectionSettings, final File lightweightFileForFile) {
    final LocalPathIndifferentLogOperation logOperation = new LocalPathIndifferentLogOperation(connectionSettings);
    logOperation.addFile(lightweightFileForFile);
    final CvsOperationExecutor executor = new CvsOperationExecutor(myProject);
    final ArrayList<VcsFileRevision> result = new ArrayList<>();
    executor.performActionSync(new CommandCvsHandler(CvsBundle.message("operation.name.load.file.content"), logOperation), new DefaultCvsOperationExecutorCallback() {

        @Override
        public void executionFinishedSuccessfully() {
            final LogInformation firstLogInformation = logOperation.getFirstLogInformation();
            if (firstLogInformation != null) {
                final List<Revision> revisionList = firstLogInformation.getRevisionList();
                for (Revision revision : revisionList) {
                    result.add(new CvsFileRevisionImpl(revision, lightweightFileForFile, firstLogInformation, connectionSettings, myProject));
                }
            }
        }
    });
    Collections.sort(result, Collections.reverseOrder(VcsFileRevisionComparator.INSTANCE));
    return result;
}
Also used : LocalPathIndifferentLogOperation(com.intellij.cvsSupport2.cvsoperations.cvsLog.LocalPathIndifferentLogOperation) Revision(org.netbeans.lib.cvsclient.command.log.Revision) CvsOperationExecutor(com.intellij.cvsSupport2.cvsExecution.CvsOperationExecutor) LogInformation(org.netbeans.lib.cvsclient.command.log.LogInformation) DefaultCvsOperationExecutorCallback(com.intellij.cvsSupport2.cvsExecution.DefaultCvsOperationExecutorCallback) CvsChangeList(com.intellij.cvsSupport2.changeBrowser.CvsChangeList) List(java.util.List) CommandCvsHandler(com.intellij.cvsSupport2.cvshandlers.CommandCvsHandler)

Example 2 with CvsEnvironment

use of com.intellij.cvsSupport2.connections.CvsEnvironment in project intellij-community by JetBrains.

the class CvsCommittedChangesProvider method getOneList.

@Nullable
@Override
public Pair<CvsChangeList, FilePath> getOneList(VirtualFile file, final VcsRevisionNumber number) throws VcsException {
    final File ioFile = new File(file.getPath());
    final FilePath filePath = VcsContextFactory.SERVICE.getInstance().createFilePathOn(ioFile);
    final VirtualFile vcsRoot = ProjectLevelVcsManager.getInstance(myProject).getVcsRootFor(filePath);
    final CvsRepositoryLocation cvsLocation = getLocationFor(filePath);
    if (cvsLocation == null)
        return null;
    final String module = CvsUtil.getModuleName(vcsRoot);
    final CvsEnvironment connectionSettings = cvsLocation.getEnvironment();
    if (connectionSettings.isOffline()) {
        return null;
    }
    final CvsChangeListsBuilder builder = new CvsChangeListsBuilder(module, connectionSettings, myProject, vcsRoot);
    final Ref<CvsChangeList> result = new Ref<>();
    final LoadHistoryOperation operation = new LoadHistoryOperation(connectionSettings, wrapper -> {
        final List<Revision> revisions = wrapper.getRevisions();
        if (revisions.isEmpty())
            return;
        final RevisionWrapper revision = new RevisionWrapper(wrapper.getFile(), revisions.get(0), null);
        result.set(builder.addRevision(revision));
    }, cvsLocation.getModuleName(), number.asString());
    final CvsResult executionResult = operation.run(myProject);
    if (executionResult.isCanceled()) {
        throw new ProcessCanceledException();
    } else if (executionResult.hasErrors()) {
        throw executionResult.composeError();
    }
    if (result.isNull()) {
        return null;
    }
    final Date commitDate = result.get().getCommitDate();
    final CvsEnvironment rootConnectionSettings = CvsEntriesManager.getInstance().getCvsConnectionSettingsFor(vcsRoot);
    final long t = commitDate.getTime();
    final Date dateFrom = new Date(t - CvsChangeList.SUITABLE_DIFF);
    final Date dateTo = new Date(t + CvsChangeList.SUITABLE_DIFF);
    final LoadHistoryOperation operation2 = new LoadHistoryOperation(rootConnectionSettings, module, dateFrom, dateTo, wrapper -> {
        final List<RevisionWrapper> wrappers = builder.revisionWrappersFromLog(wrapper);
        if (wrappers != null) {
            for (RevisionWrapper revisionWrapper : wrappers) {
                if (result.get().containsFileRevision(revisionWrapper)) {
                    continue;
                }
                builder.addRevision(revisionWrapper);
            }
        }
    });
    final CvsResult cvsResult = operation2.run(myProject);
    if (cvsResult.hasErrors()) {
        throw cvsResult.composeError();
    }
    return Pair.create(result.get(), filePath);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CvsResult(com.intellij.openapi.cvsIntegration.CvsResult) Ref(com.intellij.openapi.util.Ref) Revision(org.netbeans.lib.cvsclient.command.log.Revision) CvsEnvironment(com.intellij.cvsSupport2.connections.CvsEnvironment) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with CvsEnvironment

use of com.intellij.cvsSupport2.connections.CvsEnvironment in project intellij-community by JetBrains.

the class CvsAnnotationProvider method annotate.

public FileAnnotation annotate(VirtualFile cvsVirtualFile, String revision, CvsEnvironment environment) throws VcsException {
    // the VirtualFile has a full path if annotate is called from history (when we have a real file on disk),
    // and has the path equal to a CVS module name if annotate is called from the CVS repository browser
    // (when there's no real path)
    boolean hasLocalFile = false;
    File cvsFile = new File(cvsVirtualFile.getPath());
    if (cvsFile.isAbsolute()) {
        hasLocalFile = true;
        cvsFile = new File(CvsUtil.getModuleName(cvsVirtualFile));
    }
    final boolean binary = annotateBinary(cvsVirtualFile, environment);
    final AnnotateOperation annotateOperation = executeOperation(cvsFile, revision, environment, binary, true);
    final Annotation[] lineAnnotations = annotateOperation.getLineAnnotations();
    final List<VcsFileRevision> revisions;
    if (hasLocalFile) {
        final FilePath filePath = VcsContextFactory.SERVICE.getInstance().createFilePathOn(cvsVirtualFile);
        revisions = myCvsHistoryProvider.createRevisions(filePath);
        // in annotation cvs returns only 8 symbols of username
        // try to find usernames in history and use them
        adjustAnnotation(revisions, lineAnnotations);
    } else {
        // imitation
        revisions = new ArrayList<>();
        final Set<String> usedRevisions = new HashSet<>();
        for (Annotation annotation : lineAnnotations) {
            if (!usedRevisions.contains(annotation.getRevision())) {
                revisions.add(new RevisionPresentation(annotation.getRevision(), annotation.getUserName(), annotation.getDate()));
                usedRevisions.add(annotation.getRevision());
            }
        }
    }
    return new CvsFileAnnotation(annotateOperation.getContent(), lineAnnotations, revisions, cvsVirtualFile, revision, myProject);
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) AnnotateOperation(com.intellij.cvsSupport2.cvsoperations.cvsAnnotate.AnnotateOperation) FileAnnotation(com.intellij.openapi.vcs.annotate.FileAnnotation) Annotation(com.intellij.cvsSupport2.cvsoperations.cvsAnnotate.Annotation) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 4 with CvsEnvironment

use of com.intellij.cvsSupport2.connections.CvsEnvironment in project intellij-community by JetBrains.

the class RTagOperation method createOn.

public static RTagOperation[] createOn(FilePath[] files, String tagName, boolean overrideExisting) {
    Map<CvsEnvironment, List<File>> envToFiles = new HashMap<>();
    for (FilePath file : files) {
        CvsConnectionSettings cvsConnectionSettings = CvsUtil.getCvsConnectionSettings(file);
        if (!envToFiles.containsKey(cvsConnectionSettings))
            envToFiles.put(cvsConnectionSettings, new ArrayList<>());
        envToFiles.get(cvsConnectionSettings).add(file.getIOFile());
    }
    ArrayList<RTagOperation> result = new ArrayList<>();
    for (CvsEnvironment cvsEnvironment : envToFiles.keySet()) {
        RTagOperation rTagOperation = new RTagOperation(cvsEnvironment, tagName, overrideExisting);
        result.add(rTagOperation);
        List<File> iofiles = envToFiles.get(cvsEnvironment);
        for (File file : iofiles) {
            rTagOperation.addFile(file);
        }
    }
    return result.toArray(new RTagOperation[result.size()]);
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) HashMap(com.intellij.util.containers.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CvsEnvironment(com.intellij.cvsSupport2.connections.CvsEnvironment) CvsConnectionSettings(com.intellij.cvsSupport2.connections.CvsConnectionSettings) File(java.io.File)

Example 5 with CvsEnvironment

use of com.intellij.cvsSupport2.connections.CvsEnvironment in project intellij-community by JetBrains.

the class GetModuleContentOperation method createExpandingRepositoryPathOperation.

private LocalPathIndifferentOperation createExpandingRepositoryPathOperation(AdminWriterStoringRepositoryPath adminWriter, CvsEnvironment environment, final String moduleName) {
    return new LocalPathIndifferentOperation(adminWriter, environment) {

        @Override
        protected Command createCommand(CvsRootProvider root, CvsExecutionEnvironment cvsExecutionEnvironment) {
            final CheckoutCommand result = new CheckoutCommand(null);
            result.addModule(moduleName);
            result.setRecursive(false);
            return result;
        }

        @Override
        protected ILocalFileWriter createLocalFileWriter(String cvsRoot, UpdatedFilesManager mergedFilesCollector, CvsExecutionEnvironment cvsExecutionEnvironment) {
            return DeafLocalFileWriter.INSTANCE;
        }

        @Override
        protected String getOperationName() {
            return "checkout";
        }

        @Override
        public void moduleExpanded(String module) {
            super.moduleExpanded(module);
            if (myModuleLocation == null) {
                myModuleLocation = module;
                myStreamingDirectoryContentListener.setModuleName(myModuleLocation);
            }
        }
    };
}
Also used : CheckoutCommand(org.netbeans.lib.cvsclient.command.checkout.CheckoutCommand) CvsRootProvider(com.intellij.cvsSupport2.connections.CvsRootProvider)

Aggregations

CvsEnvironment (com.intellij.cvsSupport2.connections.CvsEnvironment)4 File (java.io.File)4 CvsResult (com.intellij.openapi.cvsIntegration.CvsResult)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 CvsRootProvider (com.intellij.cvsSupport2.connections.CvsRootProvider)2 CvsOperationExecutor (com.intellij.cvsSupport2.cvsExecution.CvsOperationExecutor)2 CommandCvsHandler (com.intellij.cvsSupport2.cvshandlers.CommandCvsHandler)2 AnnotateOperation (com.intellij.cvsSupport2.cvsoperations.cvsAnnotate.AnnotateOperation)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)2 FilePath (com.intellij.openapi.vcs.FilePath)2 List (java.util.List)2 Nullable (org.jetbrains.annotations.Nullable)2 CheckoutCommand (org.netbeans.lib.cvsclient.command.checkout.CheckoutCommand)2 Revision (org.netbeans.lib.cvsclient.command.log.Revision)2 CvsChangeList (com.intellij.cvsSupport2.changeBrowser.CvsChangeList)1 CvsApplicationLevelConfiguration (com.intellij.cvsSupport2.config.CvsApplicationLevelConfiguration)1 CvsConnectionSettings (com.intellij.cvsSupport2.connections.CvsConnectionSettings)1 CvsRootException (com.intellij.cvsSupport2.connections.CvsRootException)1 DefaultCvsOperationExecutorCallback (com.intellij.cvsSupport2.cvsExecution.DefaultCvsOperationExecutorCallback)1 LoginPerformer (com.intellij.cvsSupport2.cvsoperations.common.LoginPerformer)1