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);
}
}
});
}
}
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);
}
});
}
}
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) + "'");
}
};
}
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);
}
}
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);
}
}
Aggregations