Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2011-12-19 09:22:06 -0500
committerEike Stepper2011-12-19 09:22:06 -0500
commita63c7fd12c60c0ab962ba4c046244aedc99ec118 (patch)
tree39fcef522c3ab3704b867cbaf4dc3277eaf49ef7
parent67e7fa8d901578091e8e75e38e5f7ca7e66fecd6 (diff)
downloadcdo-a63c7fd12c60c0ab962ba4c046244aedc99ec118.tar.gz
cdo-a63c7fd12c60c0ab962ba4c046244aedc99ec118.tar.xz
cdo-a63c7fd12c60c0ab962ba4c046244aedc99ec118.zip
Apply patches to git repos
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.wingit/META-INF/MANIFEST.MF10
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.wingit/build.properties2
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.wingit/icons/apply-patch.gifbin0 -> 578 bytes
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.wingit/icons/repository.gifbin0 -> 545 bytes
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.wingit/icons/wingit.gif (renamed from plugins/org.eclipse.emf.cdo.releng.wingit/wingit.gif)bin926 -> 926 bytes
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.wingit/plugin.xml23
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.wingit/src/org/eclipse/emf/cdo/releng/wingit/ApplyPatchToGitAction.java222
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.wingit/src/org/eclipse/emf/cdo/releng/wingit/GitAction.java115
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.wingit/src/org/eclipse/emf/cdo/releng/wingit/WinGit.java137
9 files changed, 387 insertions, 122 deletions
diff --git a/plugins/org.eclipse.emf.cdo.releng.wingit/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.releng.wingit/META-INF/MANIFEST.MF
index 4fe21a9287..118394e0af 100644
--- a/plugins/org.eclipse.emf.cdo.releng.wingit/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.cdo.releng.wingit/META-INF/MANIFEST.MF
@@ -6,9 +6,13 @@ Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-Activator: org.eclipse.emf.cdo.releng.wingit.Activator
-Require-Bundle: org.eclipse.ui;bundle-version="[3.4.0,4.0.0)",
- org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)",
- org.eclipse.jgit;bundle-version="[1.0.0,2.0.0)"
+Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)",
+ org.eclipse.core.resources;bundle-version="[3.4.0,4.0.0)",
+ org.eclipse.ui;bundle-version="[3.4.0,4.0.0)",
+ org.eclipse.jgit;bundle-version="[1.0.0,2.0.0)",
+ org.eclipse.egit.core;bundle-version="[1.0.0,2.0.0)",
+ org.eclipse.mylyn.tasks.core;bundle-version="[3.3.0,4.0.0)";resolution:=optional,
+ org.eclipse.mylyn.tasks.ui;bundle-version="[3.3.0,4.0.0)";resolution:=optional
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.emf.cdo.releng.wingit;version="1.0.0";x-internal:=true
diff --git a/plugins/org.eclipse.emf.cdo.releng.wingit/build.properties b/plugins/org.eclipse.emf.cdo.releng.wingit/build.properties
index c529fb6812..2079fab631 100644
--- a/plugins/org.eclipse.emf.cdo.releng.wingit/build.properties
+++ b/plugins/org.eclipse.emf.cdo.releng.wingit/build.properties
@@ -10,6 +10,6 @@ bin.includes = plugin.xml,\
copyright.txt,\
modeling32.png,\
plugin.properties,\
- wingit.gif
+ icons/
src.includes = about.html,\
copyright.txt
diff --git a/plugins/org.eclipse.emf.cdo.releng.wingit/icons/apply-patch.gif b/plugins/org.eclipse.emf.cdo.releng.wingit/icons/apply-patch.gif
new file mode 100644
index 0000000000..17482b753c
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.releng.wingit/icons/apply-patch.gif
Binary files differ
diff --git a/plugins/org.eclipse.emf.cdo.releng.wingit/icons/repository.gif b/plugins/org.eclipse.emf.cdo.releng.wingit/icons/repository.gif
new file mode 100644
index 0000000000..0470e1588d
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.releng.wingit/icons/repository.gif
Binary files differ
diff --git a/plugins/org.eclipse.emf.cdo.releng.wingit/wingit.gif b/plugins/org.eclipse.emf.cdo.releng.wingit/icons/wingit.gif
index 674902afb8..674902afb8 100644
--- a/plugins/org.eclipse.emf.cdo.releng.wingit/wingit.gif
+++ b/plugins/org.eclipse.emf.cdo.releng.wingit/icons/wingit.gif
Binary files differ
diff --git a/plugins/org.eclipse.emf.cdo.releng.wingit/plugin.xml b/plugins/org.eclipse.emf.cdo.releng.wingit/plugin.xml
index 843c01d17b..1e48f7acef 100644
--- a/plugins/org.eclipse.emf.cdo.releng.wingit/plugin.xml
+++ b/plugins/org.eclipse.emf.cdo.releng.wingit/plugin.xml
@@ -6,19 +6,32 @@
point="org.eclipse.ui.popupMenus">
<objectContribution
adaptable="true"
- id="org.eclipse.emf.cdo.releng.winexplorer.contribution"
+ id="org.eclipse.emf.cdo.releng.wingit.contribution1"
objectClass="org.eclipse.egit.ui.internal.repository.tree.RepositoryNode">
<action
class="org.eclipse.emf.cdo.releng.wingit.GitAction"
enablesFor="1"
- icon="wingit.gif"
- id="org.eclipse.emf.cdo.releng.GitAction"
+ icon="icons/wingit.gif"
+ id="org.eclipse.emf.cdo.releng.wingit.GitAction"
label="Windows Git"
menubarPath="additions"
state="true"
style="push"
- tooltip="Open Windows Git Bash">
- </action>
+ tooltip="Open Windows Git Bash"/>
+ </objectContribution>
+ <objectContribution
+ adaptable="false"
+ id="org.eclipse.emf.cdo.releng.wingit.contribution2"
+ objectClass="org.eclipse.mylyn.tasks.core.ITaskAttachment">
+ <action
+ class="org.eclipse.emf.cdo.releng.wingit.ApplyPatchToGitAction"
+ enablesFor="1"
+ icon="icons/apply-patch.gif"
+ id="org.eclipse.emf.cdo.releng.wingit.ApplyPatchToGitAction"
+ label="Apply Patch To Git"
+ menubarPath="actions"
+ style="pulldown"
+ tooltip="Apply patch to a Git repository"/>
</objectContribution>
</extension>
diff --git a/plugins/org.eclipse.emf.cdo.releng.wingit/src/org/eclipse/emf/cdo/releng/wingit/ApplyPatchToGitAction.java b/plugins/org.eclipse.emf.cdo.releng.wingit/src/org/eclipse/emf/cdo/releng/wingit/ApplyPatchToGitAction.java
new file mode 100644
index 0000000000..ddba36c44f
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.releng.wingit/src/org/eclipse/emf/cdo/releng/wingit/ApplyPatchToGitAction.java
@@ -0,0 +1,222 @@
+/**
+ * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.releng.wingit;
+
+import org.eclipse.core.resources.IStorage;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.ActionContributionItem;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IMenuCreator;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.mylyn.tasks.core.ITaskAttachment;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.actions.BaseSelectionListenerAction;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+
+/**
+ * @author Eike Stepper
+ */
+public class ApplyPatchToGitAction extends BaseSelectionListenerAction implements IViewActionDelegate, IMenuCreator
+{
+ private ISelection currentSelection;
+
+ private Menu dropDownMenu;
+
+ public ApplyPatchToGitAction()
+ {
+ super("Adjust and Apply Patch");
+ }
+
+ protected ApplyPatchToGitAction(String text)
+ {
+ super(text);
+ }
+
+ public void init(IViewPart view)
+ {
+ // ignore
+ }
+
+ public void run(IAction action)
+ {
+ action.setMenuCreator(this);
+ }
+
+ public void selectionChanged(IAction action, ISelection selection)
+ {
+ action.setMenuCreator(this);
+ currentSelection = selection;
+ }
+
+ private ITaskAttachment getSelectedAttachment()
+ {
+ if (currentSelection instanceof StructuredSelection)
+ {
+ Object object = ((StructuredSelection)currentSelection).getFirstElement();
+ if (object instanceof ITaskAttachment)
+ {
+ return (ITaskAttachment)object;
+ }
+ }
+
+ return null;
+ }
+
+ public void dispose()
+ {
+ if (dropDownMenu != null)
+ {
+ dropDownMenu.dispose();
+ dropDownMenu = null;
+ }
+ }
+
+ public Menu getMenu(Control parent)
+ {
+ dispose();
+ dropDownMenu = new Menu(parent);
+ addActionsToMenu();
+ return dropDownMenu;
+ }
+
+ public Menu getMenu(Menu parent)
+ {
+ dispose();
+ dropDownMenu = new Menu(parent);
+ addActionsToMenu();
+ return dropDownMenu;
+ }
+
+ private void addActionsToMenu()
+ {
+ ITaskAttachment attachment = getSelectedAttachment();
+ if (attachment == null)
+ {
+ return;
+ }
+
+ Repository[] repositories = org.eclipse.egit.core.Activator.getDefault().getRepositoryCache().getAllRepositories();
+ for (Repository repository : repositories)
+ {
+ RepositorySelectionAction action = new RepositorySelectionAction(attachment, repository);
+ ActionContributionItem item = new ActionContributionItem(action);
+ item.fill(dropDownMenu, -1);
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private class RepositorySelectionAction extends Action
+ {
+ private final ITaskAttachment attachment;
+
+ private final Repository repository;
+
+ public RepositorySelectionAction(ITaskAttachment attachment, Repository repository)
+ {
+ this.attachment = attachment;
+ this.repository = repository;
+ setText(repository.getWorkTree().getName());
+ setImageDescriptor(Activator.getImageDescriptor("icons/repository.gif"));
+ }
+
+ @Override
+ @SuppressWarnings({ "restriction", "deprecation" })
+ public void run()
+ {
+ try
+ {
+ IStorage storage = org.eclipse.mylyn.internal.tasks.ui.editors.TaskAttachmentStorage.create(attachment);
+ File file = savePatch(storage);
+
+ // TODO Do apply patch here:
+ System.out.println("Applying " + file.getAbsolutePath() + " to " + repository.getWorkTree());
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ @SuppressWarnings("resource")
+ private File savePatch(IStorage storage) throws CoreException
+ {
+ InputStream in = null;
+ BufferedWriter writer = null;
+
+ try
+ {
+ File tempFile = File.createTempFile("~attachment-", ".patch");
+ writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(tempFile)));
+
+ in = storage.getContents();
+ BufferedReader reader = new BufferedReader(new InputStreamReader(in));
+
+ String line;
+ while ((line = reader.readLine()) != null)
+ {
+ writer.write(line);
+ writer.write("\n");
+ }
+
+ return tempFile;
+ }
+ catch (CoreException ex)
+ {
+ throw ex;
+ }
+ catch (Exception ex)
+ {
+ throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Problem while saving patch", ex));
+ }
+ finally
+ {
+ if (in != null)
+ {
+ try
+ {
+ in.close();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+
+ if (writer != null)
+ {
+ try
+ {
+ writer.close();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.releng.wingit/src/org/eclipse/emf/cdo/releng/wingit/GitAction.java b/plugins/org.eclipse.emf.cdo.releng.wingit/src/org/eclipse/emf/cdo/releng/wingit/GitAction.java
index 54fe922c0d..cef7cf6a99 100644
--- a/plugins/org.eclipse.emf.cdo.releng.wingit/src/org/eclipse/emf/cdo/releng/wingit/GitAction.java
+++ b/plugins/org.eclipse.emf.cdo.releng.wingit/src/org/eclipse/emf/cdo/releng/wingit/GitAction.java
@@ -12,31 +12,21 @@ package org.eclipse.emf.cdo.releng.wingit;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.dialogs.IInputValidator;
-import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
-import java.io.BufferedReader;
import java.io.File;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
/**
* @author Eike Stepper
*/
public class GitAction implements IObjectActionDelegate
{
- private static final String GIT_BASH = "C:\\Program Files (x86)\\Git\\bin\\sh.exe";
-
private IWorkbenchPart targetPart;
- private String gitBash;
-
private Repository repository;
public GitAction()
@@ -67,13 +57,13 @@ public class GitAction implements IObjectActionDelegate
{
if (repository != null)
{
- initGitBash();
+ String gitBash = WinGit.getGitBash(targetPart.getSite().getShell());
try
{
File workTree = repository.getWorkTree();
Runtime.getRuntime().exec(
- "cmd /c cd \"" + workTree.getAbsolutePath() + "\" && start cmd.exe /c \"" + GIT_BASH + "\" --login -i");
+ "cmd /c cd \"" + workTree.getAbsolutePath() + "\" && start cmd.exe /c \"" + gitBash + "\" --login -i");
}
catch (Exception ex)
{
@@ -81,105 +71,4 @@ public class GitAction implements IObjectActionDelegate
}
}
}
-
- protected void initGitBash()
- {
- if (gitBash == null)
- {
- File stateFile = Activator.getDefault().getStateLocation().append("git-bash.txt").toFile();
- if (stateFile.isFile())
- {
- gitBash = loadFile(stateFile);
- }
-
- if (gitBash == null)
- {
- gitBash = getPath(GIT_BASH);
- }
-
- if (!new File(gitBash).isFile())
- {
- gitBash = getPath(gitBash);
- }
-
- saveFile(stateFile, gitBash);
- }
- }
-
- private String getPath(String initial)
- {
- InputDialog dialog = new InputDialog(targetPart.getSite().getShell(), "Git Bash", "Location:", initial,
- new IInputValidator()
- {
- public String isValid(String newText)
- {
- return new File(newText).isFile() ? null : "Not a file!";
- }
- });
-
- if (dialog.open() != InputDialog.OK)
- {
- throw new IllegalStateException("Git bash not found at " + gitBash);
- }
-
- return dialog.getValue();
- }
-
- private String loadFile(File file)
- {
- FileReader in = null;
-
- try
- {
- in = new FileReader(file);
- return new BufferedReader(in).readLine();
- }
- catch (IOException ex)
- {
- return null;
- }
- finally
- {
- if (in != null)
- {
- try
- {
- in.close();
- }
- catch (IOException ex)
- {
- // Ignore
- }
- }
- }
- }
-
- private void saveFile(File file, String content)
- {
- FileWriter out = null;
-
- try
- {
- out = new FileWriter(file);
- out.write(content);
- }
- catch (IOException ex)
- {
- throw new IllegalStateException("Could not write to " + file, ex);
- }
- finally
- {
- if (out != null)
- {
- try
- {
- out.close();
- }
- catch (IOException ex)
- {
- // Ignore
- }
- }
- }
- }
}
diff --git a/plugins/org.eclipse.emf.cdo.releng.wingit/src/org/eclipse/emf/cdo/releng/wingit/WinGit.java b/plugins/org.eclipse.emf.cdo.releng.wingit/src/org/eclipse/emf/cdo/releng/wingit/WinGit.java
new file mode 100644
index 0000000000..c0a0b7251a
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.releng.wingit/src/org/eclipse/emf/cdo/releng/wingit/WinGit.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.releng.wingit;
+
+import org.eclipse.jface.dialogs.IInputValidator;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.swt.widgets.Shell;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+
+/**
+ * @author Eike Stepper
+ */
+public class WinGit
+{
+ private static final String GIT_BASH = "C:\\Program Files (x86)\\Git\\bin\\sh.exe";
+
+ private static String gitBash;
+
+ public WinGit()
+ {
+ }
+
+ public static synchronized String getGitBash(Shell shell)
+ {
+ if (gitBash == null)
+ {
+ File stateFile = Activator.getDefault().getStateLocation().append("git-bash.txt").toFile();
+ if (stateFile.isFile())
+ {
+ gitBash = loadFile(stateFile);
+ }
+
+ if (gitBash == null)
+ {
+ gitBash = getPath(GIT_BASH, shell);
+ }
+
+ if (!new File(gitBash).isFile())
+ {
+ gitBash = getPath(gitBash, shell);
+ }
+
+ saveFile(stateFile, gitBash);
+ }
+
+ return gitBash;
+ }
+
+ private static String getPath(String initial, Shell shell)
+ {
+ InputDialog dialog = new InputDialog(shell, "Git Bash", "Location:", initial, new IInputValidator()
+ {
+ public String isValid(String newText)
+ {
+ return new File(newText).isFile() ? null : "Not a file!";
+ }
+ });
+
+ if (dialog.open() != InputDialog.OK)
+ {
+ throw new IllegalStateException("Git bash not found at " + gitBash);
+ }
+
+ return dialog.getValue();
+ }
+
+ private static String loadFile(File file)
+ {
+ FileReader in = null;
+
+ try
+ {
+ in = new FileReader(file);
+ return new BufferedReader(in).readLine();
+ }
+ catch (IOException ex)
+ {
+ return null;
+ }
+ finally
+ {
+ if (in != null)
+ {
+ try
+ {
+ in.close();
+ }
+ catch (IOException ex)
+ {
+ // Ignore
+ }
+ }
+ }
+ }
+
+ private static void saveFile(File file, String content)
+ {
+ FileWriter out = null;
+
+ try
+ {
+ out = new FileWriter(file);
+ out.write(content);
+ }
+ catch (IOException ex)
+ {
+ throw new IllegalStateException("Could not write to " + file, ex);
+ }
+ finally
+ {
+ if (out != null)
+ {
+ try
+ {
+ out.close();
+ }
+ catch (IOException ex)
+ {
+ // Ignore
+ }
+ }
+ }
+ }
+}

Back to the top