use of com.intellij.diff.chains.DiffRequestProducerException in project intellij-community by JetBrains.
the class ChangeDiffRequestProducer method loadCurrentContents.
@NotNull
protected DiffRequest loadCurrentContents(@NotNull UserDataHolder context, @NotNull ProgressIndicator indicator) throws DiffRequestProducerException {
DiffRequestProducerException wrapperException = null;
DiffRequestProducerException requestException = null;
DiffViewerWrapper wrapper = null;
try {
for (ChangeDiffViewerWrapperProvider provider : ChangeDiffViewerWrapperProvider.EP_NAME.getExtensions()) {
if (provider.canCreate(myProject, myChange)) {
wrapper = provider.process(this, context, indicator);
break;
}
}
} catch (DiffRequestProducerException e) {
wrapperException = e;
}
DiffRequest request = null;
try {
for (ChangeDiffRequestProvider provider : ChangeDiffRequestProvider.EP_NAME.getExtensions()) {
if (provider.canCreate(myProject, myChange)) {
request = provider.process(this, context, indicator);
break;
}
}
if (request == null)
request = createRequest(myProject, myChange, context, indicator);
} catch (DiffRequestProducerException e) {
requestException = e;
}
if (requestException != null && wrapperException != null) {
String message = requestException.getMessage() + "\n\n" + wrapperException.getMessage();
throw new DiffRequestProducerException(message);
}
if (requestException != null) {
request = new ErrorDiffRequest(getRequestTitle(myChange), requestException);
LOG.info("Request: " + requestException.getMessage());
}
if (wrapperException != null) {
LOG.info("Wrapper: " + wrapperException.getMessage());
}
request.putUserData(CHANGE_KEY, myChange);
request.putUserData(DiffViewerWrapper.KEY, wrapper);
for (Map.Entry<Key, Object> entry : myChangeContext.entrySet()) {
request.putUserData(entry.getKey(), entry.getValue());
}
DiffUtil.putDataKey(request, VcsDataKeys.CURRENT_CHANGE, myChange);
return request;
}
use of com.intellij.diff.chains.DiffRequestProducerException in project intellij-community by JetBrains.
the class ChangeDiffRequestProducer method createRequest.
@NotNull
private DiffRequest createRequest(@Nullable Project project, @NotNull Change change, @NotNull UserDataHolder context, @NotNull ProgressIndicator indicator) throws DiffRequestProducerException {
if (ChangesUtil.isTextConflictingChange(change)) {
// three side diff
// FIXME: This part is ugly as a VCS merge subsystem itself.
FilePath path = ChangesUtil.getFilePath(change);
VirtualFile file = path.getVirtualFile();
if (file == null) {
file = LocalFileSystem.getInstance().refreshAndFindFileByPath(path.getPath());
}
if (file == null)
throw new DiffRequestProducerException("Can't show merge conflict - file not found");
if (project == null) {
throw new DiffRequestProducerException("Can't show merge conflict - project is unknown");
}
final AbstractVcs vcs = ChangesUtil.getVcsForChange(change, project);
if (vcs == null || vcs.getMergeProvider() == null) {
throw new DiffRequestProducerException("Can't show merge conflict - operation nos supported");
}
try {
// FIXME: loadRevisions() can call runProcessWithProgressSynchronously() inside
final Ref<Throwable> exceptionRef = new Ref<>();
final Ref<MergeData> mergeDataRef = new Ref<>();
final VirtualFile finalFile = file;
ApplicationManager.getApplication().invokeAndWait(() -> {
try {
mergeDataRef.set(vcs.getMergeProvider().loadRevisions(finalFile));
} catch (VcsException e) {
exceptionRef.set(e);
}
});
if (!exceptionRef.isNull()) {
Throwable e = exceptionRef.get();
if (e instanceof VcsException)
throw (VcsException) e;
if (e instanceof Error)
throw (Error) e;
if (e instanceof RuntimeException)
throw (RuntimeException) e;
throw new RuntimeException(e);
}
MergeData mergeData = mergeDataRef.get();
ContentRevision bRev = change.getBeforeRevision();
ContentRevision aRev = change.getAfterRevision();
String beforeRevisionTitle = getRevisionTitle(bRev, "Your version");
String afterRevisionTitle = getRevisionTitle(aRev, "Server version");
String title = DiffRequestFactory.getInstance().getTitle(file);
List<String> titles = ContainerUtil.list(beforeRevisionTitle, "Base Version", afterRevisionTitle);
DiffContentFactory contentFactory = DiffContentFactory.getInstance();
List<DiffContent> contents = ContainerUtil.list(contentFactory.createFromBytes(project, mergeData.CURRENT, file), contentFactory.createFromBytes(project, mergeData.ORIGINAL, file), contentFactory.createFromBytes(project, mergeData.LAST, file));
SimpleDiffRequest request = new SimpleDiffRequest(title, contents, titles);
MergeUtil.putRevisionInfos(request, mergeData);
return request;
} catch (VcsException | IOException e) {
LOG.info(e);
throw new DiffRequestProducerException(e);
}
} else {
ContentRevision bRev = change.getBeforeRevision();
ContentRevision aRev = change.getAfterRevision();
if (bRev == null && aRev == null) {
LOG.warn("Both revision contents are empty");
throw new DiffRequestProducerException("Bad revisions contents");
}
if (bRev != null)
checkContentRevision(project, bRev, context, indicator);
if (aRev != null)
checkContentRevision(project, aRev, context, indicator);
String title = getRequestTitle(change);
indicator.setIndeterminate(true);
DiffContent content1 = createContent(project, bRev, context, indicator);
DiffContent content2 = createContent(project, aRev, context, indicator);
final String userLeftRevisionTitle = (String) myChangeContext.get(DiffUserDataKeysEx.VCS_DIFF_LEFT_CONTENT_TITLE);
String beforeRevisionTitle = userLeftRevisionTitle != null ? userLeftRevisionTitle : getRevisionTitle(bRev, "Base version");
final String userRightRevisionTitle = (String) myChangeContext.get(DiffUserDataKeysEx.VCS_DIFF_RIGHT_CONTENT_TITLE);
String afterRevisionTitle = userRightRevisionTitle != null ? userRightRevisionTitle : getRevisionTitle(aRev, "Your version");
SimpleDiffRequest request = new SimpleDiffRequest(title, content1, content2, beforeRevisionTitle, afterRevisionTitle);
boolean bRevCurrent = bRev instanceof CurrentContentRevision;
boolean aRevCurrent = aRev instanceof CurrentContentRevision;
if (bRevCurrent && !aRevCurrent)
request.putUserData(DiffUserDataKeys.MASTER_SIDE, Side.LEFT);
if (!bRevCurrent && aRevCurrent)
request.putUserData(DiffUserDataKeys.MASTER_SIDE, Side.RIGHT);
return request;
}
}
use of com.intellij.diff.chains.DiffRequestProducerException in project intellij-community by JetBrains.
the class PatchDiffRequestFactory method createConflictDiffRequest.
@NotNull
public static DiffRequest createConflictDiffRequest(@Nullable Project project, @Nullable VirtualFile file, @NotNull TextFilePatch patch, @NotNull String afterTitle, @NotNull final Getter<ApplyPatchForBaseRevisionTexts> textsGetter, @NotNull String name, @NotNull UserDataHolder context, @NotNull ProgressIndicator indicator) throws DiffRequestProducerException {
if (file == null)
throw new DiffRequestProducerException("Can't show diff for '" + name + "'");
if (file.getFileType().isBinary())
throw new DiffRequestProducerException("Can't show diff for binary file '" + name + "'");
final Ref<ApplyPatchForBaseRevisionTexts> textsRef = new Ref<>();
ApplicationManager.getApplication().invokeAndWait(new Runnable() {
@Override
public void run() {
textsRef.set(textsGetter.get());
}
}, indicator.getModalityState());
ApplyPatchForBaseRevisionTexts texts = textsRef.get();
if (texts.getLocal() == null)
throw new DiffRequestProducerException("Can't show diff for '" + file.getPresentableUrl() + "'");
if (texts.getBase() == null) {
String localContent = texts.getLocal().toString();
final GenericPatchApplier applier = new GenericPatchApplier(localContent, patch.getHunks());
applier.execute();
final AppliedTextPatch appliedTextPatch = AppliedTextPatch.create(applier.getAppliedInfo());
return createBadDiffRequest(project, file, localContent, appliedTextPatch, null, null, null, null);
} else {
String localContent = texts.getLocal().toString();
String baseContent = texts.getBase().toString();
String patchedContent = texts.getPatched();
return createDiffRequest(project, file, ContainerUtil.list(localContent, baseContent, patchedContent), null, ContainerUtil.list("Current Version", "Base Version", afterTitle));
}
}
use of com.intellij.diff.chains.DiffRequestProducerException 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;
}
use of com.intellij.diff.chains.DiffRequestProducerException in project intellij-community by JetBrains.
the class DiffElement method createDiffContent.
/**
* Called in background thread without ReadLock OR in EDT
*
* @see com.intellij.diff.chains.DiffRequestProducer#process
*/
@NotNull
public DiffContent createDiffContent(@Nullable Project project, @NotNull ProgressIndicator indicator) throws DiffRequestProducerException, ProcessCanceledException {
try {
final T src = getValue();
if (src instanceof VirtualFile) {
return DiffContentFactory.getInstance().create(project, (VirtualFile) src);
}
byte[] content = getContent();
if (content == null)
throw new DiffRequestProducerException("Can't get content");
return DiffContentFactory.getInstance().create(project, new String(content, getCharset()), getFileType());
} catch (IOException e) {
throw new DiffRequestProducerException(e);
}
}
Aggregations