Hi,
I am struggling to find a clean way to hook into the commit action von subclipse
and finally decided on integrating the pre/post commit on client side since I
found a couple of related posts where people were having the same problem I did.
I created two extensions for the UI bundle allowing to add pre/post commit
actions. They implement an interface I called ICommitAction.
I then hooked into the CommitOperation class and execute precommits on the
aboutToRun event of the job, as well as PostCommits on the done event of the
job. I am not sure this would be the best solution. Alternatively I could hook
into the CommitAction class and operate precommit before the dialog is opened
and postcommit as soon as it is closed. The advantage with the joblistener
methods would be that postcommit would actually be executed when the commit is
done, which would not be the case otherwise.
It's a minor patch which enables user to execute custom code with the commit.
Let me know what your thinking.
Kind regards,
Artur kronenberg
I can't find the upload button in this page, so I will c/p my patch here. Maybe
I'll find the upload button later or you can let me know where it is, I'll be
happy to upload the patch as a file.
------- PATCH ---------
### Eclipse Workspace Patch 1.0
#P org.tigris.subversion.subclipse.ui
Index: src/org/tigris/subversion/subclipse/ui/prepostcommit/ICommitAction.java
===================================================================
--- src/org/tigris/subversion/subclipse/ui/prepostcommit/ICommitAction.java
(revision 0)
+++ src/org/tigris/subversion/subclipse/ui/prepostcommit/ICommitAction.java
(revision 0)
@@ -0,0 +1,11 @@
+package org.tigris.subversion.subclipse.ui.prepostcommit;
+
+import org.eclipse.core.resources.IResource;
+
+public interface ICommitAction {
+
+ public void execute( final IResource[] ResourcesToCommi,
+ final IResource[] resourcesToAdd,
+ final IResource[] resourcesToDelete);
+
+}
Index: plugin.xml
===================================================================
--- plugin.xml (revision 4859)
+++ plugin.xml (working copy)
@@ -5,6 +5,8 @@
<extension-point id="mergeProviders" name="Merge Providers"
schema="schema/mergeProviders.exsd"/>
<extension-point id="commitDialogToolBarActions" name="Commit Dialog ToolBar
Actions" schema="schema/commitDialogExtensions.exsd"/>
<extension-point id="commitDialogCompareActions" name="Commit Dialog Compare
Actions" schema="schema/commitDialogExtensions.exsd"/>
+ <extension-point id="postcommitaction" name="post commit action"
schema="schema/commitaction.exsd"/>
+ <extension-point id="precommitaction" name="Pre commit action"
schema="schema/commitaction.exsd"/>
<extension
point="org.tigris.subversion.clientadapter.loadErrorHandlers">
Index: src/org/tigris/subversion/subclipse/ui/actions/CommitAction.java
===================================================================
--- src/org/tigris/subversion/subclipse/ui/actions/CommitAction.java (revision 4859)
+++ src/org/tigris/subversion/subclipse/ui/actions/CommitAction.java (working copy)
@@ -24,8 +24,11 @@
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceVisitor;
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.NullProgressMonitor;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
@@ -48,6 +51,8 @@
import org.tigris.subversion.subclipse.ui.SVNUIPlugin;
import org.tigris.subversion.subclipse.ui.dialogs.CommitToTagsWarningDialog;
import org.tigris.subversion.subclipse.ui.operations.CommitOperation;
+import org.tigris.subversion.subclipse.ui.prepostcommit.CommitExtension;
+import org.tigris.subversion.subclipse.ui.prepostcommit.ICommitAction;
import org.tigris.subversion.subclipse.ui.settings.ProjectProperties;
import org.tigris.subversion.subclipse.ui.wizards.dialogs.SvnWizard;
import org.tigris.subversion.subclipse.ui.wizards.dialogs.SvnWizardCommitPage;
@@ -111,7 +116,7 @@
MessageDialog.openInformation(getShell(),
Policy.bind("CommitDialog.title"), Policy.bind("CommitDialog.noChanges"));
//$NON-NLS-1$ //$NON-NLS-2$
commit = false;
} else {
- ProjectProperties projectProperties =
ProjectProperties.getProjectProperties(modified[0]);
+ ProjectProperties projectProperties =
ProjectProperties.getProjectProperties(modified[0]);
commit = confirmCommit(modified, projectProperties);
}
@@ -136,12 +141,20 @@
return; // user canceled
}
- CommitOperation commitOperation = new
CommitOperation(getTargetPart(), resources,
- (IResource[]) resourcesToBeAdded.toArray(new
IResource[resourcesToBeAdded.size()]),
- (IResource[]) resourcesToBeDeleted.toArray(new
IResource[resourcesToBeDeleted.size()]),
- resourcesToCommit, commitComment, keepLocks);
+ IResource[] arrayToBeAdded = (IResource[])
resourcesToBeAdded.toArray(new IResource[resourcesToBeAdded.size()]);
+ IResource[] arrayToBeDeleted = (IResource[])
resourcesToBeDeleted.toArray(new IResource[resourcesToBeDeleted.size()]);
+ //Pre-commit execution
+
+ ICommitAction[] preCommitActions = CommitExtension.getPreCommitActions();
+ ICommitAction[] postCommitActions =
CommitExtension.getPostCommitActions();
+
+ CommitOperation commitOperation = new CommitOperation(getTargetPart(),
resources,
+ arrayToBeAdded,
+ arrayToBeDeleted,
+ resourcesToCommit, commitComment, keepLocks, preCommitActions,
postCommitActions);
commitOperation.setCanRunAsJob(canRunAsJob);
commitOperation.run();
+ //Post-commit execution
}
}
Index: schema/commitaction.exsd
===================================================================
--- schema/commitaction.exsd (revision 0)
+++ schema/commitaction.exsd (revision 0)
@@ -0,0 +1,102 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.tigris.subversion.subclipse.ui"
xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.tigris.subversion.subclipse.ui"
id="precommitaction" name="Pre commit action"/>
+ </appInfo>
+ <documentation>
+ Adds a commit action to the commit dialog.
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appInfo>
+ <meta.element />
+ </appInfo>
+ </annotation>
+ <complexType>
+ <choice minOccurs="0" maxOccurs="1">
+ <element ref="contribution" minOccurs="1" maxOccurs="unbounded"/>
+ </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="contribution">
+ <complexType>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+ Class implementing the commit action
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="java"
basedOn=":org.tigris.subversion.subclipse.ui.prepostcommit.ICommitAction"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ [Enter the first release in which this extension point appears.]
+ </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>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+
+</schema>
Index: src/org/tigris/subversion/subclipse/ui/prepostcommit/CommitExtension.java
===================================================================
--- src/org/tigris/subversion/subclipse/ui/prepostcommit/CommitExtension.java
(revision 0)
+++ src/org/tigris/subversion/subclipse/ui/prepostcommit/CommitExtension.java
(revision 0)
@@ -0,0 +1,45 @@
+package org.tigris.subversion.subclipse.ui.prepostcommit;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.Platform;
+
+public final class CommitExtension {
+
+ private static final String PRE_COMMIT_ID =
"org.tigris.subversion.subclipse.ui.precommitaction";
+ private static final String POST_COMMIT_ID =
"org.tigris.subversion.subclipse.ui.postcommitaction";
+
+ private CommitExtension(){}
+
+ public static ICommitAction[] getPreCommitActions() {
+ return getCommitActions( true );
+ }
+
+ public static ICommitAction[] getPostCommitActions() {
+ return getCommitActions( false );
+ }
+
+ private static ICommitAction[] getCommitActions(final boolean preCommit) {
+ List result = new ArrayList();
+ IExtensionRegistry eReg = Platform.getExtensionRegistry();
+ IConfigurationElement[] elements = eReg
+ .getConfigurationElementsFor(preCommit ? PRE_COMMIT_ID
+ : POST_COMMIT_ID);
+ try {
+ for (int i = 0; i < elements.length; i++) {
+ Object object = elements[i].createExecutableExtension("class");
+ if (object instanceof ICommitAction) {
+ result.add(object);
+ }
+ }
+ } catch (CoreException e1) {
+ e1.printStackTrace();
+ }
+ return (ICommitAction[]) result
+ .toArray(new ICommitAction[result.size()]);
+ }
+}
Index: src/org/tigris/subversion/subclipse/ui/operations/CommitOperation.java
===================================================================
--- src/org/tigris/subversion/subclipse/ui/operations/CommitOperation.java
(revision 4859)
+++ src/org/tigris/subversion/subclipse/ui/operations/CommitOperation.java
(working copy)
@@ -22,6 +22,7 @@
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.team.core.RepositoryProvider;
import org.eclipse.team.core.TeamException;
import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
@@ -34,6 +35,7 @@
import org.tigris.subversion.subclipse.ui.ISVNUIConstants;
import org.tigris.subversion.subclipse.ui.Policy;
import org.tigris.subversion.subclipse.ui.SVNUIPlugin;
+import org.tigris.subversion.subclipse.ui.prepostcommit.ICommitAction;
import org.tigris.subversion.subclipse.ui.subscriber.SVNSynchronizeParticipant;
import org.tigris.subversion.svnclientadapter.ISVNClientAdapter;
import org.tigris.subversion.svnclientadapter.ISVNInfo;
@@ -51,18 +53,27 @@
private ISynchronizePageConfiguration configuration;
private boolean useJavaHLHack = true;
private boolean canRunAsJob = true;
+ private final ICommitAction[] postCommitActions;
+ private final ICommitAction[] preCommitActions;
- public CommitOperation(IWorkbenchPart part, IResource[] selectedResources,
IResource[] resourcesToAdd, IResource[] resourcesToDelete, IResource[]
resourcesToCommit, String commitComment, boolean keepLocks) {
- super(part);
-// this.selectedResources = selectedResources;
- this.resourcesToAdd = resourcesToAdd;
- this.resourcesToDelete = resourcesToDelete;
- this.resourcesToCommit = resourcesToCommit;
- this.commitComment = commitComment;
- this.keepLocks = keepLocks;
- }
+ public CommitOperation(IWorkbenchPart part, IResource[] selectedResources,
+ IResource[] resourcesToAdd, IResource[] resourcesToDelete,
+ IResource[] resourcesToCommit, String commitComment,
+ boolean keepLocks, ICommitAction[] preCommitActions,
+ ICommitAction[] postCommitActions) {
+ super(part);
+ // this.selectedResources = selectedResources;
+ this.resourcesToAdd = resourcesToAdd;
+ this.resourcesToDelete = resourcesToDelete;
+ this.resourcesToCommit = resourcesToCommit;
+ this.commitComment = commitComment;
+ this.keepLocks = keepLocks;
+ this.preCommitActions = preCommitActions;
+ this.postCommitActions = postCommitActions;
+ }
protected void execute(IProgressMonitor monitor) throws SVNException,
InterruptedException {
+ System.out.println( "Execute start");
monitor.beginTask(null, resourcesToAdd.length + resourcesToDelete.length +
resourcesToCommit.length);
String adminFolderName =
SVNProviderPlugin.getPlugin().getAdminDirectoryName();
File cleanUpPathList = null;
@@ -514,4 +525,17 @@
this.canRunAsJob = canRunAsJob;
}
+ public void done(IJobChangeEvent event) {
+ for( int i = 0; i < postCommitActions.length; i++) {
+ postCommitActions[i].execute(resourcesToCommit, resourcesToAdd,
resourcesToDelete);
+ }
+ super.done(event);
+ }
+
+ public void aboutToRun(IJobChangeEvent event) {
+ for( int i = 0; i < preCommitActions.length; i++) {
+ preCommitActions[i].execute(resourcesToCommit, resourcesToAdd,
resourcesToDelete);
+ }
+ super.aboutToRun(event);
+ }
}
Index:
src/org/tigris/subversion/subclipse/ui/subscriber/CommitSynchronizeOperation.java
===================================================================
---
src/org/tigris/subversion/subclipse/ui/subscriber/CommitSynchronizeOperation.java (revision
4859)
+++
src/org/tigris/subversion/subclipse/ui/subscriber/CommitSynchronizeOperation.java (working
copy)
@@ -46,6 +46,8 @@
import org.tigris.subversion.subclipse.ui.SVNUIPlugin;
import org.tigris.subversion.subclipse.ui.dialogs.CommitToTagsWarningDialog;
import org.tigris.subversion.subclipse.ui.operations.CommitOperation;
+import org.tigris.subversion.subclipse.ui.prepostcommit.CommitExtension;
+import org.tigris.subversion.subclipse.ui.prepostcommit.ICommitAction;
import org.tigris.subversion.subclipse.ui.settings.ProjectProperties;
import org.tigris.subversion.subclipse.ui.wizards.dialogs.SvnWizard;
import org.tigris.subversion.subclipse.ui.wizards.dialogs.SvnWizardCommitPage;
@@ -324,8 +326,10 @@
toBeAddedList.toArray(resourcesToBeAdded[0]);
resourcesToBeDeleted[0] = new IResource[toBeDeletedList.size()];
toBeDeletedList.toArray(resourcesToBeDeleted[0]);
+ ICommitAction[] preCommitActions = CommitExtension.getPreCommitActions();
+ ICommitAction[] postCommitActions = CommitExtension.getPostCommitActions();
try {
- CommitOperation commit = new CommitOperation(getPart(),
resourcesToCommit, resourcesToBeAdded[0], resourcesToBeDeleted[0],
resourcesToCommit, commitComment, keepLocks);
+ CommitOperation commit = new CommitOperation(getPart(),
resourcesToCommit, resourcesToBeAdded[0], resourcesToBeDeleted[0],
resourcesToCommit, commitComment, keepLocks, preCommitActions, postCommitActions);
if
(SVNProviderPlugin.getPlugin().getPluginPreferences().getBoolean(ISVNCoreConstants.PREF_SHOW_OUT_OF_DATE_FOLDERS))
commit.setConfiguration(configuration);
commit.run();
Index: META-INF/MANIFEST.MF
===================================================================
--- META-INF/MANIFEST.MF (revision 4859)
+++ META-INF/MANIFEST.MF (working copy)
@@ -41,6 +41,7 @@
org.tigris.subversion.subclipse.ui.internal,
org.tigris.subversion.subclipse.ui.operations,
org.tigris.subversion.subclipse.ui.preferences,
+ org.tigris.subversion.subclipse.ui.prepostcommit,
org.tigris.subversion.subclipse.ui.properties,
org.tigris.subversion.subclipse.ui.repository,
org.tigris.subversion.subclipse.ui.repository.model,
Created an attachment (id=339)
There you go, found the button. This is the patch on the pre/post commit for the client siede