Search in sources :

Example 1 with DiffRequestProducer

use of com.intellij.diff.chains.DiffRequestProducer in project intellij-community by JetBrains.

the class TextFilePatchInProgress method getDiffRequestProducers.

@NotNull
@Override
public DiffRequestProducer getDiffRequestProducers(final Project project, final PatchReader patchReader) {
    final PatchChange change = getChange();
    final FilePatch patch = getPatch();
    final String path = patch.getBeforeName() == null ? patch.getAfterName() : patch.getBeforeName();
    final Getter<CharSequence> baseContentGetter = new Getter<CharSequence>() {

        @Override
        public CharSequence get() {
            return patchReader.getBaseRevision(project, path);
        }
    };
    return new DiffRequestProducer() {

        @NotNull
        @Override
        public DiffRequest process(@NotNull UserDataHolder context, @NotNull ProgressIndicator indicator) throws DiffRequestProducerException, ProcessCanceledException {
            if (myCurrentBase != null && myCurrentBase.getFileType() == UnknownFileType.INSTANCE) {
                return new UnknownFileTypeDiffRequest(myCurrentBase, getName());
            }
            if (isConflictingChange()) {
                final VirtualFile file = getCurrentBase();
                Getter<ApplyPatchForBaseRevisionTexts> getter = new Getter<ApplyPatchForBaseRevisionTexts>() {

                    @Override
                    public ApplyPatchForBaseRevisionTexts get() {
                        return ApplyPatchForBaseRevisionTexts.create(project, file, VcsUtil.getFilePath(file), getPatch(), baseContentGetter);
                    }
                };
                String afterTitle = getPatch().getAfterVersionId();
                if (afterTitle == null)
                    afterTitle = "Patched Version";
                return PatchDiffRequestFactory.createConflictDiffRequest(project, file, getPatch(), afterTitle, getter, getName(), context, indicator);
            } else {
                return PatchDiffRequestFactory.createDiffRequest(project, change, getName(), context, indicator);
            }
        }

        @NotNull
        @Override
        public String getName() {
            final File ioCurrentBase = getIoCurrentBase();
            return ioCurrentBase == null ? getCurrentPath() : ioCurrentBase.getPath();
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Getter(com.intellij.openapi.util.Getter) DiffRequestProducer(com.intellij.diff.chains.DiffRequestProducer) UnknownFileTypeDiffRequest(com.intellij.diff.requests.UnknownFileTypeDiffRequest) TextFilePatch(com.intellij.openapi.diff.impl.patch.TextFilePatch) FilePatch(com.intellij.openapi.diff.impl.patch.FilePatch) NotNull(org.jetbrains.annotations.NotNull) UserDataHolder(com.intellij.openapi.util.UserDataHolder) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with DiffRequestProducer

use of com.intellij.diff.chains.DiffRequestProducer in project intellij-community by JetBrains.

the class ExternalDiffTool method collectRequests.

@NotNull
private static List<DiffRequest> collectRequests(@Nullable Project project, @NotNull final DiffRequestChain chain, @NotNull ProgressIndicator indicator) {
    List<DiffRequest> requests = new ArrayList<>();
    UserDataHolderBase context = new UserDataHolderBase();
    List<String> errorRequests = new ArrayList<>();
    // TODO: show all changes on explicit selection
    List<? extends DiffRequestProducer> producers = Collections.singletonList(chain.getRequests().get(chain.getIndex()));
    for (DiffRequestProducer producer : producers) {
        try {
            requests.add(producer.process(context, indicator));
        } catch (DiffRequestProducerException e) {
            LOG.warn(e);
            errorRequests.add(producer.getName());
        }
    }
    if (!errorRequests.isEmpty()) {
        new Notification("diff", "Can't load some changes", StringUtil.join(errorRequests, "<br>"), NotificationType.ERROR).notify(project);
    }
    return requests;
}
Also used : DiffRequestProducerException(com.intellij.diff.chains.DiffRequestProducerException) UserDataHolderBase(com.intellij.openapi.util.UserDataHolderBase) ArrayList(java.util.ArrayList) ContentDiffRequest(com.intellij.diff.requests.ContentDiffRequest) DiffRequest(com.intellij.diff.requests.DiffRequest) DiffRequestProducer(com.intellij.diff.chains.DiffRequestProducer) Notification(com.intellij.notification.Notification) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with DiffRequestProducer

use of com.intellij.diff.chains.DiffRequestProducer in project intellij-community by JetBrains.

the class ApplyPatchDifferentiatedDialog method createBaseNotFoundErrorRequest.

@NotNull
private static DiffRequestProducer createBaseNotFoundErrorRequest(@NotNull final AbstractFilePatchInProgress patchInProgress) {
    final String beforePath = patchInProgress.getPatch().getBeforeName();
    final String afterPath = patchInProgress.getPatch().getAfterName();
    return new DiffRequestProducer() {

        @NotNull
        @Override
        public String getName() {
            final File ioCurrentBase = patchInProgress.getIoCurrentBase();
            return ioCurrentBase == null ? patchInProgress.getCurrentPath() : ioCurrentBase.getPath();
        }

        @NotNull
        @Override
        public DiffRequest process(@NotNull UserDataHolder context, @NotNull ProgressIndicator indicator) throws DiffRequestProducerException, ProcessCanceledException {
            throw new DiffRequestProducerException("Cannot find base for '" + (beforePath != null ? beforePath : afterPath) + "'");
        }
    };
}
Also used : DiffRequestProducerException(com.intellij.diff.chains.DiffRequestProducerException) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) DiffRequestProducer(com.intellij.diff.chains.DiffRequestProducer) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

DiffRequestProducer (com.intellij.diff.chains.DiffRequestProducer)3 NotNull (org.jetbrains.annotations.NotNull)3 DiffRequestProducerException (com.intellij.diff.chains.DiffRequestProducerException)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 File (java.io.File)2 ContentDiffRequest (com.intellij.diff.requests.ContentDiffRequest)1 DiffRequest (com.intellij.diff.requests.DiffRequest)1 UnknownFileTypeDiffRequest (com.intellij.diff.requests.UnknownFileTypeDiffRequest)1 Notification (com.intellij.notification.Notification)1 FilePatch (com.intellij.openapi.diff.impl.patch.FilePatch)1 TextFilePatch (com.intellij.openapi.diff.impl.patch.TextFilePatch)1 Getter (com.intellij.openapi.util.Getter)1 UserDataHolder (com.intellij.openapi.util.UserDataHolder)1 UserDataHolderBase (com.intellij.openapi.util.UserDataHolderBase)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 ArrayList (java.util.ArrayList)1