Search in sources :

Example 6 with DiffRequestProducerException

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

the class DiffShelvedChangesAction method processTextChanges.

private static void processTextChanges(@NotNull final Project project, @NotNull List<ShelvedChange> changesFromFirstList, @NotNull List<MyDiffRequestProducer> diffRequestProducers) {
    final String base = project.getBasePath();
    final ApplyPatchContext patchContext = new ApplyPatchContext(project.getBaseDir(), 0, false, false);
    final PatchesPreloader preloader = new PatchesPreloader(project);
    for (final ShelvedChange shelvedChange : changesFromFirstList) {
        final String beforePath = shelvedChange.getBeforePath();
        final String afterPath = shelvedChange.getAfterPath();
        final FilePath filePath = VcsUtil.getFilePath(new File(base, afterPath == null ? beforePath : afterPath));
        final boolean isNewFile = FileStatus.ADDED.equals(shelvedChange.getFileStatus());
        // isNewFile -> parent directory, !isNewFile -> file
        final VirtualFile file;
        try {
            file = ApplyFilePatchBase.findPatchTarget(patchContext, beforePath, afterPath, isNewFile);
            if (!isNewFile && (file == null || !file.exists()))
                throw new FileNotFoundException(beforePath);
        } catch (IOException e) {
            diffRequestProducers.add(new MyDiffRequestProducer(shelvedChange, filePath) {

                @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) + "'");
                }
            });
            continue;
        }
        diffRequestProducers.add(new MyDiffRequestProducer(shelvedChange, filePath) {

            @NotNull
            @Override
            public DiffRequest process(@NotNull UserDataHolder context, @NotNull ProgressIndicator indicator) throws DiffRequestProducerException, ProcessCanceledException {
                if (!isNewFile && file.getFileType() == UnknownFileType.INSTANCE) {
                    return new UnknownFileTypeDiffRequest(file, getName());
                }
                if (shelvedChange.isConflictingChange(project)) {
                    try {
                        final CommitContext commitContext = new CommitContext();
                        final TextFilePatch patch = preloader.getPatch(shelvedChange, commitContext);
                        final FilePath pathBeforeRename = patchContext.getPathBeforeRename(file);
                        final String relativePath = patch.getAfterName() == null ? patch.getBeforeName() : patch.getAfterName();
                        final Getter<CharSequence> baseContentGetter = new Getter<CharSequence>() {

                            @Override
                            public CharSequence get() {
                                BaseRevisionTextPatchEP baseRevisionTextPatchEP = Extensions.findExtension(PatchEP.EP_NAME, project, BaseRevisionTextPatchEP.class);
                                return baseRevisionTextPatchEP.provideContent(relativePath, commitContext);
                            }
                        };
                        Getter<ApplyPatchForBaseRevisionTexts> getter = new Getter<ApplyPatchForBaseRevisionTexts>() {

                            @Override
                            public ApplyPatchForBaseRevisionTexts get() {
                                return ApplyPatchForBaseRevisionTexts.create(project, file, pathBeforeRename, patch, baseContentGetter);
                            }
                        };
                        return PatchDiffRequestFactory.createConflictDiffRequest(project, file, patch, "Shelved Version", getter, getName(), context, indicator);
                    } catch (VcsException e) {
                        throw new DiffRequestProducerException("Can't show diff for '" + getName() + "'", e);
                    }
                } else {
                    final Change change = shelvedChange.getChange(project);
                    return PatchDiffRequestFactory.createDiffRequest(project, change, getName(), context, indicator);
                }
            }
        });
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Getter(com.intellij.openapi.util.Getter) FileNotFoundException(java.io.FileNotFoundException) DiffRequest(com.intellij.diff.requests.DiffRequest) UnknownFileTypeDiffRequest(com.intellij.diff.requests.UnknownFileTypeDiffRequest) UnknownFileTypeDiffRequest(com.intellij.diff.requests.UnknownFileTypeDiffRequest) NotNull(org.jetbrains.annotations.NotNull) UserDataHolder(com.intellij.openapi.util.UserDataHolder) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) CommitContext(com.intellij.openapi.vcs.changes.CommitContext) ApplyPatchForBaseRevisionTexts(com.intellij.openapi.vcs.changes.patch.ApplyPatchForBaseRevisionTexts) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) FilePath(com.intellij.openapi.vcs.FilePath) DiffRequestProducerException(com.intellij.diff.chains.DiffRequestProducerException) IOException(java.io.IOException) Change(com.intellij.openapi.vcs.changes.Change) VcsException(com.intellij.openapi.vcs.VcsException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 7 with DiffRequestProducerException

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

the class DiffShelvedChangesAction method processBinaryFiles.

private static void processBinaryFiles(@NotNull final Project project, @NotNull List<ShelvedBinaryFile> files, @NotNull List<MyDiffRequestProducer> diffRequestProducers) {
    final String base = project.getBaseDir().getPath();
    for (final ShelvedBinaryFile shelvedChange : files) {
        final File file = new File(base, shelvedChange.AFTER_PATH == null ? shelvedChange.BEFORE_PATH : shelvedChange.AFTER_PATH);
        final FilePath filePath = VcsUtil.getFilePath(file);
        diffRequestProducers.add(new MyDiffRequestProducer(shelvedChange, filePath) {

            @NotNull
            @Override
            public DiffRequest process(@NotNull UserDataHolder context, @NotNull ProgressIndicator indicator) throws DiffRequestProducerException, ProcessCanceledException {
                Change change = shelvedChange.createChange(project);
                return PatchDiffRequestFactory.createDiffRequest(project, change, getName(), context, indicator);
            }
        });
    }
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) DiffRequestProducerException(com.intellij.diff.chains.DiffRequestProducerException) DiffRequest(com.intellij.diff.requests.DiffRequest) UnknownFileTypeDiffRequest(com.intellij.diff.requests.UnknownFileTypeDiffRequest) Change(com.intellij.openapi.vcs.changes.Change) 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) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 8 with DiffRequestProducerException

use of com.intellij.diff.chains.DiffRequestProducerException 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)

Example 9 with DiffRequestProducerException

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

the class ChangeDiffRequestProducer method createContent.

@NotNull
public static DiffContent createContent(@Nullable Project project, @Nullable ContentRevision revision, @NotNull UserDataHolder context, @NotNull ProgressIndicator indicator) throws DiffRequestProducerException {
    try {
        indicator.checkCanceled();
        if (revision == null)
            return DiffContentFactory.getInstance().createEmpty();
        FilePath filePath = revision.getFile();
        DiffContentFactoryEx contentFactory = DiffContentFactoryEx.getInstanceEx();
        if (revision instanceof CurrentContentRevision) {
            VirtualFile vFile = ((CurrentContentRevision) revision).getVirtualFile();
            if (vFile == null)
                throw new DiffRequestProducerException("Can't get current revision content");
            return contentFactory.create(project, vFile);
        }
        if (revision instanceof BinaryContentRevision) {
            byte[] content = ((BinaryContentRevision) revision).getBinaryContent();
            if (content == null) {
                throw new DiffRequestProducerException("Can't get binary revision content");
            }
            return contentFactory.createFromBytes(project, content, filePath);
        }
        if (revision instanceof ByteBackedContentRevision) {
            byte[] revisionContent = ((ByteBackedContentRevision) revision).getContentAsBytes();
            if (revisionContent == null)
                throw new DiffRequestProducerException("Can't get revision content");
            return contentFactory.createFromBytes(project, revisionContent, filePath);
        } else {
            String revisionContent = revision.getContent();
            if (revisionContent == null)
                throw new DiffRequestProducerException("Can't get revision content");
            return contentFactory.create(project, revisionContent, filePath);
        }
    } catch (IOException | VcsException e) {
        LOG.info(e);
        throw new DiffRequestProducerException(e);
    }
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) VirtualFile(com.intellij.openapi.vfs.VirtualFile) DiffRequestProducerException(com.intellij.diff.chains.DiffRequestProducerException) VcsException(com.intellij.openapi.vcs.VcsException) DiffContentFactoryEx(com.intellij.diff.DiffContentFactoryEx) IOException(java.io.IOException) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with DiffRequestProducerException

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

the class SvnChangeDiffViewerProvider method createPropertyRequest.

@NotNull
private static SvnPropertiesDiffRequest createPropertyRequest(@NotNull Change change, @NotNull ProgressIndicator indicator) throws DiffRequestProducerException {
    try {
        Change propertiesChange = getSvnChangeLayer(change);
        if (propertiesChange == null)
            throw new DiffRequestProducerException(SvnBundle.getString("diff.cant.get.properties.changes"));
        ContentRevision bRevRaw = propertiesChange.getBeforeRevision();
        ContentRevision aRevRaw = propertiesChange.getAfterRevision();
        if (bRevRaw != null && !(bRevRaw instanceof PropertyRevision)) {
            LOG.warn("Before change is not PropertyRevision");
            throw new DiffRequestProducerException(SvnBundle.getString("diff.cant.get.properties.changes"));
        }
        if (aRevRaw != null && !(aRevRaw instanceof PropertyRevision)) {
            LOG.warn("After change is not PropertyRevision");
            throw new DiffRequestProducerException(SvnBundle.getString("diff.cant.get.properties.changes"));
        }
        PropertyRevision bRev = (PropertyRevision) bRevRaw;
        PropertyRevision aRev = (PropertyRevision) aRevRaw;
        indicator.checkCanceled();
        List<PropertyData> bContent = bRev != null ? bRev.getProperties() : null;
        indicator.checkCanceled();
        List<PropertyData> aContent = aRev != null ? aRev.getProperties() : null;
        if (aRev == null && bRev == null)
            throw new DiffRequestProducerException(SvnBundle.getString("diff.cant.get.properties.changes"));
        ContentRevision bRevMain = change.getBeforeRevision();
        ContentRevision aRevMain = change.getAfterRevision();
        String title1 = bRevMain != null ? StringUtil.nullize(bRevMain.getRevisionNumber().asString()) : null;
        String title2 = aRevMain != null ? StringUtil.nullize(aRevMain.getRevisionNumber().asString()) : null;
        return new SvnPropertiesDiffRequest(bContent, aContent, title1, title2);
    } catch (VcsException e) {
        throw new DiffRequestProducerException(e);
    }
}
Also used : DiffRequestProducerException(com.intellij.diff.chains.DiffRequestProducerException) PropertyData(org.jetbrains.idea.svn.properties.PropertyData) PropertyRevision(org.jetbrains.idea.svn.history.PropertyRevision) VcsException(com.intellij.openapi.vcs.VcsException) SvnPropertiesDiffRequest(org.jetbrains.idea.svn.difftool.properties.SvnPropertiesDiffRequest) ContentRevision(com.intellij.openapi.vcs.changes.ContentRevision) Change(com.intellij.openapi.vcs.changes.Change) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

DiffRequestProducerException (com.intellij.diff.chains.DiffRequestProducerException)10 NotNull (org.jetbrains.annotations.NotNull)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 DiffRequest (com.intellij.diff.requests.DiffRequest)4 FilePath (com.intellij.openapi.vcs.FilePath)4 VcsException (com.intellij.openapi.vcs.VcsException)4 IOException (java.io.IOException)4 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 Change (com.intellij.openapi.vcs.changes.Change)3 File (java.io.File)3 DiffRequestProducer (com.intellij.diff.chains.DiffRequestProducer)2 SimpleDiffRequest (com.intellij.diff.requests.SimpleDiffRequest)2 UnknownFileTypeDiffRequest (com.intellij.diff.requests.UnknownFileTypeDiffRequest)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)2 Ref (com.intellij.openapi.util.Ref)2 UserDataHolder (com.intellij.openapi.util.UserDataHolder)2 DiffContentFactory (com.intellij.diff.DiffContentFactory)1 DiffContentFactoryEx (com.intellij.diff.DiffContentFactoryEx)1 DiffContent (com.intellij.diff.contents.DiffContent)1 DiffViewerWrapper (com.intellij.diff.impl.DiffViewerWrapper)1