Skip to content

Commit

Permalink
#288 Add support for Idea 201
Browse files Browse the repository at this point in the history
  • Loading branch information
fabien committed Apr 30, 2020
1 parent 318145a commit c7bba07
Show file tree
Hide file tree
Showing 16 changed files with 110 additions and 84 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -50,6 +50,6 @@ Feedback and suggestions are also very welcome.
## License

This plugin is under the [Apache 2.0 license](http://www.apache.org/licenses/LICENSE-2.0.html).
Copyright 2013-2019, Opher Vishnia.
Copyright 2013-2020, Opher Vishnia.


17 changes: 11 additions & 6 deletions build.gradle
@@ -1,14 +1,14 @@
plugins {
id 'java'
id 'org.jetbrains.intellij' version '0.4.7'
id 'org.jetbrains.intellij' version '0.4.18'
}

compileJava {
options.compilerArgs += ["-Xlint"]
}

group 'gitflow4idea'
version '0.7.1'
version '0.7.2'

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
Expand All @@ -22,18 +22,23 @@ dependencies {
}

intellij {
version '2019.3'
version '2020.1'
plugins 'git4idea', 'tasks'
}

patchPluginXml {
pluginId "Gitflow"
pluginDescription 'Git Flow Integration'
version '0.7.1'
sinceBuild '182.0'
untilBuild '193.*'
version '0.7.2'
sinceBuild '201.0'
untilBuild '201.*'
changeNotes """
<H2>Changelog for 0.7.2</H2>
<ul>
<li>Support for Idea build 201 #288 (@fabmars)</li>
</ul>
<H2>Changelog for 0.7.1</H2>
<ul>
<li>Support for Idea build 193 #259 (@opherv)</li>
Expand Down
35 changes: 10 additions & 25 deletions src/main/java/gitflow/GitflowComponent.java
@@ -1,6 +1,6 @@
package gitflow;

import com.intellij.openapi.components.ProjectComponent;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
import com.intellij.openapi.vcs.VcsListener;
Expand All @@ -12,41 +12,29 @@
import git4idea.GitVcs;
import gitflow.ui.GitflowUnsupportedVersionWidget;
import gitflow.ui.GitflowWidget;
import org.jetbrains.annotations.NotNull;


/**
* @author Opher Vishnia / opherv.com / opherv@gmail.com
* One instance per project
*/
public class GitflowComponent implements ProjectComponent, VcsListener {
public class GitflowComponent implements VcsListener, Disposable {
Project myProject;
GitflowWidget myGitflowWidget;
MessageBus messageBus;

public GitflowComponent(Project project) {
myProject = project;
}

public void initComponent() {
messageBus = myProject.getMessageBus();
messageBus.connect().subscribe(ProjectLevelVcsManager.VCS_CONFIGURATION_CHANGED, this);
}

public void disposeComponent() {
// TODO: insert component disposal logic here
// Seems the event triggering this component happens after the directory mapping change, hence the incentive.
directoryMappingChanged();
}

@NotNull
public String getComponentName() {
return "GitflowComponent";
}

public void projectOpened() {

}

public void projectClosed() {

@Override
public void dispose() {
// TODO: insert component disposal logic here
}

@Override
Expand All @@ -63,18 +51,15 @@ public void directoryMappingChanged() {
//make sure to not reinitialize the widget if it's already present
if (GitflowVersionTester.forProject(myProject).isSupportedVersion() && myGitflowWidget == null) {
myGitflowWidget = new GitflowWidget(myProject);
widgetToAdd = (StatusBarWidget) myGitflowWidget;
widgetToAdd = myGitflowWidget;
} else {
widgetToAdd = new GitflowUnsupportedVersionWidget(myProject);
}

if (statusBar != null) {
statusBar.addWidget(widgetToAdd, "after " + git4idea.ui.branch.GitBranchWidget.class.getName(), myProject);
statusBar.addWidget(widgetToAdd, StatusBar.Anchors.after(git4idea.ui.branch.GitBranchWidget.class.getName()), myProject);
}
} else {
if (myGitflowWidget != null) {
myGitflowWidget.deactivate();
}
myGitflowWidget = null;
}
}
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/gitflow/GitflowService.java
@@ -0,0 +1,27 @@
package gitflow;

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.Service;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.startup.StartupActivity;
import com.intellij.openapi.util.Disposer;
import org.jetbrains.annotations.NotNull;

/**
* @author Fabien Marsaud / @fabmars
* Only one instance, runActivity is called every time a project is opened
*/
@Service
public final class GitflowService implements StartupActivity {

@Override
public void runActivity(@NotNull Project project) {
// Ensure this isn't part of testing
if (!ApplicationManager.getApplication().isUnitTestMode()) {
// Install Git Flow widget
GitflowComponent gitflowComponent = new GitflowComponent(project);
// Prepare for when the project will be closed
Disposer.register(project, gitflowComponent);
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/gitflow/actions/FinishBugfixAction.java
Expand Up @@ -88,7 +88,7 @@ public void onSuccess() {

//merge conflicts if necessary
if (errorLineHandler.hasMergeError){
if (handleMerge()){
if (handleMerge(project)){
that.runAction(project, bugfixName);
FinishBugfixAction completeFinishBugfixAction = new FinishBugfixAction(myRepo, bugfixName);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gitflow/actions/FinishFeatureAction.java
Expand Up @@ -88,7 +88,7 @@ public void onSuccess() {

//merge conflicts if necessary
if (errorLineHandler.hasMergeError){
if (handleMerge()){
if (handleMerge(project)) {
that.runAction(project, featureName);
FinishFeatureAction completeFinishFeatureAction = new FinishFeatureAction(myRepo, featureName);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gitflow/actions/FinishReleaseAction.java
Expand Up @@ -102,7 +102,7 @@ public void onSuccess() {

//merge conflicts if necessary
if (errorLineHandler.hasMergeError){
if (handleMerge()) {
if (handleMerge(myProject)) {
FinishReleaseAction completeFinisReleaseAction = new FinishReleaseAction(releaseName, tagMessage);
completeFinisReleaseAction.actionPerformed(event);
}
Expand Down
27 changes: 15 additions & 12 deletions src/main/java/gitflow/actions/GitflowAction.java
Expand Up @@ -18,7 +18,7 @@

import java.util.ArrayList;

public class GitflowAction extends DumbAwareAction {
public abstract class GitflowAction extends DumbAwareAction {
Project myProject;
Gitflow myGitflow = ServiceManager.getService(Gitflow.class);
ArrayList<GitRepository> repos = new ArrayList<GitRepository>();
Expand Down Expand Up @@ -55,28 +55,31 @@ private void setup(Project project){
branchUtil= GitflowBranchUtilManager.getBranchUtil(myRepo);
}

public void runAction(Project project, final String baseBranchName, final String branchName, @Nullable final Runnable callInAwtLater){
public void runAction(final Project project, final String baseBranchName, final String branchName, @Nullable final Runnable callInAwtLater){
setup(project);
}

//returns true if merge successful, false otherwise
public boolean handleMerge(){
//ugly, but required for intellij to catch up with the external changes made by
//the CLI before being able to run the merge tool
virtualFileMananger.syncRefresh();
public boolean handleMerge(final Project project) {
// FIXME As of 201.0 the async version of this method doesn't call the callback,
// else we'd use a FutureTask (which is a Runnable) and its get() method.
// Hence this ugly hack, to let the time to intellij to catch up with the external changes made by the CLI
// before being able to run the merge tool. Else the tool won't display and the Y/N dialog will appear directly!
try {
Thread.sleep(500);
virtualFileMananger.syncRefresh();
Thread.sleep(750L); // delay had to be bumped with v 201
} catch (InterruptedException ignored) {
}
catch (InterruptedException ignored) {
}


GitflowActions.runMergeTool();
GitflowActions.runMergeTool(project);
myRepo.update();
return askUserForMergeSuccess(project);
}

private static boolean askUserForMergeSuccess(Project myProject) {
//if merge was completed successfully, finish the action
//note that if it wasn't intellij is left in the "merging state", and git4idea provides no UI way to resolve it
//merging can be done via intellij itself or any other util
//merging can be done via intellij itself or any other util
int answer = Messages.showYesNoDialog(myProject, "Was the merge completed succesfully?", "Merge", Messages.getQuestionIcon());
if (answer==0){
GitMerger gitMerger=new GitMerger(myProject);
Expand Down
43 changes: 29 additions & 14 deletions src/main/java/gitflow/actions/GitflowActions.java
@@ -1,19 +1,10 @@
package gitflow.actions;

import com.intellij.dvcs.ui.BranchActionGroup;
import com.intellij.dvcs.ui.PopupElementWithAdditionalInfo;
import com.intellij.ide.DataManager;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFileManager;
import git4idea.branch.GitBranchUtil;
import git4idea.repo.GitRepository;
import gitflow.Gitflow;
import gitflow.GitflowBranchUtil;
import gitflow.GitflowBranchUtilManager;
import gitflow.GitflowConfigUtil;
import git4idea.actions.GitResolveConflictsAction;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* All actions associated with Gitflow
Expand All @@ -22,9 +13,33 @@
*/
public class GitflowActions {

public static void runMergeTool(){
git4idea.actions.GitResolveConflictsAction resolveAction= new git4idea.actions.GitResolveConflictsAction();
AnActionEvent e = new AnActionEvent(null, DataManager.getInstance().getDataContext(), ActionPlaces.UNKNOWN, new Presentation(""), ActionManager.getInstance(), 0);
public static void runMergeTool(Project project){
GitResolveConflictsAction resolveAction = new GitResolveConflictsAction();
AnActionEvent e = new AnActionEvent(null, new ProjectDataContext(project), ActionPlaces.UNKNOWN, new Presentation(""), ActionManager.getInstance(), 0);
resolveAction.actionPerformed(e);
}


/**
* Simple wrapper containing just enough to let the conflicts resolver to launch
* We could have transferred the DataContext or wrapped a HackyDataContext from the previous action,
* but that would make the semantics terrible
*/
private final static class ProjectDataContext implements DataContext {
private Project project;

private ProjectDataContext(Project project) {
this.project = project;
}

@Nullable
@Override
public Object getData(@NotNull String dataId) {
if(CommonDataKeys.PROJECT.getName().equals(dataId)) {
return project;
} else {
throw new UnsupportedOperationException(dataId);
}
}
}
}
3 changes: 2 additions & 1 deletion src/main/java/gitflow/actions/StartBugfixAction.java
Expand Up @@ -36,7 +36,8 @@ public void actionPerformed(AnActionEvent e) {
this.runAction(e.getProject(), baseBranchName, bugfixName, null);
}

public void runAction(Project project, final String baseBranchName, final String bugfixName, @Nullable final Runnable callInAwtLater){
@Override
public void runAction(final Project project, final String baseBranchName, final String bugfixName, @Nullable final Runnable callInAwtLater){
super.runAction(project, baseBranchName, bugfixName, callInAwtLater);

new Task.Backgroundable(myProject, "Starting bugfix " + bugfixName, false) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gitflow/actions/StartFeatureAction.java
Expand Up @@ -36,7 +36,7 @@ public void actionPerformed(AnActionEvent e) {
this.runAction(e.getProject(), baseBranchName, featureName, null);
}

public void runAction(Project project, final String baseBranchName, final String featureName, @Nullable final Runnable callInAwtLater){
public void runAction(final Project project, final String baseBranchName, final String featureName, @Nullable final Runnable callInAwtLater){
super.runAction(project, baseBranchName, featureName, callInAwtLater);

new Task.Backgroundable(myProject, "Starting feature " + featureName, false) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gitflow/actions/StartHotfixAction.java
Expand Up @@ -38,7 +38,7 @@ public void actionPerformed(AnActionEvent e) {
this.runAction(e.getProject(), baseBranchName, hotfixName, null);
}

public void runAction(Project project, final String baseBranchName, final String hotfixName, @Nullable final Runnable callInAwtLater){
public void runAction(final Project project, final String baseBranchName, final String hotfixName, @Nullable final Runnable callInAwtLater){
super.runAction(project, baseBranchName, hotfixName, callInAwtLater);

new Task.Backgroundable(myProject, "Starting hotfix " + hotfixName, false) {
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/gitflow/ui/GitflowTaskDialogPanelProvider.java
@@ -1,5 +1,4 @@
package gitflow.ui;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.project.Project;
import com.intellij.tasks.LocalTask;
import com.intellij.tasks.Task;
Expand All @@ -13,14 +12,19 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Enumeration;
import java.util.HashMap;

public class GitflowTaskDialogPanelProvider extends TaskDialogPanelProvider {

@Deprecated
@Nullable
@Override
public TaskDialogPanel getOpenTaskPanel(@NotNull Project project, @NotNull Task task) {
return null;
}

@Nullable
@Override
public TaskDialogPanel getOpenTaskPanel(@NotNull Project project, @NotNull LocalTask task) {
GitRepository currentRepo = GitBranchUtil.getCurrentRepository(project);
GitflowBranchUtil branchUtil = GitflowBranchUtilManager.getBranchUtil(currentRepo);
if (branchUtil.hasGitflow()) {
Expand Down
@@ -1,15 +1,10 @@
package gitflow.ui;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.StatusBarWidget;
import com.intellij.openapi.wm.StatusBarWidget.TextPresentation;
import com.intellij.openapi.wm.impl.status.EditorBasedWidget;
import com.intellij.util.Consumer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.awt.event.MouseEvent;

public class GitflowUnsupportedVersionWidget extends EditorBasedWidget {

public GitflowUnsupportedVersionWidget(@NotNull Project project) {
Expand All @@ -24,7 +19,7 @@ public String ID() {

@Nullable
@Override
public WidgetPresentation getPresentation(@NotNull PlatformType type) {
public WidgetPresentation getPresentation() {
return new UnsupportedVersionWidgetPresentation();
}
}

0 comments on commit c7bba07

Please sign in to comment.