-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
333 additions
and
169 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
package gitflow; | ||
|
||
import com.intellij.openapi.application.ApplicationManager; | ||
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; | ||
|
@@ -11,73 +10,43 @@ | |
import com.intellij.openapi.wm.WindowManager; | ||
import com.intellij.util.messages.MessageBus; | ||
import git4idea.GitVcs; | ||
import gitflow.ui.GitflowUnsupportedVersionWidget; | ||
import gitflow.ui.GitflowWidget; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
|
||
/** | ||
* @author Opher Vishnia / opherv.com / [email protected] | ||
* 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); | ||
// Seems the event triggering this component happens after the directory mapping change | ||
directoryMappingChanged(); | ||
} | ||
|
||
public void disposeComponent() { | ||
@Override | ||
public void dispose() { | ||
// TODO: insert component disposal logic here | ||
} | ||
|
||
@NotNull | ||
public String getComponentName() { | ||
return "GitflowComponent"; | ||
} | ||
|
||
public void projectOpened() { | ||
|
||
} | ||
|
||
public void projectClosed() { | ||
|
||
} | ||
|
||
@Override | ||
public void directoryMappingChanged() { | ||
VcsRoot[] vcsRoots = ProjectLevelVcsManager.getInstance(myProject).getAllVcsRoots(); | ||
StatusBar statusBar = WindowManager.getInstance().getStatusBar(myProject); | ||
|
||
//git repo present | ||
if (vcsRoots.length > 0 && vcsRoots[0].getVcs() instanceof GitVcs) { | ||
|
||
|
||
StatusBarWidget widgetToAdd; | ||
|
||
//make sure to not reinitialize the widget if it's already present | ||
if (GitflowVersionTester.isSupportedVersion() && myGitflowWidget == null) { | ||
myGitflowWidget = new GitflowWidget(myProject); | ||
widgetToAdd = (StatusBarWidget) myGitflowWidget; | ||
StatusBar statusBar = WindowManager.getInstance().getStatusBar(myProject); | ||
GitflowWidget widget = (GitflowWidget) statusBar.getWidget(GitflowWidget.class.getName()); | ||
if (widget != null) { | ||
widget.updateAsync(); | ||
} else { | ||
widgetToAdd = new GitflowUnsupportedVersionWidget(myProject); | ||
throw new NullPointerException("widget"); | ||
} | ||
|
||
if (statusBar != null) { | ||
statusBar.addWidget(widgetToAdd, "after " + git4idea.ui.branch.GitBranchWidget.class.getName(), myProject); | ||
} | ||
} else { | ||
if (myGitflowWidget != null) { | ||
myGitflowWidget.deactivate(); | ||
} | ||
myGitflowWidget = null; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,75 @@ | ||
package gitflow; | ||
|
||
import com.intellij.execution.configurations.GeneralCommandLine; | ||
import com.intellij.execution.ExecutionException; | ||
import com.intellij.execution.util.ExecUtil; | ||
import com.intellij.execution.process.ProcessOutput; | ||
import com.intellij.openapi.components.ServiceManager; | ||
import com.intellij.openapi.diagnostic.Logger; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.util.Disposer; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
public class GitflowVersionTester { | ||
static Boolean isSupportedVersion = null; | ||
|
||
static boolean isSupportedVersion(){ | ||
if (isSupportedVersion == null) { | ||
|
||
ProcessOutput output = null; | ||
GeneralCommandLine commandLine = new GeneralCommandLine(); | ||
commandLine.setExePath("git"); | ||
commandLine.addParameters("flow"); | ||
commandLine.addParameters("version"); | ||
try { | ||
output = ExecUtil.execAndGetOutput(commandLine); | ||
} catch (ExecutionException e) { | ||
e.printStackTrace(); | ||
|
||
private static final Logger logger = Logger.getInstance(GitflowVersionTester.class); | ||
|
||
private static final Map<Project, GitflowVersionTester> testers = new ConcurrentHashMap<>(); | ||
|
||
public static GitflowVersionTester forProject(@NotNull Project project) { | ||
return testers.computeIfAbsent( | ||
project, | ||
p -> { | ||
Disposer.register(p, () -> testers.remove(p)); | ||
return new GitflowVersionTester(ServiceManager.getService(Gitflow.class), p); | ||
} | ||
String stdout = output.getStdout(); | ||
// System.out.println("output: " + stdout); | ||
// test that the installed git flow CLI version is AVH and not the unmaintained NVIE version | ||
isSupportedVersion = stdout.contains("AVH"); | ||
); | ||
} | ||
|
||
@NotNull private final Gitflow gitflow; | ||
@NotNull private final Project project; | ||
|
||
private String version = null; | ||
|
||
private GitflowVersionTester(@NotNull Gitflow gitflow, @NotNull Project project) { | ||
this.gitflow = gitflow; | ||
this.project = project; | ||
} | ||
|
||
/** | ||
* <p>Returns the installed {@code git-flow} version. The version | ||
* is loaded on the first call to this method and is determined | ||
* by looking at the output of a {@code git flow version} command.</p> | ||
* <p>If the command fails, {@code null} is returned.</p> | ||
* | ||
* @return the {@code git flow} version, or {@code null} | ||
*/ | ||
@Nullable | ||
public String getVersion() { | ||
return version; | ||
} | ||
|
||
/** | ||
* Returns true if the {@code git flow} version can be determined | ||
* and is any AVH version ({@code #contains("AVH")}) and | ||
* not the unmaintained NVIE version. | ||
* | ||
* @return true if we think the git flow version is an AVH version. | ||
*/ | ||
public boolean isSupportedVersion() { | ||
return version != null && version.contains("AVH"); | ||
} | ||
|
||
public void init(){ | ||
String returnedVersion = null; | ||
try { | ||
returnedVersion = gitflow.version(project).getOutputOrThrow(); | ||
logger.info("git flow version: " + version); | ||
} catch (Exception e) { | ||
logger.error("Could not determine git flow version", e); | ||
} | ||
if (returnedVersion != null){ | ||
version = returnedVersion; | ||
} | ||
return isSupportedVersion; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.