Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/intellij14' into intellij14.1
Browse files Browse the repository at this point in the history
# Conflicts:
#	gradle.properties
#	src/main/java/com/urswolfer/intellij/plugin/gerrit/ui/GerritChangeListPanel.java
#	src/main/java/com/urswolfer/intellij/plugin/gerrit/ui/diff/CommentsDiffTool.java
#	src/main/java/com/urswolfer/intellij/plugin/gerrit/util/GerritDataKeys.java
  • Loading branch information
uwolfer committed Aug 16, 2017
2 parents 6d52293 + 76c9f66 commit 22055f7
Show file tree
Hide file tree
Showing 34 changed files with 896 additions and 851 deletions.
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ gerrit-intellij-plugin
======================

[![Build Status](https://travis-ci.org/uwolfer/gerrit-intellij-plugin.svg)](https://travis-ci.org/uwolfer/gerrit-intellij-plugin)
[![Version](http://phpstorm.espend.de/badge/7272/version)](https://plugins.jetbrains.com/plugin/7272)
[![Downloads](http://phpstorm.espend.de/badge/7272/downloads)](https://plugins.jetbrains.com/plugin/7272)

Introduction
-----------
Expand All @@ -22,10 +24,21 @@ Unofficial [IntelliJ Platform](http://www.jetbrains.com/idea/) plugin for the
* Gogland
* Rider

*Compiled with Java 1.6*

Only Gerrit 2.6 or newer is supported (missing / incomplete REST API in older versions).

You can install this plugin from the [IntelliJ Plugin Manager](http://plugins.jetbrains.com/plugin/7272).
If you install this plugin directly in your IDE's plugin manager, you will get notified when a new release is available.
Installation
------------
- Using IDE built-in plugin system (suggested: you'll get notified when an update is available):
- <kbd>Preferences</kbd> > <kbd>Plugins</kbd> > <kbd>Browse repositories...</kbd> >
<kbd>Search for "Gerrit"</kbd> > <kbd>Install Plugin</kbd>
- Manually:
- Download the [release](https://github.com/uwolfer/gerrit-intellij-plugin/releases)
matching your IntelliJ version and install it manually using
<kbd>Preferences</kbd> > <kbd>Plugins</kbd> > <kbd>Install plugin from disk...</kbd>

Restart your IDE.

###### Pre-Releases
If you want to get new releases earlier, you can subscribe to the release-candidate plugin channel:
Expand Down Expand Up @@ -113,6 +126,11 @@ It's very easy to set it up as an IntelliJ project.
Once ```build.gradle``` gets updated, you need to "Refresh all Gradle projects" in the Gradle panel.


Contributing
------------
Check the [`CONTRIBUTING.md`](./CONTRIBUTING.md) file.


Credits
------
* IntelliJ Github plugin (some code of this plugin is based on its code)
Expand All @@ -129,7 +147,7 @@ Please only use the link from github.com/uwolfer/gerrit-intellij-plugin to verif
Copyright and license
--------------------

Copyright 2013 - 2016 Urs Wolfer
Copyright 2013 - 2017 Urs Wolfer

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this work except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

plugins {
id 'org.jetbrains.intellij' version '0.2.9'
id 'org.jetbrains.intellij' version '0.2.16'
}

apply plugin: 'java'
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ideaVersion=IC-14.1.6
ijPluginRepoChannel=
downloadIdeaSources=false
version=1.0.0.1-141
version=1.0.1-141
javaVersion=1.6
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public Element getState() {
element.setAttribute(HOST, (getHost() != null ? getHost() : ""));
element.setAttribute(LIST_ALL_CHANGES, Boolean.toString(getListAllChanges()));
element.setAttribute(AUTOMATIC_REFRESH, Boolean.toString(getAutomaticRefresh()));
element.setAttribute(REFRESH_TIMEOUT, "" + getRefreshTimeout());
element.setAttribute(REFRESH_TIMEOUT, Integer.toString(getRefreshTimeout()));
element.setAttribute(REVIEW_NOTIFICATIONS, Boolean.toString(getReviewNotifications()));
element.setAttribute(PUSH_TO_GERRIT, Boolean.toString(getPushToGerrit()));
element.setAttribute(SHOW_CHANGE_NUMBER_COLUMN, Boolean.toString(getShowChangeNumberColumn()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
*/
public class PluginErrorReportSubmitter extends ErrorReportSubmitter {

private static final String ERROR_REPORT_URL = "http://urswolfer.com/gerrit-intellij-plugin/service/error-report/";
private static final String ERROR_REPORT_URL = "https://urswolfer.com/gerrit-intellij-plugin/service/error-report/";

@Override
public String getReportActionText() {
Expand Down Expand Up @@ -83,18 +83,18 @@ private ErrorBean createErrorBean(IdeaLoggingEvent loggingEvent, String addition
}

private void postError(String json) {
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(ERROR_REPORT_URL);
httpPost.setEntity(new StringEntity(json, ContentType.APPLICATION_JSON));
try {
CloseableHttpResponse response = httpClient.execute(httpPost);
CloseableHttpClient httpClient = HttpClients.createDefault();
try {
HttpPost httpPost = new HttpPost(ERROR_REPORT_URL);
httpPost.setEntity(new StringEntity(json, ContentType.APPLICATION_JSON));
CloseableHttpResponse response = httpClient.execute(httpPost);
if (response.getStatusLine().getStatusCode() == 406) {
String reasonPhrase = response.getStatusLine().getReasonPhrase();
Messages.showErrorDialog(reasonPhrase, "Gerrit Plugin Message");
}
} finally {
response.close();
httpClient.close();
}
} catch (IOException e) {
throw Throwables.propagate(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,22 @@

package com.urswolfer.intellij.plugin.gerrit.git;

import static git4idea.commands.GitSimpleEventDetector.Event.CHERRY_PICK_CONFLICT;
import static git4idea.commands.GitSimpleEventDetector.Event.LOCAL_CHANGES_OVERWRITTEN_BY_CHERRY_PICK;

import com.google.common.base.Optional;
import com.google.common.base.Throwables;
import com.google.common.collect.Lists;
import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.extensions.common.FetchInfo;
import com.google.inject.Inject;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.text.StringUtil;
Expand All @@ -46,30 +51,40 @@
import com.urswolfer.intellij.plugin.gerrit.util.NotificationBuilder;
import com.urswolfer.intellij.plugin.gerrit.util.NotificationService;
import com.urswolfer.intellij.plugin.gerrit.util.UrlUtils;
import git4idea.*;
import git4idea.commands.*;
import git4idea.GitCommit;
import git4idea.GitExecutionException;
import git4idea.GitPlatformFacade;
import git4idea.GitUtil;
import git4idea.GitVcs;
import git4idea.commands.Git;
import git4idea.commands.GitCommand;
import git4idea.commands.GitCommandResult;
import git4idea.commands.GitLineHandler;
import git4idea.commands.GitLineHandlerListener;
import git4idea.commands.GitSimpleEventDetector;
import git4idea.commands.GitStandardProgressAnalyzer;
import git4idea.commands.GitTask;
import git4idea.commands.GitTaskResultHandlerAdapter;
import git4idea.commands.GitUntrackedFilesOverwrittenByOperationDetector;
import git4idea.history.GitHistoryUtils;
import git4idea.merge.GitConflictResolver;
import git4idea.repo.GitRemote;
import git4idea.repo.GitRepository;
import git4idea.repo.GitRepositoryManager;
import git4idea.reset.GitResetMode;
import git4idea.update.GitFetchResult;
import git4idea.update.GitFetcher;
import git4idea.util.GitCommitCompareInfo;
import git4idea.util.UntrackedFilesNotifier;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.ArrayList;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicReference;

import static git4idea.commands.GitSimpleEventDetector.Event.CHERRY_PICK_CONFLICT;
import static git4idea.commands.GitSimpleEventDetector.Event.LOCAL_CHANGES_OVERWRITTEN_BY_CHERRY_PICK;

/**
* @author Urs Wolfer
*/
Expand Down Expand Up @@ -114,10 +129,26 @@ public Optional<GitRepository> getRepositoryForGerritProject(Project project, St
return Optional.absent();
}

public Optional<GitRemote> getRemoteForChange(Project project, GitRepository gitRepository, FetchInfo fetchInfo) {
String url = fetchInfo.url;
for (GitRemote remote : gitRepository.getRemotes()) {
for (String repositoryUrl : remote.getUrls()) {
if (UrlUtils.urlHasSameHost(repositoryUrl, url)
|| UrlUtils.urlHasSameHost(repositoryUrl, gerritSettings.getHost())) {
return Optional.of(remote);
}
}
}
NotificationBuilder notification = new NotificationBuilder(project, "Error",
String.format("Could not fetch commit because no remote url matches Gerrit host.<br/>" +
"Git repository: '%s'.", gitRepository.getPresentableUrl()));
notificationService.notifyError(notification);
return Optional.absent();
}

public void fetchChange(final Project project,
final GitRepository gitRepository,
final String url,
final String branch,
final FetchInfo fetchInfo,
@Nullable final Callable<Void> successCallable) {
GitVcs.runInBackground(new Task.Backgroundable(project, "Fetching...", false) {
@Override
Expand All @@ -134,19 +165,14 @@ public void onSuccess() {

@Override
public void run(@NotNull ProgressIndicator indicator) {
for (GitRemote remote : gitRepository.getRemotes()) {
for (String repositoryUrl : remote.getUrls()) {
if (UrlUtils.urlHasSameHost(repositoryUrl, url)
|| UrlUtils.urlHasSameHost(repositoryUrl, gerritSettings.getHost())) {
fetchNatively(gitRepository.getGitDir(), remote, repositoryUrl, branch, project, indicator);
return;
}
}
Optional<GitRemote> remote = getRemoteForChange(project, gitRepository, fetchInfo);
if (!remote.isPresent()) {
return;
}
GitFetchResult result = fetchNatively(gitRepository.getGitDir(), remote.get(), remote.get().getFirstUrl(), fetchInfo.ref, project, indicator);
if (!result.isSuccess()) {
GitFetcher.displayFetchResult(project, result, null, result.getErrors());
}
NotificationBuilder notification = new NotificationBuilder(project, "Error",
String.format("Could not fetch commit because no remote url matches Gerrit host.<br/>" +
"Git repository: '%s'.", gitRepository.getPresentableUrl()));
notificationService.notifyError(notification);
}
});
}
Expand Down Expand Up @@ -364,6 +390,25 @@ public boolean checkoutNewBranch(GitRepository repository, String branch) throws

}

public void setUpstreamBranch(GitRepository repository, String remoteBranch) throws VcsException {
FormattedGitLineHandlerListener listener = new FormattedGitLineHandlerListener();
final GitLineHandler h = new GitLineHandler(repository.getProject(), repository.getRoot(), GitCommand.BRANCH);
h.setSilent(false);
h.setStdoutSuppressed(false);
h.addParameters("-u", "remotes/" + remoteBranch);
h.endOptions();
h.addLineListener(listener);
GitCommandResult gitCommandResult = git.runCommand(new Computable<GitLineHandler>() {
@Override
public GitLineHandler compute() {
return h;
}
});
if (!gitCommandResult.success()) {
throw new VcsException(listener.getHtmlMessage());
}
}

private static class FormattedGitLineHandlerListener implements GitLineHandlerListener {

private List<String> messages = new ArrayList<String>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ private void fetchChange(RevisionInfo revisionInfo, FetchCallback fetchCallback)
if (fetchInfo == null) {
notifyError();
} else {
String ref = fetchInfo.ref;
String url = fetchInfo.url;
gerritGitUtil.fetchChange(project, gitRepository, url, ref, fetchCallback);
gerritGitUtil.fetchChange(project, gitRepository, fetchInfo, fetchCallback);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@


import com.google.common.collect.Lists;
import com.google.gerrit.extensions.common.*;
import com.google.gerrit.extensions.common.AccountInfo;
import com.google.gerrit.extensions.common.ApprovalInfo;
import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.extensions.common.ChangeMessageInfo;
import com.google.gerrit.extensions.common.LabelInfo;
import com.intellij.ide.BrowserUtil;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.changes.issueLinks.IssueLinkHtmlRenderer;
Expand All @@ -45,11 +49,11 @@
* @author Urs Wolfer
*/
public class GerritChangeDetailsPanel {
private final static String NOTHING_SELECTED = "nothingSelected";
private final static String LOADING = "loading";
private final static String DATA = "data";
private final static String MULTIPLE_SELECTED = "multiple_selected";
private final static ThreadLocal<DecimalFormat> APPROVAL_VALUE_FORMAT = new ThreadLocal<DecimalFormat>() {
private static final String NOTHING_SELECTED = "nothingSelected";
private static final String LOADING = "loading";
private static final String DATA = "data";
private static final String MULTIPLE_SELECTED = "multiple_selected";
private static final ThreadLocal<DecimalFormat> APPROVAL_VALUE_FORMAT = new ThreadLocal<DecimalFormat>() {
@Override
protected DecimalFormat initialValue() {
return new DecimalFormat("+#;-#");
Expand Down Expand Up @@ -135,7 +139,7 @@ public JPanel getComponent() {

private static class MyPresentationData {
private String startPattern;
private final String endPattern = "</table></body></html>";
private static final String endPattern = "</table></body></html>";
private final Project project;

private MyPresentationData(final Project project) {
Expand Down Expand Up @@ -204,7 +208,7 @@ private void addLabels(ChangeInfo changeInfo, StringBuilder sb) {
}

private void addMessages(ChangeInfo changeInfo, StringBuilder sb) {
if (changeInfo.messages != null && changeInfo.messages.size() > 0) {
if (changeInfo.messages != null && !changeInfo.messages.isEmpty()) {
sb.append("<tr valign=\"top\"><td><i>Comments:</i></td><td>");
for (ChangeMessageInfo changeMessageInfo : changeInfo.messages) {
AccountInfo author = changeMessageInfo.author;
Expand Down
Loading

0 comments on commit 22055f7

Please sign in to comment.