]> source.dussan.org Git - gitblit.git/commitdiff
Revisions to custom fields
authorJames Moger <james.moger@gitblit.com>
Thu, 10 May 2012 21:38:25 +0000 (17:38 -0400)
committerJames Moger <james.moger@gitblit.com>
Thu, 10 May 2012 21:38:25 +0000 (17:38 -0400)
12 files changed:
docs/01_setup.mkd
groovy/blockpush.groovy
groovy/jenkins.groovy
groovy/localclone.groovy
groovy/protect-refs.groovy
groovy/sendmail.groovy
src/com/gitblit/GitBlit.java
src/com/gitblit/IStoredSettings.java
src/com/gitblit/wicket/GitBlitWebApp.properties
src/com/gitblit/wicket/GitBlitWebApp_ja.properties
src/com/gitblit/wicket/pages/EditRepositoryPage.html
src/com/gitblit/wicket/pages/EditRepositoryPage.java

index 68c10255196c0a318ac3f0bc3e16e8e89b0e75fe..c8cd09db52b09c3f70ca12f16290f4c053971434 100644 (file)
@@ -398,6 +398,16 @@ Some sample scripts are included in the GO and WAR distributions to show you how
 \r
 Hook contributions and improvements are welcome.\r
 \r
+### Custom Fields\r
+\r
+*SINCE 1.0.0*\r
+\r
+Gitblit allows custom repository string fields to be defined in `gitblit.properties` or `web.xml`.  Entry textfields are automatically created for these fields in the Edit Repository page of Gitblit and the Edit Repository dialog of the Gitblit Manager.  These fields are accessible from your Groovy hook scripts as\r
+\r
+    repository.customFields.myField\r
+\r
+This feature allows you to customize the behavior of your hook scripts without hard-coding values in the hook scripts themselves.\r
+\r
 ### Pre-Receive\r
 \r
 Pre-Receive scripts execute after the pushed objects have all been written to the Git repository but before the refs have been updated to point to these new objects.\r
index 186b2427920fd2c9788e961a03e08c346e8a6ffb..d0e2c2e0fa7558c0d110ad506679a812771ba377 100644 (file)
@@ -58,6 +58,9 @@ import com.gitblit.utils.ClientLogger
  *     url                             Base url for Gitblit            String\r
  *  logger                     Logs messages to Gitblit        org.slf4j.Logger\r
  *  clientLogger       Logs messages to Git client     com.gitblit.utils.ClientLogger\r
+ *\r
+ * Accessing Gitblit Custom Fields:\r
+ *   def myCustomField = repository.customFields.myCustomField\r
  *  \r
  */\r
 \r
index 41083d2499a641eae9871ca5a720426f0ddce8e3..73360581398e133bd97a72e18c42400aaf5f9dfc 100644 (file)
@@ -53,6 +53,9 @@ import org.slf4j.Logger
  *     url                             Base url for Gitblit            String\r
  *  logger                     Logs messages to Gitblit        org.slf4j.Logger\r
  *  clientLogger       Logs messages to Git client     com.gitblit.utils.ClientLogger\r
+ *\r
+ * Accessing Gitblit Custom Fields:\r
+ *   def myCustomField = repository.customFields.myCustomField\r
  *  \r
  */\r
 // Indicate we have started the script\r
index e1d44938e8cce1d8d2c1c00365c715a8ca1a8b0f..11868d71767d05747f07e99f283d78ef58dc69b8 100644 (file)
@@ -63,6 +63,9 @@ import org.slf4j.Logger
  *     url                             Base url for Gitblit            String\r
  *  logger                     Logs messages to Gitblit        org.slf4j.Logger\r
  *  clientLogger       Logs messages to Git client     com.gitblit.utils.ClientLogger\r
+ *\r
+ * Accessing Gitblit Custom Fields:\r
+ *   def myCustomField = repository.customFields.myCustomField\r
  *  \r
  */\r
 \r
index 48ac60f1932d9971bfa26786a65311da51eda1c0..f730bcb23482c74934a33fa9bf7d74c08a47ede3 100644 (file)
@@ -64,6 +64,9 @@ import org.slf4j.Logger
  *     url                             Base url for Gitblit            String\r
  *  logger                     Logs messages to Gitblit        org.slf4j.Logger\r
  *  clientLogger       Logs messages to Git client     com.gitblit.utils.ClientLogger\r
+ *\r
+ * Accessing Gitblit Custom Fields:\r
+ *   def myCustomField = repository.customFields.myCustomField\r
  *  \r
  */\r
 \r
index 888f6643c6ff2fee6c8f05d281b0305292b95ecb..8d223ef50aaccd1edcd200214721f8731e7e5086 100644 (file)
@@ -59,6 +59,9 @@ import org.slf4j.Logger
  *     url                             Base url for Gitblit            String\r
  *  logger                     Logs messages to Gitblit        org.slf4j.Logger\r
  *  clientLogger       Logs messages to Git client     com.gitblit.utils.ClientLogger\r
+ *\r
+ * Accessing Gitblit Custom Fields:\r
+ *   def myCustomField = repository.customFields.myCustomField\r
  *  \r
  */\r
 \r
index 57421a3142874dc82ab4590b5156185b5011f61f..a86cfd7f2442e8f818270b37401b199025c495d5 100644 (file)
@@ -30,6 +30,7 @@ import java.util.Collection;
 import java.util.Collections;\r
 import java.util.Date;\r
 import java.util.HashMap;\r
+import java.util.LinkedHashMap;\r
 import java.util.LinkedHashSet;\r
 import java.util.List;\r
 import java.util.Map;\r
@@ -254,6 +255,17 @@ public class GitBlit implements ServletContextListener {
                return self().settings.getStrings(key);\r
        }\r
 \r
+       /**\r
+        * Returns a map of space-separated key-value pairs from the specified key.\r
+        * \r
+        * @see IStoredSettings.getStrings(String key)\r
+        * @param name\r
+        * @return map of string, string\r
+        */\r
+       public static Map<String, String> getMap(String key) {\r
+               return self().settings.getMap(key);\r
+       }\r
+\r
        /**\r
         * Returns the list of keys whose name starts with the specified prefix. If\r
         * the prefix is null or empty, all key names are returned.\r
@@ -859,7 +871,7 @@ public class GitBlit implements ServletContextListener {
                                        Constants.CONFIG_GITBLIT, null, "indexBranch")));\r
                        \r
                        // Custom defined properties\r
-                       model.customFields = new HashMap<String, String>();\r
+                       model.customFields = new LinkedHashMap<String, String>();\r
                        for (String aProperty : config.getNames(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS)) {\r
                                model.customFields.put(aProperty, config.getString(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS, aProperty));\r
                        }\r
index 2f45f09da8b8a3672c736ff8445f16c0eec7da9a..e060091955a4136cc6168e0d6bc260764c209b8d 100644 (file)
@@ -16,6 +16,7 @@
 package com.gitblit;\r
 \r
 import java.util.ArrayList;\r
+import java.util.LinkedHashMap;\r
 import java.util.List;\r
 import java.util.Map;\r
 import java.util.Properties;\r
@@ -203,6 +204,23 @@ public abstract class IStoredSettings {
                }\r
                return strings;\r
        }\r
+       \r
+       /**\r
+        * Returns a map of strings from the specified key.\r
+        * \r
+        * @param name\r
+        * @return map of string, string\r
+        */\r
+       public Map<String, String> getMap(String name) {\r
+               Map<String, String> map = new LinkedHashMap<String, String>();\r
+               for (String string : getStrings(name)) {\r
+                       String[] kvp = string.split("=", 2);\r
+                       String key = kvp[0];\r
+                       String value = kvp[1];                          \r
+                       map.put(key,  value);\r
+               }\r
+               return map;\r
+       }\r
 \r
        /**\r
         * Override the specified key with the specified value.\r
index dfbdd4bf82274f12257cbcef3f1ac71056d400b6..83b716af431bb204a60c68fca400393a177082f8 100644 (file)
@@ -203,7 +203,7 @@ gb.preReceiveScripts = pre-receive scripts
 gb.postReceiveScripts = post-receive scripts\r
 gb.hookScripts = hook scripts\r
 gb.customFields = custom fields\r
-gb.customFieldsDescription = custom fields available to groovy hooks\r
+gb.customFieldsDescription = custom fields available to Groovy hooks\r
 gb.accessPermissions = access permissions\r
 gb.filters = filters\r
 gb.generalDescription = common settings\r
index 7e50bd8d0e40f9a2a5eb49dc19191d34ae19d9ae..d73b37ea08182d71da361c029b15db94398cc865 100755 (executable)
@@ -202,6 +202,8 @@ gb.mailingLists = \u30e1\u30fc\u30ea\u30f3\u30b0\u30ea\u30b9\u30c8
 gb.preReceiveScripts = pre-receive \u30b9\u30af\u30ea\u30d7\u30c8\r
 gb.postReceiveScripts = post-receive \u30b9\u30af\u30ea\u30d7\u30c8\r
 gb.hookScripts = \u30d5\u30c3\u30af\u30b9\u30af\u30ea\u30d7\u30c8\r
+gb.customFields = custom fields\r
+gb.customFieldsDescription = custom fields available to Groovy hooks\r
 gb.accessPermissions = \u30a2\u30af\u30bb\u30b9\u6a29\u9650\r
 gb.filters = \u30d5\u30a3\u30eb\u30bf\u30fc\r
 gb.generalDescription = \u4e00\u822c\u7684\u306a\u8a2d\u5b9a\r
index 07c55226a62f055926acc9d6d1eb7d211e5c0638..a419698d941a969b2461402660db4cf46977e7b9 100644 (file)
                                <tr><td colspan="2"><h3><wicket:message key="gb.hookScripts"></wicket:message> &nbsp;<small><wicket:message key="gb.hookScriptsDescription"></wicket:message></small></h3></td></tr>    \r
                                <tr><th style="vertical-align: top;"><wicket:message key="gb.preReceiveScripts"></wicket:message><p></p><span wicket:id="inheritedPreReceive"></span></th><td style="padding:2px;"><span wicket:id="preReceiveScripts"></span></td></tr>\r
                                <tr><th style="vertical-align: top;"><wicket:message key="gb.postReceiveScripts"></wicket:message><p></p><span wicket:id="inheritedPostReceive"></span></th><td style="padding:2px;"><span wicket:id="postReceiveScripts"></span></td></tr>\r
-                               <div wicket:id="customFiledsSection">\r
+                               <div wicket:id="customFieldsSection">\r
                                        <tr><td colspan="2"><h3><wicket:message key="gb.customFields"></wicket:message> &nbsp;<small><wicket:message key="gb.customFieldsDescription"></wicket:message></small></h3></td></tr>\r
-                                       <tr wicket:id="customFieldsListView"><th style="vertical-align: top;"><span wicket:id="customFieldLabel"></span></th><td class="edit"><input class="span8" type="text" wicket:id="customFieldValue" size="30" tabindex="16" /></td></tr>\r
+                                       <tr wicket:id="customFieldsListView"><th><span wicket:id="customFieldLabel"></span></th><td class="edit"><input class="span8" type="text" wicket:id="customFieldValue" /></td></tr>\r
                                </div>\r
-                               <tr><td colspan='2'><div class="form-actions"><input class="btn btn-primary" type="submit" value="Save" wicket:message="value:gb.save" wicket:id="save" tabindex="17" /> &nbsp; <input class="btn" type="submit" value="Cancel" wicket:message="value:gb.cancel" wicket:id="cancel" tabindex="18" /></div></td></tr>\r
+                               <tr><td colspan='2'><div class="form-actions"><input class="btn btn-primary" type="submit" value="Save" wicket:message="value:gb.save" wicket:id="save" /> &nbsp; <input class="btn" type="submit" value="Cancel" wicket:message="value:gb.cancel" wicket:id="cancel" /></div></td></tr>\r
                        </tbody>\r
                </table>\r
        </form> \r
index f3e2c3865636a56f9ca7936dd54017537c2db62a..e057e2a2e364fbe7518ebe1e87ac977f20805ec8 100644 (file)
 package com.gitblit.wicket.pages;\r
 \r
 import java.text.MessageFormat;\r
-import java.util.AbstractMap;\r
 import java.util.ArrayList;\r
 import java.util.Arrays;\r
 import java.util.Collections;\r
 import java.util.HashSet;\r
 import java.util.Iterator;\r
+import java.util.LinkedHashMap;\r
 import java.util.List;\r
 import java.util.Map;\r
-import java.util.Map.Entry;\r
 import java.util.Set;\r
 \r
 import org.apache.wicket.PageParameters;\r
@@ -39,7 +38,6 @@ import org.apache.wicket.markup.html.form.Form;
 import org.apache.wicket.markup.html.form.IChoiceRenderer;\r
 import org.apache.wicket.markup.html.form.TextField;\r
 import org.apache.wicket.markup.html.list.ListItem;\r
-import org.apache.wicket.markup.html.list.ListItemModel;\r
 import org.apache.wicket.markup.html.list.ListView;\r
 import org.apache.wicket.model.CompoundPropertyModel;\r
 import org.apache.wicket.model.IModel;\r
@@ -157,22 +155,24 @@ public class EditRepositoryPage extends RootSubPage {
                                                .self().getPostReceiveScriptsUnused(repositoryModel)),\r
                                new StringChoiceRenderer(), 12, true);\r
                \r
-               // Dynamic Custom Defined Properties Properties\r
-               final List<Entry<String, String>> definedProperties = new ArrayList<Entry<String, String>>();\r
-               List<String> customFields = GitBlit.getStrings(Keys.repository.customFields);\r
-               for (String customFieldDef : customFields) {\r
-                       String[] customFieldProperty = customFieldDef.split("=");\r
-                       definedProperties.add(new AbstractMap.SimpleEntry<String, String>(customFieldProperty[0], customFieldProperty[1]));\r
-               }\r
-               \r
-               final ListView<Entry<String, String>> customFieldsListView = new ListView<Entry<String, String>>("customFieldsListView", definedProperties) {\r
+               // custom fields\r
+               final Map<String, String> customFieldsMap = GitBlit.getMap(Keys.groovy.customFields);\r
+               List<String> customKeys = new ArrayList<String>(customFieldsMap.keySet());\r
+               final ListView<String> customFieldsListView = new ListView<String>("customFieldsListView", customKeys) {\r
+                       \r
+                       private static final long serialVersionUID = 1L;\r
+\r
                        @Override\r
-                       protected void populateItem(ListItem<Entry<String, String>> item) {\r
-                               String value = repositoryModel.customFields.get(item.getModelObject().getKey());\r
+                       protected void populateItem(ListItem<String> item) {\r
+                               String key = item.getModelObject();\r
+                               item.add(new Label("customFieldLabel", customFieldsMap.get(key)));\r
                                \r
-                               item.add(new Label(item.getModelObject().getKey(), item.getModelObject().getValue()));          // Used to get the key later\r
-                               item.add(new Label("customFieldLabel", item.getModelObject().getValue()));\r
-                               item.add(new TextField<String>("customFieldValue", new Model<String>(value)));\r
+                               String value = "";\r
+                               if (repositoryModel.customFields != null && repositoryModel.customFields.containsKey(key)) {\r
+                                       value = repositoryModel.customFields.get(key);\r
+                               }\r
+                               TextField<String> field = new TextField<String>("customFieldValue", new Model<String>(value));\r
+                               item.add(field);\r
                        }\r
                };\r
                customFieldsListView.setReuseItems(true);\r
@@ -277,11 +277,14 @@ public class EditRepositoryPage extends RootSubPage {
                                        }\r
                                        repositoryModel.postReceiveScripts = postReceiveScripts;\r
                                        \r
-                                       // Loop over each of the user defined properties\r
+                                       // custom fields\r
+                                       repositoryModel.customFields = new LinkedHashMap<String, String>();\r
                                        for (int i = 0; i < customFieldsListView.size(); i++) {\r
-                                               ListItem<ListItemModel<String>> item = (ListItem<ListItemModel<String>>) customFieldsListView.get(i);\r
-                                               String key = item.get(0).getId();               // Item 0 is our 'fake' label\r
-                                               String value = ((TextField<String>)item.get(2)).getValue();             // Item 2 is out text box\r
+                                               ListItem<String> child = (ListItem<String>) customFieldsListView.get(i);\r
+                                               String key = child.getModelObject();\r
+\r
+                                               TextField<String> field = (TextField<String>) child.get("customFieldValue");\r
+                                               String value = field.getValue();\r
                                                \r
                                                repositoryModel.customFields.put(key, value);\r
                                        }\r
@@ -371,13 +374,9 @@ public class EditRepositoryPage extends RootSubPage {
                form.add(new BulletListPanel("inheritedPostReceive", "inherited", GitBlit.self()\r
                                .getPostReceiveScriptsInherited(repositoryModel)));\r
                \r
-               WebMarkupContainer customFiledsSection = new WebMarkupContainer("customFiledsSection") {\r
-                       public boolean isVisible() {\r
-                               return GitBlit.getString(Keys.repository.customFields, "").isEmpty() == false;\r
-                       };\r
-               };\r
-               customFiledsSection.add(customFieldsListView);\r
-               form.add(customFiledsSection);\r
+               WebMarkupContainer customFieldsSection = new WebMarkupContainer("customFieldsSection");\r
+               customFieldsSection.add(customFieldsListView);\r
+               form.add(customFieldsSection.setVisible(!GitBlit.getString(Keys.groovy.customFields, "").isEmpty()));\r
 \r
                form.add(new Button("save"));\r
                Button cancel = new Button("cancel") {\r