Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerd Zanker2013-12-28 13:33:01 +0000
committerMatthias Sohn2014-04-02 13:01:43 +0000
commita466e17eee26dd5c1e107ca68639eee836f26a30 (patch)
tree8343d7e51da3e07ba39cbd0b9b5745061556e1c2
parent8bf175abbb5f5a7b8faf62b1958b3894dc6f67e7 (diff)
downloadegit-a466e17eee26dd5c1e107ca68639eee836f26a30.tar.gz
egit-a466e17eee26dd5c1e107ca68639eee836f26a30.tar.xz
egit-a466e17eee26dd5c1e107ca68639eee836f26a30.zip
Provide extensibility for suggesting branch names
* Add new extension point for branch name suggestions * Add new extension to provide branch name suggestion from Mylyn task This change is needed to enable the automatic creation and checkout of branches based on the active task. Bug: 309578 Change-Id: I9e26d668617481026c81a05b6ea08b97e28f620b AlsoBy: Steffen Pingel <steffen.pingel@tasktop.com> AlsoBy: Manuel Doninger <manuel.doninger@googlemail.com> Signed-off-by: Steffen Pingel <steffen.pingel@tasktop.com> Signed-off-by: Gerd Zanker <gerd.zanker@web.de> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.egit.mylyn.ui/plugin.xml6
-rw-r--r--org.eclipse.egit.mylyn.ui/src/org/eclipse/egit/internal/mylyn/ui/commit/ActiveTaskBranchNameProvider.java62
-rw-r--r--org.eclipse.egit.ui/plugin.properties1
-rw-r--r--org.eclipse.egit.ui/plugin.xml1
-rw-r--r--org.eclipse.egit.ui/schema/branchNameProvider.exsd118
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/IBranchNameProvider.java22
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java3
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/CreateBranchPage.java48
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties1
9 files changed, 260 insertions, 2 deletions
diff --git a/org.eclipse.egit.mylyn.ui/plugin.xml b/org.eclipse.egit.mylyn.ui/plugin.xml
index 474f84f45c..59036f9e65 100644
--- a/org.eclipse.egit.mylyn.ui/plugin.xml
+++ b/org.eclipse.egit.mylyn.ui/plugin.xml
@@ -28,4 +28,10 @@
targetId="org.eclipse.mylyn.tasks.ui.TaskEditor">
</hyperlinkDetector>
</extension>
+ <extension
+ point="org.eclipse.egit.ui.branchNameProvider">
+ <branchNameProvider
+ class="org.eclipse.egit.internal.mylyn.ui.commit.ActiveTaskBranchNameProvider">
+ </branchNameProvider>
+ </extension>
</plugin>
diff --git a/org.eclipse.egit.mylyn.ui/src/org/eclipse/egit/internal/mylyn/ui/commit/ActiveTaskBranchNameProvider.java b/org.eclipse.egit.mylyn.ui/src/org/eclipse/egit/internal/mylyn/ui/commit/ActiveTaskBranchNameProvider.java
new file mode 100644
index 0000000000..c45532beca
--- /dev/null
+++ b/org.eclipse.egit.mylyn.ui/src/org/eclipse/egit/internal/mylyn/ui/commit/ActiveTaskBranchNameProvider.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * Copyright (c) 2011, 2014 Chris Aniszczyk and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Chris Aniszczyk <caniszczyk@gmail.com> - initial API and implementation
+ * Manuel Doninger <manuel.doninger@googlemail.com>
+ * Benjamin Muskalla <benjamin.muskalla@tasktop.com>
+ * Thorsten Kamann <thorsten@kamann.info>
+ * Steffen Pingel <steffen.pingel@tasktop.com>
+ *******************************************************************************/
+package org.eclipse.egit.internal.mylyn.ui.commit;
+
+import org.eclipse.egit.ui.IBranchNameProvider;
+import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal;
+import org.eclipse.mylyn.tasks.core.ITask;
+import org.eclipse.mylyn.tasks.ui.TasksUi;
+
+/**
+ * A BranchNameProvider using description and title of the currently active task
+ * to suggest a branch name.
+ */
+public class ActiveTaskBranchNameProvider implements IBranchNameProvider {
+
+ /**
+ * @return the currently activated task or <code>null</code> if no task is
+ * activated
+ */
+ protected ITask getCurrentTask() {
+ return TasksUi.getTaskActivityManager().getActiveTask();
+ }
+
+ public String getBranchNameSuggestion() {
+ ITask task = getCurrentTask();
+ if (task == null)
+ return null;
+
+ String taskKey = task.getTaskKey();
+ if (taskKey == null)
+ taskKey = task.getTaskId();
+
+ StringBuilder sb = new StringBuilder();
+ sb.append(TasksUiInternal.getTaskPrefix(task.getConnectorKind()));
+ sb.append(taskKey);
+ sb.append('-');
+ sb.append(task.getSummary());
+ return normalizeBranchName(sb.toString());
+ }
+
+ private String normalizeBranchName(String name) {
+ String normalized = name.trim()
+ .replaceAll("\\s+", "_").replaceAll("[^\\w-]", ""); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ if (normalized.length() > 30)
+ normalized = normalized.substring(0, 30);
+ return normalized;
+ }
+
+}
+
diff --git a/org.eclipse.egit.ui/plugin.properties b/org.eclipse.egit.ui/plugin.properties
index 845ee34df7..8d7e7a4e39 100644
--- a/org.eclipse.egit.ui/plugin.properties
+++ b/org.eclipse.egit.ui/plugin.properties
@@ -327,6 +327,7 @@ ConfigureFetchFromUpstreamCommand.label = Configure F&etch from Upstream...
ConfigurePushToUpstreamCommand.label = Configure P&ush to Upstream...
CommitMessageProviderExtension-point.name = CommitMessageProvider
CloneSourceProviderExtension-point.name = CloneSourceProvider
+BranchNameProviderExtension-point.name = BranchNameProvider
FetchFromGerritCommand.name = Fetch From Gerrit
FetchFromGerritCommand.label = Fetch from &Gerrit...
diff --git a/org.eclipse.egit.ui/plugin.xml b/org.eclipse.egit.ui/plugin.xml
index b887e71a2a..8d55a16d5c 100644
--- a/org.eclipse.egit.ui/plugin.xml
+++ b/org.eclipse.egit.ui/plugin.xml
@@ -3,6 +3,7 @@
<plugin>
<extension-point id="commitMessageProvider" name="%CommitMessageProviderExtension-point.name" schema="schema/commitMessageProvider.exsd"/>
<extension-point id="cloneSourceProvider" name="%CloneSourceProviderExtension-point.name" schema="schema/cloneSourceProvider.exsd"/>
+ <extension-point id="branchNameProvider" name="%BranchNameProviderExtension-point.name" schema="schema/branchNameProvider.exsd"/>
<extension point="org.eclipse.core.runtime.preferences">
<initializer class="org.eclipse.egit.ui.PluginPreferenceInitializer"/>
</extension>
diff --git a/org.eclipse.egit.ui/schema/branchNameProvider.exsd b/org.eclipse.egit.ui/schema/branchNameProvider.exsd
new file mode 100644
index 0000000000..3a4559141b
--- /dev/null
+++ b/org.eclipse.egit.ui/schema/branchNameProvider.exsd
@@ -0,0 +1,118 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.egit.ui" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.eclipse.egit.ui" id="branchNameProvider" name="BranchName"/>
+ </appInfo>
+ <documentation>
+ This extension point allows to register an implementation suggesting branch names based on contextual information.
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appInfo>
+ <meta.element />
+ </appInfo>
+ </annotation>
+ <complexType>
+ <choice>
+ <element ref="branchNameProvider"/>
+ </choice>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+ </documentation>
+ <appInfo>
+ <meta.attribute translatable="true"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="branchNameProvider">
+ <annotation>
+ <documentation>
+ This element provides the configuration of the BranchNameProvider. Only the class attribute is needed.
+ </documentation>
+ </annotation>
+ <complexType>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+ Class implementing org.eclipse.egit.ui.IBranchNameProvider to be registered for suggesting branch names.
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="java" basedOn=":org.eclipse.egit.ui.IBranchNameProvider"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ 3.4.0
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiinfo"/>
+ </appInfo>
+ <documentation>
+ There is an interface org.eclipse.egit.ui.IBranchNameProvider.
+This is the only interface you must implement to use the extension point.
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="copyright"/>
+ </appInfo>
+ <documentation>
+ Copyright (C) 2014, Gerd Zanker &lt;gerd.zanker@web.de&gt;
+
+All rights reserved. This program and the accompanying materials
+are made available under the terms of the Eclipse Public License v1.0
+which accompanies this distribution, and is available at
+http://www.eclipse.org/legal/epl-v10.html
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/IBranchNameProvider.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/IBranchNameProvider.java
new file mode 100644
index 0000000000..940bf339b5
--- /dev/null
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/IBranchNameProvider.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (C) 2012, Manuel Doninger <manuel.doninger@googlemail.com>
+ * Copyright (C) 2012, Steffen Pingel <steffen.pingel@tasktop.com>
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.egit.ui;
+
+/**
+ * A branch name provider suggests a branch name based on current context.
+ */
+public interface IBranchNameProvider {
+
+ /**
+ * @return a branch name suggestion
+ */
+ public String getBranchNameSuggestion();
+
+}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
index a7a0335827..7736c4ec3c 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
@@ -2482,6 +2482,9 @@ public class UIText extends NLS {
public static String CreateBranchPage_ChooseNameMessage;
/** */
+ public static String CreateBranchPage_CreateBranchNameProviderFailed;
+
+ /** */
public static String CreateBranchPage_CreatingBranchMessage;
/** */
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/CreateBranchPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/CreateBranchPage.java
index d330d81f5b..c7f86915fd 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/CreateBranchPage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/CreateBranchPage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 SAP AG.
+ * Copyright (c) 2010, 2014 SAP AG and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -13,11 +13,18 @@
package org.eclipse.egit.ui.internal.repository;
import java.io.IOException;
+import java.util.concurrent.atomic.AtomicReference;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.SafeRunner;
+import org.eclipse.egit.core.Activator;
import org.eclipse.egit.core.op.CreateLocalBranchOperation;
import org.eclipse.egit.core.op.CreateLocalBranchOperation.UpstreamConfig;
+import org.eclipse.egit.ui.IBranchNameProvider;
import org.eclipse.egit.ui.UIUtils;
import org.eclipse.egit.ui.internal.UIIcons;
import org.eclipse.egit.ui.internal.UIText;
@@ -32,6 +39,7 @@ import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.resource.LocalResourceManager;
+import org.eclipse.jface.util.SafeRunnable;
import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.jgit.lib.Constants;
@@ -64,6 +72,8 @@ import org.eclipse.swt.widgets.Text;
*/
class CreateBranchPage extends WizardPage {
+ private static final String BRANCH_NAME_PROVIDER_ID = "org.eclipse.egit.ui.branchNameProvider"; //$NON-NLS-1$
+
/**
* Get proposed target branch name for given source branch name
*
@@ -401,7 +411,10 @@ class CreateBranchPage extends WizardPage {
private void suggestBranchName(String ref) {
if (nameText.getText().length() == 0 || nameIsSuggestion) {
- String branchNameSuggestion = getProposedTargetName(ref);
+ String branchNameSuggestion = getBranchNameSuggestionFromProvider();
+ if (branchNameSuggestion == null)
+ branchNameSuggestion = getProposedTargetName(ref);
+
if (branchNameSuggestion != null) {
nameText.setText(branchNameSuggestion);
nameText.selectAll();
@@ -410,6 +423,37 @@ class CreateBranchPage extends WizardPage {
}
}
+ private IBranchNameProvider getBranchNameProvider() {
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IConfigurationElement[] config = registry
+ .getConfigurationElementsFor(BRANCH_NAME_PROVIDER_ID);
+ if (config.length > 0) {
+ Object provider;
+ try {
+ provider = config[0].createExecutableExtension("class"); //$NON-NLS-1$
+ if (provider instanceof IBranchNameProvider)
+ return (IBranchNameProvider) provider;
+ } catch (Throwable e) {
+ Activator.logError(
+ UIText.CreateBranchPage_CreateBranchNameProviderFailed,
+ e);
+ }
+ }
+ return null;
+ }
+
+ private String getBranchNameSuggestionFromProvider() {
+ final AtomicReference<String> ref = new AtomicReference<String>();
+ final IBranchNameProvider branchNameProvider = getBranchNameProvider();
+ if (branchNameProvider != null)
+ SafeRunner.run(new SafeRunnable() {
+ public void run() throws Exception {
+ ref.set(branchNameProvider.getBranchNameSuggestion());
+ }
+ });
+ return ref.get();
+ }
+
private static class SourceSelectionDialog extends
AbstractBranchSelectionDialog {
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
index fcb0c421e4..3f57b516ed 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
@@ -821,6 +821,7 @@ CreateBranchPage_CheckingOutMessage=Checking out new branch...
CreateBranchPage_CheckoutButton=&Checkout new branch
CreateBranchPage_ChooseBranchAndNameMessage=Please choose a source branch and a name for the new branch
CreateBranchPage_ChooseNameMessage=Please choose a name for the new branch
+CreateBranchPage_CreateBranchNameProviderFailed=Failed to create branch name provider
CreateBranchPage_CreatingBranchMessage=Creating branch...
CreateBranchPage_LocalBranchWarningMessage=Local branch as upstream is not recommended, use remote branch
CreateBranchPage_MissingSourceMessage=Please select a source branch

Back to the top